@ironcode/vas-lib 1.1.0 → 1.2.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.
@@ -5,6 +5,7 @@ import { VasFormModel } from './vas-form.model';
5
5
  import { VasJobDto } from './vas-job.dto';
6
6
  import { VasRestrictedAccountObjectModel } from './vas-restricted-account-object.model';
7
7
  import { GeoLocation } from '../model/geo-location';
8
+ import { VasFormDto } from './vas-form.dto';
8
9
  export declare interface VasJobModelDynamicInterface {
9
10
  [s: string]: string | number | Record<string, VasFieldDtoValue>;
10
11
  }
@@ -54,8 +55,7 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
54
55
  */
55
56
  get dynamicProperties(): Array<string>;
56
57
  /**
57
- * Returns a list of Job static properties i.e. those that are declared by
58
- * the type
58
+ * Returns the list of properties of the Job type
59
59
  */
60
60
  get staticProperties(): Array<string>;
61
61
  /**
@@ -63,6 +63,13 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
63
63
  */
64
64
  static empty(): VasJobModel;
65
65
  static fromDto(dto: Partial<VasJobDto>): VasJobModel;
66
+ /**
67
+ * This method will instantiate a new JobModel. The difference with this
68
+ * method of instantiation is that we are coming from a relation frame i.e.
69
+ * the job has a list of {@link VasFieldDto} instead of a Job document.
70
+ *
71
+ */
72
+ static fromRelational(dto: Partial<VasJobDto>, form: VasFormDto): VasJobModel;
66
73
  /**
67
74
  * @param {VasFormModel} formModel
68
75
  * @return {Record<string, VasFieldDtoValue>}
@@ -75,7 +82,7 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
75
82
  * return a property regardless (because it uses the form to drive the logic)
76
83
  * @return {Record<string, VasFieldDtoValue>}
77
84
  */
78
- getFields2(): Record<string, VasFieldDtoValue>;
85
+ protected getFields2(): Record<string, VasFieldDtoValue>;
79
86
  /**
80
87
  * Returns an object describing how many attachments were added to this job
81
88
  * (camera controls and files), and how many have not been uploaded yet.
@@ -88,18 +95,41 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
88
95
  total: number;
89
96
  };
90
97
  /**
91
- * This method will hydrate the `fields` property of the model. The reason for
92
- * this is that we have different ways to store the field data. One way, is
93
- * we store them as dynamic properties of the job. For example job.foo.bar,
94
- * where `foo` is the name of a Group, and `bar` is the name of a control.
95
- * Thus, when we create a job using a form in the client, the job object will
96
- * have its static properties (id, account, reference etc), and also a number
97
- * of dynamic properties determined by the Groups and Controls. This kind of
98
- * object is nice to work with in certain circumstances. However, the api
99
- * works differently. In the API a Job is a record, and references a number of
100
- * Field records. Each Field stores the value. Comparing these two models we
101
- * have:
102
- * A) job with dynamic properties, e.g.
98
+ * This method will return the dynamic property from the JobModel that
99
+ * represent a group (from a form).
100
+ *
101
+ * @param name the name of the group
102
+ * @param init if true (default) and group is not found, initialise an empty
103
+ * group, otherwise throw an error
104
+ */
105
+ getGroup(name: string, init?: boolean): Record<string, VasFieldDtoValue>;
106
+ /**
107
+ * @param path path segments
108
+ */
109
+ getValueByPath<T extends VasFieldDtoValue>(path?: string[]): T | undefined;
110
+ /**
111
+ * In order to understand why we need this method it is important to
112
+ * understand that within the system, Jobs can be represented in one of two
113
+ * ways, document and relational.
114
+ *
115
+ * The important distinction is how values submitted by a form are stored.
116
+ *
117
+ * Jobs stored as documents (JSON objects) will store user values, as dynamic
118
+ * properties of the document.
119
+ *
120
+ * Whereas, Jobs stored as relational, will store user values in an array of
121
+ * {@link VasFieldDto} objects.
122
+ *
123
+ * Depending on where we are in the system, either one of these approaches can
124
+ * be more useful than the other.
125
+ *
126
+ * This method, assumes that the JobModel has been instantiated from a
127
+ * document representation, and serves to hydrate the fields array. In order
128
+ * to achieve this, knowledge of the {@link VasFormDto} that created the job
129
+ * is required.
130
+ *
131
+ *
132
+ * Job in document representation
103
133
  * {
104
134
  * id: <guid>,
105
135
  * reference: "something"
@@ -109,7 +139,7 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
109
139
  * }
110
140
  * }
111
141
  *
112
- * B) job with fields
142
+ * Job in relational representation
113
143
  * {
114
144
  * id: <guid>,
115
145
  * reference: "something"
@@ -124,55 +154,15 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
124
154
  * ]
125
155
  * }
126
156
  *
127
- * So, what this method does is given a JobModel in the form of A, read all
128
- * of those dynamic properties and set them into `fields`. Doing this requires
129
- * knowledge of the Form that was used to create the job. Moreover, since the
130
- * dynamic properties do not contain the ids of the fields, we also allow to
131
- * pass in a `controlFieldIdMap`. This map stores the mapping between Control
132
- * and the Field that was created in the Job to store the value for that
133
- * Control. This is useful, if for example you want to compare a Job in form A
134
- * with a Job in form B, for example if you want to update the Job on the API
135
- * with a Job that was saved by a client in form A.
136
- *
137
- * E.g.
138
- * Client -> API: client requests form
139
- * User -> Client: user fills in the form and submits
140
- * Client -> Firestore: client saves the Job in form A i.e. dynamic props
141
- * Firestore -> Function: A function is triggered to sync the job to the API
142
- * Function -> API: Function checks if job already exists, it receives 404
143
- * Function -> Function: The function calls `hydrateFields(...)`
144
- * Function -> API: The function POST the Job to /jobs
145
- * Function -> API: The function POST each field to /fields
146
- *
147
- * Similarly, if the user updates the job
148
- * Client -> API: client requests form
149
- * User -> Client: user fills in the form and submits an update
150
- * Client -> Firestore: client saves the Job in form A i.e. dynamic props
151
- * Firestore -> Function: A function is triggered to sync the job to the API
152
- * Function -> API: Function checks if job already exists, it receives 200
153
- * Function -> Function: The function calls `hydrateFields(...)` passing in
154
- * the map is made by iterating over the fields it
155
- * received from the API and storing the mappings
156
- * between controlId and fieldId for each field
157
- * Function -> API: The function PATCH the Job to /jobs
158
- * Function -> API: The function POST/PATCH each field to /fields
159
- * treated as new
160
- *
161
- * @param {VasFormModel} formModel the VasFormModel that was used to create
162
- * the job
163
- * @param {Map<string, string>} controlFieldIdMap a mapping of control to
164
- * field ids. This is used to determine whether a new id for the field should
165
- * be generated, or to reuse an existing one from the map.
166
- * @param {Array<string>} controlNames if a value is provided, it will be used
157
+ *
158
+ * @param formModel the VasFormModel that was used to create the job
159
+ * @param controlFieldIdMap This is used to determine the id each field.
160
+ * Either one will be found in the map, or a new one is generated.
161
+ * @param controlNames if a value is provided, it will be used
167
162
  * to filter the fields that are returned.
168
163
  * @return {Array<VasFieldDto>}
169
164
  */
170
165
  hydrateFields(formModel: VasFormModel, controlFieldIdMap?: Map<string, string>, controlNames?: Array<string>): void;
