stack_versions_controller.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. timeoutRef: null,
  23. isPolling: false,
  24. dataIsLoaded: false,
  25. mockUrl: '/data/stack_versions/stack_version_all.json',
  26. realUrl: function () {
  27. return App.apiPrefix + '/clusters/' + App.get('clusterName') + '/stack_versions?fields=*,repository_versions/*,repository_versions/operatingSystems/repositories/*';
  28. }.property('App.clusterName'),
  29. realUpdateUrl: function () {
  30. return App.apiPrefix + '/clusters/' + App.get('clusterName') + '/stack_versions?fields=*,repository_versions/*,repository_versions/operatingSystems/repositories/*';
  31. //TODO return App.apiPrefix + '/clusters/' + App.get('clusterName') + '/stack_versions?fields=ClusterStackVersions/state,ClusterStackVersions/host_states&minimal_response=true';
  32. }.property('App.clusterName'),
  33. /**
  34. * request latest data from server and update content
  35. */
  36. doPolling: function () {
  37. var self = this;
  38. this.set('timeoutRef', setTimeout(function () {
  39. if (self.get('isPolling')) {
  40. self.loadStackVersionsToModel(self.get('dataIsLoaded')).done(function () {
  41. self.doPolling();
  42. })
  43. }
  44. }, App.componentsUpdateInterval));
  45. },
  46. /**
  47. * load all data components required by stack version table
  48. * @return {*}
  49. */
  50. load: function () {
  51. var dfd = $.Deferred();
  52. var self = this;
  53. this.loadStackVersionsToModel().done(function () {
  54. self.set('dataIsLoaded', true);
  55. dfd.resolve();
  56. });
  57. return dfd.promise();
  58. },
  59. /**
  60. * get stack versions from server and push it to model
  61. * @return {*}
  62. */
  63. loadStackVersionsToModel: function (isUpdate) {
  64. var dfd = $.Deferred();
  65. App.HttpClient.get(this.getUrl(isUpdate), App.stackVersionMapper, {
  66. complete: function () {
  67. dfd.resolve();
  68. }
  69. });
  70. return dfd.promise();
  71. },
  72. getUrl: function (isUpdate) {
  73. return App.get('testMode') ? this.get('mockUrl') :
  74. isUpdate ? this.get('realUpdateUrl') : this.get('realUrl');
  75. },
  76. filterHostsByStack: function (version, state) {
  77. if (!version || !state)
  78. return;
  79. App.router.get('mainHostController').filterByStack(version, state);
  80. App.router.get('mainHostController').set('showFilterConditionsFirstLoad', true);
  81. App.router.transitionTo('hosts.index');
  82. },
  83. showHosts: function(event) {
  84. var self = this;
  85. var status = event.currentTarget.title.toCapital();
  86. var version = event.contexts[0];
  87. var hosts = event.contexts[1];
  88. if (hosts.length) {
  89. return App.ModalPopup.show({
  90. bodyClass: Ember.View.extend({
  91. title: Em.I18n.t('admin.stackVersions.hosts.popup.title').format(version, status, hosts.length),
  92. template: Em.Handlebars.compile('<h4>{{view.title}}</h4><span class="limited-height-2">'+ hosts.join('<br/>') + '</span>')
  93. }),
  94. header: Em.I18n.t('admin.stackVersions.hosts.popup.header').format(status),
  95. primary: Em.I18n.t('admin.stackVersions.hosts.popup.primary'),
  96. secondary: Em.I18n.t('common.close'),
  97. onPrimary: function() {
  98. this.hide();
  99. self.filterHostsByStack(version, status);
  100. }
  101. });
  102. }
  103. }
  104. });