diff --git a/admin/index.html b/admin/index.html index 44a32fe..9caa5c3 100644 --- a/admin/index.html +++ b/admin/index.html @@ -74,6 +74,7 @@ + diff --git a/admin/js/main.js b/admin/js/main.js index c80f839..fb2a5c7 100644 --- a/admin/js/main.js +++ b/admin/js/main.js @@ -38,6 +38,23 @@ angular.module('ffffngAdmin').config(function(NgAdminConfigurationProvider, Rest var admin = nga.application('Knotenverwaltung - Admin-Panel'); admin + .header( + '' + + '' + + '' + ) .baseApiUrl('/internal/api/') .debug(true); diff --git a/admin/js/views/version.js b/admin/js/views/version.js new file mode 100644 index 0000000..66a5ced --- /dev/null +++ b/admin/js/views/version.js @@ -0,0 +1,22 @@ +'use strict'; + +angular.module('ffffngAdmin') +.directive('faVersion', function ($http, $state, notification) { + var link = function (scope) { + scope.version = '?'; + $http.get('/internal/api/version') + .then(function (result) { scope.version = result.data.version; }) + .catch(function (e) { + notification.log('Error: ' + e.data, { addnCls: 'humane-flatty-error' }); + console.error(e); + }); + }; + + return { + 'link': link, + 'restrict': 'E', + 'scope': {}, + + 'template': '{{version}}' + }; +}); diff --git a/server/config.js b/server/config.js index b489a6f..62ee662 100644 --- a/server/config.js +++ b/server/config.js @@ -5,7 +5,8 @@ var commandLineUsage = require('command-line-usage'); var commandLineDefs = [ { name: 'help', alias: 'h', type: Boolean, description: 'Show this help' }, - { name: 'config', alias: 'c', type: String, description: 'Location of config.json' } + { name: 'config', alias: 'c', type: String, description: 'Location of config.json' }, + { name: 'version', alias: 'v', type: Boolean, description: 'Show ffffng version' } ]; var commandLineOptions; @@ -17,18 +18,38 @@ try { process.exit(1); } -if (commandLineOptions.help || !commandLineOptions.config) { +var fs = require('graceful-fs'); + +var packageJsonFile = __dirname + '/../package.json'; +var version = 'unknown'; +if (fs.existsSync(packageJsonFile)) { + version = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8')).version; +} + +function usage() { console.log(commandLineUsage([ { - header: 'ffffng - Freifunk node management form', + header: 'ffffng - ' + version + ' - Freifunk node management form', optionList: commandLineDefs } ])); +} + +if (commandLineOptions.help) { + usage(); + process.exit(0); +} + +if (commandLineOptions.version) { + console.log('ffffng - ' + version); + process.exit(0); +} + +if (!commandLineOptions.config) { + usage(); process.exit(1); } - -var fs = require('graceful-fs'); var deepExtend = require('deep-extend'); var defaultConfig = { @@ -108,3 +129,4 @@ var config = deepExtend({}, defaultConfig, configJSON); module.exports = config; angular.module('ffffng').constant('config', config); +angular.module('ffffng').constant('version', version); diff --git a/server/main.js b/server/main.js index 3c18306..7c59750 100755 --- a/server/main.js +++ b/server/main.js @@ -28,6 +28,7 @@ require('./utils/resources'); require('./utils/strings'); require('./utils/urlBuilder'); +require('./resources/versionResource'); require('./resources/frontendResource'); require('./resources/taskResource'); require('./resources/mailResource'); diff --git a/server/resources/versionResource.js b/server/resources/versionResource.js new file mode 100644 index 0000000..0cf47be --- /dev/null +++ b/server/resources/versionResource.js @@ -0,0 +1,17 @@ +'use strict'; + +angular.module('ffffng').factory('VersionResource', function ( + version, + Resources +) { + return { + get: function (req, res) { + return Resources.success( + res, + { + version: version + } + ); + } + }; +}); diff --git a/server/router.js b/server/router.js index 9a64773..1fbeeb0 100644 --- a/server/router.js +++ b/server/router.js @@ -2,6 +2,7 @@ angular.module('ffffng').factory('Router', function ( app, + VersionResource, FrontendResource, NodeResource, MonitoringResource, @@ -20,6 +21,8 @@ angular.module('ffffng').factory('Router', function ( app.put('/api/monitoring/confirm/:token', MonitoringResource.confirm); app.put('/api/monitoring/disable/:token', MonitoringResource.disable); + app.get('/internal/api/version', VersionResource.get); + app.get('/internal/api/tasks', TaskResource.getAll); app.put('/internal/api/tasks/run/:id', TaskResource.run); app.put('/internal/api/tasks/enable/:id', TaskResource.enable);