wizard_controller.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.WidgetWizardController = App.WizardController.extend({
  20. name: 'widgetWizardController',
  21. totalSteps: 3,
  22. /**
  23. * Used for hiding back button in wizard
  24. */
  25. hideBackButton: true,
  26. content: Em.Object.create({
  27. controllerName: 'widgetWizardController',
  28. widgetService: null,
  29. widgetType: '',
  30. widgetProperties: [],
  31. widgetMetrics: [],
  32. widgetValues: [],
  33. widgetName: null,
  34. widgetDescription: null,
  35. widgetScope: null
  36. }),
  37. /**
  38. * set current step
  39. * @param {string} currentStep
  40. * @param {boolean} completed
  41. * @param {boolean} skipStateSave
  42. */
  43. setCurrentStep: function (currentStep, completed, skipStateSave) {
  44. this._super(currentStep, completed);
  45. if (App.get('testMode') || skipStateSave) {
  46. return;
  47. }
  48. App.clusterStatus.setClusterStatus({
  49. clusterName: this.get('content.cluster.name'),
  50. clusterState: 'WIDGET_DEPLOY',
  51. wizardControllerName: 'widgetWizardController',
  52. localdb: App.db.data
  53. });
  54. },
  55. setStepsEnable: function () {
  56. for (var i = 1; i <= this.get('totalSteps'); i++) {
  57. var step = this.get('isStepDisabled').findProperty('step', i);
  58. if (i <= this.get('currentStep') && App.get('router.clusterController.isLoaded')) {
  59. step.set('value', false);
  60. } else {
  61. step.set('value', i != this.get('currentStep'));
  62. }
  63. }
  64. }.observes('currentStep', 'App.router.clusterController.isLoaded'),
  65. /**
  66. * save status of the cluster.
  67. * @param clusterStatus object with status,requestId fields.
  68. */
  69. saveClusterStatus: function (clusterStatus) {
  70. var oldStatus = this.toObject(this.get('content.cluster'));
  71. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  72. if (clusterStatus.requestId) {
  73. clusterStatus.requestId.forEach(function (requestId) {
  74. if (clusterStatus.oldRequestsId.indexOf(requestId) === -1) {
  75. clusterStatus.oldRequestsId.push(requestId)
  76. }
  77. }, this);
  78. }
  79. this.set('content.cluster', clusterStatus);
  80. this.save('cluster');
  81. },
  82. loadWidgetService: function() {
  83. this.set('content.widgetService', this.getDBProperty('widgetService'));
  84. },
  85. loadWidgetType: function() {
  86. this.set('content.widgetType', this.getDBProperty('widgetType'));
  87. },
  88. loadWidgetProperties: function() {
  89. this.set('content.widgetProperties', this.getDBProperty('widgetProperties'));
  90. },
  91. loadWidgetMetrics: function() {
  92. this.set('content.widgetMetrics', this.getDBProperty('widgetMetrics'));
  93. },
  94. loadWidgetValues: function() {
  95. this.set('content.widgetValues', this.getDBProperty('widgetValues'));
  96. },
  97. saveWidgetService: function(widgetService) {
  98. this.setDBProperty('widgetService',widgetService);
  99. this.set('content.widgetService', widgetService);
  100. },
  101. saveWidgetType: function(widgetType) {
  102. this.setDBProperty('widgetType',widgetType);
  103. this.set('content.widgetType', widgetType);
  104. },
  105. saveWidgetProperties: function(widgetProperties) {
  106. this.setDBProperty('widgetProperties',widgetProperties);
  107. this.set('content.widgetProperties', widgetProperties);
  108. },
  109. saveWidgetMetrics: function(widgetMetrics) {
  110. this.setDBProperty('widgetMetrics',widgetMetrics);
  111. this.set('content.widgetMetrics', widgetMetrics);
  112. },
  113. saveWidgetValues: function(widgetValues) {
  114. this.setDBProperty('widgetValues',widgetValues);
  115. this.set('content.widgetValues', widgetValues);
  116. },
  117. loadMap: {
  118. '1': [
  119. {
  120. type: 'sync',
  121. callback: function () {
  122. this.loadWidgetService();
  123. this.loadWidgetType();
  124. }
  125. }
  126. ],
  127. '2': [
  128. {
  129. type: 'sync',
  130. callback: function () {
  131. this.loadWidgetProperties();
  132. this.loadWidgetMetrics();
  133. this.loadWidgetValues();
  134. }
  135. }
  136. ]
  137. },
  138. /**
  139. * Remove all loaded data.
  140. * Created as copy for App.router.clearAllSteps
  141. */
  142. clearAllSteps: function () {
  143. this.clearInstallOptions();
  144. // clear temporary information stored during the install
  145. this.set('content.cluster', this.getCluster());
  146. },
  147. clearTasksData: function () {
  148. this.saveTasksStatuses(undefined);
  149. this.saveRequestIds(undefined);
  150. this.saveTasksRequestIds(undefined);
  151. },
  152. /**
  153. * Clear all temporary data
  154. */
  155. finish: function () {
  156. this.setCurrentStep('1', false, true);
  157. this.saveWidgetType('');
  158. this.resetDbNamespace();
  159. App.get('router.updateController').updateAll();
  160. }
  161. });