Skip to content

Commit 6063ad2

Browse files
authored
Merge pull request #45 from fleetbase/feat/driver-scheduling-relationships
feat: add schedule, schedule-item and availability relationships to Driver model
2 parents 332dc42 + f4a25b0 commit 6063ad2

38 files changed

Lines changed: 894 additions & 38 deletions

addon/adapters/manifest-stop.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ApplicationAdapter from '@fleetbase/ember-core/adapters/application';
2+
3+
export default class ManifestStopAdapter extends ApplicationAdapter {
4+
urlForFindRecord(id) {
5+
return `${this.host}/${this.namespace}/fleet-ops/v1/manifest-stops/${id}`;
6+
}
7+
8+
urlForUpdateRecord(id) {
9+
return `${this.host}/${this.namespace}/fleet-ops/v1/manifest-stops/${id}`;
10+
}
11+
}

addon/adapters/manifest.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ApplicationAdapter from '@fleetbase/ember-core/adapters/application';
2+
3+
export default class ManifestAdapter extends ApplicationAdapter {
4+
urlForQuery() {
5+
return `${this.host}/${this.namespace}/fleet-ops/v1/manifests`;
6+
}
7+
8+
urlForFindRecord(id) {
9+
return `${this.host}/${this.namespace}/fleet-ops/v1/manifests/${id}`;
10+
}
11+
}

addon/models/asset.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { format as formatDate, isValid as isValidDate, formatDistanceToNow } fro
44

