@ironcode/vas-lib 0.0.18 → 0.0.19
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.map +1 -1
- package/cjs/lib/entity/vas-control.model.js +5 -0
- package/cjs/lib/entity/vas-control.model.js.map +1 -1
- package/cjs/lib/entity/vas-field.model.d.ts +1 -2
- package/cjs/lib/entity/vas-field.model.d.ts.map +1 -1
- package/cjs/lib/entity/vas-field.model.js +3 -11
- package/cjs/lib/entity/vas-field.model.js.map +1 -1
- package/cjs/lib/entity/vas-job.model.d.ts +10 -48
- package/cjs/lib/entity/vas-job.model.d.ts.map +1 -1
- package/cjs/lib/entity/vas-job.model.js +10 -71
- package/cjs/lib/entity/vas-job.model.js.map +1 -1
- package/esm2020/lib/entity/vas-control.model.mjs +6 -1
- package/esm2020/lib/entity/vas-field.model.mjs +4 -12
- package/esm2020/lib/entity/vas-job.model.mjs +11 -72
- package/fesm2015/ironcode-vas-lib.mjs +18 -82
- package/fesm2015/ironcode-vas-lib.mjs.map +1 -1
- package/fesm2020/ironcode-vas-lib.mjs +18 -82
- package/fesm2020/ironcode-vas-lib.mjs.map +1 -1
- package/lib/entity/vas-field.model.d.ts +1 -2
- package/lib/entity/vas-job.model.d.ts +10 -48
- package/package.json +1 -1
|
@@ -255,6 +255,11 @@ class VasControlModel extends VasBaseModel {
|
|
|
255
255
|
case 'contact': {
|
|
256
256
|
return {};
|
|
257
257
|
}
|
|
258
|
+
case 'toggle': {
|
|
259
|
+
return {
|
|
260
|
+
checked: false, comment: ''
|
|
261
|
+
};
|
|
262
|
+
}
|
|
258
263
|
}
|
|
259
264
|
}
|
|
260
265
|
return this.parseMaybeJson(this.defaultValue);
|
|
@@ -439,7 +444,7 @@ class VasFieldModel extends VasJobDataModel {
|
|
|
439
444
|
* @return {VasFieldModel}
|
|
440
445
|
*/
|
|
441
446
|
static fromDto(fieldDto) {
|
|
442
|
-
return new VasFieldModel(fieldDto.id || UUID.UUID(), fieldDto.created || '', fieldDto.serverCreated || '', fieldDto.createdBy || '', fieldDto.modified || '', fieldDto.serverModified || '', fieldDto.modifiedBy || '', fieldDto.account || '', fieldDto.job || '', fieldDto.control || '', fieldDto.fieldJobPointers || [],
|
|
447
|
+
return new VasFieldModel(fieldDto.id || UUID.UUID(), fieldDto.created || '', fieldDto.serverCreated || '', fieldDto.createdBy || '', fieldDto.modified || '', fieldDto.serverModified || '', fieldDto.modifiedBy || '', fieldDto.account || '', fieldDto.job || '', fieldDto.control || '', fieldDto.fieldJobPointers || [], fieldDto.value || '', fieldDto.version || 0);
|
|
443
448
|
}
|
|
444
449
|
/**
|
|
445
450
|
* @return {VasFieldDto}
|
|
@@ -468,7 +473,7 @@ class VasFieldModel extends VasJobDataModel {
|
|
|
468
473
|
return {
|
|
469
474
|
...super.toApiDto(),
|
|
470
475
|
control: this.control,
|
|
471
|
-
value: this.
|
|
476
|
+
value: this.prepareApiValue(this.value)
|
|
472
477
|
};
|
|
473
478
|
}
|
|
474
479
|
/**
|
|
@@ -479,7 +484,7 @@ class VasFieldModel extends VasJobDataModel {
|
|
|
479
484
|
* @return {string | number | boolean}
|
|
480
485
|
* @protected
|
|
481
486
|
*/
|
|
482
|
-
|
|
487
|
+
prepareApiValue(value) {
|
|
483
488
|
switch (typeof value) {
|
|
484
489
|
case 'object': {
|
|
485
490
|
return JSON.stringify(value);
|
|
@@ -498,14 +503,6 @@ class VasFieldModel extends VasJobDataModel {
|
|
|
498
503
|
}
|
|
499
504
|
}
|
|
500
505
|
}
|
|
501
|
-
static fromApiValue(value) {
|
|
502
|
-
try {
|
|
503
|
-
return JSON.parse(value);
|
|
504
|
-
}
|
|
505
|
-
catch (e) {
|
|
506
|
-
return value;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
506
|
}
|
|
510
507
|
|
|
511
508
|
/**
|
|
@@ -1111,67 +1108,15 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1111
1108
|
/**
|
|
1112
1109
|
* This method will hydrate the `fields` property of the model. The reason for
|
|
1113
1110
|
* this is that we have different ways to store the field data. One way, is
|
|
1114
|
-
* we store them as dynamic properties of the job
|
|
1115
|
-
* is
|
|
1116
|
-
*
|
|
1117
|
-
*
|
|
1118
|
-
*
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
1122
|
-
*
|
|
1123
|
-
* foo: {
|
|
1124
|
-
* bar: "value"
|
|
1125
|
-
* }
|
|
1126
|
-
* }
|
|
1127
|
-
*
|
|
1128
|
-
* B) job with array of Field
|
|
1129
|
-
* {
|
|
1130
|
-
* id: <guid>,
|
|
1131
|
-
* reference: "something"
|
|
1132
|
-
* <other static job properties>...
|
|
1133
|
-
* <will not have dynamic properties>...
|
|
1134
|
-
* fields: [
|
|
1135
|
-
* {
|
|
1136
|
-
* id: <guid>,
|
|
1137
|
-
* <other field properties>,
|
|
1138
|
-
* value: "value"
|
|
1139
|
-
* }
|
|
1140
|
-
* ]
|
|
1141
|
-
* }
|
|
1142
|
-
*
|
|
1143
|
-
* What this method does is given a VasJobModel that has been populated with
|
|
1144
|
-
* a VasJobDto in form B (i.e. `.fields` are populated - usually from a VASAPI
|
|
1145
|
-
* response), hydrate the dynamic properties of the model. NOTE: knowledge of
|
|
1146
|
-
* the Form that was used to crate the Job is required because it will contain
|
|
1147
|
-
* the Groups, which names are used in the hydrating
|
|
1148
|
-
*
|
|
1149
|
-
* @param {VasFormModel} formModel the VasFormModel that was used to create
|
|
1150
|
-
* the job
|
|
1151
|
-
* @return {void}
|
|
1152
|
-
*/
|
|
1153
|
-
hydrateDynamicProps(formModel) {
|
|
1154
|
-
formModel.groups
|
|
1155
|
-
.forEach(group => {
|
|
1156
|
-
const p0 = group.name;
|
|
1157
|
-
group.controls
|
|
1158
|
-
.forEach(control => {
|
|
1159
|
-
const p1 = control.name;
|
|
1160
|
-
const f = this.fields.find(field => field.control === control.id);
|
|
1161
|
-
if (!f) {
|
|
1162
|
-
return;
|
|
1163
|
-
}
|
|
1164
|
-
this.setValueByPath(f.value, [p0, p1]);
|
|
1165
|
-
});
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
/**
|
|
1169
|
-
* This method will hydrate the `fields` property of the model. The reason for
|
|
1170
|
-
* this is that we have different ways to store the field data. One way, is
|
|
1171
|
-
* we store them as dynamic properties of the job e.g. job.foo.bar, the other
|
|
1172
|
-
* is in an array of Field. The former is nice to work with in clients,
|
|
1173
|
-
* whereas the latter more suited to relational database.
|
|
1174
|
-
*
|
|
1111
|
+
* we store them as dynamic properties of the job. For example job.foo.bar,
|
|
1112
|
+
* where `foo` is the name of a Group, and `bar` is the name of a control.
|
|
1113
|
+
* Thus, when we create a job using a form in the client, the job object will
|
|
1114
|
+
* have its static properties (id, account, reference etc), and also a number
|
|
1115
|
+
* of dynamic properties determined by the Groups and Controls. This kind of
|
|
1116
|
+
* object is nice to work with in certain circumstances. However, the api
|
|
1117
|
+
* works differently. In the API a Job is a record, and references a number of
|
|
1118
|
+
* Field records. Each Field stores the value. Comparing these two models we
|
|
1119
|
+
* have:
|
|
1175
1120
|
* A) job with dynamic properties, e.g.
|
|
1176
1121
|
* {
|
|
1177
1122
|
* id: <guid>,
|
|
@@ -1238,7 +1183,7 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1238
1183
|
* be generated, or to reuse an existing one from the map.
|
|
1239
1184
|
* @param {Array<string>} controlNames if a value is provided, it will be used
|
|
1240
1185
|
* to filter the fields that are returned.
|
|
1241
|
-
* @return {
|
|
1186
|
+
* @return {Array<VasFieldDto>}
|
|
1242
1187
|
*/
|
|
1243
1188
|
hydrateFields(formModel, controlFieldIdMap = new Map(), controlNames) {
|
|
1244
1189
|
const fields = [];
|
|
@@ -1303,20 +1248,11 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1303
1248
|
return;
|
|
1304
1249
|
}
|
|
1305
1250
|
case 2: {
|
|
1306
|
-
if (!this.$this[path[0]]) {
|
|
1307
|
-
this.$this[path[0]] = {};
|
|
1308
|
-
}
|
|
1309
1251
|
// eslint-disable-next-line max-len
|
|
1310
1252
|
this.$this[path[0]][path[1]] = value;
|
|
1311
1253
|
return;
|
|
1312
1254
|
}
|
|
1313
1255
|
case 3: {
|
|
1314
|
-
if (!this.$this[path[0]]) {
|
|
1315
|
-
this.$this[path[0]] = {};
|
|
1316
|
-
}
|
|
1317
|
-
if (!this.$this[path[0]][path[1]]) {
|
|
1318
|
-
this.$this[path[0]][path[1]] = {};
|
|
1319
|
-
}
|
|
1320
1256
|
// eslint-disable-next-line max-len
|
|
1321
1257
|
this.$this[path[0]][path[1]][path[2]] = value;
|
|
1322
1258
|
return;
|