Open node in form and map.

This commit is contained in:
baldo 2016-06-07 14:08:04 +02:00
parent 5b9d2e615b
commit 03083b819b
12 changed files with 80 additions and 19 deletions

View file

@ -43,6 +43,7 @@
<script src="js/app.js"></script>
<script src="js/validation/constraints.js"></script>
<script src="js/views/taskActionButton.js"></script>
<script src="js/config.js"></script>
<script src="js/main.js"></script>
<script src="/config.js"></script>
</body>
</html>

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, RestangularProvider, Constraints) {
angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, RestangularProvider, Constraints, config) {
RestangularProvider.addFullRequestInterceptor(function(element, operation, what, url, headers, params) {
if (operation === 'getList') {
if (params._filters) {
@ -92,10 +92,16 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest
'<input type="text" ng-model="value" placeholder="Search" class="form-control"></input>' +
'<span class="input-group-addon"><i class="fa fa-search"></i></span></div>'),
])
.listActions([
'edit',
'delete'
])
.listActions(
'<ma-edit-button entry="entry" entity="entity" size="sm"></ma-edit-button> ' +
'<ma-delete-button entry="entry" entity="entity" size="sm"></ma-delete-button> ' +
'<form style="display: inline-block" action="/#!/update" method="POST" target="_blank">' +
'<input type="hidden" name="token" value="{{entry.values.token}}"/>' +
'<button class="btn btn-primary btn-sm" type="submit"><i class="fa fa-external-link"></i> Open</button>' +
'</form> ' +
'<a class="btn btn-success btn-sm" href="' + config.map.mapUrl +
'/#!v:m;n:{{entry.values.mapId}}" target="_blank"><i class="fa fa-map-o"></i> Map</a>'
)
;
nodes

View file

@ -31,4 +31,10 @@ angular.module('ffffng')
$scope.cancel = function () {
Navigator.home();
};
if (window.__nodeToken) {
var token = window.__nodeToken;
window.__nodeToken = undefined;
$scope.onSubmitToken(token);
}
});

1
client Symbolic link
View file

@ -0,0 +1 @@
app

View file

@ -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';

View file

@ -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);

View file

@ -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');

View 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'
)
);
});
}
};
});

View file

@ -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);

View file

@ -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;

View file

@ -1,6 +1,3 @@
'use strict';
angular.module('ffffng')
.factory('config', function () {
return <%= JSON.stringify(config) %>;
});
angular.module('ffffng').constant('config', <%= JSON.stringify(config) %>);

View file

@ -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');
}
};
});