host_progress_popup.js 30 KB

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