controls_view.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. /**
  20. * Abstract view for config fields.
  21. * Add popover support to control
  22. */
  23. App.ServiceConfigPopoverSupport = Ember.Mixin.create({
  24. /**
  25. * Config object. It will instance of App.ServiceConfigProperty
  26. */
  27. serviceConfig: null,
  28. placeholderBinding: 'serviceConfig.defaultValue',
  29. isPopoverEnabled: true,
  30. didInsertElement: function () {
  31. if (this.get('isPopoverEnabled') !== 'false') {
  32. App.popover(this.$(), {
  33. title: Em.I18n.t('installer.controls.serviceConfigPopover.title').format(this.get('serviceConfig.displayName'), this.get('serviceConfig.name')),
  34. content: this.get('serviceConfig.description'),
  35. placement: 'right',
  36. trigger: 'hover'
  37. });
  38. }
  39. }
  40. });
  41. /**
  42. * Default input control
  43. * @type {*}
  44. */
  45. App.ServiceConfigTextField = Ember.TextField.extend(App.ServiceConfigPopoverSupport, {
  46. valueBinding: 'serviceConfig.value',
  47. classNameBindings: 'textFieldClassName',
  48. placeholderBinding: 'serviceConfig.defaultValue',
  49. keyPress: function (event) {
  50. if (event.keyCode == 13) {
  51. return false;
  52. }
  53. },
  54. //Set editDone true for last edited config text field parameter
  55. focusOut: function(event){
  56. this.get('serviceConfig').set("editDone", true);
  57. },
  58. //Set editDone false for all current category config text field parameter
  59. focusIn: function(event){
  60. this.get("parentView.categoryConfigsAll").setEach("editDone", false);
  61. },
  62. textFieldClassName: function () {
  63. // sets the width of the field depending on display type
  64. if (['directory', 'url', 'email', 'user', 'host','advanced'].contains(this.get('serviceConfig.displayType'))) {
  65. return ['span9'];
  66. } else if (this.get('serviceConfig.displayType') === 'principal'){
  67. return ['span12'];
  68. } else {
  69. return ['input-small'];
  70. }
  71. }.property('serviceConfig.displayType'),
  72. disabled: function () {
  73. return !this.get('serviceConfig.isEditable');
  74. }.property('serviceConfig.isEditable')
  75. });
  76. /**
  77. * Customized input control with Utits type specified
  78. * @type {*}
  79. */
  80. App.ServiceConfigTextFieldWithUnit = Ember.View.extend(App.ServiceConfigPopoverSupport, {
  81. valueBinding: 'serviceConfig.value',
  82. classNames: ['input-append','with-unit'],
  83. placeholderBinding: 'serviceConfig.defaultValue',
  84. template: Ember.Handlebars.compile('{{view App.ServiceConfigTextField serviceConfigBinding="view.serviceConfig" isPopoverEnabled="false"}}<span class="add-on">{{view.serviceConfig.unit}}</span>'),
  85. disabled: function () {
  86. return !this.get('serviceConfig.isEditable');
  87. }.property('serviceConfig.isEditable')
  88. });
  89. /**
  90. * Password control
  91. * @type {*}
  92. */
  93. App.ServiceConfigPasswordField = Ember.TextField.extend({
  94. serviceConfig: null,
  95. type: 'password',
  96. valueBinding: 'serviceConfig.value',
  97. classNames: [ 'span4' ],
  98. placeholder: Em.I18n.t('form.item.placeholders.typePassword'),
  99. template: Ember.Handlebars.compile('{{view view.retypePasswordView}}'),
  100. keyPress: function (event) {
  101. if (event.keyCode == 13) {
  102. return false;
  103. }
  104. },
  105. retypePasswordView: Ember.TextField.extend({
  106. placeholder: Em.I18n.t('form.passwordRetype'),
  107. type: 'password',
  108. classNames: [ 'span4', 'retyped-password' ],
  109. keyPress: function (event) {
  110. if (event.keyCode == 13) {
  111. return false;
  112. }
  113. },
  114. valueBinding: 'parentView.serviceConfig.retypedPassword',
  115. disabled: function () {
  116. return !this.get('parentView.serviceConfig.isEditable');
  117. }.property('parentView.serviceConfig.isEditable')
  118. }),
  119. disabled: function () {
  120. return !this.get('serviceConfig.isEditable');
  121. }.property('serviceConfig.isEditable')
  122. });
  123. /**
  124. * Textarea control
  125. * @type {*}
  126. */
  127. App.ServiceConfigTextArea = Ember.TextArea.extend(App.ServiceConfigPopoverSupport, {
  128. valueBinding: 'serviceConfig.value',
  129. rows: 4,
  130. classNames: ['span9', 'directories'],
  131. placeholderBinding: 'serviceConfig.defaultValue',
  132. disabled: function () {
  133. return !this.get('serviceConfig.isEditable');
  134. }.property('serviceConfig.isEditable')
  135. });
  136. /**
  137. * Textarea control with bigger height
  138. * @type {*}
  139. */
  140. App.ServiceConfigBigTextArea = App.ServiceConfigTextArea.extend({
  141. rows: 10
  142. });
  143. /**
  144. * Checkbox control
  145. * @type {*}
  146. */
  147. App.ServiceConfigCheckbox = Ember.Checkbox.extend(App.ServiceConfigPopoverSupport, {
  148. checkedBinding: 'serviceConfig.value',
  149. disabled: function () {
  150. return !this.get('serviceConfig.isEditable');
  151. }.property('serviceConfig.isEditable')
  152. });
  153. App.ServiceConfigRadioButtons = Ember.View.extend({
  154. template: Ember.Handlebars.compile([
  155. '{{#each option in view.options}}',
  156. '{{#unless option.hidden}}',
  157. '<label class="radio">',
  158. '{{#view App.ServiceConfigRadioButton nameBinding = "view.name" valueBinding = "option.displayName"}}',
  159. '{{/view}}',
  160. '{{option.displayName}} &nbsp;',
  161. '</label>',
  162. '{{/unless}}',
  163. '{{/each}}'
  164. ].join('\n')),
  165. didInsertElement: function () {
  166. // on page render, automatically populate JDBC URLs only for default database settings
  167. // so as to not lose the user's customizations on these fields
  168. if (App.clusterStatus.clusterState == 'CLUSTER_NOT_CREATED_1' && ['New MySQL Database', 'New Derby Database'].contains(this.get('serviceConfig.value'))) {
  169. this.onOptionsChange();
  170. }
  171. },
  172. configs: function () {
  173. return this.get('categoryConfigsAll').filterProperty('isObserved', true);
  174. }.property('categoryConfigsAll'),
  175. serviceConfig: null,
  176. categoryConfigsAll: null,
  177. onOptionsChange: function () {
  178. var connectionUrl = this.get('connectionUrl');
  179. if (connectionUrl) {
  180. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  181. switch (this.get('serviceConfig.value')) {
  182. case 'New MySQL Database':
  183. case 'Existing MySQL Database':
  184. connectionUrl.set('value', "jdbc:mysql://" + this.get('hostName') + "/" + this.get('databaseName') + "?createDatabaseIfNotExist=true");
  185. break;
  186. case 'Existing Oracle Database':
  187. connectionUrl.set('value', "jdbc:oracle:thin:@//" + this.get('hostName') + ":1521/" + this.get('databaseName'));
  188. break;
  189. }
  190. } else if (this.get('serviceConfig.serviceName') === 'OOZIE') {
  191. switch (this.get('serviceConfig.value')) {
  192. case 'New Derby Database':
  193. connectionUrl.set('value', "jdbc:derby:${oozie.data.dir}/${oozie.db.schema.name}-db;create=true");
  194. break;
  195. case 'Existing MySQL Database':
  196. connectionUrl.set('value', "jdbc:mysql://" + this.get('hostName') + "/" + this.get('databaseName'));
  197. break;
  198. case 'Existing Oracle Database':
  199. connectionUrl.set('value', "jdbc:oracle:thin:@//" + this.get('hostName') + ":1521/" + this.get('databaseName'));
  200. break;
  201. }
  202. }
  203. connectionUrl.set('defaultValue', connectionUrl.get('value'));
  204. }
  205. }.observes('databaseName', 'hostName', 'connectionUrl'),
  206. nameBinding: 'serviceConfig.radioName',
  207. databaseName: function () {
  208. switch (this.get('serviceConfig.serviceName')) {
  209. case 'HIVE':
  210. return this.get('categoryConfigsAll').findProperty('name', 'hive_database_name').get('value');
  211. case 'OOZIE':
  212. return this.get('categoryConfigsAll').findProperty('name', 'oozie_database_name').get('value');
  213. default:
  214. return null;
  215. }
  216. }.property('configs.@each.value', 'serviceConfig.serviceName'),
  217. hostName: function () {
  218. var value = this.get('serviceConfig.value');
  219. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  220. switch (value) {
  221. case 'New MySQL Database':
  222. return this.get('categoryConfigsAll').findProperty('name', 'hive_ambari_host').get('value');
  223. case 'Existing MySQL Database':
  224. return this.get('categoryConfigsAll').findProperty('name', 'hive_existing_mysql_host').get('value');
  225. case 'Existing Oracle Database':
  226. return this.get('categoryConfigsAll').findProperty('name', 'hive_existing_oracle_host').get('value');
  227. }
  228. } else if (this.get('serviceConfig.serviceName') === 'OOZIE') {
  229. switch (value) {
  230. case 'New Derby Database':
  231. return this.get('categoryConfigsAll').findProperty('name', 'oozie_ambari_host').get('value');
  232. case 'Existing MySQL Database':
  233. return this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_mysql_host').get('value');
  234. case 'Existing Oracle Database':
  235. return this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_oracle_host').get('value');
  236. }
  237. }
  238. }.property('serviceConfig.serviceName', 'serviceConfig.value', 'configs.@each.value'),
  239. connectionUrl: function () {
  240. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  241. return this.get('categoryConfigsAll').findProperty('name', 'hive_jdbc_connection_url');
  242. } else {
  243. return this.get('categoryConfigsAll').findProperty('name', 'oozie_jdbc_connection_url');
  244. }
  245. }.property('serviceConfig.serviceName'),
  246. optionsBinding: 'serviceConfig.options',
  247. disabled: function () {
  248. return !this.get('serviceConfig.isEditable');
  249. }.property('serviceConfig.isEditable')
  250. });
  251. App.ServiceConfigRadioButton = Ember.Checkbox.extend({
  252. tagName: 'input',
  253. attributeBindings: ['type', 'name', 'value', 'checked'],
  254. checked: false,
  255. type: 'radio',
  256. name: null,
  257. value: null,
  258. didInsertElement: function () {
  259. if (this.get('parentView.serviceConfig.value') === this.get('value')) {
  260. this.set('checked', true);
  261. }
  262. },
  263. click: function () {
  264. this.set('checked', true);
  265. this.onChecked();
  266. },
  267. onChecked: function () {
  268. this.set('parentView.serviceConfig.value', this.get('value'));
  269. var components = this.get('parentView.serviceConfig.options');
  270. components
  271. .forEach(function (_component) {
  272. if (_component.foreignKeys) {
  273. _component.foreignKeys.forEach(function (_componentName) {
  274. if (this.get('parentView.categoryConfigsAll').someProperty('name', _componentName)) {
  275. var component = this.get('parentView.categoryConfigsAll').findProperty('name', _componentName);
  276. if (_component.displayName === this.get('value')) {
  277. component.set('isVisible', true);
  278. } else {
  279. component.set('isVisible', false);
  280. }
  281. }
  282. }, this);
  283. }
  284. }, this);
  285. }.observes('checked'),
  286. disabled: function () {
  287. return !this.get('parentView.serviceConfig.isEditable');
  288. }.property('parentView.serviceConfig.isEditable')
  289. });
  290. App.ServiceConfigComboBox = Ember.Select.extend(App.ServiceConfigPopoverSupport, {
  291. contentBinding: 'serviceConfig.options',
  292. selectionBinding: 'serviceConfig.value',
  293. classNames: [ 'span3' ],
  294. disabled: function () {
  295. return !this.get('serviceConfig.isEditable');
  296. }.property('serviceConfig.isEditable')
  297. });
  298. /**
  299. * Base component for host config with popover support
  300. */
  301. App.ServiceConfigHostPopoverSupport = Ember.Mixin.create({
  302. /**
  303. * Config object. It will instance of App.ServiceConfigProperty
  304. */
  305. serviceConfig: null,
  306. didInsertElement: function () {
  307. App.popover(this.$(), {
  308. title: this.get('serviceConfig.displayName'),
  309. content: this.get('serviceConfig.description'),
  310. placement: 'right',
  311. trigger: 'hover'
  312. });
  313. }
  314. });
  315. /**
  316. * Master host component.
  317. * Show hostname without ability to edit it
  318. * @type {*}
  319. */
  320. App.ServiceConfigMasterHostView = Ember.View.extend(App.ServiceConfigHostPopoverSupport, {
  321. classNames: ['master-host', 'span6'],
  322. valueBinding: 'serviceConfig.value',
  323. template: Ember.Handlebars.compile('{{value}}')
  324. });
  325. /**
  326. * Base component to display Multiple hosts
  327. * @type {*}
  328. */
  329. App.ServiceConfigMultipleHostsDisplay = Ember.Mixin.create(App.ServiceConfigHostPopoverSupport, {
  330. hasNoHosts: function () {
  331. console.log('view', this.get('viewName')); //to know which View cause errors
  332. console.log('controller', this.get('controller').name); //should be slaveComponentGroupsController
  333. if (!this.get('value')) {
  334. return true;
  335. }
  336. return this.get('value').length === 0;
  337. }.property('value'),
  338. hasOneHost: function () {
  339. return this.get('value').length === 1;
  340. }.property('value'),
  341. hasMultipleHosts: function () {
  342. return this.get('value').length > 1;
  343. }.property('value'),
  344. otherLength: function () {
  345. var len = this.get('value').length;
  346. if (len > 2) {
  347. return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.others').format(len - 1);
  348. } else {
  349. return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.other');
  350. }
  351. }.property('value')
  352. })
  353. /**
  354. * Multiple master host component.
  355. * Show hostnames without ability to edit it
  356. * @type {*}
  357. */
  358. App.ServiceConfigMasterHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, {
  359. viewName: "serviceConfigMasterHostsView",
  360. valueBinding: 'serviceConfig.value',
  361. classNames: ['master-hosts', 'span6'],
  362. templateName: require('templates/wizard/master_hosts'),
  363. /**
  364. * Onclick handler for link
  365. */
  366. showHosts: function () {
  367. var serviceConfig = this.get('serviceConfig');
  368. App.ModalPopup.show({
  369. header: Em.I18n.t('installer.controls.serviceConfigMasterHosts.header').format(serviceConfig.category),
  370. bodyClass: Ember.View.extend({
  371. serviceConfig: serviceConfig,
  372. templateName: require('templates/wizard/master_hosts_popup')
  373. }),
  374. onPrimary: function () {
  375. this.hide();
  376. },
  377. secondary: null
  378. });
  379. }
  380. });
  381. /**
  382. * Show tabs list for slave hosts
  383. * @type {*}
  384. */
  385. App.SlaveComponentGroupsMenu = Em.CollectionView.extend({
  386. content: function () {
  387. return this.get('controller.componentGroups');
  388. }.property('controller.componentGroups'),
  389. tagName: 'ul',
  390. classNames: ["nav", "nav-tabs"],
  391. itemViewClass: Em.View.extend({
  392. classNameBindings: ["active"],
  393. active: function () {
  394. return this.get('content.active');
  395. }.property('content.active'),
  396. errorCount: function () {
  397. return this.get('content.properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  398. }.property('content.properties.@each.isValid', 'content.properties.@each.isVisible'),
  399. template: Ember.Handlebars.compile('<a {{action showSlaveComponentGroup view.content target="controller"}} href="#"> {{view.content.name}}{{#if view.errorCount}}<span class="badge badge-important">{{view.errorCount}}</span>{{/if}}</a><i {{action removeSlaveComponentGroup view.content target="controller"}} class="icon-remove"></i>')
  400. })
  401. });
  402. /**
  403. * <code>Add group</code> button
  404. * @type {*}
  405. */
  406. App.AddSlaveComponentGroupButton = Ember.View.extend({
  407. tagName: 'span',
  408. slaveComponentName: null,
  409. didInsertElement: function () {
  410. App.popover(this.$(), {
  411. title: Em.I18n.t('installer.controls.addSlaveComponentGroupButton.title').format(this.get('slaveComponentName')),
  412. content: Em.I18n.t('installer.controls.addSlaveComponentGroupButton.content').format(this.get('slaveComponentName'), this.get('slaveComponentName'), this.get('slaveComponentName')),
  413. placement: 'right',
  414. trigger: 'hover'
  415. });
  416. }
  417. });
  418. /**
  419. * Multiple Slave Hosts component
  420. * @type {*}
  421. */
  422. App.ServiceConfigSlaveHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, {
  423. viewName: 'serviceConfigSlaveHostsView',
  424. classNames: ['slave-hosts', 'span6'],
  425. valueBinding: 'serviceConfig.value',
  426. templateName: require('templates/wizard/slave_hosts'),
  427. /**
  428. * Onclick handler for link
  429. */
  430. showHosts: function () {
  431. var serviceConfig = this.get('serviceConfig');
  432. App.ModalPopup.show({
  433. header: Em.I18n.t('installer.controls.serviceConfigMasterHosts.header').format(serviceConfig.category),
  434. bodyClass: Ember.View.extend({
  435. serviceConfig: serviceConfig,
  436. templateName: require('templates/wizard/master_hosts_popup')
  437. }),
  438. onPrimary: function () {
  439. this.hide();
  440. },
  441. secondary: null
  442. });
  443. }
  444. });
  445. /**
  446. * properties for present active slave group
  447. * @type {*}
  448. */
  449. App.SlaveGroupPropertiesView = Ember.View.extend({
  450. viewName: 'serviceConfigSlaveHostsView',
  451. group: function () {
  452. return this.get('controller.activeGroup');
  453. }.property('controller.activeGroup'),
  454. groupConfigs: function () {
  455. console.log("************************************************************************");
  456. console.log("The value of group is: " + this.get('group'));
  457. console.log("************************************************************************");
  458. return this.get('group.properties');
  459. }.property('group.properties.@each').cacheable(),
  460. errorCount: function () {
  461. return this.get('group.properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  462. }.property('configs.@each.isValid', 'configs.@each.isVisible')
  463. });
  464. /**
  465. * DropDown component for <code>select hosts for groups</code> popup
  466. * @type {*}
  467. */
  468. App.SlaveComponentDropDownGroupView = Ember.View.extend({
  469. viewName: "slaveComponentDropDownGroupView",
  470. /**
  471. * On change handler for <code>select hosts for groups</code> popup
  472. * @param event
  473. */
  474. changeGroup: function (event) {
  475. var host = this.get('content');
  476. var groupName = $('#' + this.get('elementId') + ' select').val();
  477. this.get('controller').changeHostGroup(host, groupName);
  478. },
  479. optionTag: Ember.View.extend({
  480. /**
  481. * Whether current value(OptionTag value) equals to host value(assigned to SlaveComponentDropDownGroupView.content)
  482. */
  483. selected: function () {
  484. return this.get('parentView.content.group') === this.get('content');
  485. }.property('content')
  486. })
  487. });
  488. /**
  489. * Show info about current group
  490. * @type {*}
  491. */
  492. App.SlaveComponentChangeGroupNameView = Ember.View.extend({
  493. contentBinding: 'controller.activeGroup',
  494. classNames: ['control-group'],
  495. classNameBindings: 'error',
  496. error: false,
  497. setError: function () {
  498. this.set('error', false);
  499. }.observes('controller.activeGroup'),
  500. errorMessage: function () {
  501. return this.get('error') ? Em.I18n.t('installer.controls.slaveComponentChangeGroupName.error') : '';
  502. }.property('error'),
  503. /**
  504. * Onclick handler for saving updated group name
  505. * @param event
  506. */
  507. changeGroupName: function (event) {
  508. var inputVal = $('#' + this.get('elementId') + ' input[type="text"]').val();
  509. if (inputVal !== this.get('content.name')) {
  510. var result = this.get('controller').changeSlaveGroupName(this.get('content'), inputVal);
  511. this.set('error', result);
  512. }
  513. }
  514. });