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