step1_view.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. App.WizardStep1View = Em.View.extend({
  19. templateName: require('templates/wizard/step1'),
  20. /**
  21. * List of available stacks
  22. * @type {Em.Object[]}
  23. */
  24. stacks: function () {
  25. return this.get('controller.content.stacks').map(function (stack) {
  26. return Em.Object.create({
  27. name: stack.get('name').replace('-', ' '),
  28. isSelected: stack.get('isSelected')
  29. });
  30. });
  31. }.property('controller.content.stacks.@each.isSelected'),
  32. /**
  33. * List of all repo-groups
  34. * @type {Object[][]}
  35. */
  36. allRepositoriesGroup: [
  37. [],
  38. [],
  39. []
  40. ],
  41. /**
  42. * Verify if some repo has empty base-url
  43. * @type {bool}
  44. */
  45. emptyRepoExist: function () {
  46. return this.get('allRepositoriesGroup').someProperty('empty-error', true);
  47. }.property('allRepositoriesGroup.@each.empty-error'),
  48. /**
  49. * Disable submit button flag
  50. * @type {bool}
  51. */
  52. isSubmitDisabled: function () {
  53. return this.get('emptyRepoExist') || this.get('allRepoUnchecked') || this.get('invalidUrlExist');
  54. }.property('emptyRepoExist', 'allRepoUnchecked', 'invalidUrlExist'),
  55. /**
  56. * Verify if some invalid repo-urls exist
  57. * @type {bool}
  58. */
  59. invalidUrlExist: function () {
  60. var selectedStack = this.get('controller.content.stacks').findProperty('isSelected', true);
  61. var invalidExist = this.get('allRepositoriesGroup').someProperty('validation', 'icon-exclamation-sign');
  62. return (selectedStack.get('invalidCnt') > 0) && invalidExist;
  63. }.property('controller.content.stacks.@each.invalidCnt', 'allRepositoriesGroup.@each.validation'),
  64. /**
  65. * If all repo links are unchecked
  66. * @type {bool}
  67. */
  68. allRepoUnchecked: function () {
  69. return !this.get('allRepositoriesGroup').someProperty('checked', true);
  70. }.property('allRepositoriesGroup.@each.checked'),
  71. /**
  72. * Overall errors count
  73. * @type {number}
  74. */
  75. totalErrorCnt: function () {
  76. var emptyCnt = this.get('allRepositoriesGroup').filterProperty('empty-error', true).length;
  77. var invalidCnt = this.get('allRepositoriesGroup').filterProperty('validation', 'icon-exclamation-sign').length;
  78. if (this.get('allRepoUnchecked')) {
  79. return 1;
  80. } else if (emptyCnt || invalidCnt) {
  81. return emptyCnt + invalidCnt;
  82. } else {
  83. return 0;
  84. }
  85. }.property('allRepositoriesGroup.@each.empty-error', 'allRepoUnchecked', 'allRepositoriesGroup.@each.validation'),
  86. /**
  87. * Is Repositories Accordion collapsed
  88. * @type {bool}
  89. */
  90. isRLCollapsed: true,
  91. /**
  92. * Checked flags for each repo-checkbox
  93. * @type {bool[]}
  94. */
  95. allGroupsCheckbox: [true, true, true],
  96. /**
  97. * Skip repo-validation
  98. * @type {bool}
  99. */
  100. skipValidationChecked: false,
  101. didInsertElement: function () {
  102. if (this.get('isRLCollapsed')) {
  103. this.$('.accordion-body').hide();
  104. }
  105. $("[rel=skip-validation-tooltip]").tooltip({ placement: 'right'});
  106. },
  107. /**
  108. * Checkbox for each stack
  109. * @type {Ember.Checkbox}
  110. */
  111. stackRadioButton: Em.Checkbox.extend({
  112. tagName: 'input',
  113. attributeBindings: [ 'type', 'checked' ],
  114. checked: function () {
  115. return this.get('content.isSelected');
  116. }.property('content.isSelected'),
  117. type: 'radio',
  118. click: function () {
  119. this.get('controller.content.stacks').setEach('isSelected', false);
  120. this.get('controller.content.stacks').findProperty('name', this.get('content.name').replace(' ', '-')).set('isSelected', true);
  121. }
  122. }),
  123. /**
  124. * Popover for repo-url error indicator
  125. * @type {Em.View}
  126. */
  127. popoverView: Em.View.extend({
  128. tagName: 'i',
  129. classNameBindings: ['repoGroup.validation'],
  130. attributeBindings: ['repoGroup.errorTitle:title', 'repoGroup.errorContent:data-content'],
  131. didInsertElement: function () {
  132. App.popover($(this.get('element')), {'trigger': 'hover'});
  133. }
  134. }),
  135. /**
  136. * Onclick handler for Config Group Header. Used to show/hide block
  137. * @method onToggleBlock
  138. */
  139. onToggleBlock: function () {
  140. this.$('.accordion-body').toggle('blind', 500);
  141. this.set('isRLCollapsed', !this.get('isRLCollapsed'));
  142. },
  143. /**
  144. * Format repo-group values and set it to <code>allRepositoriesGroup</code>
  145. * @method loadRepositories
  146. */
  147. loadRepositories: function () {
  148. var selectedStack = this.get('controller.content.stacks').findProperty('isSelected', true);
  149. var reposGroup = [
  150. [],
  151. [],
  152. []
  153. ];
  154. if (App.get('supports.ubuntu')) reposGroup.push([]); // @todo: remove after Ubuntu support confirmation
  155. var self = this;
  156. if (selectedStack && selectedStack.operatingSystems) {
  157. selectedStack.operatingSystems.forEach(function (os) {
  158. var cur_repo = Em.Object.create({
  159. baseUrl: os.baseUrl
  160. });
  161. switch (os.osType) {
  162. case 'redhat5':
  163. cur_repo.set('osType', 'Red Hat 5');
  164. reposGroup[0][0] = cur_repo;
  165. // set group 0 properties by redhat5 (any of the three is ok)
  166. self.setGroupByOs(reposGroup[0], os, 0);
  167. break;
  168. case 'centos5':
  169. cur_repo.set('osType', 'CentOS 5');
  170. reposGroup[0][1] = cur_repo;
  171. break;
  172. case 'oraclelinux5':
  173. cur_repo.set('osType', 'Oracle Linux 5');
  174. reposGroup[0][2] = cur_repo;
  175. break;
  176. case 'redhat6':
  177. cur_repo.set('osType', 'Red Hat 6');
  178. reposGroup[1][0] = cur_repo;
  179. // set group 1 properties by redhat6 (any of the three is ok)
  180. self.setGroupByOs(reposGroup[1], os, 1);
  181. break;
  182. case 'centos6':
  183. cur_repo.set('osType', 'CentOS 6');
  184. reposGroup[1][1] = cur_repo;
  185. break;
  186. case 'oraclelinux6':
  187. cur_repo.set('osType', 'Oracle Linux 6');
  188. reposGroup[1][2] = cur_repo;
  189. break;
  190. case 'sles11':
  191. cur_repo.set('osType', 'SLES 11');
  192. reposGroup[2][0] = cur_repo;
  193. // set group 2 properties by sles11 (any of the twe is ok)
  194. self.setGroupByOs(reposGroup[2], os, 2);
  195. break;
  196. case 'suse11':
  197. cur_repo.set('osType', 'SUSE 11');
  198. reposGroup[2][1] = cur_repo;
  199. break;
  200. case 'ubuntu12':
  201. if (App.get('supports.ubuntu')) {
  202. cur_repo.set('osType', 'Ubuntu 12');
  203. reposGroup[3][0] = cur_repo;
  204. self.setGroupByOs(reposGroup[3], os, 3);
  205. }
  206. break;
  207. }
  208. });
  209. }
  210. this.set('allRepositoriesGroup', reposGroup);
  211. }.observes('controller.content.stacks.@each.isSelected', 'controller.content.stacks.@each.reload'),
  212. /**
  213. * Set group parameters according to operation system
  214. * @method setGroupByOs
  215. * @param {Ember.Object} group
  216. * @param {Object} os
  217. * @param {number} groupNumber
  218. */
  219. setGroupByOs: function (group, os, groupNumber) {
  220. var isChecked = this.get('allGroupsCheckbox')[groupNumber];
  221. group.set('checked', isChecked);
  222. group.set('baseUrl', os.baseUrl);
  223. group.set('latestBaseUrl', os.latestBaseUrl);
  224. group.set('defaultBaseUrl', os.defaultBaseUrl);
  225. group.set('empty-error', !os.baseUrl);
  226. group.set('invalid-error', os.validation == 'icon-exclamation-sign');
  227. group.set('validation', os.validation);
  228. group.set('undo', os.baseUrl != os.latestBaseUrl);
  229. group.set('clearAll', os.baseUrl);
  230. group.set('errorTitle', os.errorTitle);
  231. group.set('errorContent', os.errorContent);
  232. group.set('group-number', groupNumber);
  233. },
  234. /**
  235. * Onclick handler for checkbox of each repo group
  236. * @method updateByCheckbox
  237. */
  238. updateByCheckbox: function () {
  239. //upload to content
  240. var groups = this.get('allRepositoriesGroup');
  241. var self = this;
  242. var selectedStack = this.get('controller.content.stacks').findProperty('isSelected', true);
  243. if (selectedStack && selectedStack.operatingSystems) {
  244. selectedStack.operatingSystems.forEach(function (os) {
  245. var groupNumber = self.osTypeToGroup(os.osType);
  246. var targetGroup = groups.findProperty('group-number', groupNumber);
  247. if (!targetGroup.get('checked')) {
  248. os.baseUrl = os.latestBaseUrl;
  249. os.validation = null;
  250. os.selected = false;
  251. targetGroup.set('baseUrl', os.latestBaseUrl);
  252. targetGroup.set('latestBaseUrl', os.latestBaseUrl);
  253. targetGroup.set('undo', targetGroup.get('baseUrl') != targetGroup.get('latestBaseUrl'));
  254. targetGroup.set('invalid-error', false);
  255. targetGroup.set('validation', null);
  256. targetGroup.set('clearAll', false);
  257. targetGroup.set('empty-error', !targetGroup.get('baseUrl'));
  258. self.get('allGroupsCheckbox')[groupNumber] = false;
  259. self.set('allGroupsCheckbox', self.get('allGroupsCheckbox'));
  260. } else {
  261. os.selected = true;
  262. os.skipValidation = self.get('skipValidationChecked');
  263. if (os.skipValidation) {
  264. targetGroup.set('validation', null);
  265. targetGroup.set('invalid-error', false);
  266. }
  267. targetGroup.set('clearAll', targetGroup.get('baseUrl'));
  268. targetGroup.set('empty-error', !targetGroup.get('baseUrl'));
  269. self.get('allGroupsCheckbox')[groupNumber] = true;
  270. }
  271. });
  272. }
  273. }.observes('allRepositoriesGroup.@each.checked', 'skipValidationChecked'),
  274. /**
  275. * Onclick handler for undo action of each repo group
  276. * @method undoGroupLocalRepository
  277. * @param {object} event
  278. */
  279. undoGroupLocalRepository: function (event) {
  280. this.doActionForGroupLocalRepository(event, 'latestBaseUrl');
  281. },
  282. /**
  283. * Handler for clear icon click
  284. * @method clearGroupLocalRepository
  285. * @param {object} event
  286. */
  287. clearGroupLocalRepository: function (event) {
  288. this.doActionForGroupLocalRepository(event, '');
  289. },
  290. /**
  291. * Common handler for repo groups actions
  292. * @method doActionForGroupLocalRepository
  293. * @param {object} event
  294. * @param {string} newBaseUrlField
  295. */
  296. doActionForGroupLocalRepository: function (event, newBaseUrlField) {
  297. var osTypes = this.groupToOsType(event.context.get('group-number'));
  298. var selectedStack = this.get('controller.content.stacks').findProperty('isSelected', true);
  299. osTypes.forEach(function (os) {
  300. var cos = selectedStack.operatingSystems.findProperty('osType', os);
  301. cos.baseUrl = Em.isEmpty(newBaseUrlField) ? '' : Em.get(cos, newBaseUrlField);
  302. cos.validation = null;
  303. });
  304. this.loadRepositories();
  305. },
  306. /**
  307. * Handler when editing any repo group BaseUrl
  308. * @method editGroupLocalRepository
  309. */
  310. editGroupLocalRepository: function () {
  311. //upload to content
  312. var groups = this.get('allRepositoriesGroup');
  313. var self = this;
  314. var selectedStack = this.get('controller.content.stacks').findProperty('isSelected', true);
  315. if (selectedStack && selectedStack.operatingSystems) {
  316. selectedStack.operatingSystems.forEach(function (os) {
  317. var targetGroup = groups.findProperty('group-number', self.osTypeToGroup(os.osType));
  318. if (os.baseUrl != targetGroup.get('baseUrl')) {
  319. os.baseUrl = targetGroup.get('baseUrl');
  320. os.validation = null;
  321. targetGroup.set('undo', targetGroup.get('baseUrl') != targetGroup.get('latestBaseUrl'));
  322. targetGroup.set('invalid-error', false);
  323. targetGroup.set('validation', null);
  324. targetGroup.set('clearAll', os.baseUrl);
  325. targetGroup.set('empty-error', !targetGroup.get('baseUrl'));
  326. }
  327. });
  328. }
  329. }.observes('allRepositoriesGroup.@each.baseUrl'),
  330. /**
  331. * Get list of OS for provided group number
  332. * @method groupToOsType
  333. * @param {number} groupNumber
  334. * @returns {Array}
  335. */
  336. groupToOsType: function (groupNumber) {
  337. return Em.getWithDefault({
  338. '0': ['redhat5', 'centos5', 'oraclelinux5'],
  339. '1': ['redhat6', 'centos6', 'oraclelinux6'],
  340. '2': ['sles11', 'suse11'],
  341. '3': ['ubuntu12']
  342. }, groupNumber.toString(), []);
  343. },
  344. /**
  345. * Get group number for provided OS
  346. * @method osTypeToGroup
  347. * @param {string} osType
  348. * @returns {number}
  349. */
  350. osTypeToGroup: function (osType) {
  351. return Em.getWithDefault({
  352. 'redhat5': 0,
  353. 'centos5': 0,
  354. 'oraclelinux5': 0,
  355. 'redhat6': 1,
  356. 'centos6': 1,
  357. 'oraclelinux6': 1,
  358. 'sles11': 2,
  359. 'suse11': 2,
  360. 'ubuntu12': 3
  361. }, osType, -1);
  362. }
  363. });