[Modals] Refactoring

This commit is contained in:
Matej Glasnák committed 2022-12-06 19:08:06 +01:00
1 parent 707526fb2d
commit e1d9e6302f
18 files changed
+292 -465

No files matched your search

@@ -0,0 +1,237 @@
<template>
<v-dialog v-model="show" max-width="650" max-height="90%" height="700px">
<W-loadable :content="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>Vytvoriť blocker</h1>
<v-icon
@click.stop="show = false"
icon="mdi-close"
size="large"
></v-icon>
</div>
<v-card-actions class="d-flex flex-column modal-content">
<v-text-field
@focus="onInputFocus"
class="modal-input"
label="Názov blocker"
v-model="blocker.name"
variant="solo"
></v-text-field>
<div
class="employee-position w-100"
v-for="(employee, index) in blocker.employees"
:key="employee.id"
>
<v-text-field
class="modal-input"
disabled
label="Zamestanec"
variant="outlined"
v-model="blocker.employees[index]._fullName"
>
</v-text-field>
<v-icon
class="remove-input"
@click.stop="blocker.employees.splice(index, 1)"
icon="mdi-close"
size="small"
></v-icon>
</div>
<Z-autocomplete
:options="employeesOptions"
class="modal-input"
@option-selected="employeeSelected"
/>
<Datepicker
class="modal-input"
v-model="blocker.date"
format="dd.MM.yyyy, HH:mm"
locale="sk"
@focus="onDateFocus"
select-text="Vybrať"
cancel-text="Zrušiť"
placeholder="02.12.2022,10:17 - 18.12.2022,10:17"
range
/>
</v-card-actions>
<v-btn class="z-btn" @click="save()">VYTVORIŤ</v-btn>
</v-card>
</W-loadable>
</v-dialog>
</template>
<script>
import ZAutocomplete from '@/plugins/tm@_components/z-autocomplete.vue'
import Datepicker from '@vuepic/vue-datepicker'
export default {
components: {
ZAutocomplete,
Datepicker,
},
props: {
visible: {
type: Boolean,
required: true
},
blockerId: {
type: Number || null,
required: false,
default: null
}
},
data() {
return {
allEmployees: null,
blocker: {
name: '',
data: null,
employees: []
}
}
},
async created() {
if (this.blockerId)
await this._load()
try {
const allEmployees = await this.$axios.get_auth_data('v1/employees')
this.allEmployees = this._enrichEmployeesByFullName(allEmployees)
} catch (error) {
this.$toast.error(error)
}
},
methods: {
employeeSelected(selectedOption) {
const employee = this.allEmployees.find((empl) => empl.id == selectedOption.key)
this.blocker.employees.push(employee)
},
async save() {
try {
if (this.blocker.id)
await this._edit()
else
await this._create()
this.$router.push({ name: 'Dashboard - Tasks' })
this.show = false
} catch (error) {
console.log(error)
}
},
async _create() {
try {
await this.$axios.post_auth('v1/blockers', this.blocker)
} catch (error) {
this.$toast.error(error)
}
},
async _edit() {
try {
await this.$axios.post_auth(`v1/blockers/${this.blocker.id}`, this.blocker)
} catch (error) {
this.$toast.error(error)
}
},
async _load() {
try {
const blocker = await this.$axios.get_auth_data(`v1/blockers/${this.blockerId}`)
blocker.employees = this._enrichEmployeesByFullName(blocker.employees)
this.blocker = blocker
} catch (error) {
this.$toast.error(error)
}
},
// Vuetify input was automatically focus after date input was clicked. This will prevent this unwanted behavior
onDateFocus($event) {
if ($event == undefined) {
this.preventInputFocus = true
}
},
onInputFocus($event) {
if (this.preventInputFocus) {
$event.target.blur()
this.preventInputFocus = false
}
},
_enrichEmployeesByFullName(employees) {
return employees.map(employee => {
employee._fullName = `${employee.name} ${employee.surname}`
return employee
})
}
},
computed: {
employeesOptions() {
const selectedEmployeesIds = this.blocker.employees.map(
(employee) => employee.id
)
const employees = this.allEmployees.filter(
(employee) => !selectedEmployeesIds.includes(employee.id)
)
return employees.map((employee) => {
return {
key: employee.id,
value: `${employee.name} ${employee.surname}`,
}
})
},
show: {
get() {
return this.visible
},
set(value) {
if (!value) this.$emit('close')
}
},
}
}
</script>
<style lang="sass" scoped>
.modal-input
width: 100%
flex: 0 0 auto
.modal-header
flex: 0 0 auto
.modal-content
flex: 1 1 100%
margin: 10px 0
overflow-y: scroll
.z-btn
height: 50px
width: 100%
flex: 0 0 auto
.remove-input
pointer-events: auto
opacity: 2
position: absolute
left: 92%
top: 25%
.employee-position
position: relative
</style>
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,162 @@
<template>
<v-dialog v-model="show" max-width="650" max-height="90%" height="700px">
<v-card height="100%" class="d-flex flex-column">
<div class="d-flex justify-space-between align-center modal-header">
<h1>Vytvoriť master task</h1>
<v-icon
@click.stop="show = false"
icon="mdi-close"
size="large"
></v-icon>
</div>
<v-card-actions class="d-flex flex-column modal-content">
<v-text-field
@focus="onInputFocus"
class="modal-input"
label="Kód projektu"
variant="solo"
></v-text-field>
<v-text-field
@focus="onInputFocus"
class="modal-input"
label="Názov mastertasku"
variant="solo"
></v-text-field>
<Datepicker
@focus="onDateFocus"
class="modal-input"
v-model="date"
format="dd.MM.yyyy, HH:mm"
locale="sk"
select-text="Vybrať"
cancel-text="Zrušiť"
placeholder="Deadline"
/>
<v-text-field
@focus="onInputFocus"
class="modal-input mt-5"
label="Celkový odhad"
variant="solo"
type="number"
placeholder="h"
></v-text-field>
<v-select
@focus="onInputFocus"
class="modal-input border-select"
label="Tím"
variant="solo"
></v-select>
<v-textarea
label="Popis"
class="modal-input"
variant="solo"
></v-textarea>
<Z-files-upload @files-uploaded="filesUploaded"/>
</v-card-actions>
<v-btn class="z-btn" @click="createMasterTask()">VYTVORIŤ</v-btn>
</v-card>
</v-dialog>
</template>
<script>
import Datepicker from '@vuepic/vue-datepicker'
import ZFilesUpload from '@/plugins/tm@_components/z-files-upload.vue'
export default {
components: {
Datepicker,
ZFilesUpload
},
props: {
visible: {
type: Boolean,
required: true
}
},
data() {
return {
date: '',
preventInputFocus: false
}
},
methods: {
async createMasterTask() {
try {
await this.$axios.post_auth('v1/master-tasks')
this.$router.push({ name: 'Dashboard - Tasks' })
this.show = false
} catch (error) {
this.$toast.error(error.response.data.error)
}
},
// Vuetify input was automatically focus after date input was clicked. This will prevent this unwanted behavior
onDateFocus($event) {
if ($event == undefined) {
this.preventInputFocus = true
}
},
onInputFocus($event) {
if (this.preventInputFocus) {
$event.target.blur()
this.preventInputFocus = false
}
},
filesUploaded(files) {
console.log(files.length)
}
},
computed: {
show: {
get() {
return this.visible
},
set(value) {
if (!value) this.$emit('close')
}
},
}
}
</script>
<style lang="sass" scoped>
.modal-input
width: 100% !important
flex: 0 0 auto
.modal-header
flex: 0 0 auto
.modal-content
flex: 1 1 100%
margin: 10px 0
overflow-y: scroll
.z-btn
height: 50px
width: 100%
flex: 0 0 auto
.remove-input
pointer-events: auto
opacity: 2
position: absolute
left: 92%
top: 25%
.employee-position
position: relative
</style>
@@ -0,0 +1,60 @@
<template>
<v-dialog v-model="show" max-width="650">
<v-card>
<div class="d-flex justify-space-between align-center">
<h1>Ste si istý, že chcete zmazať <b>{{ task.title }}</b>?</h1>
<v-icon
@click.stop="show = false"
icon="mdi-close"
size="large"
></v-icon>
</div>
<v-card-actions class="mt-10 d-flex justify-start align-center">
<v-btn class="z-btn" variant="flat" @click="deleteTask()">ÁNO</v-btn>
<v-btn class="ml-7 cancel-btn" @click.stop="show = false">ZRUŠIŤ</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script>
export default {
emits: ['close'],
props: {
visible: {
type: Boolean,
required: true
},
task: {
type: Object,
required: true
}
},
methods: {
async deleteTask() {
try {
await this.$axios.delete(`v1/teams/${this.task.id}`)
this.show = false
} catch (error) {
this.$toast.error(error)
}
}
},
computed: {
show: {
get() {
return this.visible
},
set(value) {
if (!value) this.$emit('close')
}
},
}
}
</script>
@@ -0,0 +1,59 @@
<template>
<v-dialog v-model="show" max-width="650">
<v-card>
<div class="d-flex justify-space-between align-center">
<h1>Ste si istý, že chcete zmazať tím <b>{{ team.name }}</b>?</h1>
<v-icon
@click.stop="show = false"
icon="mdi-close"
size="large"
></v-icon>
</div>
<v-card-actions class="mt-10 d-flex justify-start align-center">
<v-btn class="z-btn" variant="flat" @click="deleteTeam()">ÁNO</v-btn>
<v-btn class="ml-7 cancel-btn" @click.stop="show = false">ZRUŠIŤ</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script>
export default {
emits: ['delete-team', 'close'],
props: {
visible: {
type: Boolean,
required: true
},
team: {
type: Object,
required: true
}
},
methods: {
async deleteTeam() {
try {
await this.$axios.delete(`v1/teams/${this.team.id}`)
this.show = false
} catch (error) {
this.$toast.error(error)
}
}
},
computed: {
show: {
get() {
return this.visible
},
set(value) {
if (!value) this.$emit('close')
}
},
}
}
</script>
@@ -0,0 +1,235 @@
<template>
<v-dialog v-model="show" max-width="650" max-height="90%" height="700px">
<W-loadable :content="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>Vytvoriť tím</h1>
<v-icon
@click.stop="show = false"
icon="mdi-close"
size="large"
></v-icon>
</div>
<v-card-actions class="d-flex flex-column modal-content">
<v-text-field
class="modal-input"
label="Názov tímu"
variant="solo"
:class="{ error: v$.team.name.$errors.length }"
:hint="
v$.team.name.$errors
? errorUtils.parseErrors(v$.team.name.$errors)
: null
"
v-model="team.name"
></v-text-field>
<div
class="employee-position w-100"
v-for="(employee, index) in team.employees"
:key="employee.id"
>
<v-text-field
class="modal-input"
disabled
label="Zamestanec"
variant="solo"
v-model="team.employees[index]._fullName"
>
</v-text-field>
<v-icon
class="remove-input"
@click.stop="team.employees.splice(index, 1)"
icon="mdi-close"
size="small"
></v-icon>
</div>
<Z-autocomplete
:options="employeesOptions"
:validations="v$.team.employees"
class="modal-input"
@option-selected="employeeSelected"
/>
</v-card-actions>
<v-btn class="z-btn" @click="save()">VYTVORIŤ</v-btn>
</v-card>
</W-loadable>
</v-dialog>
</template>
<script>
import ZAutocomplete from '@/plugins/tm@_components/z-autocomplete.vue'
import useVuelidate from '@vuelidate/core'
import { required } from '@vuelidate/validators'
import errorUtils from '@/plugins/lib@auth/_utils/error.utils'
const atLeastOne = (value) => value.length
export default {
components: {
ZAutocomplete,
},
props: {
visible: {
type: Boolean,
required: true
},
teamId: {
type: Number || null,
required: false,
default: null
}
},
data() {
return {
allEmployees: null,
v$: useVuelidate(),
errorUtils,
team: {
name: '',
employees: []
},
}
},
validations() {
return {
team: {
name: { required },
employees: { atLeastOne }
},
}
},
async created() {
if (this.teamId)
await this._load()
try {
const allEmployees = await this.$axios.get_auth_data('v1/employees')
this.allEmployees = this._enrichEmployeesByFullName(allEmployees)
} catch (error) {
this.$toast.error(error)
}
},
methods: {
async save() {
if (!(await this.v$.$validate())) return console.log(this.v$)
try {
if (this.team.id)
await this._edit()
else
await this._create()
this.$router.push({ name: 'Overview - Teams' })
this.show = false
} catch (error) {
console.log(error)
}
},
async _create() {
try {
await this.$axios.post_auth('v1/teams', this.team)
} catch (error) {
this.$toast.error(error.response.data.error)
}
},
async _edit() {
try {
await this.$axios.post_auth(`v1/teams/${this.team.id}`, this.team)
} catch (error) {
this.$toast.error(error.response.data.error)
}
},
async _load() {
try {
const team = await this.$axios.get_auth_data(`v1/teams/${this.teamId}`)
team.employees = this._enrichEmployeesByFullName(team.employees)
this.team = team
} catch (error) {
this.$toast.error(error)
}
},
employeeSelected(selectedOption) {
const employee = this.allEmployees.find((empl) => empl.id == selectedOption.key)
this.team.employees.push(employee)
},
_enrichEmployeesByFullName(employees) {
return employees.map(employee => {
employee._fullName = `${employee.name} ${employee.surname}`
return employee
})
}
},
computed: {
employeesOptions() {
const selectedEmployeesIds = this.team.employees.map(
(employee) => employee.id
)
const employees = this.allEmployees.filter(
(employee) => !selectedEmployeesIds.includes(employee.id)
)
return employees.map((employee) => {
return {
key: employee.id,
value: `${employee.name} ${employee.surname}`,
}
})
},
show: {
get() {
return this.visible
},
set(value) {
if (!value) this.$emit('close')
}
},
}
}
</script>
<style lang="sass" scoped>
.modal-input
width: 100%
flex: 0 0 auto
.modal-header
flex: 0 0 auto
.modal-content
flex: 1 1 100%
margin: 10px 0
overflow-y: scroll
.z-btn
height: 50px
width: 100%
flex: 0 0 auto
.remove-input
pointer-events: auto
opacity: 2
position: absolute
left: 92%
top: 25%
.employee-position
position: relative
</style>