Open node in form and map.
This commit is contained in:
parent
5b9d2e615b
commit
03083b819b
12 changed files with 80 additions and 19 deletions
|
@ -24,6 +24,7 @@ angular.module('ffffng').factory('app', function (fs, config, _) {
|
|||
app.use('/internal', auth.connect(internalAuth));
|
||||
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
var adminDir = __dirname + '/../admin';
|
||||
var clientDir = __dirname + '/../client';
|
||||
|
|
|
@ -76,6 +76,4 @@ var config = deepExtend({}, defaultConfig, configJSON);
|
|||
|
||||
module.exports = config;
|
||||
|
||||
angular.module('ffffng').factory('config', function () {
|
||||
return config;
|
||||
});
|
||||
angular.module('ffffng').constant('config', config);
|
||||
|
|
|
@ -19,6 +19,7 @@ require('./utils/resources');
|
|||
require('./utils/strings');
|
||||
require('./utils/urlBuilder');
|
||||
|
||||
require('./resources/frontendResource');
|
||||
require('./resources/taskResource');
|
||||
require('./resources/nodeResource');
|
||||
require('./resources/monitoringResource');
|
||||
|
|
31
server/resources/frontendResource.js
Normal file
31
server/resources/frontendResource.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng').factory('FrontendResource', function (
|
||||
Logger,
|
||||
Resources,
|
||||
ErrorTypes,
|
||||
fs
|
||||
) {
|
||||
var indexHtml = __dirname + '/../../client/index.html';
|
||||
|
||||
return {
|
||||
render: function (req, res) {
|
||||
var data = Resources.getData(req);
|
||||
|
||||
fs.readFile(indexHtml, 'utf8', function (err, body) {
|
||||
if (err) {
|
||||
Logger.tag('frontend').error('Could not read file: ', indexHtml, err);
|
||||
return Resources.error(res, {data: 'Internal error.', type: ErrorTypes.internalError});
|
||||
}
|
||||
|
||||
return Resources.successHtml(
|
||||
res,
|
||||
body.replace(
|
||||
/<body/,
|
||||
'<script>window.__nodeToken = \''+ data.token + '\';</script><body'
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -2,12 +2,15 @@
|
|||
|
||||
angular.module('ffffng').factory('Router', function (
|
||||
app,
|
||||
FrontendResource,
|
||||
NodeResource,
|
||||
MonitoringResource,
|
||||
TaskResource
|
||||
) {
|
||||
return {
|
||||
init: function () {
|
||||
app.post('/', FrontendResource.render);
|
||||
|
||||
app.post('/api/node', NodeResource.create);
|
||||
app.put('/api/node/:token', NodeResource.update);
|
||||
app.delete('/api/node/:token', NodeResource.delete);
|
||||
|
|
|
@ -212,7 +212,10 @@ angular.module('ffffng')
|
|||
}
|
||||
|
||||
_.each(entries, function (value, key) {
|
||||
if (key === 'monitoring') {
|
||||
if (key === 'mac') {
|
||||
node['mac'] = value;
|
||||
node['mapId'] = _.toLower(value).replace(/:/g, '')
|
||||
} else if (key === 'monitoring') {
|
||||
var active = value === 'aktiv';
|
||||
var pending = value === 'pending';
|
||||
node.monitoring = active || pending;
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng')
|
||||
.factory('config', function () {
|
||||
return <%= JSON.stringify(config) %>;
|
||||
});
|
||||
angular.module('ffffng').constant('config', <%= JSON.stringify(config) %>);
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng').factory('Resources', function (_, Constraints, Validator, ErrorTypes) {
|
||||
function respond(res, httpCode, data) {
|
||||
res.writeHead(httpCode, {'Content-Type': 'application/json'});
|
||||
res.end(JSON.stringify(data));
|
||||
function respond(res, httpCode, data, type) {
|
||||
switch (type) {
|
||||
case 'html':
|
||||
res.writeHead(httpCode, {'Content-Type': 'text/html'});
|
||||
res.end(data);
|
||||
break;
|
||||
|
||||
default:
|
||||
res.writeHead(httpCode, {'Content-Type': 'application/json'});
|
||||
res.end(JSON.stringify(data));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -84,11 +93,15 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato
|
|||
},
|
||||
|
||||
success: function (res, data) {
|
||||
respond(res, 200, data);
|
||||
respond(res, 200, data, 'json');
|
||||
},
|
||||
|
||||
successHtml: function (res, html) {
|
||||
respond(res, 200, html, 'html');
|
||||
},
|
||||
|
||||
error: function (res, err) {
|
||||
respond(res, err.type.code, err.data);
|
||||
respond(res, err.type.code, err.data, 'json');
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue