From 9427e054865818be1e2a95f316613df1b07a8f70 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Jul 2022 02:58:54 +0700 Subject: [PATCH] unused --- src/backend/data-dynamic.json | 246 -------------------------- src/backend/data.json | 230 ------------------------ src/backend/index.js | 6 - src/backend/item_initializer.js | 16 -- src/backend/package.json | 16 -- src/backend/router.js | 92 ---------- src/backend/router_dynamic_loading.js | 12 -- src/backend/server.js | 41 ----- src/backend/storage.js | 65 ------- src/backend/storage_tree.js | 29 --- 10 files changed, 753 deletions(-) delete mode 100644 src/backend/data-dynamic.json delete mode 100644 src/backend/data.json delete mode 100644 src/backend/index.js delete mode 100644 src/backend/item_initializer.js delete mode 100644 src/backend/package.json delete mode 100644 src/backend/router.js delete mode 100644 src/backend/router_dynamic_loading.js delete mode 100644 src/backend/server.js delete mode 100644 src/backend/storage.js delete mode 100644 src/backend/storage_tree.js diff --git a/src/backend/data-dynamic.json b/src/backend/data-dynamic.json deleted file mode 100644 index 0de35f9..0000000 --- a/src/backend/data-dynamic.json +++ /dev/null @@ -1,246 +0,0 @@ -{ - "data": [ - { - "id": 1, - "start_date": "2018-04-01 00:00:00", - "duration": 5, - "text": "Project #1", - "progress": 0.8, - "parent": 0, - "open": 0 - }, - { - "id": 2, - "start_date": "2018-04-06 00:00:00", - "duration": 4, - "text": "Task #1", - "progress": 0.5, - "parent": 1, - "open": 0 - }, - { - "id": 5, - "start_date": "2018-04-05 00:00:00", - "duration": 5, - "text": "Task #1.1", - "progress": 0.34, - "parent": 2, - "open": 0 - }, - { - "id": 6, - "start_date": "2018-04-11 00:00:00", - "duration": 4, - "text": "Task #1.2", - "progress": 0.491477, - "parent": 2, - "open": 0 - }, - { - "id": 3, - "start_date": "2018-04-03 00:00:00", - "duration": 6, - "text": "Task #2", - "progress": 0.7, - "parent": 1, - "open": 0 - }, - { - "id": 7, - "start_date": "2018-04-07 00:00:00", - "duration": 5, - "text": "Task #2.1", - "progress": 0.2, - "parent": 3, - "open": 0 - }, - { - "id": 8, - "start_date": "2018-04-06 00:00:00", - "duration": 4, - "text": "Task #2.2", - "progress": 0.9, - "parent": 3, - "open": 0 - }, - { - "id": 4, - "start_date": "2018-04-07 00:00:00", - "duration": 2, - "text": "Task #3", - "progress": 0, - "parent": 1, - "open": 0 - }, - { - "id": 9, - "start_date": "2018-04-06 00:00:00", - "duration": 5, - "text": "Task #3.1", - "progress": 1, - "parent": 4, - "open": 0 - }, - { - "id": 10, - "start_date": "2018-04-06 00:00:00", - "duration": 3, - "text": "Task #3.2", - "progress": 0, - "parent": 4, - "open": 0 - }, - { - "id": 11, - "start_date": "2018-04-06 00:00:00", - "duration": 4, - "text": "Task #3.3", - "progress": 0.33, - "parent": 4, - "open": 0 - }, - { - "id": 12, - "start_date": "2018-04-02 00:00:00", - "duration": 8, - "text": "Project #2", - "progress": 0, - "parent": 0, - "open": 0 - }, - { - "id": 13, - "start_date": "2018-04-02 00:00:00", - "duration": 10, - "text": "Task #1", - "progress": 0.2, - "parent": 12, - "open": 0 - }, - { - "id": 14, - "start_date": "2018-04-04 00:00:00", - "duration": 4, - "text": "Task #2", - "progress": 0.9, - "parent": 12, - "open": 0 - }, - { - "id": 18, - "start_date": "2018-04-05 00:00:00", - "duration": 5, - "text": "Task #2.1", - "progress": 0.3, - "parent": 14, - "open": 0 - }, - { - "id": 19, - "start_date": "2018-04-05 00:00:00", - "duration": 6, - "text": "Task #2.2", - "progress": 0.453052, - "parent": 14, - "open": 0 - }, - { - "id": 20, - "start_date": "2018-04-05 00:00:00", - "duration": 4, - "text": "Task #2.3", - "progress": 0.512605, - "parent": 14, - "open": 0 - }, - { - "id": 21, - "start_date": "2018-04-05 00:00:00", - "duration": 6, - "text": "Task #2.4", - "progress": 0.7, - "parent": 14, - "open": 0 - }, - { - "id": 15, - "start_date": "2018-04-05 00:00:00", - "duration": 3, - "text": "Task #3", - "progress": 0.6, - "parent": 12, - "open": 0 - }, - { - "id": 16, - "start_date": "2018-04-01 00:00:00", - "duration": 3, - "text": "Task #4", - "progress": 0.214286, - "parent": 12, - "open": 0 - }, - { - "id": 22, - "start_date": "2018-04-05 00:00:00", - "duration": 7, - "text": "Task #4.1", - "progress": 1, - "parent": 16, - "open": 0 - }, - { - "id": 23, - "start_date": "2018-04-05 00:00:00", - "duration": 5, - "text": "Task #4.2", - "progress": 1, - "parent": 16, - "open": 0 - }, - { - "id": 24, - "start_date": "2018-04-05 00:00:00", - "duration": 5, - "text": "Task #4.3", - "progress": 0, - "parent": 16, - "open": 0 - }, - { - "id": 17, - "start_date": "2018-04-06 00:00:00", - "duration": 6, - "text": "Task #5", - "progress": 0.5, - "parent": 12, - "open": 0 - } - ], - "links": [ - { - "id": 1, - "source": 1, - "target": 2, - "type": "0" - }, - { - "id": 2, - "source": 1, - "target": 3, - "type": "0" - }, - { - "id": 3, - "source": 1, - "target": 4, - "type": "0" - }, - { - "id": 4, - "source": 2, - "target": 6, - "type": "0" - } - ] -} \ No newline at end of file diff --git a/src/backend/data.json b/src/backend/data.json deleted file mode 100644 index 25101c1..0000000 --- a/src/backend/data.json +++ /dev/null @@ -1,230 +0,0 @@ -{ - "data": [ - { - "id": 1, - "text": "Project #1", - "start_date": "2018-04-01 00:00", - "duration": 11, - "progress": 0.6, - "open": true, - "users": [ - "John", - "Mike", - "Anna" - ], - "priority": "2", - "end_date": "2018-04-12 00:00", - "parent": 0, - "usage": [ - { - "id": "1", - "value": "222" - } - ] - }, - { - "id": 2, - "text": "Task #1", - "start_date": "2018-04-03 00:00", - "duration": 5, - "parent": "1", - "progress": 1, - "open": true, - "users": [ - "John", - "Mike" - ], - "priority": "1", - "end_date": "2018-04-08 00:00" - }, - { - "id": 3, - "text": "Task #2", - "start_date": "2018-04-02 00:00", - "duration": 7, - "parent": "1", - "progress": 0.5, - "open": true, - "users": [ - "Anna" - ], - "priority": "1", - "end_date": "2018-04-09 00:00" - }, - { - "id": 7, - "text": "Task #2.1", - "start_date": "2018-04-03 00:00", - "duration": 2, - "parent": "3", - "progress": 1, - "open": true, - "users": [ - "Mike", - "Anna" - ], - "priority": "2", - "end_date": "2018-04-05 00:00", - "usage": [ - { - "id": "3", - "value": "1" - } - ] - }, - { - "id": 8, - "text": "Task #2.2", - "start_date": "2018-04-06 00:00", - "duration": 3, - "parent": "3", - "progress": 0.8, - "open": true, - "users": [ - "Anna" - ], - "priority": "3", - "end_date": "2018-04-09 00:00" - }, - { - "id": 9, - "text": "Task #2.3", - "start_date": "2018-04-10 00:00", - "duration": 4, - "parent": "3", - "progress": 0.2, - "open": true, - "users": [ - "Mike", - "Anna" - ], - "priority": "1", - "end_date": "2018-04-14 00:00", - "usage": [ - { - "id": "2", - "value": "50" - }, - { - "id": "1", - "value": "2" - } - ] - }, - { - "id": 10, - "text": "Task #2.4", - "start_date": "2018-04-10 00:00", - "duration": 4, - "parent": "3", - "progress": 0, - "open": true, - "users": [ - "John", - "Mike" - ], - "priority": "1", - "end_date": "2018-04-14 00:00" - }, - { - "id": 4, - "text": "Task #3", - "start_date": "2018-04-02 00:00", - "duration": 6, - "parent": "1", - "progress": 0.8, - "open": true, - "users": [ - "Mike", - "Anna" - ], - "priority": "2", - "end_date": "2018-04-08 00:00" - }, - { - "id": 5, - "text": "Task #4", - "start_date": "2018-04-02 00:00", - "duration": 5, - "parent": "1", - "progress": 0.2, - "open": true, - "users": [ - "John" - ], - "priority": "3", - "end_date": "2018-04-07 00:00" - }, - { - "id": 11, - "text": "Task #4.1", - "start_date": "2018-04-03 00:00", - "duration": 4, - "parent": "5", - "progress": 0.5, - "open": true, - "users": [ - "John", - "Anna" - ], - "priority": "3", - "end_date": "2018-04-07 00:00" - }, - { - "id": 12, - "text": "Task #4.2", - "start_date": "2018-04-03 00:00", - "duration": 4, - "parent": "5", - "progress": 0.1, - "open": true, - "users": [ - "John" - ], - "priority": "3", - "end_date": "2018-04-07 00:00" - }, - { - "id": 13, - "text": "Task #4.3", - "start_date": "2018-04-03 00:00", - "duration": 5, - "parent": "5", - "progress": 0, - "open": true, - "users": [ - "Anna" - ], - "priority": "3", - "end_date": "2018-04-08 00:00" - }, - { - "id": 6, - "text": "Task #5", - "start_date": "2018-04-02 00:00", - "duration": 7, - "parent": "1", - "progress": 0, - "open": true, - "users": [ - "John" - ], - "priority": "2", - "end_date": "2018-04-09 00:00" - } - ], - "links": [ - { - "id": "10", - "source": "11", - "target": "12", - "type": "1" - }, - { - "id": "11", - "source": "11", - "target": "13", - "type": "1" - } - ] -} \ No newline at end of file diff --git a/src/backend/index.js b/src/backend/index.js deleted file mode 100644 index 1ddc9de..0000000 --- a/src/backend/index.js +++ /dev/null @@ -1,6 +0,0 @@ -const backend = require("./server"); - -const host = process.env.HOST || "127.0.0.1"; -const port = process.env.PORT || "9200"; - -backend(host, port); \ No newline at end of file diff --git a/src/backend/item_initializer.js b/src/backend/item_initializer.js deleted file mode 100644 index 4dd7d78..0000000 --- a/src/backend/item_initializer.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = { - data: function(task) { - task.open = task.open * 1; - task.progress = task.progress * 1; - task.duration = task.duration * 1; - task.id = task.id * 1; - task.parent = task.parent * 1; - return task; - }, - links: function(link){ - link.id = link.id * 1; - link.source = link.source * 1; - link.source = link.source * 1; - return link; - } -}; \ No newline at end of file diff --git a/src/backend/package.json b/src/backend/package.json deleted file mode 100644 index e140ce9..0000000 --- a/src/backend/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "dhtmlx-gantt-samples", - "version": "1.0.0", - "description": "Simple backend and REST api for dhtmlx gantt samples", - "main": "./index.js", - "scripts": { - "start": "node ./index.js" - }, - "author": "DHTMLX", - "license": "DHTMLX Evaluation License", - "dependencies": { - "body-parser": "^1.18.3", - "express": "^4.16.4", - "striptags": "^3.1.1" - } -} diff --git a/src/backend/router.js b/src/backend/router.js deleted file mode 100644 index 60c7faf..0000000 --- a/src/backend/router.js +++ /dev/null @@ -1,92 +0,0 @@ -const actions = { - inserted: "inserted", - updated: "updated", - deleted: "deleted", - error: "error" -}; - -class Router { - constructor(root, storage) { - this.root = root; - this.storage = storage; - } - - _tryProcess(code, req, res) { - try { - code.call(this, req, res); - } catch (e) { - res.send({action: actions.error, message: e.message}); - } - } - - getData(req, res) { - res.send(this.storage.all()); - } - - insertTask(req, res) { - this._tryProcess(function (req, res) { - var insertedTask = this.storage.insert("data", req.body); - res.send({action: actions.inserted, tid: insertedTask.id}); - }, req, res); - - } - - updateTask(req, res) { - this._tryProcess(function (req, res) { - var sid = req.params.id; - - this.storage.update(sid, "data", req.body); - res.send({action: actions.updated}); - }, req, res) - } - - deleteTask(req, res) { - this._tryProcess(function (req, res) { - var sid = req.params.id; - this.storage.delete(sid, "data"); - res.send({action: actions.deleted}); - }, req, res); - } - - insertLink(req, res) { - this._tryProcess(function (req, res) { - var insertedLink = this.storage.insert("links", req.body); - res.send({action: actions.inserted, tid: insertedLink.id}); - }, req, res); - } - - updateLink(req, res) { - this._tryProcess(function (req, res) { - var sid = req.params.id; - this.storage.update(sid, "links", req.body); - res.send({action: actions.updated}); - }, req, res); - - } - - deleteLink(req, res) { - this._tryProcess(function (req, res) { - var sid = req.params.id; - this.storage.delete(sid, "links"); - res.send({action: actions.deleted}); - }, req, res); - - } - - connect(app) { - this._connect(app, ""); - this._connect(app, "/gantt/backend"); - this._connect(app, "/backend"); - } - - _connect(app, prefix){ - app.get(`${prefix}${this.root}`, this.getData.bind(this)); - app.post(`${prefix}${this.root}/task`, this.insertTask.bind(this)); - app.put(`${prefix}${this.root}/task/:id`, this.updateTask.bind(this)); - app.delete(`${prefix}${this.root}/task/:id`, this.deleteTask.bind(this)); - app.post(`${prefix}${this.root}/link`, this.insertLink.bind(this)); - app.put(`${prefix}${this.root}/link/:id`, this.updateLink.bind(this)); - app.delete(`${prefix}${this.root}/link/:id`, this.deleteLink.bind(this)); - } -} -module.exports = Router; diff --git a/src/backend/router_dynamic_loading.js b/src/backend/router_dynamic_loading.js deleted file mode 100644 index 9076020..0000000 --- a/src/backend/router_dynamic_loading.js +++ /dev/null @@ -1,12 +0,0 @@ -var Router = require("./router"); - -class RouterDynamicLoading extends Router { - getData(req, res) { - this._tryProcess(function (req, res) { - var parentId = req.query.parent_id || 0; - res.send(this.storage.children(parentId)); - }, req, res); - } -} - -module.exports = RouterDynamicLoading; \ No newline at end of file diff --git a/src/backend/server.js b/src/backend/server.js deleted file mode 100644 index c7c7bbd..0000000 --- a/src/backend/server.js +++ /dev/null @@ -1,41 +0,0 @@ -var express = require("express"); -var bodyParser = require("body-parser"); -var path = require("path"); -var Storage = require("./storage"); -var StorageTree = require("./storage_tree"); -var Router = require("./router"); -var RouterDynamicLoading = require("./router_dynamic_loading"); -var itemInitializer = require("./item_initializer"); - -module.exports = function (host = "127.0.0.1", port = "9200") { - - var app = express(); - - var storage = new Storage(require("./data.json"), itemInitializer); - var dynamicStorage = new StorageTree(require("./data-dynamic.json"), itemInitializer); - var router = new Router("/data", storage); - var dynLoading = new RouterDynamicLoading("/data-dynamic", dynamicStorage); - - app.use(bodyParser.json()); // for parsing application/json - app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded - app.use(function (req, res, next) { - res.header("Access-Control-Allow-Origin", "*"); - res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); - res.header("Access-Control-Allow-Methods", "*"); - next(); - }); - - router.connect(app); - dynLoading.connect(app); - - app.use("/codebase", express.static(path.join(__dirname, "..", "codebase"))); - app.use("/samples", express.static(path.join(__dirname, "..", "samples"))); - app.use(/^\/$/, function (req, res) {//default url - res.redirect("/samples"); - }); - - var server = app.listen(port, host, function () { - console.log("Server is running on port " + port + "..."); - }); - -}; \ No newline at end of file diff --git a/src/backend/storage.js b/src/backend/storage.js deleted file mode 100644 index 5281902..0000000 --- a/src/backend/storage.js +++ /dev/null @@ -1,65 +0,0 @@ -const striptags = require("striptags"); - -class Storage { - constructor(data, initItem) { - this._data = data; - this._initItem = initItem; - } - all() { - return this._data; - } - get(id, table) { - return this._data[table].find(function(entry) { - return id === entry.id; - }); - } - delete(id, table) { - this._data[table] = this._data[table].filter(function(entry) { - return id !== entry.id; - }); - } - update(id, table, newData) { - return this._data[table].find(function(entry, index, arr) { - if (id == entry.id) { - var preparedItem = newData; - console.log(table) - if(this._initItem && this._initItem[table]){ - preparedItem = this._initItem[table](preparedItem); - } - arr[index] = _addId(id, sanitizeObject(preparedItem)); - return true; - } - }.bind(this)); - } - insert(table, data) { - data.id = uid(); - var preparedItem = data; - if(this._initItem && this._initItem[table]){ - preparedItem = this._initItem[table](data); - } - this._data[table].push(sanitizeObject(preparedItem)); - return data; - } -} - -var seed = Date.now(); -function uid(){ - return seed++; -} - -function sanitizeObject(data){ - for(var i in data){ - if(typeof data[i] === "string"){ - data[i] = striptags(data[i]); - }else if(typeof data[i] === "object"){ - sanitizeObject(data[i]); - } - } - return data; -} - -function _addId(id, data) { - return Object.assign(data, {id: id}); -} - -module.exports = Storage; \ No newline at end of file diff --git a/src/backend/storage_tree.js b/src/backend/storage_tree.js deleted file mode 100644 index dd898b3..0000000 --- a/src/backend/storage_tree.js +++ /dev/null @@ -1,29 +0,0 @@ -var Storage = require("./storage"); -class StorageTree extends Storage{ - children(parentId = 0) { - var all = this._data.data; - - var loaded = this._data.data.filter(function(entry) { - return parentId == entry.parent; - }); - - var search = {}; - loaded.forEach(function(value){ - search[value.id] = value; - }); - - all.forEach(function(task){ - if(search[task.parent]) { - search[task.parent]["$has_child"] = true; - } - }); - - var links = this._data.links.filter(function(entry) { - return (search[entry.source] || search[entry.target]); - }); - - return {data: loaded, links: links}; - } -} - -module.exports = StorageTree; \ No newline at end of file