Move everything to models and services #17

Merged
konrad merged 82 commits from refactor/models into master 2019-03-02 10:25:10 +00:00
9 changed files with 295 additions and 295 deletions
Showing only changes of commit d813e35bd7 - Show all commits

View File

@ -7,29 +7,29 @@
</template>
<script>
import auth from '../auth'
import router from '../router'
import auth from '../auth'
import router from '../router'
export default {
name: "Home",
data() {
return {
user: auth.user,
export default {
name: "Home",
data() {
return {
user: auth.user,
loading: false,
currentDate: new Date(),
tasks: []
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (!auth.user.authenticated) {
router.push({name: 'login'})
}
},
methods: {
logout() {
auth.logout()
},
},
}
router.push({name: 'login'})
}
},
methods: {
logout() {
auth.logout()
},
},
}
</script>

View File

@ -56,49 +56,49 @@
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import auth from '../../auth'
import router from '../../router'
import message from '../../message'
import manageusers from '../sharing/user'
import manageteams from '../sharing/team'
import ListModel from '../../models/list'
import ListService from '../../services/list'
export default {
name: "EditList",
data() {
return {
list: ListModel,
export default {
name: "EditList",
data() {
return {
list: ListModel,
listService: ListService,
showDeleteModal: false,
showDeleteModal: false,
user: auth.user,
userIsAdmin: false, // FIXME: we should be able to know somehow if the user is admin, not only based on if he's the owner
manageUsersComponent: '',
manageTeamsComponent: '',
}
},
}
},
components: {
manageusers,
manageteams,
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (!auth.user.authenticated) {
router.push({name: 'home'})
}
},
created() {
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (!auth.user.authenticated) {
router.push({name: 'home'})
}
},
created() {
this.listService = new ListService()
this.loadList()
},
watch: {
// call again the method if the route changes
'$route': 'loadList'
},
methods: {
loadList() {
this.loadList()
},
watch: {
// call again the method if the route changes
'$route': 'loadList'
},
methods: {
loadList() {
let list = new ListModel({id: this.$route.params.id})
this.listService.get(list)
.then(r => {
@ -113,8 +113,8 @@
.catch(e => {
message.error(e, this)
})
},
submit() {
},
submit() {
this.listService.update(this.list)
.then(r => {
// Update the list in the parent
@ -131,17 +131,17 @@
.catch(e => {
message.error(e, this)
})
},
deleteList() {
},
deleteList() {
this.listService.delete(this.list)
.then(() => {
.then(() => {
message.success({message: 'The list was successfully deleted.'}, this)
router.push({name: 'home'})
})
.catch(e => {
router.push({name: 'home'})
})
.catch(e => {
message.error(e, this)
})
},
}
}
})
},
}
}
</script>

View File

@ -24,47 +24,47 @@
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import message from '../../message'
import auth from '../../auth'
import router from '../../router'
import message from '../../message'
import ListService from '../../services/list'
import ListModel from '../../models/list'
export default {
name: "NewList",
data() {
return {
list: ListModel,
export default {
name: "NewList",
data() {
return {
list: ListModel,
listService: ListService,
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (!auth.user.authenticated) {
router.push({name: 'home'})
}
},
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (!auth.user.authenticated) {
router.push({name: 'home'})
}
},
created() {
this.list = new ListModel()
this.listService = new ListService()
this.$parent.setFullPage();
},
methods: {
newList() {
methods: {
newList() {
this.list.namespaceID = this.$route.params.id
this.listService.create(this.list)
.then(response => {
this.$parent.loadNamespaces()
message.success({message: 'The list was successfully created.'}, this)
router.push({name: 'showList', params: {id: response.id}})
})
.catch(e => {
})
.catch(e => {
message.error(e, this)
})
},
})
},
back() {
router.go(-1)
},
}
}
}
}
</script>

View File

@ -200,64 +200,64 @@
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import message from '../../message'
import flatPickr from 'vue-flatpickr-component'
import 'flatpickr/dist/flatpickr.css'
import auth from '../../auth'
import router from '../../router'
import message from '../../message'
import flatPickr from 'vue-flatpickr-component'
import 'flatpickr/dist/flatpickr.css'
import ListService from '../../services/list'
import TaskService from '../../services/task'
import TaskModel from '../../models/task'
import ListModel from '../../models/list'
import ListService from '../../services/list'
import TaskService from '../../services/task'
import TaskModel from '../../models/task'
import ListModel from '../../models/list'
export default {
data() {
return {
listID: this.$route.params.id,
export default {
data() {
return {
listID: this.$route.params.id,
listService: ListService,
taskService: TaskService,
list: {},
newTask: TaskModel,
list: {},
newTask: TaskModel,
isTaskEdit: false,
taskEditTask: {
subtasks: [],
},
lastReminder: 0,
nowUnix: new Date(),
flatPickerConfig:{
altFormat: 'j M Y H:i',
altInput: true,
dateFormat: 'Y-m-d H:i',
flatPickerConfig:{
altFormat: 'j M Y H:i',
altInput: true,
dateFormat: 'Y-m-d H:i',
enableTime: true,
onOpen: this.updateLastReminderDate,
onClose: this.addReminderDate,
},
}
},
}
},
components: {
flatPickr
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (!auth.user.authenticated) {
router.push({name: 'home'})
}
},
created() {
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (!auth.user.authenticated) {
router.push({name: 'home'})
}
},
created() {
this.listService = new ListService()
this.taskService = new TaskService()
this.newTask = new TaskModel()
this.loadList()
},
watch: {
// call again the method if the route changes
'$route': 'loadList'
},
methods: {
loadList() {
this.isTaskEdit = false
this.loadList()
},
watch: {
// call again the method if the route changes
'$route': 'loadList'
},
methods: {
loadList() {
this.isTaskEdit = false
// We create an extra list object instead of creating it in this.list because that would trigger a ui update which would result in bad ux.
let list = new ListModel({id: this.$route.params.id})
this.listService.get(list)
@ -267,8 +267,8 @@
.catch(e => {
message.error(e, this)
})
},
addTask() {
},
addTask() {
this.newTask.listID = this.$route.params.id
this.taskService.create(this.newTask)
.then(r => {
@ -279,8 +279,8 @@
message.error(e, this)
})
this.newTask = {}
},
this.newTask = {}
},
markAsDone(e) {
let updateFunc = () => {
// We get the task, update the 'done' property and then push it to the api.
@ -303,7 +303,7 @@
}
},
editTask(id) {
// Find the selected task and set it to the current object
// Find the selected task and set it to the current object
let theTask = this.list.getTaskByID(id) // Somehow this does not work if we directly assign this to this.taskEditTask
this.taskEditTask = theTask
this.isTaskEdit = true
@ -325,11 +325,11 @@
},
updateTaskInList(task) {
// We need to do the update here in the component, because there is no way of notifiying vue of the change otherwise.
for (const t in this.list.tasks) {
if (this.list.tasks[t].id === task.id) {
this.$set(this.list.tasks, t, task)
break
}
for (const t in this.list.tasks) {
if (this.list.tasks[t].id === task.id) {
this.$set(this.list.tasks, t, task)
break
}
if (this.list.tasks[t].id === task.parentTaskID) {
for (const s in this.list.tasks[t].subtasks) {
@ -339,7 +339,7 @@
}
}
}
}
}
this.list.sortTasks()
},
updateLastReminderDate(selectedDates) {
@ -367,6 +367,6 @@
// Reset the last to 0 to have the "add reminder" button
this.taskEditTask.reminderDates[this.taskEditTask.reminderDates.length - 1] = null
}
}
}
}
}
</script>

View File

@ -20,17 +20,17 @@
</template>
<script>
export default {
name: 'modal',
mounted: function () {
document.addEventListener('keydown', (e) => {
// Close the model when escape is pressed
if (e.keyCode === 27) {
this.$emit('close')
}
})
}
}
export default {
name: 'modal',
mounted: function () {
document.addEventListener('keydown', (e) => {
// Close the model when escape is pressed
if (e.keyCode === 27) {
this.$emit('close')
}
})
}
}
</script>
<style lang="scss">

View File

@ -56,91 +56,91 @@
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import message from '../../message'
import auth from '../../auth'
import router from '../../router'
import message from '../../message'
import manageusers from '../sharing/user'
import manageteams from '../sharing/team'
import NamespaceService from '../../services/namespace'
import NamespaceModel from '../../models/namespace'
export default {
name: "EditNamespace",
data() {
return {
export default {
name: "EditNamespace",
data() {
return {
namespaceService: NamespaceService,
userIsAdmin: false,
manageUsersComponent: '',
manageTeamsComponent: '',
userIsAdmin: false,
manageUsersComponent: '',
manageTeamsComponent: '',
namespace: NamespaceModel,
showDeleteModal: false,
user: auth.user,
}
},
namespace: NamespaceModel,
showDeleteModal: false,
user: auth.user,
}
},
components: {
manageusers,
manageteams,
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (!auth.user.authenticated) {
router.push({name: 'home'})
}
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (!auth.user.authenticated) {
router.push({name: 'home'})
}
this.namespace.id = this.$route.params.id
},
created() {
this.namespace.id = this.$route.params.id
},
created() {
this.namespaceService = new NamespaceService()
this.loadNamespace()
},
watch: {
// call again the method if the route changes
'$route': 'loadNamespace'
},
this.loadNamespace()
},
watch: {
// call again the method if the route changes
'$route': 'loadNamespace'
},
methods: {
loadNamespace() {
loadNamespace() {
let namespace = new NamespaceModel({id: this.$route.params.id})
this.namespaceService.get(namespace)
.then(r => {
this.$set(this, 'namespace', r)
this.$set(this, 'namespace', r)
if (r.owner.id === this.user.infos.id) {
this.userIsAdmin = true
}
// This will trigger the dynamic loading of components once we actually have all the data to pass to them
this.manageTeamsComponent = 'manageteams'
this.manageUsersComponent = 'manageusers'
})
.catch(e => {
})
.catch(e => {
message.error(e, this)
})
},
submit() {
})
},
submit() {
this.namespaceService.update(this.namespace)
.then(r => {
// Update the namespace in the parent
for (const n in this.$parent.namespaces) {
if (this.$parent.namespaces[n].id === r.id) {
r.lists = this.$parent.namespaces[n].lists
this.$set(this.$parent.namespaces, n, r)
}
}
// Update the namespace in the parent
for (const n in this.$parent.namespaces) {
if (this.$parent.namespaces[n].id === r.id) {
r.lists = this.$parent.namespaces[n].lists
this.$set(this.$parent.namespaces, n, r)
}
}
message.success({message: 'The namespace was successfully updated.'}, this)
})
.catch(e => {
.catch(e => {
message.error(e, this)
})
},
deleteNamespace() {
})
},
deleteNamespace() {
this.namespaceService.delete(this.namespace)
.then(() => {
message.success({message: 'The namespace was successfully deleted.'}, this)
router.push({name: 'home'})
})
.catch(e => {
})
.catch(e => {
message.error(e, this)
})
})
}
}
}
}
</script>

View File

@ -33,59 +33,59 @@
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import {HTTP} from '../../http-common'
import auth from '../../auth'
import router from '../../router'
import {HTTP} from '../../http-common'
import message from '../../message'
export default {
data() {
return {
credentials: {
username: '',
password: ''
},
error: '',
confirmedEmailSuccess: false,
loading: false
}
},
beforeMount() {
// Try to verify the email
export default {
data() {
return {
credentials: {
username: '',
password: ''
},
error: '',
confirmedEmailSuccess: false,
loading: false
}
},
beforeMount() {
// Try to verify the email
// FIXME: Why is this here? Can we find a better place for this?
let emailVerifyToken = localStorage.getItem('emailConfirmToken')
if (emailVerifyToken) {
const cancel = message.setLoading(this)
HTTP.post(`user/confirm`, {token: emailVerifyToken})
.then(() => {
localStorage.removeItem('emailConfirmToken')
this.confirmedEmailSuccess = true
localStorage.removeItem('emailConfirmToken')
this.confirmedEmailSuccess = true
cancel()
})
.catch(e => {
cancel()
this.error = e.response.data.message
})
})
.catch(e => {
cancel()
this.error = e.response.data.message
})
}
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
router.push({name: 'home'})
}
},
methods: {
submit() {
this.loading = true
this.error = ''
let credentials = {
username: this.credentials.username,
password: this.credentials.password
}
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
router.push({name: 'home'})
}
},
methods: {
submit() {
this.loading = true
this.error = ''
let credentials = {
username: this.credentials.username,
password: this.credentials.password
}
auth.login(this, credentials, 'home')
}
}
}
auth.login(this, credentials, 'home')
}
}
}
</script>
<style scoped>

