mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 22:39:34 +00:00
refactor(z-task-modal): streamline employee timeblock assignment with dedicated method for improved clarity and maintainability
This commit is contained in:
1 parent
198f50dfc1
commit
1bca6cbfae
1 file changed
+47
-36
@@ -1054,23 +1054,20 @@ export default {
|
|||||||
|
|
||||||
// Assign timeblocks to each employee
|
// Assign timeblocks to each employee
|
||||||
validEmployees.forEach((employee) => {
|
validEmployees.forEach((employee) => {
|
||||||
employee.timeblocks = this.timeblocks
|
const employeeTimeblocks = this._getEmployeeTimeblocks(
|
||||||
.filter(
|
employee.id,
|
||||||
(tb) =>
|
true,
|
||||||
tb.employee_id == employee.id &&
|
);
|
||||||
tb.date &&
|
|
||||||
tb.starts_at_time &&
|
employee.timeblocks = employeeTimeblocks.map((tb) => ({
|
||||||
tb.ends_at_time,
|
start: `${moment(tb.date).format('YYYY-MM-DD')} ${
|
||||||
)
|
tb.starts_at_time
|
||||||
.map((tb) => ({
|
}:00`,
|
||||||
start: `${moment(tb.date).format('YYYY-MM-DD')} ${
|
end: `${moment(tb.date).format('YYYY-MM-DD')} ${
|
||||||
tb.starts_at_time
|
tb.ends_at_time
|
||||||
}:00`,
|
}:00`,
|
||||||
end: `${moment(tb.date).format('YYYY-MM-DD')} ${
|
id: tb.id || null,
|
||||||
tb.ends_at_time
|
}));
|
||||||
}:00`,
|
|
||||||
id: tb.id || null,
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
payload.employees = validEmployees;
|
payload.employees = validEmployees;
|
||||||
@@ -1100,25 +1097,22 @@ export default {
|
|||||||
// Assign timeblocks to each employee based on employee_id
|
// Assign timeblocks to each employee based on employee_id
|
||||||
// Filter out empty/incomplete timeblocks - only send fully filled timeblocks
|
// Filter out empty/incomplete timeblocks - only send fully filled timeblocks
|
||||||
validEmployees.forEach((employee) => {
|
validEmployees.forEach((employee) => {
|
||||||
employee.timeblocks = this.timeblocks
|
const employeeTimeblocks = this._getEmployeeTimeblocks(
|
||||||
.filter(
|
employee.id,
|
||||||
(timeblock) =>
|
true,
|
||||||
timeblock.date &&
|
);
|
||||||
timeblock.starts_at_time &&
|
|
||||||
timeblock.ends_at_time &&
|
employee.timeblocks = employeeTimeblocks.map((timeblock) => {
|
||||||
timeblock.employee_id == employee.id,
|
return {
|
||||||
)
|
start: `${moment(timeblock.date).format('YYYY-MM-DD')} ${
|
||||||
.map((timeblock) => {
|
timeblock.starts_at_time
|
||||||
return {
|
}:00`,
|
||||||
start: `${moment(timeblock.date).format('YYYY-MM-DD')} ${
|
end: `${moment(timeblock.date).format('YYYY-MM-DD')} ${
|
||||||
timeblock.starts_at_time
|
timeblock.ends_at_time
|
||||||
}:00`,
|
}:00`,
|
||||||
end: `${moment(timeblock.date).format('YYYY-MM-DD')} ${
|
id: null,
|
||||||
timeblock.ends_at_time
|
};
|
||||||
}:00`,
|
});
|
||||||
id: null,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const subtaskCopy = {
|
const subtaskCopy = {
|
||||||
@@ -1212,6 +1206,23 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getEmployeeTimeblocks(employeeId, requireComplete = true) {
|
||||||
|
// Get timeblocks for a specific employee with proper type handling
|
||||||
|
// Use Number() conversion to avoid type mismatch issues (string vs number)
|
||||||
|
const filtered = this.timeblocks.filter((tb) => {
|
||||||
|
const idsMatch = Number(tb.employee_id) === Number(employeeId);
|
||||||
|
|
||||||
|
if (!requireComplete) {
|
||||||
|
return idsMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For complete timeblocks, also require date and time fields
|
||||||
|
return idsMatch && tb.date && tb.starts_at_time && tb.ends_at_time;
|
||||||
|
});
|
||||||
|
|
||||||
|
return filtered;
|
||||||
|
},
|
||||||
|
|
||||||
async _validateEmployees() {
|
async _validateEmployees() {
|
||||||
if (this.subtask.id && !this.subtask.is_draft) {
|
if (this.subtask.id && !this.subtask.is_draft) {
|
||||||
// For existing subtasks, at least one employee is required
|
// For existing subtasks, at least one employee is required
|
||||||
|
|||||||
Reference in new issue
Block a user