55
export default class AssetModel extends Model {
66
/** @ids */
7+
@attr('string') uuid;
78
@attr('string') public_id;
89
@attr('string') company_uuid;
910
@attr('string') category_uuid;
@@ -63,11 +64,16 @@ export default class AssetModel extends Model {
6364
@attr('raw') attributes;
6465
@attr('string') notes;
6566
@attr('string') slug;
67+
/** @server-computed (read-only appended attributes) */
6668
@attr('string') photo_url;
6769
@attr('string') display_name;
6870
@attr('string') category_name;
6971
@attr('string') vendor_name;
7072
@attr('string') warranty_name;
73+
@attr('string') current_location;
74+
@attr('boolean') is_online;
75+
@attr('date') last_maintenance;
76+
@attr('date') next_maintenance_due;
7177

7278
/** @dates */
7379
@attr('date') deleted_at;

addon/models/device.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { format as formatDate, isValid as isValidDate, formatDistanceToNow } fro
44

55
export default class DeviceModel extends Model {
66
/** @ids */
7+
@attr('string') uuid;
78
@attr('string') public_id;
89
@attr('string') company_uuid;
910
@attr('string') telematic_uuid;
@@ -30,7 +31,15 @@ export default class DeviceModel extends Model {
3031
@attr('string') imsi;
3132
@attr('string') firmware_version;
3233
@attr('string') provider;
34+
35+
/** @server-computed (read-only appended attributes) */
3336
@attr('string') photo_url;
37+
@attr('string') warranty_name;
38+
@attr('string') telematic_name;
39+
@attr('boolean') is_online;
40+
@attr('string') attached_to_name;
41+
@attr('string') connection_status;
42+
3443
@attr('string') manufacturer;
3544
@attr('string') serial_number;
3645
@attr('point') last_position;

addon/models/driver.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export default class DriverModel extends Model {
3131
@belongsTo('vendor', { async: true }) vendor;
3232
@hasMany('custom-field-value', { async: false }) custom_field_values;
3333

34+
/** @scheduling-relationships */
35+
@hasMany('schedule', { async: true }) schedules;
36+
@hasMany('schedule-item', { async: true }) schedule_items;
37+
@hasMany('schedule-availability', { async: true }) availabilities;
38+
3439
/** @attributes */
3540
@attr('string') name;
3641
@attr('string') phone;

addon/models/equipment.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { format as formatDate, isValid as isValidDate, formatDistanceToNow } fro
44

55
export default class EquipmentModel extends Model {
66
/** @ids */
7+
@attr('string') uuid;
78
@attr('string') public_id;
89
@attr('string') company_uuid;
910
@attr('string') warranty_uuid;
@@ -25,11 +26,17 @@ export default class EquipmentModel extends Model {
2526
@attr('string') serial_number;
2627
@attr('string') manufacturer;
2728
@attr('string') model;
28-
@attr('number') purchase_price;
29+
@attr('string') purchase_price;
30+
@attr('string') currency;
2931
@attr('raw') meta;
3032
@attr('string') slug;
33+
/** @server-computed (read-only appended attributes) */
3134
@attr('string') warranty_name;
3235
@attr('string') photo_url;
36+
@attr('string') equipped_to_name;
37+
@attr('boolean') is_equipped;
38+
@attr('number') age_in_days;
39+
@attr('string') depreciated_value;
3340

3441
/** @dates */
3542
@attr('date') purchased_at;
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import Model, { attr, belongsTo } from '@ember-data/model';
2+
import { computed } from '@ember/object';
3+
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
4+
5+
export default class MaintenanceScheduleModel extends Model {
6+
/** @ids */
7+
@attr('string') uuid;
8+
@attr('string') public_id;
9+
@attr('string') company_uuid;
10+
11+
/** @polymorphic relationships */
12+
@belongsTo('maintenance-subject', { polymorphic: true, async: false }) subject;
13+
@belongsTo('facilitator', { polymorphic: true, async: false }) default_assignee;
14+
/** @computed names — server-side convenience fields (read-only) */
15+
@attr('string') subject_name;
16+
@attr('string') default_assignee_name;
17+
18+
/** @attributes */
19+
@attr('string') code;
20+
@attr('string') title;
21+
@attr('string') description;
22+
@attr('string') name;
23+
@attr('string') type;
24+
@attr('string') status;
25+
@attr('string') interval_method;
26+
27+
/** @interval — time-based */
28+
@attr('string') interval_type;
29+
@attr('number') interval_value;
30+
@attr('string') interval_unit;
31+
32+
/** @interval — distance / engine-hours */
33+
@attr('number') interval_distance;
34+
@attr('number') interval_engine_hours;
35+
36+
/** @baseline readings */
37+
@attr('number') last_service_odometer;
38+
@attr('number') last_service_engine_hours;
39+
@attr('date') last_service_date;
40+
41+
/** @next-due thresholds */
42+
@attr('date') next_due_date;
43+
@attr('number') next_due_odometer;
44+
@attr('number') next_due_engine_hours;
45+
46+
/** @work-order defaults */
47+
@attr('string') default_priority;
48+
49+
@attr('string') instructions;
50+
@attr('raw') meta;
51+
@attr('string') slug;
52+
53+
/** @reminders — array of integer day offsets, e.g. [15, 7, 3] */
54+
@attr('raw') reminder_offsets;
55+
56+
/** @dates */
57+
@attr('date') last_triggered_at;
58+
@attr('date') deleted_at;
59+
@attr('date') created_at;
60+
@attr('date') updated_at;
61+
62+
/** @computed */
63+
@computed('status') get isActive() {
64+
return this.status === 'active';
65+
}
66+
67+
@computed('status') get isPaused() {
68+
return this.status === 'paused';
69+
}
70+
71+
@computed('next_due_date') get nextDueAt() {
72+
if (!isValidDate(this.next_due_date)) {
73+
return null;
74+
}
75+
return formatDate(this.next_due_date, 'yyyy-MM-dd HH:mm');
76+
}
77+
78+
@computed('next_due_date') get nextDueAtShort() {
79+
if (!isValidDate(this.next_due_date)) {
80+
return null;
81+
}
82+
return formatDate(this.next_due_date, 'dd, MMM yyyy');
83+
}
84+
85+
@computed('next_due_date') get nextDueAgo() {
86+
if (!isValidDate(this.next_due_date)) {
87+
return null;
88+
}
89+
return formatDistanceToNow(this.next_due_date, { addSuffix: true });
90+
}
91+
92+
@computed('updated_at') get updatedAgo() {
93+
if (!isValidDate(this.updated_at)) {
94+
return null;
95+
}
96+
return formatDistanceToNow(this.updated_at);
97+
}
98+
99+
@computed('updated_at') get updatedAt() {
100+
if (!isValidDate(this.updated_at)) {
101+
return null;
102+
}
103+
return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
104+
}
105+
106+
@computed('updated_at') get updatedAtShort() {
107+
if (!isValidDate(this.updated_at)) {
108+
return null;
109+
}
110+
return formatDate(this.updated_at, 'dd, MMM');
111+
}
112+
113+
@computed('created_at') get createdAgo() {
114+
if (!isValidDate(this.created_at)) {
115+
return null;
116+
}
117+
return formatDistanceToNow(this.created_at);
118+
}
119+
120+
@computed('created_at') get createdAt() {
121+
if (!isValidDate(this.created_at)) {
122+
return null;
123+
}
124+
return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
125+
}
126+
127+
@computed('created_at') get createdAtShort() {
128+
if (!isValidDate(this.created_at)) {
129+
return null;
130+
}
131+
return formatDate(this.created_at, 'dd, MMM');
132+
}
133+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import MaintenanceSubjectModel from './maintenance-subject';
2+
import { attr } from '@ember-data/model';
3+
4+
/**
5+
* Concrete polymorphic model for Equipment acting as a maintenance subject.
6+
* Resolved when the backend sends subject_type / target_type / maintainable_type = 'fleet-ops:equipment'.
7+
*/
8+
export default class MaintenanceSubjectEquipmentModel extends MaintenanceSubjectModel {
9+
/** @ids */
10+
@attr('string') warranty_uuid;
11+
@attr('string') photo_uuid;
12+
@attr('string') equipable_type;
13+
@attr('string') equipable_uuid;
14+
15+
/** @attributes */
16+
@attr('string') code;
17+
@attr('string') serial_number;
18+
@attr('string') manufacturer;
19+
@attr('string') model;
20+
@attr('number') purchase_price;
21+
@attr('string') warranty_name;
22+
@attr('raw') meta;
23+
24+
/** @dates */
25+
@attr('date') purchased_at;
26+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import MaintenanceSubjectModel from './maintenance-subject';
2+
import { attr } from '@ember-data/model';
3+
import { get } from '@ember/object';
4+
import config from 'ember-get-config';
5+
6+
/**
7+
* Concrete polymorphic model for a Vehicle acting as a maintenance subject.
8+
* Resolved when the backend sends subject_type / target_type / maintainable_type = 'fleet-ops:vehicle'.
9+
*/
10+
export default class MaintenanceSubjectVehicleModel extends MaintenanceSubjectModel {
11+
/** @ids */
12+
@attr('string') internal_id;
13+
@attr('string') photo_uuid;
14+
@attr('string') vendor_uuid;
15+
@attr('string') category_uuid;
16+
@attr('string') warranty_uuid;
17+
@attr('string') telematic_uuid;
18+
19+
/** @attributes */
20+
@attr('string', {
21+
defaultValue: get(config, 'defaultValues.vehicleImage'),
22+
})
23+
photo_url;
24+
25+
@attr('string') make;
26+
@attr('string') model;
27+
@attr('string') year;
28+
@attr('string') trim;
29+
@attr('string') plate_number;
30+
@attr('string') vin;
31+
@attr('string') driver_name;
32+
@attr('string') vendor_name;
33+
@attr('string') display_name;
34+
@attr('string', {
35+
defaultValue: get(config, 'defaultValues.vehicleAvatar'),
36+
})
37+
avatar_url;
38+
@attr('string') avatar_value;
39+
@attr('string') color;
40+
@attr('string') country;
41+
@attr('number') odometer;
42+
@attr('number') engine_hours;
43+
@attr('raw') meta;
44+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import Model, { attr } from '@ember-data/model';
2+
import { computed } from '@ember/object';
3+
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
4+
5+
/**
6+
* Abstract base model for polymorphic maintenance subjects.
7+
* Concrete types: maintenance-subject-vehicle, maintenance-subject-equipment
8+
*
9+
* The backend stores the type as a PolymorphicType cast string, e.g.:
10+
* 'fleet-ops:vehicle' -> maintenance-subject-vehicle
11+
* 'fleet-ops:equipment' -> maintenance-subject-equipment
12+
*/
13+
export default class MaintenanceSubjectModel extends Model {
14+
/** @ids */
15+
@attr('string') uuid;
16+
@attr('string') public_id;
17+
@attr('string') company_uuid;
18+
19+
/** @attributes */
20+
@attr('string') name;
21+
@attr('string') display_name;
22+
@attr('string') type;
23+
@attr('string') status;
24+
@attr('string') photo_url;
25+
@attr('string') slug;
26+
27+
/** @dates */
28+
@attr('date') deleted_at;
29+
@attr('date') created_at;
30+
@attr('date') updated_at;
31+
32+
/** @computed */
33+
@computed('name', 'display_name', 'public_id') get displayName() {
34+
return this.display_name || this.name || this.public_id;
35+
}
36+
37+
@computed('updated_at') get updatedAgo() {
38+
if (!isValidDate(this.updated_at)) {
39+
return null;
40+
}
41+
return formatDistanceToNow(this.updated_at);
42+
}
43+
44+
@computed('updated_at') get updatedAt() {
45+
if (!isValidDate(this.updated_at)) {
46+
return null;
47+
}
48+
return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
49+
}
50+
51+
@computed('updated_at') get updatedAtShort() {
52+
if (!isValidDate(this.updated_at)) {
53+
return null;
54+
}
55+
return formatDate(this.updated_at, 'dd, MMM');
56+
}
57+
58+
@computed('created_at') get createdAgo() {
59+
if (!isValidDate(this.created_at)) {
60+
return null;
61+
}
62+
return formatDistanceToNow(this.created_at);
63+
}
64+
65+
@computed('created_at') get createdAt() {
66+
if (!isValidDate(this.created_at)) {
67+
return null;
68+
}
69+
return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
70+
}
71+
72+
@computed('created_at') get createdAtShort() {
73+
if (!isValidDate(this.created_at)) {
74+
return null;
75+
}
76+
return formatDate(this.created_at, 'dd, MMM');
77+
}
78+
}

0 commit comments

Comments
 (0)