osl-base-extended 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Component, Inject, inject, Injector, Injectable } from '@angular/core';
3
+ import * as i1 from '@angular/material/dialog';
4
+ import { MAT_DIALOG_DATA, MatDialogModule, MatDialog } from '@angular/material/dialog';
5
+ import { MatSnackBar } from '@angular/material/snack-bar';
6
+ import { Router } from '@angular/router';
7
+ import { NgTemplateOutlet } from '@angular/common';
8
+ import { MatIconButton } from '@angular/material/button';
9
+ import * as i2 from '@angular/material/icon';
10
+ import { MatIconModule } from '@angular/material/icon';
11
+ import { HttpHeaders, HttpParams, HttpClient } from '@angular/common/http';
12
+ import { firstValueFrom, timeout } from 'rxjs';
13
+
14
+ class OslBaseExtended {
15
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: OslBaseExtended, deps: [], target: i0.ɵɵFactoryTarget.Component });
16
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.9", type: OslBaseExtended, isStandalone: true, selector: "lib-osl-base-extended", ngImport: i0, template: ` <p>osl-base-extended works!</p> `, isInline: true, styles: [""] });
17
+ }
18
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: OslBaseExtended, decorators: [{
19
+ type: Component,
20
+ args: [{ selector: 'lib-osl-base-extended', imports: [], template: ` <p>osl-base-extended works!</p> ` }]
21
+ }] });
22
+
23
+ class DialogWrapper {
24
+ dialogRef;
25
+ data;
26
+ dialogData = new Dialog();
27
+ constructor(dialogRef, data) {
28
+ this.dialogRef = dialogRef;
29
+ this.data = data;
30
+ this.dialogData.header = data.header;
31
+ this.dialogData.formBody = data.formBody;
32
+ this.dialogData.formFooter = data.formFooter;
33
+ this.dialogData.data = data.data;
34
+ }
35
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DialogWrapper, deps: [{ token: i1.MatDialogRef }, { token: MAT_DIALOG_DATA }], target: i0.ɵɵFactoryTarget.Component });
36
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.9", type: DialogWrapper, isStandalone: true, selector: "dialog-wrapper", ngImport: i0, template: "<div>\n @if(typeof dialogData.header == 'string'){\n <div class=\"dialog-header\" mat-dialog-title>\n <span class=\"dialog-heading\">{{dialogData.header}}</span>\n <button mat-dialog-close mat-icon-button><mat-icon>close</mat-icon></button>\n </div>\n }@else{\n <ng-container *ngTemplateOutlet=\"dialogData.header; context: { $implicit: dialogData }\"></ng-container>\n\n }\n \n\n</div>\n<mat-dialog-content>\n <div class=\"dialog-body\">\n @if(dialogData.formBody){\n <ng-container *ngTemplateOutlet=\"dialogData.formBody; context: { $implicit: dialogData }\"></ng-container>\n\n }\n\n </div>\n\n\n</mat-dialog-content>\n<mat-dialog-actions>\n @if(dialogData.formFooter){\n <div class=\"dialog-footer\">\n <ng-container *ngTemplateOutlet=\"dialogData.formFooter; context: { $implicit: dialogData }\"></ng-container>\n </div>\n\n }\n\n</mat-dialog-actions>", styles: [".dialog-header{display:flex;align-items:center;justify-content:space-between}.mat-dialog-close{margin-left:2px;margin-right:2px}.dialog-body,.dialog-footer{padding:0 5px}.mat-mdc-dialog-title:before{display:none}.dialog-heading{font-size:20px;font-weight:500}\n"], dependencies: [{ kind: "ngmodule", type: MatDialogModule }, { kind: "directive", type: i1.MatDialogClose, selector: "[mat-dialog-close], [matDialogClose]", inputs: ["aria-label", "type", "mat-dialog-close", "matDialogClose"], exportAs: ["matDialogClose"] }, { kind: "directive", type: i1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { kind: "directive", type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]", inputs: ["align"] }, { kind: "directive", type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }] });
37
+ }
38
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DialogWrapper, decorators: [{
39
+ type: Component,
40
+ args: [{ selector: 'dialog-wrapper', imports: [MatDialogModule, MatIconModule, NgTemplateOutlet, MatIconButton], template: "<div>\n @if(typeof dialogData.header == 'string'){\n <div class=\"dialog-header\" mat-dialog-title>\n <span class=\"dialog-heading\">{{dialogData.header}}</span>\n <button mat-dialog-close mat-icon-button><mat-icon>close</mat-icon></button>\n </div>\n }@else{\n <ng-container *ngTemplateOutlet=\"dialogData.header; context: { $implicit: dialogData }\"></ng-container>\n\n }\n \n\n</div>\n<mat-dialog-content>\n <div class=\"dialog-body\">\n @if(dialogData.formBody){\n <ng-container *ngTemplateOutlet=\"dialogData.formBody; context: { $implicit: dialogData }\"></ng-container>\n\n }\n\n </div>\n\n\n</mat-dialog-content>\n<mat-dialog-actions>\n @if(dialogData.formFooter){\n <div class=\"dialog-footer\">\n <ng-container *ngTemplateOutlet=\"dialogData.formFooter; context: { $implicit: dialogData }\"></ng-container>\n </div>\n\n }\n\n</mat-dialog-actions>", styles: [".dialog-header{display:flex;align-items:center;justify-content:space-between}.mat-dialog-close{margin-left:2px;margin-right:2px}.dialog-body,.dialog-footer{padding:0 5px}.mat-mdc-dialog-title:before{display:none}.dialog-heading{font-size:20px;font-weight:500}\n"] }]
41
+ }], ctorParameters: () => [{ type: i1.MatDialogRef }, { type: Dialog, decorators: [{
42
+ type: Inject,
43
+ args: [MAT_DIALOG_DATA]
44
+ }] }] });
45
+ class Dialog {
46
+ header = "No Title Found";
47
+ formBody;
48
+ formFooter;
49
+ data;
50
+ }
51
+
52
+ class baseComponent {
53
+ _injector = inject(Injector);
54
+ showSuccess(message) {
55
+ if (Array.isArray(message)) {
56
+ message = message.join(',');
57
+ }
58
+ this.showSnack(message);
59
+ }
60
+ showError(error) {
61
+ if (Array.isArray(error)) {
62
+ error = error.join(',');
63
+ }
64
+ this.showSnack(error);
65
+ }
66
+ navigate(url) {
67
+ this._injector.get(Router).navigate([url]);
68
+ }
69
+ showSnack(message) {
70
+ this._injector.get(MatSnackBar).open(message, 'Ok', {
71
+ duration: 3000
72
+ });
73
+ }
74
+ openDialog(header, formBody, formFooter, width = '40vw', data) {
75
+ const dialogData = {
76
+ header: header,
77
+ formBody: formBody,
78
+ formFooter: formFooter
79
+ };
80
+ const dialogRef = this._injector.get(MatDialog)?.open(DialogWrapper, {
81
+ width: width,
82
+ data: { ...dialogData, ...data },
83
+ });
84
+ return dialogRef;
85
+ }
86
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: baseComponent, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
87
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: baseComponent });
88
+ }
89
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: baseComponent, decorators: [{
90
+ type: Injectable
91
+ }] });
92
+
93
+ class Httpbase {
94
+ controller;
95
+ controllerName = '';
96
+ constructor(controller) {
97
+ this.controller = controller;
98
+ this.controllerName = controller;
99
+ }
100
+ getEndPoint(methodName) {
101
+ return `${this.baseUrl}${this.controllerName}/${methodName}`;
102
+ }
103
+ getHeaders() {
104
+ const token = localStorage.getItem('token');
105
+ return new HttpHeaders({
106
+ 'Content-Type': 'application/json',
107
+ Authorization: token ? `Bearer ${token}` : '',
108
+ });
109
+ }
110
+ handleSuccess(statusCode, result) {
111
+ return {
112
+ isSuccessful: statusCode >= 200 && statusCode < 300,
113
+ error: '',
114
+ result: result,
115
+ statusCode: statusCode,
116
+ };
117
+ }
118
+ handleError(error) {
119
+ return {
120
+ isSuccessful: false,
121
+ error: this.mapError(error),
122
+ statusCode: error.status,
123
+ result: null,
124
+ };
125
+ }
126
+ mapError(error) {
127
+ let errorMessage = '';
128
+ switch (error.status) {
129
+ case 0:
130
+ errorMessage = 'Connection Error! Please Contact Adminsitration';
131
+ break;
132
+ case 400:
133
+ errorMessage = error.error.message || 'Something Went Wrong';
134
+ break;
135
+ case 401:
136
+ errorMessage = 'Unauthorized Access';
137
+ break;
138
+ case 403:
139
+ errorMessage = "You don't have rights to perform this action";
140
+ break;
141
+ case 500:
142
+ errorMessage = 'An error has occured,Please contact support';
143
+ break;
144
+ default:
145
+ errorMessage = 'Something went wrong';
146
+ }
147
+ return errorMessage;
148
+ }
149
+ buildParams(paramsArray) {
150
+ return (paramsArray || []).reduce((params, { property, value }) => {
151
+ if (property && value != null) {
152
+ return Array.isArray(value)
153
+ ? value.reduce((p, v) => p.append(property, v), params)
154
+ : params.set(property, value);
155
+ }
156
+ return params;
157
+ }, new HttpParams());
158
+ }
159
+ http = inject(HttpClient);
160
+ baseUrl = '/api/'; // Change later
161
+ async post(methodName, body) {
162
+ try {
163
+ const res = await firstValueFrom(this.http
164
+ .post(this.getEndPoint(methodName), body, {
165
+ observe: 'response',
166
+ headers: this.getHeaders(),
167
+ })
168
+ .pipe(timeout(30000)));
169
+ return this.handleSuccess(res.status, res.body);
170
+ }
171
+ catch (error) {
172
+ return this.handleError(error);
173
+ }
174
+ }
175
+ async get(methodName, params) {
176
+ try {
177
+ const res = await firstValueFrom(this.http
178
+ .get(this.getEndPoint(methodName), {
179
+ observe: 'response',
180
+ headers: this.getHeaders(),
181
+ params: this.buildParams(params || []),
182
+ })
183
+ .pipe(timeout(30000)));
184
+ return this.handleSuccess(res.status, res.body);
185
+ }
186
+ catch (error) {
187
+ return this.handleError(error);
188
+ }
189
+ }
190
+ }
191
+
192
+ /*
193
+ * Public API Surface of osl-base-extended
194
+ */
195
+
196
+ /**
197
+ * Generated bundle index. Do not edit.
198
+ */
199
+
200
+ export { Dialog, DialogWrapper, Httpbase, OslBaseExtended, baseComponent };
201
+ //# sourceMappingURL=osl-base-extended.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"osl-base-extended.mjs","sources":["../../../projects/osl-base-extended/src/lib/osl-base-extended.ts","../../../projects/osl-base-extended/src/lib/core/shared/components/dialog-wrapper/dialog-wrapper.ts","../../../projects/osl-base-extended/src/lib/core/shared/components/dialog-wrapper/dialog-wrapper.html","../../../projects/osl-base-extended/src/lib/core/base/base.component.ts","../../../projects/osl-base-extended/src/lib/core/http/httpbase.ts","../../../projects/osl-base-extended/src/public-api.ts","../../../projects/osl-base-extended/src/osl-base-extended.ts"],"sourcesContent":["import { Component } from '@angular/core';\n\n@Component({\n selector: 'lib-osl-base-extended',\n imports: [],\n template: ` <p>osl-base-extended works!</p> `,\n styles: ``,\n})\nexport class OslBaseExtended {}\n","import { NgTemplateOutlet } from '@angular/common';\nimport { Component, Inject, TemplateRef } from '@angular/core';\nimport { MatIconButton } from '@angular/material/button';\nimport { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';\nimport { MatIconModule } from '@angular/material/icon';\n\n\n@Component({\n selector: 'dialog-wrapper',\n imports: [MatDialogModule, MatIconModule, NgTemplateOutlet, MatIconButton],\n templateUrl: './dialog-wrapper.html',\n styleUrl: './dialog-wrapper.scss',\n})\nexport class DialogWrapper {\n public dialogData:Dialog= new Dialog()\n constructor(public dialogRef:MatDialogRef<DialogWrapper>,@Inject(MAT_DIALOG_DATA) public data: Dialog){\n this.dialogData.header = data.header;\n this.dialogData.formBody = data.formBody;\n this.dialogData.formFooter = data.formFooter;\n this.dialogData.data = data.data\n }\n}\n\nexport class Dialog{\n header:string|TemplateRef<any>= \"No Title Found\";\n formBody:TemplateRef<any> | undefined;\n formFooter:TemplateRef<any> | undefined;\n data?:any;\n\n\n\n}\n","<div>\n @if(typeof dialogData.header == 'string'){\n <div class=\"dialog-header\" mat-dialog-title>\n <span class=\"dialog-heading\">{{dialogData.header}}</span>\n <button mat-dialog-close mat-icon-button><mat-icon>close</mat-icon></button>\n </div>\n }@else{\n <ng-container *ngTemplateOutlet=\"dialogData.header; context: { $implicit: dialogData }\"></ng-container>\n\n }\n \n\n</div>\n<mat-dialog-content>\n <div class=\"dialog-body\">\n @if(dialogData.formBody){\n <ng-container *ngTemplateOutlet=\"dialogData.formBody; context: { $implicit: dialogData }\"></ng-container>\n\n }\n\n </div>\n\n\n</mat-dialog-content>\n<mat-dialog-actions>\n @if(dialogData.formFooter){\n <div class=\"dialog-footer\">\n <ng-container *ngTemplateOutlet=\"dialogData.formFooter; context: { $implicit: dialogData }\"></ng-container>\n </div>\n\n }\n\n</mat-dialog-actions>","import { inject, Injectable, Injector, TemplateRef } from \"@angular/core\";\r\nimport { MatDialog, MatDialogRef } from \"@angular/material/dialog\";\r\nimport { MatSnackBar } from \"@angular/material/snack-bar\";\r\nimport { Router } from \"@angular/router\";\r\nimport { Dialog, DialogWrapper } from \"../shared/components/dialog-wrapper/dialog-wrapper\";\r\n@Injectable()\r\n\r\nexport class baseComponent{\r\n private _injector = inject(Injector);\r\n\r\n protected showSuccess(message:any){\r\n if(Array.isArray(message)){\r\n message = message.join(',')\r\n }\r\n this.showSnack(message)\r\n }\r\n\r\n\r\n protected showError(error:string|string[]){\r\n if(Array.isArray(error)){\r\n error = error.join(',')\r\n }\r\n this.showSnack(error)\r\n }\r\n\r\n protected navigate(url:string){\r\n this._injector.get(Router).navigate([url])\r\n }\r\n\r\n private showSnack(message:string){\r\n this._injector.get(MatSnackBar).open(message,'Ok',{\r\n duration:3000\r\n })\r\n }\r\n\r\n protected openDialog(\r\n header:string|TemplateRef<any>, \r\n formBody:TemplateRef<any>,\r\n formFooter:TemplateRef<any>,\r\n width:string = '40vw',\r\n data?:any,\r\n ):MatDialogRef<any>{\r\n const dialogData:Dialog= {\r\n header:header,\r\n formBody:formBody,\r\n formFooter:formFooter\r\n }\r\n const dialogRef = this._injector.get(MatDialog)?.open(DialogWrapper,{\r\n width:width,\r\n data:{...dialogData,...data},\r\n\r\n })\r\n return dialogRef;\r\n \r\n\r\n }\r\n\r\n}","import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport { firstValueFrom, timeout } from 'rxjs';\n\nexport interface HttpResponse<T = any> {\n isSuccessful: boolean;\n statusCode: number;\n error: string;\n result: T;\n}\nexport interface myParams {\n property: string;\n value: any;\n}\nexport abstract class Httpbase {\n private controllerName: string = '';\n constructor(private controller: string) {\n this.controllerName = controller;\n }\n\n private getEndPoint(methodName: string) {\n return `${this.baseUrl}${this.controllerName}/${methodName}`;\n }\n private getHeaders() {\n const token = localStorage.getItem('token');\n return new HttpHeaders({\n 'Content-Type': 'application/json',\n Authorization: token ? `Bearer ${token}` : '',\n });\n }\n private handleSuccess<T>(statusCode: number, result: any): HttpResponse<T> {\n return {\n isSuccessful: statusCode >= 200 && statusCode < 300,\n error: '',\n result: result,\n statusCode: statusCode,\n };\n }\n\n private handleError<T>(error: any): HttpResponse<T> {\n return {\n isSuccessful: false,\n error: this.mapError(error),\n statusCode: error.status,\n result: null as any,\n };\n }\n\n private mapError(error: HttpErrorResponse): any {\n let errorMessage = '';\n switch (error.status) {\n case 0:\n errorMessage = 'Connection Error! Please Contact Adminsitration';\n break;\n case 400:\n errorMessage = error.error.message || 'Something Went Wrong';\n break;\n case 401:\n errorMessage = 'Unauthorized Access';\n break;\n case 403:\n errorMessage = \"You don't have rights to perform this action\";\n break;\n case 500:\n errorMessage = 'An error has occured,Please contact support';\n break;\n default:\n errorMessage = 'Something went wrong';\n }\n return errorMessage;\n }\n private buildParams(paramsArray: myParams[]): HttpParams {\n return (paramsArray || []).reduce((params, { property, value }) => {\n if (property && value != null) {\n return Array.isArray(value)\n ? value.reduce((p, v) => p.append(property, v), params)\n : params.set(property, value);\n }\n return params;\n }, new HttpParams());\n }\n protected http = inject(HttpClient);\n\n private baseUrl = '/api/'; // Change later\n protected async post<T>(methodName: string, body: any): Promise<HttpResponse<T>> {\n try {\n const res = await firstValueFrom(\n this.http\n .post(this.getEndPoint(methodName), body, {\n observe: 'response',\n headers: this.getHeaders(),\n })\n .pipe(timeout(30000)),\n );\n return this.handleSuccess(res.status, res.body);\n } catch (error: any) {\n return this.handleError(error);\n }\n }\n protected async get<T>(methodName: string, params?: myParams[]): Promise<HttpResponse<T>> {\n try {\n const res = await firstValueFrom(\n this.http\n .get(this.getEndPoint(methodName), {\n observe: 'response',\n headers: this.getHeaders(),\n params: this.buildParams(params || []),\n })\n .pipe(timeout(30000)),\n );\n\n return this.handleSuccess(res.status, res.body);\n } catch (error: any) {\n return this.handleError(error);\n }\n }\n}\n","/*\n * Public API Surface of osl-base-extended\n */\n\nexport * from './lib/osl-base-extended';\nexport * from './lib/core/base/base.component';\nexport * from './lib/core/http/httpbase';\nexport * from './lib/core/shared/components/dialog-wrapper/dialog-wrapper';\n\n\n\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;;;;MAQa,eAAe,CAAA;uGAAf,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAf,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,eAAe,iFAHhB,CAAA,iCAAA,CAAmC,EAAA,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,EAAA,CAAA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AkB,EAAE,MAAmB,EAAA;AAC5D,QAAA,IAAI;AACF,YAAA,MAAM,GAAG,GAAG,MAAM,cAAc,CAC9B,IAAI,CAAC;AACF,iBAAA,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE;AACjC,gBAAA,OAAO,EAAE,UAAU;AACnB,gBAAA,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;gBAC1B,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,IAAI,EAAE,CAAC;aACvC;AACA,iBAAA,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CACxB;AAED,YAAA,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC;QACjD;QAAE,OAAO,KAAU,EAAE;AACnB,YAAA,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QAChC;IACF;AACD;;ACpHD;;AAEG;;ACFH;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osl-base-extended",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^21.2.0",
6
6
  "@angular/core": "^21.2.0"
