stack_versions_controller.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.MainStackVersionsController = Em.ArrayController.extend({
  20. name: 'mainStackVersionsController',
  21. content: App.StackVersion.find(),
  22. mockUrl: '/data/stack_versions/stack_version_all.json',
  23. realUrl: function () {
  24. return App.apiPrefix + '/clusters/' + App.get('clusterName') + '/stack_versions&minimal_response=true';
  25. }.property('App.clusterName'),
  26. /**
  27. * load all data components required by stack version table
  28. * @return {*}
  29. */
  30. load: function () {
  31. var dfd = $.Deferred();
  32. var self = this;
  33. this.loadStackVersionsToModel().done(function () {
  34. self.set('dataIsLoaded', true);
  35. dfd.resolve();
  36. });
  37. return dfd.promise();
  38. },
  39. /**
  40. * get stack versions from server and push it to model
  41. * @return {*}
  42. */
  43. loadStackVersionsToModel: function () {
  44. var dfd = $.Deferred();
  45. App.HttpClient.get(this.getUrl(), App.stackVersionMapper, {
  46. complete: function () {
  47. dfd.resolve();
  48. }
  49. });
  50. return dfd.promise();
  51. },
  52. getUrl: function () {
  53. return App.get('testMode') ? this.get('mockUrl') : this.get('realUrl');
  54. },
  55. filterHostsByStack: function (version, state) {
  56. if (!version || !state)
  57. return;
  58. App.router.get('mainHostController').filterByStack(version, state);
  59. App.router.get('mainHostController').set('showFilterConditionsFirstLoad', true);
  60. App.router.transitionTo('hosts.index');
  61. },
  62. showHosts: function(event) {
  63. var self = this;
  64. var status = event.currentTarget.title.toCapital();
  65. var version = event.contexts[0];
  66. var hosts = event.contexts[1];
  67. return App.ModalPopup.show({
  68. bodyClass: Ember.View.extend({
  69. title: Em.I18n.t('admin.stackVersions.hosts.popup.title').format(version, status, hosts.length),
  70. template: Em.Handlebars.compile('<h4>{{view.title}}</h4><span class="limited-height-2">'+ hosts.join('<br/>') + '</span>')
  71. }),
  72. header: Em.I18n.t('admin.stackVersions.hosts.popup.header').format(status),
  73. primary: Em.I18n.t('admin.stackVersions.hosts.popup.primary'),
  74. secondary: Em.I18n.t('common.close'),
  75. onPrimary: function() {
  76. this.hide();
  77. self.filterHostsByStack(version, status);
  78. }
  79. });
  80. }
  81. });