stack_upgrade_routes.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. module.exports = App.WizardRoute.extend({
  20. route: 'stack/upgrade',
  21. enter: function (router) {
  22. if (App.isAuthorized('CLUSTER.UPGRADE_DOWNGRADE_STACK')) {
  23. router.get('mainController').dataLoading().done(function () {
  24. Ember.run.next(function () {
  25. //if upgrade id is absent then upgrade is completed
  26. if (Em.isNone(App.db.get('MainAdminStackAndUpgrade', 'upgradeId'))) {
  27. router.transitionTo('main.admin.stackAndUpgrade.versions');
  28. return null;
  29. }
  30. App.router.get('updateController').set('isWorking', false);
  31. return App.ModalPopup.show({
  32. classNames: ['full-width-modal'],
  33. header: function () {
  34. var controller = App.router.get('mainAdminStackAndUpgradeController');
  35. if (controller.get('isDowngrade')) {
  36. return Em.I18n.t('admin.stackUpgrade.dialog.downgrade.header').format(controller.get('upgradeVersion'));
  37. } else {
  38. return Em.I18n.t('admin.stackUpgrade.dialog.header').format(controller.get('upgradeTypeDisplayName'), controller.get('upgradeVersion'));
  39. }
  40. }.property('App.router.mainAdminStackAndUpgradeController.upgradeVersion', 'App.router.mainAdminStackAndUpgradeController.isDowngrade'),
  41. bodyClass: App.upgradeWizardView,
  42. primary: Em.I18n.t('common.dismiss'),
  43. secondary: null,
  44. didInsertElement: function () {
  45. this._super();
  46. this.fitHeight();
  47. this.fitInnerHeight();
  48. },
  49. /**
  50. * fit height of scrollable block inside of modal body
  51. */
  52. fitInnerHeight: function () {
  53. var block = this.$().find('#modal > .modal-body');
  54. var scrollable = this.$().find('#modal .scrollable-block');
  55. scrollable.css('max-height', Number(block.css('max-height').slice(0, -2)) - block.height());
  56. block.css('max-height', 'none');
  57. },
  58. onPrimary: function () {
  59. this.closeWizard();
  60. },
  61. onClose: function () {
  62. this.closeWizard();
  63. },
  64. closeWizard: function () {
  65. App.router.get('updateController').set('isWorking', true);
  66. App.router.transitionTo('main.admin.stackAndUpgrade.versions');
  67. this.hide();
  68. location.reload();
  69. }
  70. });
  71. });
  72. });
  73. } else {
  74. Em.run.next(function () {
  75. App.router.transitionTo('main.views');
  76. });
  77. }
  78. }
  79. });