Browse Source

unused

pull/1/head
Yusuf 2 years ago
parent
commit
9427e05486
  1. 246
      src/backend/data-dynamic.json
  2. 230
      src/backend/data.json
  3. 6
      src/backend/index.js
  4. 16
      src/backend/item_initializer.js
  5. 16
      src/backend/package.json
  6. 92
      src/backend/router.js
  7. 12
      src/backend/router_dynamic_loading.js
  8. 41
      src/backend/server.js
  9. 65
      src/backend/storage.js
  10. 29
      src/backend/storage_tree.js

246
src/backend/data-dynamic.json

@ -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"
}
]
}

230
src/backend/data.json

@ -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"
}
]
}

6
src/backend/index.js

@ -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);

16
src/backend/item_initializer.js

@ -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;
}
};

16
src/backend/package.json

@ -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"
}
}

92
src/backend/router.js

@ -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;

12
src/backend/router_dynamic_loading.js

@ -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;

41
src/backend/server.js

@ -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 + "...");
});
};

65
src/backend/storage.js

@ -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;

29
src/backend/storage_tree.js

@ -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;
Loading…
Cancel
Save