Skip to content

Commit 3b4c1c3

Browse files
committed
added OrderConfigModel for order config refactor, also fixed date formats
1 parent 9d92927 commit 3b4c1c3

27 files changed

+162
-60
lines changed

addon/models/contact.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class ContactModel extends Model {
5252
if (!isValidDate(this.updated_at)) {
5353
return null;
5454
}
55-
return formatDate(this.updated_at, 'PP');
55+
return formatDate(this.updated_at, 'dd, MMM');
5656
}
5757

5858
@computed('created_at') get createdAgo() {
@@ -73,6 +73,6 @@ export default class ContactModel extends Model {
7373
if (!isValidDate(this.created_at)) {
7474
return null;
7575
}
76-
return formatDate(this.created_at, 'PP');
76+
return formatDate(this.created_at, 'dd, MMM');
7777
}
7878
}

addon/models/customer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class CustomerModel extends ContactModel {
3131
if (!isValidDate(this.updated_at)) {
3232
return null;
3333
}
34-
return formatDate(this.updated_at, 'PP');
34+
return formatDate(this.updated_at, 'dd, MMM');
3535
}
3636

3737
@computed('created_at') get createdAgo() {
@@ -52,6 +52,6 @@ export default class CustomerModel extends ContactModel {
5252
if (!isValidDate(this.created_at)) {
5353
return null;
5454
}
55-
return formatDate(this.created_at, 'PP');
55+
return formatDate(this.created_at, 'dd, MMM');
5656
}
5757
}

addon/models/driver.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default class DriverModel extends Model {
9494
if (!isValidDate(this.updated_at)) {
9595
return null;
9696
}
97-
return formatDate(this.updated_at, 'PP');
97+
return formatDate(this.updated_at, 'dd, MMM');
9898
}
9999

