@fleetbase/fleetops-data
Version:
Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.
112 lines (94 loc) • 3.21 kB
JavaScript
import Model, { attr, belongsTo } from '@ember-data/model';
import { computed, action } from '@ember/object';
import { format as formatDate, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
export default class OrderConfigModel extends Model {
/** @ids */
public_id;
company_uuid;
author_uuid;
category_uuid;
icon_uuid;
/** @relationships */
author;
category;
icon;
/** @attributs */
name;
namespace;
description;
key;
status;
version;
type;
core_service;
tags;
entities;
flow;
meta;
/** @computed */
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, 'PP 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, 'PP HH:mm');
}
get createdAtShort() {
if (!isValidDate(this.created_at)) {
return null;
}
return formatDate(this.created_at, 'dd, MMM');
}
/** @methods */
/**
* Adds a new tag to the tags array.
*
* This method takes a tag and adds it to the 'tags' array property
* of the current instance. The 'pushObject' method is used, which is
* typically available in Ember.js or similar frameworks that extend
* JavaScript array functionalities.
*
* @param {string} tag - The tag to be added to the tags array.
*/
addTag(tag) {
this.tags.push(tag);
this.tags = [...this.tags];
}
/**
* Removes a tag from the tags array at a specific index.
*
* This method takes an index and removes the element at that position
* from the 'tags' array property of the current instance. The 'removeAt'
* method is used, which is typically available in Ember.js or similar
* frameworks that provide extended array functionalities.
*
* @param {number} index - The index of the tag to be removed from the tags array.
*/
removeTag(index) {
this.tags.removeAt(index);
this.tags = [...this.tags];
}
}