repo_versions_controller.js 4.1 KB

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