repo_versions_controller.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.RepoVersionsController = Em.ArrayController.extend({
  20. name: 'repoVersionsController',
  21. content: function () {
  22. return App.RepositoryVersion.find().filterProperty('stackVersion', null);
  23. }.property('dataIsLoaded'),
  24. dataIsLoaded: false,
  25. mockUrl: '/data/stack_versions/repo_versions_all.json',
  26. realUrl: function () {
  27. return App.get('apiPrefix') + App.get('stackVersionURL') + '/repository_versions?fields=*,operatingSystems/*,operatingSystems/repositories/*';
  28. }.property('App.stackVersionURL'),
  29. /**
  30. * load all data components required by repo version table
  31. * @return {*}
  32. */
  33. load: function () {
  34. this.set('dataIsLoaded', false);
  35. var dfd = $.Deferred();
  36. var self = this;
  37. this.loadRepoVersionsToModel().done(function () {
  38. self.set('dataIsLoaded', true);
  39. dfd.resolve();
  40. });
  41. return dfd.promise();
  42. },
  43. /**
  44. * get repo versions from server and push it to model
  45. * @return {*}
  46. */
  47. loadRepoVersionsToModel: function (isUpdate) {
  48. var dfd = $.Deferred();
  49. var self = this;
  50. App.get('router.mainStackVersionsController').loadStackVersionsToModel().done(function () {
  51. App.HttpClient.get(self.getUrl(isUpdate), App.repoVersionMapper, {
  52. complete: function () {
  53. dfd.resolve();
  54. }
  55. });
  56. });
  57. return dfd.promise();
  58. },
  59. getUrl: function (isUpdate) {
  60. return App.get('testMode') ? this.get('mockUrl') :
  61. isUpdate ? this.get('realUpdateUrl') : this.get('realUrl');
  62. },
  63. installRepoVersion: function (event) {
  64. var repo = event.context;
  65. var data = {
  66. ClusterStackVersions: {
  67. stack: repo.get('stackVersionType'),
  68. version: repo.get('stackVersionNumber'),
  69. repository_version: repo.get('repositoryVersion')
  70. },
  71. id: repo.get('id')
  72. };
  73. App.ajax.send({
  74. name: 'admin.stack_version.install.repo_version',
  75. sender: this,
  76. data: data,
  77. success: 'installStackVersionSuccess'
  78. });
  79. },
  80. installStackVersionSuccess: function (data, opt, params) {
  81. var stackVersion = App.StackVersion.find().findProperty('repositoryVersion.id', params.id);
  82. App.router.transitionTo('main.admin.adminStackVersions.version', stackVersion);
  83. }
  84. });