host_progress_popup.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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. * App.HostPopup is for the popup that shows up upon clicking already-performed or currently-in-progress operations
  21. */
  22. App.HostPopup = Em.Object.create({
  23. servicesInfo: null,
  24. hosts: null,
  25. inputData: null,
  26. serviceName: "",
  27. currentServiceId: null,
  28. previousServiceId: null,
  29. popupHeaderName: "",
  30. serviceController: null,
  31. showServices: false,
  32. currentHostName: null,
  33. /**
  34. * Sort object array
  35. * @param array
  36. * @param p
  37. * @return {*}
  38. */
  39. sortArray: function (array, p) {
  40. return array.sort(function (a, b) {
  41. return (a[p] > b[p]) ? 1 : (a[p] < b[p]) ? -1 : 0;
  42. });
  43. },
  44. /**
  45. * Entering point of this component
  46. * @param serviceName
  47. * @param controller
  48. * @param showServices
  49. */
  50. initPopup: function (serviceName, controller, showServices) {
  51. if (!showServices) {
  52. this.clearHostPopup();
  53. this.set("popupHeaderName", serviceName);
  54. }
  55. this.set("serviceName", serviceName);
  56. this.set("serviceController", controller);
  57. this.set("showServices", showServices);
  58. this.set("inputData", this.get("serviceController.services"));
  59. if(this.get('showServices')){
  60. this.onServiceUpdate();
  61. } else {
  62. this.onHostUpdate();
  63. }
  64. return this.createPopup();
  65. },
  66. clearHostPopup: function () {
  67. this.set('servicesInfo', null);
  68. this.set('hosts', null);
  69. this.set('inputData', null);
  70. this.set('serviceName', "");
  71. this.set('currentServiceId', null);
  72. this.set('previousServiceId', null);
  73. this.set('popupHeaderName', "");
  74. this.set('serviceController', null);
  75. this.set('showServices', false);
  76. this.set('currentHostName', null);
  77. },
  78. /**
  79. * Depending on tasks status
  80. * @param tasks
  81. * @return {Array} [Status, Icon type, Progressbar color, is IN_PROGRESS]
  82. */
  83. getStatus: function(tasks){
  84. var isCompleted = true;
  85. var status;
  86. var tasksLength = tasks.length;
  87. var isFailed = false;
  88. var isAborted = false;
  89. var isTimedout = false;
  90. var isInProgress = false;
  91. for (var i = 0; i < tasksLength; i++) {
  92. if (tasks[i].Tasks.status !== 'COMPLETED') {
  93. isCompleted = false;
  94. }
  95. if(tasks[i].Tasks.status === 'FAILED'){
  96. isFailed = true;
  97. }
  98. if (tasks[i].Tasks.status === 'ABORTED') {
  99. isAborted = true;
  100. }
  101. if (tasks[i].Tasks.status === 'TIMEDOUT') {
  102. isTimedout = true;
  103. }
  104. if (tasks[i].Tasks.status === 'IN_PROGRESS') {
  105. isInProgress = true;
  106. }
  107. }
  108. if (isFailed) {
  109. status = ['FAILED', 'icon-exclamation-sign', 'progress-danger', false];
  110. } else if (isAborted) {
  111. status = ['CANCELLED', 'icon-minus', 'progress-warning', false];
  112. } else if (isTimedout) {
  113. status = ['TIMEDOUT', 'icon-time', 'progress-warning', false];
  114. } else if (isInProgress) {
  115. status = ['IN_PROGRESS', 'icon-cogs', 'progress-info', true];
  116. }
  117. if(status){
  118. return status;
  119. } else if(isCompleted){
  120. return ['SUCCESS', 'icon-ok', 'progress-success', false];
  121. } else {
  122. return ['PENDING', 'icon-cog', 'progress-info', true];
  123. }
  124. },
  125. /**
  126. * Progress of host or service depending on tasks status
  127. * @param tasks
  128. * @return {Number} percent of completion
  129. */
  130. getProgress: function (tasks) {
  131. var completedActions = 0;
  132. var queuedActions = 0;
  133. var inProgressActions = 0;
  134. tasks.forEach(function(task){
  135. if(['COMPLETED', 'FAILED', 'ABORTED', 'TIMEDOUT'].contains(task.Tasks.status)){
  136. completedActions++;
  137. } else if(task.Tasks.status === 'QUEUED'){
  138. queuedActions++;
  139. } else if(task.Tasks.status === 'IN_PROGRESS'){
  140. inProgressActions++;
  141. }
  142. });
  143. return Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / tasks.length * 100);
  144. },
  145. /**
  146. * Count number of operations for select box options
  147. * @param obj
  148. * @param categories
  149. */
  150. setSelectCount: function (obj, categories) {
  151. if (!obj) return;
  152. var countAll = obj.length;
  153. var countPending = 0;
  154. var countInProgress = 0;
  155. var countFailed = 0;
  156. var countCompleted = 0;
  157. var countAborted = 0;
  158. var countTimedout = 0;
  159. obj.forEach(function(item){
  160. switch (item.status){
  161. case 'pending':
  162. countPending++;
  163. break;
  164. case 'queued':
  165. countPending++;
  166. break;
  167. case 'in_progress':
  168. countInProgress++;
  169. break;
  170. case 'failed':
  171. countFailed++;
  172. break;
  173. case 'success':
  174. countCompleted++;
  175. break;
  176. case 'completed':
  177. countCompleted++;
  178. break;
  179. case 'aborted':
  180. countAborted++;
  181. break;
  182. case 'timedout':
  183. countTimedout++;
  184. break;
  185. }
  186. }, this);
  187. categories.findProperty("value", 'all').set("count", countAll);
  188. categories.findProperty("value", 'pending').set("count", countPending);
  189. categories.findProperty("value", 'in_progress').set("count", countInProgress);
  190. categories.findProperty("value", 'failed').set("count", countFailed);
  191. categories.findProperty("value", 'completed').set("count", countCompleted);
  192. categories.findProperty("value", 'aborted').set("count", countAborted);
  193. categories.findProperty("value", 'timedout').set("count", countTimedout);
  194. },
  195. /**
  196. * For Background operation popup calculate number of running Operations, and set popup header
  197. */
  198. setBackgroundOperationHeader: function () {
  199. if (this.get("showServices")) {
  200. var numRunning = App.router.get('backgroundOperationsController.allOperationsCount');
  201. this.set("popupHeaderName", numRunning + Em.I18n.t('hostPopup.header.postFix'));
  202. } else {
  203. this.set("popupHeaderName", this.get("serviceName"));
  204. }
  205. },
  206. /**
  207. * Create services obj data structure for popup
  208. * Set data for services
  209. */
  210. onServiceUpdate: function () {
  211. if (this.get('showServices') && this.get("inputData")) {
  212. var self = this;
  213. var allNewServices = [];
  214. this.set("servicesInfo", null);
  215. this.get("inputData").forEach(function (service) {
  216. var newService = Ember.Object.create({
  217. id: service.id,
  218. displayName: service.displayName,
  219. detailMessage: service.detailMessage,
  220. message: service.message,
  221. progress: 0,
  222. status: App.format.taskStatus("PENDING"),
  223. name: service.name,
  224. isVisible: true,
  225. icon: 'icon-cog',
  226. barColor: 'progress-info',
  227. barWidth: 'width:0%;'
  228. });
  229. var allTasks = service.tasks;
  230. if (allTasks.length > 0) {
  231. var status = self.getStatus(allTasks);
  232. var progress = self.getProgress(allTasks);
  233. newService.set('status', App.format.taskStatus(status[0]));
  234. newService.set('icon', status[1]);
  235. newService.set('barColor', status[2]);
  236. newService.set('isInProgress', status[3]);
  237. newService.set('progress', progress);
  238. newService.set('barWidth', "width:" + progress + "%;");
  239. }
  240. allNewServices.push(newService);
  241. });
  242. self.set('servicesInfo', allNewServices);
  243. if (this.get("serviceName") == "") this.setBackgroundOperationHeader();
  244. }
  245. },
  246. /**
  247. * update icon of task depending on its status
  248. * @param taskInfo
  249. */
  250. updateTaskIcon: function(taskInfo){
  251. if (taskInfo.get('status') == 'pending' || taskInfo.get('status') == 'queued') {
  252. taskInfo.set('icon', 'icon-cog');
  253. } else if (taskInfo.get('status') == 'in_progress') {
  254. taskInfo.set('icon', 'icon-cogs');
  255. } else if (taskInfo.get('status') == 'completed') {
  256. taskInfo.set('icon', ' icon-ok');
  257. } else if (taskInfo.get('status') == 'failed') {
  258. taskInfo.set('icon', 'icon-exclamation-sign');
  259. } else if (taskInfo.get('status') == 'aborted') {
  260. taskInfo.set('icon', 'icon-minus');
  261. } else if (taskInfo.get('status') == 'timedout') {
  262. taskInfo.set('icon', 'icon-time');
  263. }
  264. },
  265. /**
  266. * Create hosts and tasks data structure for popup
  267. * Set data for hosts and tasks
  268. */
  269. onHostUpdate: function () {
  270. var self = this;
  271. if (this.get("inputData")) {
  272. var hostsArr = [];
  273. var hostsData = this.get("inputData");
  274. var hostsMap = {};
  275. if (!this.get("showServices") || this.get("serviceName")) {
  276. if (this.get("currentServiceId") != null) {
  277. hostsData = hostsData.findProperty("id", this.get("currentServiceId"));
  278. } else {
  279. hostsData = hostsData.findProperty("name", this.get("serviceName"));
  280. }
  281. if (hostsData) {
  282. if (hostsData.hostsMap) {
  283. hostsMap = hostsData.hostsMap;
  284. } else if (hostsData.hosts) {
  285. //hosts data come from wizard as array
  286. hostsData.hosts.forEach(function (_host) {
  287. hostsMap[_host.name] = _host;
  288. });
  289. }
  290. }
  291. }
  292. var existedHosts = self.get('hosts');
  293. if (existedHosts && this.get('currentServiceId') === this.get('previousServiceId')) {
  294. existedHosts.forEach(function (host) {
  295. var newHostInfo = hostsMap[host.get('name')];
  296. if (newHostInfo) {
  297. var hostStatus = self.getStatus(newHostInfo.logTasks);
  298. var hostProgress = self.getProgress(newHostInfo.logTasks);
  299. host.set('status', App.format.taskStatus(hostStatus[0]));
  300. host.set('icon', hostStatus[1]);
  301. host.set('barColor', hostStatus[2]);
  302. host.set('isInProgress', hostStatus[3]);
  303. host.set('progress', hostProgress);
  304. host.set('barWidth', "width:" + hostProgress + "%;");
  305. var existTasks = host.get('tasks');
  306. var newTasks = newHostInfo.logTasks;
  307. if (existTasks && newTasks && existTasks.length == newTasks.length) {
  308. // Same number of source and destinations
  309. var existTaskMap = {};
  310. var newTaskMap = {};
  311. host.get('tasks').forEach(function (taskInfo) {
  312. var id = taskInfo.get('id');
  313. existTaskMap[id] = taskInfo;
  314. });
  315. var newTasksArray = [];
  316. newTasks.forEach(function (newTask) {
  317. var existTask = existTaskMap[newTask.Tasks.id];
  318. if (existTask) {
  319. // reuse
  320. existTask.set('status', App.format.taskStatus(newTask.Tasks.status));
  321. existTask.set('stderr', newTask.Tasks.stderr);
  322. existTask.set('stdout', newTask.Tasks.stdout);
  323. self.updateTaskIcon(existTask);
  324. delete existTaskMap[newTask.Tasks.id];
  325. } else {
  326. // create new
  327. var taskInfo = Ember.Object.create({
  328. id: newTask.Tasks.id,
  329. hostName: newHostInfo.publicName,
  330. command: newTask.Tasks.command.toLowerCase(),
  331. status: App.format.taskStatus(newTask.Tasks.status),
  332. role: App.format.role(newTask.Tasks.role),
  333. stderr: newTask.Tasks.stderr,
  334. stdout: newTask.Tasks.stdout,
  335. isVisible: true,
  336. icon: 'icon-cogs'
  337. });
  338. self.updateTaskIcon(taskInfo);
  339. newTasksArray.push(taskInfo);
  340. }
  341. });
  342. for (var id in existTaskMap) {
  343. host.get('tasks').removeObject(existTaskMap[id]);
  344. }
  345. if (newTasksArray.length) {
  346. host.get('tasks').pushObjects(newTasksArray);
  347. }
  348. } else {
  349. // Tasks have changed
  350. var tasksArr = [];
  351. newTasks.forEach(function (newTask) {
  352. var taskInfo = Ember.Object.create({
  353. id: newTask.Tasks.id,
  354. hostName: newHostInfo.publicName,
  355. command: newTask.Tasks.command.toLowerCase(),
  356. status: App.format.taskStatus(newTask.Tasks.status),
  357. role: App.format.role(newTask.Tasks.role),
  358. stderr: newTask.Tasks.stderr,
  359. stdout: newTask.Tasks.stdout,
  360. isVisible: true,
  361. icon: 'icon-cogs'
  362. });
  363. self.updateTaskIcon(taskInfo);
  364. tasksArr.push(taskInfo);
  365. });
  366. host.set('tasks', tasksArr);
  367. }
  368. }
  369. }, this);
  370. } else {
  371. for (var hostName in hostsMap) {
  372. var _host = hostsMap[hostName];
  373. var tasks = _host.logTasks;
  374. var hostInfo = Ember.Object.create({
  375. name: hostName,
  376. publicName: _host.publicName,
  377. progress: 0,
  378. status: App.format.taskStatus("PENDING"),
  379. serviceName: _host.serviceName,
  380. isVisible: true,
  381. icon: "icon-cog",
  382. barColor: "progress-info",
  383. barWidth: "width:0%;"
  384. });
  385. var tasksArr = [];
  386. if (tasks.length) {
  387. tasks = self.sortTasksById(tasks);
  388. var hostStatus = self.getStatus(tasks);
  389. var hostProgress = self.getProgress(tasks);
  390. hostInfo.set('status', App.format.taskStatus(hostStatus[0]));
  391. hostInfo.set('icon', hostStatus[1]);
  392. hostInfo.set('barColor', hostStatus[2]);
  393. hostInfo.set('isInProgress', hostStatus[3]);
  394. hostInfo.set('progress', hostProgress);
  395. hostInfo.set('barWidth', "width:" + hostProgress + "%;");
  396. tasks.forEach(function (_task) {
  397. var taskInfo = Ember.Object.create({
  398. id: _task.Tasks.id,
  399. hostName: _host.publicName,
  400. command: _task.Tasks.command.toLowerCase(),
  401. status: App.format.taskStatus(_task.Tasks.status),
  402. role: App.format.role(_task.Tasks.role),
  403. stderr: _task.Tasks.stderr,
  404. stdout: _task.Tasks.stdout,
  405. isVisible: true,
  406. icon: 'icon-cogs'
  407. });
  408. this.updateTaskIcon(taskInfo);
  409. tasksArr.push(taskInfo);
  410. }, this);
  411. }
  412. hostInfo.set('tasks', tasksArr);
  413. hostsArr.push(hostInfo);
  414. }
  415. //sort hosts by name
  416. this.sortArray(hostsArr, "name");
  417. hostsArr.setEach("serviceName", this.get("serviceName"));
  418. self.set("hosts", hostsArr);
  419. self.set('previousServiceId', this.get('currentServiceId'));
  420. }
  421. }
  422. },
  423. /**
  424. * Sort tasks by it`s id
  425. * @param tasks
  426. * @return {Array}
  427. */
  428. sortTasksById: function (tasks) {
  429. return tasks.sort(function (a, b) {
  430. return (a.Tasks.id > b.Tasks.id) ? 1 : (a.Tasks.id < b.Tasks.id) ? -1 : 0;
  431. });
  432. },
  433. /**
  434. * Show popup
  435. * @return PopupObject For testing purposes
  436. */
  437. createPopup: function () {
  438. var self = this;
  439. var hostsInfo = this.get("hosts");
  440. var servicesInfo = this.get("servicesInfo");
  441. var showServices = this.get('showServices');
  442. var categoryObject = Em.Object.extend({
  443. value: '',
  444. count: 0,
  445. labelPath: '',
  446. label: function(){
  447. return Em.I18n.t(this.get('labelPath')).format(this.get('count'));
  448. }.property('count')
  449. });
  450. return App.ModalPopup.show({
  451. //no need to track is it loaded when popup contain only list of hosts
  452. isLoaded: !showServices,
  453. isOpen: false,
  454. didInsertElement: function(){
  455. this.set('isOpen', true);
  456. },
  457. headerClass: Ember.View.extend({
  458. controller: this,
  459. template: Ember.Handlebars.compile('{{popupHeaderName}}')
  460. }),
  461. classNames: ['sixty-percent-width-modal'],
  462. autoHeight: false,
  463. closeModelPopup: function () {
  464. this.set('isOpen', false);
  465. if(showServices){
  466. $(this.get('element')).detach();
  467. } else {
  468. this.hide();
  469. }
  470. },
  471. onPrimary: function () {
  472. this.closeModelPopup();
  473. },
  474. onClose: function () {
  475. this.closeModelPopup();
  476. },
  477. secondary: null,
  478. bodyClass: Ember.View.extend({
  479. templateName: require('templates/common/host_progress_popup'),
  480. isLogWrapHidden: true,
  481. isTaskListHidden: true,
  482. isHostListHidden: true,
  483. isServiceListHidden: false,
  484. showTextArea: false,
  485. isServiceEmptyList: true,
  486. isHostEmptyList: true,
  487. isTasksEmptyList: true,
  488. controller: this,
  489. hosts: self.get("hosts"),
  490. services: self.get('servicesInfo'),
  491. tasks: function () {
  492. if (!this.get('controller.currentHostName')) return [];
  493. if (this.get('hosts') && this.get('hosts').length) {
  494. var currentHost = this.get('hosts').findProperty('name', this.get('controller.currentHostName'));
  495. if (currentHost) {
  496. return currentHost.get('tasks');
  497. }
  498. }
  499. return [];
  500. }.property('hosts.@each.tasks', 'hosts.@each.tasks.@each.status'),
  501. didInsertElement: function () {
  502. this.setOnStart();
  503. },
  504. /**
  505. * Preset values on init
  506. */
  507. setOnStart: function () {
  508. if (this.get("controller.showServices")) {
  509. this.get('controller').setSelectCount(this.get("services"), this.get('categories'));
  510. } else {
  511. this.set("isHostListHidden", false);
  512. this.set("isServiceListHidden", true);
  513. }
  514. },
  515. /**
  516. * force popup to show list of operations
  517. */
  518. resetState: function(){
  519. if(this.get('parentView.isOpen')){
  520. this.set('isLogWrapHidden', true);
  521. this.set('isTaskListHidden', true);
  522. this.set('isHostListHidden', true);
  523. this.set('isServiceListHidden', false);
  524. this.get("controller").setBackgroundOperationHeader();
  525. this.setOnStart();
  526. }
  527. }.observes('parentView.isOpen'),
  528. /**
  529. * When popup is opened, and data after polling has changed, update this data in component
  530. */
  531. updateHostInfo: function () {
  532. if(!this.get('parentView.isOpen')) return;
  533. this.set('parentView.isLoaded', false);
  534. this.get("controller").set("inputData", this.get("controller.serviceController.services"));
  535. this.get("controller").onServiceUpdate();
  536. this.get("controller").onHostUpdate();
  537. this.set('parentView.isLoaded', true);
  538. this.set("hosts", this.get("controller.hosts"));
  539. this.set("services", this.get("controller.servicesInfo"));
  540. }.observes("controller.serviceController.serviceTimestamp"),
  541. /**
  542. * Depending on service filter, set which services should be shown
  543. */
  544. visibleServices: function () {
  545. if (this.get("services")) {
  546. this.set("isServiceEmptyList", true);
  547. if (this.get('serviceCategory.value')) {
  548. var filter = this.get('serviceCategory.value');
  549. var services = this.get('services');
  550. this.setVisability(filter, services);
  551. if (services.filterProperty("isVisible", true).length > 0) {
  552. this.set("isServiceEmptyList", false);
  553. }
  554. }
  555. }
  556. }.observes('serviceCategory', 'services'),
  557. /**
  558. * Depending on hosts filter, set which hosts should be shown
  559. */
  560. visibleHosts: function () {
  561. this.set("isHostEmptyList", true);
  562. if (this.get('hostCategory.value') && this.get('hosts')) {
  563. var filter = this.get('hostCategory.value');
  564. var hosts = this.get('hosts');
  565. this.setVisability(filter, hosts);
  566. if (hosts.filterProperty("isVisible", true).length > 0) {
  567. this.set("isHostEmptyList", false);
  568. }
  569. }
  570. }.observes('hostCategory', 'hosts'),
  571. /**
  572. * Depending on tasks filter, set which tasks should be shown
  573. */
  574. visibleTasks: function () {
  575. this.set("isTasksEmptyList", true);
  576. if (this.get('taskCategory.value') && this.get('tasks')) {
  577. var filter = this.get('taskCategory.value');
  578. var tasks = this.get('tasks');
  579. this.setVisability(filter, tasks);
  580. if (tasks.filterProperty("isVisible", true).length > 0) {
  581. this.set("isTasksEmptyList", false);
  582. }
  583. }
  584. }.observes('taskCategory', 'tasks'),
  585. /**
  586. * Depending on selected filter type, set object visibility value
  587. * @param filter
  588. * @param obj
  589. */
  590. setVisability: function (filter, obj) {
  591. obj.setEach("isVisible", false);
  592. if (filter == "all") {
  593. obj.setEach("isVisible", true);
  594. }
  595. else if (filter == "pending") {
  596. obj.filterProperty("status", "pending").setEach("isVisible", true);
  597. obj.filterProperty("status", "queued").setEach("isVisible", true);
  598. }
  599. else if (filter == "in_progress") {
  600. obj.filterProperty("status", "in_progress").setEach("isVisible", true);
  601. obj.filterProperty("status", "upgrading").setEach("isVisible", true);
  602. }
  603. else if (filter == "failed") {
  604. obj.filterProperty("status", "failed").setEach("isVisible", true);
  605. }
  606. else if (filter == "completed") {
  607. obj.filterProperty("status", "completed").setEach("isVisible", true);
  608. obj.filterProperty("status", "success").setEach("isVisible", true);
  609. }
  610. else if (filter == "aborted") {
  611. obj.filterProperty("status", "aborted").setEach("isVisible", true);
  612. }
  613. else if (filter == "timedout") {
  614. obj.filterProperty("status", "timedout").setEach("isVisible", true);
  615. }
  616. },
  617. /**
  618. * Select box, display names and values
  619. */
  620. categories: [
  621. categoryObject.create({value: 'all', labelPath: 'hostPopup.status.category.all'}),
  622. categoryObject.create({value: 'pending', labelPath: 'hostPopup.status.category.pending'}),
  623. categoryObject.create({value: 'in_progress', labelPath: 'hostPopup.status.category.inProgress'}),
  624. categoryObject.create({value: 'failed', labelPath: 'hostPopup.status.category.failed'}),
  625. categoryObject.create({value: 'completed', labelPath: 'hostPopup.status.category.success'}),
  626. categoryObject.create({value: 'aborted', labelPath: 'hostPopup.status.category.aborted'}),
  627. categoryObject.create({value: 'timedout', labelPath: 'hostPopup.status.category.timedout'})
  628. ],
  629. /**
  630. * Selected option is binded to this values
  631. */
  632. serviceCategory: null,
  633. hostCategory: null,
  634. taskCategory: null,
  635. /**
  636. * Depending on currently viewed tab, call setSelectCount function
  637. */
  638. updateSelectView: function () {
  639. if (!this.get('isHostListHidden')) {
  640. this.get('controller').setSelectCount(this.get("hosts"), this.get('categories'));
  641. } else if (!this.get('isTaskListHidden')) {
  642. this.get('controller').setSelectCount(this.get("tasks"), this.get('categories'));
  643. } else if (!this.get('isServiceListHidden')) {
  644. this.get('controller').setSelectCount(this.get("services"), this.get('categories'));
  645. }
  646. }.observes('hosts', 'isTaskListHidden', 'isHostListHidden', 'services.length', 'services.@each.status'),
  647. /**
  648. * Onclick handler for button <-Tasks
  649. * @param event
  650. * @param context
  651. */
  652. backToTaskList: function (event, context) {
  653. this.destroyClipBoard();
  654. this.set("openedTaskId", 0);
  655. this.set("isLogWrapHidden", true);
  656. this.set("isTaskListHidden", false);
  657. },
  658. /**
  659. * Onclick handler for button <-Hosts
  660. * @param event
  661. * @param context
  662. */
  663. backToHostList: function (event, context) {
  664. this.set("isHostListHidden", false);
  665. this.set("isTaskListHidden", true);
  666. this.set("tasks", null);
  667. this.get("controller").set("popupHeaderName", this.get("controller.serviceName"));
  668. },
  669. /**
  670. * Onclick handler for button <-Services
  671. * @param event
  672. * @param context
  673. */
  674. backToServiceList: function (event, context) {
  675. this.get("controller").set("serviceName", "");
  676. this.set("isHostListHidden", true);
  677. this.set("isServiceListHidden", false);
  678. this.set("isTaskListHidden", true);
  679. this.set("tasks", null);
  680. this.set("hosts", null);
  681. this.get("controller").setBackgroundOperationHeader();
  682. },
  683. /**
  684. * Onclick handler for selected Service
  685. * @param event
  686. * @param context
  687. */
  688. gotoHosts: function (event, context) {
  689. this.get("controller").set("serviceName", event.context.get("name"));
  690. this.get("controller").set("currentServiceId", event.context.get("id"));
  691. this.get("controller").onHostUpdate();
  692. var servicesInfo = this.get("controller.hosts");
  693. if (servicesInfo.length) {
  694. this.get("controller").set("popupHeaderName", event.context.get("name"));
  695. }
  696. this.set('hosts', servicesInfo);
  697. this.set("isServiceListHidden", true);
  698. this.set("isHostListHidden", false);
  699. $(".modal").scrollTop(0);
  700. $(".modal-body").scrollTop(0);
  701. },
  702. /**
  703. * Onclick handler for selected Host
  704. * @param event
  705. * @param context
  706. */
  707. gotoTasks: function (event, context) {
  708. var taskInfo = event.context.tasks;
  709. if (taskInfo.length) {
  710. this.get("controller").set("popupHeaderName", taskInfo.objectAt(0).hostName);
  711. this.get("controller").set("currentHostName", taskInfo.objectAt(0).hostName);
  712. }
  713. this.set('tasks', taskInfo);
  714. this.set("isHostListHidden", true);
  715. this.set("isTaskListHidden", false);
  716. $(".modal").scrollTop(0);
  717. $(".modal-body").scrollTop(0);
  718. },
  719. /**
  720. * Onclick handler for selected Task
  721. */
  722. openTaskLogInDialog: function () {
  723. if ($(".task-detail-log-clipboard").length > 0) {
  724. this.destroyClipBoard();
  725. }
  726. var newWindow = window.open();
  727. var newDocument = newWindow.document;
  728. newDocument.write($(".task-detail-log-info").html());
  729. newDocument.close();
  730. },
  731. openedTaskId: 0,
  732. /**
  733. * Return task detail info of opened task
  734. */
  735. openedTask: function () {
  736. if (!this.get('openedTaskId')) {
  737. return Ember.Object.create();
  738. }
  739. return this.get('tasks').findProperty('id', this.get('openedTaskId'));
  740. }.property('tasks', 'tasks.@each.stderr', 'tasks.@each.stdout', 'openedTaskId'),
  741. /**
  742. * Onclick event for show task detail info
  743. * @param event
  744. * @param context
  745. */
  746. toggleTaskLog: function (event, context) {
  747. var taskInfo = event.context;
  748. this.set("isLogWrapHidden", false);
  749. if ($(".task-detail-log-clipboard").length > 0) {
  750. this.destroyClipBoard();
  751. }
  752. this.set("isHostListHidden", true);
  753. this.set("isTaskListHidden", true);
  754. this.set('openedTaskId', taskInfo.id);
  755. $(".modal").scrollTop(0);
  756. $(".modal-body").scrollTop(0);
  757. },
  758. /**
  759. * Onclick event for copy to clipboard button
  760. * @param event
  761. */
  762. textTrigger: function (event) {
  763. if ($(".task-detail-log-clipboard").length > 0) {
  764. this.destroyClipBoard();
  765. } else {
  766. this.createClipBoard();
  767. }
  768. },
  769. /**
  770. * Create Clip Board
  771. */
  772. createClipBoard: function () {
  773. $(".task-detail-log-clipboard-wrap").html('<textarea class="task-detail-log-clipboard"></textarea>');
  774. $(".task-detail-log-clipboard")
  775. .html("stderr: \n" + $(".stderr").html() + "\n stdout:\n" + $(".stdout").html())
  776. .css("display", "block")
  777. .width($(".task-detail-log-maintext").width())
  778. .height($(".task-detail-log-maintext").height())
  779. .select();
  780. $(".task-detail-log-maintext").css("display", "none")
  781. },
  782. /**
  783. * Destroy Clip Board
  784. */
  785. destroyClipBoard: function () {
  786. $(".task-detail-log-clipboard").remove();
  787. $(".task-detail-log-maintext").css("display", "block");
  788. }
  789. })
  790. });
  791. }
  792. });