Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions addon/models/asset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';

export default class AssetModel extends Model {
/** @ids */
@attr('string') public_id;
@attr('string') company_uuid;
@attr('string') category_uuid;
@attr('string') vendor_uuid;
@attr('string') warranty_uuid;
@attr('string') telematic_uuid;
@attr('string') assigned_to_uuid;
@attr('string') assigned_to_type;
@attr('string') operator_uuid;
@attr('string') operator_type;
@attr('string') current_place_uuid;
@attr('string') photo_uuid;

/** @relationships */
@belongsTo('category', { async: false }) category;
@belongsTo('vendor', { async: false }) vendor;
@belongsTo('warranty', { async: false }) warranty;
@belongsTo('telematic', { async: false }) telematic;
@belongsTo('place', { async: false }) current_place;
@belongsTo('file', { async: false }) photo;
@hasMany('device', { async: false }) devices;
@hasMany('equipment', { async: false }) equipments;
@hasMany('maintenance', { async: false }) maintenances;
@hasMany('sensor', { async: false }) sensors;
@hasMany('part', { async: false }) parts;
@hasMany('custom-field-value', { async: false }) custom_field_values;

/** @attributes */
@attr('string') name;
@attr('string') description;
@attr('string') code;
@attr('string') type;
@attr('point') location;
@attr('string') speed;
@attr('string') heading;
@attr('string') altitude;
@attr('string') status;
@attr('string') usage_type;
@attr('string') vin;
@attr('string') plate_number;
@attr('string') make;
@attr('string') model;
@attr('string') year;
@attr('string') color;
@attr('string') serial_number;
@attr('string') measurement_system;
@attr('string') odometer;
@attr('string') odometer_unit;
@attr('string') transmission;
@attr('string') fuel_volume_unit;
@attr('string') fuel_Type;
@attr('string') ownership_type;
@attr('string') engine_hours;
@attr('string') gvw;
@attr('raw') capacity;
@attr('raw') specs;
@attr('raw') attributes;
@attr('string') notes;
@attr('string') slug;
@attr('string') photo_url;
@attr('string') display_name;
@attr('string') category_name;
@attr('string') vendor_name;
@attr('string') warranty_name;

/** @dates */
@attr('date') deleted_at;
@attr('date') created_at;
@attr('date') updated_at;

/** @computed */
@computed('year', 'make', 'model') get yearMakeModel() {
return [this.year, this.make, this.model].filter(Boolean).join(' ');
}

@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, 'yyyy-MM-dd 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, 'yyyy-MM-dd HH:mm');
}

@computed('created_at') get createdAtShort() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'dd, MMM');
}

@computed('deleted_at') get deletedAgo() {
if (!isValidDate(this.deleted_at)) {
return null;
}
return formatDistanceToNow(this.deleted_at);
}

@computed('deleted_at') get deletedAt() {
if (!isValidDate(this.deleted_at)) {
return null;
}
return formatDate(this.deleted_at, 'yyyy-MM-dd HH:mm');
}

@computed('deleted_at') get deletedAtShort() {
if (!isValidDate(this.deleted_at)) {
return null;
}
return formatDate(this.deleted_at, 'dd, MMM');
}
}
8 changes: 6 additions & 2 deletions addon/models/contact.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import { computed } from '@ember/object';
import { notEmpty } from '@ember/object/computed';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';

export default class ContactModel extends Model {
Expand All @@ -16,6 +17,7 @@ export default class ContactModel extends Model {
@belongsTo('user') user;
@belongsTo('place') place;
@hasMany('place') places;
@hasMany('custom-field-value', { async: false }) custom_field_values;

/** @attributes */
@attr('string') name;
Expand All @@ -37,6 +39,8 @@ export default class ContactModel extends Model {
@attr('date') updated_at;

/** @computed */
@notEmpty('place_uuid') has_place;

@computed('public_id') get customerId() {
return this.public_id.replace('contact_', 'customer_');
}
Expand All @@ -52,7 +56,7 @@ export default class ContactModel extends Model {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDate(this.updated_at, 'PPP p');
return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
}

@computed('updated_at') get updatedAtShort() {
Expand All @@ -73,7 +77,7 @@ export default class ContactModel extends Model {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'PPP p');
return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
}

@computed('created_at') get createdAtShort() {
Expand Down
6 changes: 3 additions & 3 deletions addon/models/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class CustomerModel extends ContactModel {
@attr('string') customer_type;

/** @relations */
@hasMany('waypoint') waypoints;
@hasMany('waypoint', { async: false, inverse: 'customer' }) waypoints;

/** @computed */
@equal('customer_type', 'vendor') isVendor;
Expand All @@ -27,7 +27,7 @@ export default class CustomerModel extends ContactModel {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDate(this.updated_at, 'PPP p');
return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
}

@computed('updated_at') get updatedAtShort() {
Expand All @@ -48,7 +48,7 @@ export default class CustomerModel extends ContactModel {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'PPP p');
return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
}

@computed('created_at') get createdAtShort() {
Expand Down
142 changes: 142 additions & 0 deletions addon/models/device-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';

export default class DeviceEventModel extends Model {
/** @ids */
@attr('string') public_id;
@attr('string') device_uuid;

/** @relationships */
@belongsTo('device', { async: false }) device;

/** @attributes */
@attr('raw') payload;
@attr('raw') meta;
@attr('string') location;
@attr('string') event_type;
@attr('string') severity;
@attr('string') ident;
@attr('string') protocol;
@attr('string') provider;
@attr('string') mileage;
@attr('string') state;
@attr('string') code;
@attr('string') reason;
@attr('string') comment;
@attr('string') slug;
@attr('string') device_name;

/** @dates */
@attr('date') occurred_at;
@attr('date') processed_at;
@attr('date') deleted_at;
@attr('date') created_at;
@attr('date') updated_at;

/** @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, 'yyyy-MM-dd 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, 'yyyy-MM-dd HH:mm');
}

@computed('created_at') get createdAtShort() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'dd, MMM');
}

@computed('deleted_at') get deletedAgo() {
if (!isValidDate(this.deleted_at)) {
return null;
}
return formatDistanceToNow(this.deleted_at);
}

@computed('deleted_at') get deletedAt() {
if (!isValidDate(this.deleted_at)) {
return null;
}
return formatDate(this.deleted_at, 'yyyy-MM-dd HH:mm');
}

@computed('deleted_at') get deletedAtShort() {
if (!isValidDate(this.deleted_at)) {
return null;
}
return formatDate(this.deleted_at, 'dd, MMM');
}

@computed('occurred_at') get occurredAgo() {
if (!isValidDate(this.occurred_at)) {
return null;
}
return formatDistanceToNow(this.occurred_at);
}

@computed('occurred_at') get occurredAt() {
if (!isValidDate(this.occurred_at)) {
return null;
}
return formatDate(this.occurred_at, 'yyyy-MM-dd HH:mm');
}

@computed('occurred_at') get occurredAtShort() {
if (!isValidDate(this.occurred_at)) {
return null;
}
return formatDate(this.occurred_at, 'dd, MMM');
}

@computed('processed_at') get processedAgo() {
if (!isValidDate(this.processed_at)) {
return null;
}
return formatDistanceToNow(this.processed_at);
}

@computed('processed_at') get processedAt() {
if (!isValidDate(this.processed_at)) {
return null;
}
return formatDate(this.processed_at, 'yyyy-MM-dd HH:mm');
}

@computed('processed_at') get processedAtShort() {
if (!isValidDate(this.processed_at)) {
return null;
}
return formatDate(this.processed_at, 'dd, MMM');
}
}
Loading
Loading