Implement download tasks

This commit is contained in:
Zaid Abdulla committed 2018-12-26 00:22:07 -08:00
1 parent cfb62adfe8
commit 99e7c8a14c
4 files changed
+128 -22

No files matched your search

+16
View File
@@ -43,6 +43,22 @@ const component = {
) )
); );
buttons.push(
m(
"button.critical",
{
title: "Push a firmware or a config file",
onclick: () => {
taskQueue.stageDownload({
name: "download",
device: device["DeviceID.ID"].value[0]
});
}
},
"Push file"
)
);
buttons.push( buttons.push(
m( m(
"button.primary", "button.primary",
+105 -22
View File
@@ -5,6 +5,7 @@ import m from "mithril";
import * as taskQueue from "./task-queue"; import * as taskQueue from "./task-queue";
import * as store from "./store"; import * as store from "./store";
import * as notifications from "./notifications"; import * as notifications from "./notifications";
import Filter from "../common/filter";
function mparam(param) { function mparam(param) {
return m("span.parameter", { title: param }, `${param}`); return m("span.parameter", { title: param }, `${param}`);
@@ -14,22 +15,12 @@ function mval(val) {
return m("span.value", { title: val }, `${val}`); return m("span.value", { title: val }, `${val}`);
} }
function renderStaging(staging) { function renderStagingSpv(task, queueFunc, cancelFunc) {
let elements = [];
for (let s of staging) {
const queueFunc = () => {
staging.delete(s);
taskQueue.queueTask(s);
};
const cancelFunc = () => {
staging.delete(s);
};
const input = m("input", { const input = m("input", {
value: s.parameterValues[0][1], value: task.parameterValues[0][1],
oninput: e => { oninput: e => {
e.redraw = false; e.redraw = false;
s.parameterValues[0][1] = input.dom.value; task.parameterValues[0][1] = input.dom.value;
}, },
onkeydown: e => { onkeydown: e => {
if (e.keyCode === 13) queueFunc(); if (e.keyCode === 13) queueFunc();
@@ -45,9 +36,100 @@ function renderStaging(staging) {
} }
}); });
return [m("span", "Editing ", mparam(task.parameterValues[0][0])), input];
}
function renderStagingDownload(task) {
task.invalid = !task.fileName || !task.fileType;
const files = store.fetch("files", new Filter());
const idParts = task.device.split("-");
const oui = decodeURIComponent(idParts[0]);
const productClass =
idParts.length === 3 ? decodeURIComponent(idParts[1]) : "";
const typesList = [
"",
"1 Firmware Upgrade Image",
"2 Web Content",
"3 Vendor Configuration File",
"4 Tone File",
"5 Ringer File"
].map(t =>
m(
"option",
{
disabled: !t,
value: t,
selected: (task.fileType || "") === t,
onclick: () => {
task.fileType = t;
}
},
t
)
);
const filesList = [""]
.concat(
files.value
.filter(
f =>
(!f.metadata.oui || f.metadata.oui === oui) &&
(!f.metadata.productClass ||
f.metadata.productClass === productClass)
)
.map(f => f._id)
)
.map(f =>
m(
"option",
{
disabled: !f,
value: f,
selected: (task.fileName || "") === f,
onclick: () => {
task.fileName = f;
task.fileType = "";
for (let file of files.value)
if (file._id === f) task.fileType = file.metadata.fileType;
}
},
f
)
);
return [
"Push ",
m(
"select",
{ disabled: files.fulfilling, style: "width: 350px" },
filesList
),
" as ",
m("select", typesList)
];
}
function renderStaging(staging) {
let elements = [];
for (let s of staging) {
const queueFunc = () => {
staging.delete(s);
taskQueue.queueTask(s);
};
const cancelFunc = () => {
staging.delete(s);
};
let elms;
if (s.name === "setParameterValues")
elms = renderStagingSpv(s, queueFunc, cancelFunc);
else if (s.name === "download")
elms = renderStagingDownload(s, queueFunc, cancelFunc);
const queue = m( const queue = m(
"button.primary", "button.primary",
{ title: "Queue task", onclick: queueFunc }, { title: "Queue task", onclick: queueFunc, disabled: s.invalid },
"Queue" "Queue"
); );
const cancel = m( const cancel = m(
@@ -56,14 +138,7 @@ function renderStaging(staging) {
"Cancel" "Cancel"
); );
elements.push( elements.push(m(".staging", elms, m("div.actions", queue, cancel)));
m(
".staging",
m("span", "Editing ", mparam(s.parameterValues[0][0])),
input,
m("div.actions", queue, cancel)
)
);
} }
return elements; return elements;
} }
@@ -161,6 +236,14 @@ function renderQueue(queue) {
m(".actions", actions) m(".actions", actions)
) )
); );
else if (t.name === "download")
details.push(
m(
`div.${t.status}`,
`Push file: ${t.fileName} (${t.fileType})`,
m(".actions", actions)
)
);
else details.push(m(`div.${t.status}`, t.name, m(".actions", actions))); else details.push(m(`div.${t.status}`, t.name, m(".actions", actions)));
} }
} }
+5
View File
@@ -36,6 +36,10 @@ function stageSpv(task) {
staging.add(task); staging.add(task);
} }
function stageDownload(task) {
staging.add(task);
}
function commit(tasks, callback) { function commit(tasks, callback) {
let devices = {}; let devices = {};
for (let t of tasks) { for (let t of tasks) {
@@ -76,5 +80,6 @@ export {
getStaging, getStaging,
clearStaging, clearStaging,
stageSpv, stageSpv,
stageDownload,
commit commit
}; };
+2
View File
@@ -11,8 +11,10 @@
"permissions.admin.1.devices.validate.pass": true, "permissions.admin.1.devices.validate.pass": true,
"permissions.admin.1.faults.access": 3, "permissions.admin.1.faults.access": 3,
"permissions.admin.1.faults.validate.pass": true, "permissions.admin.1.faults.validate.pass": true,
"permissions.admin.1.files.access": 3,
"permissions.view.1.devices.access": 2, "permissions.view.1.devices.access": 2,
"permissions.view.1.faults.access": 2, "permissions.view.1.faults.access": 2,
"permissions.view.1.files.access": 2,
"ui.pageSize": 10, "ui.pageSize": 10,
"ui.filters.1.label": "Serial number", "ui.filters.1.label": "Serial number",
"ui.filters.1.parameter": "DeviceID.SerialNumber", "ui.filters.1.parameter": "DeviceID.SerialNumber",