repo_versions_controller.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /**
  25. * true if content is loaded to model
  26. * @type {Boolean}
  27. */
  28. dataIsLoaded: false,
  29. /**
  30. * path to the mock json
  31. * @type {String}
  32. */
  33. mockUrl: '/data/stack_versions/repo_versions_all.json',
  34. /**
  35. * api to get RepoVersions
  36. * @type {String}
  37. */
  38. realUrl: function () {
  39. return App.get('apiPrefix') + App.get('stackVersionURL') + '/repository_versions?fields=*,operatingSystems/*,operatingSystems/repositories/*';
  40. }.property('App.stackVersionURL'),
  41. /**
  42. * load all data components required by repo version table
  43. * @return {*}
  44. * @method load()
  45. */
  46. load: function () {
  47. this.set('dataIsLoaded', false);
  48. var dfd = $.Deferred();
  49. var self = this;
  50. this.loadRepoVersionsToModel().done(function () {
  51. self.set('dataIsLoaded', true);
  52. dfd.resolve();
  53. });
  54. return dfd.promise();
  55. },
  56. /**
  57. * get repo versions from server and push it to model
  58. * @return {*}
  59. * @params {Boolean} isUpdate - if true loads part of data that need to be updated
  60. * @method loadRepoVersionsToModel()
  61. */
  62. loadRepoVersionsToModel: function () {
  63. var dfd = $.Deferred();
  64. var self = this;
  65. App.get('router.mainStackVersionsController').loadStackVersionsToModel().done(function () {
  66. App.HttpClient.get(self.getUrl(), App.repoVersionMapper, {
  67. complete: function () {
  68. dfd.resolve();
  69. }
  70. });
  71. });
  72. return dfd.promise();
  73. },
  74. /**
  75. * returns api url to get repositoryVersion
  76. * or mock json if testmode is on
  77. * @returns {String}
  78. * @method getUrl
  79. */
  80. getUrl: function () {
  81. return App.get('testMode') ? this.get('mockUrl') : this.get('realUrl');
  82. },
  83. /**
  84. * sends request to install repoVersion to the cluster
  85. * and create clusterStackVersion resourse
  86. * @param event
  87. * @return {$.ajax}
  88. * @method installRepoVersion
  89. */
  90. installRepoVersion: function (event) {
  91. var repo = event.context;
  92. var data = {
  93. ClusterStackVersions: {
  94. stack: repo.get('stackVersionType'),
  95. version: repo.get('stackVersionNumber'),
  96. repository_version: repo.get('repositoryVersion')
  97. },
  98. id: repo.get('id')
  99. };
  100. return App.ajax.send({
  101. name: 'admin.stack_version.install.repo_version',
  102. sender: this,
  103. data: data,
  104. success: 'installStackVersionSuccess'
  105. });
  106. },
  107. /**
  108. * success callback for <code>installRepoVersion()<code>
  109. * saves request id to the db, and redirect user to the just
  110. * created clusterStackVersion.
  111. * @param data
  112. * @param opt
  113. * @param params
  114. * @method installStackVersionSuccess
  115. */
  116. installStackVersionSuccess: function (data, opt, params) {
  117. App.db.set('repoVersion', 'id', [data.Requests.id]);
  118. if(!App.StackVersion.find().findProperty('repositoryVersion.id', params.id)) {
  119. App.get('router.mainStackVersionsController').loadStackVersionsToModel().done(function() {
  120. var stackVersion = App.StackVersion.find().findProperty('repositoryVersion.id', params.id);
  121. App.router.transitionTo('main.admin.adminStackVersions.version', stackVersion);
  122. });
  123. }
  124. }
  125. });