123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
- var App = require('app');
- App.WizardStep1View = Em.View.extend({
- templateName: require('templates/wizard/step1'),
- /**
- * List of available stacks
- * @type {Em.Object[]}
- */
- stacks: function () {
- return this.get('controller.content.stacks').map(function (stack) {
- return Em.Object.create({
- name: stack.get('name').replace('-', ' '),
- isSelected: stack.get('isSelected')
- });
- });
- }.property('controller.content.stacks.@each.isSelected'),
- /**
- * List of all repo-groups
- * @type {Object[][]}
- */
- allRepositoriesGroup: [
- [],
- [],
- []
- ],
- /**
- * Verify if some repo has empty base-url
- * @type {bool}
- */
- emptyRepoExist: function () {
- return this.get('allRepositoriesGroup').someProperty('empty-error', true);
- }.property('allRepositoriesGroup.@each.empty-error'),
- /**
- * Disable submit button flag
- * @type {bool}
- */
- isSubmitDisabled: function () {
- return this.get('emptyRepoExist') || this.get('allRepoUnchecked') || this.get('invalidUrlExist');
- }.property('emptyRepoExist', 'allRepoUnchecked', 'invalidUrlExist'),
- /**
- * Verify if some invalid repo-urls exist
- * @type {bool}
- */
- invalidUrlExist: function () {
- var selectedStack = this.get('controller.content.stacks').findProperty('isSelected', true);
- var invalidExist = this.get('allRepositoriesGroup').someProperty('validation', 'icon-exclamation-sign');
- return (selectedStack.get('invalidCnt') > 0) && invalidExist;
- }.property('controller.content.stacks.@each.invalidCnt', 'allRepositoriesGroup.@each.validation'),
- /**
- * If all repo links are unchecked
- * @type {bool}
- */
- allRepoUnchecked: function () {
- return !this.get('allRepositoriesGroup').someProperty('checked', true);
- }.property('allRepositoriesGroup.@each.checked'),
- /**
- * Overall errors count
- * @type {number}
- */
- totalErrorCnt: function () {
- var emptyCnt = this.get('allRepositoriesGroup').filterProperty('empty-error', true).length;
- var invalidCnt = this.get('allRepositoriesGroup').filterProperty('validation', 'icon-exclamation-sign').length;
- if (this.get('allRepoUnchecked')) {
- return 1;
- } else if (emptyCnt || invalidCnt) {
- return emptyCnt + invalidCnt;
- } else {
- return 0;
- }
- }.property('allRepositoriesGroup.@each.empty-error', 'allRepoUnchecked', 'allRepositoriesGroup.@each.validation'),
- /**
- * Is Repositories Accordion collapsed
- * @type {bool}
- */
- isRLCollapsed: true,
- /**
- * Checked flags for each repo-checkbox
- * @type {bool[]}
- */
- allGroupsCheckbox: [true, true, true],
- /**
- * Skip repo-validation
- * @type {bool}
- */
- skipValidationChecked: false,
- didInsertElement: function () {
- if (this.get('isRLCollapsed')) {
- this.$('.accordion-body').hide();
- }
- $("[rel=skip-validation-tooltip]").tooltip({ placement: 'right'});
- },
- /**
- * Checkbox for each stack
- * @type {Ember.Checkbox}
- */
- stackRadioButton: Em.Checkbox.extend({
- tagName: 'input',
- attributeBindings: [ 'type', 'checked' ],
- checked: function () {
- return this.get('content.isSelected');
- }.property('content.isSelected'),
- type: 'radio',
- click: function () {
- this.get('controller.content.stacks').setEach('isSelected', false);
- this.get('controller.content.stacks').findProperty('name', this.get('content.name').replace(' ', '-')).set('isSelected', true);
- }
- }),
- /**
- * Popover for repo-url error indicator
- * @type {Em.View}
- */
- popoverView: Em.View.extend({
- tagName: 'i',
- classNameBindings: ['repoGroup.validation'],
- attributeBindings: ['repoGroup.errorTitle:title', 'repoGroup.errorContent:data-content'],
- didInsertElement: function () {
- App.popover($(this.get('element')), {'trigger': 'hover'});
- }
- }),
- /**
- * Onclick handler for Config Group Header. Used to show/hide block
- * @method onToggleBlock
- */
- onToggleBlock: function () {
- this.$('.accordion-body').toggle('blind', 500);
- this.set('isRLCollapsed', !this.get('isRLCollapsed'));
- },
- /**
- * Format repo-group values and set it to <code>allRepositoriesGroup</code>
- * @method loadRepositories
- */
- loadRepositories: function () {
- var selectedStack = this.get('controller.content.stacks').findProperty('isSelected', true);
- var reposGroup = [
- [],
- [],
- []
- ];
- if (App.get('supports.ubuntu')) reposGroup.push([]); // @todo: remove after Ubuntu support confirmation
- var self = this;
- if (selectedStack && selectedStack.operatingSystems) {
- selectedStack.operatingSystems.forEach(function (os) {
- var cur_repo = Em.Object.create({
- baseUrl: os.baseUrl
- });
- switch (os.osType) {
- case 'redhat5':
- cur_repo.set('osType', 'Red Hat 5');
- reposGroup[0][0] = cur_repo;
- // set group 0 properties by redhat5 (any of the three is ok)
- self.setGroupByOs(reposGroup[0], os, 0);
- break;
- case 'centos5':
- cur_repo.set('osType', 'CentOS 5');
- reposGroup[0][1] = cur_repo;
- break;
- case 'oraclelinux5':
- cur_repo.set('osType', 'Oracle Linux 5');
- reposGroup[0][2] = cur_repo;
- break;
- case 'redhat6':
- cur_repo.set('osType', 'Red Hat 6');
- reposGroup[1][0] = cur_repo;
- // set group 1 properties by redhat6 (any of the three is ok)
- self.setGroupByOs(reposGroup[1], os, 1);
- break;
- case 'centos6':
- cur_repo.set('osType', 'CentOS 6');
- reposGroup[1][1] = cur_repo;
- break;
- case 'oraclelinux6':
- cur_repo.set('osType', 'Oracle Linux 6');
- reposGroup[1][2] = cur_repo;
- break;
- case 'sles11':
- cur_repo.set('osType', 'SLES 11');
- reposGroup[2][0] = cur_repo;
- // set group 2 properties by sles11 (any of the twe is ok)
- self.setGroupByOs(reposGroup[2], os, 2);
- break;
- case 'suse11':
- cur_repo.set('osType', 'SUSE 11');
- reposGroup[2][1] = cur_repo;
- break;
- case 'ubuntu12':
- if (App.get('supports.ubuntu')) {
- cur_repo.set('osType', 'Ubuntu 12');
- reposGroup[3][0] = cur_repo;
- self.setGroupByOs(reposGroup[3], os, 3);
- }
- break;
- }
- });
- }
- this.set('allRepositoriesGroup', reposGroup);
- }.observes('controller.content.stacks.@each.isSelected', 'controller.content.stacks.@each.reload'),
- /**
- * Set group parameters according to operation system
- * @method setGroupByOs
- * @param {Ember.Object} group
- * @param {Object} os
- * @param {number} groupNumber
- */
- setGroupByOs: function (group, os, groupNumber) {
- var isChecked = this.get('allGroupsCheckbox')[groupNumber];
- group.set('checked', isChecked);
- group.set('baseUrl', os.baseUrl);
- group.set('latestBaseUrl', os.latestBaseUrl);
- group.set('defaultBaseUrl', os.defaultBaseUrl);
- group.set('empty-error', !os.baseUrl);
- group.set('invalid-error', os.validation == 'icon-exclamation-sign');
- group.set('validation', os.validation);
- group.set('undo', os.baseUrl != os.latestBaseUrl);
- group.set('clearAll', os.baseUrl);
- group.set('errorTitle', os.errorTitle);
- group.set('errorContent', os.errorContent);
- group.set('group-number', groupNumber);
- },
- /**
- * Onclick handler for checkbox of each repo group
- * @method updateByCheckbox
- */
- updateByCheckbox: function () {
- //upload to content
- var groups = this.get('allRepositoriesGroup');
- var self = this;
- var selectedStack = this.get('controller.content.stacks').findProperty('isSelected', true);
- if (selectedStack && selectedStack.operatingSystems) {
- selectedStack.operatingSystems.forEach(function (os) {
- var groupNumber = self.osTypeToGroup(os.osType);
- var targetGroup = groups.findProperty('group-number', groupNumber);
- if (!targetGroup.get('checked')) {
- os.baseUrl = os.latestBaseUrl;
- os.validation = null;
- os.selected = false;
- targetGroup.set('baseUrl', os.latestBaseUrl);
- targetGroup.set('latestBaseUrl', os.latestBaseUrl);
- targetGroup.set('undo', targetGroup.get('baseUrl') != targetGroup.get('latestBaseUrl'));
- targetGroup.set('invalid-error', false);
- targetGroup.set('validation', null);
- targetGroup.set('clearAll', false);
- targetGroup.set('empty-error', !targetGroup.get('baseUrl'));
- self.get('allGroupsCheckbox')[groupNumber] = false;
- self.set('allGroupsCheckbox', self.get('allGroupsCheckbox'));
- } else {
- os.selected = true;
- os.skipValidation = self.get('skipValidationChecked');
- if (os.skipValidation) {
- targetGroup.set('validation', null);
- targetGroup.set('invalid-error', false);
- }
- targetGroup.set('clearAll', targetGroup.get('baseUrl'));
- targetGroup.set('empty-error', !targetGroup.get('baseUrl'));
- self.get('allGroupsCheckbox')[groupNumber] = true;
- }
- });
- }
- }.observes('allRepositoriesGroup.@each.checked', 'skipValidationChecked'),
- /**
- * Onclick handler for undo action of each repo group
- * @method undoGroupLocalRepository
- * @param {object} event
- */
- undoGroupLocalRepository: function (event) {
- this.doActionForGroupLocalRepository(event, 'latestBaseUrl');
- },
- /**
- * Handler for clear icon click
- * @method clearGroupLocalRepository
- * @param {object} event
- */
- clearGroupLocalRepository: function (event) {
- this.doActionForGroupLocalRepository(event, '');
- },
- /**
- * Common handler for repo groups actions
- * @method doActionForGroupLocalRepository
- * @param {object} event
- * @param {string} newBaseUrlField
- */
- doActionForGroupLocalRepository: function (event, newBaseUrlField) {
- var osTypes = this.groupToOsType(event.context.get('group-number'));
- var selectedStack = this.get('controller.content.stacks').findProperty('isSelected', true);
- osTypes.forEach(function (os) {
- var cos = selectedStack.operatingSystems.findProperty('osType', os);
- cos.baseUrl = Em.isEmpty(newBaseUrlField) ? '' : Em.get(cos, newBaseUrlField);
- cos.validation = null;
- });
- this.loadRepositories();
- },
- /**
- * Handler when editing any repo group BaseUrl
- * @method editGroupLocalRepository
- */
- editGroupLocalRepository: function () {
- //upload to content
- var groups = this.get('allRepositoriesGroup');
- var self = this;
- var selectedStack = this.get('controller.content.stacks').findProperty('isSelected', true);
- if (selectedStack && selectedStack.operatingSystems) {
- selectedStack.operatingSystems.forEach(function (os) {
- var targetGroup = groups.findProperty('group-number', self.osTypeToGroup(os.osType));
- if (os.baseUrl != targetGroup.get('baseUrl')) {
- os.baseUrl = targetGroup.get('baseUrl');
- os.validation = null;
- targetGroup.set('undo', targetGroup.get('baseUrl') != targetGroup.get('latestBaseUrl'));
- targetGroup.set('invalid-error', false);
- targetGroup.set('validation', null);
- targetGroup.set('clearAll', os.baseUrl);
- targetGroup.set('empty-error', !targetGroup.get('baseUrl'));
- }
- });
- }
- }.observes('allRepositoriesGroup.@each.baseUrl'),
- /**
- * Get list of OS for provided group number
- * @method groupToOsType
- * @param {number} groupNumber
- * @returns {Array}
- */
- groupToOsType: function (groupNumber) {
- return Em.getWithDefault({
- '0': ['redhat5', 'centos5', 'oraclelinux5'],
- '1': ['redhat6', 'centos6', 'oraclelinux6'],
- '2': ['sles11', 'suse11'],
- '3': ['ubuntu12']
- }, groupNumber.toString(), []);
- },
- /**
- * Get group number for provided OS
- * @method osTypeToGroup
- * @param {string} osType
- * @returns {number}
- */
- osTypeToGroup: function (osType) {
- return Em.getWithDefault({
- 'redhat5': 0,
- 'centos5': 0,
- 'oraclelinux5': 0,
- 'redhat6': 1,
- 'centos6': 1,
- 'oraclelinux6': 1,
- 'sles11': 2,
- 'suse11': 2,
- 'ubuntu12': 3
- }, osType, -1);
- }
- });
|