mmhglobal-dynamicform 2.26.0 → 2.28.0

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.
@@ -7,7 +7,7 @@ import { NavigationStart, NavigationEnd, NavigationError, RouterModule } from '@
7
7
  import { BehaviorSubject, forkJoin, of, tap as tap$1, map as map$1, first, isObservable, switchMap as switchMap$1, interval, takeWhile, from, Subject, delay as delay$1, filter, auditTime } from 'rxjs';
8
8
  import { tap, switchMap, map, take, delay, concatMap, ignoreElements } from 'rxjs/operators';
9
9
  import * as i2 from 'mmhglobal-zcore';
10
- import { ZGroup, FormType, ZComponentHelper, MESSAGETYPE, ActionType, DefaultMessage, DefaultDialogTitle, Delimiter, ZSelectPostApiParams, ComponentType as ComponentType$1, ZComponentProperties, SignalType, DropdownSearchOperator, InternalComponentType_DropDown, UploadMetaData, AttachmentConfig, DefaultPageSettingParams, ZCoreModule } from 'mmhglobal-zcore';
10
+ import { ZGroup, FormType, ZComponentHelper, MESSAGETYPE, ActionType, DefaultMessage, DefaultDialogTitle, TriggerFromType, Delimiter, ZSelectPostApiParams, ComponentType as ComponentType$1, ZComponentProperties, SignalType, DropdownSearchOperator, InternalComponentType_DropDown, UploadMetaData, AttachmentConfig, DefaultPageSettingParams, ZCoreModule } from 'mmhglobal-zcore';
11
11
  import * as i2$1 from '@ionic/angular';
12
12
  import { IonicModule } from '@ionic/angular';
13
13
  import * as i3 from 'mmhglobal-zmodal';