100100
@computed('created_at') get createdAgo() {
@@ -115,7 +115,7 @@ export default class DriverModel extends Model {
115115
if (!isValidDate(this.created_at)) {
116116
return null;
117117
}
118-
return formatDate(this.created_at, 'PP');
118+
return formatDate(this.created_at, 'dd, MMM');
119119
}
120120

121121
@computed('location') get latitude() {

addon/models/entity.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default class EntityModel extends Model {
103103
if (!isValidDate(this.updated_at)) {
104104
return null;
105105
}
106-
return formatDate(this.updated_at, 'PP');
106+
return formatDate(this.updated_at, 'dd, MMM');
107107
}
108108

109109
@computed('created_at') get createdAgo() {
@@ -124,6 +124,6 @@ export default class EntityModel extends Model {
124124
if (!isValidDate(this.created_at)) {
125125
return null;
126126
}
127-
return formatDate(this.created_at, 'PP');
127+
return formatDate(this.created_at, 'dd, MMM');
128128
}
129129
}

addon/models/facilitator.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class FacilitatorModel extends Model {
3939
if (!isValidDate(this.updated_at)) {
4040
return null;
4141
}
42-
return formatDate(this.updated_at, 'PP');
42+
return formatDate(this.updated_at, 'dd, MMM');
4343
}
4444

4545
@computed('created_at') get createdAgo() {
@@ -60,6 +60,6 @@ export default class FacilitatorModel extends Model {
6060
if (!isValidDate(this.created_at)) {
6161
return null;
6262
}
63-
return formatDate(this.created_at, 'PP');
63+
return formatDate(this.created_at, 'dd, MMM');
6464
}
6565
}

addon/models/fleet-driver.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default class FleetDriverModel extends Model {
3535
if (!isValidDate(this.updated_at)) {
3636
return null;
3737
}
38-
return formatDate(this.updated_at, 'PP');
38+
return formatDate(this.updated_at, 'dd, MMM');
3939
}
4040

4141
@computed('created_at') get createdAgo() {
@@ -56,6 +56,6 @@ export default class FleetDriverModel extends Model {
5656
if (!isValidDate(this.created_at)) {
5757
return null;
5858
}
59-
return formatDate(this.created_at, 'PP');
59+
return formatDate(this.created_at, 'dd, MMM');
6060
}
6161
}

addon/models/fleet.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class FleetModel extends Model {
5757
if (!isValidDate(this.updated_at)) {
5858
return null;
5959
}
60-
return formatDate(this.updated_at, 'PP');
60+
return formatDate(this.updated_at, 'dd, MMM');
6161
}
6262

6363
@computed('created_at') get createdAgo() {
@@ -78,6 +78,6 @@ export default class FleetModel extends Model {
7878
if (!isValidDate(this.created_at)) {
7979
return null;
8080
}
81-
return formatDate(this.created_at, 'PP');
81+
return formatDate(this.created_at, 'dd, MMM');
8282
}
8383
}

addon/models/fuel-report.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class FuelReportModel extends Model {
5555
if (!isValidDate(this.updated_at)) {
5656
return null;
5757
}
58-
return formatDate(this.updated_at, 'PP');
58+
return formatDate(this.updated_at, 'dd, MMM');
5959
}
6060

6161
@computed('created_at') get createdAgo() {
@@ -76,7 +76,7 @@ export default class FuelReportModel extends Model {
7676
if (!isValidDate(this.created_at)) {
7777
return null;
7878
}
79-
return formatDate(this.created_at, 'PP');
79+
return formatDate(this.created_at, 'dd, MMM');
8080
}
8181

8282
/** @methods */

addon/models/issue.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class IssueModel extends Model {
5858
if (!isValidDate(this.updated_at)) {
5959
return null;
6060
}
61-
return formatDate(this.updated_at, 'PP');
61+
return formatDate(this.updated_at, 'dd, MMM');
6262
}
6363

6464
@computed('created_at') get createdAgo() {
@@ -79,7 +79,7 @@ export default class IssueModel extends Model {
7979
if (!isValidDate(this.created_at)) {
8080
return null;
8181
}
82-
return formatDate(this.created_at, 'PP');
82+
return formatDate(this.created_at, 'dd, MMM');
8383
}
8484

8585
/** @methods */

addon/models/order-config.js

+107-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,109 @@
1-
import ExtensionModel from '@fleetbase/console/models/extension';
2-
import { attr } from '@ember-data/model';
1+
import Model, { attr, belongsTo } from '@ember-data/model';
2+
import { computed, action } from '@ember/object';
3+
import { format as formatDate, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
34

4-
export default class OrderConfigModel extends ExtensionModel {
5-
@attr('string') install_uuid;
6-
@attr('boolean') installed;
5+
export default class OrderConfigModel extends Model {
6+
/** @ids */
7+
@attr('string') company_uuid;
8+
@attr('string') author_uuid;
9+
@attr('string') category_uuid;
10+
@attr('string') icon_uuid;
11+
12+
/** @relationships */
13+
@belongsTo('user') author;
14+
@belongsTo('category') category;
15+
@belongsTo('file') icon;
16+
17+
/** @attributs */
18+
@attr('string') name;
19+
@attr('string') namespace;
20+
@attr('string') description;
21+
@attr('string') key;
22+
@attr('string') status;
23+
@attr('string') version;
24+
@attr('boolean', { defaultValue: false }) core_service;
25+
@attr('array') tags;
26+
@attr('object') flow;
27+
@attr('object') entities;
28+
@attr('object') meta;
29+
30+
/** @computed */
31+
@computed('updated_at') get updatedAgo() {
32+
if (!isValidDate(this.updated_at)) {
33+
return null;
34+
}
35+
36+
return formatDistanceToNow(this.updated_at);
37+
}
38+
39+
@computed('updated_at') get updatedAt() {
40+
if (!isValidDate(this.updated_at)) {
41+
return null;
42+
}
43+
44+
return formatDate(this.updated_at, 'PP HH:mm');
45+
}
46+
47+
@computed('updated_at') get updatedAtShort() {
48+
if (!isValidDate(this.updated_at)) {
49+
return null;
50+
}
51+
52+
return formatDate(this.updated_at, 'dd, MMM');
53+
}
54+
55+
@computed('created_at') get createdAgo() {
56+
if (!isValidDate(this.created_at)) {
57+
return null;
58+
}
59+
60+
return formatDistanceToNow(this.created_at);
61+
}
62+
63+
@computed('created_at') get createdAt() {
64+
if (!isValidDate(this.created_at)) {
65+
return null;
66+
}
67+
68+
return formatDate(this.created_at, 'PP HH:mm');
69+
}
70+
71+
@computed('created_at') get createdAtShort() {
72+
if (!isValidDate(this.created_at)) {
73+
return null;
74+
}
75+
76+
return formatDate(this.created_at, 'dd, MMM');
77+
}
78+
79+
/** @methods */
80+
/**
81+
* Adds a new tag to the tags array.
82+
*
83+
* This method takes a tag and adds it to the 'tags' array property
84+
* of the current instance. The 'pushObject' method is used, which is
85+
* typically available in Ember.js or similar frameworks that extend
86+
* JavaScript array functionalities.
87+
*
88+
* @param {string} tag - The tag to be added to the tags array.
89+
*/
90+
@action addTag(tag) {
91+
this.tags.push(tag);
92+
this.tags = [...this.tags];
93+
}
94+
95+
/**
96+
* Removes a tag from the tags array at a specific index.
97+
*
98+
* This method takes an index and removes the element at that position
99+
* from the 'tags' array property of the current instance. The 'removeAt'
100+
* method is used, which is typically available in Ember.js or similar
101+
* frameworks that provide extended array functionalities.
102+
*
103+
* @param {number} index - The index of the tag to be removed from the tags array.
104+
*/
105+
@action removeTag(index) {
106+
this.tags.removeAt(index);
107+
this.tags = [...this.tags];
108+
}
7109
}

addon/models/order.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export default class OrderModel extends Model {
170170
return null;
171171
}
172172

173-
return formatDate(this.updated_at, 'PP');
173+
return formatDate(this.updated_at, 'dd, MMM');
174174
}
175175

176176
@computed('created_at') get createdAgo() {
@@ -194,7 +194,7 @@ export default class OrderModel extends Model {
194194
return null;
195195
}
196196

197-
return formatDate(this.created_at, 'PP');
197+
return formatDate(this.created_at, 'dd, MMM');
198198
}
199199

200200
@computed('created_at') get createdAtWithTime() {
@@ -226,15 +226,15 @@ export default class OrderModel extends Model {
226226
return null;
227227
}
228228

229-
return formatDate(this.dispatched_at, 'PP HH:mm');
229+
return formatDate(this.dispatched_at, 'PP HH:mm');
230230
}
231231

232232
@computed('dispatched_at') get dispatchedAtShort() {
233233
if (!isValidDate(this.dispatched_at)) {
234234
return null;
235235
}
236236

237-
return formatDate(this.dispatched_at, 'PP');
237+
return formatDate(this.dispatched_at, 'dd, MMM');
238238
}
239239

240240
@computed('started_at') get startedAgo() {
@@ -258,7 +258,7 @@ export default class OrderModel extends Model {
258258
return null;
259259
}
260260

261-
return formatDate(this.started_at, 'PP');
261+
return formatDate(this.started_at, 'dd, MMM');
262262
}
263263

264264
@computed('scheduled_at') get scheduledAt() {

addon/models/payload.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default class PayloadModel extends Model {
103103
}
104104

105105
@computed('updated_at') get updatedAtShort() {
106-
return formatDate(this.updated_at, 'PP');
106+
return formatDate(this.updated_at, 'dd, MMM');
107107
}
108108

109109
@computed('created_at') get createdAgo() {
@@ -118,7 +118,7 @@ export default class PayloadModel extends Model {
118118
}
119119

120120
@computed('created_at') get createdAtShort() {
121-
return formatDate(this.created_at, 'PP');
121+
return formatDate(this.created_at, 'dd, MMM');
122122
}
123123

124124
/** @methods */

addon/models/place.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export default class PlaceModel extends Model {
130130
if (!isValidDate(this.updated_at)) {
131131
return null;
132132
}
133-
return formatDate(this.updated_at, 'PP');
133+
return formatDate(this.updated_at, 'dd, MMM');
134134
}
135135

136136
@computed('created_at') get createdAgo() {
@@ -151,6 +151,6 @@ export default class PlaceModel extends Model {
151151
if (!isValidDate(this.created_at)) {
152152
return null;
153153
}
154-
return formatDate(this.created_at, 'PP');
154+
return formatDate(this.created_at, 'dd, MMM');
155155
}
156156
}

addon/models/purchase-rate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class PurchaseRateModel extends Model {
4141
if (!isValidDate(this.updated_at)) {
4242
return null;
4343
}
44-
return formatDate(this.updated_at, 'PP');
44+
return formatDate(this.updated_at, 'dd, MMM');
4545
}
4646

4747
@computed('created_at') get createdAgo() {
@@ -62,6 +62,6 @@ export default class PurchaseRateModel extends Model {
6262
if (!isValidDate(this.created_at)) {
6363
return null;
6464
}
65-
return formatDate(this.created_at, 'PP');
65+
return formatDate(this.created_at, 'dd, MMM');
6666
}
6767
}

addon/models/route.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class RouteModel extends Model {
3737
if (!isValidDate(this.updated_at)) {
3838
return null;
3939
}
40-
return formatDate(this.updated_at, 'PP');
40+
return formatDate(this.updated_at, 'dd, MMM');
4141
}
4242

4343
@computed('created_at') get createdAgo() {
@@ -58,6 +58,6 @@ export default class RouteModel extends Model {
5858
if (!isValidDate(this.created_at)) {
5959
return null;
6060
}
61-
return formatDate(this.created_at, 'PP');
61+
return formatDate(this.created_at, 'dd, MMM');
6262
}
6363
}

0 commit comments

Comments
 (0)