From 3f4af0defb1d53c3963fbc6118c159f3e61f2eb4 Mon Sep 17 00:00:00 2001 From: Will Date: Wed, 30 Jun 2021 23:58:40 -0700 Subject: [PATCH] render data-table (#262) --- controller/app/index.js | 62 ++++++++++++++++++++++++++++---- controller/app/package-lock.json | 17 +++++++++ controller/app/package.json | 1 + controller/static/index.html | 4 +-- 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/controller/app/index.js b/controller/app/index.js index 433ff46b..38369851 100644 --- a/controller/app/index.js +++ b/controller/app/index.js @@ -1,4 +1,5 @@ import "./jquery-global"; +import "bootstrap-table"; import "bootstrap-cron-picker/dist/cron-picker"; let auth = ""; @@ -38,8 +39,56 @@ $().ready(() => { $("#addtask button").on('click', doSubmit); $("schedulesection form").on('submit', doSubmit); + + syncTable(); }) +function syncTable() { + let username = undefined; + let password = undefined; + if (auth != "") { + let ap = auth.split(":"); + username = ap[0]; + password = ap[1]; + } + $.ajax({ + type: "GET", + url: "./tasks", + username: username, + password: password, + success: gotTable, + }); +} + +function operate(val, row) { + return 'Cancel'; +} + +function gotTable(data) { + for (let i = 0; i < data.length; i++) { + data[i].task = data[i].StorageTask || data[i].RetrievalTask; + data[i].sched = { + Schedule: data[i].task.Schedule, + Limit: data[i].task.ScheduleLimit, + } + delete data[i].task.Schedule; + delete data[i].task.ScheduleLimit; + } + let stringify = (d) => JSON.stringify(d, null, 2); + console.log(data); + $("#taskTable").bootstrapTable({ + idField: 'UUID', + columns: [ + {title:'ID', field:'UUID'}, + {title:'Status', field:'Status'}, + {title:'Task', field:'task', formatter: stringify}, + {title:'Schedule', field:'sched', formatter: stringify}, + {title:'Delete', field: 'operate', align: 'center', formatter: operate} + ], + data: data, + }); +} + function doSubmit(e) { if (e.preventDefault) { e.preventDefault() @@ -56,8 +105,8 @@ function doSubmit(e) { } } - username = undefined; - password = undefined; + let username = undefined; + let password = undefined; if (auth != "") { let ap = auth.split(":"); username = ap[0]; @@ -66,10 +115,10 @@ function doSubmit(e) { for (let i = 0; i < miners.length; i++) { let miner = miners[i]; - let url = "/tasks/storage"; + let url = "./tasks/storage"; let data = {}; if ($('#newSR').is(':checked')) { - url = "/tasks/retrieval"; + url = "./tasks/retrieval"; data = { "Miner": miner, "PayloadCID": $('#newCid').val(), @@ -79,7 +128,7 @@ function doSubmit(e) { } else { data = { "Miner": miner, - "Size": $('#newSize').val(), + "Size": Number($('#newSize').val()), "StartOffset": 6152, // 3 days? "FastRetrieval": $('#newFast').is(':checked'), "Verified": $('#newVerified').is(':checked'), @@ -97,8 +146,9 @@ function doSubmit(e) { $.ajax({ type: "POST", + contentType: "application/json", url: url, - data: data, + data: JSON.stringify(data), username: username, password: password, success: done, diff --git a/controller/app/package-lock.json b/controller/app/package-lock.json index 4d50a4be..9d371083 100644 --- a/controller/app/package-lock.json +++ b/controller/app/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "devDependencies": { "bootstrap-cron-picker": "^1.0.0", + "bootstrap-table": "^1.18.3", "jquery": "^3.6.0" } }, @@ -32,6 +33,15 @@ "jquery": "^3.2.1" } }, + "node_modules/bootstrap-table": { + "version": "1.18.3", + "resolved": "https://registry.npmjs.org/bootstrap-table/-/bootstrap-table-1.18.3.tgz", + "integrity": "sha512-/eFLkldDlNFi37qC/d9THfRVxMUGD34E8fQBFtXJLDHLBOVKWDTq7BV+udoP7k3FfCEyhM1jWQnQ0rMQdBv//w==", + "dev": true, + "peerDependencies": { + "jquery": "1.9.1 - 3" + } + }, "node_modules/jquery": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz", @@ -56,6 +66,13 @@ "jquery": "^3.2.1" } }, + "bootstrap-table": { + "version": "1.18.3", + "resolved": "https://registry.npmjs.org/bootstrap-table/-/bootstrap-table-1.18.3.tgz", + "integrity": "sha512-/eFLkldDlNFi37qC/d9THfRVxMUGD34E8fQBFtXJLDHLBOVKWDTq7BV+udoP7k3FfCEyhM1jWQnQ0rMQdBv//w==", + "dev": true, + "requires": {} + }, "jquery": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz", diff --git a/controller/app/package.json b/controller/app/package.json index b87ff3e7..e5c20f8e 100644 --- a/controller/app/package.json +++ b/controller/app/package.json @@ -18,6 +18,7 @@ "homepage": "https://github.com/filecoin-project/dealbot#readme", "devDependencies": { "bootstrap-cron-picker": "^1.0.0", + "bootstrap-table": "^1.18.3", "jquery": "^3.6.0" } } diff --git a/controller/static/index.html b/controller/static/index.html index c3e0e574..cb5ec55d 100644 --- a/controller/static/index.html +++ b/controller/static/index.html @@ -18,7 +18,7 @@

List of tasks and ability to cancel them. - +
@@ -93,7 +93,7 @@

- +

ID