View File

@ -40,42 +40,42 @@
import PasswordResetModel from '../../models/passwordReset'
import PasswordResetService from '../../services/passwordReset'
export default {
data() {
return {
export default {
data() {
return {
passwordResetService: PasswordResetService,
credentials: {
password: '',
password2: '',
},
error: '',
credentials: {
password: '',
password2: '',
},
error: '',
successMessage: ''
}
},
}
},
created() {
this.passwordResetService = new PasswordResetService()
},
methods: {
submit() {
methods: {
submit() {
this.error = ''
if (this.credentials.password2 !== this.credentials.password) {
this.error = 'Passwords don\'t match'
return
}
if (this.credentials.password2 !== this.credentials.password) {
this.error = 'Passwords don\'t match'
return
}
let passwordReset = new PasswordResetModel({new_password: this.credentials.password})
this.passwordResetService.resetPassword(passwordReset)
.then(response => {
this.passwordResetService.resetPassword(passwordReset)
.then(response => {
this.successMessage = response.data.message
localStorage.removeItem('passwordResetToken')
})
.catch(e => {
this.error = e.response.data.message
})
}
}
}
localStorage.removeItem('passwordResetToken')
})
.catch(e => {
this.error = e.response.data.message
})
}
}
}
</script>
<style scoped>

View File

@ -42,50 +42,50 @@
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import auth from '../../auth'
import router from '../../router'
export default {
data() {
return {
credentials: {
username: '',
export default {
data() {
return {
credentials: {
username: '',
email: '',
password: '',
password2: '',
},
error: '',
loading: false
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
router.push({name: 'home'})
}
},
methods: {
submit() {
this.loading = true
password: '',
password2: '',
},
error: '',
loading: false
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
router.push({name: 'home'})
}
},
methods: {
submit() {
this.loading = true
this.error = ''
this.error = ''
if (this.credentials.password2 !== this.credentials.password) {
this.loading = false
this.error = 'Passwords don\'t match'
this.loading = false
this.error = 'Passwords don\'t match'
return
}
let credentials = {
username: this.credentials.username,
email: this.credentials.email,
password: this.credentials.password
}
let credentials = {
username: this.credentials.username,
email: this.credentials.email,
password: this.credentials.password
}
auth.register(this, credentials, 'home')
}
}
}
auth.register(this, credentials, 'home')
}
}
}
</script>
<style scoped>