ngx-techlify-core 11.4.5 → 11.4.6

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.
@@ -441,6 +441,7 @@ class TechlifyConfig {
441
441
  this.authClientSecret = '';
442
442
  this.authGrantType = '';
443
443
  this.apiUrl = '';
444
+ this.isLogoutWhileApiGetsFailed = false;
444
445
  this.loadFromMap(data);
445
446
  }
446
447
  loadFromMap(data) {
@@ -451,6 +452,7 @@ class TechlifyConfig {
451
452
  this.apiUrl = data.apiUrl;
452
453
  this.storage = data === null || data === void 0 ? void 0 : data.storage;
453
454
  this.rawConfigs = data;
455
+ this.isLogoutWhileApiGetsFailed = data === null || data === void 0 ? void 0 : data.isLogoutWhileApiGetsFailed;
454
456
  }
455
457
  }
456
458
 
@@ -570,8 +572,9 @@ AlertService.ctorParameters = () => [
570
572
  * @since 20171202
571
573
  */
572
574
  class ErrorHandlerService {
573
- constructor(alerter) {
575
+ constructor(alerter, config) {
574
576
  this.alerter = alerter;
577
+ this.config = config;
575
578
  }
576
579
  handleError(errorResponse, msg = '') {
577
580
  var _a, _b, _c, _d;
@@ -598,16 +601,22 @@ class ErrorHandlerService {
598
601
  }
599
602
  var errMessage = errors.length ? errors[0] : msg;
600
603
  this.alerter.addAlert("Error: " + errMessage, "warning");
604
+ if (errorResponse.status == 403 && this.config.isLogoutWhileApiGetsFailed) {
605
+ sessionStorage.clear();
606
+ localStorage.clear();
607
+ location.reload();
608
+ }
601
609
  }
602
610
  }
603
- ErrorHandlerService.ɵprov = ɵɵdefineInjectable({ factory: function ErrorHandlerService_Factory() { return new ErrorHandlerService(ɵɵinject(AlertService)); }, token: ErrorHandlerService, providedIn: "root" });
611
+ ErrorHandlerService.ɵprov = ɵɵdefineInjectable({ factory: function ErrorHandlerService_Factory() { return new ErrorHandlerService(ɵɵinject(AlertService), ɵɵinject(TechlifyConfig)); }, token: ErrorHandlerService, providedIn: "root" });
604
612
  ErrorHandlerService.decorators = [
605
613
  { type: Injectable, args: [{
606
614
  providedIn: 'root'
607
615
  },] }
608
616
  ];
609
617
  ErrorHandlerService.ctorParameters = () => [
610
- { type: AlertService }
618
+ { type: AlertService },
619
+ { type: TechlifyConfig }
611
620
  ];
612
621
 
613
622
  const log = new Logger('ErrorHandlerInterceptor');
@@ -1052,9 +1061,13 @@ class EntityFileService {
1052
1061
  deleteEntityFile(model) {
1053
1062
  return this.http.delete(`api/entity-files/${model.id}`).toPromise();
1054
1063
  }
1055
- uploadEntityFile(file) {
1064
+ uploadEntityFile(file, params) {
1056
1065
  const formData = new FormData();
1057
1066
  formData.append("fileData", file, file.name);
1067
+ if (params === null || params === void 0 ? void 0 : params.entity_id) {
1068
+ formData.append('entity_id', params.entity_id);
1069
+ formData.append('entity_type', params.entity_type);
1070
+ }
1058
1071
  return this.http
1059
1072
  .skipHeader()
1060
1073
  .post("api/entity-files-upload", formData).toPromise();
@@ -1117,7 +1130,8 @@ class EntityFileFormComponent {
1117
1130
  entity_type: [''],
1118
1131
  entity_id: [],
1119
1132
  file: ['', Validators.required],
1120
- url: ['', Validators.required]
1133
+ url: ['', Validators.required],
1134
+ file_size: ['', Validators.required],
1121
1135
  });
1122
1136
  }
1123
1137
  ngOnInit() {
@@ -1175,12 +1189,8 @@ class EntityFileFormComponent {
1175
1189
  this.fileList = event;
1176
1190
  if (this.fileList.length > 0) {
1177
1191
  const result = yield this.entityFileService.uploadEntityFile(this.fileList[0]);
1178
- this.entityFileGroup
1179
- .get("file")
1180
- .setValue(result.item.file);
1181
- this.entityFileGroup
1182
- .get("url")
1183
- .setValue(result.item.url);
1192
+ this.entityFileGroup.patchValue(result.item);
1193
+ ;
1184
1194
  this.fileList = [];
1185
1195
  }
1186
1196
  });
@@ -1212,7 +1222,7 @@ class EntityFileFormComponent {
1212
1222
  EntityFileFormComponent.decorators = [
1213
1223
  { type: Component, args: [{
1214
1224
  selector: 'entity-file-form',
1215
- template: "<form [formGroup]=\"entityFileGroup\" (ngSubmit)=\"submit()\">\n <div fxLayout=\"column\" class=\"mat-typography\">\n <div mat-dialog-title class=\"text-center\">\n <div>Entity File</div>\n </div>\n\n <div mat-dialog-content fxLayout=\"column\" fxLayoutAlign.=\"start\">\n <ng-container *ngIf=\"!hideTitleAndDetails\">\n <mat-form-field>\n <input type=\"text\" matInput formControlName=\"title\" placeholder=\"Title\" autocomplete=\"off\">\n </mat-form-field>\n <mat-form-field>\n <textarea matInput formControlName=\"details\" placeholder=\"Details\" autocomplete=\"off\"></textarea>\n </mat-form-field>\n </ng-container>\n\n <ng-template #fileUpload>\n <section fxFlex=\"100%\">\n <div>Entity File*</div>\n <app-file-dropper [config]=\"fileConfig\" (fileChanged)=\"fileChanged($event)\" [fileArray]=\"fileList\">\n </app-file-dropper>\n <div class=\"text-danger\" *ngIf=\"isFieldValid('url')\">\n {{getErrorMessage(\"url\")}}\n </div>\n </section>\n </ng-template>\n\n\n <div fxFlex=\"100%\" class=\"mt-2\" *ngIf=\"entityFileGroup.get('url').value;else fileUpload;\">\n <app-document-viewer [file]=\"entityFileGroup.get('file').value\"\n [fileUrl]=\"entityFileGroup.get('url').value\" [config]=\"this.viewerConfig\" (remove)=\"removeFile()\"\n [disableEdit]=\"updateMode\">\n </app-document-viewer>\n\n </div>\n\n <div class=\"mt-4 mb-2\" fxLayout=\"row\" fxLayoutGap=\"30px\" fxLayoutAlign=\"end\" fxFlex=\"100%\">\n <button mat-raised-button type=\"button\" (click)=\"dialogRef.close()\">\n Cancel\n </button>\n <button mat-raised-button type=\"submit\" color=\"primary\">Save</button>\n </div>\n </div>\n </div>\n</form>",
1225
+ template: "<form [formGroup]=\"entityFileGroup\" (ngSubmit)=\"submit()\">\n <div fxLayout=\"column\" class=\"mat-typography\">\n <div mat-dialog-title class=\"text-center\">\n <div>Entity File</div>\n </div>\n <div mat-dialog-content fxLayout=\"column\" fxLayoutAlign.=\"start\">\n <ng-container *ngIf=\"!hideTitleAndDetails\">\n <mat-form-field>\n <input type=\"text\" matInput formControlName=\"title\" placeholder=\"Title\" autocomplete=\"off\">\n </mat-form-field>\n <mat-form-field>\n <textarea matInput formControlName=\"details\" placeholder=\"Details\" autocomplete=\"off\"></textarea>\n </mat-form-field>\n </ng-container>\n <ng-template #fileUpload>\n <section fxFlex=\"100%\">\n <div>Entity File*</div>\n <app-file-dropper [config]=\"fileConfig\" (fileChanged)=\"fileChanged($event)\" [fileArray]=\"fileList\">\n </app-file-dropper>\n <div class=\"text-danger\" *ngIf=\"isFieldValid('url')\">\n {{getErrorMessage(\"url\")}}\n </div>\n </section>\n </ng-template>\n <div fxFlex=\"100%\" class=\"mt-2\" *ngIf=\"entityFileGroup.get('url').value;else fileUpload;\">\n <app-document-viewer [file]=\"entityFileGroup.get('file').value\" [fileUrl]=\"entityFileGroup.get('url').value\"\n [config]=\"this.viewerConfig\" (remove)=\"removeFile()\" [disableEdit]=\"updateMode\">\n </app-document-viewer>\n </div>\n <div class=\"mt-4 mb-2\" fxLayout=\"row\" fxLayoutGap=\"30px\" fxLayoutAlign=\"end\" fxFlex=\"100%\">\n <button mat-raised-button type=\"button\" (click)=\"dialogRef.close()\">\n Cancel\n </button>\n <button mat-raised-button type=\"submit\" color=\"primary\">Save</button>\n </div>\n </div>\n </div>\n</form>\n",
1216
1226
  styles: [""]
1217
1227
  },] }
1218
1228
  ];
@@ -1232,16 +1242,36 @@ let EntityFilesViewAllComponent = class EntityFilesViewAllComponent {
1232
1242
  this.alertService = alertService;
1233
1243
  this.dialog = dialog;
1234
1244
  this.viewOnly = false;
1245
+ this.title = "File";
1235
1246
  this.filters = {};
1236
1247
  this.entityFiles = [];
1237
- this.displayedColumns = ['index', 'title', 'details', 'file',];
1248
+ this.displayedColumns = [
1249
+ 'index',
1250
+ 'title',
1251
+ 'details',
1252
+ 'file_size',
1253
+ 'uploaded_on',
1254
+ ];
1238
1255
  this.isWorking = false;
1239
1256
  this.search = new FormControl('');
1240
1257
  this.page = 1;
1241
1258
  this.perPage = 25;
1242
1259
  this.lastPage = 0;
1260
+ this.fileList = [];
1243
1261
  }
1244
1262
  ngOnInit() {
1263
+ //File dropper config
1264
+ this.fileConfig = {
1265
+ fileId: "entityDashboardDropper",
1266
+ containerId: "entityDashboardDropperContainer",
1267
+ styles: {
1268
+ height: "500px"
1269
+ },
1270
+ multiple: false,
1271
+ acceptFile: "*",
1272
+ maxSize: 10,
1273
+ acceptFileText: "All Files"
1274
+ };
1245
1275
  this.viewerConfig = {
1246
1276
  imageStyle: {
1247
1277
  height: '200px',
@@ -1273,6 +1303,7 @@ let EntityFilesViewAllComponent = class EntityFilesViewAllComponent {
1273
1303
  fetchEntityFilesDetails() {
1274
1304
  return __awaiter(this, void 0, void 0, function* () {
1275
1305
  this.filters.page = this.page;
1306
+ this.filters.perPage = this.perPage;
1276
1307
  this.isWorking = true;
1277
1308
  const result = yield this.entityFileService.getEntityFiles(this.filters);
1278
1309
  this.lastPage = result.last_page || this.page;
@@ -1348,11 +1379,32 @@ let EntityFilesViewAllComponent = class EntityFilesViewAllComponent {
1348
1379
  resetFieldValue() {
1349
1380
  this.search.setValue("");
1350
1381
  }
1382
+ sizeOf(bytes) {
1383
+ if (!bytes) {
1384
+ return "0.00 B";
1385
+ }
1386
+ var e = Math.floor(Math.log(bytes) / Math.log(1024));
1387
+ return (bytes / Math.pow(1024, e)).toFixed(2) + ' ' + ' KMGTP'.charAt(e) + 'B';
1388
+ }
1389
+ fileChanged(event) {
1390
+ return __awaiter(this, void 0, void 0, function* () {
1391
+ this.fileList = event;
1392
+ if (this.fileList.length > 0) {
1393
+ const result = yield this.entityFileService.uploadEntityFile(this.fileList[0], {
1394
+ entity_type: this.entityType,
1395
+ entity_id: this.entityId,
1396
+ });
1397
+ this.fileList = [];
1398
+ this.alertService.addAlert('Successfull uploaded', 'success');
1399
+ this.reload();
1400
+ }
1401
+ });
1402
+ }
1351
1403
  };
1352
1404
  EntityFilesViewAllComponent.decorators = [
1353
1405
  { type: Component, args: [{
1354
1406
  selector: 'app-entity-files-view-all',
1355
- template: "<div fxLayout=\"column\" fxLayoutGap=\"1rem\" class=\"mat-typography p-4\" *ngIf=\"!displayMode\">\n <div fxLayout=\"column\" fxLayoutGap=\"0.25rem\">\n <h3 class=\"font-weight-bold\" fxLayoutAlign=\"center center\"> Files\n <button type=\"button\" class=\"mx-1\" mat-mini-fab color=\"primary\" (click)=\"addEntityFile()\" *ngIf=\"!viewOnly\">\n <mat-icon>add</mat-icon>\n </button>\n </h3>\n <div fxLayout=\"row wrap\" fxLayoutAlign=\"start\" *ngIf=\"!removeSearch\">\n <mat-form-field class=\"mt-1\">\n <input type=\"text\" matInput [formControl]=\"search\" placeholder=\"Title\" name=\"title\"\n autocomplete=\"off\" />\n <button mat-button *ngIf=\"filters.title\" matSuffix mat-icon-button (click)=\"resetFieldValue()\">\n <mat-icon>close</mat-icon>\n </button>\n </mat-form-field>\n </div>\n <table mat-table [dataSource]=\"entityFiles\" class=\"w-100\" matSort multiTemplateDataRows\n infiniteScrollContainer=\"body\" infiniteScroll [infiniteScrollDistance]=\"1.5\" [infiniteScrollThrottle]=\"50\"\n [fromRoot]=\"true\" (scrolled)=\"onScroll()\">\n\n <!-- Index Column -->\n <ng-container matColumnDef=\"index\">\n <th mat-header-cell *matHeaderCellDef> # </th>\n <td mat-cell *matCellDef=\"let element; let i = dataIndex\"> {{ i+1 }} </td>\n </ng-container>\n\n <!-- Title Column -->\n <ng-container matColumnDef=\"title\">\n <th mat-header-cell *matHeaderCellDef> Title </th>\n <td mat-cell *matCellDef=\"let element\"> {{element.title}} </td>\n </ng-container>\n\n <!-- Details Column -->\n <ng-container matColumnDef=\"details\">\n <th mat-header-cell *matHeaderCellDef> Details </th>\n <td mat-cell *matCellDef=\"let element\"> {{element.details}} </td>\n </ng-container>\n\n <!-- File Column -->\n <ng-container matColumnDef=\"file\">\n <th mat-header-cell *matHeaderCellDef> File </th>\n <td mat-cell *matCellDef=\"let element\">\n <a href=\"{{element.url}}\" target=\"_blank\">\n <button mat-button type=\"button\">View</button>\n </a>\n </td>\n </ng-container>\n\n <!-- Actions Column -->\n <ng-container matColumnDef=\"actions\">\n <th mat-header-cell *matHeaderCellDef> Actions </th>\n <td mat-cell *matCellDef=\"let element\" style=\"min-width:110px\">\n <button type=\"button\" mat-icon-button (click)=\"editEntityFile(element)\">\n <mat-icon>edit</mat-icon>\n </button>\n <button type=\"button\" mat-icon-button (click)=\"deleteEntityFile(element)\">\n <mat-icon>delete</mat-icon>\n </button>\n </td>\n </ng-container>\n\n <tr mat-header-row *matHeaderRowDef=\"displayedColumns\"></tr>\n <tr mat-row *matRowDef=\"let row; columns: displayedColumns;\"></tr>\n </table>\n </div>\n</div>\n\n<div fxLayout=\"row wrap\" fxLayoutGap=\"1rem\" class=\"mat-typography p-4\" *ngIf=\"displayMode\">\n\n <div *ngFor=\"let efile of entityFiles\">\n <app-document-viewer [file]=\"efile.file\" [fileUrl]=\"efile.url\" [config]=\"this.viewerConfig\"\n [disableEdit]=\"true\">\n </app-document-viewer>\n <a href=\"{{efile.url}}\" target=\"_blank\">\n <button mat-button type=\"button\">View</button>\n </a>\n </div>\n\n</div>",
1407
+ template: "<div class=\"mat-typography\" *ngIf=\"!displayMode\">\n <div fxLayout=\"row\" fxLayoutGap=\"1rem\">\n <mat-card fxFlex=\"70%\">\n <mat-card-title fxLayout fxLayoutGap=\"1rem\">\n <h3 class=\"font-weight-bold primary-color\" fxLayout=\"center center\">\n <mat-icon>\n <span class=\"material-icons\">\n description\n </span>\n </mat-icon>\n {{title}}s\n </h3>\n <div>\n <button type=\"button\" class=\"mx-1\" mat-raised-button color=\"primary\" (click)=\"addEntityFile()\"\n *ngIf=\"!viewOnly\">\n <mat-icon>\n <span class=\"material-icons\">\n add_circle_outline\n </span>\n </mat-icon>\n {{title}}\n </button>\n </div>\n <mat-form-field *ngIf=\"!removeSearch\" appearance=\"outline\" style=\"font-size: 10px;\">\n <mat-label>Search</mat-label>\n <input type=\"text\" matInput [formControl]=\"search\" placeholder=\"Search\" name=\"title\" autocomplete=\"off\" />\n <button mat-button *ngIf=\"filters.title\" matSuffix mat-icon-button (click)=\"resetFieldValue()\">\n <mat-icon>close</mat-icon>\n </button>\n </mat-form-field>\n </mat-card-title>\n <mat-card-content class=\"entity-file-card\">\n <table mat-table [dataSource]=\"entityFiles\" class=\"w-100\" matSort multiTemplateDataRows infiniteScroll\n [infiniteScrollDistance]=\"1.5\" [infiniteScrollThrottle]=\"50\" (scrolled)=\"onScroll()\">\n\n <!-- Index Column -->\n <ng-container matColumnDef=\"index\">\n <th mat-header-cell *matHeaderCellDef> # </th>\n <td mat-cell *matCellDef=\"let element; let i = dataIndex\"> {{ i+1 }} </td>\n </ng-container>\n\n <!-- Title Column -->\n <ng-container matColumnDef=\"title\">\n <th mat-header-cell *matHeaderCellDef> Title </th>\n <td mat-cell *matCellDef=\"let element\">\n <div>\n <span>\n {{element.title}}\n </span>\n <span>\n <a href=\"{{element.url}}\" target=\"_blank\" class=\"text-decoration-none text-muted\">\n <button mat-icon-button type=\"button\">\n <mat-icon>download</mat-icon>\n </button>\n </a>\n </span>\n </div>\n </td>\n </ng-container>\n\n <!-- Details Column -->\n <ng-container matColumnDef=\"details\">\n <th mat-header-cell *matHeaderCellDef> Details </th>\n <td mat-cell *matCellDef=\"let element\"> {{element.details}} </td>\n </ng-container>\n\n <!-- File size Column -->\n <ng-container matColumnDef=\"file_size\">\n <th mat-header-cell *matHeaderCellDef> File Size </th>\n <td mat-cell *matCellDef=\"let element\"> {{ sizeOf(element.file_size)}} </td>\n </ng-container>\n\n <!-- Uploaded On Column -->\n <ng-container matColumnDef=\"uploaded_on\">\n <th mat-header-cell *matHeaderCellDef> Uploaded On </th>\n <td mat-cell *matCellDef=\"let element\">\n <div>\n {{element.created_at | date: 'mediumDate'}}\n </div>\n <div class=\"text-muted\">\n By {{element.creator?.name}}\n </div>\n </td>\n </ng-container>\n\n <!-- Actions Column -->\n <ng-container matColumnDef=\"actions\">\n <th mat-header-cell *matHeaderCellDef> Actions </th>\n <td mat-cell *matCellDef=\"let element\" style=\"min-width:110px\" class=\"text-muted\">\n <button type=\"button\" mat-icon-button (click)=\"editEntityFile(element)\">\n <mat-icon>edit</mat-icon>\n </button>\n <button type=\"button\" mat-icon-button (click)=\"deleteEntityFile(element)\">\n <mat-icon>delete</mat-icon>\n </button>\n </td>\n </ng-container>\n\n <tr mat-header-row *matHeaderRowDef=\"displayedColumns\"></tr>\n <tr mat-row *matRowDef=\"let row; columns: displayedColumns;\"></tr>\n </table>\n </mat-card-content>\n </mat-card>\n <section fxFlex=\"30%\">\n <app-file-dropper [config]=\"fileConfig\" (fileChanged)=\"fileChanged($event)\" [fileArray]=\"fileList\">\n </app-file-dropper>\n </section>\n </div>\n</div>\n\n<div fxLayout=\"row wrap\" fxLayoutGap=\"1rem\" class=\"mat-typography p-4\" *ngIf=\"displayMode\">\n <div *ngFor=\"let efile of entityFiles\">\n <app-document-viewer [file]=\"efile.file\" [fileUrl]=\"efile.url\" [config]=\"this.viewerConfig\" [disableEdit]=\"true\">\n </app-document-viewer>\n <a href=\"{{efile.url}}\" target=\"_blank\">\n <button mat-button type=\"button\">View</button>\n </a>\n </div>\n</div>\n",
1356
1408
  styles: [""]
1357
1409
  },] }
1358
1410
  ];
@@ -1368,7 +1420,8 @@ EntityFilesViewAllComponent.propDecorators = {
1368
1420
  viewOnly: [{ type: Input }],
1369
1421
  removeSearch: [{ type: Input }],
1370
1422
  hideTitleAndDetails: [{ type: Input }],
1371
- displayMode: [{ type: Input }]
1423
+ displayMode: [{ type: Input }],
1424
+ title: [{ type: Input }]
1372
1425
  };
1373
1426
  EntityFilesViewAllComponent = __decorate([
1374
1427
  UntilDestroy()