171
- /**
172
- * @param {string[]} path path segments
173
- * @return {void}
174
- */
175
- getValueByPath<T extends VasFieldDtoValue>(path?: string[]): T | undefined;
176
166
  /**
177
167
  * A very non sophisticated way to set values in the job via paths
178
168
  *
@@ -187,14 +177,13 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
187
177
  * }
188
178
  * }
189
179
  *
190
- * @param {any} value the value to set
191
- * @param {string[]} path path segments
180
+ * @param value the value to set
181
+ * @param path path segments
192
182
  */
193
183
  setValueByPath(value: VasFieldDtoValue, path?: string[]): void;
194
184
  /**
195
- * @param {boolean} staticOnly if true, will only output values for the static
185
+ * @param staticOnly if true, will only output values for the static
196
186
  * properties in the dto
197
- * @return {VasJobDto}
198
187
  */
199
188
  toDto(staticOnly?: boolean): VasJobDto;
200
189
  /**
@@ -221,7 +210,7 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
221
210
  *
222
211
  * @param {string} value a string with the syntax
223
212
  * @param {ParseSyntaxOptions} options
224
- * @return {string} the results of parsing the syntax on this job
213
+ * @return the results of parsing the syntax on this job
225
214
  */
226
215
  parseSyntax(value: string, options?: ParseSyntaxOptions): string;
227
216
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"vas-job.model.d.ts","sourceRoot":"","sources":["../../../../../projects/vas-lib/src/lib/entity/vas-job.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIvD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEhE,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H,oBAAoB,CAClB,SAAS,EAAE,YAAY,GACtB;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IA6CrC;;;;;;;OAOG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAO,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAmBrE;;OAEG;IACH,cAAc,CAAC,CAAC,SAAS,gBAAgB,EACvC,IAAI,GAAE,MAAM,EAAO,GAClB,CAAC,GAAG,SAAS;IAIhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsDG;IACH,aAAa,CACX,SAAS,EAAE,YAAY,EACvB,iBAAiB,GAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAA6B,EAClE,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAC3B,IAAI;IAkCP;;;;;;;;;;;;;;;;OAgBG;IACH,cAAc,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,GAAE,MAAM,EAAO,GAAG,IAAI;IAyBlE;;;OAGG;IACH,KAAK,CAAC,UAAU,UAAQ,GAAG,SAAS;IAwCpC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,WAAW,CACT,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,kBAER,GACA,MAAM;IA0ET;;OAEG;IACM,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAc/D"}
@@ -62,8 +62,7 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
62
62
  .filter(prop => !nativeProps.includes(prop));
63
63
  }
64
64
  /**
65
- * Returns a list of Job static properties i.e. those that are declared by
66
- * the type
65
+ * Returns the list of properties of the Job type
67
66
  */
68
67
  get staticProperties() {
69
68
  return Object.getOwnPropertyNames(VasJobModel.empty());
@@ -83,6 +82,28 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
83
82
  .forEach((key) => model.$this[key] = dto[key]);
84
83
  return model;
85
84
  }
85
+ /**
86
+ * This method will instantiate a new JobModel. The difference with this
87
+ * method of instantiation is that we are coming from a relation frame i.e.
88
+ * the job has a list of {@link VasFieldDto} instead of a Job document.
89
+ *
90
+ */
91
+ static fromRelational(dto, form) {
92
+ const model = new VasJobModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.accessGroup || '', dto.reference || '', dto.jobDate || '', dto.jobStatus || '', dto.jobType || '', dto.assigneeId || '', dto.formId || '', dto.timeZoneOffset || (0, moment_1.default)().utcOffset(), dto.pendingFields || 0, dto.childModified || '', dto.version || 0, dto.fields || [], dto.files || [], dto.createdByDisplayName || '', dto.modifiedByDisplayName || '', dto.geoLocation || (0, geo_location_1.getEmptyGeoLocation)());
93
+ form.groups
94
+ .forEach(group => {
95
+ group.controls
96
+ .forEach(control => {
97
+ var _a;
98
+ const field = (_a = dto.fields) === null || _a === void 0 ? void 0 : _a.find(f => f.control === control.id);
99
+ if (!field) {
100
+ return;
101
+ }
102
+ model.getGroup(group.name)[control.name] = field.value;
103
+ });
104
+ });
105
+ return model;
106
+ }
86
107
  /**
87
108
  * @param {VasFormModel} formModel
88
109
  * @return {Record<string, VasFieldDtoValue>}
@@ -163,18 +184,63 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
163
184
  };
164
185
  }
165
186
  /**
166
- * This method will hydrate the `fields` property of the model. The reason for
167
- * this is that we have different ways to store the field data. One way, is
168
- * we store them as dynamic properties of the job. For example job.foo.bar,
169
- * where `foo` is the name of a Group, and `bar` is the name of a control.
170
- * Thus, when we create a job using a form in the client, the job object will
171
- * have its static properties (id, account, reference etc), and also a number
172
- * of dynamic properties determined by the Groups and Controls. This kind of
173
- * object is nice to work with in certain circumstances. However, the api
174
- * works differently. In the API a Job is a record, and references a number of
175
- * Field records. Each Field stores the value. Comparing these two models we
176
- * have:
177
- * A) job with dynamic properties, e.g.
187
+ * This method will return the dynamic property from the JobModel that
188
+ * represent a group (from a form).
189
+ *
190
+ * @param name the name of the group
191
+ * @param init if true (default) and group is not found, initialise an empty
192
+ * group, otherwise throw an error
193
+ */
194
+ getGroup(name, init = true) {
195
+ let prop;
196
+ if (this.staticProperties.includes(name)) {
197
+ throw Error(`invalid group name ${name}, not a dynamic property`);
198
+ }
199
+ else if (this.$this[name] === undefined) {
200
+ if (init) {
201
+ prop = this.$this[name] = {};
202
+ }
203
+ else {
204
+ throw Error(`invalid group name ${name}, not found`);
205
+ }
206
+ }
207
+ else {
208
+ prop = this.$this[name];
209
+ if (typeof prop !== 'object') {
210
+ throw Error(`invalid group name ${name}, not an object`);
211
+ }
212
+ }
213
+ return prop;
214
+ }
215
+ /**
216
+ * @param path path segments
217
+ */
218
+ getValueByPath(path = []) {
219
+ return (0, get_value_by_path_1.getValueByPath)(path, this.$this);
220
+ }
221
+ /**
222
+ * In order to understand why we need this method it is important to
223
+ * understand that within the system, Jobs can be represented in one of two
224
+ * ways, document and relational.
225
+ *
226
+ * The important distinction is how values submitted by a form are stored.
227
+ *
228
+ * Jobs stored as documents (JSON objects) will store user values, as dynamic
229
+ * properties of the document.
230
+ *
231
+ * Whereas, Jobs stored as relational, will store user values in an array of
232
+ * {@link VasFieldDto} objects.
233
+ *
234
+ * Depending on where we are in the system, either one of these approaches can
235
+ * be more useful than the other.
236
+ *
237
+ * This method, assumes that the JobModel has been instantiated from a
238
+ * document representation, and serves to hydrate the fields array. In order
239
+ * to achieve this, knowledge of the {@link VasFormDto} that created the job
240
+ * is required.
241
+ *
242
+ *
243
+ * Job in document representation
178
244
  * {
179
245
  * id: <guid>,
180
246
  * reference: "something"
@@ -184,7 +250,7 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
184
250
  * }
185
251
  * }
186
252
  *
187
- * B) job with fields
253
+ * Job in relational representation
188
254
  * {
189
255
  * id: <guid>,
190
256
  * reference: "something"
@@ -199,46 +265,11 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
199
265
  * ]
200
266
  * }
201
267
  *
202
- * So, what this method does is given a JobModel in the form of A, read all
203
- * of those dynamic properties and set them into `fields`. Doing this requires
204
- * knowledge of the Form that was used to create the job. Moreover, since the
205
- * dynamic properties do not contain the ids of the fields, we also allow to
206
- * pass in a `controlFieldIdMap`. This map stores the mapping between Control
207
- * and the Field that was created in the Job to store the value for that
208
- * Control. This is useful, if for example you want to compare a Job in form A
209
- * with a Job in form B, for example if you want to update the Job on the API
210
- * with a Job that was saved by a client in form A.
211
- *
212
- * E.g.
213
- * Client -> API: client requests form
214
- * User -> Client: user fills in the form and submits
215
- * Client -> Firestore: client saves the Job in form A i.e. dynamic props
216
- * Firestore -> Function: A function is triggered to sync the job to the API
217
- * Function -> API: Function checks if job already exists, it receives 404
218
- * Function -> Function: The function calls `hydrateFields(...)`
219
- * Function -> API: The function POST the Job to /jobs
220
- * Function -> API: The function POST each field to /fields
221
- *
222
- * Similarly, if the user updates the job
223
- * Client -> API: client requests form
224
- * User -> Client: user fills in the form and submits an update
225
- * Client -> Firestore: client saves the Job in form A i.e. dynamic props
226
- * Firestore -> Function: A function is triggered to sync the job to the API
227
- * Function -> API: Function checks if job already exists, it receives 200
228
- * Function -> Function: The function calls `hydrateFields(...)` passing in
229
- * the map is made by iterating over the fields it
230
- * received from the API and storing the mappings
231
- * between controlId and fieldId for each field
232
- * Function -> API: The function PATCH the Job to /jobs
233
- * Function -> API: The function POST/PATCH each field to /fields
234
- * treated as new
235
268
  *
236
- * @param {VasFormModel} formModel the VasFormModel that was used to create
237
- * the job
238
- * @param {Map<string, string>} controlFieldIdMap a mapping of control to
239
- * field ids. This is used to determine whether a new id for the field should
240
- * be generated, or to reuse an existing one from the map.
241
- * @param {Array<string>} controlNames if a value is provided, it will be used
269
+ * @param formModel the VasFormModel that was used to create the job
270
+ * @param controlFieldIdMap This is used to determine the id each field.
271
+ * Either one will be found in the map, or a new one is generated.
272
+ * @param controlNames if a value is provided, it will be used
242
273
  * to filter the fields that are returned.
243
274
  * @return {Array<VasFieldDto>}
244
275
  */
