|
@@ -18,402 +18,412 @@
|
|
|
'use strict';
|
|
|
|
|
|
angular.module('ambariAdminConsole')
|
|
|
-.controller('ViewsEditCtrl', ['$scope', '$routeParams' , 'Cluster', 'View', 'Alert', 'PermissionLoader', 'PermissionSaver', 'ConfirmationModal', '$location', 'UnsavedDialog', '$translate', function($scope, $routeParams, Cluster, View, Alert, PermissionLoader, PermissionSaver, ConfirmationModal, $location, UnsavedDialog, $translate) {
|
|
|
- var $t = $translate.instant;
|
|
|
- $scope.identity = angular.identity;
|
|
|
- $scope.isConfigurationEmpty = true;
|
|
|
- $scope.isSettingsEmpty = true;
|
|
|
- $scope.constants = {
|
|
|
- instance: $t('views.instance'),
|
|
|
- props: $t('views.properties'),
|
|
|
- perms: $t('views.permissions').toLowerCase()
|
|
|
- };
|
|
|
-
|
|
|
- function reloadViewInfo(section){
|
|
|
- // Load instance data, after View permissions meta loaded
|
|
|
- View.getInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId)
|
|
|
- .then(function(instance) {
|
|
|
- $scope.instance = instance;
|
|
|
- $scope.settings = {
|
|
|
- 'visible': $scope.instance.ViewInstanceInfo.visible,
|
|
|
- 'label': $scope.instance.ViewInstanceInfo.label,
|
|
|
- 'description': $scope.instance.ViewInstanceInfo.description,
|
|
|
- 'shortUrl': $scope.instance.ViewInstanceInfo.short_url
|
|
|
- };
|
|
|
- switch (section) {
|
|
|
- case "details" :
|
|
|
- initConfigurations();
|
|
|
- initCtrlVariables(instance);
|
|
|
- break;
|
|
|
- case "settings" :
|
|
|
- initConfigurations(true);
|
|
|
- break;
|
|
|
- case "cluster" :
|
|
|
- initCtrlVariables(instance);
|
|
|
- break;
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(function(data) {
|
|
|
- Alert.error($t('views.alerts.cannotLoadInstanceInfo'), data.data.message);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- function initCtrlVariables(instance) {
|
|
|
- if(instance.ViewInstanceInfo.cluster_handle) {
|
|
|
- $scope.isLocalCluster = true;
|
|
|
- $scope.cluster = instance.ViewInstanceInfo.cluster_handle;
|
|
|
- }else{
|
|
|
- $scope.isLocalCluster = false;
|
|
|
- $scope.cluster = $scope.clusters.length > 0 ? $scope.clusters[0] : $t('common.noClusters');
|
|
|
- }
|
|
|
- $scope.originalLocalCluster = $scope.isLocalCluster;
|
|
|
- $scope.isConfigurationEmpty = !$scope.numberOfClusterConfigs;
|
|
|
- $scope.isSettingsEmpty = !$scope.numberOfSettingsConfigs;
|
|
|
- }
|
|
|
-
|
|
|
- function isClusterConfig(name) {
|
|
|
- var configurationMeta = $scope.configurationMeta;
|
|
|
- var clusterConfigs = configurationMeta.filter(function(el) {
|
|
|
- return el.clusterConfig;
|
|
|
- }).map(function(el) {
|
|
|
- return el.name;
|
|
|
- });
|
|
|
- return clusterConfigs.indexOf(name) !== -1;
|
|
|
- }
|
|
|
-
|
|
|
- function initConfigurations(initClusterConfig) {
|
|
|
- var initAllConfigs = !initClusterConfig;
|
|
|
- var configuration = angular.copy($scope.instance.ViewInstanceInfo.properties);
|
|
|
- if (initAllConfigs) {
|
|
|
- $scope.configuration = angular.copy($scope.instance.ViewInstanceInfo.properties);
|
|
|
+ .controller('ViewsEditCtrl', ['$scope', '$routeParams' , 'Cluster', 'View', 'Alert', 'PermissionLoader', 'PermissionSaver', 'ConfirmationModal', '$location', 'UnsavedDialog', '$translate', function($scope, $routeParams, Cluster, View, Alert, PermissionLoader, PermissionSaver, ConfirmationModal, $location, UnsavedDialog, $translate) {
|
|
|
+ var $t = $translate.instant;
|
|
|
+ $scope.identity = angular.identity;
|
|
|
+ $scope.isConfigurationEmpty = true;
|
|
|
+ $scope.isSettingsEmpty = true;
|
|
|
+ $scope.clusterInheritedPermissionKeys = View.clusterInheritedPermissionKeys;
|
|
|
+ $scope.constants = {
|
|
|
+ instance: $t('views.instance'),
|
|
|
+ props: $t('views.properties'),
|
|
|
+ perms: $t('views.permissions').toLowerCase()
|
|
|
+ };
|
|
|
+
|
|
|
+ function reloadViewInfo(section){
|
|
|
+ // Load instance data, after View permissions meta loaded
|
|
|
+ View.getInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId)
|
|
|
+ .then(function(instance) {
|
|
|
+ $scope.instance = instance;
|
|
|
+ $scope.settings = {
|
|
|
+ 'visible': $scope.instance.ViewInstanceInfo.visible,
|
|
|
+ 'label': $scope.instance.ViewInstanceInfo.label,
|
|
|
+ 'description': $scope.instance.ViewInstanceInfo.description,
|
|
|
+ 'shortUrl': $scope.instance.ViewInstanceInfo.short_url
|
|
|
+ };
|
|
|
+ switch (section) {
|
|
|
+ case "details" :
|
|
|
+ initConfigurations();
|
|
|
+ initCtrlVariables(instance);
|
|
|
+ break;
|
|
|
+ case "settings" :
|
|
|
+ initConfigurations(true);
|
|
|
+ break;
|
|
|
+ case "cluster" :
|
|
|
+ initCtrlVariables(instance);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function(data) {
|
|
|
+ Alert.error($t('views.alerts.cannotLoadInstanceInfo'), data.data.message);
|
|
|
+ });
|
|
|
}
|
|
|
- for (var confName in configuration) {
|
|
|
- if (configuration.hasOwnProperty(confName)) {
|
|
|
- if (!isClusterConfig(confName) || initAllConfigs) {
|
|
|
- $scope.configuration[confName] = configuration[confName] === 'null' ? '' : configuration[confName];
|
|
|
- }
|
|
|
+
|
|
|
+ function initCtrlVariables(instance) {
|
|
|
+ if(instance.ViewInstanceInfo.cluster_handle) {
|
|
|
+ $scope.isLocalCluster = true;
|
|
|
+ $scope.cluster = instance.ViewInstanceInfo.cluster_handle;
|
|
|
+ }else{
|
|
|
+ $scope.isLocalCluster = false;
|
|
|
+ $scope.cluster = $scope.clusters.length > 0 ? $scope.clusters[0] : $t('common.noClusters');
|
|
|
}
|
|
|
+ $scope.originalLocalCluster = $scope.isLocalCluster;
|
|
|
+ $scope.isConfigurationEmpty = !$scope.numberOfClusterConfigs;
|
|
|
+ $scope.isSettingsEmpty = !$scope.numberOfSettingsConfigs;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- function filterClusterConfigs() {
|
|
|
- $scope.configurationMeta.forEach(function (element) {
|
|
|
- if (element.masked && !$scope.editConfigurationDisabled && element.clusterConfig && !$scope.isLocalCluster) {
|
|
|
- $scope.configuration[element.name] = '';
|
|
|
- }
|
|
|
- if(!element.clusterConfig) {
|
|
|
- delete $scope.configurationBeforeEdit[element.name];
|
|
|
+ function isClusterConfig(name) {
|
|
|
+ var configurationMeta = $scope.configurationMeta;
|
|
|
+ var clusterConfigs = configurationMeta.filter(function(el) {
|
|
|
+ return el.clusterConfig;
|
|
|
+ }).map(function(el) {
|
|
|
+ return el.name;
|
|
|
+ });
|
|
|
+ return clusterConfigs.indexOf(name) !== -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ function initConfigurations(initClusterConfig) {
|
|
|
+ var initAllConfigs = !initClusterConfig;
|
|
|
+ var configuration = angular.copy($scope.instance.ViewInstanceInfo.properties);
|
|
|
+ if (initAllConfigs) {
|
|
|
+ $scope.configuration = angular.copy($scope.instance.ViewInstanceInfo.properties);
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Get META for properties
|
|
|
- View.getMeta($routeParams.viewId, $routeParams.version).then(function(data) {
|
|
|
- $scope.configurationMeta = data.data.ViewVersionInfo.parameters;
|
|
|
- $scope.clusterConfigurable = data.data.ViewVersionInfo.cluster_configurable;
|
|
|
- $scope.clusterConfigurableErrorMsg = $scope.clusterConfigurable ? "" : $t('views.alerts.cannotUseOption');
|
|
|
- angular.forEach($scope.configurationMeta, function (item) {
|
|
|
- item.displayName = item.name.replace(/\./g, '\.\u200B');
|
|
|
- item.clusterConfig = !!item.clusterConfig;
|
|
|
- if (!item.clusterConfig) {
|
|
|
- $scope.numberOfSettingsConfigs++;
|
|
|
+ for (var confName in configuration) {
|
|
|
+ if (configuration.hasOwnProperty(confName)) {
|
|
|
+ if (!isClusterConfig(confName) || initAllConfigs) {
|
|
|
+ $scope.configuration[confName] = configuration[confName] === 'null' ? '' : configuration[confName];
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- $scope.numberOfClusterConfigs = $scope.numberOfClusterConfigs + !!item.clusterConfig;
|
|
|
- });
|
|
|
- reloadViewInfo("details");
|
|
|
- });
|
|
|
-
|
|
|
- function reloadViewPrivileges(){
|
|
|
- PermissionLoader.getViewPermissions({
|
|
|
- viewName: $routeParams.viewId,
|
|
|
- version: $routeParams.version,
|
|
|
- instanceId: $routeParams.instanceId
|
|
|
- })
|
|
|
- .then(function(permissions) {
|
|
|
- // Refresh data for rendering
|
|
|
- $scope.permissionsEdit = permissions;
|
|
|
- $scope.permissions = angular.copy(permissions);
|
|
|
- $scope.isPermissionsEmpty = angular.equals({}, $scope.permissions);
|
|
|
- })
|
|
|
- .catch(function(data) {
|
|
|
- Alert.error($t('views.alerts.cannotLoadPermissions'), data.data.message);
|
|
|
- });
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- $scope.permissions = [];
|
|
|
+ function filterClusterConfigs() {
|
|
|
+ $scope.configurationMeta.forEach(function (element) {
|
|
|
+ if (element.masked && !$scope.editConfigurationDisabled && element.clusterConfig && !$scope.isLocalCluster) {
|
|
|
+ $scope.configuration[element.name] = '';
|
|
|
+ }
|
|
|
+ if(!element.clusterConfig) {
|
|
|
+ delete $scope.configurationBeforeEdit[element.name];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- reloadViewPrivileges();
|
|
|
+ // Get META for properties
|
|
|
+ View.getMeta($routeParams.viewId, $routeParams.version).then(function(data) {
|
|
|
+ $scope.configurationMeta = data.data.ViewVersionInfo.parameters;
|
|
|
+ $scope.clusterConfigurable = data.data.ViewVersionInfo.cluster_configurable;
|
|
|
+ $scope.clusterConfigurableErrorMsg = $scope.clusterConfigurable ? "" : $t('views.alerts.cannotUseOption');
|
|
|
+ angular.forEach($scope.configurationMeta, function (item) {
|
|
|
+ item.displayName = item.name.replace(/\./g, '\.\u200B');
|
|
|
+ item.clusterConfig = !!item.clusterConfig;
|
|
|
+ if (!item.clusterConfig) {
|
|
|
+ $scope.numberOfSettingsConfigs++;
|
|
|
+ }
|
|
|
+ $scope.numberOfClusterConfigs = $scope.numberOfClusterConfigs + !!item.clusterConfig;
|
|
|
+ });
|
|
|
+ reloadViewInfo("details");
|
|
|
+ });
|
|
|
|
|
|
- $scope.clusterConfigurable = false;
|
|
|
- $scope.clusterConfigurableErrorMsg = "";
|
|
|
- $scope.clusters = [];
|
|
|
- $scope.cluster = null;
|
|
|
- $scope.noClusterAvailible = true;
|
|
|
+ function reloadViewPrivileges(){
|
|
|
+ PermissionLoader.getViewPermissions({
|
|
|
+ viewName: $routeParams.viewId,
|
|
|
+ version: $routeParams.version,
|
|
|
+ instanceId: $routeParams.instanceId
|
|
|
+ })
|
|
|
+ .then(function(permissions) {
|
|
|
+ // Refresh data for rendering
|
|
|
+ $scope.permissionsEdit = permissions;
|
|
|
+ $scope.permissions = angular.copy(permissions);
|
|
|
+ $scope.isPermissionsEmpty = angular.equals({}, $scope.permissions);
|
|
|
+ })
|
|
|
+ .catch(function(data) {
|
|
|
+ Alert.error($t('views.alerts.cannotLoadPermissions'), data.data.message);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
+ $scope.permissions = [];
|
|
|
|
|
|
- $scope.editSettingsDisabled = true;
|
|
|
- $scope.editDetailsSettingsDisabled = true;
|
|
|
- $scope.numberOfClusterConfigs = 0;
|
|
|
- $scope.numberOfSettingsConfigs = 0;
|
|
|
+ reloadViewPrivileges();
|
|
|
|
|
|
- $scope.enableLocalCluster = function() {
|
|
|
- angular.extend($scope.configuration, $scope.configurationBeforeEdit);
|
|
|
- $scope.propertiesForm.$setPristine();
|
|
|
- };
|
|
|
+ $scope.clusterConfigurable = false;
|
|
|
+ $scope.clusterConfigurableErrorMsg = "";
|
|
|
+ $scope.clusters = [];
|
|
|
+ $scope.cluster = null;
|
|
|
+ $scope.noClusterAvailible = true;
|
|
|
|
|
|
- $scope.disableLocalCluster = function() {
|
|
|
- filterClusterConfigs();
|
|
|
- };
|
|
|
|
|
|
- $scope.toggleSettingsEdit = function() {
|
|
|
- $scope.editSettingsDisabled = !$scope.editSettingsDisabled;
|
|
|
- $scope.settingsBeforeEdit = angular.copy($scope.configuration);
|
|
|
- $scope.configurationMeta.forEach(function (element) {
|
|
|
- if (element.masked && !$scope.editSettingsDisabled && !element.clusterConfig) {
|
|
|
- $scope.configuration[element.name] = '';
|
|
|
- }
|
|
|
- if(element.clusterConfig) {
|
|
|
- delete $scope.settingsBeforeEdit[element.name];
|
|
|
- }
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
- $scope.toggleDetailsSettingsEdit = function() {
|
|
|
- $scope.editDetailsSettingsDisabled = !$scope.editDetailsSettingsDisabled;
|
|
|
- $scope.settingsBeforeEdit = angular.copy($scope.configuration);
|
|
|
- $scope.configurationMeta.forEach(function (element) {
|
|
|
- if (element.masked && !$scope.editDetailsSettingsDisabled && !element.clusterConfig) {
|
|
|
- $scope.configuration[element.name] = '';
|
|
|
- }
|
|
|
- if(element.clusterConfig) {
|
|
|
- delete $scope.settingsBeforeEdit[element.name];
|
|
|
- }
|
|
|
- });
|
|
|
- };
|
|
|
+ $scope.editSettingsDisabled = true;
|
|
|
+ $scope.editDetailsSettingsDisabled = true;
|
|
|
+ $scope.numberOfClusterConfigs = 0;
|
|
|
+ $scope.numberOfSettingsConfigs = 0;
|
|
|
|
|
|
- Cluster.getAllClusters().then(function (clusters) {
|
|
|
- if(clusters.length >0){
|
|
|
- clusters.forEach(function(cluster) {
|
|
|
- $scope.clusters.push(cluster.Clusters.cluster_name)
|
|
|
- });
|
|
|
- $scope.noClusterAvailible = false;
|
|
|
- }else{
|
|
|
- $scope.clusters.push($t('common.noClusters'));
|
|
|
- }
|
|
|
- $scope.cluster = $scope.clusters[0];
|
|
|
- });
|
|
|
+ $scope.enableLocalCluster = function() {
|
|
|
+ angular.extend($scope.configuration, $scope.configurationBeforeEdit);
|
|
|
+ $scope.propertiesForm.$setPristine();
|
|
|
+ };
|
|
|
|
|
|
+ $scope.disableLocalCluster = function() {
|
|
|
+ filterClusterConfigs();
|
|
|
+ };
|
|
|
|
|
|
- $scope.saveSettings = function(callback) {
|
|
|
- if( $scope.settingsForm.$valid ){
|
|
|
- var data = {
|
|
|
- 'ViewInstanceInfo':{
|
|
|
- 'properties':{}
|
|
|
- }
|
|
|
- };
|
|
|
+ $scope.toggleSettingsEdit = function() {
|
|
|
+ $scope.editSettingsDisabled = !$scope.editSettingsDisabled;
|
|
|
+ $scope.settingsBeforeEdit = angular.copy($scope.configuration);
|
|
|
$scope.configurationMeta.forEach(function (element) {
|
|
|
- if(!element.clusterConfig) {
|
|
|
- data.ViewInstanceInfo.properties[element.name] = $scope.configuration[element.name];
|
|
|
+ if (element.masked && !$scope.editSettingsDisabled && !element.clusterConfig) {
|
|
|
+ $scope.configuration[element.name] = '';
|
|
|
}
|
|
|
- });
|
|
|
- return View.updateInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId, data)
|
|
|
- .success(function() {
|
|
|
- if( callback ){
|
|
|
- callback();
|
|
|
- } else {
|
|
|
- reloadViewInfo("settings");
|
|
|
- $scope.editSettingsDisabled = true;
|
|
|
- $scope.settingsForm.$setPristine();
|
|
|
+ if(element.clusterConfig) {
|
|
|
+ delete $scope.settingsBeforeEdit[element.name];
|
|
|
}
|
|
|
- })
|
|
|
- .catch(function(data) {
|
|
|
- Alert.error($t('views.alerts.cannotSaveSettings'), data.data.message);
|
|
|
});
|
|
|
- }
|
|
|
- };
|
|
|
- $scope.cancelSettings = function() {
|
|
|
- angular.extend($scope.configuration, $scope.settingsBeforeEdit);
|
|
|
+ };
|
|
|
|
|
|
- $scope.editSettingsDisabled = true;
|
|
|
- $scope.settingsForm.$setPristine();
|
|
|
- };
|
|
|
-
|
|
|
- $scope.saveDetails = function(callback) {
|
|
|
- if( $scope.detailsForm.$valid ){
|
|
|
- var data = {
|
|
|
- 'ViewInstanceInfo':{
|
|
|
- 'visible': $scope.settings.visible,
|
|
|
- 'label': $scope.settings.label,
|
|
|
- 'description': $scope.settings.description
|
|
|
+ $scope.toggleDetailsSettingsEdit = function() {
|
|
|
+ $scope.editDetailsSettingsDisabled = !$scope.editDetailsSettingsDisabled;
|
|
|
+ $scope.settingsBeforeEdit = angular.copy($scope.configuration);
|
|
|
+ $scope.configurationMeta.forEach(function (element) {
|
|
|
+ if (element.masked && !$scope.editDetailsSettingsDisabled && !element.clusterConfig) {
|
|
|
+ $scope.configuration[element.name] = '';
|
|
|
}
|
|
|
- };
|
|
|
- return View.updateInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId, data)
|
|
|
- .success(function() {
|
|
|
- $scope.$root.$emit('instancesUpdate');
|
|
|
- if( callback ){
|
|
|
- callback();
|
|
|
- } else {
|
|
|
- reloadViewInfo("cluster");
|
|
|
- $scope.editDetailsSettingsDisabled = true;
|
|
|
- $scope.settingsForm.$setPristine();
|
|
|
+ if(element.clusterConfig) {
|
|
|
+ delete $scope.settingsBeforeEdit[element.name];
|
|
|
}
|
|
|
- })
|
|
|
- .catch(function(data) {
|
|
|
- Alert.error($t('views.alerts.cannotSaveSettings'), data.data.message);
|
|
|
});
|
|
|
- }
|
|
|
- };
|
|
|
- $scope.cancelDetails = function() {
|
|
|
- $scope.settings = {
|
|
|
- 'visible': $scope.instance.ViewInstanceInfo.visible,
|
|
|
- 'label': $scope.instance.ViewInstanceInfo.label,
|
|
|
- 'description': $scope.instance.ViewInstanceInfo.description,
|
|
|
- 'shortUrl': $scope.instance.ViewInstanceInfo.short_url
|
|
|
};
|
|
|
- $scope.editDetailsSettingsDisabled = true;
|
|
|
- $scope.settingsForm.$setPristine();
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- $scope.editConfigurationDisabled = true;
|
|
|
- $scope.togglePropertiesEditing = function () {
|
|
|
- $scope.editConfigurationDisabled = !$scope.editConfigurationDisabled;
|
|
|
- $scope.configurationBeforeEdit = angular.copy($scope.configuration);
|
|
|
- filterClusterConfigs();
|
|
|
- };
|
|
|
- $scope.saveConfiguration = function() {
|
|
|
- if( $scope.propertiesForm.$valid ){
|
|
|
- var data = {
|
|
|
- 'ViewInstanceInfo':{
|
|
|
- 'properties':{}
|
|
|
- }
|
|
|
- };
|
|
|
- if($scope.isLocalCluster) {
|
|
|
- data.ViewInstanceInfo.cluster_handle = $scope.cluster;
|
|
|
- } else {
|
|
|
- data.ViewInstanceInfo.cluster_handle = null;
|
|
|
+
|
|
|
+ Cluster.getAllClusters().then(function (clusters) {
|
|
|
+ if(clusters.length >0){
|
|
|
+ clusters.forEach(function(cluster) {
|
|
|
+ $scope.clusters.push(cluster.Clusters.cluster_name)
|
|
|
+ });
|
|
|
+ $scope.noClusterAvailible = false;
|
|
|
+ }else{
|
|
|
+ $scope.clusters.push($t('common.noClusters'));
|
|
|
+ }
|
|
|
+ $scope.cluster = $scope.clusters[0];
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ $scope.saveSettings = function(callback) {
|
|
|
+ if( $scope.settingsForm.$valid ){
|
|
|
+ var data = {
|
|
|
+ 'ViewInstanceInfo':{
|
|
|
+ 'properties':{}
|
|
|
+ }
|
|
|
+ };
|
|
|
$scope.configurationMeta.forEach(function (element) {
|
|
|
- if(element.clusterConfig) {
|
|
|
+ if(!element.clusterConfig) {
|
|
|
data.ViewInstanceInfo.properties[element.name] = $scope.configuration[element.name];
|
|
|
}
|
|
|
});
|
|
|
+ return View.updateInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId, data)
|
|
|
+ .success(function() {
|
|
|
+ if( callback ){
|
|
|
+ callback();
|
|
|
+ } else {
|
|
|
+ reloadViewInfo("settings");
|
|
|
+ $scope.editSettingsDisabled = true;
|
|
|
+ $scope.settingsForm.$setPristine();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function(data) {
|
|
|
+ Alert.error($t('views.alerts.cannotSaveSettings'), data.data.message);
|
|
|
+ });
|
|
|
}
|
|
|
- $scope.originalLocalCluster = $scope.isLocalCluster;
|
|
|
- return View.updateInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId, data)
|
|
|
- .success(function() {
|
|
|
- $scope.editConfigurationDisabled = true;
|
|
|
- $scope.propertiesForm.$setPristine();
|
|
|
- })
|
|
|
- .catch(function(data) {
|
|
|
- var errorMessage = data.data.message;
|
|
|
-
|
|
|
- //TODO: maybe the BackEnd should sanitize the string beforehand?
|
|
|
- errorMessage = errorMessage.substr(errorMessage.indexOf("\{"));
|
|
|
-
|
|
|
- if (data.status >= 400 && !$scope.isLocalCluster) {
|
|
|
- try {
|
|
|
- var errorObject = JSON.parse(errorMessage);
|
|
|
- errorMessage = errorObject.detail;
|
|
|
- angular.forEach(errorObject.propertyResults, function (item, key) {
|
|
|
- $scope.propertiesForm[key].validationError = !item.valid;
|
|
|
- if (!item.valid) {
|
|
|
- $scope.propertiesForm[key].validationMessage = item.detail;
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (e) {
|
|
|
- console.error($t('views.alerts.unableToParseError', {message: data.message}));
|
|
|
+ };
|
|
|
+ $scope.cancelSettings = function() {
|
|
|
+ angular.extend($scope.configuration, $scope.settingsBeforeEdit);
|
|
|
+
|
|
|
+ $scope.editSettingsDisabled = true;
|
|
|
+ $scope.settingsForm.$setPristine();
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.saveDetails = function(callback) {
|
|
|
+ if( $scope.detailsForm.$valid ){
|
|
|
+ var data = {
|
|
|
+ 'ViewInstanceInfo':{
|
|
|
+ 'visible': $scope.settings.visible,
|
|
|
+ 'label': $scope.settings.label,
|
|
|
+ 'description': $scope.settings.description
|
|
|
}
|
|
|
- }
|
|
|
- Alert.error($t('views.alerts.cannotSaveProperties'), errorMessage);
|
|
|
- });
|
|
|
- }
|
|
|
- };
|
|
|
- $scope.cancelConfiguration = function() {
|
|
|
- angular.extend($scope.configuration, $scope.configurationBeforeEdit);
|
|
|
- $scope.isLocalCluster = $scope.originalLocalCluster;
|
|
|
+ };
|
|
|
+ return View.updateInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId, data)
|
|
|
+ .success(function() {
|
|
|
+ $scope.$root.$emit('instancesUpdate');
|
|
|
+ if( callback ){
|
|
|
+ callback();
|
|
|
+ } else {
|
|
|
+ reloadViewInfo("cluster");
|
|
|
+ $scope.editDetailsSettingsDisabled = true;
|
|
|
+ $scope.settingsForm.$setPristine();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(function(data) {
|
|
|
+ Alert.error($t('views.alerts.cannotSaveSettings'), data.data.message);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ $scope.cancelDetails = function() {
|
|
|
+ $scope.settings = {
|
|
|
+ 'visible': $scope.instance.ViewInstanceInfo.visible,
|
|
|
+ 'label': $scope.instance.ViewInstanceInfo.label,
|
|
|
+ 'description': $scope.instance.ViewInstanceInfo.description,
|
|
|
+ 'shortUrl': $scope.instance.ViewInstanceInfo.short_url
|
|
|
+ };
|
|
|
+ $scope.editDetailsSettingsDisabled = true;
|
|
|
+ $scope.settingsForm.$setPristine();
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
$scope.editConfigurationDisabled = true;
|
|
|
- $scope.propertiesForm.$setPristine();
|
|
|
- };
|
|
|
+ $scope.togglePropertiesEditing = function () {
|
|
|
+ $scope.editConfigurationDisabled = !$scope.editConfigurationDisabled;
|
|
|
+ $scope.configurationBeforeEdit = angular.copy($scope.configuration);
|
|
|
+ filterClusterConfigs();
|
|
|
+ };
|
|
|
+ $scope.saveConfiguration = function() {
|
|
|
+ if( $scope.propertiesForm.$valid ){
|
|
|
+ var data = {
|
|
|
+ 'ViewInstanceInfo':{
|
|
|
+ 'properties':{}
|
|
|
+ }
|
|
|
+ };
|
|
|
+ if($scope.isLocalCluster) {
|
|
|
+ data.ViewInstanceInfo.cluster_handle = $scope.cluster;
|
|
|
+ } else {
|
|
|
+ data.ViewInstanceInfo.cluster_handle = null;
|
|
|
+ $scope.configurationMeta.forEach(function (element) {
|
|
|
+ if(element.clusterConfig) {
|
|
|
+ data.ViewInstanceInfo.properties[element.name] = $scope.configuration[element.name];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $scope.clearClusterInheritedPermissions();
|
|
|
+ }
|
|
|
+ $scope.originalLocalCluster = $scope.isLocalCluster;
|
|
|
+ return View.updateInstance($routeParams.viewId, $routeParams.version, $routeParams.instanceId, data)
|
|
|
+ .success(function() {
|
|
|
+ $scope.editConfigurationDisabled = true;
|
|
|
+ $scope.propertiesForm.$setPristine();
|
|
|
+ })
|
|
|
+ .catch(function(data) {
|
|
|
+ var errorMessage = data.data.message;
|
|
|
|
|
|
- // Permissions edit
|
|
|
- $scope.editPermissionDisabled = true;
|
|
|
- $scope.cancelPermissions = function() {
|
|
|
- $scope.permissionsEdit = angular.copy($scope.permissions); // Reset textedit areaes
|
|
|
- $scope.editPermissionDisabled = true;
|
|
|
- };
|
|
|
+ //TODO: maybe the BackEnd should sanitize the string beforehand?
|
|
|
+ errorMessage = errorMessage.substr(errorMessage.indexOf("\{"));
|
|
|
|
|
|
- $scope.savePermissions = function() {
|
|
|
- $scope.editPermissionDisabled = true;
|
|
|
- return PermissionSaver.saveViewPermissions(
|
|
|
- $scope.permissionsEdit,
|
|
|
- {
|
|
|
- view_name: $routeParams.viewId,
|
|
|
- version: $routeParams.version,
|
|
|
- instance_name: $routeParams.instanceId
|
|
|
+ if (data.status >= 400 && !$scope.isLocalCluster) {
|
|
|
+ try {
|
|
|
+ var errorObject = JSON.parse(errorMessage);
|
|
|
+ errorMessage = errorObject.detail;
|
|
|
+ angular.forEach(errorObject.propertyResults, function (item, key) {
|
|
|
+ $scope.propertiesForm[key].validationError = !item.valid;
|
|
|
+ if (!item.valid) {
|
|
|
+ $scope.propertiesForm[key].validationMessage = item.detail;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (e) {
|
|
|
+ console.error($t('views.alerts.unableToParseError', {message: data.message}));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Alert.error($t('views.alerts.cannotSaveProperties'), errorMessage);
|
|
|
+ });
|
|
|
}
|
|
|
- )
|
|
|
- .then(reloadViewPrivileges)
|
|
|
- .catch(function(data) {
|
|
|
- reloadViewPrivileges();
|
|
|
- Alert.error($t('common.alerts.cannotSavePermissions'), data.data.message);
|
|
|
- });
|
|
|
- };
|
|
|
+ };
|
|
|
+ $scope.cancelConfiguration = function() {
|
|
|
+ angular.extend($scope.configuration, $scope.configurationBeforeEdit);
|
|
|
+ $scope.isLocalCluster = $scope.originalLocalCluster;
|
|
|
+ $scope.editConfigurationDisabled = true;
|
|
|
+ $scope.propertiesForm.$setPristine();
|
|
|
+ };
|
|
|
|
|
|
- $scope.$watch(function() {
|
|
|
- return $scope.permissionsEdit;
|
|
|
- }, function(newValue) {
|
|
|
- if(newValue){
|
|
|
- $scope.savePermissions();
|
|
|
- }
|
|
|
- }, true);
|
|
|
-
|
|
|
- $scope.deleteInstance = function(instance) {
|
|
|
- ConfirmationModal.show(
|
|
|
- $t('common.delete', {
|
|
|
- term: $t('views.viewInstance')
|
|
|
- }),
|
|
|
- $t('common.deleteConfirmation', {
|
|
|
- instanceType: $t('views.viewInstance'),
|
|
|
- instanceName: instance.ViewInstanceInfo.label
|
|
|
- })
|
|
|
- ).then(function() {
|
|
|
- View.deleteInstance(instance.ViewInstanceInfo.view_name, instance.ViewInstanceInfo.version, instance.ViewInstanceInfo.instance_name)
|
|
|
- .then(function() {
|
|
|
- $location.path('/views');
|
|
|
+ // Permissions edit
|
|
|
+ $scope.editPermissionDisabled = true;
|
|
|
+ $scope.cancelPermissions = function() {
|
|
|
+ $scope.permissionsEdit = angular.copy($scope.permissions); // Reset textedit areaes
|
|
|
+ $scope.editPermissionDisabled = true;
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.savePermissions = function() {
|
|
|
+ $scope.editPermissionDisabled = true;
|
|
|
+ return PermissionSaver.saveViewPermissions(
|
|
|
+ $scope.permissionsEdit,
|
|
|
+ {
|
|
|
+ view_name: $routeParams.viewId,
|
|
|
+ version: $routeParams.version,
|
|
|
+ instance_name: $routeParams.instanceId
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then(reloadViewPrivileges)
|
|
|
+ .catch(function(data) {
|
|
|
+ reloadViewPrivileges();
|
|
|
+ Alert.error($t('common.alerts.cannotSavePermissions'), data.data.message);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.clearClusterInheritedPermissions = function() {
|
|
|
+ angular.forEach(View.clusterInheritedPermissionKeys, function(key) {
|
|
|
+ $scope.permissionsEdit["VIEW.USER"][key] = false;
|
|
|
})
|
|
|
- .catch(function(data) {
|
|
|
- Alert.error($t('views.alerts.cannotDeleteInstance'), data.data.message);
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.$watch(function() {
|
|
|
+ return $scope.permissionsEdit;
|
|
|
+ }, function(newValue, oldValue) {
|
|
|
+ if(newValue && oldValue != undefined) {
|
|
|
+ $scope.savePermissions();
|
|
|
+ }
|
|
|
+ }, true);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $scope.deleteInstance = function(instance) {
|
|
|
+ ConfirmationModal.show(
|
|
|
+ $t('common.delete', {
|
|
|
+ term: $t('views.viewInstance')
|
|
|
+ }),
|
|
|
+ $t('common.deleteConfirmation', {
|
|
|
+ instanceType: $t('views.viewInstance'),
|
|
|
+ instanceName: instance.ViewInstanceInfo.label
|
|
|
+ })
|
|
|
+ ).then(function() {
|
|
|
+ View.deleteInstance(instance.ViewInstanceInfo.view_name, instance.ViewInstanceInfo.version, instance.ViewInstanceInfo.instance_name)
|
|
|
+ .then(function() {
|
|
|
+ $location.path('/views');
|
|
|
+ })
|
|
|
+ .catch(function(data) {
|
|
|
+ Alert.error($t('views.alerts.cannotDeleteInstance'), data.data.message);
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
- $scope.$on('$locationChangeStart', function(event, targetUrl) {
|
|
|
- if( $scope.settingsForm.$dirty || $scope.propertiesForm.$dirty){
|
|
|
- UnsavedDialog().then(function(action) {
|
|
|
- targetUrl = targetUrl.split('#').pop();
|
|
|
- switch(action){
|
|
|
- case 'save':
|
|
|
- if($scope.settingsForm.$valid && $scope.propertiesForm.$valid ){
|
|
|
- $scope.saveSettings(function() {
|
|
|
- $scope.saveConfiguration().then(function() {
|
|
|
- $scope.propertiesForm.$setPristine();
|
|
|
- $scope.settingsForm.$setPristine();
|
|
|
- $location.path(targetUrl);
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.$on('$locationChangeStart', function(event, targetUrl) {
|
|
|
+ if( $scope.settingsForm.$dirty || $scope.propertiesForm.$dirty){
|
|
|
+ UnsavedDialog().then(function(action) {
|
|
|
+ targetUrl = targetUrl.split('#').pop();
|
|
|
+ switch(action){
|
|
|
+ case 'save':
|
|
|
+ if($scope.settingsForm.$valid && $scope.propertiesForm.$valid ){
|
|
|
+ $scope.saveSettings(function() {
|
|
|
+ $scope.saveConfiguration().then(function() {
|
|
|
+ $scope.propertiesForm.$setPristine();
|
|
|
+ $scope.settingsForm.$setPristine();
|
|
|
+ $location.path(targetUrl);
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
- }
|
|
|
- break;
|
|
|
- case 'discard':
|
|
|
- $scope.propertiesForm.$setPristine();
|
|
|
- $scope.settingsForm.$setPristine();
|
|
|
- $location.path(targetUrl);
|
|
|
- break;
|
|
|
- case 'cancel':
|
|
|
- targetUrl = '';
|
|
|
- break;
|
|
|
- }
|
|
|
- });
|
|
|
- event.preventDefault();
|
|
|
- }
|
|
|
- });
|
|
|
-}]);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'discard':
|
|
|
+ $scope.propertiesForm.$setPristine();
|
|
|
+ $scope.settingsForm.$setPristine();
|
|
|
+ $location.path(targetUrl);
|
|
|
+ break;
|
|
|
+ case 'cancel':
|
|
|
+ targetUrl = '';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ event.preventDefault();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }]);
|