|
1 |
| -import ExtensionModel from '@fleetbase/console/models/extension'; |
2 |
| -import { attr } from '@ember-data/model'; |
| 1 | +import Model, { attr, belongsTo } from '@ember-data/model'; |
| 2 | +import { computed, action } from '@ember/object'; |
| 3 | +import { format as formatDate, formatDistanceToNow, isValid as isValidDate } from 'date-fns'; |
3 | 4 |
|
4 |
| -export default class OrderConfigModel extends ExtensionModel { |
5 |
| - @attr('string') install_uuid; |
6 |
| - @attr('boolean') installed; |
| 5 | +export default class OrderConfigModel extends Model { |
| 6 | + /** @ids */ |
| 7 | + @attr('string') company_uuid; |
| 8 | + @attr('string') author_uuid; |
| 9 | + @attr('string') category_uuid; |
| 10 | + @attr('string') icon_uuid; |
| 11 | + |
| 12 | + /** @relationships */ |
| 13 | + @belongsTo('user') author; |
| 14 | + @belongsTo('category') category; |
| 15 | + @belongsTo('file') icon; |
| 16 | + |
| 17 | + /** @attributs */ |
| 18 | + @attr('string') name; |
| 19 | + @attr('string') namespace; |
| 20 | + @attr('string') description; |
| 21 | + @attr('string') key; |
| 22 | + @attr('string') status; |
| 23 | + @attr('string') version; |
| 24 | + @attr('boolean', { defaultValue: false }) core_service; |
| 25 | + @attr('array') tags; |
| 26 | + @attr('object') flow; |
| 27 | + @attr('object') entities; |
| 28 | + @attr('object') meta; |
| 29 | + |
| 30 | + /** @computed */ |
| 31 | + @computed('updated_at') get updatedAgo() { |
| 32 | + if (!isValidDate(this.updated_at)) { |
| 33 | + return null; |
| 34 | + } |
| 35 | + |
| 36 | + return formatDistanceToNow(this.updated_at); |
| 37 | + } |
| 38 | + |
| 39 | + @computed('updated_at') get updatedAt() { |
| 40 | + if (!isValidDate(this.updated_at)) { |
| 41 | + return null; |
| 42 | + } |
| 43 | + |
| 44 | + return formatDate(this.updated_at, 'PP HH:mm'); |
| 45 | + } |
| 46 | + |
| 47 | + @computed('updated_at') get updatedAtShort() { |
| 48 | + if (!isValidDate(this.updated_at)) { |
| 49 | + return null; |
| 50 | + } |
| 51 | + |
| 52 | + return formatDate(this.updated_at, 'dd, MMM'); |
| 53 | + } |
| 54 | + |
| 55 | + @computed('created_at') get createdAgo() { |
| 56 | + if (!isValidDate(this.created_at)) { |
| 57 | + return null; |
| 58 | + } |
| 59 | + |
| 60 | + return formatDistanceToNow(this.created_at); |
| 61 | + } |
| 62 | + |
| 63 | + @computed('created_at') get createdAt() { |
| 64 | + if (!isValidDate(this.created_at)) { |
| 65 | + return null; |
| 66 | + } |
| 67 | + |
| 68 | + return formatDate(this.created_at, 'PP HH:mm'); |
| 69 | + } |
| 70 | + |
| 71 | + @computed('created_at') get createdAtShort() { |
| 72 | + if (!isValidDate(this.created_at)) { |
| 73 | + return null; |
| 74 | + } |
| 75 | + |
| 76 | + return formatDate(this.created_at, 'dd, MMM'); |
| 77 | + } |
| 78 | + |
| 79 | + /** @methods */ |
| 80 | + /** |
| 81 | + * Adds a new tag to the tags array. |
| 82 | + * |
| 83 | + * This method takes a tag and adds it to the 'tags' array property |
| 84 | + * of the current instance. The 'pushObject' method is used, which is |
| 85 | + * typically available in Ember.js or similar frameworks that extend |
| 86 | + * JavaScript array functionalities. |
| 87 | + * |
| 88 | + * @param {string} tag - The tag to be added to the tags array. |
| 89 | + */ |
| 90 | + @action addTag(tag) { |
| 91 | + this.tags.push(tag); |
| 92 | + this.tags = [...this.tags]; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Removes a tag from the tags array at a specific index. |
| 97 | + * |
| 98 | + * This method takes an index and removes the element at that position |
| 99 | + * from the 'tags' array property of the current instance. The 'removeAt' |
| 100 | + * method is used, which is typically available in Ember.js or similar |
| 101 | + * frameworks that provide extended array functionalities. |
| 102 | + * |
| 103 | + * @param {number} index - The index of the tag to be removed from the tags array. |
| 104 | + */ |
| 105 | + @action removeTag(index) { |
| 106 | + this.tags.removeAt(index); |
| 107 | + this.tags = [...this.tags]; |
| 108 | + } |
7 | 109 | }
|
0 commit comments