|
@@ -21,6 +21,11 @@ var App = require('app');
|
|
|
App.MainAdminServiceAutoStartController = Em.Controller.extend({
|
|
|
name: 'mainAdminServiceAutoStartController',
|
|
|
|
|
|
+ clusterConfigs: null,
|
|
|
+ componentsConfigs: [],
|
|
|
+ isSaveDisabled: true,
|
|
|
+ valueChanged: false,
|
|
|
+
|
|
|
loadClusterConfig: function () {
|
|
|
return App.ajax.send({
|
|
|
name: 'config.tags.site',
|
|
@@ -31,6 +36,161 @@ App.MainAdminServiceAutoStartController = Em.Controller.extend({
|
|
|
});
|
|
|
},
|
|
|
|
|
|
+ loadComponentsConfigs: function () {
|
|
|
+ return App.ajax.send({
|
|
|
+ name: 'components.get_category',
|
|
|
+ sender: this,
|
|
|
+ success: 'loadComponentsConfigsSuccess'
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ loadComponentsConfigsSuccess: function (data) {
|
|
|
+ this.set('componentsConfigs', data.items);
|
|
|
+ },
|
|
|
+
|
|
|
+ tabs: function() {
|
|
|
+ var services = {};
|
|
|
+ var tabs = [];
|
|
|
+ this.get('componentsConfigs').forEach(function(component) {
|
|
|
+ var serviceComponentInfo = component.ServiceComponentInfo;
|
|
|
+ if (serviceComponentInfo.category === "MASTER" || serviceComponentInfo.category === "SLAVE") {
|
|
|
+ var componentRecovery = Ember.Object.create({
|
|
|
+ display_name: App.format.role(serviceComponentInfo.component_name),
|
|
|
+ component_name: serviceComponentInfo.component_name,
|
|
|
+ //recovery_enabled: serviceComponentInfo.recovery_enabled === 'true',
|
|
|
+ recovery_enabled: false,
|
|
|
+ valueChanged: false,
|
|
|
+ service_name: serviceComponentInfo.service_name
|
|
|
+ });
|
|
|
+ if (services[serviceComponentInfo.service_name]) {
|
|
|
+ services[serviceComponentInfo.service_name].get('componentRecovery').push(componentRecovery);
|
|
|
+ services[serviceComponentInfo.service_name].set('enabledComponents', services[serviceComponentInfo.service_name].get('enabledComponents') + (componentRecovery.get('recovery_enabled') ? 1 : 0));
|
|
|
+ services[serviceComponentInfo.service_name].set('totalComponents', services[serviceComponentInfo.service_name].get('totalComponents') + 1);
|
|
|
+ } else {
|
|
|
+ services[serviceComponentInfo.service_name] = Ember.Object.create({
|
|
|
+ service_name: serviceComponentInfo.service_name,
|
|
|
+ display_name: App.format.role(serviceComponentInfo.service_name),
|
|
|
+ headingClass: "." + serviceComponentInfo.service_name,
|
|
|
+ isActive: false,
|
|
|
+ componentRecovery: [componentRecovery],
|
|
|
+ enabledComponents: componentRecovery.recovery_enabled ? 1 : 0,
|
|
|
+ totalComponents: 1,
|
|
|
+ indicator: function() {
|
|
|
+ var percentage = this.get('enabledComponents') / this.get('totalComponents');
|
|
|
+ var indicator = "icon-adjust";
|
|
|
+ if (percentage === 1) {
|
|
|
+ indicator = "icon-circle";
|
|
|
+ } else if (percentage === 0) {
|
|
|
+ indicator = "icon-circle-blank";
|
|
|
+ }
|
|
|
+ return indicator;
|
|
|
+ }.property('enabledComponents', 'totalComponents')
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ for (var service in services ) {
|
|
|
+ tabs.push(services[service]);
|
|
|
+ }
|
|
|
+ if (tabs.length) {
|
|
|
+ tabs[0].set('isActive', true);
|
|
|
+ }
|
|
|
+ return tabs;
|
|
|
+ }.property('componentsConfigs'),
|
|
|
+
|
|
|
+ checkValuesChange: function () {
|
|
|
+ var valuesChanged = this.get('valueChanged');
|
|
|
+ this.get('tabs').forEach(function (service) {
|
|
|
+ service.get('componentRecovery').forEach(function (component) {
|
|
|
+ valuesChanged = valuesChanged || component.get('valueChanged');
|
|
|
+ });
|
|
|
+ });
|
|
|
+ this.set('isSaveDisabled', !valuesChanged);
|
|
|
+ }.observes('valueChanged'),
|
|
|
+
|
|
|
+ doReload: function () {
|
|
|
+ window.location.reload();
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * If some configs are changed and user navigates away or select another config-group, show this popup with propose to save changes
|
|
|
+ * @param {object} transitionCallback - callback with action to change configs view
|
|
|
+ * @return {App.ModalPopup}
|
|
|
+ * @method showSavePopup
|
|
|
+ */
|
|
|
+ showSavePopup: function (transitionCallback) {
|
|
|
+ var self = this;
|
|
|
+ return App.ModalPopup.show({
|
|
|
+ header: Em.I18n.t('dashboard.configHistory.info-bar.save.popup.title'),
|
|
|
+ footerClass: Em.View.extend({
|
|
|
+ templateName: require('templates/main/service/info/save_popup_footer'),
|
|
|
+ }),
|
|
|
+ primary: Em.I18n.t('common.save'),
|
|
|
+ secondary: Em.I18n.t('common.cancel'),
|
|
|
+ onSave: function () {
|
|
|
+ //save cluster setting
|
|
|
+ if (self.get('valueChanged')) {
|
|
|
+ self.saveClusterConfigs(self.get('clusterConfigs'));
|
|
|
+ }
|
|
|
+ //save component settings
|
|
|
+ var enabledComponents = [];
|
|
|
+ var disabledComponents = [];
|
|
|
+ self.get('tabs').forEach(function (service) {
|
|
|
+ service.get('componentRecovery').forEach(function (component) {
|
|
|
+ if (component.get('valueChanged')) {
|
|
|
+ if (component.get('recoveryEnabled')) {
|
|
|
+ enabledComponents.push(component.get('component_name'));
|
|
|
+ } else {
|
|
|
+ disabledComponents.push(component.get('component_name'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ if (enabledComponents.length){
|
|
|
+ App.ajax.send({
|
|
|
+ name: 'components.update',
|
|
|
+ sender: this,
|
|
|
+ data: {
|
|
|
+ ServiceComponentInfo: {
|
|
|
+ recovery_enabled: "true"
|
|
|
+ },
|
|
|
+ query: 'ServiceComponentInfo/component_name.in(' + enabledComponents.join(',') + ')'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (disabledComponents.length){
|
|
|
+ App.ajax.send({
|
|
|
+ name: 'components.update',
|
|
|
+ sender: this,
|
|
|
+ data: {
|
|
|
+ ServiceComponentInfo: {
|
|
|
+ recovery_enabled: "false"
|
|
|
+ },
|
|
|
+ query: 'ServiceComponentInfo/component_name.in(' + disabledComponents.join(',') + ')'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (typeof transitionCallback === 'function') {
|
|
|
+ transitionCallback();
|
|
|
+ } else {
|
|
|
+ self.doReload();
|
|
|
+ }
|
|
|
+ this.hide();
|
|
|
+ },
|
|
|
+ onDiscard: function () {
|
|
|
+ if (typeof transitionCallback === 'function') {
|
|
|
+ transitionCallback();
|
|
|
+ } else {
|
|
|
+ self.doReload();
|
|
|
+ }
|
|
|
+ this.hide();
|
|
|
+ },
|
|
|
+ onCancel: function () {
|
|
|
+ this.hide();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
saveClusterConfigs: function (clusterConfigs) {
|
|
|
return App.ajax.send({
|
|
|
name: 'admin.save_configs',
|
|
@@ -41,5 +201,4 @@ App.MainAdminServiceAutoStartController = Em.Controller.extend({
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
});
|