From 3b4c1c343701a30eee889c30f0530cf20647767e Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Mon, 4 Mar 2024 18:40:48 +0800 Subject: [PATCH] added `OrderConfigModel` for order config refactor, also fixed date formats --- addon/models/contact.js | 4 +- addon/models/customer.js | 4 +- addon/models/driver.js | 4 +- addon/models/entity.js | 4 +- addon/models/facilitator.js | 4 +- addon/models/fleet-driver.js | 4 +- addon/models/fleet.js | 4 +- addon/models/fuel-report.js | 4 +- addon/models/issue.js | 4 +- addon/models/order-config.js | 112 ++++++++++++++++++++++-- addon/models/order.js | 10 +-- addon/models/payload.js | 4 +- addon/models/place.js | 4 +- addon/models/purchase-rate.js | 4 +- addon/models/route.js | 4 +- addon/models/service-area.js | 4 +- addon/models/service-quote-item.js | 4 +- addon/models/service-quote.js | 4 +- addon/models/service-rate-fee.js | 4 +- addon/models/service-rate-parcel-fee.js | 4 +- addon/models/service-rate.js | 4 +- addon/models/tracking-number.js | 4 +- addon/models/tracking-status.js | 4 +- addon/models/vehicle-device.js | 4 +- addon/models/vehicle.js | 4 +- addon/models/vendor.js | 4 +- addon/models/zone.js | 4 +- 27 files changed, 162 insertions(+), 60 deletions(-) diff --git a/addon/models/contact.js b/addon/models/contact.js index f41e39f..5f7ec7a 100644 --- a/addon/models/contact.js +++ b/addon/models/contact.js @@ -52,7 +52,7 @@ export default class ContactModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -73,6 +73,6 @@ export default class ContactModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/customer.js b/addon/models/customer.js index c494d2e..895d1da 100644 --- a/addon/models/customer.js +++ b/addon/models/customer.js @@ -31,7 +31,7 @@ export default class CustomerModel extends ContactModel { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -52,6 +52,6 @@ export default class CustomerModel extends ContactModel { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/driver.js b/addon/models/driver.js index e5ebcbc..c3fe131 100644 --- a/addon/models/driver.js +++ b/addon/models/driver.js @@ -94,7 +94,7 @@ export default class DriverModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -115,7 +115,7 @@ export default class DriverModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } @computed('location') get latitude() { diff --git a/addon/models/entity.js b/addon/models/entity.js index e4e69a4..e4628e8 100644 --- a/addon/models/entity.js +++ b/addon/models/entity.js @@ -103,7 +103,7 @@ export default class EntityModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -124,6 +124,6 @@ export default class EntityModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/facilitator.js b/addon/models/facilitator.js index 4d4c96e..a205889 100644 --- a/addon/models/facilitator.js +++ b/addon/models/facilitator.js @@ -39,7 +39,7 @@ export default class FacilitatorModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -60,6 +60,6 @@ export default class FacilitatorModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/fleet-driver.js b/addon/models/fleet-driver.js index f4bf62e..d10c63d 100644 --- a/addon/models/fleet-driver.js +++ b/addon/models/fleet-driver.js @@ -35,7 +35,7 @@ export default class FleetDriverModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -56,6 +56,6 @@ export default class FleetDriverModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/fleet.js b/addon/models/fleet.js index cc871bc..6ffb3f9 100644 --- a/addon/models/fleet.js +++ b/addon/models/fleet.js @@ -57,7 +57,7 @@ export default class FleetModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -78,6 +78,6 @@ export default class FleetModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/fuel-report.js b/addon/models/fuel-report.js index 8a93515..00d8bbf 100644 --- a/addon/models/fuel-report.js +++ b/addon/models/fuel-report.js @@ -55,7 +55,7 @@ export default class FuelReportModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -76,7 +76,7 @@ export default class FuelReportModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } /** @methods */ diff --git a/addon/models/issue.js b/addon/models/issue.js index 9b85934..46f13a1 100644 --- a/addon/models/issue.js +++ b/addon/models/issue.js @@ -58,7 +58,7 @@ export default class IssueModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -79,7 +79,7 @@ export default class IssueModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } /** @methods */ diff --git a/addon/models/order-config.js b/addon/models/order-config.js index d4d5e89..e43d490 100644 --- a/addon/models/order-config.js +++ b/addon/models/order-config.js @@ -1,7 +1,109 @@ -import ExtensionModel from '@fleetbase/console/models/extension'; -import { attr } from '@ember-data/model'; +import Model, { attr, belongsTo } from '@ember-data/model'; +import { computed, action } from '@ember/object'; +import { format as formatDate, formatDistanceToNow, isValid as isValidDate } from 'date-fns'; -export default class OrderConfigModel extends ExtensionModel { - @attr('string') install_uuid; - @attr('boolean') installed; +export default class OrderConfigModel extends Model { + /** @ids */ + @attr('string') company_uuid; + @attr('string') author_uuid; + @attr('string') category_uuid; + @attr('string') icon_uuid; + + /** @relationships */ + @belongsTo('user') author; + @belongsTo('category') category; + @belongsTo('file') icon; + + /** @attributs */ + @attr('string') name; + @attr('string') namespace; + @attr('string') description; + @attr('string') key; + @attr('string') status; + @attr('string') version; + @attr('boolean', { defaultValue: false }) core_service; + @attr('array') tags; + @attr('object') flow; + @attr('object') entities; + @attr('object') meta; + + /** @computed */ + @computed('updated_at') get updatedAgo() { + if (!isValidDate(this.updated_at)) { + return null; + } + + return formatDistanceToNow(this.updated_at); + } + + @computed('updated_at') get updatedAt() { + if (!isValidDate(this.updated_at)) { + return null; + } + + return formatDate(this.updated_at, 'PP HH:mm'); + } + + @computed('updated_at') get updatedAtShort() { + if (!isValidDate(this.updated_at)) { + return null; + } + + return formatDate(this.updated_at, 'dd, MMM'); + } + + @computed('created_at') get createdAgo() { + if (!isValidDate(this.created_at)) { + return null; + } + + return formatDistanceToNow(this.created_at); + } + + @computed('created_at') get createdAt() { + if (!isValidDate(this.created_at)) { + return null; + } + + return formatDate(this.created_at, 'PP HH:mm'); + } + + @computed('created_at') get createdAtShort() { + if (!isValidDate(this.created_at)) { + return null; + } + + return formatDate(this.created_at, 'dd, MMM'); + } + + /** @methods */ + /** + * Adds a new tag to the tags array. + * + * This method takes a tag and adds it to the 'tags' array property + * of the current instance. The 'pushObject' method is used, which is + * typically available in Ember.js or similar frameworks that extend + * JavaScript array functionalities. + * + * @param {string} tag - The tag to be added to the tags array. + */ + @action addTag(tag) { + this.tags.push(tag); + this.tags = [...this.tags]; + } + + /** + * Removes a tag from the tags array at a specific index. + * + * This method takes an index and removes the element at that position + * from the 'tags' array property of the current instance. The 'removeAt' + * method is used, which is typically available in Ember.js or similar + * frameworks that provide extended array functionalities. + * + * @param {number} index - The index of the tag to be removed from the tags array. + */ + @action removeTag(index) { + this.tags.removeAt(index); + this.tags = [...this.tags]; + } } diff --git a/addon/models/order.js b/addon/models/order.js index b76a519..bfd9ea5 100644 --- a/addon/models/order.js +++ b/addon/models/order.js @@ -170,7 +170,7 @@ export default class OrderModel extends Model { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -194,7 +194,7 @@ export default class OrderModel extends Model { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } @computed('created_at') get createdAtWithTime() { @@ -226,7 +226,7 @@ export default class OrderModel extends Model { return null; } - return formatDate(this.dispatched_at, 'PP HH:mm'); + return formatDate(this.dispatched_at, 'PP HH:mm'); } @computed('dispatched_at') get dispatchedAtShort() { @@ -234,7 +234,7 @@ export default class OrderModel extends Model { return null; } - return formatDate(this.dispatched_at, 'PP'); + return formatDate(this.dispatched_at, 'dd, MMM'); } @computed('started_at') get startedAgo() { @@ -258,7 +258,7 @@ export default class OrderModel extends Model { return null; } - return formatDate(this.started_at, 'PP'); + return formatDate(this.started_at, 'dd, MMM'); } @computed('scheduled_at') get scheduledAt() { diff --git a/addon/models/payload.js b/addon/models/payload.js index 2964afe..fa50e1a 100644 --- a/addon/models/payload.js +++ b/addon/models/payload.js @@ -103,7 +103,7 @@ export default class PayloadModel extends Model { } @computed('updated_at') get updatedAtShort() { - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -118,7 +118,7 @@ export default class PayloadModel extends Model { } @computed('created_at') get createdAtShort() { - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } /** @methods */ diff --git a/addon/models/place.js b/addon/models/place.js index cb0de50..7cf4bff 100644 --- a/addon/models/place.js +++ b/addon/models/place.js @@ -130,7 +130,7 @@ export default class PlaceModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -151,6 +151,6 @@ export default class PlaceModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/purchase-rate.js b/addon/models/purchase-rate.js index b33fc09..a7d4f8a 100644 --- a/addon/models/purchase-rate.js +++ b/addon/models/purchase-rate.js @@ -41,7 +41,7 @@ export default class PurchaseRateModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -62,6 +62,6 @@ export default class PurchaseRateModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/route.js b/addon/models/route.js index 5a4b671..bdef52a 100644 --- a/addon/models/route.js +++ b/addon/models/route.js @@ -37,7 +37,7 @@ export default class RouteModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -58,6 +58,6 @@ export default class RouteModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/service-area.js b/addon/models/service-area.js index db1098e..a31157a 100644 --- a/addon/models/service-area.js +++ b/addon/models/service-area.js @@ -63,7 +63,7 @@ export default class ServiceAreaModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -84,6 +84,6 @@ export default class ServiceAreaModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/service-quote-item.js b/addon/models/service-quote-item.js index 7697954..89c32ce 100644 --- a/addon/models/service-quote-item.js +++ b/addon/models/service-quote-item.js @@ -36,7 +36,7 @@ export default class ServiceQuoteItemModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -57,6 +57,6 @@ export default class ServiceQuoteItemModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/service-quote.js b/addon/models/service-quote.js index b68de80..fe4cb86 100644 --- a/addon/models/service-quote.js +++ b/addon/models/service-quote.js @@ -41,7 +41,7 @@ export default class ServiceQuoteModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -62,6 +62,6 @@ export default class ServiceQuoteModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/service-rate-fee.js b/addon/models/service-rate-fee.js index b017148..5eb1175 100644 --- a/addon/models/service-rate-fee.js +++ b/addon/models/service-rate-fee.js @@ -39,7 +39,7 @@ export default class ServiceRateFeeModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -60,7 +60,7 @@ export default class ServiceRateFeeModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } /** @methods */ diff --git a/addon/models/service-rate-parcel-fee.js b/addon/models/service-rate-parcel-fee.js index 31200af..6b2bd5e 100644 --- a/addon/models/service-rate-parcel-fee.js +++ b/addon/models/service-rate-parcel-fee.js @@ -41,7 +41,7 @@ export default class ServiceRateParcelFeeModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -62,7 +62,7 @@ export default class ServiceRateParcelFeeModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } /** @methods */ diff --git a/addon/models/service-rate.js b/addon/models/service-rate.js index 3380c70..678b731 100644 --- a/addon/models/service-rate.js +++ b/addon/models/service-rate.js @@ -57,7 +57,7 @@ export default class ServiceRate extends Model { } @computed('updated_at') get updatedAtShort() { - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -69,7 +69,7 @@ export default class ServiceRate extends Model { } @computed('created_at') get createdAtShort() { - return this.created_at ? formatDate(this.created_at, 'PP') : null; + return this.created_at ? formatDate(this.created_at, 'dd, MMM') : null; } @computed('rate_calculation_method') get isFixedMeter() { diff --git a/addon/models/tracking-number.js b/addon/models/tracking-number.js index c229519..7d0787f 100644 --- a/addon/models/tracking-number.js +++ b/addon/models/tracking-number.js @@ -39,7 +39,7 @@ export default class TrackingNumberModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -60,6 +60,6 @@ export default class TrackingNumberModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/tracking-status.js b/addon/models/tracking-status.js index de11b0f..02ca777 100644 --- a/addon/models/tracking-status.js +++ b/addon/models/tracking-status.js @@ -40,7 +40,7 @@ export default class TrackingStatusModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -61,7 +61,7 @@ export default class TrackingStatusModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } @computed('created_at') get createdAtShortWithTime() { diff --git a/addon/models/vehicle-device.js b/addon/models/vehicle-device.js index dd249ef..b858f48 100644 --- a/addon/models/vehicle-device.js +++ b/addon/models/vehicle-device.js @@ -48,7 +48,7 @@ export default class VehicleDeviceModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -69,6 +69,6 @@ export default class VehicleDeviceModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/vehicle.js b/addon/models/vehicle.js index 5f1d900..9192bb1 100644 --- a/addon/models/vehicle.js +++ b/addon/models/vehicle.js @@ -75,7 +75,7 @@ export default class VehicleModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -96,7 +96,7 @@ export default class VehicleModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } /** @methods */ diff --git a/addon/models/vendor.js b/addon/models/vendor.js index 96c5da6..997ac5f 100644 --- a/addon/models/vendor.js +++ b/addon/models/vendor.js @@ -64,7 +64,7 @@ export default class VendorModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -85,6 +85,6 @@ export default class VendorModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } } diff --git a/addon/models/zone.js b/addon/models/zone.js index d6a3e84..73fc790 100644 --- a/addon/models/zone.js +++ b/addon/models/zone.js @@ -65,7 +65,7 @@ export default class ZoneModel extends Model { if (!isValidDate(this.updated_at)) { return null; } - return formatDate(this.updated_at, 'PP'); + return formatDate(this.updated_at, 'dd, MMM'); } @computed('created_at') get createdAgo() { @@ -86,6 +86,6 @@ export default class ZoneModel extends Model { if (!isValidDate(this.created_at)) { return null; } - return formatDate(this.created_at, 'PP'); + return formatDate(this.created_at, 'dd, MMM'); } }