host_progress_popup.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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 && hostsData.hostsMap) {
  282. hostsMap = hostsData.hostsMap;
  283. }
  284. }
  285. var existedHosts = self.get('hosts');
  286. if (existedHosts && this.get('currentServiceId') === this.get('previousServiceId')) {
  287. existedHosts.forEach(function (host) {
  288. var newHostInfo = hostsMap[host.get('name')];
  289. if (newHostInfo) {
  290. var hostStatus = self.getStatus(newHostInfo.logTasks);
  291. var hostProgress = self.getProgress(newHostInfo.logTasks);
  292. host.set('status', App.format.taskStatus(hostStatus[0]));
  293. host.set('icon', hostStatus[1]);
  294. host.set('barColor', hostStatus[2]);
  295. host.set('isInProgress', hostStatus[3]);
  296. host.set('progress', hostProgress);
  297. host.set('barWidth', "width:" + hostProgress + "%;");
  298. var existTasks = host.get('tasks');
  299. var newTasks = newHostInfo.logTasks;
  300. if (existTasks && newTasks && existTasks.length == newTasks.length) {
  301. // Same number of source and destinations
  302. var existTaskMap = {};
  303. var newTaskMap = {};
  304. host.get('tasks').forEach(function (taskInfo) {
  305. var id = taskInfo.get('id');
  306. existTaskMap[id] = taskInfo;
  307. });
  308. var newTasksArray = [];
  309. newTasks.forEach(function (newTask) {
  310. var existTask = existTaskMap[newTask.Tasks.id];
  311. if (existTask) {
  312. // reuse
  313. existTask.set('status', App.format.taskStatus(newTask.Tasks.status));
  314. existTask.set('stderr', newTask.Tasks.stderr);
  315. existTask.set('stdout', newTask.Tasks.stdout);
  316. self.updateTaskIcon(existTask);
  317. delete existTaskMap[newTask.Tasks.id];
  318. } else {
  319. // create new
  320. var taskInfo = Ember.Object.create({
  321. id: newTask.Tasks.id,
  322. hostName: newHostInfo.publicName,
  323. command: newTask.Tasks.command.toLowerCase(),
  324. status: App.format.taskStatus(newTask.Tasks.status),
  325. role: App.format.role(newTask.Tasks.role),
  326. stderr: newTask.Tasks.stderr,
  327. stdout: newTask.Tasks.stdout,
  328. isVisible: true,
  329. icon: 'icon-cogs'
  330. });
  331. self.updateTaskIcon(taskInfo);
  332. newTasksArray.push(taskInfo);
  333. }
  334. });
  335. for (var id in existTaskMap) {
  336. host.get('tasks').removeObject(existTaskMap[id]);
  337. }
  338. if (newTasksArray.length) {
  339. host.get('tasks').pushObjects(newTasksArray);
  340. }
  341. } else {
  342. // Tasks have changed
  343. var tasksArr = [];
  344. newTasks.forEach(function (newTask) {
  345. var taskInfo = Ember.Object.create({
  346. id: newTask.Tasks.id,
  347. hostName: newHostInfo.publicName,
  348. command: newTask.Tasks.command.toLowerCase(),
  349. status: App.format.taskStatus(newTask.Tasks.status),
  350. role: App.format.role(newTask.Tasks.role),
  351. stderr: newTask.Tasks.stderr,
  352. stdout: newTask.Tasks.stdout,
  353. isVisible: true,
  354. icon: 'icon-cogs'
  355. });
  356. self.updateTaskIcon(taskInfo);
  357. tasksArr.push(taskInfo);
  358. });
  359. host.set('tasks', tasksArr);
  360. }
  361. }
  362. }, this);
  363. } else {
  364. for (var hostName in hostsMap) {
  365. var _host = hostsMap[hostName];
  366. var tasks = _host.logTasks;
  367. var hostInfo = Ember.Object.create({
  368. name: hostName,
  369. publicName: _host.publicName,
  370. progress: 0,
  371. status: App.format.taskStatus("PENDING"),
  372. serviceName: _host.serviceName,
  373. isVisible: true,
  374. icon: "icon-cog",
  375. barColor: "progress-info",
  376. barWidth: "width:0%;"
  377. });
  378. var tasksArr = [];
  379. if (tasks.length) {
  380. tasks = self.sortTasksById(tasks);
  381. var hostStatus = self.getStatus(tasks);
  382. var hostProgress = self.getProgress(tasks);
  383. hostInfo.set('status', App.format.taskStatus(hostStatus[0]));
  384. hostInfo.set('icon', hostStatus[1]);
  385. hostInfo.set('barColor', hostStatus[2]);
  386. hostInfo.set('isInProgress', hostStatus[3]);
  387. hostInfo.set('progress', hostProgress);
  388. hostInfo.set('barWidth', "width:" + hostProgress + "%;");
  389. tasks.forEach(function (_task) {
  390. var taskInfo = Ember.Object.create({
  391. id: _task.Tasks.id,
  392. hostName: _host.publicName,
  393. command: _task.Tasks.command.toLowerCase(),
  394. status: App.format.taskStatus(_task.Tasks.status),
  395. role: App.format.role(_task.Tasks.role),
  396. stderr: _task.Tasks.stderr,
  397. stdout: _task.Tasks.stdout,
  398. isVisible: true,
  399. icon: 'icon-cogs'
  400. });
  401. this.updateTaskIcon(taskInfo);
  402. tasksArr.push(taskInfo);
  403. }, this);
  404. }
  405. hostInfo.set('tasks', tasksArr);
  406. hostsArr.push(hostInfo);
  407. }
  408. //sort hosts by name
  409. this.sortArray(hostsArr, "name");
  410. hostsArr.setEach("serviceName", this.get("serviceName"));
  411. self.set("hosts", hostsArr);
  412. self.set('previousServiceId', this.get('currentServiceId'));
  413. }
  414. }
  415. },
  416. /**
  417. * Sort tasks by it`s id
  418. * @param tasks
  419. * @return {Array}
  420. */
  421. sortTasksById: function (tasks) {
  422. return tasks.sort(function (a, b) {
  423. return (a.Tasks.id > b.Tasks.id) ? 1 : (a.Tasks.id < b.Tasks.id) ? -1 : 0;
  424. });
  425. },
  426. /**
  427. * Show popup
  428. * @return PopupObject For testing purposes
  429. */
  430. createPopup: function () {
  431. var self = this;
  432. var hostsInfo = this.get("hosts");
  433. var servicesInfo = this.get("servicesInfo");
  434. var showServices = this.get('showServices');
  435. var categoryObject = Em.Object.extend({
  436. value: '',
  437. count: 0,
  438. labelPath: '',
  439. label: function(){
  440. return Em.I18n.t(this.get('labelPath')).format(this.get('count'));
  441. }.property('count')
  442. });
  443. return App.ModalPopup.show({
  444. //no need to track is it loaded when popup contain only list of hosts
  445. isLoaded: !showServices,
  446. isOpen: false,
  447. didInsertElement: function(){
  448. this.set('isOpen', true);
  449. },
  450. headerClass: Ember.View.extend({
  451. controller: this,
  452. template: Ember.Handlebars.compile('{{popupHeaderName}}')
  453. }),
  454. classNames: ['sixty-percent-width-modal'],
  455. autoHeight: false,
  456. closeModelPopup: function () {
  457. this.set('isOpen', false);
  458. if(showServices){
  459. $(this.get('element')).detach();
  460. } else {
  461. this.hide();
  462. }
  463. },
  464. onPrimary: function () {
  465. this.closeModelPopup();
  466. },
  467. onClose: function () {
  468. this.closeModelPopup();
  469. },
  470. secondary: null,
  471. bodyClass: Ember.View.extend({
  472. templateName: require('templates/common/host_progress_popup'),
  473. isLogWrapHidden: true,
  474. isTaskListHidden: true,
  475. isHostListHidden: true,
  476. isServiceListHidden: false,
  477. showTextArea: false,
  478. isServiceEmptyList: true,
  479. isHostEmptyList: true,
  480. isTasksEmptyList: true,
  481. controller: this,
  482. hosts: self.get("hosts"),
  483. services: self.get('servicesInfo'),
  484. tasks: function () {
  485. if (!this.get('controller.currentHostName')) return [];
  486. if (this.get('hosts') && this.get('hosts').length) {
  487. var currentHost = this.get('hosts').findProperty('name', this.get('controller.currentHostName'));
  488. if (currentHost) {
  489. return currentHost.get('tasks');
  490. }
  491. }
  492. return [];
  493. }.property('hosts.@each.tasks', 'hosts.@each.tasks.@each.status'),
  494. didInsertElement: function () {
  495. this.setOnStart();
  496. },
  497. /**
  498. * Preset values on init
  499. */
  500. setOnStart: function () {
  501. if (this.get("controller.showServices")) {
  502. this.get('controller').setSelectCount(this.get("services"), this.get('categories'));
  503. } else {
  504. this.set("isHostListHidden", false);
  505. this.set("isServiceListHidden", true);
  506. }
  507. },
  508. /**
  509. * force popup to show list of operations
  510. */
  511. resetState: function(){
  512. if(this.get('parentView.isOpen')){
  513. this.set('isLogWrapHidden', true);
  514. this.set('isTaskListHidden', true);
  515. this.set('isHostListHidden', true);
  516. this.set('isServiceListHidden', false);
  517. this.get("controller").setBackgroundOperationHeader();
  518. this.setOnStart();
  519. }
  520. }.observes('parentView.isOpen'),
  521. /**
  522. * When popup is opened, and data after polling has changed, update this data in component
  523. */
  524. updateHostInfo: function () {
  525. if(!this.get('parentView.isOpen')) return;
  526. this.set('parentView.isLoaded', false);
  527. this.get("controller").set("inputData", this.get("controller.serviceController.services"));
  528. this.get("controller").onServiceUpdate();
  529. this.get("controller").onHostUpdate();
  530. this.set('parentView.isLoaded', true);
  531. this.set("hosts", this.get("controller.hosts"));
  532. this.set("services", this.get("controller.servicesInfo"));
  533. }.observes("controller.serviceController.serviceTimestamp"),
  534. /**
  535. * Depending on service filter, set which services should be shown
  536. */
  537. visibleServices: function () {
  538. if (this.get("services")) {
  539. this.set("isServiceEmptyList", true);
  540. if (this.get('serviceCategory.value')) {
  541. var filter = this.get('serviceCategory.value');
  542. var services = this.get('services');
  543. this.setVisability(filter, services);
  544. if (services.filterProperty("isVisible", true).length > 0) {
  545. this.set("isServiceEmptyList", false);
  546. }
  547. }
  548. }
  549. }.observes('serviceCategory', 'services'),
  550. /**
  551. * Depending on hosts filter, set which hosts should be shown
  552. */
  553. visibleHosts: function () {
  554. this.set("isHostEmptyList", true);
  555. if (this.get('hostCategory.value') && this.get('hosts')) {
  556. var filter = this.get('hostCategory.value');
  557. var hosts = this.get('hosts');
  558. this.setVisability(filter, hosts);
  559. if (hosts.filterProperty("isVisible", true).length > 0) {
  560. this.set("isHostEmptyList", false);
  561. }
  562. }
  563. }.observes('hostCategory', 'hosts'),
  564. /**
  565. * Depending on tasks filter, set which tasks should be shown
  566. */
  567. visibleTasks: function () {
  568. this.set("isTasksEmptyList", true);
  569. if (this.get('taskCategory.value') && this.get('tasks')) {
  570. var filter = this.get('taskCategory.value');
  571. var tasks = this.get('tasks');
  572. this.setVisability(filter, tasks);
  573. if (tasks.filterProperty("isVisible", true).length > 0) {
  574. this.set("isTasksEmptyList", false);
  575. }
  576. }
  577. }.observes('taskCategory', 'tasks'),
  578. /**
  579. * Depending on selected filter type, set object visibility value
  580. * @param filter
  581. * @param obj
  582. */
  583. setVisability: function (filter, obj) {
  584. obj.setEach("isVisible", false);
  585. if (filter == "all") {
  586. obj.setEach("isVisible", true);
  587. }
  588. else if (filter == "pending") {
  589. obj.filterProperty("status", "pending").setEach("isVisible", true);
  590. obj.filterProperty("status", "queued").setEach("isVisible", true);
  591. }
  592. else if (filter == "in_progress") {
  593. obj.filterProperty("status", "in_progress").setEach("isVisible", true);
  594. obj.filterProperty("status", "upgrading").setEach("isVisible", true);
  595. }
  596. else if (filter == "failed") {
  597. obj.filterProperty("status", "failed").setEach("isVisible", true);
  598. }
  599. else if (filter == "completed") {
  600. obj.filterProperty("status", "completed").setEach("isVisible", true);
  601. obj.filterProperty("status", "success").setEach("isVisible", true);
  602. }
  603. else if (filter == "aborted") {
  604. obj.filterProperty("status", "aborted").setEach("isVisible", true);
  605. }
  606. else if (filter == "timedout") {
  607. obj.filterProperty("status", "timedout").setEach("isVisible", true);
  608. }
  609. },
  610. /**
  611. * Select box, display names and values
  612. */
  613. categories: [
  614. categoryObject.create({value: 'all', labelPath: 'hostPopup.status.category.all'}),
  615. categoryObject.create({value: 'pending', labelPath: 'hostPopup.status.category.pending'}),
  616. categoryObject.create({value: 'in_progress', labelPath: 'hostPopup.status.category.inProgress'}),
  617. categoryObject.create({value: 'failed', labelPath: 'hostPopup.status.category.failed'}),
  618. categoryObject.create({value: 'completed', labelPath: 'hostPopup.status.category.success'}),
  619. categoryObject.create({value: 'aborted', labelPath: 'hostPopup.status.category.aborted'}),
  620. categoryObject.create({value: 'timedout', labelPath: 'hostPopup.status.category.timedout'})
  621. ],
  622. /**
  623. * Selected option is binded to this values
  624. */
  625. serviceCategory: null,
  626. hostCategory: null,
  627. taskCategory: null,
  628. /**
  629. * Depending on currently viewed tab, call setSelectCount function
  630. */
  631. updateSelectView: function () {
  632. if (!this.get('isHostListHidden')) {
  633. this.get('controller').setSelectCount(this.get("hosts"), this.get('categories'));
  634. } else if (!this.get('isTaskListHidden')) {
  635. this.get('controller').setSelectCount(this.get("tasks"), this.get('categories'));
  636. } else if (!this.get('isServiceListHidden')) {
  637. this.get('controller').setSelectCount(this.get("services"), this.get('categories'));
  638. }
  639. }.observes('hosts', 'isTaskListHidden', 'isHostListHidden', 'services.length', 'services.@each.status'),
  640. /**
  641. * Onclick handler for button <-Tasks
  642. * @param event
  643. * @param context
  644. */
  645. backToTaskList: function (event, context) {
  646. this.destroyClipBoard();
  647. this.set("openedTaskId", 0);
  648. this.set("isLogWrapHidden", true);
  649. this.set("isTaskListHidden", false);
  650. },
  651. /**
  652. * Onclick handler for button <-Hosts
  653. * @param event
  654. * @param context
  655. */
  656. backToHostList: function (event, context) {
  657. this.set("isHostListHidden", false);
  658. this.set("isTaskListHidden", true);
  659. this.set("tasks", null);
  660. this.get("controller").set("popupHeaderName", this.get("controller.serviceName"));
  661. },
  662. /**
  663. * Onclick handler for button <-Services
  664. * @param event
  665. * @param context
  666. */
  667. backToServiceList: function (event, context) {
  668. this.get("controller").set("serviceName", "");
  669. this.set("isHostListHidden", true);
  670. this.set("isServiceListHidden", false);
  671. this.set("isTaskListHidden", true);
  672. this.set("tasks", null);
  673. this.set("hosts", null);
  674. this.get("controller").setBackgroundOperationHeader();
  675. },
  676. /**
  677. * Onclick handler for selected Service
  678. * @param event
  679. * @param context
  680. */
  681. gotoHosts: function (event, context) {
  682. this.get("controller").set("serviceName", event.context.get("name"));
  683. this.get("controller").set("currentServiceId", event.context.get("id"));
  684. this.get("controller").onHostUpdate();
  685. var servicesInfo = this.get("controller.hosts");
  686. if (servicesInfo.length) {
  687. this.get("controller").set("popupHeaderName", event.context.get("name"));
  688. }
  689. this.set('hosts', servicesInfo);
  690. this.set("isServiceListHidden", true);
  691. this.set("isHostListHidden", false);
  692. $(".modal").scrollTop(0);
  693. $(".modal-body").scrollTop(0);
  694. },
  695. /**
  696. * Onclick handler for selected Host
  697. * @param event
  698. * @param context
  699. */
  700. gotoTasks: function (event, context) {
  701. var taskInfo = event.context.tasks;
  702. if (taskInfo.length) {
  703. this.get("controller").set("popupHeaderName", taskInfo.objectAt(0).hostName);
  704. this.get("controller").set("currentHostName", taskInfo.objectAt(0).hostName);
  705. }
  706. this.set('tasks', taskInfo);
  707. this.set("isHostListHidden", true);
  708. this.set("isTaskListHidden", false);
  709. $(".modal").scrollTop(0);
  710. $(".modal-body").scrollTop(0);
  711. },
  712. /**
  713. * Onclick handler for selected Task
  714. */
  715. openTaskLogInDialog: function () {
  716. if ($(".task-detail-log-clipboard").length > 0) {
  717. this.destroyClipBoard();
  718. }
  719. var newWindow = window.open();
  720. var newDocument = newWindow.document;
  721. newDocument.write($(".task-detail-log-info").html());
  722. newDocument.close();
  723. },
  724. openedTaskId: 0,
  725. /**
  726. * Return task detail info of opened task
  727. */
  728. openedTask: function () {
  729. if (!this.get('openedTaskId')) {
  730. return Ember.Object.create();
  731. }
  732. return this.get('tasks').findProperty('id', this.get('openedTaskId'));
  733. }.property('tasks', 'tasks.@each.stderr', 'tasks.@each.stdout', 'openedTaskId'),
  734. /**
  735. * Onclick event for show task detail info
  736. * @param event
  737. * @param context
  738. */
  739. toggleTaskLog: function (event, context) {
  740. var taskInfo = event.context;
  741. this.set("isLogWrapHidden", false);
  742. if ($(".task-detail-log-clipboard").length > 0) {
  743. this.destroyClipBoard();
  744. }
  745. this.set("isHostListHidden", true);
  746. this.set("isTaskListHidden", true);
  747. this.set('openedTaskId', taskInfo.id);
  748. $(".modal").scrollTop(0);
  749. $(".modal-body").scrollTop(0);
  750. },
  751. /**
  752. * Onclick event for copy to clipboard button
  753. * @param event
  754. */
  755. textTrigger: function (event) {
  756. if ($(".task-detail-log-clipboard").length > 0) {
  757. this.destroyClipBoard();
  758. } else {
  759. this.createClipBoard();
  760. }
  761. },
  762. /**
  763. * Create Clip Board
  764. */
  765. createClipBoard: function () {
  766. $(".task-detail-log-clipboard-wrap").html('<textarea class="task-detail-log-clipboard"></textarea>');
  767. $(".task-detail-log-clipboard")
  768. .html("stderr: \n" + $(".stderr").html() + "\n stdout:\n" + $(".stdout").html())
  769. .css("display", "block")
  770. .width($(".task-detail-log-maintext").width())
  771. .height($(".task-detail-log-maintext").height())
  772. .select();
  773. $(".task-detail-log-maintext").css("display", "none")
  774. },
  775. /**
  776. * Destroy Clip Board
  777. */
  778. destroyClipBoard: function () {
  779. $(".task-detail-log-clipboard").remove();
  780. $(".task-detail-log-maintext").css("display", "block");
  781. }
  782. })
  783. });
  784. }
  785. });