Skip to content

Commit

Permalink
Merge pull request #15 from fleetbase/dev-v0.1.2
Browse files Browse the repository at this point in the history
v0.1.2
  • Loading branch information
roncodes authored Nov 6, 2023
2 parents 063ef50 + 80bc964 commit 6d0ab56
Show file tree
Hide file tree
Showing 10 changed files with 1,601 additions and 1,161 deletions.
4 changes: 0 additions & 4 deletions addon/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ export default class ContactModel extends Model {
@attr('string') public_id;
@attr('string') company_uuid;
@attr('string') photo_uuid;
@attr('string') place_uuid;

/** @relationships */
@belongsTo('place') place;
@belongsTo('file') photo;

/** @attributes */
Expand All @@ -19,8 +17,6 @@ export default class ContactModel extends Model {
@attr('string') email;
@attr('string') phone;
@attr('string') type;
@attr('string') customer_type;
@attr('string') facilitator_type;
@attr('string', {
defaultValue: 'https://s3.ap-southeast-1.amazonaws.com/flb-assets/static/no-avatar.png',
})
Expand Down
17 changes: 6 additions & 11 deletions addon/models/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class DriverModel extends Model {
@attr('string') vehicle_uuid;
@attr('string') vendor_uuid;
@attr('string') current_job_uuid;
@attr('string') photo_uuid;
@attr('string') vehicle_id;
@attr('string') vendor_id;
@attr('string') current_job_id;
Expand Down Expand Up @@ -174,20 +175,17 @@ export default class DriverModel extends Model {
/** @methods */
loadVehicle() {
const owner = getOwner(this);
const store = owner.lookup(`service:store`);
const store = owner.lookup('service:store');

return new Promise((resolve) => {
return new Promise((resolve, reject) => {
if (isRelationMissing(this, 'vehicle')) {
return store
.findRecord('vehicle', this.vehicle_uuid)
.then((vehicle) => {
this.vehicle = vehicle;

resolve(vehicle);
})
.catch(() => {
resolve(null);
});
.catch(reject);
}

resolve(this.vehicle);
Expand All @@ -198,18 +196,15 @@ export default class DriverModel extends Model {
const owner = getOwner(this);
const store = owner.lookup(`service:store`);

return new Promise((resolve) => {
return new Promise((resolve, reject) => {
if (isRelationMissing(this, 'vendor')) {
return store
.findRecord('vendor', this.vendor_uuid)
.then((vendor) => {
this.vendor = vendor;

resolve(vendor);
})
.catch(() => {
resolve(null);
});
.catch(reject);
}

resolve(this.vendor);
Expand Down
47 changes: 46 additions & 1 deletion addon/models/fuel-report.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
import { getOwner } from '@ember/application';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
import isRelationMissing from '@fleetbase/ember-core/utils/is-relation-missing';

export default class FuelReportModel extends Model {
/** @ids */
@attr('string') public_id;
@attr('string') company_uuid;
@attr('string') driver_uuid;
@attr('string') vehicle_uuid;
@attr('string') reported_by_uuid;

/** @relationships */
@belongsTo('driver') driver;
@belongsTo('vehicle') vehicle;
@belongsTo('user') reporter;

/** @attributes */
@attr('string') reporter_name;
@attr('string') driver_name;
@attr('string') vehicle_name;
@attr('string') report;
@attr('string') odometer;
@attr('string') amount;
@attr('string') currency;
@attr('string') volume;
@attr('string', { defaultValue: 'L' }) metric_unit;
@attr('string') type;
@attr('point') location;
@attr('raw') meta;

/** @dates */
@attr('date') deleted_at;
Expand Down Expand Up @@ -71,4 +77,43 @@ export default class FuelReportModel extends Model {
}
return formatDate(this.created_at, 'PP');
}

/** @methods */
loadVehicle() {
const owner = getOwner(this);
const store = owner.lookup('service:store');

return new Promise((resolve, reject) => {
if (isRelationMissing(this, 'vehicle')) {
return store
.findRecord('vehicle', this.vehicle_uuid)
.then((vehicle) => {
this.vehicle = vehicle;
resolve(vehicle);
})
.catch(reject);
}

resolve(this.vehicle);
});
}

loadDriver() {
const owner = getOwner(this);
const store = owner.lookup('service:store');

return new Promise((resolve, reject) => {
if (isRelationMissing(this, 'driver')) {
return store
.findRecord('driver', this.driver_uuid)
.then((driver) => {
this.driver = driver;
resolve(driver);
})
.catch(reject);
}

resolve(this.driver);
});
}
}
54 changes: 51 additions & 3 deletions addon/models/issue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
import { getOwner } from '@ember/application';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
import isRelationMissing from '@fleetbase/ember-core/utils/is-relation-missing';

export default class IssueModel extends Model {
/** @ids */
Expand All @@ -9,21 +11,28 @@ export default class IssueModel extends Model {
@attr('string') company_uuid;
@attr('string') reported_by_uuid;
@attr('string') assigned_to_uuid;
@attr('string') driver_uuid;
@attr('string') vehicle_uuid;

/** @relationships */
@belongsTo('user') reporter;
@belongsTo('user') assignee;
@belongsTo('vehicle') vehicle;
@belongsTo('driver') driver;

/** @attributes */
@attr('string') odometer;
@attr('string') latitude;
@attr('string') longitude;
@attr('string') driver_name;
@attr('string') vehicle_name;
@attr('string') assignee_name;
@attr('string') reporter_name;
@attr('string') type;
@attr('string') category;
@attr('string') report;
@attr('string') priority;
@attr('string') status;
@attr('point') location;
@attr('raw') tags;
@attr('raw') meta;

/** @dates */
@attr('date') deleted_at;
Expand Down Expand Up @@ -72,4 +81,43 @@ export default class IssueModel extends Model {
}
return formatDate(this.created_at, 'PP');
}

/** @methods */
loadVehicle() {
const owner = getOwner(this);
const store = owner.lookup('service:store');

return new Promise((resolve, reject) => {
if (isRelationMissing(this, 'vehicle')) {
return store
.findRecord('vehicle', this.vehicle_uuid)
.then((vehicle) => {
this.vehicle = vehicle;
resolve(vehicle);
})
.catch(reject);
}

resolve(this.vehicle);
});
}

loadDriver() {
const owner = getOwner(this);
const store = owner.lookup('service:store');

return new Promise((resolve, reject) => {
if (isRelationMissing(this, 'driver')) {
return store
.findRecord('driver', this.driver_uuid)
.then((driver) => {
this.driver = driver;
resolve(driver);
})
.catch(reject);
}

resolve(this.driver);
});
}
}
8 changes: 6 additions & 2 deletions addon/models/vendor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
import { computed, get } from '@ember/object';
import { notEmpty } from '@ember/object/computed';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
import config from 'ember-get-config';

export default class VendorModel extends Model {
/** @ids */
Expand All @@ -21,7 +22,10 @@ export default class VendorModel extends Model {
@attr('string') name;
@attr('string') email;
@attr('string') website_url;
@attr('string') logo_url;
@attr('string', {
defaultValue: get(config, 'defaultValues.vendorImage'),
})
logo_url;
@attr('string') phone;
@attr('string') address;
@attr('string') address_street;
Expand Down
3 changes: 2 additions & 1 deletion addon/serializers/fleet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ export default class FleetSerializer extends ApplicationSerializer.extend(Embedd
return {
vendor: { embedded: 'always' },
parent_fleet: { embedded: 'always' },
subfleets: { embedded: 'always' },
service_area: { embedded: 'always' },
zone: { embedded: 'always' },
drivers: { embedded: 'always' },
vehicles: { embedded: 'always' },
};
}

serializeBelongsTo(snapshot, json, relationship) {
let key = relationship.key;

Expand Down
18 changes: 18 additions & 0 deletions addon/serializers/fuel-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ export default class FuelReportSerializer extends ApplicationSerializer.extend(E
return {
driver: { embedded: 'always' },
vehicle: { embedded: 'always' },
reporter: { embedded: 'always' },
};
}

/**
* Customize serializer so that any attributes that are instances of Models or objects
* that are to accept and ID get serialized into the id only
*
* @param {Snapshot} snapshot
* @param {Object} options
* @return {Object} json
*/
serialize() {
const json = super.serialize(...arguments);

// remove automatically set `reporter_uuid`
delete json.reporter_uuid;

return json;
}
}
36 changes: 35 additions & 1 deletion addon/serializers/issue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';

export default class IssueSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {}
export default class IssueSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
/**
* Embedded relationship attributes
*
* @var {Object}
*/
get attrs() {
return {
driver: { embedded: 'always' },
vehicle: { embedded: 'always' },
reporter: { embedded: 'always' },
assignee: { embedded: 'always' },
};
}

/**
* Customize serializer so that any attributes that are instances of Models or objects
* that are to accept and ID get serialized into the id only
*
* @param {Snapshot} snapshot
* @param {Object} options
* @return {Object} json
*/
serialize() {
const json = super.serialize(...arguments);

// remove automatically set `reporter_uuid`
delete json.reporter_uuid;

// remove automatically set `assignee_uuid`
delete json.assignee_uuid;

return json;
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/fleetops-data",
"version": "0.1.1",
"version": "0.1.2",
"description": "Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.",
"keywords": [
"fleetbase-data",
Expand Down Expand Up @@ -42,7 +42,7 @@
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.8.1",
"@embroider/test-setup": "^1.8.3",
"@fleetbase/ember-core": "^0.0.8",
"@fleetbase/ember-core": "^0.1.6",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"babel-eslint": "^10.1.0",
Expand Down
Loading

0 comments on commit 6d0ab56

Please sign in to comment.