+
+
@@ -133,12 +158,16 @@
loading: false,
isTaskEdit: false,
taskEditTask: {},
+ lastReminder: 0,
+ nowUnix: new Date(),
+ repeatAfter: {type: 'days', amount: null},
flatPickerConfig:{
altFormat: 'j M Y H:i',
altInput: true,
dateFormat: 'Y-m-d H:i',
enableTime: true,
- defaultDate: new Date(),
+ onOpen: this.updateLastReminderDate,
+ onClose: this.addReminderDate,
},
}
},
@@ -161,18 +190,22 @@
methods: {
loadList() {
this.isTaskEdit = false
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.get(`lists/` + this.$route.params.id, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
- this.loading = false
-
// Make date objects from timestamps
for (const t in response.data.tasks) {
let dueDate = new Date(response.data.tasks[t].dueDate * 1000)
- let reminderDate = new Date(response.data.tasks[t].reminderDate * 1000)
- response.data.tasks[t].dueDate = dueDate
- response.data.tasks[t].reminderDate = reminderDate
+ if (dueDate === 0) {
+ response.data.tasks[t].dueDate = null
+ } else {
+ response.data.tasks[t].dueDate = dueDate
+ }
+
+ for (const rd in response.data.tasks[t].reminderDates) {
+ response.data.tasks[t].reminderDates[rd] = new Date(response.data.tasks[t].reminderDates[rd] * 1000)
+ }
}
// This adds a new elemednt "list" to our object which contains all lists
@@ -180,40 +213,45 @@
if (this.list.tasks === null) {
this.list.tasks = []
}
+ cancel() // cancel the timer
})
.catch(e => {
- this.handleError(e)
+ cancel()
+ this.handleError(e)
})
},
addTask() {
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.put(`lists/` + this.$route.params.id, {text: this.newTask}, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
this.list.tasks.push(response.data)
this.handleSuccess({message: 'The task was successfully created.'})
+ cancel() // cancel the timer
})
.catch(e => {
- this.handleError(e)
+ cancel()
+ this.handleError(e)
})
this.newTask = ''
},
markAsDone(e) {
-
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.post(`tasks/` + e.target.id, {done: e.target.checked}, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
this.updateTaskByID(parseInt(e.target.id), response.data)
this.handleSuccess({message: 'The task was successfully ' + (e.target.checked ? 'un-' :'') + 'marked as done.'})
+ cancel() // To not set the spinner to loading when the request is made in less than 100ms, would lead to loading infinitly.
})
.catch(e => {
- this.handleError(e)
+ cancel()
+ this.handleError(e)
})
},
editTask(id) {
- // Find the slected task and set it to the current object
+ // Find the selected task and set it to the current object
for (const t in this.list.tasks) {
if (this.list.tasks[t].id === id) {
this.taskEditTask = this.list.tasks[t]
@@ -221,45 +259,150 @@
}
}
+ if (this.taskEditTask.reminderDates === null) {
+ this.taskEditTask.reminderDates = []
+ }
+ this.taskEditTask.reminderDates = this.removeNullsFromArray(this.taskEditTask.reminderDates)
+ this.taskEditTask.reminderDates.push(null)
+
+ // Re-convert the the amount from seconds to be used with our form
+ let repeatAfterHours = (this.taskEditTask.repeatAfter / 60) / 60
+ // if its dividable by 24, its something with days
+ if (repeatAfterHours % 24 === 0) {
+ let repeatAfterDays = repeatAfterHours / 24
+ if (repeatAfterDays % 7 === 0) {
+ this.repeatAfter.type = 'weeks'
+ this.repeatAfter.amount = repeatAfterDays / 7
+ } else if (repeatAfterDays % 30 === 0) {
+ this.repeatAfter.type = 'months'
+ this.repeatAfter.amount = repeatAfterDays / 30
+ } else if (repeatAfterDays % 365 === 0) {
+ this.repeatAfter.type = 'years'
+ this.repeatAfter.amount = repeatAfterDays / 365
+ } else {
+ this.repeatAfter.type = 'days'
+ this.repeatAfter.amount = repeatAfterDays
+ }
+ } else {
+ // otherwise hours
+ this.repeatAfter.type = 'hours'
+ this.repeatAfter.amount = repeatAfterHours
+ }
this.isTaskEdit = true
},
editTaskSubmit() {
- this.loading = true
+ const cancel = message.setLoading(this)
// Convert the date in a unix timestamp
let duedate = (+ new Date(this.taskEditTask.dueDate)) / 1000
- let reminderdate = (+ new Date(this.taskEditTask.reminderDate)) / 1000
this.taskEditTask.dueDate = duedate
- this.taskEditTask.reminderDate = reminderdate
+
+ // remove all nulls
+ this.taskEditTask.reminderDates = this.removeNullsFromArray(this.taskEditTask.reminderDates)
+ // Make normal timestamps from js timestamps
+ for (const t in this.taskEditTask.reminderDates) {
+ this.taskEditTask.reminderDates[t] = Math.round(this.taskEditTask.reminderDates[t] / 1000)
+ }
+
+ // Make the repeating amount to seconds
+ let repeatAfterSeconds = 0
+ if (this.repeatAfter.amount !== null || this.repeatAfter.amount !== 0) {
+ switch (this.repeatAfter.type) {
+ case 'hours':
+ repeatAfterSeconds = this.repeatAfter.amount * 60 * 60
+ break;
+ case 'days':
+ repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24
+ break;
+ case 'weeks':
+ repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24 * 7
+ break;
+ case 'months':
+ repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24 * 30
+ break;
+ case 'years':
+ repeatAfterSeconds = this.repeatAfter.amount * 60 * 60 * 24 * 365
+ break;
+ }
+ }
+ this.taskEditTask.repeatAfter = repeatAfterSeconds
HTTP.post(`tasks/` + this.taskEditTask.id, this.taskEditTask, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
response.data.dueDate = new Date(response.data.dueDate * 1000)
- response.data.reminderDate = new Date(response.data.reminderDate * 1000)
+ response.data.reminderDates = this.makeJSReminderDatesAfterUpdate(response.data.reminderDates)
+
// Update the task in the list
this.updateTaskByID(this.taskEditTask.id, response.data)
- // Also update the current taskedit object so the ui changes
- this.$set(this, 'taskEditTask', response.data)
+
+ // Also update the current taskedit object so the ui changes
+ this.$set(this, 'taskEditTask', response.data)
this.handleSuccess({message: 'The task was successfully updated.'})
+ cancel() // cancel the timers
})
.catch(e => {
- this.handleError(e)
+ cancel()
+ this.handleError(e)
})
},
updateTaskByID(id, updatedTask) {
for (const t in this.list.tasks) {
if (this.list.tasks[t].id === id) {
+ //updatedTask.reminderDates = this.makeJSReminderDatesAfterUpdate(updatedTask.reminderDates)
this.$set(this.list.tasks, t, updatedTask)
break
}
}
},
+ updateLastReminderDate(selectedDates) {
+ this.lastReminder = +new Date(selectedDates[0])
+ },
+ addReminderDate(selectedDates, dateStr, instance) {
+ let newDate = +new Date(selectedDates[0])
+
+ // Don't update if nothing changed
+ if (newDate === this.lastReminder) {
+ return
+ }
+
+ let index = parseInt(instance.input.dataset.index)
+ this.taskEditTask.reminderDates[index] = newDate
+
+ let lastIndex = this.taskEditTask.reminderDates.length - 1
+ // put a new null at the end if we changed something
+ if (lastIndex === index && !isNaN(newDate)) {
+ this.taskEditTask.reminderDates.push(null)
+ }
+ },
+ removeReminderByIndex(index) {
+ this.taskEditTask.reminderDates.splice(index, 1)
+ // Reset the last to 0 to have the "add reminder" button
+ this.taskEditTask.reminderDates[this.taskEditTask.reminderDates.length - 1] = null
+ },
+ removeNullsFromArray(array) {
+ for (const index in array) {
+ if (array[index] === null) {
+ array.splice(index, 1)
+ }
+ }
+ return array
+ },
+ makeJSReminderDatesAfterUpdate(dates) {
+ // Make js timestamps from normal timestamps
+ for (const rd in dates) {
+ dates[rd] = +new Date(dates[rd] * 1000)
+ }
+
+ if (dates == null) {
+ dates = []
+ }
+ dates.push(null)
+ return dates
+ },
handleError(e) {
- this.loading = false
message.error(e, this)
},
handleSuccess(e) {
- this.loading = false
message.success(e, this)
}
}
diff --git a/src/components/namespaces/EditNamespace.vue b/src/components/namespaces/EditNamespace.vue
index 68ab4cf0..507bd398 100644
--- a/src/components/namespaces/EditNamespace.vue
+++ b/src/components/namespaces/EditNamespace.vue
@@ -97,7 +97,7 @@
},
methods: {
loadNamespace() {
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.get(`namespaces/` + this.$route.params.id, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
@@ -105,14 +105,15 @@
if (response.data.owner.id === this.user.infos.id) {
this.userIsAdmin = true
}
- this.loading = false
+ cancel()
})
.catch(e => {
- this.handleError(e)
+ cancel()
+ this.handleError(e)
})
},
submit() {
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.post(`namespaces/` + this.$route.params.id, this.namespace, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
@@ -124,27 +125,30 @@
}
}
this.handleSuccess({message: 'The namespace was successfully updated.'})
+ cancel()
})
.catch(e => {
- this.handleError(e)
+ cancel()
+ this.handleError(e)
})
},
deleteNamespace() {
+ const cancel = message.setLoading(this)
HTTP.delete(`namespaces/` + this.$route.params.id, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(() => {
this.handleSuccess({message: 'The namespace was successfully deleted.'})
- router.push({name: 'home'})
+ cancel()
+ router.push({name: 'home'})
})
.catch(e => {
- this.handleError(e)
+ cancel()
+ this.handleError(e)
})
},
handleError(e) {
- this.loading = false
message.error(e, this)
},
handleSuccess(e) {
- this.loading = false
message.success(e, this)
}
}
diff --git a/src/components/namespaces/NewNamespace.vue b/src/components/namespaces/NewNamespace.vue
index 7f523fd8..7e5b18fd 100644
--- a/src/components/namespaces/NewNamespace.vue
+++ b/src/components/namespaces/NewNamespace.vue
@@ -45,23 +45,23 @@
},
methods: {
newNamespace() {
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.put(`namespaces`, this.namespace, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(() => {
this.$parent.loadNamespaces()
this.handleSuccess({message: 'The namespace was successfully created.'})
+ cancel()
})
.catch(e => {
- this.handleError(e)
+ cancel()
+ this.handleError(e)
})
},
handleError(e) {
- this.loading = false
message.error(e, this)
},
handleSuccess(e) {
- this.loading = false
message.success(e, this)
}
}
diff --git a/src/components/sharing/team.vue b/src/components/sharing/team.vue
index 2f36c615..93f008c5 100644
--- a/src/components/sharing/team.vue
+++ b/src/components/sharing/team.vue
@@ -121,27 +121,33 @@
},
methods: {
loadTeams() {
+ const cancel = message.setLoading(this)
HTTP.get(this.typeString + `s/` + this.id + `/teams`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
this.$set(this, 'listTeams', response.data)
- this.loading = false
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
deleteTeam() {
+ const cancel = message.setLoading(this)
HTTP.delete(this.typeString + `s/` + this.id + `/teams/` + this.teamToDelete, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(() => {
this.showTeamDeleteModal = false;
this.handleSuccess({message: 'The team was successfully deleted from the ' + this.typeString + '.'})
this.loadTeams()
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
addTeam(admin) {
+ const cancel = message.setLoading(this)
if(admin === null) {
admin = false
}
@@ -154,12 +160,15 @@
.then(() => {
this.loadTeams()
this.handleSuccess({message: 'The team was successfully added.'})
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
toggleTeamType(teamid, current) {
+ const cancel = message.setLoading(this)
let right = 0
if (!current) {
right = 2
@@ -169,17 +178,17 @@
.then(() => {
this.loadTeams()
this.handleSuccess({message: 'The team right was successfully updated.'})
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
handleError(e) {
- this.loading = false
message.error(e, this)
},
handleSuccess(e) {
- this.loading = false
message.success(e, this)
}
},
diff --git a/src/components/sharing/user.vue b/src/components/sharing/user.vue
index c96c3f46..3405c958 100644
--- a/src/components/sharing/user.vue
+++ b/src/components/sharing/user.vue
@@ -142,28 +142,34 @@
},
methods: {
loadUsers() {
+ const cancel = message.setLoading(this)
HTTP.get(this.typeString + `s/` + this.id + `/users`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
//response.data.push(this.list.owner)
this.$set(this, 'users', response.data)
- this.loading = false
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
deleteUser() {
+ const cancel = message.setLoading(this)
HTTP.delete(this.typeString + `s/` + this.id + `/users/` + this.userToDelete, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(() => {
this.showUserDeleteModal = false;
this.handleSuccess({message: 'The user was successfully deleted from the ' + this.typeString + '.'})
this.loadUsers()
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
addUser(admin) {
+ const cancel = message.setLoading(this)
if(admin === null) {
admin = false
}
@@ -179,12 +185,15 @@
this.loadUsers()
this.newUser = {}
this.handleSuccess({message: 'The user was successfully added.'})
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
toggleUserType(userid, current) {
+ const cancel = message.setLoading(this)
let right = 0
if (!current) {
right = 2
@@ -194,16 +203,18 @@
.then(() => {
this.loadUsers()
this.handleSuccess({message: 'The user right was successfully updated.'})
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
findUsers(query) {
- this.loading = true;
+ const cancel = message.setLoading(this)
if(query === '') {
this.$set(this, 'foundUsers', [])
- this.loading = false
+ cancel()
return
}
@@ -220,9 +231,10 @@
})
}
- this.loading = false
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
@@ -233,11 +245,9 @@
return `and ${count} others`
},
handleError(e) {
- this.loading = false
message.error(e, this)
},
handleSuccess(e) {
- this.loading = false
message.success(e, this)
}
},
diff --git a/src/components/teams/EditTeam.vue b/src/components/teams/EditTeam.vue
index d560bd2f..4de67b58 100644
--- a/src/components/teams/EditTeam.vue
+++ b/src/components/teams/EditTeam.vue
@@ -170,7 +170,7 @@
},
methods: {
loadTeam() {
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.get(`teams/` + this.$route.params.id, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
@@ -181,14 +181,14 @@
this.userIsAdmin = true
}
}
- this.loading = false
+ cancel()
})
.catch(e => {
this.handleError(e)
})
},
submit() {
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.post(`teams/` + this.$route.params.id, this.team, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
@@ -200,33 +200,42 @@
}
}
this.handleSuccess({message: 'The team was successfully updated.'})
+ cancel()
})
.catch(e => {
- this.handleError(e)
+ cancel()
+ this.handleError(e)
})
},
deleteTeam() {
+ const cancel = message.setLoading(this)
HTTP.delete(`teams/` + this.$route.params.id, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(() => {
this.handleSuccess({message: 'The team was successfully deleted.'})
+ cancel()
router.push({name: 'home'})
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
deleteUser() {
+ const cancel = message.setLoading(this)
HTTP.delete(`teams/` + this.$route.params.id + `/members/` + this.userToDelete, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(() => {
this.showUserDeleteModal = false;
this.handleSuccess({message: 'The user was successfully deleted from the team.'})
this.loadTeam()
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
addUser(admin) {
+ const cancel = message.setLoading(this)
if(admin === null) {
admin = false
}
@@ -234,8 +243,10 @@
.then(() => {
this.loadTeam()
this.handleSuccess({message: 'The team member was successfully added.'})
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
@@ -246,11 +257,9 @@
this.addUser(!current)
},
handleError(e) {
- this.loading = false
message.error(e, this)
},
handleSuccess(e) {
- this.loading = false
message.success(e, this)
}
}
diff --git a/src/components/teams/ListTeams.vue b/src/components/teams/ListTeams.vue
index c6cf2c1b..8d9fe742 100644
--- a/src/components/teams/ListTeams.vue
+++ b/src/components/teams/ListTeams.vue
@@ -40,19 +40,18 @@
},
methods: {
loadTeams() {
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.get(`teams`, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
this.$set(this, 'teams', response.data)
- this.loading = false
+ cancel()
})
.catch(e => {
this.handleError(e)
})
},
handleError(e) {
- this.loading = false
message.error(e, this)
},
}
diff --git a/src/components/teams/NewTeam.vue b/src/components/teams/NewTeam.vue
index ce29c045..25aea6b5 100644
--- a/src/components/teams/NewTeam.vue
+++ b/src/components/teams/NewTeam.vue
@@ -45,23 +45,23 @@
},
methods: {
newTeam() {
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.put(`teams`, this.team, {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}})
.then(response => {
router.push({name:'editTeam', params:{id: response.data.id}})
this.handleSuccess({message: 'The team was successfully created.'})
+ cancel()
})
.catch(e => {
+ cancel()
this.handleError(e)
})
},
handleError(e) {
- this.loading = false
message.error(e, this)
},
handleSuccess(e) {
- this.loading = false
message.success(e, this)
}
}
diff --git a/src/components/user/Login.vue b/src/components/user/Login.vue
index db80c23f..ce354f5e 100644
--- a/src/components/user/Login.vue
+++ b/src/components/user/Login.vue
@@ -36,6 +36,7 @@
import auth from '../../auth'
import router from '../../router'
import {HTTP} from '../../http-common'
+ import message from '../../message'
export default {
data() {
@@ -53,15 +54,15 @@
// Try to verify the email
let emailVerifyToken = localStorage.getItem('emailConfirmToken')
if (emailVerifyToken) {
- this.loading = true
+ const cancel = message.setLoading(this)
HTTP.post(`user/confirm`, {token: emailVerifyToken})
.then(() => {
localStorage.removeItem('emailConfirmToken')
- this.loading = false
this.confirmedEmailSuccess = true
+ cancel()
})
.catch(e => {
- this.loading = false
+ cancel()
this.error = e.response.data.message
})
}
diff --git a/src/components/user/PasswordReset.vue b/src/components/user/PasswordReset.vue
index c42a5ca7..735b7a57 100644
--- a/src/components/user/PasswordReset.vue
+++ b/src/components/user/PasswordReset.vue
@@ -38,6 +38,7 @@