Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
feat: add Template and TemplateQuery Ember Data models
Ronald A Richardson3fcd21ec285a
diff --git a/console/app/models/template-query.js b/console/app/models/template-query.jsnew file mode 100644index 00000000..32070d39--- /dev/null+++ b/console/app/models/template-query.js@@ -0,0 +1,90 @@+import Model, { attr, belongsTo } from '@ember-data/model';+import { computed } from '@ember/object';+import { format, formatDistanceToNow } from 'date-fns';++export default class TemplateQueryModel extends Model {+ /** @ids */+ @attr('string') public_id;+ @attr('string') uuid;+ @attr('string') company_uuid;+ @attr('string') template_uuid;++ /** @relationships */+ @belongsTo('template', { async: false, inverse: 'queries' }) template;++ /** @attributes */+ @attr('string') name;+ @attr('string') label;+ @attr('string') description;++ /**+ * The fully-qualified PHP model class this query runs against.+ * e.g. "Fleetbase\\Models\\Order", "Fleetbase\\Ledger\\Models\\Invoice"+ */+ @attr('string') resource_type;++ /**+ * JSON object of filter conditions applied to the query.+ * e.g. { "status": "completed", "created_at_gte": "2024-12-01" }+ */+ @attr('object', { defaultValue: () => ({}) }) filters;++ @attr('string') sort_by;+ @attr('string', { defaultValue: 'desc' }) sort_direction;+ @attr('number') limit;++ /** @dates */+ @attr('date') deleted_at;+ @attr('date') created_at;+ @attr('date') updated_at;++ /** @computed */++ /**+ * The variable name available in the template for iterating this query's results.+ * Derived from the `name` field — lowercased and underscored.+ * e.g. name "December Orders" → variable "{december_orders}"+ */+ @computed('name') get variableName() {+ if (!this.name) return '';+ return this.name+ .toLowerCase()+ .replace(/[^a-z0-9]+/g, '_')+ .replace(/^_+|_+$/g, '');+ }++ @computed('variableName') get variableToken() {+ return `{${this.variableName}}`;+ }++ @computed('resource_type') get resourceTypeLabel() {+ if (!this.resource_type) return '';+ // Extract the short class name from the fully-qualified namespace+ const parts = this.resource_type.split('\\');+ return parts[parts.length - 1];+ }++ @computed('updated_at') get updatedAgo() {+ return formatDistanceToNow(this.updated_at);+ }++ @computed('updated_at') get updatedAt() {+ return format(this.updated_at, 'yyyy-MM-dd HH:mm');+ }++ @computed('updated_at') get updatedAtShort() {+ return format(this.updated_at, 'PP');+ }++ @computed('created_at') get createdAgo() {+ return formatDistanceToNow(this.created_at);+ }++ @computed('created_at') get createdAt() {+ return format(this.created_at, 'yyyy-MM-dd HH:mm');+ }++ @computed('created_at') get createdAtShort() {+ return format(this.created_at, 'PP');+ }+}diff --git a/console/app/models/template.js b/console/app/models/template.jsnew file mode 100644index 00000000..c9396dac--- /dev/null+++ b/console/app/models/template.js@@ -0,0 +1,89 @@+import Model, { attr, hasMany } from '@ember-data/model';+import { computed } from '@ember/object';+import { format, formatDistanceToNow } from 'date-fns';++export default class TemplateModel extends Model {+ /** @ids */+ @attr('string') public_id;+ @attr('string') uuid;+ @attr('string') company_uuid;+ @attr('string') created_by_uuid;++ /** @relationships */+ @hasMany('template-query', { async: false, inverse: 'template' }) queries;++ /** @attributes */+ @attr('string') name;+ @attr('string') description;+ @attr('string') context_type;+ @attr('string', { defaultValue: 'A4' }) paper_size;+ @attr('string', { defaultValue: 'portrait' }) orientation;+ @attr('number') width;+ @attr('number') height;+ @attr('string', { defaultValue: 'mm' }) unit;+ @attr('string', { defaultValue: '#ffffff' }) background_color;+ @attr('array', { defaultValue: () => [] }) content;+ @attr('boolean', { defaultValue: false }) is_default;+ @attr('string', { defaultValue: 'draft' }) status;+ @attr('object') meta;++ /** @dates */+ @attr('date') deleted_at;+ @attr('date') created_at;+ @attr('date') updated_at;++ /** @computed */+ @computed('status') get isDraft() {+ return this.status === 'draft';+ }++ @computed('status') get isPublished() {+ return this.status === 'published';+ }++ @computed('context_type') get contextTypeLabel() {+ const labels = {+ invoice: 'Invoice',+ order: 'Order',+ transaction: 'Transaction',+ wallet: 'Wallet',+ contact: 'Contact',+ company: 'Company',+ shipment: 'Shipment',+ waybill: 'Waybill',+ receipt: 'Receipt',+ };+ return labels[this.context_type] ?? this.context_type;+ }++ @computed('paper_size', 'orientation') get dimensionLabel() {+ if (this.paper_size === 'custom') {+ return `${this.width} × ${this.height} ${this.unit}`;+ }+ return `${this.paper_size} (${this.orientation})`;+ }++ @computed('updated_at') get updatedAgo() {+ return formatDistanceToNow(this.updated_at);+ }++ @computed('updated_at') get updatedAt() {+ return format(this.updated_at, 'yyyy-MM-dd HH:mm');+ }++ @computed('updated_at') get updatedAtShort() {+ return format(this.updated_at, 'PP');+ }++ @computed('created_at') get createdAgo() {+ return formatDistanceToNow(this.created_at);+ }++ @computed('created_at') get createdAt() {+ return format(this.created_at, 'yyyy-MM-dd HH:mm');+ }++ @computed('created_at') get createdAtShort() {+ return format(this.created_at, 'PP');+ }+}