UNPKG

@fleetbase/fleetops-data

Version:

Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.

79 lines (68 loc) 2.32 kB
import Model, { attr } from '@ember-data/model'; import { computed } from '@ember/object'; import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns'; /** * Abstract base model for polymorphic maintenance subjects. * Concrete types: maintenance-subject-vehicle, maintenance-subject-equipment * * The backend stores the type as a PolymorphicType cast string, e.g.: * 'fleet-ops:vehicle' -> maintenance-subject-vehicle * 'fleet-ops:equipment' -> maintenance-subject-equipment */ export default class MaintenanceSubjectModel extends Model { /** @ids */ @attr('string') uuid; @attr('string') public_id; @attr('string') company_uuid; /** @attributes */ @attr('string') name; @attr('string') display_name; @attr('string') type; @attr('string') status; @attr('string') photo_url; @attr('string') slug; /** @dates */ @attr('date') deleted_at; @attr('date') created_at; @attr('date') updated_at; /** @computed */ @computed('name', 'display_name', 'public_id') get displayName() { return this.display_name || this.name || this.public_id; } @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'); } }