@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
96 lines (80 loc) • 2.87 kB
JavaScript
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 ZoneModel extends Model {
/** @ids */
public_id;
service_area_uuid;
/** @relationships */
service_area;
custom_field_values;
/** @attributes */
name;
description;
color;
stroke_color;
status;
border;
center;
/** @dates */
deleted_at;
created_at;
updated_at;
/** @computed */
get coordinates() {
return this.border?.coordinates[0] ?? [];
}
get leafletCoordinates() {
return this.coordinates.map(([longitude, latitude]) => [latitude, longitude]);
}
get firstCoordinatePair() {
const [latitude, longitude] = this.leafletCoordinates[0] ?? [0, 0];
return [latitude, longitude];
}
/* eslint-disable no-unused-vars */
get firstCoordinatePairLatitude() {
const [latitude, longitude] = this.firstCoordinatePair;
return latitude;
}
/* eslint-disable no-unused-vars */
get firstCoordinatePairLongitude() {
const [latitude, longitude] = this.firstCoordinatePair;
return longitude;
}
get updatedAgo() {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDistanceToNow(this.updated_at);
}
get updatedAt() {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDate(this.updated_at, 'yyyy-MM-dd HH:mm');
}
get updatedAtShort() {
if (!isValidDate(this.updated_at)) {
return null;
}
return formatDate(this.updated_at, 'dd, MMM');
}
get createdAgo() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDistanceToNow(this.created_at);
}
get createdAt() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'yyyy-MM-dd HH:mm');
}
get createdAtShort() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'dd, MMM');
}
}