Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91d7152ca7 | ||
|
|
3fccc1d8a4 | ||
|
|
5bb6f60c4d | ||
|
|
c2f002b95a | ||
|
|
c55a256d52 | ||
|
|
3fc0b1740d | ||
|
|
1956441d52 | ||
|
|
01e01dae69 | ||
|
|
f14e6ceb97 | ||
|
|
82124d471e | ||
|
|
9286bd6aa0 | ||
|
|
328bfa03e0 | ||
|
|
de65ca0921 |
No files matched your search
@@ -1,5 +1,13 @@
|
||||
# Change Log
|
||||
|
||||
## 1.2.2 (2020-10-03)
|
||||
- Added button to push files to selected devices from device listing page.
|
||||
- A few minor UI improvements.
|
||||
- Fix exception that can happen and persist after a Download request.
|
||||
- Fix validation bug preventing running refreshObject task on data model root.
|
||||
- Fix invalid arguments fault in refresh preset configuration when upgrading
|
||||
from v1.1.
|
||||
|
||||
## 1.2.1 (2020-09-08)
|
||||
- Fix bug causing faults to not be displayed in the UI.
|
||||
- Fix bug where deleting objects does not get reflected immediately in the UI.
|
||||
|
||||
@@ -236,6 +236,10 @@ function sanitizeTask(task): void {
|
||||
break;
|
||||
|
||||
case "refreshObject":
|
||||
if (typeof task.objectName !== "string")
|
||||
throw new Error("Missing 'objectName' property");
|
||||
break;
|
||||
|
||||
case "deleteObject":
|
||||
if (typeof task.objectName !== "string" || !task.objectName.length)
|
||||
throw new Error("Missing 'objectName' property");
|
||||
|
||||
@@ -42,7 +42,7 @@ function interpretEscapes(str): string {
|
||||
|
||||
export function map(
|
||||
exp: Expression,
|
||||
callback: (exp: Expression) => Expression
|
||||
callback: (e: Expression) => Expression
|
||||
): Expression {
|
||||
if (!Array.isArray(exp)) return callback(exp);
|
||||
|
||||
@@ -60,7 +60,7 @@ export function map(
|
||||
|
||||
export async function mapAsync(
|
||||
exp: Expression,
|
||||
callback: (exp: Expression) => Promise<Expression>
|
||||
callback: (e: Expression) => Promise<Expression>
|
||||
): Promise<Expression> {
|
||||
if (!Array.isArray(exp)) return callback(exp);
|
||||
|
||||
|
||||
@@ -264,21 +264,21 @@ export function evaluateCallback(exp: Expression): Expression {
|
||||
|
||||
export function evaluate(
|
||||
exp: Expression,
|
||||
obj: Record<string, unknown> | ((exp: string) => Expression),
|
||||
obj: Record<string, unknown> | ((e: string) => Expression),
|
||||
now: number,
|
||||
cb?: (exp: Expression) => Expression
|
||||
cb?: (e: Expression) => Expression
|
||||
): string | number | boolean | null;
|
||||
export function evaluate(
|
||||
exp: Expression,
|
||||
obj?: Record<string, unknown> | ((exp: string) => Expression),
|
||||
obj?: Record<string, unknown> | ((e: string) => Expression),
|
||||
now?: number,
|
||||
cb?: (exp: Expression) => Expression
|
||||
cb?: (e: Expression) => Expression
|
||||
): Expression;
|
||||
export function evaluate(
|
||||
exp: Expression,
|
||||
obj?: Record<string, unknown> | ((exp: string) => Expression),
|
||||
obj?: Record<string, unknown> | ((e: string) => Expression),
|
||||
now?: number,
|
||||
cb?: (exp: Expression) => Expression
|
||||
cb?: (e: Expression) => Expression
|
||||
): Expression {
|
||||
return map(exp, (e) => {
|
||||
if (cb) e = cb(e);
|
||||
@@ -306,19 +306,19 @@ export async function evaluateAsync(
|
||||
exp: Expression,
|
||||
obj: Record<string, unknown>,
|
||||
now: number,
|
||||
cb?: (exp: Expression) => Promise<Expression>
|
||||
cb?: (e: Expression) => Promise<Expression>
|
||||
): Promise<string | number | boolean | null>;
|
||||
export async function evaluateAsync(
|
||||
exp: Expression,
|
||||
obj?: Record<string, unknown>,
|
||||
now?: number,
|
||||
cb?: (exp: Expression) => Promise<Expression>
|
||||
cb?: (e: Expression) => Promise<Expression>
|
||||
): Promise<Expression>;
|
||||
export async function evaluateAsync(
|
||||
exp: Expression,
|
||||
obj?: Record<string, unknown>,
|
||||
now?: number,
|
||||
cb?: (exp: Expression) => Promise<Expression>
|
||||
cb?: (e: Expression) => Promise<Expression>
|
||||
): Promise<Expression> {
|
||||
return mapAsync(exp, async (e) => {
|
||||
if (cb) e = await cb(e);
|
||||
|
||||
+7
-2
@@ -1211,12 +1211,17 @@ export function listener(
|
||||
})
|
||||
.catch((err) => {
|
||||
currentSessions.delete(httpResponse.connection);
|
||||
httpResponse.writeHead(500, { Connection: "close" });
|
||||
httpResponse.end(`${err.name}: ${err.message}`);
|
||||
stats.concurrentRequests -= 1;
|
||||
setTimeout(() => {
|
||||
throw err;
|
||||
});
|
||||
try {
|
||||
httpResponse.connection.unref();
|
||||
httpResponse.writeHead(500, { Connection: "close" });
|
||||
httpResponse.end(`${err.name}: ${err.message}`);
|
||||
} catch (err) {
|
||||
// Ignore
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -691,6 +691,11 @@ export async function getOperations(
|
||||
for (const r of res) {
|
||||
const commandKey = r._id.slice(deviceId.length + 1);
|
||||
delete r._id;
|
||||
// Workaround for a bug in v1.2.1 where operation object is saved without deserialization
|
||||
if (typeof r.provisions !== "string") {
|
||||
operations[commandKey] = r;
|
||||
continue;
|
||||
}
|
||||
r.timestamp = +r.timestamp;
|
||||
if (r.args) r.args = JSON.parse(r.args);
|
||||
r.provisions = JSON.parse(r.provisions);
|
||||
@@ -712,7 +717,7 @@ export async function saveOperation(
|
||||
o["provisions"] = JSON.stringify(operation.provisions);
|
||||
o["retries"] = JSON.stringify(operation.retries);
|
||||
o["args"] = JSON.stringify(operation.args);
|
||||
await operationsCollection.replaceOne({ _id: id }, operation, {
|
||||
await operationsCollection.replaceOne({ _id: id }, o, {
|
||||
upsert: true,
|
||||
});
|
||||
}
|
||||
|
||||
+2
-2
@@ -188,7 +188,7 @@ async function fetchPresets(): Promise<Preset[]> {
|
||||
for (const c of preset["configurations"]) {
|
||||
switch (c.type) {
|
||||
case "age":
|
||||
_provisions.push(["refresh", c.name, c.age]);
|
||||
_provisions.push(["refresh", c.name, +c.age]);
|
||||
break;
|
||||
|
||||
case "value":
|
||||
@@ -475,7 +475,7 @@ export function getConfig(
|
||||
key: string,
|
||||
context: Record<string, unknown>,
|
||||
now: number,
|
||||
cb?: (Expression) => Expression
|
||||
cb?: (e: Expression) => Expression
|
||||
): string | number | boolean | null {
|
||||
const snapshot = snapshots.get(snapshotKey);
|
||||
if (!snapshot) throw new Error("Cache snapshot does not exist");
|
||||
|
||||
@@ -60,7 +60,9 @@ const getAuthorizer = memoize(
|
||||
);
|
||||
|
||||
koa.on("error", async (err) => {
|
||||
throw err;
|
||||
setTimeout(() => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
|
||||
koa.use(async (ctx, next) => {
|
||||
|
||||
@@ -145,16 +145,6 @@ export async function postTasks(
|
||||
return { connectionRequest: "OK", tasks: statuses };
|
||||
}
|
||||
|
||||
interface PingResponse {
|
||||
packetsTransmitted: number;
|
||||
packetsReceived: number;
|
||||
packetLoss: string;
|
||||
min: number;
|
||||
avg: number;
|
||||
max: number;
|
||||
mdev: number;
|
||||
}
|
||||
|
||||
export async function putResource(
|
||||
resource: string,
|
||||
id: string,
|
||||
|
||||
Generated
+2143
-842
File diff suppressed because it is too large.
Load diff
+20
-20
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "genieacs",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.2",
|
||||
"description": "A TR-069 Auto Configuration Server (ACS)",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -31,47 +31,47 @@
|
||||
"koa-router": "^9.4.0",
|
||||
"koa-static": "^5.0.0",
|
||||
"later": "^1.2.0",
|
||||
"mongodb": "^3.6.1",
|
||||
"mongodb": "^3.6.2",
|
||||
"parsimmon": "^1.16.0",
|
||||
"seedrandom": "^3.0.5",
|
||||
"yaml": "^1.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^15.0.0",
|
||||
"@rollup/plugin-commonjs": "^15.1.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^9.0.0",
|
||||
"@rollup/plugin-typescript": "^5.0.2",
|
||||
"@rollup/plugin-typescript": "^6.0.0",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/koa": "^2.11.4",
|
||||
"@types/koa-compress": "^4.0.0",
|
||||
"@types/koa-compress": "^4.0.1",
|
||||
"@types/koa-router": "^7.4.1",
|
||||
"@types/koa-static": "^4.0.1",
|
||||
"@types/mithril": "^2.0.3",
|
||||
"@types/mithril": "^2.0.4",
|
||||
"@types/mongodb": "^3.5.27",
|
||||
"@types/parsimmon": "^1.10.2",
|
||||
"@types/parsimmon": "^1.10.3",
|
||||
"@types/seedrandom": "^2.4.28",
|
||||
"@types/svgo": "^1.3.3",
|
||||
"@typescript-eslint/eslint-plugin": "^3.10.1",
|
||||
"@typescript-eslint/parser": "^3.10.1",
|
||||
"ava": "^3.12.1",
|
||||
"codemirror": "^5.57.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.3.0",
|
||||
"@typescript-eslint/parser": "^4.3.0",
|
||||
"ava": "^3.13.0",
|
||||
"codemirror": "^5.58.1",
|
||||
"cssnano": "^4.1.10",
|
||||
"eslint": "^7.8.0",
|
||||
"eslint-config-prettier": "^6.11.0",
|
||||
"eslint": "^7.10.0",
|
||||
"eslint-config-prettier": "^6.12.0",
|
||||
"esm": "^3.2.25",
|
||||
"jsbi": "^3.1.3",
|
||||
"jsbi": "^3.1.4",
|
||||
"mithril": "^2.0.4",
|
||||
"postcss": "^7.0.32",
|
||||
"postcss": "^8.1.1",
|
||||
"postcss-import": "^12.0.1",
|
||||
"postcss-preset-env": "^6.7.0",
|
||||
"prettier": "^2.1.1",
|
||||
"rollup": "^2.26.9",
|
||||
"rollup-plugin-terser": "^7.0.1",
|
||||
"prettier": "^2.1.2",
|
||||
"rollup": "^2.28.2",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"source-map-loader": "^1.1.0",
|
||||
"svgo": "^1.3.2",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.2",
|
||||
"webpack": "^4.44.1"
|
||||
"typescript": "^4.0.3",
|
||||
"webpack": "^4.44.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.13.0"
|
||||
|
||||
@@ -70,7 +70,7 @@ const component: ClosureComponent = (): Component => {
|
||||
onclick: () => {
|
||||
taskQueue.stageDownload({
|
||||
name: "download",
|
||||
device: device["DeviceID.ID"].value[0],
|
||||
devices: [device["DeviceID.ID"].value[0]],
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
@@ -90,7 +90,7 @@ const component: ClosureComponent = (): Component => {
|
||||
onclick: () => {
|
||||
taskQueue.stageSpv({
|
||||
name: "setParameterValues",
|
||||
device: device["DeviceID.ID"].value[0],
|
||||
devices: [device["DeviceID.ID"].value[0]],
|
||||
parameterValues: [
|
||||
[
|
||||
parameter,
|
||||
|
||||
@@ -81,7 +81,8 @@ const component: ClosureComponent = (): Component => {
|
||||
store.fulfill(0, Date.now());
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
e.target.disabled = false;
|
||||
notifications.push("error", err.message);
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
+32
-1
@@ -42,6 +42,35 @@ export function flattenConfig(config: Record<string, unknown>): any {
|
||||
return flatten;
|
||||
}
|
||||
|
||||
// Order keys such that nested objects come last
|
||||
function orderKeys(config: any): number {
|
||||
let res = 1;
|
||||
if (typeof config !== "object") return res;
|
||||
if (Array.isArray(config)) {
|
||||
for (const c of config) res += orderKeys(c);
|
||||
return res;
|
||||
}
|
||||
|
||||
const weights: [string, number][] = Object.entries(config).map(([k, v]) => [
|
||||
k,
|
||||
orderKeys(v),
|
||||
]);
|
||||
|
||||
weights.sort((a, b) => {
|
||||
if (a[1] !== b[1]) return a[1] - b[1];
|
||||
if (b[0] > a[0]) return -1;
|
||||
else return 1;
|
||||
});
|
||||
|
||||
for (const [k, w] of weights) {
|
||||
res += w;
|
||||
const v = config[k];
|
||||
delete config[k];
|
||||
config[k] = v;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export function structureConfig(config: Config[]): any {
|
||||
config.sort((a, b) => (a._id > b._id ? 1 : a._id < b._id ? -1 : 0));
|
||||
const _config = {};
|
||||
@@ -93,7 +122,9 @@ export function structureConfig(config: Config[]): any {
|
||||
return object;
|
||||
};
|
||||
|
||||
return toArray(_config);
|
||||
const res = toArray(_config);
|
||||
orderKeys(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
export function diffConfig(
|
||||
|
||||
@@ -178,6 +178,8 @@ body {
|
||||
}
|
||||
|
||||
& > .queue {
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
& > .pending {
|
||||
animation: 0.5s linear 0s infinite alternate pending-blink;
|
||||
border-radius: 0.4em;
|
||||
|
||||
+28
-13
@@ -23,7 +23,7 @@ import config from "./config";
|
||||
import indexTableComponent from "./index-table-component";
|
||||
import filterComponent from "./filter-component";
|
||||
import * as store from "./store";
|
||||
import * as taskQueue from "./task-queue";
|
||||
import { queueTask, stageDownload } from "./task-queue";
|
||||
import * as notifications from "./notifications";
|
||||
import { parse, stringify } from "../lib/common/expression-parser";
|
||||
import { evaluate, extractParams } from "../lib/common/expression";
|
||||
@@ -91,12 +91,11 @@ function renderActions(selected: Set<string>): Children {
|
||||
title: "Reboot selected devices",
|
||||
disabled: !selected.size,
|
||||
onclick: () => {
|
||||
for (const d of selected) {
|
||||
taskQueue.queueTask({
|
||||
name: "reboot",
|
||||
device: d,
|
||||
});
|
||||
}
|
||||
const tasks = [...selected].map((s) => ({
|
||||
name: "reboot",
|
||||
device: s,
|
||||
}));
|
||||
queueTask(...tasks);
|
||||
},
|
||||
},
|
||||
"Reboot"
|
||||
@@ -110,18 +109,34 @@ function renderActions(selected: Set<string>): Children {
|
||||
title: "Factory reset selected devices",
|
||||
disabled: !selected.size,
|
||||
onclick: () => {
|
||||
for (const d of selected) {
|
||||
taskQueue.queueTask({
|
||||
name: "factoryReset",
|
||||
device: d,
|
||||
});
|
||||
}
|
||||
const tasks = [...selected].map((s) => ({
|
||||
name: "factoryReset",
|
||||
device: s,
|
||||
}));
|
||||
queueTask(...tasks);
|
||||
},
|
||||
},
|
||||
"Reset"
|
||||
)
|
||||
);
|
||||
|
||||
buttons.push(
|
||||
m(
|
||||
"button.critical",
|
||||
{
|
||||
title: "Push a firmware or a config file",
|
||||
disabled: !selected.size,
|
||||
onclick: () => {
|
||||
stageDownload({
|
||||
name: "download",
|
||||
devices: [...selected],
|
||||
});
|
||||
},
|
||||
},
|
||||
"Push file"
|
||||
)
|
||||
);
|
||||
|
||||
buttons.push(
|
||||
m(
|
||||
"button.primary",
|
||||
|
||||
+83
-58
@@ -24,10 +24,21 @@ import m, {
|
||||
Component,
|
||||
VnodeDOM,
|
||||
} from "mithril";
|
||||
import * as taskQueue from "./task-queue";
|
||||
import * as store from "./store";
|
||||
import * as notifications from "./notifications";
|
||||
import { getIcon } from "./icons";
|
||||
import {
|
||||
clear,
|
||||
commit,
|
||||
deleteTask,
|
||||
getQueue,
|
||||
getStaging,
|
||||
QueueTask,
|
||||
queueTask,
|
||||
StageTask,
|
||||
} from "./task-queue";
|
||||
|
||||
const invalid: WeakSet<StageTask> = new WeakSet();
|
||||
|
||||
function mparam(param): Children {
|
||||
return m("span.parameter", { title: param }, `${param}`);
|
||||
@@ -37,7 +48,7 @@ function mval(val): Children {
|
||||
return m("span.value", { title: val }, `${val}`);
|
||||
}
|
||||
|
||||
function renderStagingSpv(task, queueFunc, cancelFunc): Children {
|
||||
function renderStagingSpv(task: StageTask, queueFunc, cancelFunc): Children {
|
||||
function keydown(e): void {
|
||||
if (e.keyCode === 13) queueFunc();
|
||||
else if (e.keyCode === 27) cancelFunc();
|
||||
@@ -90,13 +101,24 @@ function renderStagingSpv(task, queueFunc, cancelFunc): Children {
|
||||
return [m("span", "Editing ", mparam(task.parameterValues[0][0])), input];
|
||||
}
|
||||
|
||||
function renderStagingDownload(task): Children {
|
||||
task.invalid = !task.fileName || !task.fileType;
|
||||
function renderStagingDownload(task: StageTask): Children {
|
||||
if (!task.fileName || !task.fileType) invalid.add(task);
|
||||
else invalid.delete(task);
|
||||
const files = store.fetch("files", true);
|
||||
const idParts = task.device.split("-");
|
||||
const oui = decodeURIComponent(idParts[0]);
|
||||
const productClass =
|
||||
idParts.length === 3 ? decodeURIComponent(idParts[1]) : "";
|
||||
let oui = "";
|
||||
let productClass = "";
|
||||
for (const d of task.devices) {
|
||||
const parts = d.split("-");
|
||||
if (oui === "") oui = parts[0];
|
||||
else if (oui !== parts[0]) oui = null;
|
||||
if (parts.length === 3) {
|
||||
if (productClass === "") productClass = parts[1];
|
||||
else if (productClass !== parts[1]) productClass = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (oui) oui = decodeURIComponent(oui);
|
||||
if (productClass) productClass = decodeURIComponent(productClass);
|
||||
|
||||
const typesList = [
|
||||
"",
|
||||
@@ -162,13 +184,17 @@ function renderStagingDownload(task): Children {
|
||||
];
|
||||
}
|
||||
|
||||
function renderStaging(staging): Child[] {
|
||||
function renderStaging(staging: Set<StageTask>): Child[] {
|
||||
const elements: Child[] = [];
|
||||
|
||||
for (const s of staging) {
|
||||
const queueFunc = (): void => {
|
||||
staging.delete(s);
|
||||
taskQueue.queueTask(s);
|
||||
for (const d of s.devices) {
|
||||
const t = Object.assign({ device: d }, s);
|
||||
delete t.devices;
|
||||
queueTask(t);
|
||||
}
|
||||
};
|
||||
const cancelFunc = (): void => {
|
||||
staging.delete(s);
|
||||
@@ -181,7 +207,7 @@ function renderStaging(staging): Child[] {
|
||||
|
||||
const queue = m(
|
||||
"button.primary",
|
||||
{ title: "Queue task", onclick: queueFunc, disabled: s.invalid },
|
||||
{ title: "Queue task", onclick: queueFunc, disabled: invalid.has(s) },
|
||||
"Queue"
|
||||
);
|
||||
const cancel = m(
|
||||
@@ -195,7 +221,7 @@ function renderStaging(staging): Child[] {
|
||||
return elements;
|
||||
}
|
||||
|
||||
function renderQueue(queue): Child[] {
|
||||
function renderQueue(queue: Set<QueueTask>): Child[] {
|
||||
const details: Child[] = [];
|
||||
const devices: { [deviceId: string]: any[] } = {};
|
||||
for (const t of queue) {
|
||||
@@ -215,7 +241,7 @@ function renderQueue(queue): Child[] {
|
||||
{
|
||||
title: "Retry this task",
|
||||
onclick: () => {
|
||||
taskQueue.queueTask(t);
|
||||
queueTask(t);
|
||||
},
|
||||
},
|
||||
getIcon("retry")
|
||||
@@ -229,7 +255,7 @@ function renderQueue(queue): Child[] {
|
||||
{
|
||||
title: "Remove this task",
|
||||
onclick: () => {
|
||||
taskQueue.deleteTask(t);
|
||||
deleteTask(t);
|
||||
},
|
||||
},
|
||||
getIcon("remove")
|
||||
@@ -347,8 +373,8 @@ function renderNotifications(notifs): Child[] {
|
||||
const component: ClosureComponent = (): Component => {
|
||||
return {
|
||||
view: (vnode) => {
|
||||
const queue = taskQueue.getQueue();
|
||||
const staging = taskQueue.getStaging();
|
||||
const queue = getQueue();
|
||||
const staging = getStaging();
|
||||
const notifs = notifications.getNotifications();
|
||||
|
||||
let drawerElement, statusElement;
|
||||
@@ -394,56 +420,55 @@ const component: ClosureComponent = (): Component => {
|
||||
title: "Commit queued tasks",
|
||||
disabled: !statusCount.queued,
|
||||
onclick: () => {
|
||||
const tasks = Array.from(taskQueue.getQueue()).filter(
|
||||
const tasks = Array.from(getQueue()).filter(
|
||||
(t) => t["status"] === "queued"
|
||||
);
|
||||
taskQueue
|
||||
.commit(
|
||||
tasks,
|
||||
(deviceId, err, connectionRequestStatus, tasks2) => {
|
||||
if (err) {
|
||||
notifications.push(
|
||||
"error",
|
||||
`${deviceId}: ${err.message}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (connectionRequestStatus !== "OK") {
|
||||
notifications.push(
|
||||
"error",
|
||||
`${deviceId}: ${connectionRequestStatus}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const t of tasks2) {
|
||||
if (t.status === "stale") {
|
||||
notifications.push(
|
||||
"error",
|
||||
`${deviceId}: No contact from device`
|
||||
);
|
||||
return;
|
||||
} else if (t.status === "fault") {
|
||||
notifications.push(
|
||||
"error",
|
||||
`${deviceId}: Task(s) faulted`
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
commit(
|
||||
tasks,
|
||||
(deviceId, err, connectionRequestStatus, tasks2) => {
|
||||
if (err) {
|
||||
notifications.push(
|
||||
"success",
|
||||
`${deviceId}: Task(s) committed`
|
||||
"error",
|
||||
`${deviceId}: ${err.message}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
)
|
||||
|
||||
if (connectionRequestStatus !== "OK") {
|
||||
notifications.push(
|
||||
"error",
|
||||
`${deviceId}: ${connectionRequestStatus}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const t of tasks2) {
|
||||
if (t.status === "stale") {
|
||||
notifications.push(
|
||||
"error",
|
||||
`${deviceId}: No contact from device`
|
||||
);
|
||||
return;
|
||||
} else if (t.status === "fault") {
|
||||
notifications.push(
|
||||
"error",
|
||||
`${deviceId}: Task(s) faulted`
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
notifications.push(
|
||||
"success",
|
||||
`${deviceId}: Task(s) committed`
|
||||
);
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
store.fulfill(0, Date.now());
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
notifications.push("error", err.message);
|
||||
});
|
||||
},
|
||||
},
|
||||
@@ -453,7 +478,7 @@ const component: ClosureComponent = (): Component => {
|
||||
"button",
|
||||
{
|
||||
title: "Clear tasks",
|
||||
onclick: taskQueue.clear,
|
||||
onclick: clear,
|
||||
disabled: !queueElements.length,
|
||||
},
|
||||
"Clear"
|
||||
|
||||
@@ -27,6 +27,8 @@ interface Attribute {
|
||||
type?: string;
|
||||
}
|
||||
|
||||
const MAX_PAGE_SIZE = 200;
|
||||
|
||||
function renderTable(
|
||||
attributes: Attribute[],
|
||||
data: Record<string, any>[],
|
||||
@@ -37,7 +39,7 @@ function renderTable(
|
||||
onSortChange: (obj: Record<string, number>) => void,
|
||||
downloadUrl?: string,
|
||||
valueCallback?: (attr: Attribute, record: Record<string, any>) => Children,
|
||||
actionsCallback?: Children | ((selected: Set<string>) => Children),
|
||||
actionsCallback?: Children | ((sel: Set<string>) => Children),
|
||||
recordActionsCallback?: Children | ((record: Record<string, any>) => Children)
|
||||
): Children {
|
||||
const records = data || [];
|
||||
@@ -180,7 +182,8 @@ function renderTable(
|
||||
{
|
||||
title: "Show more records",
|
||||
onclick: showMoreCallback,
|
||||
disabled: !data.length || records.length >= total,
|
||||
disabled:
|
||||
!data.length || records.length >= Math.min(MAX_PAGE_SIZE, total),
|
||||
},
|
||||
"More"
|
||||
)
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ export const component: ClosureComponent = (): Component => {
|
||||
location.reload();
|
||||
})
|
||||
.catch((err) => {
|
||||
notifications.push("error", err.message);
|
||||
notifications.push("error", err.response || err.message);
|
||||
e.target.disabled = false;
|
||||
});
|
||||
return false;
|
||||
|
||||
+44
-13
@@ -19,23 +19,41 @@
|
||||
|
||||
import * as store from "./store";
|
||||
import { Task } from "../lib/types";
|
||||
import * as notifications from "./notifications";
|
||||
|
||||
export interface QueueTask extends Task {
|
||||
status?: string;
|
||||
device?: string;
|
||||
device: string;
|
||||
}
|
||||
|
||||
const queue: Set<QueueTask> = new Set();
|
||||
const staging: Set<QueueTask> = new Set();
|
||||
export interface StageTask extends Task {
|
||||
devices: string[];
|
||||
}
|
||||
|
||||
export function queueTask(task: QueueTask): void {
|
||||
staging.delete(task);
|
||||
task.status = "queued";
|
||||
queue.add(task);
|
||||
const MAX_QUEUE = 100;
|
||||
|
||||
const queue: Set<QueueTask> = new Set();
|
||||
const staging: Set<StageTask> = new Set();
|
||||
|
||||
function canQueue(tasks: QueueTask[]): boolean {
|
||||
let count = queue.size;
|
||||
for (const task of tasks) if (!queue.has(task)) ++count;
|
||||
return count <= MAX_QUEUE;
|
||||
}
|
||||
|
||||
export function queueTask(...tasks: QueueTask[]): void {
|
||||
if (!canQueue(tasks)) {
|
||||
notifications.push("error", "Too many tasks in queue");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const task of tasks) {
|
||||
task.status = "queued";
|
||||
queue.add(task);
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteTask(task: QueueTask): void {
|
||||
staging.delete(task);
|
||||
queue.delete(task);
|
||||
}
|
||||
|
||||
@@ -47,7 +65,7 @@ export function clear(): void {
|
||||
queue.clear();
|
||||
}
|
||||
|
||||
export function getStaging(): Set<QueueTask> {
|
||||
export function getStaging(): Set<StageTask> {
|
||||
return staging;
|
||||
}
|
||||
|
||||
@@ -55,11 +73,19 @@ export function clearStaging(): void {
|
||||
staging.clear();
|
||||
}
|
||||
|
||||
export function stageSpv(task: QueueTask): void {
|
||||
export function stageSpv(task: StageTask): void {
|
||||
if (queue.size + task.devices.length > MAX_QUEUE) {
|
||||
notifications.push("error", "Too many tasks in queue");
|
||||
return;
|
||||
}
|
||||
staging.add(task);
|
||||
}
|
||||
|
||||
export function stageDownload(task: QueueTask): void {
|
||||
export function stageDownload(task: StageTask): void {
|
||||
if (queue.size + task.devices.length > MAX_QUEUE) {
|
||||
notifications.push("error", "Too many tasks in queue");
|
||||
return;
|
||||
}
|
||||
staging.add(task);
|
||||
}
|
||||
|
||||
@@ -69,14 +95,19 @@ export function commit(
|
||||
deviceId: string,
|
||||
err: Error,
|
||||
conReqStatus: string,
|
||||
tasks: QueueTask[]
|
||||
_tasks: QueueTask[]
|
||||
) => void
|
||||
): Promise<void> {
|
||||
const devices: { [deviceId: string]: any[] } = {};
|
||||
|
||||
if (!canQueue(tasks))
|
||||
return Promise.reject(new Error("Too many tasks in queue"));
|
||||
|
||||
for (const t of tasks) {
|
||||
devices[t.device] = devices[t.device] || [];
|
||||
devices[t.device].push(t);
|
||||
queueTask(t);
|
||||
t.status = "queued";
|
||||
queue.add(t);
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
|
||||
Reference in new issue
Block a user