@@ -270,13 +301,6 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
270
301
  });
271
302
  this.fields = fields;
272
303
  }
273
- /**
274
- * @param {string[]} path path segments
275
- * @return {void}
276
- */
277
- getValueByPath(path = []) {
278
- return (0, get_value_by_path_1.getValueByPath)(path, this.$this);
279
- }
280
304
  /**
281
305
  * A very non sophisticated way to set values in the job via paths
282
306
  *
@@ -291,8 +315,8 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
291
315
  * }
292
316
  * }
293
317
  *
294
- * @param {any} value the value to set
295
- * @param {string[]} path path segments
318
+ * @param value the value to set
319
+ * @param path path segments
296
320
  */
297
321
  setValueByPath(value, path = []) {
298
322
  switch (path.length) {
@@ -319,9 +343,8 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
319
343
  }
320
344
  }
321
345
  /**
322
- * @param {boolean} staticOnly if true, will only output values for the static
346
+ * @param staticOnly if true, will only output values for the static
323
347
  * properties in the dto
324
- * @return {VasJobDto}
325
348
  */
326
349
  toDto(staticOnly = false) {
327
350
  if (staticOnly) {
@@ -356,7 +379,7 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
356
379
  }
357
380
  const dto = {};
358
381
  [...this.staticProperties, ...this.dynamicProperties]
359
- .forEach(prop => (dto)[prop] = this.$this[prop]);
382
+ .forEach(prop => dto[prop] = this.$this[prop]);
360
383
  return dto;
361
384
  }
362
385
  /**
@@ -383,7 +406,7 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
383
406
  *
384
407
  * @param {string} value a string with the syntax
385
408
  * @param {ParseSyntaxOptions} options
386
- * @return {string} the results of parsing the syntax on this job
409
+ * @return the results of parsing the syntax on this job
387
410
  */
