Admin backend

This commit is contained in:
baldo 2016-06-04 14:58:11 +02:00
parent bee528f1b8
commit 8f8d78d1df
13 changed files with 129 additions and 5 deletions

View file

@ -371,6 +371,12 @@ module.exports = function (grunt) {
cwd: 'bin', cwd: 'bin',
dest: '<%= yeoman.dist %>/bin', dest: '<%= yeoman.dist %>/bin',
src: ['*'] src: ['*']
},
{
expand: true,
cwd: 'admin',
dest: '<%= yeoman.dist %>/admin',
src: ['{,**}/*.*']
} }
] ]
}, },

1
admin/css/ng-admin.min.css vendored Symbolic link
View file

@ -0,0 +1 @@
../../node_modules/ng-admin/build/ng-admin.min.css

View file

@ -0,0 +1 @@
../../node_modules/ng-admin/build/ng-admin.min.css.map

15
admin/index.html Normal file
View file

@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<title>Knotenverwaltung - Admin-Panel</title>
<link rel="stylesheet" href="css/ng-admin.min.css">
</head>
<body ng-app="ffffngAdmin">
<div ui-view></div>
<script src="js/moment-with-locales.min.js"></script>
<script src="js/ng-admin.min.js"></script>
<script src="js/config.js"></script>
<script src="js/taskActionButton.js"></script>
</body>
</html>

55
admin/js/config.js Normal file
View file

@ -0,0 +1,55 @@
'use strict';
var myApp = angular.module('ffffngAdmin', ['ng-admin']);
myApp.config(['NgAdminConfigurationProvider', function(NgAdminConfigurationProvider) {
function formatMoment(unix) {
return unix ? moment.unix(unix).fromNow() : 'N/A';
}
var nga = NgAdminConfigurationProvider;
var admin = nga.application('Knotenverwaltung - Admin-Panel');
admin
.baseApiUrl('/internal/api/')
.debug(true);
var tasks = nga.entity('tasks').label('Background-Jobs');
tasks
.listView()
.title('Background-Jobs')
.actions([])
.batchActions([])
.exportFields([])
.fields([
nga.field('id'),
nga.field('name'),
nga.field('schedule'),
nga.field('runningSince').map(formatMoment),
nga.field('lastRunStarted').map(formatMoment)
])
.listActions(
'<fa-task-action-button action="run" task="entry" label="Run" size="sm"></fa-task-action-button>'
)
;
admin.addEntity(tasks);
admin.menu(
nga.menu()
.addChild(nga
.menu(tasks)
.icon('<span class="glyphicon glyphicon-cog"></span>')
)
.addChild(nga
.menu()
.template(
'<a href="/internal/logs" target="_blank">' +
'<span class="glyphicon glyphicon-list"></span> Logs' +
'</a>'
)
)
);
nga.configure(admin);
}]);

1
admin/js/moment-with-locales.min.js vendored Symbolic link
View file

@ -0,0 +1 @@
../../node_modules/moment/min/moment-with-locales.min.js

1
admin/js/ng-admin.min.js vendored Symbolic link
View file

@ -0,0 +1 @@
../../node_modules/ng-admin/build/ng-admin.min.js

View file

@ -0,0 +1 @@
../../node_modules/ng-admin/build/ng-admin.min.js.map

View file

@ -0,0 +1,39 @@
'use strict';
angular.module('ffffngAdmin')
.directive('faTaskActionButton', function (Restangular, $state, notification) {
var link = function (scope) {
scope.label = scope.label || 'ACTION';
scope.icon = scope.icon || 'play';
scope.perform = function () {
var task = scope.task();
Restangular
.one('/internal/api/tasks/' + scope.action, task.values.id).put()
.then(function () { $state.reload() })
.then(function () { notification.log('Done', { addnCls: 'humane-flatty-success' }); })
.catch(function (e) {
notification.log('Error: ' + e.data, { addnCls: 'humane-flatty-error' });
console.error(e)
});
};
};
return {
'link': link,
'restrict': 'E',
'scope': {
'action': '@',
'icon': '@',
'task': '&',
'size': '@',
'label': '@'
},
'template':
'<a class="btn btn-default" ng-class="size ? \'btn-\' + size : \'\'" ng-click="perform()">' +
'<span class="glyphicon glyphicon-{{ icon }}" aria-hidden="true"></span>&nbsp;<span class="hidden-xs">{{ label }}</span>' +
'</a>'
};
});

View file

@ -41,6 +41,7 @@
"load-grunt-tasks": "~3.5.0", "load-grunt-tasks": "~3.5.0",
"lodash": "~4.12.0", "lodash": "~4.12.0",
"moment": "~2.13.0", "moment": "~2.13.0",
"ng-admin": "~0.9.1",
"ng-di": "~0.2.1", "ng-di": "~0.2.1",
"node-cron": "~1.1.1", "node-cron": "~1.1.1",
"nodemailer": "~2.4.1", "nodemailer": "~2.4.1",

View file

@ -25,6 +25,7 @@ angular.module('ffffng').factory('app', function (fs, config, _) {
app.use(bodyParser.json()); app.use(bodyParser.json());
var adminDir = __dirname + '/../admin';
var clientDir = __dirname + '/../client'; var clientDir = __dirname + '/../client';
var templateDir = __dirname + '/templates'; var templateDir = __dirname + '/templates';
@ -54,6 +55,7 @@ angular.module('ffffng').factory('app', function (fs, config, _) {
return next(); return next();
}); });
app.use('/internal/admin', express.static(adminDir + '/'));
app.use('/', express.static(clientDir + '/')); app.use('/', express.static(clientDir + '/'));
return app; return app;

View file

@ -11,8 +11,9 @@ angular.module('ffffng').factory('TaskResource', function (
) { ) {
var isValidId = Validator.forConstraint(Constraints.id); var isValidId = Validator.forConstraint(Constraints.id);
function toExternalTask(task) { function toExternalTask(task, id) {
return { return {
id: 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(),
@ -23,7 +24,7 @@ angular.module('ffffng').factory('TaskResource', function (
return { return {
getAll: function (req, res) { getAll: function (req, res) {
var tasks = Scheduler.getTasks(); var tasks = Scheduler.getTasks();
return Resources.success(res, _.mapValues(tasks, toExternalTask)); return Resources.success(res, _.map(tasks, toExternalTask));
}, },
run: function (req, res) { run: function (req, res) {
@ -46,7 +47,7 @@ angular.module('ffffng').factory('TaskResource', function (
task.run(); task.run();
return Resources.success(res, toExternalTask(task)); return Resources.success(res, toExternalTask(task, id));
} }
}; };
}); });

View file

@ -16,8 +16,8 @@ angular.module('ffffng').factory('Router', function (
app.put('/api/monitoring/confirm/:token', MonitoringResource.confirm); app.put('/api/monitoring/confirm/:token', MonitoringResource.confirm);
app.put('/api/monitoring/disable/:token', MonitoringResource.disable); app.put('/api/monitoring/disable/:token', MonitoringResource.disable);
app.get('/internal/api/task/all', TaskResource.getAll); app.get('/internal/api/tasks', TaskResource.getAll);
app.put('/internal/api/task/run/:id', TaskResource.run); app.put('/internal/api/tasks/run/:id', TaskResource.run);
} }
}; };
}); });