[Master task modal] Fixed team verification

This commit is contained in:
Matej Glasnák committed 2023-06-13 12:07:24 +02:00
1 parent b2470a80c2
commit 3f37acd04f
3 files changed
+28 -25

No files matched your search

@@ -45,27 +45,11 @@ export default {
if (typeof employee.duration == 'string') { if (typeof employee.duration == 'string') {
totalDuration += parseFloat(employee.duration) totalDuration += parseFloat(employee.duration)
employee.duration = parseFloat(employee.duration) employee.duration = parseFloat(employee.duration)
employee.invalid = false
} }
else if (typeof employee.duration == 'number') { else if (typeof employee.duration == 'number') {
totalDuration += employee.duration totalDuration += employee.duration
} employee.invalid = false
return employee
})
if (!this.mastertask.team)
return this.mastertask.duration = totalDuration
this.mastertask.team.employees = this.mastertask.team.employees.map(employee => {
if (isNaN(employee.duration) || isNaN(parseFloat(employee.duration)))
return employee
if (typeof employee.duration == 'string') {
totalDuration += parseFloat(employee.duration)
employee.duration = parseFloat(employee.duration)
}
else if (typeof employee.duration == 'number') {
totalDuration += employee.duration
} }
return employee return employee
@@ -23,10 +23,10 @@
<v-text-field v-model="mastertask.duration" @focus="onInputFocus" class="modal-input" variant="solo" type="number" :label="`${mastertask.duration} h`" :disabled="true"></v-text-field> <v-text-field v-model="mastertask.duration" @focus="onInputFocus" class="modal-input" variant="solo" type="number" :label="`${mastertask.duration} h`" :disabled="true"></v-text-field>
<v-select v-model="mastertask.team_id" @focus="onInputFocus" class="modal-input border-select" label="Tím" variant="solo" :items="teams" item-value="id" item-title="name"></v-select> <v-select v-model="mastertask.team_id" @focus="onInputFocus" class="modal-input border-select" :class="{error: v$.mastertask.employees.$errors.length}" label="Tím" variant="solo" :items="teams" item-value="id" item-title="name"></v-select>
<template v-if="mastertask.employees"> <template v-if="mastertask.employees">
<v-text-field v-for="(employee, index) in mastertask.employees" :key="employee.id" @focus="onInputFocus" class="modal-input" :label="`${employee.name} ${employee.surname}`" variant="solo" placeholder="h" v-model="mastertask.employees[index].duration" type="number" min="1" @input="onEmployeeDurationChanged"> <v-text-field v-for="(employee, index) in mastertask.employees" :key="employee.id" @focus="onInputFocus" class="modal-input" :class="{error: employee.invalid}" :label="`${employee.name} ${employee.surname}`" variant="solo" placeholder="h" v-model="mastertask.employees[index].duration" type="number" min="1" @input="onEmployeeDurationChanged">
<p class="employee-select-avatar d-flex justify-center align-center"> <p class="employee-select-avatar d-flex justify-center align-center">
{{ employee?.name.charAt(0) + employee?.surname.charAt(0) }} {{ employee?.name.charAt(0) + employee?.surname.charAt(0) }}
</p> </p>
@@ -88,7 +88,7 @@
import Datepicker from '@vuepic/vue-datepicker' import Datepicker from '@vuepic/vue-datepicker'
import ZFilesUpload from '@/plugins/tm@_components/z-files-upload.vue' import ZFilesUpload from '@/plugins/tm@_components/z-files-upload.vue'
import useVuelidate from '@vuelidate/core' import useVuelidate from '@vuelidate/core'
import { required } from '@vuelidate/validators' import { required, minLength } from '@vuelidate/validators'
import errorUtils from '@/plugins/lib@auth/_utils/error.utils' import errorUtils from '@/plugins/lib@auth/_utils/error.utils'
// import ZAutocomplete from '@/plugins/tm@_components/z-autocomplete.vue' // import ZAutocomplete from '@/plugins/tm@_components/z-autocomplete.vue'
import VuetifyFixFocusMixin from '@/plugins/tm@modal/_mixins/vuetify-fix-focus' import VuetifyFixFocusMixin from '@/plugins/tm@modal/_mixins/vuetify-fix-focus'
@@ -163,6 +163,7 @@ export default {
validations() { validations() {
return { return {
mastertask: { mastertask: {
employees: { required, minLength: minLength(1), $each: {duration: { required}} },
project_id: { required }, project_id: { required },
name: { required }, name: { required },
description: { required }, description: { required },
@@ -209,7 +210,7 @@ export default {
methods: { methods: {
removeEmployee({ id }) { removeEmployee({ id }) {
const isEmployeeInTeam = this.mastertask.team.employees.find(employee => employee.id == id) const isEmployeeInTeam = this.mastertask.team?.employees.find(employee => employee.id == id)
if (isEmployeeInTeam) { if (isEmployeeInTeam) {
this.mastertask.team_id = null this.mastertask.team_id = null
@@ -258,8 +259,9 @@ export default {
}, },
async save() { async save() {
console.log(this.mastertask) const vuelidateValid = await this.v$.$validate()
if (!(await this.v$.$validate())) return const employeesValid = await this._validateEmployees()
if (!vuelidateValid || !employeesValid) return
if (this.$refs['description']) if (this.$refs['description'])
this.mastertask.description = this.$refs['description'].getHTML() this.mastertask.description = this.$refs['description'].getHTML()
@@ -302,6 +304,21 @@ export default {
date.setMinutes(parseInt(timeParts[1])); date.setMinutes(parseInt(timeParts[1]));
this.mastertask.deadline = date this.mastertask.deadline = date
},
_validateEmployees() {
let isValid = true
this.mastertask.employees = this.mastertask.employees.map(employee => {
if (!employee.duration) {
employee.invalid = true
isValid = false
}
return employee
})
return isValid
} }
}, },
@@ -26,7 +26,7 @@
<div class="d-flex align-center flex-start width-100"> <div class="d-flex align-center flex-start width-100">
<p class="task-badge rounded-pill">{{ timesheet.time }}</p> <p class="task-badge rounded-pill">{{ timesheet.time }}</p>
<p class="ml-5">{{ timesheet.timestamp }}</p> <p class="ml-5">{{ timesheet.employee_name }} ({{ moment(timesheet.timestamp).format('M.D.YYYY') }})</p>
</div> </div>
</div> </div>
</template> </template>
@@ -50,6 +50,7 @@
</template> </template>
<script> <script>
import moment from 'moment'
import errorUtils from '@/plugins/lib@auth/_utils/error.utils' import errorUtils from '@/plugins/lib@auth/_utils/error.utils'
import useVuelidate from '@vuelidate/core' import useVuelidate from '@vuelidate/core'
import { required, numeric, minValue } from '@vuelidate/validators' import { required, numeric, minValue } from '@vuelidate/validators'
@@ -69,6 +70,7 @@ export default {
data() { data() {
return { return {
moment,
v$: useVuelidate(), v$: useVuelidate(),
errorUtils, errorUtils,
showModal: false, showModal: false,