diff --git a/admin/index.html b/admin/index.html index 1f42b55..ee281ea 100644 --- a/admin/index.html +++ b/admin/index.html @@ -43,6 +43,7 @@ - + + diff --git a/admin/js/config.js b/admin/js/main.js similarity index 90% rename from admin/js/config.js rename to admin/js/main.js index 432c808..774e5f9 100644 --- a/admin/js/config.js +++ b/admin/js/main.js @@ -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 '' + ''), ]) - .listActions([ - 'edit', - 'delete' - ]) + .listActions( + ' ' + + ' ' + + '
' + + '' + + '' + + '
' + + ' Map' + ) ; nodes diff --git a/app/scripts/controllers/updateNodeCtrl.js b/app/scripts/controllers/updateNodeCtrl.js index a84b1c5..21d38b7 100644 --- a/app/scripts/controllers/updateNodeCtrl.js +++ b/app/scripts/controllers/updateNodeCtrl.js @@ -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); + } }); diff --git a/client b/client new file mode 120000 index 0000000..7a0b7f0 --- /dev/null +++ b/client @@ -0,0 +1 @@ +app \ No newline at end of file diff --git a/server/app.js b/server/app.js index 10dbbc2..1fac098 100644 --- a/server/app.js +++ b/server/app.js @@ -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'; diff --git a/server/config.js b/server/config.js index c28c773..847ab80 100644 --- a/server/config.js +++ b/server/config.js @@ -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); diff --git a/server/main.js b/server/main.js index a72c23f..46200d7 100644 --- a/server/main.js +++ b/server/main.js @@ -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'); diff --git a/server/resources/frontendResource.js b/server/resources/frontendResource.js new file mode 100644 index 0000000..4f4161a --- /dev/null +++ b/server/resources/frontendResource.js @@ -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( + /window.__nodeToken = \''+ data.token + '\';; -}); +angular.module('ffffng').constant('config', <%= JSON.stringify(config) %>); diff --git a/server/utils/resources.js b/server/utils/resources.js index 9230869..a9a9669 100644 --- a/server/utils/resources.js +++ b/server/utils/resources.js @@ -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'); } }; });