stack_and_upgrade_view.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. var stringUtils = require('utils/string_utils');
  20. App.MainAdminStackAndUpgradeView = Em.View.extend({
  21. templateName: require('templates/main/admin/stack_and_upgrade'),
  22. hostsOnlineLabel: function () {
  23. var hostsCountMap = App.router.get('mainHostController.hostsCountMap');
  24. return Em.I18n.t('admin.stackUpgrade.hostsOnline').format(hostsCountMap.HEALTHY, hostsCountMap.TOTAL);
  25. }.property('App.router.mainHostController.hostsCountMap'),
  26. upgradeStateLabel: function () {
  27. return "";
  28. }.property(),
  29. willInsertElement: function () {
  30. if (App.get('supports.stackUpgrade')) this.get('controller').loadVersionsInfo();
  31. },
  32. sourceVersionView: App.UpgradeVersionBoxView.extend({
  33. version: function () {
  34. return this.get('controller.currentVersion');
  35. }.property('controller.currentVersion'),
  36. btnClass: 'btn-danger',
  37. action: function () {
  38. return {
  39. method: ['UPGRADING', 'UPGRADED', 'UPGRADE_FAILED'].contains(this.get('version.state')) && 'downgrade',
  40. label: ['UPGRADING', 'UPGRADED', 'UPGRADE_FAILED'].contains(this.get('version.state')) && Em.I18n.t('common.downgrade')
  41. };
  42. }.property('version.state'),
  43. hostsCount: function () {
  44. return this.get('version.current_hosts.length');
  45. }.property('version.current_hosts.length')
  46. }),
  47. targetVersionView: App.UpgradeVersionBoxView.extend({
  48. versions: function () {
  49. return this.get('controller.targetVersions');
  50. }.property('controller.targetVersions'),
  51. btnClass: 'btn-success',
  52. versionName: function () {
  53. if (!this.get('hasVersionsToUpgrade')) return Em.I18n.t('admin.stackUpgrade.state.notAvailable');
  54. return this.get('version.stack') + "-" + this.get('version.version');
  55. }.property('version.stack', 'version.version', 'hasVersionsToUpgrade'),
  56. hasVersionsToUpgrade: function () {
  57. return this.get('versions.length') > 0;
  58. }.property('versions.length'),
  59. selectedVersion: null,
  60. versionsSelectContent: function () {
  61. return this.get('versions').map(function (version) {
  62. return {
  63. label: version.stack + "-" + version.version,
  64. value: version.id
  65. }
  66. });
  67. }.property('versions.length'),
  68. action: function () {
  69. var methodName = null,
  70. labelName = null,
  71. versions = this.get('versions');
  72. if (versions.length > 0) {
  73. labelName = Em.I18n.t('common.upgrade');
  74. methodName = 'upgrade';
  75. }
  76. return {
  77. method: methodName,
  78. label: labelName
  79. };
  80. }.property('versions.length')
  81. })
  82. });