@ironcode/vas-lib 0.0.9 → 0.0.10

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.
Files changed (36) hide show
  1. package/cjs/lib/entity/vas-control.model.d.ts +1 -1
  2. package/cjs/lib/entity/vas-control.model.js +1 -1
  3. package/cjs/lib/entity/vas-control.model.js.map +1 -1
  4. package/cjs/lib/entity/vas-form.dto.d.ts +1 -0
  5. package/cjs/lib/entity/vas-form.dto.d.ts.map +1 -1
  6. package/cjs/lib/entity/vas-form.dto.js.map +1 -1
  7. package/cjs/lib/entity/vas-form.model.d.ts +3 -1
  8. package/cjs/lib/entity/vas-form.model.d.ts.map +1 -1
  9. package/cjs/lib/entity/vas-form.model.js +5 -2
  10. package/cjs/lib/entity/vas-form.model.js.map +1 -1
  11. package/cjs/lib/entity/vas-job.model.d.ts +14 -27
  12. package/cjs/lib/entity/vas-job.model.d.ts.map +1 -1
  13. package/cjs/lib/entity/vas-job.model.js +74 -70
  14. package/cjs/lib/entity/vas-job.model.js.map +1 -1
  15. package/cjs/lib/entity/vas-job.model.spec-data.d.ts.map +1 -1
  16. package/cjs/lib/entity/vas-job.model.spec-data.js +1 -0
  17. package/cjs/lib/entity/vas-job.model.spec-data.js.map +1 -1
  18. package/cjs/lib/utils/get-value-by-path.d.ts +20 -0
  19. package/cjs/lib/utils/get-value-by-path.d.ts.map +1 -0
  20. package/cjs/lib/utils/get-value-by-path.js +68 -0
  21. package/cjs/lib/utils/get-value-by-path.js.map +1 -0
  22. package/esm2020/lib/entity/vas-control.model.mjs +2 -2
  23. package/esm2020/lib/entity/vas-form.dto.mjs +1 -1
  24. package/esm2020/lib/entity/vas-form.model.mjs +6 -3
  25. package/esm2020/lib/entity/vas-job.model.mjs +75 -71
  26. package/esm2020/lib/utils/get-value-by-path.mjs +64 -0
  27. package/fesm2015/ironcode-vas-lib.mjs +143 -73
  28. package/fesm2015/ironcode-vas-lib.mjs.map +1 -1
  29. package/fesm2020/ironcode-vas-lib.mjs +143 -73
  30. package/fesm2020/ironcode-vas-lib.mjs.map +1 -1
  31. package/lib/entity/vas-control.model.d.ts +1 -1
  32. package/lib/entity/vas-form.dto.d.ts +1 -0
  33. package/lib/entity/vas-form.model.d.ts +3 -1
  34. package/lib/entity/vas-job.model.d.ts +14 -27
  35. package/lib/utils/get-value-by-path.d.ts +19 -0
  36. package/package.json +1 -1
@@ -243,7 +243,7 @@ class VasControlModel extends VasBaseModel {
243
243
  }
244
244
  /**
245
245
  * Returns the name of this control to be used in the report templates
246
- * i.e. field.foo -> foo
246
+ * i.e. fields.foo -> foo
247
247
  * @return {string}
248
248
  */
