mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 06:20:21 +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
|
||||
validEmployees.forEach((employee) => {
|
||||
employee.timeblocks = this.timeblocks
|
||||
.filter(
|
||||
(tb) =>
|
||||
tb.employee_id == employee.id &&
|
||||
tb.date &&
|
||||
tb.starts_at_time &&
|
||||
tb.ends_at_time,
|
||||
)
|
||||
.map((tb) => ({
|
||||
start: `${moment(tb.date).format('YYYY-MM-DD')} ${
|
||||
tb.starts_at_time
|
||||
}:00`,
|
||||
end: `${moment(tb.date).format('YYYY-MM-DD')} ${
|
||||
tb.ends_at_time
|
||||
}:00`,
|
||||
id: tb.id || null,
|
||||
}));
|
||||
const employeeTimeblocks = this._getEmployeeTimeblocks(
|
||||
employee.id,
|
||||
true,
|
||||
);
|
||||
|
||||
employee.timeblocks = employeeTimeblocks.map((tb) => ({
|
||||
start: `${moment(tb.date).format('YYYY-MM-DD')} ${
|
||||
tb.starts_at_time
|
||||
}:00`,
|
||||
end: `${moment(tb.date).format('YYYY-MM-DD')} ${
|
||||
tb.ends_at_time
|
||||
}:00`,
|
||||
id: tb.id || null,
|
||||
}));
|
||||
});
|
||||
|
||||
payload.employees = validEmployees;
|
||||
@@ -1100,25 +1097,22 @@ export default {
|
||||
// Assign timeblocks to each employee based on employee_id
|
||||
// Filter out empty/incomplete timeblocks - only send fully filled timeblocks
|
||||
validEmployees.forEach((employee) => {
|
||||
employee.timeblocks = this.timeblocks
|
||||
.filter(
|
||||
(timeblock) =>
|
||||
timeblock.date &&
|
||||
timeblock.starts_at_time &&
|
||||
timeblock.ends_at_time &&
|
||||
timeblock.employee_id == employee.id,
|
||||
)
|
||||
.map((timeblock) => {
|
||||
return {
|
||||
start: `${moment(timeblock.date).format('YYYY-MM-DD')} ${
|
||||
timeblock.starts_at_time
|
||||
}:00`,
|
||||
end: `${moment(timeblock.date).format('YYYY-MM-DD')} ${
|
||||
timeblock.ends_at_time
|
||||
}:00`,
|
||||
id: null,
|
||||
};
|
||||
});
|
||||
const employeeTimeblocks = this._getEmployeeTimeblocks(
|
||||
employee.id,
|
||||
true,
|
||||
);
|
||||
|
||||
employee.timeblocks = employeeTimeblocks.map((timeblock) => {
|
||||
return {
|
||||
start: `${moment(timeblock.date).format('YYYY-MM-DD')} ${
|
||||
timeblock.starts_at_time
|
||||
}:00`,
|
||||
end: `${moment(timeblock.date).format('YYYY-MM-DD')} ${
|
||||
timeblock.ends_at_time
|
||||
}:00`,
|
||||
id: null,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
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() {
|
||||
if (this.subtask.id && !this.subtask.is_draft) {
|
||||
// For existing subtasks, at least one employee is required
|
||||
|
||||
Reference in new issue
Block a user