From adeccde0b49351c1023aa25f078e59e5ab6b6a7f Mon Sep 17 00:00:00 2001 From: maria Date: Sun, 25 Oct 2015 14:39:21 +0100 Subject: [PATCH] Issue #9: get ip addresses automatically more code for ip registration ui --- src/index.html | 11 +--- src/js/controllers/dialog.js | 82 +++++++++++++--------------- src/js/controllers/wizard.js | 42 +++++++------- src/nls/locale-en.json | 21 ++++++- src/view/partials/dialog/dialog.html | 51 +++++++++++------ 5 files changed, 114 insertions(+), 93 deletions(-) diff --git a/src/index.html b/src/index.html index 262dd70..19df382 100644 --- a/src/index.html +++ b/src/index.html @@ -56,7 +56,7 @@

+ class="form-horizontal wizard-categories" ng-submit="processForm()">
@@ -776,15 +776,10 @@

{{ 'configIncorrect' | translate }} - - - -

diff --git a/src/js/controllers/dialog.js b/src/js/controllers/dialog.js index a274286..bc3f752 100644 --- a/src/js/controllers/dialog.js +++ b/src/js/controllers/dialog.js @@ -2,74 +2,53 @@ module.exports = function(app) { app.controller('DialogController', - function($scope, $modalInstance, state, wizard, $interval, $http) { - - console.log(state); - + function($scope, $modalInstance, state, wizard, $interval, $http, $translate, downloadFile, $filter) { $scope.state = state; $scope.wizard = wizard; $scope.state.registerips = { - max: 4, - progress: 0 + progress: { + reserved: 'notStarted', + keyEntered: 'notStarted', + confirmed: 'notStarted', + configWritten: 'notStarted' + }, + steps: 0, }; $scope.state.generatevpn = { max: 4, progress: 0 }; + $scope.getObjectKeys = function(scopeObject) { + return Object.keys(scopeObject); + } + $scope.reserveIPs = function() { - //call register ips + //TODO call register ips $http.get('/nls/locale-de.json').then(function(response) { //success callback - //TODO handle error in response - //render confirmation code field - $scope.state.registerips.reserved = true; - $scope.state.registerips.message = { - type:'info', - value: 'success.reserveip' - } - $scope.state.registerips.progress++; + $scope.state.registerips.progress.reserved = 'success'; + $scope.state.registerips.steps++; }, function(response){ //error callback console.log(response); - $scope.state.registerips.message = { - type:'error', - value: 'error.reserveip' - } + $scope.state.registerips.progress.reserved = 'error'; }); - - //just some testcode - /*$interval(function() { - if ($scope.state.registerips.progress < - $scope.state.registerips.max) { - $scope.state.registerips.progress++; - } - },3500,$scope.state.registerips.max);*/ }; //check confirmation code $scope.confirmIPs = function() { - $scope.state.registerips.progress++; + $scope.state.registerips.steps++; + $scope.state.registerips.progress.keyEntered = 'success' $http.get('gibs/nich.html').then( function(response) { //succuess callback - - //TODO check for error in response - - $scope.state.registerips.progress++; - - $scope.state.registerips.message = { - type:'success', - value: 'success.reserveip' - } - //write ips to wizard config + $scope.state.registerips.steps++; + $scope.state.registerips.progress.confirmed = 'success' + //TODO write ips to wizard config }, function(response) { //error callback - console.log(response); - $scope.state.registerips.message = { - type:'error', - value: 'error.confirmip' - } + $scope.state.registerips.progress.confirmed = 'error' } ); } @@ -96,18 +75,33 @@ module.exports = function(app) { // show download cert and key tar file button or but everything in the "Download Config"? }; + $scope.downloadConfig = function() { + downloadFile( + 'config.json', + $filter('json')($scope.wizard), + 'application/json', + true + ); + }; + + //return wizard and state back to parent controller $scope.ok = function() { - $modalInstance.close($scope.selected.item); + $modalInstance.close({ + "wizard": $scope.wizard, + "state": $scope.state + }); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; + //show ip registration processing if ($scope.state.ip.register) { $scope.reserveIPs(); } + //show vpn files generation process if ($scope.wizard.internet.share && $scope.state.internet.vpn03.generate) { $scope.generateVPN03CertAndKey(); diff --git a/src/js/controllers/wizard.js b/src/js/controllers/wizard.js index c1abae5..d5ac953 100644 --- a/src/js/controllers/wizard.js +++ b/src/js/controllers/wizard.js @@ -288,31 +288,29 @@ module.exports = function(app) { }; }; - $scope.downloadConfig = function() { - downloadFile( - 'config.json', - $filter('json')($scope.wizard), - 'application/json', - true - ); - }; - $scope.pow = Math.pow; - //TODO open dialog on submit if there are no errors - $scope.open = function() { - var modalInstance = $uibModal.open({ - templateUrl: '/view/partials/dialog/dialog.html', - controller: 'DialogController', - resolve: { - state: function() { - return $scope.state; - }, - wizard: function() { - return $scope.wizard; + $scope.processForm = function() { + if(!$scope.wizardForm.$invalid) { + var modalInstance = $uibModal.open({ + templateUrl: '/view/partials/dialog/dialog.html', + controller: 'DialogController', + resolve: { + state: function() { + return $scope.state; + }, + wizard: function() { + return $scope.wizard; + } } - } - }); + }); + + //handle wizard and state from dialog + modalInstance.result.then(function(returnData) { + console.log(returnData.wizard); + console.log(returnData.state); + }); + } }; } ]); diff --git a/src/nls/locale-en.json b/src/nls/locale-en.json index d113cdb..dbdeaad 100644 --- a/src/nls/locale-en.json +++ b/src/nls/locale-en.json @@ -169,6 +169,23 @@ } }, "configIncorrect": "The data you entered is invalid. Please correct them before saving.", - "save": "Save & Restart", - "download": "Download configuration" + "processData": { + "start": "Process data", + "finished": "Your data was process successfully. Click the reboot button to become a Freifunka.", + "headline": "Process Data", + "registerIPs": { + "headline": "Register IPs", + "reserved": "Reserve IPs", + "keyEntered": "Enter confirmation key", + "confirmed": "Confirm IPs", + "configWritten": "Write IPs to configuration", + "confirmKey": { + "label": "Confirmation Key", + "submit": "Enter" + } + }, + "reboot": "Save & Reboot", + "cancel": "Cancel", + "download": "Download configuration" + } } diff --git a/src/view/partials/dialog/dialog.html b/src/view/partials/dialog/dialog.html index da9519d..c0fd104 100644 --- a/src/view/partials/dialog/dialog.html +++ b/src/view/partials/dialog/dialog.html @@ -1,25 +1,41 @@ -