249
249
  get reportTemplateName() {
@@ -487,8 +487,9 @@ class VasFormModel extends VasBaseModel {
487
487
  * @param {string} title
488
488
  * @param {string} description
489
489
  * @param {VasGroupModel[]} groups
490
+ * @param {string} dynamicDescriptor
490
491
  */
491
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, jobType, title, description, groups) {
492
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, jobType, title, description, groups, dynamicDescriptor) {
492
493
  super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy);
493
494
  this.id = id;
494
495
  this.created = created;
@@ -503,6 +504,7 @@ class VasFormModel extends VasBaseModel {
503
504
  this.title = title;
504
505
  this.description = description;
505
506
  this.groups = groups;
507
+ this.dynamicDescriptor = dynamicDescriptor;
506
508
  }
507
509
  /**
508
510
  * Returns the name of this form in a "safe" way, i.e. no spaces, special
@@ -545,7 +547,7 @@ class VasFormModel extends VasBaseModel {
545
547
  static fromDto(dto) {
546
548
  return new VasFormModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.account || '', dto.accessGroup || '', dto.jobType || '', dto.title || '', dto.description || '', (dto.groups || [])
547
549
  .sort((a, b) => a.sequence - b.sequence)
548
- .map(g => VasGroupModel.fromDto(g)));
550
+ .map(g => VasGroupModel.fromDto(g)), dto.dynamicDescriptor || '');
549
551
  }
550
552
  addControlTypesToControl(controlTypes) {
551
553
  const controlTypeModels = controlTypes
@@ -646,10 +648,75 @@ class VasFormModel extends VasBaseModel {
646
648
  title: this.title,
647
649
  description: this.description,
648
650
  groups: this.groups.map(group => group.toDto()),
651
+ dynamicDescriptor: this.dynamicDescriptor
649
652
  };
650
653
  }
651
654
  }
652
655
 
656
+ /**
657
+ * A non sophisticated way to get values from the job via paths. For example:
658
+ *
659
+ * getValueByPath(
660
+ * ['foo', 'bar'],
661
+ * {
662
+ * foo: {
663
+ * bar: 'value'
664
+ * }
665
+ * }
666
+ * );
667
+ *
668
+ * will return "value"
669
+ * @param {string[]} path
670
+ * @param {Record<string, VasFieldDtoValue>} object
671
+ * @return {T | undefined}
672
+ */
673
+ const getValueByPath = (path, object) => {
674
+ switch (path.length) {
675
+ case 0: {
676
+ return;
677
+ }
678
+ case 1: {
679
+ return (object)[path[0]];
680
+ }
681
+ case 2: {
682
+ const val0 = object[path[0]];
683
+ if (!val0) {
684
+ return undefined;
685
+ }
686
+ return val0[path[1]];
687
+ }
688
+ case 3: {
689
+ const val0 = object[path[0]];
690
+ if (!val0) {
691
+ return undefined;
692
+ }
693
+ const val1 = val0[path[1]];
694
+ if (!val1) {
695
+ return undefined;
696
+ }
697
+ return val1[path[2]];
698
+ }
699
+ case 4: {
700
+ const val0 = object[path[0]];
701
+ if (!val0) {
702
+ return undefined;
703
+ }
704
+ const val1 = val0[path[1]];
705
+ if (!val1) {
706
+ return undefined;
707
+ }
708
+ const val2 = val1[path[2]];
709
+ if (!val2) {
710
+ return undefined;
711
+ }
712
+ return val2[path[3]];
713
+ }
714
+ default: {
715
+ throw Error('path has too many segments');
716
+ }
717
+ }
718
+ };
719
+
653
720
  /**
654
721
  * JobModel
655
722
  */
@@ -696,8 +763,6 @@ class VasJobModel extends VasBaseModel {
696
763
  * @return {VasJobModelDynamicInterface}
697
764
  */
698
765
  get $this() {
699
- // eslint-disable-next-line @typescript-eslint/no-this-alias
700
- const $this = this;
701
766
  return this;
702
767
  }
703
768
  /**
@@ -756,69 +821,33 @@ class VasJobModel extends VasBaseModel {
756
821
  return fields;
757
822
  }
758
823
  /**
759
- * A very non sophisticated way to get values from the job via paths
760
- *
761
- * For example:
762
- *
763
- * getValueByPath(['foo', 'bar']);
764
- *
765
- * if job is
766
- * {
767
- * foo: {
768
- * bar: 'value'
769
- * }
770
- * }
771
- *
772
- * will return "value"
773
- *
824
+ * Will return an object whose keys are the names of all fields in the job but
825
+ * with the "fields." part removed. This method is similar to `getFields`
826
+ * except that this method will only return values that are set whereas
827
+ * `getFields` will return a property regardless (because it uses the form to
828
+ * drive the logic)
829
+ * @return {Record<string, VasFieldDtoValue>}
830
+ */
831
+ getFields2() {
832
+ let fields = {};
833
+ this.dynamicProperties
834
+ .forEach((groupName) => {
835
+ Object
836
+ .keys(this.$this[groupName])
837
+ .forEach(controlName => {
838
+ const controlNameShort = controlName.replace(/fields\./, '');
839
+ fields[controlNameShort] = this.getValueByPath([groupName, controlName]);
840
+ });
841
+ }, {});
842
+ return fields;
843
+ }
844
+ /**
845
+
774
846
  * @param {string[]} path path segments
775
847
  * @return {void}
776
848
  */
777
849
  getValueByPath(path = []) {
778
- switch (path.length) {
779
- case 0: {
780
- return;
781
- }
782
- case 1: {
783
- return (this.$this)[path[0]];
784
- }
785
- case 2: {
786
- const val0 = this.$this[path[0]];
787
- if (!val0) {
788
- return undefined;
789
- }
790
- return val0[path[1]];
791
- }
792
- case 3: {
793
- const val0 = this.$this[path[0]];
794
- if (!val0) {
795
- return undefined;
796
- }
797
- const val1 = val0[path[1]];
798
- if (!val1) {
799
- return undefined;
800
- }
801
- return val1[path[2]];
802
- }
803
- case 4: {
804
- const val0 = this.$this[path[0]];
805
- if (!val0) {
806
- return undefined;
807
- }
808
- const val1 = val0[path[1]];
809
- if (!val1) {
810
- return undefined;
811
- }
812
- const val2 = val1[path[2]];
813
- if (!val2) {
814
- return undefined;
815
- }
816
- return val2[path[3]];
817
- }
818
- default: {
819
- throw Error('path has too many segments');
820
- }
821
- }
850
+ return getValueByPath(path, this.$this);
822
851
  }
823
852
  /**
824
853
  * A very non sophisticated way to set values in the job via paths
@@ -843,7 +872,7 @@ class VasJobModel extends VasBaseModel {
843
872
  return;
844
873
  }
845
874
  case 1: {
846
- (this.$this)[path[0]] = value;
875
+ this[path[0]] = value;
847
876
  return;
848
877
  }
849
878
  case 2: {
@@ -867,14 +896,29 @@ class VasJobModel extends VasBaseModel {
867
896
  * @return {VasJobDto}
868
897
  */
869
898
  toDto(staticOnly = false) {
870
- const dto = {};
871
- this.staticProperties
872
- .forEach(prop => (dto)[prop] = this.$this[prop]);
873
899
  if (staticOnly) {
874
- return dto;
900
+ return {
901
+ id: this.id,
902
+ created: this.created,
903
+ createdBy: this.createdBy,
904
+ modified: this.modified,
905
+ modifiedBy: this.modifiedBy,
906
+ serverCreated: this.serverCreated,
907
+ serverModified: this.serverModified,
908
+ account: this.account,
909
+ accessGroup: this.accessGroup,
910
+ reference: this.reference,
911
+ jobDate: this.jobDate,
912
+ jobStatus: this.jobStatus,
913
+ jobType: this.jobType,
914
+ assignee: this.assignee,
915
+ formId: this.formId,
916
+ timeZoneOffset: this.timeZoneOffset,
917
+ };
875
918
  }
876
- this.dynamicProperties
877
- .forEach(prop => dto[prop] = this.$this[prop]);
919
+ const dto = {};
920
+ [...this.staticProperties, ...this.dynamicProperties]
921
+ .forEach(prop => (dto)[prop] = this.$this[prop]);
878
922
  return dto;
879
923
  }
880
924
  /**
@@ -929,7 +973,33 @@ class VasJobModel extends VasBaseModel {
929
973
  filterArg = (filterArg || '').trim();
930
974
  }
931
975
  const path = key.split('.');
932
- let result = (this.getValueByPath(path) || '').toString();
976
+ const objectKey = path.shift() || '';
977
+ let result = '';
978
+ if (objectKey === 'job') {
979
+ result = (this.getValueByPath(path) || '').toString();
980
+ }
981
+ else if (objectKey === 'fields') {
982
+ result = (getValueByPath(path, this.getFields2()) || '').toString();
983
+ }
984
+ else if (objectKey.length) {
985
+ if (options.objects) {
986
+ if (options.objects[objectKey] === undefined) {
987
+ console.debug(`objectKey ${objectKey} is not present in options.object`);
988
+ result = '';
989
+ }
990
+ else {
991
+ result = (getValueByPath(path, options.objects[objectKey]) || '')
992
+ .toString();
993
+ }
994
+ }
995
+ else {
996
+ console.debug(`objectKey ${objectKey} was used but options.object is not set`);
997
+ return '';
998
+ }
999
+ }
1000
+ else {
1001
+ return '';
1002
+ }
933
1003
  if (filterName && result) {
934
1004
  switch (filterName) {
935
1005
  case 'date': {
@@ -943,7 +1013,7 @@ class VasJobModel extends VasBaseModel {
943
1013
  }
944
1014
  }
945
1015
  return result;
946
- });
1016
+ }).trim();
947
1017
  }
948
1018
  ;
949
1019
  }