From 005da263fa38acc9dff468791cc93057f3516c7c Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 14 Aug 2024 23:03:58 +0100 Subject: [PATCH 1/7] Removed project to its own repo --- demo-project.css | 80 ------- demo-project.html | 178 --------------- package.json | 9 +- src/project.js | 11 - src/project/gantt-chart.js | 244 --------------------- src/project/project.js | 428 ------------------------------------- src/project/task-grid.js | 120 ----------- webpack.config.js | 19 +- 8 files changed, 22 insertions(+), 1067 deletions(-) delete mode 100644 demo-project.css delete mode 100644 demo-project.html delete mode 100644 src/project.js delete mode 100644 src/project/gantt-chart.js delete mode 100644 src/project/project.js delete mode 100644 src/project/task-grid.js diff --git a/demo-project.css b/demo-project.css deleted file mode 100644 index bedef6c..0000000 --- a/demo-project.css +++ /dev/null @@ -1,80 +0,0 @@ -.ryz-project { - border-spacing: 0px; - border-collapse: separate; - cursor: default; - padding: 0px 0px 30px 0px; - width: 100%; -} - -.ryz-project .b { - font-weight: bold; -} -.ryz-project .c { - text-align: center; -} -.ryz-project .i { - display: inline-block; - width: 20px; -} - -.ryz-project thead tr { - font-weight: bold; - font-size: 0.8em; - user-select: none; - height: 40px; - text-align: center; - vertical-align: bottom; -} -.ryz-project thead tr th { - background-color: #E1E1E1; - border-color: #B8B8B8; - border-style: solid; - border-width: 0px 0px 1px 1px; - color: #3E7138; - margin: 0px; - padding: 6px 10px 5px 10px; - min-width: 20px; -} -.ryz-project thead tr th:first-child { - background-color: inherit; - border-left-width: 0px; -} -.ryz-project thead tr th:last-child { - border-right-width: 1px; -} - -.ryz-project tbody tr td { - border-color: #B8B8B8; - border-style: solid; - border-width: 0px 0px 1px 0px; - margin: 0px; - overflow: hidden; - padding: 5px 5px 5px 5px; - text-overflow: ellipsis; - white-space: nowrap; -} -.ryz-project tbody tr td:first-child { - border-right-width: 1px; - color: #7E7E7E; - font-size: 0.8em; - text-align: center; - user-select: none; -} -.ryz-project tbody tr td:last-child { - border-right-width: 1px; -} - -.ryz-project tbody tr:hover td:first-child { - background-color: #D1F2C7; - color: #3E7138; - font-weight: bold; -} - - - - -.border { - border-color: #B8B8B8; - border-style: solid; - border-width: 1px; -} \ No newline at end of file diff --git a/demo-project.html b/demo-project.html deleted file mode 100644 index c9eff55..0000000 --- a/demo-project.html +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - -
-
- -
-
- - -
- - -
-
- - - - \ No newline at end of file diff --git a/package.json b/package.json index daf304f..f761d19 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,16 @@ { "name": "LiteRyzJS", - "version": "0.1.0.154", + "version": "0.1.0.301", "devDependencies": { + "css-loader": "^7.1.2", + "sass": "^1.77.8", + "sass-loader": "^16.0.0", + "style-loader": "^4.0.0", "webpack": "^5.93.0", "webpack-cli": "^5.1.4" }, "scripts": { - "build": "webpack" + "build": "webpack", + "watch": "webpack --watch" } } \ No newline at end of file diff --git a/src/project.js b/src/project.js deleted file mode 100644 index 1725430..0000000 --- a/src/project.js +++ /dev/null @@ -1,11 +0,0 @@ -// src/project.js -import GanttChart from './project/gantt-chart.js'; -import Project from './project/project.js'; -import ProjectTaskGrid from './project/task-grid.js'; - - -export { - GanttChart, - Project, - ProjectTaskGrid -}; \ No newline at end of file diff --git a/src/project/gantt-chart.js b/src/project/gantt-chart.js deleted file mode 100644 index e43df7a..0000000 --- a/src/project/gantt-chart.js +++ /dev/null @@ -1,244 +0,0 @@ -import Canvas from '../graphics/canvas.js'; - - -class GanttChart { - constructor(el, options) { - const a = this; - - a.Canvas = new Canvas(el); - a.Options = Object.assign(a.DefaultOptions, options); - - a.Debug = false; - a.Project = null; - - a.StartDate = null; - } - - - get DefaultOptions() { - return { - DayWidth: 24, - HeaderRow: { - Height: [ 21, 21 ] - }, - Row: { - Height: 28, - Task: { - Height: 13, - PaddingTop: 6, - BorderColour: "#555555", - FillColour: "#9CC2E6" - }, - CollatedTask: { - Height: 3, - PaddingTop: 11, - BorderColour: "#555555", - FillColour: "#555555" - } - }, - Line: { - Margin: 5, - Colour: "#555555", - Width: 1, - ArrowSize: 5 - }, - DateFont: "7pt sans-serif", - DateForeColour: "#636363", - BorderWidth: 1, - BorderColour: "#B8B8B8", - BorderDashPattern: [1, 3], - }; - } - - get HeaderHeight() { - const a = this; - - return a.Options.HeaderRow.Height[0] + a.Options.HeaderRow.Height[1]; - } - - Invalidate() { - const a = this; - - a.Canvas.Clear(); - - if (a.Project == null) { - return; - } - - const tasks = a.Project.ExportTasks(); - const width = ((a.Project.Duration + 2) * a.Options.DayWidth); - const height = (tasks.length * a.Options.Row.Height) + a.HeaderHeight; - - a.AutoSize = false; - a.ClientWidth = width; - a.ClientHeight = height; - - a.Canvas.Invalidate(); - - a.drawChartLabel(a.Project); - a.drawTasks(tasks); - a.drawLines(tasks); - } - - Load(project) { - const a = this; - - a.Canvas.Clear(); - - if (project == null) { - return; - } - - a.Project = project; - a.StartDate = new Date(project.StartDate); - - a.Invalidate(); - } - - drawChartLabel(project) { - const a = this; - - const width = a.Canvas.ClientWidth; - const height = a.Canvas.ClientHeight; - const displayDays = project.Duration + 2; - - let startDate = new Date(a.StartDate); - startDate.addDays(-1); - - // Draw vertical lines - for (let i=1; i { - if (e.FinishDate == null) { - return; - } - - result = Date.max(result, e.FinishDate); - }); - - return result; - } - - get Duration() { - const a = this; - - return Date.diffDays(a.StartDate, a.FinishDate); - } - - - get newProject() { - return { - Name: "", - Description: "", - StartDate: Date.today(), - Tag: null, - StartOfWeek: 1, // Monday - WorkHours: [0, 7.5, 7.5, 7.5, 7.5, 7.5, 0] // 0 = Sunday - }; - } - - 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); - - if ((newTaskNode.PredecessorTaskID == null) && (newTaskNode.CollatedTaskID == null)) { - a.Tasks.push(newTaskNode); - } else if (newTaskNode.PredecessorTaskID != null) { - const node = a.FindTask(newTaskNode.PredecessorTaskID); - - if (node != null) { - node.Tasks.push(newTaskNode); - } else { - a.log("Task not found (" + newTaskNode.PredecessorTaskID + ")"); - } - } else if (newTaskNode.CollatedTaskID != null) { - const node = a.FindTask(newTaskNode.CollatedTaskID); - - if (node != null) { - node.Tasks.push(newTaskNode); - } else { - a.log("Task not found (" + newTaskNode.CollatedTaskID + ")"); - } - } else { - a.log("Task not found (" + newTaskNode.ID + ")"); - } - } - - ClearTasks() { - const a = this; - - a.Tasks = []; - } - - ExportTasks() { - const a = this; - - let result = a.Tasks.copy().flatten("Tasks"); - for (var i=0; i { - if (e.FinishDate > node2FinishDate) { - node2FinishDate = e.FinishDate; - } - }); - - array[index].Progress = Math.average(node2.toList("Progress")); - array[index].FinishDate = new Date(node2FinishDate); - array[index].Duration = Date.diffDays(array[index].StartDate, array[index].FinishDate); - } - -} - - -export default Project; \ No newline at end of file diff --git a/src/project/task-grid.js b/src/project/task-grid.js deleted file mode 100644 index 0283fd5..0000000 --- a/src/project/task-grid.js +++ /dev/null @@ -1,120 +0,0 @@ -class ProjectTaskGrid { - constructor(el) { - const a = this; - - a.Container = el; - - a.Columns = [ - null, - null, - "Task Name", - "Duration", - "Start", - "Finish", - "Predecessor", - "Resource Names", - null - ]; - - a.initialiseComponents(); - } - - initialiseComponents() { - const a = this; - - let htmlContent = ""; - htmlContent += ""; - htmlContent += a.renderTHead(); - htmlContent += ""; - htmlContent += a.renderPlaceholder(); - htmlContent += ""; - htmlContent += "
"; - - a.Container.innerHTML = htmlContent; - } - - - Render(model) { - const a = this; - - let htmlContent = ""; - htmlContent += ""; - htmlContent += a.renderTHead(); - htmlContent += ""; - - model.forEach(e => { - htmlContent += a.renderRow(e); - }); - - htmlContent += ""; - htmlContent += "
"; - - a.Container.innerHTML = htmlContent; - } - - - renderTHead() { - const a = this; - - let htmlContent = ""; - htmlContent += ""; - htmlContent += ""; - - a.Columns.forEach(e => { - htmlContent += "" + (e ?? "") + ""; - }); - - htmlContent += ""; - htmlContent += ""; - - return htmlContent; - } - - renderPlaceholder() { - const a = this; - - let htmlContent = ""; - htmlContent += ""; - htmlContent += ""; - htmlContent += "Loading..."; - htmlContent += ""; - - return htmlContent; - } - - renderRow(e) { - const a = this; - - let htmlContent = ""; - - if (e.IsCollated == true) { - htmlContent += ""; - } else { - htmlContent += ""; - } - - htmlContent += "" + e.Order + ""; - htmlContent += ""; - htmlContent += ""; - - for (let i=0; i"; - htmlContent += "" + new Date(e.StartDate).toLocaleDateString() + ""; - htmlContent += "" + new Date(e.FinishDate).toLocaleDateString() + ""; - htmlContent += "" + (e.PredecessorTaskNo ?? "") + ""; - htmlContent += ""; - htmlContent += ""; - htmlContent += ""; - - return htmlContent; - } - -} - - -export default ProjectTaskGrid; \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index b372ac0..9d47beb 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -30,11 +30,10 @@ class PrependVersionPlugin { module.exports = { entry: { extensions: './src/extensions.js', - graphics: './src/graphics.js', - project: './src/project.js' + graphics: './src/graphics.js' }, output: { - filename: `[name].min.js`, + filename: `[name].dist.js`, path: path.resolve(__dirname, 'dist'), library: 'LiteRyzJS', libraryTarget: 'umd', @@ -46,5 +45,17 @@ module.exports = { 'process.env.VERSION': JSON.stringify(version) }), new PrependVersionPlugin() - ] + ], + module: { + rules: [ + { + test: /\.scss$/, + use: [ + 'style-loader', + 'css-loader', + 'sass-loader' + ] + } + ] + } }; \ No newline at end of file From ba85af796eba936d96ead535022b8994344a06ef Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 14 Aug 2024 23:05:42 +0100 Subject: [PATCH 2/7] Updated array extension with docs --- src/extensions/array.js | 120 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 6 deletions(-) diff --git a/src/extensions/array.js b/src/extensions/array.js index 95222c6..f85a4e6 100644 --- a/src/extensions/array.js +++ b/src/extensions/array.js @@ -19,15 +19,19 @@ Array.toFlatten = function (sourceArray, propName, destArray) { } }; - +/** + * Add elements from an array into this array. + * @param {Array} array Array. + * @returns Array. + */ Array.prototype.addRange = function (array) { if (array == null) { return this; } - for (let i = 0; i < array.length; i++) { - this.push(array[i]); - } + array.forEach(e => { + this.push(e); + }); return this; }; @@ -70,6 +74,12 @@ Array.prototype.countMany = function (...filters) { return result; }; +/** + * Create an empty array of a given length with a given default value. + * @param {int} length Length of array. + * @param {object} value Default value. + * @returns Array. + */ Array.prototype.create = function (length, value) { let result = []; @@ -88,6 +98,12 @@ Array.prototype.flatten = function (propName) { return result; }; +/** + * Find index of first occurrence of value in property. + * @param {string} propName Property name. + * @param {object} value Property value. + * @returns Index of element. + */ Array.prototype.index = function (propName, value) { const result = this.indexes(propName, value); if (result.length <= 0) { @@ -97,6 +113,12 @@ Array.prototype.index = function (propName, value) { return result[0]; }; +/** + * Find index of occurrences of value in property in array. + * @param {string} propName Property name. + * @param {object} value Property value. + * @returns Array of indexes. + */ Array.prototype.indexes = function (propName, value) { let result = []; @@ -117,6 +139,12 @@ Array.prototype.indexes = function (propName, value) { return result; }; +/** + * Insert an element into an array at index position. + * @param {int} index Array index. + * @param {object} item Array element. + * @returns Array. + */ Array.prototype.insert = function(index, item) { if (index < 0) { this.splice(0, 0, item); @@ -129,6 +157,11 @@ Array.prototype.insert = function(index, item) { return this; }; +/** + * Concatenates an array if value is not null or whitespace using a separator. + * @param {string} separator Separator text. + * @returns string. + */ Array.prototype.joinIfNotNullOrWhitespace = function (separator) { const a = this; @@ -149,6 +182,12 @@ Array.prototype.joinIfNotNullOrWhitespace = function (separator) { return result; }; +/** + * Returns first element that matches. + * @param {string} propName Property name. + * @param {string} value Property value. + * @returns Array element. + */ Array.prototype.first = function (propName, value) { for (let i = 0; i < this.length; i++) { if (typeof(this[i][propName]) == "undefined") { @@ -163,6 +202,11 @@ Array.prototype.first = function (propName, value) { return null; }; +/** + * Traverses an array tree following a property (by name), performing the defined function. + * @param {string} propName Property name. + * @param {function} func Function to perform at each element. + */ Array.prototype.forEachTree = function (propName, func) { for (let i=0; i= this.length)) { return this; @@ -233,6 +297,11 @@ Array.prototype.removeAt = function(index) { return this; }; +/** + * Remove elements in an array. + * @param {Array} array Array of elements to be removed. + * @returns Array. + */ Array.prototype.removeRange = function (array) { for (let i=0; i Date: Mon, 26 Aug 2024 12:59:53 +0100 Subject: [PATCH 3/7] Added all and any to arrays Removed notes --- devnotes.txt | 2 -- package.json | 2 +- src/extensions/array.js | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) delete mode 100644 devnotes.txt diff --git a/devnotes.txt b/devnotes.txt deleted file mode 100644 index ff0f2a7..0000000 --- a/devnotes.txt +++ /dev/null @@ -1,2 +0,0 @@ -npm install --save-dev webpack webpack-cli -npm run build \ No newline at end of file diff --git a/package.json b/package.json index f761d19..17625e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "LiteRyzJS", - "version": "0.1.0.301", + "version": "0.1.0.357", "devDependencies": { "css-loader": "^7.1.2", "sass": "^1.77.8", diff --git a/src/extensions/array.js b/src/extensions/array.js index f85a4e6..6c383dd 100644 --- a/src/extensions/array.js +++ b/src/extensions/array.js @@ -36,8 +36,40 @@ Array.prototype.addRange = function (array) { return this; }; +Array.prototype.all = function (propName, value) { + for (let i = 0; i < this.length; i++) { + if (propName == null) { + if (this[i] != value){ + return false; + } + } else { + if (typeof(this[i][propName]) != "undefined") { + if (this[i][propName] != value){ + return false; + } + } + } + } + + return true; +}; + Array.prototype.any = function (propName, value) { - return (this.count(propName, value) > 0); + for (let i = 0; i < this.length; i++) { + if (propName == null) { + if (this[i] == value){ + return true; + } + } else { + if (typeof(this[i][propName]) != "undefined") { + if (this[i][propName] == value){ + return true; + } + } + } + } + + return false; }; Array.prototype.copy = function () { From 1d9c6bd14693123fab5fcbdd18f9f2c627226633 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 28 Aug 2024 20:16:58 +0100 Subject: [PATCH 4/7] Added doc comments for array --- src/extensions/array.js | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/extensions/array.js b/src/extensions/array.js index 6c383dd..e551376 100644 --- a/src/extensions/array.js +++ b/src/extensions/array.js @@ -1,3 +1,8 @@ +/** + * Check is array empty. + * @param {Array} value Array. + * @returns Boolean True, if array is empty or not an array type. + */ Array.isEmpty = function(value) { const dataType = Object.getDataType(value); if (dataType != "array") { @@ -7,6 +12,12 @@ Array.isEmpty = function(value) { return (value.length <= 0); }; +/** + * Create a linear/one-dimension array of objects from an object's property. + * @param {*} sourceArray Source array. + * @param {*} propName Property name. + * @param {*} destArray Destination array. + */ Array.toFlatten = function (sourceArray, propName, destArray) { for (let i=0; i= this.length) { + return ""; + } + + return this[index]; +}; + /** * Find index of first occurrence of value in property. * @param {string} propName Property name. From c4434e1b2b939ab87d48c8af4cf5169feb33ed79 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 18 Sep 2024 23:38:17 +0100 Subject: [PATCH 5/7] Added document methods --- package.json | 2 +- src/extensions/document.js | 49 +++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 17625e3..5ff135d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "LiteRyzJS", - "version": "0.1.0.357", + "version": "0.1.0.397", "devDependencies": { "css-loader": "^7.1.2", "sass": "^1.77.8", diff --git a/src/extensions/document.js b/src/extensions/document.js index adea58c..88349b9 100644 --- a/src/extensions/document.js +++ b/src/extensions/document.js @@ -6,4 +6,51 @@ Document.ready = async function(fn) { fn(); }); })(); -} \ No newline at end of file +} + +Document.getWidth = function(el) { + if (el == null) { + return 0; + } + + if (typeof(el) == "undefined") { + return 0; + } + + return (el.offsetWidth || el.innerWidth || el.clientWidth); +} + +Document.getHeight = function(el) { + if (el == null) { + return 0; + } + + if (typeof(el) == "undefined") { + return 0; + } + + return (el.offsetHeight || el.innerHeight || el.clientHeight); +} + +Document.appendHtml = function(el, html) { + const newEl = document.createElement(html); + + el.appendChild(newEl); +} + +Document.addClass = function(el, className) { + if (el.classList.contains(className)) { + return; + } + + el.classList.add(className); +} + +Document.removeClass = function(el, className) { + if (!el.classList.contains(className)) { + return; + } + + el.classList.remove(className); +} + From 993a2eef96c055ee7237d97898c2ce7d606b2636 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 13 Oct 2024 19:30:22 +0100 Subject: [PATCH 6/7] Added distinct array --- package.json | 2 +- src/extensions/array.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 5ff135d..0dcb509 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "LiteRyzJS", - "version": "0.1.0.397", + "version": "0.1.0.424", "devDependencies": { "css-loader": "^7.1.2", "sass": "^1.77.8", diff --git a/src/extensions/array.js b/src/extensions/array.js index e551376..1aad74c 100644 --- a/src/extensions/array.js +++ b/src/extensions/array.js @@ -160,6 +160,14 @@ Array.prototype.create = function (length, value) { return result }; +Array.prototype.distinct = function () { + this = this.filter((obj, index, self) => + index === self.findIndex((x) => JSON.stringify(x) === JSON.stringify(obj)) + ); + + return this; +} + /** * Convert this array of objects to a linear/one-dimensional array using a property. * @param {*} propName Property name. From 8cfb52d2a68e28b8a7352540fa21245e0a76eb7b Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 31 Dec 2024 23:08:59 +0000 Subject: [PATCH 7/7] Add additional check for array.isEmpty --- package.json | 2 +- src/extensions/array.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 0dcb509..4e821d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "LiteRyzJS", - "version": "0.1.0.424", + "version": "0.1.0.455", "devDependencies": { "css-loader": "^7.1.2", "sass": "^1.77.8", diff --git a/src/extensions/array.js b/src/extensions/array.js index 1aad74c..38eaab4 100644 --- a/src/extensions/array.js +++ b/src/extensions/array.js @@ -4,6 +4,10 @@ * @returns Boolean True, if array is empty or not an array type. */ Array.isEmpty = function(value) { + if (typeof(value) == "undefined") { + return true; + } + const dataType = Object.getDataType(value); if (dataType != "array") { return true; @@ -160,12 +164,12 @@ Array.prototype.create = function (length, value) { return result }; -Array.prototype.distinct = function () { - this = this.filter((obj, index, self) => +Array.prototype.distinct = function() { + let result = this.filter((obj, index, self) => index === self.findIndex((x) => JSON.stringify(x) === JSON.stringify(obj)) ); - return this; + return result; } /**