redirections.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /**
  20. * Mixin for routers which may redirect user to the some cluster installer steps
  21. * Based on cluster state
  22. * @type {Em.Mixin}
  23. */
  24. App.RouterRedirections = Em.Mixin.create({
  25. /**
  26. * List of cluster statuses when it's not installed
  27. * @type {string[]}
  28. */
  29. installerStatuses: ['CLUSTER_NOT_CREATED_1', 'CLUSTER_DEPLOY_PREP_2', 'CLUSTER_INSTALLING_3', 'SERVICE_STARTING_3', 'CLUSTER_INSTALLED_4'],
  30. /**
  31. * Redirect user to the proper installer step if needed
  32. * Based on cluster state:
  33. * 1. CLUSTER_NOT_CREATED_1 - to current step
  34. * 2. CLUSTER_DEPLOY_PREP_2 - to step 8
  35. * 3. CLUSTER_INSTALLING_3/SERVICE_STARTING_3 - to step 9
  36. * 4. CLUSTER_INSTALLED_4 - to step 10
  37. * @param {Em.Router} router
  38. * @param {Object} currentClusterStatus
  39. * @param {Boolean} isOnInstaller true - user is on the cluster installer, false - something else
  40. * @method redirectToInstaller
  41. */
  42. redirectToInstaller: function (router, currentClusterStatus, isOnInstaller) {
  43. var installerController = router.get('installerController');
  44. var path = isOnInstaller ? '' : 'installer.';
  45. switch (currentClusterStatus.clusterState) {
  46. case 'CLUSTER_NOT_CREATED_1' :
  47. App.get('router').setAuthenticated(true);
  48. router.transitionTo(path + 'step' + installerController.get('currentStep'));
  49. break;
  50. case 'CLUSTER_DEPLOY_PREP_2' :
  51. installerController.setCurrentStep('8');
  52. App.db.data = currentClusterStatus.localdb;
  53. App.get('router').setAuthenticated(true);
  54. router.transitionTo(path + 'step' + installerController.get('currentStep'));
  55. break;
  56. case 'CLUSTER_INSTALLING_3' :
  57. case 'SERVICE_STARTING_3' :
  58. if (!installerController.get('isStep9')) {
  59. installerController.setCurrentStep('9');
  60. installerController.setLowerStepsDisable(9);
  61. }
  62. router.transitionTo(path + 'step' + installerController.get('currentStep'));
  63. break;
  64. case 'CLUSTER_INSTALLED_4' :
  65. if (!installerController.get('isStep10')) {
  66. installerController.setCurrentStep('10');
  67. installerController.setLowerStepsDisable(10);
  68. }
  69. App.db.data = currentClusterStatus.localdb;
  70. App.get('router').setAuthenticated(true);
  71. router.transitionTo(path + 'step' + installerController.get('currentStep'));
  72. break;
  73. }
  74. }
  75. });