@ironcode/vas-lib 0.0.39 → 0.0.40

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.
@@ -1180,6 +1180,10 @@ const getEmptyGeoLocation = () => ({
1180
1180
  timestamp: ''
1181
1181
  });
1182
1182
 
1183
+ const isArrayString = (value) => {
1184
+ return Array.isArray(value) && value.every(i => typeof i === 'string');
1185
+ };
1186
+
1183
1187
  /**
1184
1188
  * JobModel
1185
1189
  */
@@ -1320,6 +1324,51 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
1320
1324
  }, {});
1321
1325
  return fields;
1322
1326
  }
1327
+ /**
1328
+ * Returns an object describing how many attachments were added to this job
1329
+ * (camera controls and files), and how many have not been uploaded yet.
1330
+ *
1331
+ * @param formModel instance of {@link VasFormModel} that was used when the
1332
+ * job was created
1333
+ */
1334
+ getFilesUploadStatus(formModel) {
1335
+ const pathsWithValue = formModel
1336
+ .getCameraControlPaths()
1337
+ .map(path => {
1338
+ const value = this.getValueByPath(path);
1339
+ if (value && !!value.id) {
1340
+ return path;
1341
+ }
1342
+ return null;
1343
+ })
1344
+ .filter(path => path !== null ? path : null)
1345
+ .filter(isArrayString);
1346
+ let total = pathsWithValue.length;
1347
+ total += this.files.length;
1348
+ // calculate the number of camera images still to upload
1349
+ let pending = pathsWithValue
1350
+ .map(path => this.getValueByPath(path))
1351
+ .map((value) => {
1352
+ if (isFileDto(value)) {
1353
+ return value.id && value.status !== 'COMPLETE';
1354
+ }
1355
+ else if (isCameraControlValueV1(value)) {
1356
+ // if url is not set, it hasn't been uploaded
1357
+ return value.id && !value.url;
1358
+ }
1359
+ return false;
1360
+ })
1361
+ .filter(hasUploaded => hasUploaded)
1362
+ .length;
1363
+ // add total from files that are pending
1364
+ pending += this.files
1365
+ .filter(value => value.status !== 'COMPLETED')
1366
+ .length;
1367
+ return {
1368
+ pending,
1369
+ total
1370
+ };
1371
+ }
1323
1372
  /**
1324
1373
  * This method will hydrate the `fields` property of the model. The reason for
1325
1374
  * this is that we have different ways to store the field data. One way, is
@@ -1429,7 +1478,6 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
1429
1478
  this.fields = fields;
1430
1479
  }
1431
1480
  /**
1432
-
1433
1481
  * @param {string[]} path path segments
1434
1482
  * @return {void}
1435
1483
  */