mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
[Task modal] Refactored task modal
This commit is contained in:
1 parent
3d7ceea9c6
commit
278bdeabc7
3 files changed
+49
-46
No files matched your search
@@ -1,11 +1,11 @@
|
||||
<template>
|
||||
<v-dialog v-model="show" max-width="650" max-height="90%" height="700px">
|
||||
<W-loadable :content="allEmployees" class="h-100">
|
||||
<v-dialog v-model="visible" max-width="650" max-height="90%" height="700px">
|
||||
<W-loadable :content="team && allEmployees" class="h-100">
|
||||
<v-card height="100%" class="d-flex flex-column">
|
||||
<div class="d-flex justify-space-between align-center modal-header">
|
||||
<h1>{{ team.id ? 'Upraviť tím' : 'Vytvoriť tím' }}</h1>
|
||||
<v-icon
|
||||
@click.stop="show = false"
|
||||
@click.stop="close()"
|
||||
icon="mdi-close"
|
||||
size="large"
|
||||
></v-icon>
|
||||
@@ -69,32 +69,19 @@ import errorUtils from '@/plugins/lib@auth/_utils/error.utils'
|
||||
const atLeastOne = (value) => value.length
|
||||
|
||||
export default {
|
||||
emits: ['close'],
|
||||
|
||||
components: {
|
||||
ZAutocomplete,
|
||||
},
|
||||
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
},
|
||||
|
||||
teamId: {
|
||||
type: Number || null,
|
||||
required: false,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
allEmployees: null,
|
||||
v$: useVuelidate(),
|
||||
errorUtils,
|
||||
team: {
|
||||
name: '',
|
||||
employees: []
|
||||
},
|
||||
team: null
|
||||
}
|
||||
},
|
||||
|
||||
@@ -108,9 +95,6 @@ export default {
|
||||
},
|
||||
|
||||
async created() {
|
||||
if (this.teamId)
|
||||
await this._load()
|
||||
|
||||
try {
|
||||
const allEmployees = await this.$axios.get_auth_data('v1/employees')
|
||||
this.allEmployees = this._enrichEmployeesByFullName(allEmployees)
|
||||
@@ -120,8 +104,23 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
async create(team = null) {
|
||||
if (team) {
|
||||
this.team = team
|
||||
await this._load()
|
||||
} else {
|
||||
this.team = {
|
||||
name: '',
|
||||
employees: []
|
||||
}
|
||||
}
|
||||
|
||||
this.visible = true
|
||||
},
|
||||
|
||||
async save() {
|
||||
if (!(await this.v$.$validate())) return console.log(this.v$)
|
||||
if (!(await this.v$.$validate()))
|
||||
return
|
||||
|
||||
try {
|
||||
if (this.team.id)
|
||||
@@ -129,18 +128,23 @@ export default {
|
||||
else
|
||||
await this._create()
|
||||
|
||||
this.$router.push({ name: 'Overview - Teams' })
|
||||
this.show = false
|
||||
this.close()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
},
|
||||
|
||||
close() {
|
||||
this.visible = false
|
||||
this.$emit('close', this.team)
|
||||
this.team = null
|
||||
},
|
||||
|
||||
async _create() {
|
||||
try {
|
||||
await this.$axios.post_auth('v1/teams', this.team)
|
||||
} catch (error) {
|
||||
this.$toast.error(error.response.data.error)
|
||||
this.$toast.error(error)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -148,14 +152,14 @@ export default {
|
||||
try {
|
||||
await this.$axios.post_auth(`v1/teams/${this.team.id}`, this.team)
|
||||
} catch (error) {
|
||||
this.$toast.error(error.response.data.error)
|
||||
this.$toast.error(error)
|
||||
}
|
||||
},
|
||||
|
||||
async _load() {
|
||||
try {
|
||||
const team = await this.$axios.get_auth_data(`v1/teams/${this.teamId}`)
|
||||
team.employees = this._enrichEmployeesByFullName(team.employees)
|
||||
const team = await this.$axios.get_auth_data(`v1/teams/${this.team.id}`)
|
||||
team.employees = this._enrichEmployeesByFullName(team.employees)
|
||||
|
||||
this.team = team
|
||||
} catch (error) {
|
||||
@@ -191,17 +195,7 @@ export default {
|
||||
value: `${employee.name} ${employee.surname}`,
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
show: {
|
||||
get() {
|
||||
return this.visible
|
||||
},
|
||||
|
||||
set(value) {
|
||||
if (!value) this.$emit('close')
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user