hostWarningPopupBody_view.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. var lazyloading = require('utils/lazy_loading');
  20. var numberUtils = require('utils/number_utils');
  21. App.WizardStep3HostWarningPopupBody = Em.View.extend({
  22. templateName: require('templates/wizard/step3/step3_host_warnings_popup'),
  23. classNames: ['host-check'],
  24. bodyControllerBinding: 'App.router.wizardStep3Controller',
  25. /**
  26. * Listbox with host filters
  27. * @type {Ember.Select}
  28. */
  29. hostSelectView: Em.Select.extend({
  30. selectionBinding: "parentView.category",
  31. /**
  32. * Content has default value "All Hosts" to bind selection to category
  33. * @type {string[]}
  34. */
  35. content: ['All Hosts'],
  36. /**
  37. * List of filtered hostnames
  38. * @type {string[]}
  39. */
  40. hosts: function () {
  41. var warningsByHost = this.get('parentView.warningsByHost');
  42. if (Em.isNone(warningsByHost)) return [];
  43. return warningsByHost.mapProperty('name');
  44. }.property('parentView.warningsByHost'),
  45. /**
  46. * Is data loaded
  47. * @type {bool}
  48. */
  49. isLoaded: false,
  50. didInsertElement: function () {
  51. this.initContent();
  52. },
  53. /**
  54. * Check browser and set content for listbox
  55. * @method initContent
  56. */
  57. initContent: function () {
  58. this.set('isLoaded', false);
  59. //The lazy loading for select elements supported only by Firefox and Chrome
  60. var isBrowserSupported = $.browser.mozilla || ($.browser.safari && navigator.userAgent.indexOf('Chrome') !== -1);
  61. var isLazyLoading = isBrowserSupported && this.get('hosts').length > 100;
  62. this.set('isLazyLoading', isLazyLoading);
  63. if (isLazyLoading) {
  64. //select need at least 30 hosts to have scrollbar
  65. this.set('content', this.get('hosts').slice(0, 30));
  66. } else {
  67. this.set('content', this.get('hosts'));
  68. this.set('isLoaded', true);
  69. }
  70. }.observes('parentView.warningsByHost'),
  71. /**
  72. * On click start lazy loading
  73. * @method click
  74. */
  75. click: function () {
  76. if (!this.get('isLoaded') && this.get('isLazyLoading')) {
  77. //filter out hosts, which already pushed in select
  78. var source = this.get('hosts').filter(function (_host) {
  79. return !this.get('content').contains(_host);
  80. }, this).slice();
  81. lazyloading.run({
  82. destination: this.get('content'),
  83. source: source,
  84. context: this,
  85. initSize: 30,
  86. chunkSize: 200,
  87. delay: 50
  88. });
  89. }
  90. }
  91. }),
  92. /**
  93. * List of warnings grouped by host
  94. * Same to <code>bodyController.warningsByHost</code>
  95. * @type {Ember.Enumerable}
  96. */
  97. warningsByHost: function () {
  98. return this.get('bodyController.warningsByHost');
  99. }.property('bodyController.warningsByHost'),
  100. /**
  101. * List of all warnings
  102. * Same to <code>bodyController.warnings</code>
  103. * @type {Ember.Enumerable}
  104. */
  105. warnings: function () {
  106. return this.get('bodyController.warnings');
  107. }.property('bodyController.warnings'),
  108. /**
  109. * Selected category
  110. * @type {string}
  111. */
  112. category: 'All Hosts',
  113. /**
  114. * List of warnings for selected <code>category</code>
  115. * @type {Ember.Enumerable}
  116. */
  117. categoryWarnings: function () {
  118. var warningsByHost = this.get('warningsByHost');
  119. if (Em.isNone(warningsByHost)) return [];
  120. return warningsByHost.findProperty('name', this.get('category')).warnings
  121. }.property('warningsByHost', 'category'),
  122. /**
  123. * List of warnings grouped by <code>category</code>
  124. * @type {Ember.Object[]}
  125. */
  126. content: function () {
  127. var hostCheckWarnings = this.get('bodyController.hostCheckWarnings');
  128. var repoCategoryWarnings = this.get('bodyController.repoCategoryWarnings');
  129. var diskCategoryWarnings = this.get('bodyController.diskCategoryWarnings');
  130. var jdkCategoryWarnings = this.get('bodyController.jdkCategoryWarnings') || [];
  131. var categoryWarnings = this.get('categoryWarnings');
  132. return [
  133. Em.Object.create({
  134. warnings: jdkCategoryWarnings,
  135. title: Em.I18n.t('installer.step3.hostWarningsPopup.jdk'),
  136. message: Em.I18n.t('installer.step3.hostWarningsPopup.jdk.message'),
  137. type: Em.I18n.t('common.issues'),
  138. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.jdk'),
  139. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  140. category: 'jdk',
  141. isCollapsed: true
  142. }),
  143. Em.Object.create({
  144. warnings: diskCategoryWarnings,
  145. title: Em.I18n.t('installer.step3.hostWarningsPopup.disk'),
  146. message: Em.I18n.t('installer.step3.hostWarningsPopup.disk.message'),
  147. type: Em.I18n.t('common.issues'),
  148. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.disk'),
  149. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  150. category: 'disk',
  151. isCollapsed: true
  152. }),
  153. Em.Object.create({
  154. warnings: repoCategoryWarnings,
  155. title: Em.I18n.t('installer.step3.hostWarningsPopup.repositories'),
  156. message: Em.I18n.t('installer.step3.hostWarningsPopup.repositories.message'),
  157. type: Em.I18n.t('common.issues'),
  158. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.repositories'),
  159. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.invalid'),
  160. category: 'repositories',
  161. isCollapsed: true
  162. }),
  163. Em.Object.create({
  164. warnings: categoryWarnings.filterProperty('category', 'firewall'),
  165. title: Em.I18n.t('installer.step3.hostWarningsPopup.firewall'),
  166. message: Em.I18n.t('installer.step3.hostWarningsPopup.firewall.message'),
  167. type: Em.I18n.t('common.issues'),
  168. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.firewall'),
  169. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.running'),
  170. category: 'firewall',
  171. isCollapsed: true
  172. }),
  173. Em.Object.create({
  174. warnings: categoryWarnings.filterProperty('category', 'processes'),
  175. title: Em.I18n.t('installer.step3.hostWarningsPopup.process'),
  176. message: Em.I18n.t('installer.step3.hostWarningsPopup.processes.message'),
  177. type: Em.I18n.t('common.process'),
  178. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.processes'),
  179. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.running'),
  180. category: 'process',
  181. isCollapsed: true
  182. }),
  183. Em.Object.create({
  184. warnings: categoryWarnings.filterProperty('category', 'packages'),
  185. title: Em.I18n.t('installer.step3.hostWarningsPopup.package'),
  186. message: Em.I18n.t('installer.step3.hostWarningsPopup.packages.message'),
  187. type: Em.I18n.t('common.package'),
  188. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.packages'),
  189. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.installed'),
  190. category: 'package',
  191. isCollapsed: true
  192. }),
  193. Em.Object.create({
  194. warnings: categoryWarnings.filterProperty('category', 'fileFolders'),
  195. title: Em.I18n.t('installer.step3.hostWarningsPopup.fileAndFolder'),
  196. message: Em.I18n.t('installer.step3.hostWarningsPopup.fileFolders.message'),
  197. type: Em.I18n.t('common.path'),
  198. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.filesAndFolders'),
  199. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  200. category: 'fileFolders',
  201. isCollapsed: true
  202. }),
  203. Em.Object.create({
  204. warnings: categoryWarnings.filterProperty('category', 'services'),
  205. title: Em.I18n.t('installer.step3.hostWarningsPopup.service'),
  206. message: Em.I18n.t('installer.step3.hostWarningsPopup.services.message'),
  207. type: Em.I18n.t('common.service'),
  208. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.services'),
  209. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.notRunning'),
  210. category: 'service',
  211. isCollapsed: true
  212. }),
  213. Em.Object.create({
  214. warnings: categoryWarnings.filterProperty('category', 'users'),
  215. title: Em.I18n.t('installer.step3.hostWarningsPopup.user'),
  216. message: Em.I18n.t('installer.step3.hostWarningsPopup.users.message'),
  217. type: Em.I18n.t('common.user'),
  218. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.users'),
  219. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  220. category: 'user',
  221. isCollapsed: true
  222. }),
  223. Em.Object.create({
  224. warnings: categoryWarnings.filterProperty('category', 'misc'),
  225. title: Em.I18n.t('installer.step3.hostWarningsPopup.misc'),
  226. message: Em.I18n.t('installer.step3.hostWarningsPopup.misc.message'),
  227. type: Em.I18n.t('installer.step3.hostWarningsPopup.misc.umask'),
  228. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.empty.misc'),
  229. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  230. category: 'misc',
  231. isCollapsed: true
  232. }),
  233. Em.Object.create({
  234. warnings: categoryWarnings.filterProperty('category', 'alternatives'),
  235. title: Em.I18n.t('installer.step3.hostWarningsPopup.alternatives'),
  236. message: Em.I18n.t('installer.step3.hostWarningsPopup.alternatives.message'),
  237. type: Em.I18n.t('installer.step3.hostWarningsPopup.alternatives.umask'),
  238. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.alternatives.empty'),
  239. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.exists'),
  240. category: 'alternatives',
  241. isCollapsed: true
  242. }),
  243. Em.Object.create({
  244. warnings: categoryWarnings.filterProperty('category', 'reverseLookup'),
  245. title: Em.I18n.t('installer.step3.hostWarningsPopup.reverseLookup'),
  246. message: Em.I18n.t('installer.step3.hostWarningsPopup.reverseLookup.message'),
  247. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.reverseLookup.empty'),
  248. category: 'reverseLookup',
  249. isCollapsed: true
  250. }),
  251. Em.Object.create({
  252. warnings: hostCheckWarnings,
  253. title: Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.name'),
  254. message: Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.message'),
  255. type: Em.I18n.t('common.issues'),
  256. emptyName: Em.I18n.t('installer.step3.hostWarningsPopup.resolution.validation.empty'),
  257. action: Em.I18n.t('installer.step3.hostWarningsPopup.action.failed'),
  258. category: 'hostNameResolution',
  259. isCollapsed: true
  260. })
  261. ]
  262. }.property('category', 'warningsByHost', 'bodyController.jdkCategoryWarnings', 'bodyController.repoCategoryWarnings', 'bodyController.diskCategoryWarnings', 'bodyController.hostCheckWarnings'),
  263. /**
  264. * Message with info about warnings
  265. * @return {string}
  266. */
  267. warningsNotice: function () {
  268. var issuesNumber = this.get('warnings.length') + this.get('bodyController.repoCategoryWarnings.length') + this.get('bodyController.diskCategoryWarnings.length')
  269. + this.get('bodyController.jdkCategoryWarnings.length') + this.get('bodyController.hostCheckWarnings.length');
  270. var issues = issuesNumber + ' ' + (issuesNumber.length === 1 ? Em.I18n.t('installer.step3.hostWarningsPopup.issue') : Em.I18n.t('installer.step3.hostWarningsPopup.issues'));
  271. var hostsCnt = this.warningHostsNamesCount();
  272. var hosts = hostsCnt + ' ' + (hostsCnt === 1 ? Em.I18n.t('installer.step3.hostWarningsPopup.host') : Em.I18n.t('installer.step3.hostWarningsPopup.hosts'));
  273. return Em.I18n.t('installer.step3.hostWarningsPopup.summary').format(issues, hosts);
  274. }.property('warnings', 'warningsByHost', 'bodyController.jdkCategoryWarnings', 'bodyController.repoCategoryWarnings', 'bodyController.diskCategoryWarnings', 'bodyController.hostCheckWarnings'),
  275. /**
  276. * Detailed content to show it in new window
  277. * @return {string}
  278. */
  279. contentInDetails: function () {
  280. var content = this.get('content');
  281. var warningsByHost = this.get('warningsByHost').slice();
  282. warningsByHost.shift();
  283. var newContent = '';
  284. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.header') + new Date;
  285. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.hosts');
  286. newContent += warningsByHost.filterProperty('warnings.length').mapProperty('name').join(' ');
  287. if (content.findProperty('category', 'firewall').warnings.length) {
  288. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.firewall');
  289. newContent += content.findProperty('category', 'firewall').warnings.mapProperty('name').join('<br>');
  290. }
  291. if (content.findProperty('category', 'fileFolders').warnings.length) {
  292. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.fileFolders');
  293. newContent += content.findProperty('category', 'fileFolders').warnings.mapProperty('name').join(' ');
  294. }
  295. if (content.findProperty('category', 'reverseLookup').warnings.length) {
  296. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.reverseLookup');
  297. newContent += content.findProperty('category', 'reverseLookup').warnings[0].hosts.join(' ');
  298. }
  299. if (content.findProperty('category', 'process').warnings.length) {
  300. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.process');
  301. content.findProperty('category', 'process').warnings.forEach(function (process, i) {
  302. process.hosts.forEach(function (host, j) {
  303. if (!!i || !!j) {
  304. newContent += ',';
  305. }
  306. newContent += '(' + host + ',' + process.user + ',' + process.pid + ')';
  307. });
  308. });
  309. }
  310. if (content.findProperty('category', 'package').warnings.length) {
  311. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.package');
  312. newContent += content.findProperty('category', 'package').warnings.mapProperty('name').join(' ');
  313. }
  314. if (content.findProperty('category', 'service').warnings.length) {
  315. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.service');
  316. newContent += content.findProperty('category', 'service').warnings.mapProperty('name').join(' ');
  317. }
  318. if (content.findProperty('category', 'user').warnings.length) {
  319. newContent += Em.I18n.t('installer.step3.hostWarningsPopup.report.user');
  320. newContent += content.findProperty('category', 'user').warnings.mapProperty('name').join(' ');
  321. }
  322. newContent += '</p>';
  323. return newContent;
  324. }.property('content', 'warningsByHost'),
  325. didInsertElement: function () {
  326. Em.run.next(this, function () {
  327. App.tooltip(this.$("[rel='HostsListTooltip']"), {html: true, placement: "right"});
  328. App.tooltip(this.$('#process .warning-name'), {html: true, placement: "top"});
  329. });
  330. }.observes('content'),
  331. /**
  332. * Show popup with selected hostnames
  333. * @param {object} hosts
  334. * @method showHostsPopup
  335. * @return {App.ModalPopup}
  336. */
  337. showHostsPopup: function (hosts) {
  338. $('.tooltip').hide();
  339. return App.ModalPopup.show({
  340. header: Em.I18n.t('installer.step3.hostWarningsPopup.allHosts'),
  341. bodyClass: Em.View.extend({
  342. hosts: hosts.context,
  343. template: Em.Handlebars.compile('<ul>{{#each host in view.hosts}}<li>{{host}}</li>{{/each}}</ul>')
  344. }),
  345. secondary: null
  346. });
  347. },
  348. /**
  349. * Open/Close selected category
  350. * @param {object} category
  351. * @method onToggleBlock
  352. */
  353. onToggleBlock: function (category) {
  354. this.$('#' + category.context.category).toggle('blind', 500);
  355. category.context.set("isCollapsed", !category.context.get("isCollapsed"));
  356. },
  357. /**
  358. * Generate number of hosts which had warnings, avoid duplicated host names in different warnings.
  359. * @method warningHostsNamesCount
  360. * @return {number}
  361. */
  362. warningHostsNamesCount: function () {
  363. var hostNameMap = Em.Object.create();
  364. if (Em.isNone(this.get('bodyController.warningsByHost'))) return 0;
  365. var warningsByHost = this.get('bodyController.warningsByHost').slice();
  366. warningsByHost.shift();
  367. warningsByHost.forEach(function (_host) {
  368. if (_host.warnings.length) {
  369. hostNameMap[_host.name] = true;
  370. }
  371. });
  372. var repoCategoryWarnings = this.get('bodyController.repoCategoryWarnings');
  373. var diskCategoryWarnings = this.get('bodyController.diskCategoryWarnings');
  374. var jdkCategoryWarnings = this.get('bodyController.jdkCategoryWarnings');
  375. var hostResolutionWarnings = this.get('bodyController.hostCheckWarnings');
  376. if (repoCategoryWarnings.length) {
  377. repoCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  378. if (!hostNameMap[_hostName]) {
  379. hostNameMap[_hostName] = true;
  380. }
  381. });
  382. }
  383. if (diskCategoryWarnings.length) {
  384. diskCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  385. if (!hostNameMap[_hostName]) {
  386. hostNameMap[_hostName] = true;
  387. }
  388. });
  389. }
  390. if (jdkCategoryWarnings && jdkCategoryWarnings.length) {
  391. jdkCategoryWarnings[0].hostsNames.forEach(function (_hostName) {
  392. if (!hostNameMap[_hostName]) {
  393. hostNameMap[_hostName] = true;
  394. }
  395. });
  396. }
  397. if (hostResolutionWarnings && hostResolutionWarnings.length) {
  398. hostResolutionWarnings[0].hosts.forEach(function (_hostName) {
  399. if (!hostNameMap[_hostName]) {
  400. hostNameMap[_hostName] = true;
  401. }
  402. });
  403. }
  404. return Em.keys(hostNameMap).length;
  405. },
  406. /**
  407. * Open new browser tab with detailed content
  408. * @method openWarningsInDialog
  409. */
  410. openWarningsInDialog: function () {
  411. var newWindow = window.open('');
  412. var newDocument = newWindow.document;
  413. newDocument.write(this.get('contentInDetails'));
  414. newWindow.focus();
  415. }
  416. });