388
411
  parseSyntax(value, options = {
389
412
  timeZoneOffset: 0
@@ -417,7 +440,7 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
417
440
  result = (this.getValueByPath(path) || '').toString();
418
441
  }
419
442
  else if (objectKey === 'fields') {
420
- result = ((0, get_value_by_path_1.getValueByPath)(path, this.getFields2()) || '').toString();
443
+ result = ((0, get_value_by_path_1.getValueByPath)(['fields.' + path.shift(), ...path], this.getFields2()) || '').toString();
421
444
  }
422
445
  else if (objectKey.length) {
423
446
  if (options.objects) {
@@ -1 +1 @@
1
- {"version":3,"file":"vas-job.model.js","sourceRoot":"","sources":["../../../../../projects/vas-lib/src/lib/entity/vas-job.model.ts"],"names":[],"mappings":";;;;AAAA,iDAAuD;AACvD,iDAAqC;AACrC,4DAA4B;AAC5B,kEAA4D;AAG5D,uDAAkD;AAGlD,+FAAwF;AACxF,wDAAyE;AACzE,oGAAqH;AACrH,8DAAyD;AAoBzD;;GAEG;AACH,MAAa,WAAY,SAAQ,qEAA+B;IAE9D,YACkB,EAAU,EACV,OAAe,EACf,aAAqB,EACrB,SAAiB,EACjB,QAAgB,EAChB,cAAsB,EACtB,UAAkB,EAClB,aAAqB,EACrB,cAAsB,EACtB,OAAe,EACf,WAAmB,EAC5B,SAAiB,EACjB,OAAe,EACf,SAAiB,EACjB,OAAe,EACf,UAAkB,EAClB,MAAc,EACd,cAAsB,EACtB,aAAqB,EACrB,aAAqB,EACrB,OAAe,EACf,MAA0B,EAC1B,KAAwB,EACxB,oBAA4B,EAC5B,qBAA6B,EAC7B,WAAwB;QAE/B,KAAK,CACH,EAAE,EACF,OAAO,EACP,aAAa,EACb,SAAS,EACT,QAAQ,EACR,cAAc,EACd,UAAU,EACV,aAAa,EACb,cAAc,EACd,OAAO,EACP,WAAW,CACZ,CAAC;QAvCc,OAAE,GAAF,EAAE,CAAQ;QACV,YAAO,GAAP,OAAO,CAAQ;QACf,kBAAa,GAAb,aAAa,CAAQ;QACrB,cAAS,GAAT,SA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,CAAC;6BACjC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;qBAC5B;oBACD,OAAO,CAAC,CAAC;wBACP,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;qBAC/C;iBACF;aACF;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC;IAAA,CAAC;IAEF;;OAEG;IACM,QAAQ;QACf,uCACK,KAAK,CAAC,QAAQ,EAAE,KACnB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,GAAG,EAChC,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,GAAG,EAC5B,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,GAAG,EAC5B,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,GAAG,EACpC,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,GAAG,EAChC,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,GAAG,EAClC,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,CAAC,EACxC,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,CAAC,EACtC,QAAQ,EAAE,IAAI,CAAC,MAAM,IAAI,GAAG,IAC5B;IACJ,CAAC;CACF;AA1jBD,kCA0jBC","sourcesContent":["import { isFileDto, VasFileDto } from './vas-file.dto';\nimport { UUID } from 'angular2-uuid';\nimport moment from 'moment';\nimport { getValueByPath } from '../utils/get-value-by-path';\nimport { VasBaseDto } from './vas-base.dto';\nimport { VasFieldDto, VasFieldDtoValue } from './vas-field.dto';\nimport { VasFieldModel } from './vas-field.model';\nimport { VasFormModel } from './vas-form.model';\nimport { VasJobDto } from './vas-job.dto';\nimport { VasRestrictedAccountObjectModel } from './vas-restricted-account-object.model';\nimport { GeoLocation, getEmptyGeoLocation } from '../model/geo-location';\nimport { isCameraControlValueV1, VasCameraControlValueModel } from '../control-value/vas-camera-control-value.model';\nimport { isArrayString } from '../utils/is-array-string';\n\nexport declare interface VasJobModelDynamicInterface {\n [s: string]: string | number | Record<string, VasFieldDtoValue>;\n}\n\nexport interface ParseSyntaxOptions {\n // This value will be used to adjust any datetime values that are referenced\n // in the syntax string. See\n // https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/09-utc-offset/\n // for more information about how `moment` will handle the value.\n timeZoneOffset: number,\n // this dictionary can be passed in to contain other objects to be referenced\n // in the syntax. For example if we have {job.foo} this will reference the\n // job's `foo` property, however if we have \"reportLayout.title\" this will\n // expect to find a property of `objects` called `reportLayout` which will\n // have a property called `title`\n objects?: Record<string, Partial<VasBaseDto> | Record<string, VasFieldDtoValue>>;\n}\n\n/**\n * JobModel\n */\nexport class VasJobModel extends VasRestrictedAccountObjectModel {\n\n constructor(\n public override id: string,\n public override created: string,\n public override serverCreated: string,\n public override createdBy: string,\n public override modified: string,\n public override serverModified: string,\n public override modifiedBy: string,\n public override createdByName: string,\n public override modifiedByName: string,\n public override account: string,\n public override accessGroup: string,\n public reference: string,\n public jobDate: string,\n public jobStatus: string,\n public jobType: string,\n public assigneeId: string,\n public formId: string,\n public timeZoneOffset: number,\n public pendingFields: number,\n public childModified: string,\n public version: number,\n public fields: Array<VasFieldDto>,\n public files: Array<VasFileDto>,\n public createdByDisplayName: string,\n public modifiedByDisplayName: string,\n public geoLocation: GeoLocation\n ) {\n super(\n id,\n created,\n serverCreated,\n createdBy,\n modified,\n serverModified,\n modifiedBy,\n createdByName,\n modifiedByName,\n account,\n accessGroup\n );\n }\n\n /**\n * Returns this with the dynamic interface\n * @return {VasJobModelDynamicInterface}\n */\n get $this(): VasJobModelDynamicInterface {\n return this as any;\n }\n\n /**\n * Returns a list of Job dynamic properties i.e. those that are added by the\n * dynamic forms\n */\n get dynamicProperties(): Array<string> {\n const nativeProps = this.staticProperties;\n return Object\n .getOwnPropertyNames(this)\n .filter(prop => !nativeProps.includes(prop));\n }\n\n /**\n * Returns a list of Job static properties i.e. those that are declared by\n * the type\n */\n get staticProperties(): Array<string> {\n return Object.getOwnPropertyNames(VasJobModel.empty());\n }\n\n /**\n * @return {VasJobModel}\n */\n static empty(): VasJobModel {\n return new VasJobModel(\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n moment().utcOffset(),\n 0,\n '',\n 0,\n [],\n [],\n '',\n '',\n getEmptyGeoLocation()\n );\n }\n\n static override fromDto(dto: Partial<VasJobDto>): VasJobModel {\n const model = new VasJobModel(\n dto.id || '',\n dto.created || '',\n dto.serverCreated || '',\n dto.createdBy || '',\n dto.modified || '',\n dto.serverModified || '',\n dto.modifiedBy || '',\n dto.createdByName || '',\n dto.modifiedByName || '',\n dto.account || '',\n dto.accessGroup || '',\n dto.reference || '',\n dto.jobDate || '',\n dto.jobStatus || '',\n dto.jobType || '',\n dto.assigneeId || '',\n dto.formId || '',\n dto.timeZoneOffset || moment().utcOffset(),\n dto.pendingFields || 0,\n dto.childModified || '',\n dto.version || 0,\n dto.fields || [],\n dto.files || [],\n dto.createdByDisplayName || '',\n dto.modifiedByDisplayName || '',\n dto.geoLocation || getEmptyGeoLocation()\n );\n const emptyKeys = model.staticProperties;\n Object\n .keys(dto)\n .filter(key => emptyKeys.indexOf(key) === -1)\n .forEach((key: string) =>\n model.$this[key] = (dto as VasJobModelDynamicInterface)[key]\n );\n return model;\n }\n\n /**\n * @param {VasFormModel} formModel\n * @return {Record<string, VasFieldDtoValue>}\n */\n getFields(formModel: VasFormModel): Record<string, VasFieldDtoValue> {\n const fields: { [key: string]: VasFieldDtoValue } = {};\n formModel.groups\n .forEach(group => {\n group.controls.forEach(control => {\n (fields)[control.reportTemplateName] =\n this.getValueByPath([group.name, control.name]);\n });\n });\n return fields;\n }\n\n /**\n * Will return an object whose keys are the names of all fields in the job.\n * This method is similar to `getFields` except that this method will only\n * return values where a value was set, as opposed to `getFields` which\n * return a property regardless (because it uses the form to drive the logic)\n * @return {Record<string, VasFieldDtoValue>}\n */\n getFields2(): Record<string, VasFieldDtoValue> {\n let fields: { [key: string]: VasFieldDtoValue } = {};\n this.dynamicProperties\n .forEach((groupName) => {\n Object\n .keys(this.$this[groupName])\n .forEach(controlName => {\n fields[controlName] = this.getValueByPath([groupName, controlName]);\n });\n }, {});\n return fields;\n }\n\n /**\n * Returns an object describing how many attachments were added to this job\n * (camera controls and files), and how many have not been uploaded yet.\n *\n * @param formModel instance of {@link VasFormModel} that was used when the\n * job was created\n */\n getFilesUploadStatus(\n formModel: VasFormModel\n ): { pending: number; total: number } {\n\n const pathsWithValue: Array<Array<string>> = formModel\n .getCameraControlPaths()\n .map(path => {\n const value: VasFileDto | VasCameraControlValueModel =\n this.getValueByPath(path) as any;\n if (value && !!value.id) {\n return path;\n }\n return null;\n })\n .filter(path => path !== null ? path : null)\n .filter(isArrayString);\n\n let total = pathsWithValue.length;\n\n total += this.files.length;\n\n // calculate the number of camera images still to upload\n let pending = pathsWithValue\n .map(path => this.getValueByPath(path) as any)\n .map((value: VasFileDto | VasCameraControlValueModel) => {\n if (isFileDto(value)) {\n return value.id && value.status !== 'COMPLETE';\n } else if (isCameraControlValueV1(value)) {\n // if url is not set, it hasn't been uploaded\n return value.id && !value.url;\n }\n return false;\n })\n .filter(hasUploaded => hasUploaded)\n .length;\n\n // add total from files that are pending\n pending += this.files\n .filter(value => value.status !== 'COMPLETED')\n .length;\n\n return {\n pending,\n total\n };\n }\n\n /**\n * This method will hydrate the `fields` property of the model. The reason for\n * this is that we have different ways to store the field data. One way, is\n * we store them as dynamic properties of the job. For example job.foo.bar,\n * where `foo` is the name of a Group, and `bar` is the name of a control.\n * Thus, when we create a job using a form in the client, the job object will\n * have its static properties (id, account, reference etc), and also a number\n * of dynamic properties determined by the Groups and Controls. This kind of\n * object is nice to work with in certain circumstances. However, the api\n * works differently. In the API a Job is a record, and references a number of\n * Field records. Each Field stores the value. Comparing these two models we\n * have:\n * A) job with dynamic properties, e.g.\n * {\n * id: <guid>,\n * reference: \"something\"\n * <other static job properties>...\n * foo: {\n * bar: \"value\"\n * }\n * }\n *\n * B) job with fields\n * {\n * id: <guid>,\n * reference: \"something\"\n * <other static job properties>...\n * <will not have dynamic properties>...\n * fields: [\n * {\n * id: <guid>,\n * <other field properties>,\n * value: \"value\"\n * }\n * ]\n * }\n *\n * So, what this method does is given a JobModel in the form of A, read all\n * of those dynamic properties and set them into `fields`. Doing this requires\n * knowledge of the Form that was used to create the job. Moreover, since the\n * dynamic properties do not contain the ids of the fields, we also allow to\n * pass in a `controlFieldIdMap`. This map stores the mapping between Control\n * and the Field that was created in the Job to store the value for that\n * Control. This is useful, if for example you want to compare a Job in form A\n * with a Job in form B, for example if you want to update the Job on the API\n * with a Job that was saved by a client in form A.\n *\n * E.g.\n * Client -> API: client requests form\n * User -> Client: user fills in the form and submits\n * Client -> Firestore: client saves the Job in form A i.e. dynamic props\n * Firestore -> Function: A function is triggered to sync the job to the API\n * Function -> API: Function checks if job already exists, it receives 404\n * Function -> Function: The function calls `hydrateFields(...)`\n * Function -> API: The function POST the Job to /jobs\n * Function -> API: The function POST each field to /fields\n *\n * Similarly, if the user updates the job\n * Client -> API: client requests form\n * User -> Client: user fills in the form and submits an update\n * Client -> Firestore: client saves the Job in form A i.e. dynamic props\n * Firestore -> Function: A function is triggered to sync the job to the API\n * Function -> API: Function checks if job already exists, it receives 200\n * Function -> Function: The function calls `hydrateFields(...)` passing in\n * the map is made by iterating over the fields it\n * received from the API and storing the mappings\n * between controlId and fieldId for each field\n * Function -> API: The function PATCH the Job to /jobs\n * Function -> API: The function POST/PATCH each field to /fields\n * treated as new\n *\n * @param {VasFormModel} formModel the VasFormModel that was used to create\n * the job\n * @param {Map<string, string>} controlFieldIdMap a mapping of control to\n * field ids. This is used to determine whether a new id for the field should\n * be generated, or to reuse an existing one from the map.\n * @param {Array<string>} controlNames if a value is provided, it will be used\n * to filter the fields that are returned.\n * @return {Array<VasFieldDto>}\n */\n hydrateFields(\n formModel: VasFormModel,\n controlFieldIdMap: Map<string, string> = new Map<string, string>(),\n controlNames?: Array<string>\n ): void {\n const fields: Array<VasFieldDto> = [];\n formModel.groups\n .forEach(group => {\n group.controls.forEach(control => {\n\n if (!control.name.startsWith('fields.')) {\n return;\n }\n\n if (controlNames && !controlNames.includes(control.name)) {\n return;\n }\n\n fields.push(VasFieldModel.fromDto({\n // if the controlId exists in the map, use the associated fieldId,\n // otherwise generate a new id for the field.\n id: controlFieldIdMap.get(control.id) || UUID.UUID(),\n account: this.account,\n job: this.id,\n createdBy: this.createdBy,\n created: this.created,\n modifiedBy: this.modifiedBy,\n modified: this.modified,\n control: control.id,\n value: this.getValueByPath(\n [group.name, control.name]\n )\n }));\n });\n });\n this.fields = fields;\n }\n\n /**\n * @param {string[]} path path segments\n * @return {void}\n */\n getValueByPath<T extends VasFieldDtoValue>(\n path: string[] = []\n ): T | undefined {\n return getValueByPath(path, this.$this);\n }\n\n /**\n * A very non sophisticated way to set values in the job via paths\n *\n * For example:\n *\n * setValueByPath('value', ['foo', 'bar']);\n *\n * will make results in job\n * {\n * foo: {\n * bar: 'value'\n * }\n * }\n *\n * @param {any} value the value to set\n * @param {string[]} path path segments\n */\n setValueByPath(value: VasFieldDtoValue, path: string[] = []): void {\n switch (path.length) {\n case 0: {\n return;\n }\n case 1: {\n (this as any)[path[0]] = value;\n return;\n }\n case 2: {\n // eslint-disable-next-line max-len\n (this.$this[path[0]] as Record<string, VasFieldDtoValue>)[path[1]] = value;\n return;\n }\n case 3: {\n // eslint-disable-next-line max-len\n ((this.$this[path[0]] as Record<string, VasFieldDtoValue>)[path[1]] as Record<string, VasFieldDtoValue>)[path[2]] = value;\n return;\n }\n default: {\n throw Error('path has too many segments');\n }\n }\n }\n\n /**\n * @param {boolean} staticOnly if true, will only output values for the static\n * properties in the dto\n * @return {VasJobDto}\n */\n toDto(staticOnly = false): VasJobDto {\n\n if (staticOnly) {\n return {\n id: this.id,\n created: this.created,\n createdBy: this.createdBy,\n modified: this.modified,\n modifiedBy: this.modifiedBy,\n serverCreated: this.serverCreated,\n serverModified: this.serverModified,\n createdByName: this.createdByName,\n modifiedByName: this.modifiedByName,\n account: this.account,\n accessGroup: this.accessGroup,\n reference: this.reference,\n jobDate: this.jobDate,\n jobStatus: this.jobStatus,\n jobType: this.jobType,\n assigneeId: this.assigneeId,\n formId: this.formId,\n timeZoneOffset: this.timeZoneOffset,\n pendingFields: this.pendingFields,\n childModified: this.childModified,\n version: this.version,\n fields: this.fields,\n files: this.files,\n createdByDisplayName: this.createdByDisplayName,\n modifiedByDisplayName: this.modifiedByDisplayName,\n geoLocation: this.geoLocation\n };\n }\n\n const dto = {} as VasJobModelDynamicInterface;\n [...this.staticProperties, ...this.dynamicProperties]\n .forEach(prop =>\n (dto)[prop] = this.$this[prop]);\n\n return dto as any;\n }\n\n /**\n * This method will parse a syntax that allows us to build strings from the\n * values of from the job model. For example if the job model was:\n *\n * {\n * foo: 'bar'\n * }\n *\n * and we pass \"i am foo {foo}\", the result would be:\n *\n * \"i am foo bar\"\n *\n * we can also use moment to parse dates, for example if the job model was:\n *\n * {\n * created: \"2022-01-01T00:00:00+0000\"\n * }\n *\n * and we pass \"{created|date:YY-MM-DD}\", the result would be:\n *\n * \"2022-01-01\"\n *\n * @param {string} value a string with the syntax\n * @param {ParseSyntaxOptions} options\n * @return {string} the results of parsing the syntax on this job\n */\n parseSyntax(\n value: string,\n options: ParseSyntaxOptions = {\n timeZoneOffset: 0\n }\n ): string {\n\n if (!value || typeof value !== 'string') {\n return '';\n }\n return value.replace(/({[^}]*})/g, (match: string, token: string) => {\n const syntax = token.substring(1, token.length - 1);\n\n let [key, filter] = syntax.split('|');\n key = (key || '').trim();\n filter = (filter || '').trim();\n\n let filterName, filterArg: string = '';\n if (filter) {\n const splitIndex = filter.indexOf(':');\n if (splitIndex !== -1) {\n filterName = filter.substring(0, splitIndex);\n filterArg = filter.substring(splitIndex + 1);\n } else {\n filterName = filter;\n filterArg = '';\n }\n filterName = (filterName || '').trim();\n filterArg = (filterArg || '').trim();\n }\n const path = key.split('.');\n const objectKey = path.shift() || '';\n let result = '';\n if (objectKey === 'job') {\n result = (this.getValueByPath(path) || '').toString();\n } else if (objectKey === 'fields') {\n result = (getValueByPath(path, this.getFields2()) || '').toString();\n } else if (objectKey.length) {\n if (options.objects) {\n if (options.objects[objectKey] === undefined) {\n console.debug(\n `objectKey ${objectKey} is not present in options.object`\n );\n result = '';\n } else {\n result = (getValueByPath(path, options.objects[objectKey]) || '')\n .toString();\n }\n } else {\n console.debug(\n `objectKey ${objectKey} was used but options.object is not set`\n );\n return '';\n }\n } else {\n return '';\n }\n\n\n if (filterName && result) {\n switch (filterName) {\n case 'date': {\n return moment(result)\n .utcOffset(options.timeZoneOffset)\n .format(filterArg || '');\n }\n default: {\n console.warn('unknown filter %s', filterName);\n }\n }\n }\n\n return result;\n }).trim();\n };\n\n /**\n * @return {object}\n */\n override toApiDto(): Record<string, string | number | boolean> {\n return {\n ...super.toApiDto(),\n reference: this.reference || '~',\n jobDate: this.jobDate || '~',\n jobType: this.jobType || '~',\n accessGroup: this.accessGroup || '~',\n jobStatus: this.jobStatus || '~',\n assigneeId: this.assigneeId || '~',\n timeZoneOffset: this.timeZoneOffset || 0,\n pendingFields: this.pendingFields || 0,\n lastForm: this.formId || '~'\n };\n }\n}\n"]}
1
+ {"version":3,"file":"vas-job.model.js","sourceRoot":"","sources":["../../../../../projects/vas-lib/src/lib/entity/vas-job.model.ts"],"names":[],"mappings":";;;;AAAA,iDAAuD;AACvD,iDAAqC;AACrC,4DAA4B;AAC5B,kEAA4D;AAG5D,uDAAkD;AAGlD,+FAAwF;AACxF,wDAAyE;AACzE,oGAAqH;AACrH,8DAAyD;AAqBzD;;GAEG;AACH,MAAa,WAAY,SAAQ,qEAA+B;IAE9D,YACkB,EAAU,EACV,OAAe,EACf,aAAqB,EACrB,SAAiB,EACjB,QAAgB,EAChB,cAAsB,EACtB,UAAkB,EAClB,aAAqB,EACrB,cAAsB,EACtB,OAAe,EACf,WAAmB,EAC5B,SAAiB,EACjB,OAAe,E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AAK,CACX,aAAa,SAAS,yCAAyC,CAChE,CAAC;oBACF,OAAO,EAAE,CAAC;iBACX;aACF;iBAAM;gBACL,OAAO,EAAE,CAAC;aACX;YAGD,IAAI,UAAU,IAAI,MAAM,EAAE;gBACxB,QAAQ,UAAU,EAAE;oBAClB,KAAK,MAAM,CAAC,CAAC;wBACX,OAAO,IAAA,gBAAM,EAAC,MAAM,CAAC;6BAClB,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC;6BACjC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;qBAC5B;oBACD,OAAO,CAAC,CAAC;wBACP,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;qBAC/C;iBACF;aACF;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC;IAAA,CAAC;IAEF;;OAEG;IACM,QAAQ;QACf,uCACK,KAAK,CAAC,QAAQ,EAAE,KACnB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,GAAG,EAChC,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,GAAG,EAC5B,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,GAAG,EAC5B,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,GAAG,EACpC,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,GAAG,EAChC,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,GAAG,EAClC,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,CAAC,EACxC,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,CAAC,EACtC,QAAQ,EAAE,IAAI,CAAC,MAAM,IAAI,GAAG,IAC5B;IACJ,CAAC;CACF;AAhnBD,kCAgnBC","sourcesContent":["import { isFileDto, VasFileDto } from './vas-file.dto';\nimport { UUID } from 'angular2-uuid';\nimport moment from 'moment';\nimport { getValueByPath } from '../utils/get-value-by-path';\nimport { VasBaseDto } from './vas-base.dto';\nimport { VasFieldDto, VasFieldDtoValue } from './vas-field.dto';\nimport { VasFieldModel } from './vas-field.model';\nimport { VasFormModel } from './vas-form.model';\nimport { VasJobDto } from './vas-job.dto';\nimport { VasRestrictedAccountObjectModel } from './vas-restricted-account-object.model';\nimport { GeoLocation, getEmptyGeoLocation } from '../model/geo-location';\nimport { isCameraControlValueV1, VasCameraControlValueModel } from '../control-value/vas-camera-control-value.model';\nimport { isArrayString } from '../utils/is-array-string';\nimport { VasFormDto } from './vas-form.dto';\n\nexport declare interface VasJobModelDynamicInterface {\n [s: string]: string | number | Record<string, VasFieldDtoValue>;\n}\n\nexport interface ParseSyntaxOptions {\n // This value will be used to adjust any datetime values that are referenced\n // in the syntax string. See\n // https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/09-utc-offset/\n // for more information about how `moment` will handle the value.\n timeZoneOffset: number,\n // this dictionary can be passed in to contain other objects to be referenced\n // in the syntax. For example if we have {job.foo} this will reference the\n // job's `foo` property, however if we have \"reportLayout.title\" this will\n // expect to find a property of `objects` called `reportLayout` which will\n // have a property called `title`\n objects?: Record<string, Partial<VasBaseDto> | Record<string, VasFieldDtoValue>>;\n}\n\n/**\n * JobModel\n */\nexport class VasJobModel extends VasRestrictedAccountObjectModel {\n\n constructor(\n public override id: string,\n public override created: string,\n public override serverCreated: string,\n public override createdBy: string,\n public override modified: string,\n public override serverModified: string,\n public override modifiedBy: string,\n public override createdByName: string,\n public override modifiedByName: string,\n public override account: string,\n public override accessGroup: string,\n public reference: string,\n public jobDate: string,\n public jobStatus: string,\n public jobType: string,\n public assigneeId: string,\n public formId: string,\n public timeZoneOffset: number,\n public pendingFields: number,\n public childModified: string,\n public version: number,\n public fields: Array<VasFieldDto>,\n public files: Array<VasFileDto>,\n public createdByDisplayName: string,\n public modifiedByDisplayName: string,\n public geoLocation: GeoLocation\n ) {\n super(\n id,\n created,\n serverCreated,\n createdBy,\n modified,\n serverModified,\n modifiedBy,\n createdByName,\n modifiedByName,\n account,\n accessGroup\n );\n }\n\n /**\n * Returns this with the dynamic interface\n * @return {VasJobModelDynamicInterface}\n */\n get $this(): VasJobModelDynamicInterface {\n return this as any;\n }\n\n /**\n * Returns a list of Job dynamic properties i.e. those that are added by the\n * dynamic forms\n */\n get dynamicProperties(): Array<string> {\n const nativeProps = this.staticProperties;\n return Object\n .getOwnPropertyNames(this)\n .filter(prop => !nativeProps.includes(prop));\n }\n\n /**\n * Returns the list of properties of the Job type\n */\n get staticProperties(): Array<string> {\n return Object.getOwnPropertyNames(VasJobModel.empty());\n }\n\n /**\n * @return {VasJobModel}\n */\n static empty(): VasJobModel {\n return new VasJobModel(\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n '',\n moment().utcOffset(),\n 0,\n '',\n 0,\n [],\n [],\n '',\n '',\n getEmptyGeoLocation()\n );\n }\n\n static override fromDto(dto: Partial<VasJobDto>): VasJobModel {\n const model = new VasJobModel(\n dto.id || '',\n dto.created || '',\n dto.serverCreated || '',\n dto.createdBy || '',\n dto.modified || '',\n dto.serverModified || '',\n dto.modifiedBy || '',\n dto.createdByName || '',\n dto.modifiedByName || '',\n dto.account || '',\n dto.accessGroup || '',\n dto.reference || '',\n dto.jobDate || '',\n dto.jobStatus || '',\n dto.jobType || '',\n dto.assigneeId || '',\n dto.formId || '',\n dto.timeZoneOffset || moment().utcOffset(),\n dto.pendingFields || 0,\n dto.childModified || '',\n dto.version || 0,\n dto.fields || [],\n dto.files || [],\n dto.createdByDisplayName || '',\n dto.modifiedByDisplayName || '',\n dto.geoLocation || getEmptyGeoLocation()\n );\n const emptyKeys = model.staticProperties;\n Object\n .keys(dto)\n .filter(key => emptyKeys.indexOf(key) === -1)\n .forEach((key: string) =>\n model.$this[key] = (dto as VasJobModelDynamicInterface)[key]\n );\n return model;\n }\n\n /**\n * This method will instantiate a new JobModel. The difference with this\n * method of instantiation is that we are coming from a relation frame i.e.\n * the job has a list of {@link VasFieldDto} instead of a Job document.\n *\n */\n static fromRelational(\n dto: Partial<VasJobDto>,\n form: VasFormDto\n ): VasJobModel {\n const model = new VasJobModel(\n dto.id || '',\n dto.created || '',\n dto.serverCreated || '',\n dto.createdBy || '',\n dto.modified || '',\n dto.serverModified || '',\n dto.modifiedBy || '',\n dto.createdByName || '',\n dto.modifiedByName || '',\n dto.account || '',\n dto.accessGroup || '',\n dto.reference || '',\n dto.jobDate || '',\n dto.jobStatus || '',\n dto.jobType || '',\n dto.assigneeId || '',\n dto.formId || '',\n dto.timeZoneOffset || moment().utcOffset(),\n dto.pendingFields || 0,\n dto.childModified || '',\n dto.version || 0,\n dto.fields || [],\n dto.files || [],\n dto.createdByDisplayName || '',\n dto.modifiedByDisplayName || '',\n dto.geoLocation || getEmptyGeoLocation()\n );\n\n form.groups\n .forEach(group => {\n group.controls\n .forEach(control => {\n const field = dto.fields?.find(f => f.control === control.id);\n if (!field) {\n return;\n }\n model.getGroup(group.name)[control.name] = field.value;\n });\n });\n return model;\n }\n\n /**\n * @param {VasFormModel} formModel\n * @return {Record<string, VasFieldDtoValue>}\n */\n getFields(formModel: VasFormModel): Record<string, VasFieldDtoValue> {\n const fields: { [key: string]: VasFieldDtoValue } = {};\n formModel.groups\n .forEach(group => {\n group.controls.forEach(control => {\n (fields)[control.reportTemplateName] =\n this.getValueByPath([group.name, control.name]);\n });\n });\n return fields;\n }\n\n /**\n * Will return an object whose keys are the names of all fields in the job.\n * This method is similar to `getFields` except that this method will only\n * return values where a value was set, as opposed to `getFields` which\n * return a property regardless (because it uses the form to drive the logic)\n * @return {Record<string, VasFieldDtoValue>}\n */\n protected getFields2(): Record<string, VasFieldDtoValue> {\n let fields: { [key: string]: VasFieldDtoValue } = {};\n this.dynamicProperties\n .forEach((groupName) => {\n Object\n .keys(this.$this[groupName])\n .forEach(controlName => {\n fields[controlName] = this.getValueByPath([groupName, controlName]);\n });\n }, {});\n return fields;\n }\n\n /**\n * Returns an object describing how many attachments were added to this job\n * (camera controls and files), and how many have not been uploaded yet.\n *\n * @param formModel instance of {@link VasFormModel} that was used when the\n * job was created\n */\n getFilesUploadStatus(\n formModel: VasFormModel\n ): { pending: number; total: number } {\n\n const pathsWithValue: Array<Array<string>> = formModel\n .getCameraControlPaths()\n .map(path => {\n const value: VasFileDto | VasCameraControlValueModel =\n this.getValueByPath(path) as any;\n if (value && !!value.id) {\n return path;\n }\n return null;\n })\n .filter(path => path !== null ? path : null)\n .filter(isArrayString);\n\n let total = pathsWithValue.length;\n\n total += this.files.length;\n\n // calculate the number of camera images still to upload\n let pending = pathsWithValue\n .map(path => this.getValueByPath(path) as any)\n .map((value: VasFileDto | VasCameraControlValueModel) => {\n if (isFileDto(value)) {\n return value.id && value.status !== 'COMPLETE';\n } else if (isCameraControlValueV1(value)) {\n // if url is not set, it hasn't been uploaded\n return value.id && !value.url;\n }\n return false;\n })\n .filter(hasUploaded => hasUploaded)\n .length;\n\n // add total from files that are pending\n pending += this.files\n .filter(value => value.status !== 'COMPLETED')\n .length;\n\n return {\n pending,\n total\n };\n }\n\n /**\n * This method will return the dynamic property from the JobModel that\n * represent a group (from a form).\n *\n * @param name the name of the group\n * @param init if true (default) and group is not found, initialise an empty\n * group, otherwise throw an error\n */\n getGroup(name: string, init = true): Record<string, VasFieldDtoValue> {\n let prop;\n if (this.staticProperties.includes(name)) {\n throw Error(`invalid group name ${name}, not a dynamic property`);\n } else if (this.$this[name] === undefined) {\n if (init) {\n prop = this.$this[name] = {};\n } else {\n throw Error(`invalid group name ${name}, not found`);\n }\n } else {\n prop = this.$this[name];\n if (typeof prop !== 'object') {\n throw Error(`invalid group name ${name}, not an object`);\n }\n }\n return prop;\n }\n\n /**\n * @param path path segments\n */\n getValueByPath<T extends VasFieldDtoValue>(\n path: string[] = []\n ): T | undefined {\n return getValueByPath(path, this.$this);\n }\n\n /**\n * In order to understand why we need this method it is important to\n * understand that within the system, Jobs can be represented in one of two\n * ways, document and relational.\n *\n * The important distinction is how values submitted by a form are stored.\n *\n * Jobs stored as documents (JSON objects) will store user values, as dynamic\n * properties of the document.\n *\n * Whereas, Jobs stored as relational, will store user values in an array of\n * {@link VasFieldDto} objects.\n *\n * Depending on where we are in the system, either one of these approaches can\n * be more useful than the other.\n *\n * This method, assumes that the JobModel has been instantiated from a\n * document representation, and serves to hydrate the fields array. In order\n * to achieve this, knowledge of the {@link VasFormDto} that created the job\n * is required.\n *\n *\n * Job in document representation\n * {\n * id: <guid>,\n * reference: \"something\"\n * <other static job properties>...\n * foo: {\n * bar: \"value\"\n * }\n * }\n *\n * Job in relational representation\n * {\n * id: <guid>,\n * reference: \"something\"\n * <other static job properties>...\n * <will not have dynamic properties>...\n * fields: [\n * {\n * id: <guid>,\n * <other field properties>,\n * value: \"value\"\n * }\n * ]\n * }\n *\n *\n * @param formModel the VasFormModel that was used to create the job\n * @param controlFieldIdMap This is used to determine the id each field.\n * Either one will be found in the map, or a new one is generated.\n * @param controlNames if a value is provided, it will be used\n * to filter the fields that are returned.\n * @return {Array<VasFieldDto>}\n */\n hydrateFields(\n formModel: VasFormModel,\n controlFieldIdMap: Map<string, string> = new Map<string, string>(),\n controlNames?: Array<string>\n ): void {\n const fields: Array<VasFieldDto> = [];\n formModel.groups\n .forEach(group => {\n group.controls.forEach(control => {\n\n if (!control.name.startsWith('fields.')) {\n return;\n }\n\n if (controlNames && !controlNames.includes(control.name)) {\n return;\n }\n\n fields.push(VasFieldModel.fromDto({\n // if the controlId exists in the map, use the associated fieldId,\n // otherwise generate a new id for the field.\n id: controlFieldIdMap.get(control.id) || UUID.UUID(),\n account: this.account,\n job: this.id,\n createdBy: this.createdBy,\n created: this.created,\n modifiedBy: this.modifiedBy,\n modified: this.modified,\n control: control.id,\n value: this.getValueByPath(\n [group.name, control.name]\n )\n }));\n });\n });\n this.fields = fields;\n }\n\n /**\n * A very non sophisticated way to set values in the job via paths\n *\n * For example:\n *\n * setValueByPath('value', ['foo', 'bar']);\n *\n * will make results in job\n * {\n * foo: {\n * bar: 'value'\n * }\n * }\n *\n * @param value the value to set\n * @param path path segments\n */\n setValueByPath(value: VasFieldDtoValue, path: string[] = []): void {\n switch (path.length) {\n case 0: {\n return;\n }\n case 1: {\n (this as any)[path[0]] = value;\n return;\n }\n case 2: {\n // eslint-disable-next-line max-len\n (this.$this[path[0]] as Record<string, VasFieldDtoValue>)[path[1]] = value;\n return;\n }\n case 3: {\n // eslint-disable-next-line max-len\n ((this.$this[path[0]] as Record<string, VasFieldDtoValue>)[path[1]] as Record<string, VasFieldDtoValue>)[path[2]] = value;\n return;\n }\n default: {\n throw Error('path has too many segments');\n }\n }\n }\n\n /**\n * @param staticOnly if true, will only output values for the static\n * properties in the dto\n */\n toDto(staticOnly = false): VasJobDto {\n\n if (staticOnly) {\n return {\n id: this.id,\n created: this.created,\n createdBy: this.createdBy,\n modified: this.modified,\n modifiedBy: this.modifiedBy,\n serverCreated: this.serverCreated,\n serverModified: this.serverModified,\n createdByName: this.createdByName,\n modifiedByName: this.modifiedByName,\n account: this.account,\n accessGroup: this.accessGroup,\n reference: this.reference,\n jobDate: this.jobDate,\n jobStatus: this.jobStatus,\n jobType: this.jobType,\n assigneeId: this.assigneeId,\n formId: this.formId,\n timeZoneOffset: this.timeZoneOffset,\n pendingFields: this.pendingFields,\n childModified: this.childModified,\n version: this.version,\n fields: this.fields,\n files: this.files,\n createdByDisplayName: this.createdByDisplayName,\n modifiedByDisplayName: this.modifiedByDisplayName,\n geoLocation: this.geoLocation\n };\n }\n\n const dto = {} as VasJobModelDynamicInterface;\n [...this.staticProperties, ...this.dynamicProperties]\n .forEach(prop => dto[prop] = this.$this[prop]);\n\n return dto as any;\n }\n\n /**\n * This method will parse a syntax that allows us to build strings from the\n * values of from the job model. For example if the job model was:\n *\n * {\n * foo: 'bar'\n * }\n *\n * and we pass \"i am foo {foo}\", the result would be:\n *\n * \"i am foo bar\"\n *\n * we can also use moment to parse dates, for example if the job model was:\n *\n * {\n * created: \"2022-01-01T00:00:00+0000\"\n * }\n *\n * and we pass \"{created|date:YY-MM-DD}\", the result would be:\n *\n * \"2022-01-01\"\n *\n * @param {string} value a string with the syntax\n * @param {ParseSyntaxOptions} options\n * @return the results of parsing the syntax on this job\n */\n parseSyntax(\n value: string,\n options: ParseSyntaxOptions = {\n timeZoneOffset: 0\n }\n ): string {\n\n if (!value || typeof value !== 'string') {\n return '';\n }\n return value.replace(/({[^}]*})/g, (match: string, token: string) => {\n const syntax = token.substring(1, token.length - 1);\n\n let [key, filter] = syntax.split('|');\n key = (key || '').trim();\n filter = (filter || '').trim();\n\n let filterName, filterArg: string = '';\n if (filter) {\n const splitIndex = filter.indexOf(':');\n if (splitIndex !== -1) {\n filterName = filter.substring(0, splitIndex);\n filterArg = filter.substring(splitIndex + 1);\n } else {\n filterName = filter;\n filterArg = '';\n }\n filterName = (filterName || '').trim();\n filterArg = (filterArg || '').trim();\n }\n const path = key.split('.');\n const objectKey = path.shift() || '';\n let result = '';\n if (objectKey === 'job') {\n result = (this.getValueByPath(path) || '').toString();\n } else if (objectKey === 'fields') {\n result = (getValueByPath(\n ['fields.' + path.shift(), ...path],\n this.getFields2()\n ) || '').toString();\n } else if (objectKey.length) {\n if (options.objects) {\n if (options.objects[objectKey] === undefined) {\n console.debug(\n `objectKey ${objectKey} is not present in options.object`\n );\n result = '';\n } else {\n result = (getValueByPath(path, options.objects[objectKey]) || '')\n .toString();\n }\n } else {\n console.debug(\n `objectKey ${objectKey} was used but options.object is not set`\n );\n return '';\n }\n } else {\n return '';\n }\n\n\n if (filterName && result) {\n switch (filterName) {\n case 'date': {\n return moment(result)\n .utcOffset(options.timeZoneOffset)\n .format(filterArg || '');\n }\n default: {\n console.warn('unknown filter %s', filterName);\n }\n }\n }\n\n return result;\n }).trim();\n };\n\n /**\n * @return {object}\n */\n override toApiDto(): Record<string, string | number | boolean> {\n return {\n ...super.toApiDto(),\n reference: this.reference || '~',\n jobDate: this.jobDate || '~',\n jobType: this.jobType || '~',\n accessGroup: this.accessGroup || '~',\n jobStatus: this.jobStatus || '~',\n assigneeId: this.assigneeId || '~',\n timeZoneOffset: this.timeZoneOffset || 0,\n pendingFields: this.pendingFields || 0,\n lastForm: this.formId || '~'\n };\n }\n}\n"]}