stack_versions_controller.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. });