@@ -833,8 +833,8 @@ class MainService {
833
833
  getResourceServerData() {
834
834
  return this.resourceApiService.loadData();
835
835
  }
836
- getGroupFields(fieldElementName, formType, group, propertyName) {
837
- return this.fieldService.getFormFieldCode(fieldElementName, formType, group, propertyName);
836
+ getGroupFields(fieldElementName, formType, triggerFrom, group, propertyName) {
837
+ return this.fieldService.getFormFieldCode(fieldElementName, formType, group, propertyName, triggerFrom);
838
838
  }
839
839
  initializeGroup(group, ctrlName, pageName, me) {
840
840
  if (me.subscription) {
@@ -844,7 +844,7 @@ class MainService {
844
844
  group.resourceURLName = resourceName;
845
845
  Object.assign(group, {
846
846
  resourceURL: this.resourceApiService.getURL(resourceName),
847
- gridColumnFields: this.fieldService.getFormFieldCode(ctrlName, "FormField", null, null),
847
+ gridColumnFields: this.fieldService.getFormFieldCode(ctrlName, "FormField"),
848
848
  ctrlScope: me,
849
849
  pageName,
850
850
  ctrlName,
@@ -884,23 +884,12 @@ class MainService {
884
884
  me.subscription = group.subject.subscribe((event) => this.subjectEvent(event, group, me));
885
885
  return me.subscription;
886
886
  }
887
- getModel$(group, id) {
887
+ getModel$(group, id, triggerFrom) {
888
888
  const recId = id || group.referenceId;
889
889
  return this.webApiService
890
- .httpGet$(group.resourceURL + "/" + recId, null)
890
+ .httpGet$(`${group.resourceURL}/${recId}`, null, { triggerFrom: triggerFrom })
891
891
  .pipe(tap((zmodel) => {
892
892
  group.zModel = zmodel;
893
- //if (
894
- // group.parentReferenceField &&
895
- // Object.keys(zmodel).indexOf(group.parentReferenceField) !== -1 &&
896
- // !group.backNavigationPage.endsWith(".edit")
897
- //) {
898
- // group.backNavigationPage =
899
- // group.backNavigationPage +
900
- // "/" +
901
- // zmodel[group.parentReferenceField].toString() +
902
- // "/edit";
903
- //}
904
893
  }), switchMap(() => {
905
894
  if (group.afterGetModelSuccess) {
906
895
  return this.afterGetModelSuccess(group);
@@ -1373,7 +1362,7 @@ class MainService {
1373
1362
  }), switchMap(() => {
1374
1363
  const newModel = Object.assign({}, group.zModel);
1375
1364
  ZComponentHelper.removeNullFields(newModel);
1376
- return this.webApiService.httpPost$(group.resourceURL, newModel).pipe(tap((resp) => {
1365
+ return this.webApiService.httpPost$(group.resourceURL, newModel, { buttonDetail: event, group: group, triggerFrom: event.triggerFrom }).pipe(tap((resp) => {
1377
1366
  createModelres = resp;
1378
1367
  return resp;
1379
1368
  }), tap((res) => {
@@ -1419,7 +1408,7 @@ class MainService {
1419
1408
  }
1420
1409
  return of(false);
1421
1410
  }
1422
- updateAPIObservable = updateAPIObservable || this.webApiService.httpPut$(`${group.resourceURL}/${group.zModel.Id}`, group.zModel, false).pipe(tap((res) => {
1411
+ updateAPIObservable = updateAPIObservable || this.webApiService.httpPut$(`${group.resourceURL}/${group.zModel.Id}`, group.zModel, { buttonDetail: event, group: group, triggerFrom: event.triggerFrom }).pipe(tap((res) => {
1423
1412
  this.handleSuccess(res, resMessage);
1424
1413
  }
1425
1414
  //this.handleSuccess(res, "Record is updated successfully.")
@@ -1510,7 +1499,7 @@ class MainService {
1510
1499
  group.zModel.Disabled = true;
1511
1500
  let tempResponse = {};
1512
1501
  return this.webApiService
1513
- .httpPut$(group.resourceURL + "/" + group.zModel.Id, group.zModel)
1502
+ .httpPut$(`${group.resourceURL}/${group.zModel.Id}`, group.zModel, { buttonDetail: event, group: group, triggerFrom: event.triggerFrom })
1514
1503
  .pipe(tap((res) => {
1515
1504
  tempResponse = Object.assign({}, res);
1516
1505
  this.handleSuccess(res, resMessage);
@@ -1807,7 +1796,7 @@ class MainService {
1807
1796
  if (formId === ((_a = respResult.Id) === null || _a === void 0 ? void 0 : _a.toString()) && eventName === window.location.href) {
1808
1797
  if (respResult.UserName === this.authService.e1Token.myProfile.UserName) {
1809
1798
  if (respResult.Action === ActionType.Update) {
1810
- this.webApiService.httpGet$(`${this.group.resourceURL}/${formId}`, null).subscribe(resp => {
1799
+ this.webApiService.httpGet$(`${this.group.resourceURL}/${formId}`, null, { triggerFrom: TriggerFromType.signalRAlert }).subscribe(resp => {
1811
1800
  this.reloadDataAndWorkflowButton(resp);
1812
1801
  });
1813
1802
  }
@@ -4029,7 +4018,7 @@ class UipageComponent {
4029
4018
  const fieldElementName = this.group.fieldName ? this.group.fieldName : ctrlName;
4030
4019
  this.group.fieldName = fieldElementName; // to be decprecated
4031
4020
  this.group.fieldElementName = fieldElementName;
4032
- return this.mainService.getGroupFields(fieldElementName, formType, this.group, "fields");
4021
+ return this.mainService.getGroupFields(fieldElementName, formType, TriggerFromType.initialPageLoad, this.group, "fields");
4033
4022
  //let formFieldName = this.group.fieldName ? this.group.fieldName : ctrlName;
4034
4023
  //this.group.fieldName = formFieldName;
4035
4024
  //if(UipageComponent.signalrEventSubscription){
@@ -4074,7 +4063,7 @@ class UipageComponent {
4074
4063
  return this.group.getModel(this.group, this.group.referenceId);
4075
4064
  }
4076
4065
  else {
4077
- return this.mainService.getModel$(this.group, this.group.referenceId);
4066
+ return this.mainService.getModel$(this.group, this.group.referenceId, TriggerFromType.initialPageLoad);
4078
4067
  }
4079
4068
  }
4080
4069
  else {
@@ -5330,7 +5319,7 @@ class ZbuttonsComponent extends ButtonFieldBase {
5330
5319
  this.componentService.decrementComponentCounterForField(this.data);
5331
5320
  }
5332
5321
  loadButton() {
5333
- const field$ = this.fieldService.getFormFieldCode(this.data.Value, "FormField", null, null);
5322
+ const field$ = this.fieldService.getFormFieldCode(this.data.Value, "FormField");
5334
5323
  this.group.zButtonsCount++;
5335
5324
  if (this.group.zButtonsCount === 1) {
5336
5325
  this.FirstZbtn = true;
@@ -5381,6 +5370,7 @@ class ZbuttonsComponent extends ButtonFieldBase {
5381
5370
  SubType: this.data.SubType,
5382
5371
  Type: button.Type,
5383
5372
  buttonData: button,
5373
+ eventId: ZComponentHelper.generateTimeStampId()
5384
5374
  };
5385
5375
  }
5386
5376
  if (button['PositionX'] && button['PositionX'] === "right") {
@@ -5405,7 +5395,8 @@ class ZbuttonsComponent extends ButtonFieldBase {
5405
5395
  this.group.subject.next({
5406
5396
  type: "buttonClick",
5407
5397
  target: item.clickEvent,
5408
- data: item
5398
+ data: item,
5399
+ triggerFrom: TriggerFromType.button
5409
5400
  });
5410
5401
  }
5411
5402
  getButtonDisableTriggerValue(data, button) {
@@ -6884,13 +6875,13 @@ class ZworkflowbuttonsComponent extends ButtonFieldBase {
6884
6875
  if (this.group.resourceURL) {
6885
6876
  this.isLocalHostAPI = this.group.resourceURL.toLowerCase().includes("localhost") ? true : false;
6886
6877
  }
6887
- this.loadButton();
6878
+ this.loadButton(TriggerFromType.initialPageLoad);
6888
6879
  });
6889
6880
  }
6890
6881
  ngAfterViewInit() {
6891
6882
  this.componentService.decrementComponentCounterForField(this.data);
6892
6883
  }
6893
- loadButton() {
6884
+ loadButton(triggerFrom) {
6894
6885
  var _a;
6895
6886
  this.leftBtns = [];
6896
6887
  this.rightBtns = [];
@@ -6905,7 +6896,7 @@ class ZworkflowbuttonsComponent extends ButtonFieldBase {
6905
6896
  try {
6906
6897
  of(true).pipe(concatMap(() => {
6907
6898
  // retrieve the workflow button
6908
- return this.workflowService.getWorkflowButtonsField(this.data.WorkflowCode, this.e1wfs_wfcGetWorkflowButtonURL, String(this.isLocalHostAPI));
6899
+ return this.workflowService.getWorkflowButtonsField(this.data.WorkflowCode, this.e1wfs_wfcGetWorkflowButtonURL, String(this.isLocalHostAPI), triggerFrom);
6909
6900
  }), tap(resultData => {
6910
6901
  if (resultData) {
6911
6902
  resultData.forEach((button) => {
@@ -6941,7 +6932,7 @@ class ZworkflowbuttonsComponent extends ButtonFieldBase {
6941
6932
  this.items.push(...this.leftBtns, ...this.rightBtns);
6942
6933
  }
6943
6934
  else {
6944
- console.warn('Unable to get workflow button. Data returned null.');
6935
+ console.warn(`Unable to get workflow button. Data returned null.`);
6945
6936
  }
6946
6937
  }), switchMap(() => {
6947
6938
  return super.translateButtonsLabel(this.items);
@@ -6988,19 +6979,6 @@ class ZworkflowbuttonsComponent extends ButtonFieldBase {
6988
6979
  const formGroup = this.group.form;
6989
6980
  const attributes = JSON.parse(button.Attributes);
6990
6981
  const buttonTypeCode = button.TypeCode.toUpperCase();
6991
- //// Skip if the button's click event includes backnavigation
6992
- //if (buttonTypeCode === 'GOTO') {
6993
- // // Check if the form has unsaved changes
6994
- // if (!this.data.SkipCheckFormDirty && !formGroup.dirty) {
6995
- // console.warn(`Record not saved because the form is not dirty.`);
6996
- // return;
6997
- // }
6998
- // // Check if the form is valid
6999
- // if (this.data.UseDefaultValidate && !formGroup.valid) {
7000
- // this.componentErrorHandlerService.showFormGroupErrorMessage(this.group, formGroup);
7001
- // return;
7002
- // }
7003
- //}
7004
6982
  // Type 1 == functional;
7005
6983
  // Type 2 == GOTO;
7006
6984
  this.group.isTriggered = button.disableTrigger != undefined ? !button.disableTrigger : true;
@@ -7010,11 +6988,10 @@ class ZworkflowbuttonsComponent extends ButtonFieldBase {
7010
6988
  if (!this.group.isTriggered) {
7011
6989
  return;
7012
6990
  }
7013
- const group = this.group;
7014
6991
  // Disable trigger timer
7015
6992
  if (!attributes['DisableTriggerTimer']) {
7016
6993
  setTimeout(function () {
7017
- group['isTriggered'] = false;
6994
+ this.group['isTriggered'] = false;
7018
6995
  }, 500);
7019
6996
  }
7020
6997
  console.log("Functional Button: ", button.Name);
@@ -7026,7 +7003,7 @@ class ZworkflowbuttonsComponent extends ButtonFieldBase {
7026
7003
  // Call the workflow service to handle the GOTO button click event
7027
7004
  this.workflowService.gotoButton_Onclick(button, this.data, attributes, this.group, this.isLocalHostAPI).subscribe(res => {
7028
7005
  // Reload the button
7029
- this.loadButton();
7006
+ this.loadButton(TriggerFromType.goToButton);
7030
7007
  // Reset trigger status
7031
7008
  this.group.isTriggered = false;
7032
7009
  if (res) {
@@ -7043,7 +7020,7 @@ class ZworkflowbuttonsComponent extends ButtonFieldBase {
7043
7020
  appendToAttributeUsefulDetail(button) {
7044
7021
  const attributes = JSON.parse(button.Attributes);
7045
7022
  const newAttributes = Object.assign(Object.assign({}, attributes), { zButtonName: this.data.Name, TypeCode: button.TypeCode, WorkflowCode: this.data.WorkflowCode });
7046
- const newButton = Object.assign(Object.assign({}, button), { Attributes: JSON.stringify(newAttributes), disableTrigger: this.isButtonDisableTrigger(this.data, button) });
7023
+ const newButton = Object.assign(Object.assign({}, button), { eventId: ZComponentHelper.generateTimeStampId(), Attributes: JSON.stringify(newAttributes), disableTrigger: this.isButtonDisableTrigger(this.data, button) });
7047
7024
  return newButton;
7048
7025
  }
7049
7026
  isButtonDisableTrigger(data, button) {
@@ -7239,6 +7216,7 @@ class ZselectmultipleComponent extends InputFieldBase {
7239
7216
  this.itemDataField = null;
7240
7217
  this.itemTemplate = "{{item[itemTextField]}}";
7241
7218
  this.infiniteScrollPageNo = 0;
7219
+ this.infiniteDataLoaded = false;
7242
7220
  this.isLoading = true;
7243
7221
  this.allowCustomValue = false;
7244
7222
  this.autoClose = true;
@@ -7457,6 +7435,8 @@ class ZselectmultipleComponent extends InputFieldBase {
7457
7435
  this.infiniteScrollPageNo = 0;
7458
7436
  this.modelzData = [];
7459
7437
  }
7438
+ this.infiniteDataLoaded = false;
7439
+ ZComponentHelper.cancelGetInfiniteData;
7460
7440
  this.getInfiniteData(event);
7461
7441
  }
7462
7442
  else {
@@ -7555,7 +7535,10 @@ class ZselectmultipleComponent extends InputFieldBase {
7555
7535
  }
7556
7536
  handleOpen(event) {
7557
7537
  if (this.data.HasInfiniteScroll) {
7558
- this.handleFilter(null);
7538
+ if (!this.infiniteDataLoaded) {
7539
+ this.infiniteDataLoaded = true;
7540
+ this.handleFilter(null);
7541
+ }
7559
7542
  }
7560
7543
  // Ensure multiselect value meets the search length requirement
7561
7544
  if (this.multiselect && this.data.SearchLength && this.multiselect.value.length < this.data.SearchLength) {
@@ -8272,7 +8255,7 @@ class ZuploadComponent extends InputFieldBase {
8272
8255
  // DivClass: "col-md-12 col-md-6",
8273
8256
  // Visible: true
8274
8257
  // }];
8275
- constructor(componentService, authService, compressImage, zcoreService, ngZone, sharePointService) {
8258
+ constructor(componentService, authService, compressImage, zcoreService, ngZone, sharePointService, alertService) {
8276
8259
  super(componentService);
8277
8260
  this.componentService = componentService;
8278
8261
  this.authService = authService;
@@ -8280,6 +8263,7 @@ class ZuploadComponent extends InputFieldBase {
8280
8263
  this.zcoreService = zcoreService;
8281
8264
  this.ngZone = ngZone;
8282
8265
  this.sharePointService = sharePointService;
8266
+ this.alertService = alertService;
8283
8267
  this.uploadAttachmentUrl = null;
8284
8268
  this.uploadSaveUrl = "/Attachment/Chunk_Upload_Save"; // should represent an actual API endpoint
8285
8269
  this.uploadRemoveUrl = "/Attachment/Chunk_Upload_Remove"; // should represent an actual API endpoint
@@ -8340,6 +8324,9 @@ class ZuploadComponent extends InputFieldBase {
8340
8324
  if (this.data.Multiple) {
8341
8325
  this.isMultiple = this.data.Multiple;
8342
8326
  }
8327
+ if (this.data.AllowedFileExtension) {
8328
+ this.restrictions.allowedExtensions = this.restrictions.allowedExtensions.concat(this.data.AllowedFileExtension);
8329
+ }
8343
8330
  this.componentProperties.style.style6 = this.componentProperties.style.style6 || "margin: 5px; border: 1px solid gray;";
8344
8331
  }
8345
8332
  onSuccess(e) {
@@ -8435,18 +8422,24 @@ class ZuploadComponent extends InputFieldBase {
8435
8422
  // Image Preview
8436
8423
  const me = this;
8437
8424
  e.files.forEach((file) => {
8438
- if (file.rawFile && file.rawFile.type.includes("image")) {
8439
- if (!file.validationErrors) {
8440
- const reader = new FileReader();
8441
- reader.onload = function (ev) {
8442
- if (me.data.EnableImagePreview) {
8443
- if (!me.uid.includes(file.uid)) {
8444
- me.uid.push(file.uid);
8445
- me.imagePreviews.push(Object.assign(Object.assign({}, file), { src: reader.result }));
8425
+ if (!me.isValidUploadedFile(me, file)) {
8426
+ e.preventDefault();
8427
+ return;
8428
+ }
8429
+ else {
8430
+ if (file.rawFile && file.rawFile.type.includes("image")) {
8431
+ if (!file.validationErrors) {
8432
+ const reader = new FileReader();
8433
+ reader.onload = function (ev) {
8434
+ if (me.data.EnableImagePreview) {
8435
+ if (!me.uid.includes(file.uid)) {
8436
+ me.uid.push(file.uid);
8437
+ me.imagePreviews.push(Object.assign(Object.assign({}, file), { src: reader.result }));
8438
+ }
8446
8439
  }
8447
- }
8448
- };
8449
- reader.readAsDataURL(file.rawFile);
8440
+ };
8441
+ reader.readAsDataURL(file.rawFile);
8442
+ }
8450
8443
  }
8451
8444
  }
8452
8445
  });
@@ -8510,38 +8503,60 @@ class ZuploadComponent extends InputFieldBase {
8510
8503
  });
8511
8504
  }
8512
8505
  }
8506
+ isValidUploadedFile(me, file) {
8507
+ const fileSize = file.rawFile.size;
8508
+ const fileExtension = file.rawFile.name.split('.').pop().toLowerCase();
8509
+ // Check if file size and extension are valid
8510
+ if (fileSize > me.restrictions.maxFileSize || !me.restrictions.allowedExtensions.includes(fileExtension)) {
8511
+ let errorMessage = 'Error: ';
8512
+ if (!me.restrictions.allowedExtensions.includes(fileExtension)) {
8513
+ errorMessage = `Invalid file type. Allowed types are: ${me.restrictions.allowedExtensions.join(', ')}.`;
8514
+ }
8515
+ else if (fileSize > me.restrictions.maxFileSize) {
8516
+ errorMessage = `File size cannot exceeds ${me.formatFileSize(me.restrictions.maxFileSize)}.`;
8517
+ }
8518
+ me.alertService.showOkay('Failed to upload', errorMessage, ['col-4']);
8519
+ return false;
8520
+ }
8521
+ return true;
8522
+ }
8513
8523
  selectEventHandler(e) {
8514
8524
  const me = this;
8515
- /****** sharepoint ******/
8525
+ //#region sharepoint
8516
8526
  const attachmentInfo = this.sharePointService.getAttachmentInfo(this.data["DownloadFileConfig"]);
8517
- //change uploadSaveUrl
8527
+ // Change uploadSaveUrl if saving to SharePoint
8518
8528
  if (attachmentInfo && attachmentInfo.isSaveToSharePoint && attachmentInfo.siteName) {
8519
8529
  const attachmentSourceUrl = this.zcoreService.getEnvironment().attachmentSourceUrl;
8520
8530
  this.uploadSaveUrl = attachmentSourceUrl + '/Chunk_Upload_Save';
8521
8531
  }
8522
- /****** sharepoint ******/
8532
+ //#endregion
8523
8533
  if (this.data['SelectFileOnly']) {
8524
- // append all file to component memory
8534
+ // Append all files to component memory
8525
8535
  e.files.forEach((file) => __awaiter(this, void 0, void 0, function* () {
8526
- if (file.rawFile) {
8527
- const reader = new FileReader();
8528
- reader.onload = function (ev) {
8529
- // clone the data and also add the readed file to the object
8530
- const fileData = Object.assign({}, file);
8531
- fileData['file'] = ev.target["result"];
8532
- // push to component fileList
8533
- me.fileList.push(fileData);
8534
- me.group['zupload_' + me.data.Value] = me.fileList;
8535
- if (me.data['FileSelectedEvent']) {
8536
- // call the project event
8537
- me.group.subject.next({
8538
- type: "zupload-fileSelectedEvent",
8539
- target: me.data['FileSelectedEvent'],
8540
- data: me.fileList
8541
- });
8542
- }
8543
- };
8544
- yield reader.readAsDataURL(file.rawFile);
8536
+ if (me.isValidUploadedFile(me, file)) {
8537
+ if (file.rawFile) {
8538
+ const reader = new FileReader();
8539
+ reader.onload = function (ev) {
8540
+ // Clone the data and also add the read file to the object
8541
+ const fileData = Object.assign({}, file);
8542
+ fileData['file'] = ev.target["result"];
8543
+ // Push to component fileList
8544
+ me.fileList.push(fileData);
8545
+ me.group['zupload_' + me.data.Value] = me.fileList;
8546
+ if (me.data['FileSelectedEvent']) {
8547
+ // Call the project event
8548
+ me.group.subject.next({
8549
+ type: "zupload-fileSelectedEvent",
8550
+ target: me.data['FileSelectedEvent'],
8551
+ data: me.fileList
8552
+ });
8553
+ }
8554
+ };
8555
+ yield reader.readAsDataURL(file.rawFile);
8556
+ }
8557
+ }
8558
+ else {
8559
+ e.preventDefault();
8545
8560
  }
8546
8561
  }));
8547
8562
  }
@@ -8553,29 +8568,32 @@ class ZuploadComponent extends InputFieldBase {
8553
8568
  //Check if Image Compression is enabled.
8554
8569
  if (imageCompressionEnabled === true) {
8555
8570
  e.files.forEach((file) => {
8556
- // Compress only if it is an image file
8557
- if (file.rawFile && file.rawFile.type.includes("image")) {
8558
- if (!file.validationErrors) {
8559
- const imgConfig = this.compressionConfigHandler(this.data.Compression);
8560
- if (file.size > imgConfig.FileSizeMinSizeByte) {
8561
- me.compressImage.compress(file.rawFile, imgConfig) //Pass in parameter to set the Compression Options
8562
- .pipe(take(1))
8563
- .subscribe(compressFile => {
8564
- this.ngZone.run(() => {
8565
- file.rawFile = compressFile;
8566
- file.size = compressFile.size;
8567
- // clone the data and also add the readed file to the object
8568
- const fileData = Object.assign({}, file);
8569
- // push to component fileList
8570
- me.fileList.push(fileData);
8571
- const reader = new FileReader();
8572
- reader.readAsDataURL(file.rawFile);
8571
+ if (me.isValidUploadedFile(me, file)) {
8572
+ // Compress only if it is an image file
8573
+ if (file.rawFile && file.rawFile.type.includes("image")) {
8574
+ if (!file.validationErrors) {
8575
+ const imgConfig = this.compressionConfigHandler(this.data.Compression);
8576
+ if (file.size > imgConfig.FileSizeMinSizeByte) {
8577
+ me.compressImage.compress(file.rawFile, imgConfig) //Pass in parameter to set the Compression Options
8578
+ .pipe(take(1))
8579
+ .subscribe(compressFile => {
8580
+ this.ngZone.run(() => {
8581
+ file.rawFile = compressFile;
8582
+ file.size = compressFile.size;
8583
+ // Push to component fileList
8584
+ me.fileList.push(Object.assign({}, file));
8585
+ const reader = new FileReader();
8586
+ reader.readAsDataURL(file.rawFile);
8587
+ });
8588
+ console.log(`Compressed file size: ${(file.rawFile.size / 1024).toFixed(2)}KB`);
8573
8589
  });
8574
- console.log(`Compressed file size: ${(file.rawFile.size / 1024).toFixed(2)}KB`);
8575
- });
8576
- } // file size check
8577
- } // validationErrors check
8578
- } // file type check
8590
+ } // file size check
8591
+ } // validationErrors check
8592
+ } // file type check
8593
+ }
8594
+ else {
8595
+ e.preventDefault();
8596
+ }
8579
8597
  }); // loop each file
8580
8598
  } // imagecompression check
8581
8599
  // add to group scope
@@ -8587,13 +8605,20 @@ class ZuploadComponent extends InputFieldBase {
8587
8605
  this.uploadComponent.clearFiles();
8588
8606
  this.group['zupload_' + this.data.Value] = this.fileList;
8589
8607
  }
8608
+ formatFileSize(bytes) {
8609
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
8610
+ if (bytes === 0)
8611
+ return '0 Byte';
8612
+ const i = Math.floor(Math.log(bytes) / Math.log(1024));
8613
+ return parseFloat((bytes / Math.pow(1024, i)).toFixed(2)) + sizes[i];
8614
+ }
8590
8615
  }
8591
- ZuploadComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: ZuploadComponent, deps: [{ token: ZComponentService }, { token: i2.AuthService }, { token: i2.CompressImageService }, { token: i2.ZCoreService }, { token: i0.NgZone }, { token: i2.SharePointService }], target: i0.ɵɵFactoryTarget.Component });
8592
- ZuploadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: ZuploadComponent, selector: "app-zupload", viewQueries: [{ propertyName: "uploadComponent", first: true, predicate: ["uploadComponent"], descendants: true }], usesInheritance: true, ngImport: i0, template: "<div [formGroup]=\"form\" class=\"zupload-container e1tag-style\" [style]=\"componentProperties.style.style\">\r\n <kendo-upload #uploadComponent *ngIf=\"!data.SelectFileOnly\" [id]=\"data.Value\" [autoUpload]=\"isAutoUpload\"\r\n [saveUrl]=\"uploadSaveUrl\" [removeUrl]=\"uploadRemoveUrl\" [restrictions]=\"restrictions\"\r\n [multiple]=\"isMultiple\" [chunkable]=\"chunkSettings\" [showFileList]=\"showFileList\"\r\n (select)=\"selectEventHandler($event)\" (remove)=\"onRemove($event)\" (success)=\"onSuccess($event)\"\r\n (upload)=\"uploadEventHandler($event)\" [style]=\"componentProperties.style.style1\" class=\"e1tag-style1\">\r\n </kendo-upload>\r\n\r\n <kendo-fileselect #uploadComponent *ngIf=\"data.SelectFileOnly\" [id]=\"data.Value\" (select)=\"selectEventHandler($event)\"\r\n (remove)=\"onRemove($event)\" [formControlName]=\"data.Value\" (valueChange)=\"onChange($event)\" [restrictions]=\"restrictions\"\r\n [style]=\"componentProperties.style.style1\" class=e1tag-style1>\r\n </kendo-fileselect>\r\n\r\n <div *ngIf=\"imagePreviews.length\" class=\"image-preview-container e1tag-style2\"\r\n [style]=\"componentProperties.style.style2\">\r\n <div class=\"label-container e1tag-style3\" [style]=\"componentProperties.style.style3\">\r\n Image Preview:\r\n </div>\r\n <div class=\"image-container e1tag-style4\" [style]=\"componentProperties.style.style4\">\r\n <img *ngFor=\"let image of imagePreviews\" [src]=\"image.src\" alt=\"image preview\" height=\"100\" class=\"e1tag-style5\"\r\n [style]=\"componentProperties.style.style5\" />\r\n </div>\r\n </div>\r\n</div>\r\n", styles: [".image-preview-container{border:1px solid rgba(0,0,0,.08)}.image-preview-container>.label-container{margin:5px}\n"], components: [{ type: i3$7.UploadComponent, selector: "kendo-upload", inputs: ["autoUpload", "batch", "withCredentials", "saveField", "saveHeaders", "saveMethod", "saveUrl", "responseType", "removeField", "removeHeaders", "removeMethod", "removeUrl", "chunkable", "concurrent", "multiple", "disabled", "showFileList", "tabindex", "zoneId", "tabIndex", "accept", "restrictions", "focusableId", "actionsLayout"], outputs: ["blur", "cancel", "clear", "complete", "error", "focus", "pause", "remove", "resume", "select", "success", "upload", "uploadProgress", "valueChange"], exportAs: ["kendoUpload"] }, { type: i3$7.FileSelectComponent, selector: "kendo-fileselect", inputs: ["accept", "disabled", "multiple", "name", "showFileList", "tabindex", "restrictions", "zoneId", "focusableId"], outputs: ["blur", "focus", "select", "remove", "valueChange"], exportAs: ["kendoFileSelect"] }], directives: [{ type: i4$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i4$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i4$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i4$1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { type: i5.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }] });
8616
+ ZuploadComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: ZuploadComponent, deps: [{ token: ZComponentService }, { token: i2.AuthService }, { token: i2.CompressImageService }, { token: i2.ZCoreService }, { token: i0.NgZone }, { token: i2.SharePointService }, { token: i2.AlertService }], target: i0.ɵɵFactoryTarget.Component });
8617
+ ZuploadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.4.0", type: ZuploadComponent, selector: "app-zupload", viewQueries: [{ propertyName: "uploadComponent", first: true, predicate: ["uploadComponent"], descendants: true }], usesInheritance: true, ngImport: i0, template: "<div [formGroup]=\"form\" class=\"zupload-container e1tag-style\" [style]=\"componentProperties.style.style\">\r\n <kendo-upload\r\n *ngIf=\"!data.SelectFileOnly\"\r\n #uploadComponent\r\n [id]=\"data.Value\"\r\n [autoUpload]=\"isAutoUpload\"\r\n [saveUrl]=\"uploadSaveUrl\"\r\n [removeUrl]=\"uploadRemoveUrl\"\r\n [restrictions]=\"restrictions\"\r\n [multiple]=\"isMultiple\"\r\n [chunkable]=\"chunkSettings\"\r\n [showFileList]=\"showFileList\"\r\n (select)=\"selectEventHandler($event)\"\r\n (remove)=\"onRemove($event)\"\r\n (success)=\"onSuccess($event)\"\r\n (upload)=\"uploadEventHandler($event)\"\r\n [style]=\"componentProperties.style.style1\"\r\n class=\"e1tag-style1\">\r\n </kendo-upload>\r\n\r\n <kendo-fileselect\r\n *ngIf=\"data.SelectFileOnly\"\r\n #uploadComponent\r\n [id]=\"data.Value\"\r\n (select)=\"selectEventHandler($event)\"\r\n (remove)=\"onRemove($event)\"\r\n [formControlName]=\"data.Value\"\r\n (valueChange)=\"onChange($event)\" \r\n [restrictions]=\"restrictions\"\r\n [style]=\"componentProperties.style.style1\"\r\n class=\"e1tag-style1\">\r\n </kendo-fileselect>\r\n\r\n <div\r\n *ngIf=\"imagePreviews.length\"\r\n class=\"image-preview-container e1tag-style2\"\r\n [style]=\"componentProperties.style.style2\">\r\n <div\r\n class=\"label-container e1tag-style3\"\r\n [style]=\"componentProperties.style.style3\">\r\n Image Preview:\r\n </div>\r\n <div\r\n class=\"image-container e1tag-style4\"\r\n [style]=\"componentProperties.style.style4\">\r\n <img\r\n *ngFor=\"let image of imagePreviews\"\r\n [src]=\"image.src\"\r\n alt=\"image preview\"\r\n height=\"100\"\r\n class=\"e1tag-style5\"\r\n [style]=\"componentProperties.style.style5\" />\r\n </div>\r\n </div>\r\n</div>\r\n", styles: [".image-preview-container{border:1px solid rgba(0,0,0,.08)}.image-preview-container>.label-container{margin:5px}\n"], components: [{ type: i3$7.UploadComponent, selector: "kendo-upload", inputs: ["autoUpload", "batch", "withCredentials", "saveField", "saveHeaders", "saveMethod", "saveUrl", "responseType", "removeField", "removeHeaders", "removeMethod", "removeUrl", "chunkable", "concurrent", "multiple", "disabled", "showFileList", "tabindex", "zoneId", "tabIndex", "accept", "restrictions", "focusableId", "actionsLayout"], outputs: ["blur", "cancel", "clear", "complete", "error", "focus", "pause", "remove", "resume", "select", "success", "upload", "uploadProgress", "valueChange"], exportAs: ["kendoUpload"] }, { type: i3$7.FileSelectComponent, selector: "kendo-fileselect", inputs: ["accept", "disabled", "multiple", "name", "showFileList", "tabindex", "restrictions", "zoneId", "focusableId"], outputs: ["blur", "focus", "select", "remove", "valueChange"], exportAs: ["kendoFileSelect"] }], directives: [{ type: i4$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i4$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i4$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i4$1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { type: i5.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }] });
8593
8618
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: ZuploadComponent, decorators: [{
8594
8619
  type: Component,
8595
- args: [{ selector: "app-zupload", template: "<div [formGroup]=\"form\" class=\"zupload-container e1tag-style\" [style]=\"componentProperties.style.style\">\r\n <kendo-upload #uploadComponent *ngIf=\"!data.SelectFileOnly\" [id]=\"data.Value\" [autoUpload]=\"isAutoUpload\"\r\n [saveUrl]=\"uploadSaveUrl\" [removeUrl]=\"uploadRemoveUrl\" [restrictions]=\"restrictions\"\r\n [multiple]=\"isMultiple\" [chunkable]=\"chunkSettings\" [showFileList]=\"showFileList\"\r\n (select)=\"selectEventHandler($event)\" (remove)=\"onRemove($event)\" (success)=\"onSuccess($event)\"\r\n (upload)=\"uploadEventHandler($event)\" [style]=\"componentProperties.style.style1\" class=\"e1tag-style1\">\r\n </kendo-upload>\r\n\r\n <kendo-fileselect #uploadComponent *ngIf=\"data.SelectFileOnly\" [id]=\"data.Value\" (select)=\"selectEventHandler($event)\"\r\n (remove)=\"onRemove($event)\" [formControlName]=\"data.Value\" (valueChange)=\"onChange($event)\" [restrictions]=\"restrictions\"\r\n [style]=\"componentProperties.style.style1\" class=e1tag-style1>\r\n </kendo-fileselect>\r\n\r\n <div *ngIf=\"imagePreviews.length\" class=\"image-preview-container e1tag-style2\"\r\n [style]=\"componentProperties.style.style2\">\r\n <div class=\"label-container e1tag-style3\" [style]=\"componentProperties.style.style3\">\r\n Image Preview:\r\n </div>\r\n <div class=\"image-container e1tag-style4\" [style]=\"componentProperties.style.style4\">\r\n <img *ngFor=\"let image of imagePreviews\" [src]=\"image.src\" alt=\"image preview\" height=\"100\" class=\"e1tag-style5\"\r\n [style]=\"componentProperties.style.style5\" />\r\n </div>\r\n </div>\r\n</div>\r\n", styles: [".image-preview-container{border:1px solid rgba(0,0,0,.08)}.image-preview-container>.label-container{margin:5px}\n"] }]
8596
- }], ctorParameters: function () { return [{ type: ZComponentService }, { type: i2.AuthService }, { type: i2.CompressImageService }, { type: i2.ZCoreService }, { type: i0.NgZone }, { type: i2.SharePointService }]; }, propDecorators: { uploadComponent: [{
8620
+ args: [{ selector: "app-zupload", template: "<div [formGroup]=\"form\" class=\"zupload-container e1tag-style\" [style]=\"componentProperties.style.style\">\r\n <kendo-upload\r\n *ngIf=\"!data.SelectFileOnly\"\r\n #uploadComponent\r\n [id]=\"data.Value\"\r\n [autoUpload]=\"isAutoUpload\"\r\n [saveUrl]=\"uploadSaveUrl\"\r\n [removeUrl]=\"uploadRemoveUrl\"\r\n [restrictions]=\"restrictions\"\r\n [multiple]=\"isMultiple\"\r\n [chunkable]=\"chunkSettings\"\r\n [showFileList]=\"showFileList\"\r\n (select)=\"selectEventHandler($event)\"\r\n (remove)=\"onRemove($event)\"\r\n (success)=\"onSuccess($event)\"\r\n (upload)=\"uploadEventHandler($event)\"\r\n [style]=\"componentProperties.style.style1\"\r\n class=\"e1tag-style1\">\r\n </kendo-upload>\r\n\r\n <kendo-fileselect\r\n *ngIf=\"data.SelectFileOnly\"\r\n #uploadComponent\r\n [id]=\"data.Value\"\r\n (select)=\"selectEventHandler($event)\"\r\n (remove)=\"onRemove($event)\"\r\n [formControlName]=\"data.Value\"\r\n (valueChange)=\"onChange($event)\" \r\n [restrictions]=\"restrictions\"\r\n [style]=\"componentProperties.style.style1\"\r\n class=\"e1tag-style1\">\r\n </kendo-fileselect>\r\n\r\n <div\r\n *ngIf=\"imagePreviews.length\"\r\n class=\"image-preview-container e1tag-style2\"\r\n [style]=\"componentProperties.style.style2\">\r\n <div\r\n class=\"label-container e1tag-style3\"\r\n [style]=\"componentProperties.style.style3\">\r\n Image Preview:\r\n </div>\r\n <div\r\n class=\"image-container e1tag-style4\"\r\n [style]=\"componentProperties.style.style4\">\r\n <img\r\n *ngFor=\"let image of imagePreviews\"\r\n [src]=\"image.src\"\r\n alt=\"image preview\"\r\n height=\"100\"\r\n class=\"e1tag-style5\"\r\n [style]=\"componentProperties.style.style5\" />\r\n </div>\r\n </div>\r\n</div>\r\n", styles: [".image-preview-container{border:1px solid rgba(0,0,0,.08)}.image-preview-container>.label-container{margin:5px}\n"] }]
8621
+ }], ctorParameters: function () { return [{ type: ZComponentService }, { type: i2.AuthService }, { type: i2.CompressImageService }, { type: i2.ZCoreService }, { type: i0.NgZone }, { type: i2.SharePointService }, { type: i2.AlertService }]; }, propDecorators: { uploadComponent: [{
8597
8622
  type: ViewChild,
8598
8623
  args: ["uploadComponent"]
8599
8624
  }] } });