@@ -11,9 +11,18 @@
11
11
  "sideEffects": false,
12
12
  "description": "This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 21.2.0.",
13
13
  "main": "index.js",
14
- "scripts": {
15
- "test": "echo \"Error: no test specified\" && exit 1"
16
- },
17
14
  "author": "Bilal Raza",
18
- "license": "ISC"
15
+ "license": "ISC",
16
+ "module": "fesm2022/osl-base-extended.mjs",
17
+ "typings": "types/osl-base-extended.d.ts",
18
+ "exports": {
19
+ "./package.json": {
20
+ "default": "./package.json"
21
+ },
22
+ ".": {
23
+ "types": "./types/osl-base-extended.d.ts",
24
+ "default": "./fesm2022/osl-base-extended.mjs"
25
+ }
26
+ },
27
+ "type": "module"
19
28
  }
@@ -0,0 +1,64 @@
1
+ import * as i0 from '@angular/core';
2
+ import { TemplateRef } from '@angular/core';
3
+ import { MatDialogRef } from '@angular/material/dialog';
4
+ import { HttpClient } from '@angular/common/http';
5
+
6
+ declare class OslBaseExtended {
7
+ static ɵfac: i0.ɵɵFactoryDeclaration<OslBaseExtended, never>;
8
+ static ɵcmp: i0.ɵɵComponentDeclaration<OslBaseExtended, "lib-osl-base-extended", never, {}, {}, never, never, true, never>;
9
+ }
10
+
11
+ declare class baseComponent {
12
+ private _injector;
13
+ protected showSuccess(message: any): void;
14
+ protected showError(error: string | string[]): void;
15
+ protected navigate(url: string): void;
16
+ private showSnack;
17
+ protected openDialog(header: string | TemplateRef<any>, formBody: TemplateRef<any>, formFooter: TemplateRef<any>, width?: string, data?: any): MatDialogRef<any>;
18
+ static ɵfac: i0.ɵɵFactoryDeclaration<baseComponent, never>;
19
+ static ɵprov: i0.ɵɵInjectableDeclaration<baseComponent>;
20
+ }
21
+
22
+ interface HttpResponse<T = any> {
23
+ isSuccessful: boolean;
24
+ statusCode: number;
25
+ error: string;
26
+ result: T;
27
+ }
28
+ interface myParams {
29
+ property: string;
30
+ value: any;
31
+ }
32
+ declare abstract class Httpbase {
33
+ private controller;
34
+ private controllerName;
35
+ constructor(controller: string);
36
+ private getEndPoint;
37
+ private getHeaders;
38
+ private handleSuccess;
39
+ private handleError;
40
+ private mapError;
41
+ private buildParams;
42
+ protected http: HttpClient;
43
+ private baseUrl;
44
+ protected post<T>(methodName: string, body: any): Promise<HttpResponse<T>>;
45
+ protected get<T>(methodName: string, params?: myParams[]): Promise<HttpResponse<T>>;
46
+ }
47
+
48
+ declare class DialogWrapper {
49
+ dialogRef: MatDialogRef<DialogWrapper>;
50
+ data: Dialog;
51
+ dialogData: Dialog;
52
+ constructor(dialogRef: MatDialogRef<DialogWrapper>, data: Dialog);
53
+ static ɵfac: i0.ɵɵFactoryDeclaration<DialogWrapper, never>;
54
+ static ɵcmp: i0.ɵɵComponentDeclaration<DialogWrapper, "dialog-wrapper", never, {}, {}, never, never, true, never>;
55
+ }
56
+ declare class Dialog {
57
+ header: string | TemplateRef<any>;
58
+ formBody: TemplateRef<any> | undefined;
59
+ formFooter: TemplateRef<any> | undefined;
60
+ data?: any;
61
+ }
62
+
63
+ export { Dialog, DialogWrapper, Httpbase, OslBaseExtended, baseComponent };
64
+ export type { HttpResponse, myParams };
package/ng-package.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
- "dest": "../../dist/osl-base-extended",
4
- "lib": {
5
- "entryFile": "src/public-api.ts"
6
- }
7
- }
@@ -1,34 +0,0 @@
1
- import { inject, Injectable, Injector } from "@angular/core";
2
- import { MatSnackBar } from "@angular/material/snack-bar";
3
- import { Router } from "@angular/router";
4
- @Injectable()
5
-
6
- export class baseComponent{
7
- private _injector = inject(Injector);
8
-
9
- protected showSuccess(message:any){
10
- if(Array.isArray(message)){
11
- message = message.join(',')
12
- }
13
- this.showSnack(message)
14
- }
15
-
16
-
17
- protected showError(error:string|string[]){
18
- if(Array.isArray(error)){
19
- error = error.join(',')
20
- }
21
- this.showSnack(error)
22
- }
23
-
24
- protected navigate(url:string){
25
- this._injector.get(Router).navigate([url])
26
- }
27
-
28
- private showSnack(message:string){
29
- this._injector.get(MatSnackBar).open(message,'Ok',{
30
- duration:3000
31
- })
32
- }
33
-
34
- }
@@ -1,117 +0,0 @@
1
- import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';
2
- import { inject, Injectable } from '@angular/core';
3
- import { catchError, firstValueFrom, map, Observable, of, timeout } from 'rxjs';
4
-
5
- export interface HttpResponse<T = any> {
6
- isSuccessful: boolean;
7
- statusCode: number;
8
- error: string;
9
- result: T;
10
- }
11
- export interface myParams {
12
- property: string;
13
- value: any;
14
- }
15
- export abstract class Base {
16
- private controllerName: string = '';
17
- constructor(private controller: string) {
18
- this.controllerName = controller;
19
- }
20
-
21
- private getEndPoint(methodName: string) {
22
- return `${this.baseUrl}${this.controllerName}/${methodName}`;
23
- }
24
- private getHeaders() {
25
- const token = localStorage.getItem('token');
26
- return new HttpHeaders({
27
- 'Content-Type': 'application/json',
28
- Authorization: token ? `Bearer ${token}` : '',
29
- });
30
- }
31
- private handleSuccess<T>(statusCode: number, result: any): HttpResponse<T> {
32
- return {
33
- isSuccessful: statusCode >= 200 && statusCode < 300,
34
- error: '',
35
- result: result,
36
- statusCode: statusCode,
37
- };
38
- }
39
-
40
- private handleError<T>(error: any): HttpResponse<T> {
41
- return {
42
- isSuccessful: false,
43
- error: this.mapError(error),
44
- statusCode: error.status,
45
- result: null as any,
46
- };
47
- }
48
-
49
- private mapError(error: HttpErrorResponse): any {
50
- let errorMessage = '';
51
- switch (error.status) {
52
- case 0:
53
- errorMessage = 'Connection Error! Please Contact Adminsitration';
54
- break;
55
- case 400:
56
- errorMessage = error.error.message || 'Something Went Wrong';
57
- break;
58
- case 401:
59
- errorMessage = 'Unauthorized Access';
60
- break;
61
- case 403:
62
- errorMessage = "You don't have rights to perform this action";
63
- break;
64
- case 500:
65
- errorMessage = 'An error has occured,Please contact support';
66
- break;
67
- default:
68
- errorMessage = 'Something went wrong';
69
- }
70
- return errorMessage;
71
- }
72
- private buildParams(paramsArray: myParams[]): HttpParams {
73
- return (paramsArray || []).reduce((params, { property, value }) => {
74
- if (property && value != null) {
75
- return Array.isArray(value)
76
- ? value.reduce((p, v) => p.append(property, v), params)
77
- : params.set(property, value);
78
- }
79
- return params;
80
- }, new HttpParams());
81
- }
82
- protected http = inject(HttpClient);
83
-
84
- private baseUrl = '/api/'; // Change later
85
- protected async post<T>(methodName: string, body: any): Promise<HttpResponse<T>> {
86
- try {
87
- const res = await firstValueFrom(
88
- this.http
89
- .post(this.getEndPoint(methodName), body, {
90
- observe: 'response',
91
- headers: this.getHeaders(),
92
- })
93
- .pipe(timeout(30000)),
94
- );
95
- return this.handleSuccess(res.status, res.body);
96
- } catch (error: any) {
97
- return this.handleError(error);
98
- }
99
- }
100
- protected async get<T>(methodName: string, params?: myParams[]): Promise<HttpResponse<T>> {
101
- try {
102
- const res = await firstValueFrom(
103
- this.http
104
- .get(this.getEndPoint(methodName), {
105
- observe: 'response',
106
- headers: this.getHeaders(),
107
- params: this.buildParams(params || []),
108
- })
109
- .pipe(timeout(30000)),
110
- );
111
-
112
- return this.handleSuccess(res.status, res.body);
113
- } catch (error: any) {
114
- return this.handleError(error);
115
- }
116
- }
117
- }
@@ -1,22 +0,0 @@
1
- import { ComponentFixture, TestBed } from '@angular/core/testing';
2
-
3
- import { OslBaseExtended } from './osl-base-extended';
4
-
5
- describe('OslBaseExtended', () => {
6
- let component: OslBaseExtended;
7
- let fixture: ComponentFixture<OslBaseExtended>;
8
-
9
- beforeEach(async () => {
10
- await TestBed.configureTestingModule({
11
- imports: [OslBaseExtended],
12
- }).compileComponents();
13
-
14
- fixture = TestBed.createComponent(OslBaseExtended);
15
- component = fixture.componentInstance;
16
- await fixture.whenStable();
17
- });
18
-
19
- it('should create', () => {
20
- expect(component).toBeTruthy();
21
- });
22
- });
@@ -1,9 +0,0 @@
1
- import { Component } from '@angular/core';
2
-
3
- @Component({
4
- selector: 'lib-osl-base-extended',
5
- imports: [],
6
- template: ` <p>osl-base-extended works!</p> `,
7
- styles: ``,
8
- })
9
- export class OslBaseExtended {}
package/src/public-api.ts DELETED
@@ -1,8 +0,0 @@
1
- /*
2
- * Public API Surface of osl-base-extended
3
- */
4
-
5
- export * from './lib/osl-base-extended';
6
- export * from './lib/core/base/base.component';
7
- export * from './lib/core/http/base';
8
-
package/tsconfig.lib.json DELETED
@@ -1,13 +0,0 @@
1
- /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
- /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
- {
4
- "extends": "../../tsconfig.json",
5
- "compilerOptions": {
6
- "outDir": "../../out-tsc/lib",
7
- "declaration": true,
8
- "declarationMap": true,
9
- "types": []
10
- },
11
- "include": ["src/**/*.ts"],
12
- "exclude": ["**/*.spec.ts"]
13
- }
@@ -1,11 +0,0 @@
1
- /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
- /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
- {
4
- "extends": "./tsconfig.lib.json",
5
- "compilerOptions": {
6
- "declarationMap": false
7
- },
8
- "angularCompilerOptions": {
9
- "compilationMode": "partial"
10
- }
11
- }
@@ -1,10 +0,0 @@
1
- /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
- /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
- {
4
- "extends": "../../tsconfig.json",
5
- "compilerOptions": {
6
- "outDir": "../../out-tsc/spec",
7
- "types": ["vitest/globals"]
8
- },
9
- "include": ["src/**/*.d.ts", "src/**/*.spec.ts"]
10
- }