Paging for tasks in admin panel.

This commit is contained in:
baldo 2016-06-07 11:01:35 +02:00
parent 0f1a21c905
commit ce2359a094
4 changed files with 28 additions and 11 deletions

View file

@ -34,7 +34,7 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Cons
nodes nodes
.listView() .listView()
.title('Nodes') .title('Nodes')
.perPage(5) .perPage(30)
.actions([]) .actions([])
.batchActions([]) .batchActions([])
.exportFields([]) .exportFields([])
@ -103,6 +103,7 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Cons
tasks tasks
.listView() .listView()
.title('Background-Jobs') .title('Background-Jobs')
.perPage(30)
.actions([]) .actions([])
.batchActions([]) .batchActions([])
.exportFields([]) .exportFields([])

View file

@ -31,6 +31,7 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger, confi
var id = nextTaskId(); var id = nextTaskId();
var task = { var task = {
id: id,
name: jobName, name: jobName,
schedule: expr, schedule: expr,
job: job, job: job,

View file

@ -108,7 +108,6 @@ angular.module('ffffng').factory('NodeResource', function (
} }
res.set('X-Total-Count', total); res.set('X-Total-Count', total);
return Resources.success(res, nodes); return Resources.success(res, nodes);
}); });
}); });

View file

@ -11,9 +11,9 @@ angular.module('ffffng').factory('TaskResource', function (
) { ) {
var isValidId = Validator.forConstraint(Constraints.id); var isValidId = Validator.forConstraint(Constraints.id);
function toExternalTask(task, id) { function toExternalTask(task) {
return { return {
id: id, id: task.id,
name: task.name, name: task.name,
schedule: task.schedule, schedule: task.schedule,
runningSince: task.runningSince && task.runningSince.unix(), runningSince: task.runningSince && task.runningSince.unix(),
@ -55,31 +55,47 @@ angular.module('ffffng').factory('TaskResource', function (
return callback(err); return callback(err);
} }
callback(null, id, task); callback(null, task);
}); });
}); });
} }
function setTaskEnabled(req, res, enable) { function setTaskEnabled(req, res, enable) {
withTask(req, res, function (err, id, task) { withTask(req, res, function (err, task) {
if (err) { if (err) {
return Resources.error(res, err); return Resources.error(res, err);
} }
task.enabled = !!enable; // ensure boolean task.enabled = !!enable; // ensure boolean
return Resources.success(res, toExternalTask(task, id)); return Resources.success(res, toExternalTask(task));
}); });
} }
return { return {
getAll: function (req, res) { getAll: function (req, res) {
var tasks = Scheduler.getTasks(); Resources.getValidRestParams('list', req, function (err, restParams) {
return Resources.success(res, _.map(tasks, toExternalTask)); if (err) {
return Resources.error(res, err);
}
// TODO: Sort
var tasks = _.values(Scheduler.getTasks());
var total = tasks.length;
var page = restParams._page;
var perPage = restParams._perPage;
var pageTasks = tasks.slice((page - 1) * perPage, page * perPage);
res.set('X-Total-Count', total);
return Resources.success(res, _.map(pageTasks, toExternalTask));
});
}, },
run: function (req, res) { run: function (req, res) {
withTask(req, res, function (err, id, task) { withTask(req, res, function (err, task) {
if (err) { if (err) {
return Resources.error(res, err); return Resources.error(res, err);
} }
@ -90,7 +106,7 @@ angular.module('ffffng').factory('TaskResource', function (
task.run(); task.run();
return Resources.success(res, toExternalTask(task, id)); return Resources.success(res, toExternalTask(task));
}); });
}, },