Change to use classes instead of default objects

This commit is contained in:
Ray 2024-08-17 14:51:04 +01:00
parent fc8d736127
commit 2b8baa0c3c
6 changed files with 85 additions and 82 deletions

View File

@ -138,15 +138,16 @@ textarea {
window.project1.Clear();
var tasks = [
{"Order":1,"ID":1,"Name":"Task A","Description":"","Tag":null,"StartDate":"2024-08-11T23:00:00.000Z","FinishDate":"2024-08-14T23:00:00.000Z","StartDelay":0,"Duration":3,"PredecessorTaskID":null,"IsCollated":false,"CollatedTaskID":null,"CalcWorkHours":22.5,"ActuWorkHours":null,"Progress":0,"Resources":[],"Level":0,"PredecessorTaskNo":null},
{"Order":2,"ID":2,"Name":"Task B","Description":"","Tag":null,"StartDate":"2024-08-14T23:00:00.000Z","FinishDate":"2024-08-28T23:00:00.000Z","StartDelay":0,"Duration":14,"PredecessorTaskID":1,"IsCollated":false,"CollatedTaskID":null,"CalcWorkHours":105,"ActuWorkHours":null,"Progress":0,"Resources":[],"Level":0,"PredecessorTaskNo":1},
{"Order":3,"ID":5,"Name":"Task B1","Description":"","Tag":null,"StartDate":"2024-08-29T23:00:00.000Z","FinishDate":"2024-09-26T23:00:00.000Z","StartDelay":1,"Duration":28,"PredecessorTaskID":2,"IsCollated":true,"CollatedTaskID":null,"CalcWorkHours":210,"ActuWorkHours":null,"Progress":25,"Resources":[],"Level":0,"PredecessorTaskNo":2},
{"Order":4,"ID":6,"Name":"Task B11","Description":"","Tag":null,"StartDate":"2024-09-02T23:00:00.000Z","FinishDate":"2024-09-26T23:00:00.000Z","StartDelay":4,"Duration":24,"PredecessorTaskID":null,"IsCollated":false,"CollatedTaskID":5,"CalcWorkHours":180,"ActuWorkHours":null,"Progress":0,"Resources":[],"Level":1,"PredecessorTaskNo":null},
{"Order":5,"ID":7,"Name":"Task B12","Description":"","Tag":null,"StartDate":"2024-08-30T23:00:00.000Z","FinishDate":"2024-09-25T23:00:00.000Z","StartDelay":1,"Duration":26,"PredecessorTaskID":null,"IsCollated":false,"CollatedTaskID":5,"CalcWorkHours":0,"ActuWorkHours":null,"Progress":50,"Resources":[],"Level":1,"PredecessorTaskNo":null},
{"Order":6,"ID":8,"Name":"Task E","Description":"","Tag":null,"StartDate":"2024-08-11T23:00:00.000Z","FinishDate":"2024-08-26T23:00:00.000Z","StartDelay":0,"Duration":15,"PredecessorTaskID":null,"IsCollated":true,"CollatedTaskID":null,"CalcWorkHours":112.5,"ActuWorkHours":null,"Progress":0,"Resources":[],"Level":0,"PredecessorTaskNo":null},
{"Order":7,"ID":3,"Name":"Task C","Description":"","Tag":null,"StartDate":"2024-08-26T23:00:00.000Z","FinishDate":"2024-09-13T23:00:00.000Z","StartDelay":0,"Duration":18,"PredecessorTaskID":8,"IsCollated":false,"CollatedTaskID":null,"CalcWorkHours":135,"ActuWorkHours":null,"Progress":0,"Resources":[],"Level":0,"PredecessorTaskNo":6},
{"Order":8,"ID":4,"Name":"Task D","Description":"","Tag":null,"StartDate":"2024-09-14T23:00:00.000Z","FinishDate":"2024-09-24T23:00:00.000Z","StartDelay":1,"Duration":10,"PredecessorTaskID":3,"IsCollated":false,"CollatedTaskID":null,"CalcWorkHours":0,"ActuWorkHours":null,"Progress":0,"Resources":[],"Level":0,"PredecessorTaskNo":7},
{"Order":9,"ID":9,"Name":"Task E1","Description":"","Tag":null,"StartDate":"2024-08-14T23:00:00.000Z","FinishDate":"2024-08-26T23:00:00.000Z","StartDelay":3,"Duration":12,"PredecessorTaskID":null,"IsCollated":false,"CollatedTaskID":8,"CalcWorkHours":90,"ActuWorkHours":null,"Progress":0,"Resources":[],"Level":1,"PredecessorTaskNo":null}
{"ID":1,"Name":"Task A","Description":"","Tag":null,"StartDate":"2024-08-11T23:00:00.000Z","StartDelay":0,"Duration":3,"PredecessorTaskID":null,"IsCollated":false,"CollatedTaskID":null,"ActuWorkHours":null,"Progress":0,"Resources":[]},
{"ID":2,"Name":"Task B","Description":"","Tag":null,"StartDate":"2024-08-14T23:00:00.000Z","StartDelay":0,"Duration":14,"PredecessorTaskID":1,"IsCollated":false,"CollatedTaskID":null,"ActuWorkHours":null,"Progress":0,"Resources":[]},
{"ID":5,"Name":"Task B1","Description":"","Tag":null,"StartDate":"2024-08-29T23:00:00.000Z","StartDelay":1,"Duration":28,"PredecessorTaskID":2,"IsCollated":true,"CollatedTaskID":null,"ActuWorkHours":null,"Progress":25,"Resources":[]},
{"ID":6,"Name":"Task B11","Description":"","Tag":null,"StartDate":"2024-09-02T23:00:00.000Z","StartDelay":4,"Duration":24,"PredecessorTaskID":null,"IsCollated":false,"CollatedTaskID":5,"ActuWorkHours":null,"Progress":0,"Resources":[]},
{"ID":7,"Name":"Task B12","Description":"","Tag":null,"StartDate":"2024-08-30T23:00:00.000Z","StartDelay":1,"Duration":26,"PredecessorTaskID":null,"IsCollated":false,"CollatedTaskID":5,"ActuWorkHours":null,"Progress":50,"Resources":[]},
{"ID":8,"Name":"Task E","Description":"","Tag":null,"StartDate":"2024-08-11T23:00:00.000Z","StartDelay":0,"Duration":15,"PredecessorTaskID":null,"IsCollated":true,"CollatedTaskID":null,"ActuWorkHours":null,"Progress":0,"Resources":[]},
{"ID":3,"Name":"Task C","Description":"","Tag":null,"StartDate":"2024-08-26T23:00:00.000Z","StartDelay":0,"Duration":18,"PredecessorTaskID":8,"IsCollated":false,"CollatedTaskID":null,"ActuWorkHours":null,"Progress":0,"Resources":[]},
{"ID":4,"Name":"Task D","Description":"","Tag":null,"StartDate":"2024-09-14T23:00:00.000Z","StartDelay":1,"Duration":10,"PredecessorTaskID":3,"IsCollated":false,"CollatedTaskID":null,"ActuWorkHours":null,"Progress":0,"Resources":[]},
{"ID":9,"Name":"Task E1","Description":"","Tag":null,"StartDate":"2024-08-14T23:00:00.000Z","StartDelay":3,"Duration":12,"PredecessorTaskID":null,"IsCollated":false,"CollatedTaskID":8,"ActuWorkHours":null,"Progress":0,"Resources":[]},
{"ID":10,"Name":"Task C2","Description":"","Tag":null,"StartDate":"2024-08-26T23:00:00.000Z","StartDelay":0,"Duration":18,"PredecessorTaskID":8,"IsCollated":false,"CollatedTaskID":null,"ActuWorkHours":null,"Progress":0,"Resources":[]},
];
tasks.forEach((e, i) => {

View File

@ -298,7 +298,7 @@ class GanttChart {
style = a.Options.Row.CollatedTask;
} else if (a.Tasks[i].CollatedTaskID != null) {
style = a.Options.Row.ChildTask;
} else if (a.Tasks[i].PredecessorTaskNo == null) {
} else if (a.Tasks[i].PredecessorTaskID == null) {
style = a.Options.Row.OrphanTask;
}
@ -320,7 +320,7 @@ class GanttChart {
continue;
}
if (a.Tasks[i].PredecessorTaskNo == null) {
if (a.Tasks[i].PredecessorTaskID == null) {
continue;
}
@ -329,7 +329,7 @@ class GanttChart {
const paddingX = (a.Options.Row.CollatedTask.Height + a.Options.BorderWidth);
const offsetX = (rectangle.X + paddingX);
const predecessorTask = a.Tasks.first("Order", a.Tasks[i].PredecessorTaskNo);
const predecessorTask = a.Tasks.first("ID", a.Tasks[i].PredecessorTaskID);
if (predecessorTask == null) {
continue;
}

View File

@ -0,0 +1,24 @@
import ProjectTaskModel from './project-task-model.js';
import '../references/extensions.dist.js';
class ProjectNodeModel extends ProjectTaskModel{
Order = null;
StartDate = null;
FinishDate = null;
CalcWorkHours = 0;
Level = 0;
Tasks = [];
constructor(options) {
super();
Object.assign(this, options);
}
}
export default ProjectNodeModel;

View File

@ -8,7 +8,6 @@ class ProjectPlanner {
const a = this;
a.Container = el;
a.Columns = [
null,
null,
@ -20,6 +19,7 @@ class ProjectPlanner {
"Resource Names",
null
];
a.Tasks = [];
a.#initialiseComponents();
}
@ -52,6 +52,8 @@ class ProjectPlanner {
Load(tasks) {
const a = this;
a.Tasks = tasks;
if (!a.Container.classList.contains("literyzjs-project")) {
a.Container.classList.add("literyzjs-project");
}
@ -125,7 +127,7 @@ class ProjectPlanner {
htmlContent += "<td>" + task.Duration + " day" + (parseInt(task.Duration) == 1 ? "" : "s") + "</td>";
htmlContent += "<td class='c'>" + new Date(task.StartDate).toLocaleDateString() + "</td>";
htmlContent += "<td class='c'>" + new Date(task.FinishDate).toLocaleDateString() + "</td>";
htmlContent += "<td class='c'>" + (task.PredecessorTaskNo ?? "") + "</td>";
htmlContent += "<td class='c'>" + a.#findTaskNo(task.PredecessorTaskID) + "</td>";
htmlContent += "<td></td>";
htmlContent += "<td></td>";
htmlContent += "</tr>";
@ -133,6 +135,18 @@ class ProjectPlanner {
return htmlContent;
}
#findTaskNo(id) {
const a = this;
if (id == null) {
return "";
}
const item = a.Tasks.first("ID", id);
return (item == null) ? "" : item.Order;
}
}

View File

@ -0,0 +1,26 @@
import '../references/extensions.dist.js';
class ProjectTaskModel {
ID = null;
Name = "";
Description = "";
Tag = null;
StartDelay = 0; // Days
Duration = 1; // Days
PredecessorTaskID = null;
IsCollated = false;
CollatedTaskID = null;
ActuWorkHours = null;
Progress = 0;
Resources = [];
constructor(options) {
Object.assign(this, options);
}
}
export default ProjectTaskModel;

View File

@ -1,3 +1,6 @@
import ProjectTaskModel from './project-task-model.js';
import ProjectNodeModel from './project-node-model.js';
import '../references/extensions.dist.js';
@ -12,27 +15,6 @@ class Project {
}
get NewTask() {
return {
// Order: null,
ID: null,
Name: "",
Description: "",
Tag: null,
// StartDate: null, // new Date(),
// FinishDate: null, // new Date(),
StartDelay: 0, // Days
Duration: 1, // Days
PredecessorTaskID: null,
IsCollated: false,
CollatedTaskID: null,
// CalcWorkHours: 0,
ActuWorkHours: null,
Progress: 0,
Resources: []
};
}
get StartDate() {
const a = this;
@ -72,35 +54,11 @@ class Project {
};
}
get #newTaskNode() {
return {
Order: null,
ID: null,
Name: "",
Description: "",
Tag: null,
StartDate: null, // new Date(),
FinishDate: null, // new Date(),
StartDelay: 0, // Days
Duration: 1, // Days
PredecessorTaskID: null,
IsCollated: false,
CollatedTaskID: null,
CalcWorkHours: 0,
ActuWorkHours: null,
Progress: 0,
Resources: [],
Level: 0,
PredecessorTaskNo: null,
Tasks: []
};
}
AddTask(task) {
const a = this;
const newTask = Object.assign(a.NewTask, task);
const newTaskNode = Object.assign(a.#newTaskNode, newTask);
const newTask = new ProjectTaskModel(task);
const newTaskNode = new ProjectNodeModel(newTask);
if ((newTaskNode.PredecessorTaskID == null) && (newTaskNode.CollatedTaskID == null)) {
a.Tasks.push(newTaskNode);
@ -330,9 +288,6 @@ class Project {
// Calculate work-hours
a.#recalculateWorkHours(result);
// Calculate predecessor
a.#recalculatePredecessorTaskNo(result);
return isSuccess;
}
@ -378,23 +333,6 @@ class Project {
}
}
#recalculatePredecessorTaskNo(array) {
const a = this;
for (var i=0; i<array.length; i++) {
if (array[i].PredecessorTaskID == null) {
continue;
}
const predecessor = a.FindTask(array[i].PredecessorTaskID);
if (predecessor == null) {
continue;
}
array[i].PredecessorTaskNo = predecessor.Order;
}
}
#recalculateCollatedTask(array, index) {
let node2 = array.select("CollatedTaskID", array[index].ID);
if (node2.length <= 0) {