diff --git a/package.json b/package.json index 82d86b82..6196f96b 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "bulma": "^0.8.0", "copy-to-clipboard": "^3.2.0", "lodash": "^4.17.15", + "moment": "^2.24.0", "register-service-worker": "^1.6.2", "v-tooltip": "^2.0.2", "verte": "^0.0.12", diff --git a/src/components/tasks/ShowListTasks.vue b/src/components/tasks/ShowListTasks.vue index 81e3ec28..c689c476 100644 --- a/src/components/tasks/ShowListTasks.vue +++ b/src/components/tasks/ShowListTasks.vue @@ -46,7 +46,7 @@ {{ label.title }} - - Due on {{new Date(l.dueDate).toLocaleString()}} + - Due {{formatDateSince(l.dueDate)}} diff --git a/src/components/tasks/ShowTasks.vue b/src/components/tasks/ShowTasks.vue index d6b452d8..05d655c0 100644 --- a/src/components/tasks/ShowTasks.vue +++ b/src/components/tasks/ShowTasks.vue @@ -21,7 +21,7 @@ {{l.text}} - - Due on {{formatUnixDate(l.dueDate)}} + - Due {{formatDateSince(l.dueDate)}} @@ -84,9 +84,6 @@ message.error(e, this) }) }, - formatUnixDate(dateUnix) { - return (new Date(dateUnix * 1000)).toLocaleString() - }, gotoList(lid) { router.push({name: 'showList', params: {id: lid}}) }, diff --git a/src/components/tasks/reusable/attachments.vue b/src/components/tasks/reusable/attachments.vue index 258e000c..380323f7 100644 --- a/src/components/tasks/reusable/attachments.vue +++ b/src/components/tasks/reusable/attachments.vue @@ -31,8 +31,7 @@ {{ a.file.getHumanSize() }} {{ a.file.mime }} - - {{ new Date(a.created) }} + {{ formatDateSince(a.created) }}
diff --git a/src/main.js b/src/main.js index 7aca0fa1..0653d04b 100644 --- a/src/main.js +++ b/src/main.js @@ -120,6 +120,15 @@ Vue.directive('focus', { // Check the user's auth status when the app starts auth.checkAuth() +// Format date mixin +import moment from 'moment' +Vue.mixin({ + methods: { + formatDateSince: date => moment(date).fromNow(), + formatDate: date => moment(date).format('LLL'), + } +}) + new Vue({ router, render: h => h(App) diff --git a/src/models/attachment.js b/src/models/attachment.js index 369fa1f5..1c8650e0 100644 --- a/src/models/attachment.js +++ b/src/models/attachment.js @@ -7,6 +7,7 @@ export default class AttachmentModel extends AbstractModel { super(data) this.created_by = new UserModel(this.created_by) this.file = new FileModel(this.file) + this.created = new Date(this.created * 1000) } defaults() { diff --git a/src/services/attachment.js b/src/services/attachment.js index 8a600444..19eef1e3 100644 --- a/src/services/attachment.js +++ b/src/services/attachment.js @@ -82,4 +82,9 @@ export default class AttachmentService extends AbstractService { cancel() }) } + + processModel(model) { + model.created = Math.round(+new Date(model.created) / 1000) + return model + } } diff --git a/src/services/task.js b/src/services/task.js index b91585b0..a3903090 100644 --- a/src/services/task.js +++ b/src/services/task.js @@ -1,5 +1,6 @@ import AbstractService from './abstractService' import TaskModel from '../models/task' +import AttachmentService from './attachment' export default class TaskService extends AbstractService { constructor() { @@ -81,6 +82,14 @@ export default class TaskService extends AbstractService { }) }) + // Process all attachments to preven parsing errors + if(model.attachments.length > 0) { + const attachmentService = new AttachmentService() + model.attachments.map(a => { + return attachmentService.processModel(a) + }) + } + return model } } \ No newline at end of file diff --git a/src/styles/components/tasks.scss b/src/styles/components/tasks.scss index df9b999d..30655b5c 100644 --- a/src/styles/components/tasks.scss +++ b/src/styles/components/tasks.scss @@ -33,7 +33,8 @@ display: inline-block; cursor: pointer; - .tasktext { + .tasktext, + &.tasktext { vertical-align: top; white-space: nowrap; text-overflow: ellipsis;