mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
fix(z-task-modal): fixed employee handling and validation logic, as well as saving subtask to local storage
This commit is contained in:
1 parent
fd4c8bb285
commit
f0bb76d131
1 file changed
+40
-11
@@ -121,6 +121,7 @@
|
|||||||
class="dp__icon dp__clear_icon dp__input_icons"
|
class="dp__icon dp__clear_icon dp__input_icons"
|
||||||
data-test="clear-icon"
|
data-test="clear-icon"
|
||||||
@click.prevent="
|
@click.prevent="
|
||||||
|
handleOnRemoveEmployee();
|
||||||
subtask.employee_id = null;
|
subtask.employee_id = null;
|
||||||
subtask.employee = null;
|
subtask.employee = null;
|
||||||
"
|
"
|
||||||
@@ -202,7 +203,10 @@
|
|||||||
viewBox="0 0 32 32"
|
viewBox="0 0 32 32"
|
||||||
class="dp__icon dp__clear_icon dp__input_icons"
|
class="dp__icon dp__clear_icon dp__input_icons"
|
||||||
data-test="clear-icon"
|
data-test="clear-icon"
|
||||||
@click.prevent="employee.id = null"
|
@click.prevent="
|
||||||
|
handleOnRemoveEmployee();
|
||||||
|
employee.id = null;
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<path
|
<path
|
||||||
d="M23.057 7.057l-16 16c-0.52 0.52-0.52 1.365 0 1.885s1.365 0.52 1.885 0l16-16c0.52-0.52 0.52-1.365 0-1.885s-1.365-0.52-1.885 0z"
|
d="M23.057 7.057l-16 16c-0.52 0.52-0.52 1.365 0 1.885s1.365 0.52 1.885 0l16-16c0.52-0.52 0.52-1.365 0-1.885s-1.365-0.52-1.885 0z"
|
||||||
@@ -454,6 +458,7 @@ export default {
|
|||||||
ends_at_time: null,
|
ends_at_time: null,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
wasFormValidationTriggered: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -622,7 +627,7 @@ export default {
|
|||||||
this.$router.replace({ name: this.$route.name });
|
this.$router.replace({ name: this.$route.name });
|
||||||
},
|
},
|
||||||
|
|
||||||
async save() {
|
async validateAllFields() {
|
||||||
const employeesValid = await this._validateEmployees();
|
const employeesValid = await this._validateEmployees();
|
||||||
const timeblocksValid = this.subtask?.id
|
const timeblocksValid = this.subtask?.id
|
||||||
? true
|
? true
|
||||||
@@ -630,6 +635,19 @@ export default {
|
|||||||
|
|
||||||
if (!(await this.v$.$validate())) return;
|
if (!(await this.v$.$validate())) return;
|
||||||
if (!employeesValid || !timeblocksValid) return;
|
if (!employeesValid || !timeblocksValid) return;
|
||||||
|
},
|
||||||
|
|
||||||
|
async handleOnRemoveEmployee() {
|
||||||
|
if (this.wasFormValidationTriggered) {
|
||||||
|
setTimeout(async () => {
|
||||||
|
this.validateAllFields();
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async save() {
|
||||||
|
this.wasFormValidationTriggered = true;
|
||||||
|
if (!(await this.validateAllFields())) return;
|
||||||
|
|
||||||
this.subtask.description = this.$refs['description'].getHTML();
|
this.subtask.description = this.$refs['description'].getHTML();
|
||||||
this._mergeDeadlineTimeDate();
|
this._mergeDeadlineTimeDate();
|
||||||
@@ -749,17 +767,19 @@ export default {
|
|||||||
if (!this.subtask.duration)
|
if (!this.subtask.duration)
|
||||||
this.employeeValidations[0].duration = true;
|
this.employeeValidations[0].duration = true;
|
||||||
} else {
|
} else {
|
||||||
|
// For new subtasks, only validate non-empty employee entries
|
||||||
this.subtask.employees.forEach((employee, index) => {
|
this.subtask.employees.forEach((employee, index) => {
|
||||||
if (index == this.subtask.employees.length - 1 && index > 0) return; // Skip the last which is allways empty
|
// Skip validation if both id and duration are empty
|
||||||
|
if (!employee.id && !employee.duration) return;
|
||||||
|
|
||||||
if (employee.id && employee.duration) return;
|
// Only validate if either id or duration is filled
|
||||||
|
if (employee.id || employee.duration) {
|
||||||
|
this.employeeValidations[index] = {};
|
||||||
|
|
||||||
this.employeeValidations[index] = {};
|
if (!employee.id) this.employeeValidations[index].employee = true;
|
||||||
|
if (!employee.duration)
|
||||||
if (!employee.id) this.employeeValidations[index].employee = true;
|
this.employeeValidations[index].duration = true;
|
||||||
|
}
|
||||||
if (!employee.duration)
|
|
||||||
this.employeeValidations[index].duration = true;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -835,7 +855,16 @@ export default {
|
|||||||
subtask: {
|
subtask: {
|
||||||
handler(val) {
|
handler(val) {
|
||||||
if (this.editMode && !this.subtask?.id) {
|
if (this.editMode && !this.subtask?.id) {
|
||||||
localStorage.setItem('subtaskData', JSON.stringify(val));
|
const employees = val.employees.filter(
|
||||||
|
(employee) => employee?.id || employee?.duration,
|
||||||
|
) || [{}];
|
||||||
|
|
||||||
|
const subtaskData = {
|
||||||
|
...val,
|
||||||
|
employees: employees && employees.length > 0 ? employees : [{}],
|
||||||
|
};
|
||||||
|
console.log('subtaskData', subtaskData);
|
||||||
|
localStorage.setItem('subtaskData', JSON.stringify(subtaskData));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deep: true,
|
deep: true,
|
||||||
|
|||||||
Reference in new issue
Block a user