support import/export config
Change-Id: Ia7802e8236ca2f90b97331961b9cf205cbd521aa
This commit is contained in:
parent
34b610c12f
commit
f220bdd59f
|
@ -178,7 +178,7 @@ angular.module("kbWebApp").controller("AboutCtrl", function($scope, $http, $loca
|
|||
}, this.setLogNum = function(lognumber) {
|
||||
return logNum = lognumber;
|
||||
};
|
||||
}).service("showAlert", function($mdDialog) {
|
||||
}).service("showAlert", function($mdDialog, $q) {
|
||||
this.showAlert = function(words, ev) {
|
||||
var alert = $mdDialog.alert({
|
||||
title: "Attention",
|
||||
|
@ -188,5 +188,19 @@ angular.module("kbWebApp").controller("AboutCtrl", function($scope, $http, $loca
|
|||
$mdDialog.show(alert)["finally"](function() {
|
||||
alert = void 0;
|
||||
});
|
||||
}, this.showPrompt = function($scope, $event) {
|
||||
var deferred = $q.defer(), parentEl = angular.element(document.body);
|
||||
return $mdDialog.show({
|
||||
parent: parentEl,
|
||||
targetEvent: $event,
|
||||
template: '<md-dialog aria-label="List dialog"> <md-dialog-content class="md-dialog-content" role="document" tabIndex="-1"> <h2 class="md-title">Configuration Import</h2> <div class="md-dialog-content-body"> <p>Paste Json Format Configuration Below:</p> </div> <md-input-container md-no-float class="md-prompt-input-container"> <textarea ng-model="dialog.result" md-maxlength="" rows="5" md-select-on-focus="" placeholder="..."></textarea> </md-input-container> </md-dialog-content> <md-dialog-actions"> <md-button ng-click="cancel()" class="md-primary"> Cancel </md-button> <md-button ng-click="answer()" class="md-primary" style="float:right;"> Submit </md-button> </md-dialog-actions></md-dialog>',
|
||||
controller: function($scope, $mdDialog, kbCookie) {
|
||||
$scope.cancel = function() {
|
||||
$mdDialog.cancel(), deferred.reject();
|
||||
}, $scope.answer = function() {
|
||||
kbCookie.setConfig(angular.fromJson($scope.dialog.result)), $mdDialog.hide(), deferred.resolve();
|
||||
};
|
||||
}
|
||||
}), deferred.promise;
|
||||
};
|
||||
});
|
|
@ -32,6 +32,14 @@ angular.module("kbWebApp").controller("ConfigCtrl", function($scope, $http, $loc
|
|||
function reset() {
|
||||
$scope.selectedA = [], $scope.selectedB = [], $scope.selectedC = [], $scope.toggle = !1;
|
||||
}
|
||||
function downloadFile(fileName, content) {
|
||||
var aLink = document.createElement("a"), blob = new Blob([ content ]), evt = document.createEvent("HTMLEvents");
|
||||
evt.initEvent("click", !1, !1), aLink.download = fileName, aLink.href = URL.createObjectURL(blob),
|
||||
aLink.dispatchEvent(evt);
|
||||
}
|
||||
function to2(num) {
|
||||
return 10 > num ? "0" + num : 99 > num ? "" + num : -1;
|
||||
}
|
||||
this.awesomeThings = [ "HTML5 Boilerplate", "AngularJS", "Karma" ], "" === kbCookie.getSessionID() ? $location.path("/Login") : kbCookie.checkMode("http"),
|
||||
$(window).on("hashchange", locationChange.change()), $scope.sessionID = kbCookie.getSessionID(),
|
||||
$scope.status = kbCookie.getStatus(), $scope.dashstatus1 = "active", $scope.dashstatus1vis = !0,
|
||||
|
@ -209,5 +217,14 @@ angular.module("kbWebApp").controller("ConfigCtrl", function($scope, $http, $loc
|
|||
clients_rack: ""
|
||||
}), init(), $scope.getTopology()) : 3 == $scope.availability_zone && ($scope.config.server.availability_zone = "",
|
||||
$scope.config.client.availability_zone = "");
|
||||
}, $scope["import"] = function() {
|
||||
showAlert.showPrompt($scope).then(function(response) {
|
||||
$scope.config = kbCookie.getConfig(), "READY" !== $scope.status && "STAGED" !== $scope.status && "" !== $scope.status || $scope.changeConfig(),
|
||||
console.log("import config");
|
||||
}, function(response) {});
|
||||
}, $scope["export"] = function() {
|
||||
"READY" !== $scope.status && "STAGED" !== $scope.status && "" !== $scope.status || $scope.changeConfig();
|
||||
var date = new Date(), m = to2(date.getMonth() + 1), d = to2(date.getDate()), h = to2(date.getHours()), min = to2(date.getMinutes()), filename = "ConfigFile" + m + d + h + min + ".json", myresult = JSON.stringify(kbCookie.getConfig(), null, " ");
|
||||
downloadFile(filename, myresult);
|
||||
};
|
||||
});
|
|
@ -17,6 +17,14 @@ permissions and limitations under the License.
|
|||
"use strict";
|
||||
|
||||
angular.module("kbWebApp").controller("StorageConfigCtrl", function($scope, $http, $location, showAlert, kbHttp, kbCookie, locationChange) {
|
||||
function downloadFile(fileName, content) {
|
||||
var aLink = document.createElement("a"), blob = new Blob([ content ]), evt = document.createEvent("HTMLEvents");
|
||||
evt.initEvent("click", !1, !1), aLink.download = fileName, aLink.href = URL.createObjectURL(blob),
|
||||
aLink.dispatchEvent(evt);
|
||||
}
|
||||
function to2(num) {
|
||||
return 10 > num ? "0" + num : 99 > num ? "" + num : -1;
|
||||
}
|
||||
this.awesomeThings = [ "HTML5 Boilerplate", "AngularJS", "Karma" ], "" === kbCookie.getSessionID() ? $location.path("/Login") : kbCookie.checkMode("storage"),
|
||||
$(window).on("hashchange", locationChange.change()), $scope.sessionID = kbCookie.getSessionID(),
|
||||
$scope.status = kbCookie.getStatus(), $scope.dash1status1 = "active", $scope.dash1status1vis = !0,
|
||||
|
@ -140,18 +148,25 @@ angular.module("kbWebApp").controller("StorageConfigCtrl", function($scope, $htt
|
|||
console.log("get running config error:"), console.log(response);
|
||||
});
|
||||
}, $scope.getRunConfig(), $scope.changeConfig = function() {
|
||||
"READY" === $scope.status || "" === $scope.status ? 1 == $scope.server.$valid && 1 == $scope.general.$valid ? (kbCookie.setConfig($scope.config),
|
||||
"READY" === $scope.status || "STAGED" === $scope.status || "" === $scope.status ? 1 == $scope.server.$valid && 1 == $scope.general.$valid ? (kbCookie.setConfig($scope.config),
|
||||
$scope.chaCon = {
|
||||
kb_cfg: {},
|
||||
topo_cfg: {}
|
||||
}, $scope.chaCon.kb_cfg = kbCookie.getConfig(), kbCookie.setTopology({
|
||||
servers_rack: "",
|
||||
clients_rack: ""
|
||||
}), $scope.chaCon.topo_cfg = kbCookie.getTopology(), $scope.config.server.availability_zone = "",
|
||||
$scope.config.client.availability_zone = "", console.log($scope.chaCon), kbHttp.putMethod("/config/running_config/" + $scope.sessionID, $scope.chaCon).then(function(response) {
|
||||
}, $scope.chaCon.kb_cfg = kbCookie.getConfig(), $scope.chaCon.topo_cfg = kbCookie.getTopology(),
|
||||
$scope.config.server.availability_zone = "", $scope.config.client.availability_zone = "",
|
||||
console.log($scope.chaCon), kbHttp.putMethod("/config/running_config/" + $scope.sessionID, $scope.chaCon).then(function(response) {
|
||||
console.log("change running config");
|
||||
}, function(response) {
|
||||
showAlert.showAlert("Failed to update configuration!");
|
||||
})) : showAlert.showAlert("Please check your inputs!") : showAlert.showAlert("Configuration cannot be changed now!");
|
||||
}, $scope["import"] = function() {
|
||||
showAlert.showPrompt($scope).then(function(response) {
|
||||
$scope.config = kbCookie.getConfig(), "READY" !== $scope.status && "STAGED" !== $scope.status && "" !== $scope.status || $scope.changeConfig(),
|
||||
console.log("import config");
|
||||
}, function(response) {});
|
||||
}, $scope["export"] = function() {
|
||||
"READY" !== $scope.status && "STAGED" !== $scope.status && "" !== $scope.status || $scope.changeConfig();
|
||||
var date = new Date(), m = to2(date.getMonth() + 1), d = to2(date.getDate()), h = to2(date.getHours()), min = to2(date.getMinutes()), filename = "ConfigFile" + m + d + h + min + ".json", myresult = JSON.stringify(kbCookie.getConfig(), null, " ");
|
||||
downloadFile(filename, myresult);
|
||||
};
|
||||
});
|
|
@ -17,6 +17,15 @@ permissions and limitations under the License.
|
|||
<div class="md-padding dialogdemoBasicUsage" id="popupContainer" ng-cloak=""></div>
|
||||
<div class="row">
|
||||
<div style="float:right;padding:1px 30px" id="getButton">
|
||||
<div class="btn-group">
|
||||
<a href="" class="btn btn-default btn-sm" style="width:80px">Action</a>
|
||||
<a href="" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="" ng-click="import()">Import</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="" ng-click="export()">Export</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<input type="button" value="Default/Reset" class="btn btn-default btn-sm" ng-click="getDefaultConfig()" style="width:110px">
|
||||
<input type="button" value="Save" class="btn btn-primary btn-sm" ng-click="changeConfig()" style="width:80px">
|
||||
</div>
|
||||
|
|
|
@ -17,6 +17,15 @@ permissions and limitations under the License.
|
|||
<div class="md-padding dialogdemoBasicUsage" id="popupContainer" ng-cloak=""></div>
|
||||
<div class="row">
|
||||
<div style="float:right;padding:1px 30px" id="getButton">
|
||||
<div class="btn-group">
|
||||
<a href="" class="btn btn-default btn-sm" style="width:80px">Action</a>
|
||||
<a href="" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="" ng-click="import()">Import</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="" ng-click="export()">Export</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<input type="button" value="Default/Reset" class="btn btn-default btn-sm" ng-click="getDefaultConfig()" style="width:110px">
|
||||
<input type="button" value="Save" class="btn btn-primary btn-sm" ng-click="changeConfig()" style="width:80px" ng-disabled="general.$pristine && server.$pristine">
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue