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