Add moment.js for date related things (#50)

Fix saving

Use mixin everywhere

Format attachment dates

Add format date mixing

Use moment js on task list page

Use moment js on home page tasks

Add moment js

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/50
This commit is contained in:
konrad 2020-01-30 20:49:00 +00:00
parent da10b4310b
commit a0c4732f81
9 changed files with 30 additions and 8 deletions

View file

@ -11,6 +11,7 @@
"bulma": "^0.8.0", "bulma": "^0.8.0",
"copy-to-clipboard": "^3.2.0", "copy-to-clipboard": "^3.2.0",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"moment": "^2.24.0",
"register-service-worker": "^1.6.2", "register-service-worker": "^1.6.2",
"v-tooltip": "^2.0.2", "v-tooltip": "^2.0.2",
"verte": "^0.0.12", "verte": "^0.0.12",

View file

@ -46,7 +46,7 @@
<span>{{ label.title }}</span> <span>{{ label.title }}</span>
</span> </span>
<img :src="gravatar(a)" :alt="a.username" v-for="(a, i) in l.assignees" class="avatar" :key="l.id + 'assignee' + a.id + i"/> <img :src="gravatar(a)" :alt="a.username" v-for="(a, i) in l.assignees" class="avatar" :key="l.id + 'assignee' + a.id + i"/>
<i v-if="l.dueDate > 0" :class="{'overdue': (l.dueDate <= new Date())}"> - Due on {{new Date(l.dueDate).toLocaleString()}}</i> <i v-if="l.dueDate > 0" :class="{'overdue': l.dueDate <= new Date() && !l.done}" v-tooltip="formatDate(l.dueDate)"> - Due {{formatDateSince(l.dueDate)}}</i>
<priority-label :priority="l.priority"/> <priority-label :priority="l.priority"/>
</router-link> </router-link>
</span> </span>

View file

@ -21,7 +21,7 @@
</div> </div>
<span class="tasktext"> <span class="tasktext">
{{l.text}} {{l.text}}
<i v-if="l.dueDate > 0" :class="{'overdue': (new Date(l.dueDate * 1000) <= new Date())}"> - Due on {{formatUnixDate(l.dueDate)}}</i> <i v-if="l.dueDate > 0" :class="{'overdue': l.dueDate <= new Date()}" v-tooltip="formatDate(l.dueDate)"> - Due {{formatDateSince(l.dueDate)}}</i>
<priority-label :priority="l.priority"/> <priority-label :priority="l.priority"/>
</span> </span>
</label> </label>
@ -84,9 +84,6 @@
message.error(e, this) message.error(e, this)
}) })
}, },
formatUnixDate(dateUnix) {
return (new Date(dateUnix * 1000)).toLocaleString()
},
gotoList(lid) { gotoList(lid) {
router.push({name: 'showList', params: {id: lid}}) router.push({name: 'showList', params: {id: lid}})
}, },

View file

@ -31,8 +31,7 @@
</td> </td>
<td>{{ a.file.getHumanSize() }}</td> <td>{{ a.file.getHumanSize() }}</td>
<td>{{ a.file.mime }}</td> <td>{{ a.file.mime }}</td>
<!-- FIXME: This needs a better solution--> <td v-tooltip="formatDate(a.created)">{{ formatDateSince(a.created) }}</td>
<td>{{ new Date(a.created) }}</td>
<td> <td>
<div class="buttons has-addons"> <div class="buttons has-addons">
<a class="button is-primary noshadow" @click="downloadAttachment(a)" v-tooltip="'Download this attachment'"> <a class="button is-primary noshadow" @click="downloadAttachment(a)" v-tooltip="'Download this attachment'">

View file

@ -120,6 +120,15 @@ Vue.directive('focus', {
// Check the user's auth status when the app starts // Check the user's auth status when the app starts
auth.checkAuth() 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({ new Vue({
router, router,
render: h => h(App) render: h => h(App)

View file

@ -7,6 +7,7 @@ export default class AttachmentModel extends AbstractModel {
super(data) super(data)
this.created_by = new UserModel(this.created_by) this.created_by = new UserModel(this.created_by)
this.file = new FileModel(this.file) this.file = new FileModel(this.file)
this.created = new Date(this.created * 1000)
} }
defaults() { defaults() {

View file

@ -82,4 +82,9 @@ export default class AttachmentService extends AbstractService {
cancel() cancel()
}) })
} }
processModel(model) {
model.created = Math.round(+new Date(model.created) / 1000)
return model
}
} }

View file

@ -1,5 +1,6 @@
import AbstractService from './abstractService' import AbstractService from './abstractService'
import TaskModel from '../models/task' import TaskModel from '../models/task'
import AttachmentService from './attachment'
export default class TaskService extends AbstractService { export default class TaskService extends AbstractService {
constructor() { 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 return model
} }
} }

View file

@ -33,7 +33,8 @@
display: inline-block; display: inline-block;
cursor: pointer; cursor: pointer;
.tasktext { .tasktext,
&.tasktext {
vertical-align: top; vertical-align: top;
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;