Implemented /task/list

pull/99/head
Piero Toffanin 2020-01-19 16:37:54 -05:00
rodzic f695c7b44e
commit dccc51f7da
7 zmienionych plików z 106 dodań i 18 usunięć

Wyświetl plik

@ -8,7 +8,7 @@ REST API to access ODM
=== Version information
[%hardbreaks]
_Version_ : 1.5.3
_Version_ : 1.6.0
=== Contact information
@ -279,6 +279,48 @@ _required_|UUID of the task|string|
|===
[[_task_list_get]]
=== GET /task/list
==== Description
Gets the list of tasks available on this node.
==== Parameters
[options="header", cols=".^2,.^3,.^9,.^4,.^2"]
|===
|Type|Name|Description|Schema|Default
|*Query*|*token* +
_optional_|Token required for authentication (when authentication is required).|string|
|===
==== Responses
[options="header", cols=".^2,.^14,.^4"]
|===
|HTTP Code|Description|Schema
|*200*|Task List|< <<_task_list_get_response_200,Response 200>> > array
|*default*|Error|<<_error,Error>>
|===
[[_task_list_get_response_200]]
*Response 200*
[options="header", cols=".^3,.^11,.^4"]
|===
|Name|Description|Schema
|*uuid* +
_required_|UUID|string
|===
==== Tags
* task
[[_task_new_post]]
=== POST /task/new

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -292,6 +292,44 @@ let getTaskFromUuid = (req, res, next) => {
} else res.json({ error: `${req.params.uuid} not found` });
};
/** @swagger
* /task/list:
* get:
* description: Gets the list of tasks available on this node.
* tags: [task]
* parameters:
* -
* name: token
* in: query
* description: 'Token required for authentication (when authentication is required).'
* required: false
* type: string
* responses:
* 200:
* description: Task List
* schema:
* title: TaskList
* type: array
* items:
* type: object
* required: [uuid]
* properties:
* uuid:
* type: string
* description: UUID
* default:
* description: Error
* schema:
* $ref: '#/definitions/Error'
*/
app.get('/task/list', authCheck, (req, res) => {
const tasks = [];
for (let uuid in taskManager.tasks){
tasks.push({uuid});
}
res.json(tasks);
});
/** @swagger
* /task/{uuid}/info:
* get:

Wyświetl plik

@ -22,7 +22,6 @@ const async = require('async');
const assert = require('assert');
const logger = require('./logger');
const fs = require('fs');
const si = require("systeminformation");
const path = require('path');
const rmdir = require('rimraf');
const odmRunner = require('./odmRunner');

Wyświetl plik

@ -1,6 +1,6 @@
{
"name": "NodeODM",
"version": "1.5.4",
"version": "1.6.0",
"description": "REST API to access ODM",
"main": "index.js",
"scripts": {

Wyświetl plik

@ -141,7 +141,13 @@
</form>
</div>
<div class="col-md-7" id="taskList">
<p data-bind="visible: tasks().length === 0">No running tasks.</p>
<div data-bind="visible: error() != ''">
<div class="alert alert-warning" role="alert" data-bind="text: error()"></div>
</div>
<div data-bind="visible: loading()">
Loading task list... <span class="glyphicon glyphicon-refresh spinning"></span>
</div>
<p data-bind="visible: !loading() && tasks().length === 0">No running tasks.</p>
<div data-bind="foreach: tasks">
<div class="task" data-bind="css: {pulsePositive: info().status && info().status.code === 40, pulseNegative: info().status && info().status.code === 30}">
<p data-bind="visible: loading()">Retrieving <span data-bind="text: uuid"></span> ... <span class="glyphicon glyphicon-refresh spinning"></span></p>
@ -208,7 +214,7 @@
<script src="js/vendor/knockout-3.4.0.js"></script>
<script src="js/vendor/ko.observableDictionary.js"></script>
<script src="js/dropzone.js" type="text/javascript"></script>
<script src="js/main.js?t=1"></script>
<script src="js/main.js?t=2"></script>
</body>
</html>

Wyświetl plik

@ -205,27 +205,30 @@ $(function() {
}
function TaskList() {
var uuids = JSON.parse(localStorage.getItem("odmTaskList") || "[]");
if (Object.prototype.toString.call(uuids) !== "[object Array]") uuids = [];
var self = this;
var url = "/task/list?token=" + token;
this.error = ko.observable("");
this.loading = ko.observable(true);
this.tasks = ko.observableArray();
this.tasks = ko.observableArray($.map(uuids, function(uuid) {
return new Task(uuid);
}));
$.get(url)
.done(function(tasksJson) {
for (var i in tasksJson){
self.tasks.push(new Task(tasksJson[i].uuid));
}
})
.fail(function() {
self.error(url + " is unreachable.");
})
.always(function() { self.loading(false); });
}
TaskList.prototype.add = function(task) {
this.tasks.push(task);
this.saveTaskListToLocalStorage();
};
TaskList.prototype.saveTaskListToLocalStorage = function() {
localStorage.setItem("odmTaskList", JSON.stringify($.map(this.tasks(), function(task) {
return task.uuid;
})));
};
TaskList.prototype.remove = function(task) {
this.tasks.remove(function(t) {
return t === task;
});
this.saveTaskListToLocalStorage();
};
var codes = {