apps_controller.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. require('utils/jquery.unique');
  20. App.MainAppsController = Em.ArrayController.extend({
  21. name:'mainAppsController',
  22. content:App.Run.find(),
  23. apps:App.App.find(),
  24. staredRuns: [],
  25. filteredRuns: [],
  26. routeHome:function () {
  27. App.router.transitionTo('main.dashboard');
  28. var view = Ember.View.views['main_menu'];
  29. },
  30. clearFilteredRuns: function() {
  31. this.set('filteredRuns', []);
  32. this.set('filteredRunsLength', 0);
  33. },
  34. addFilteredRun: function(id) {
  35. this.get('filteredRuns').push(this.getRunById(id));
  36. this.set('filteredRunsLength', this.get('filteredRuns').length);
  37. },
  38. /**
  39. * Get run by id
  40. * @param id run identifier (NOT runId)
  41. * @return {*} run if exists, undefined - not exists
  42. */
  43. getRunById: function(id) {
  44. var r;
  45. this.get('content').forEach(function(item){
  46. if (item.get('workflowId') == id) {
  47. r = item;
  48. }
  49. });
  50. return r;
  51. },
  52. /**
  53. * Check if run with such id exists
  54. * @param id run identifier (NOT runId)
  55. * @return {Boolean} true - record with this id exists, false - not exists
  56. */
  57. issetStaredRun: function(id) {
  58. var r = false;
  59. this.get('staredRuns').forEach(function(item){
  60. if (item.get('workflowId') == id) {
  61. r = true;
  62. }
  63. });
  64. return r;
  65. },
  66. /**
  67. * Identifier of the last starred/unstarred run
  68. */
  69. lastStarClicked: -1,
  70. /**
  71. * Click on star on table row
  72. * @return {Boolean} false for prevent default event handler
  73. */
  74. starClick: function(event) {
  75. $(event.target).closest('table').find('.containerRow').remove(); // hack for valid "turning-off" star in table, where graphs row where enabled. We remove it
  76. event.target.classList.toggle('stared');
  77. var cell = event.target.parentNode.parentNode;
  78. var row = cell.parentNode;
  79. var id = jQuery(event.target).parent().children(1).text();
  80. if (!this.issetStaredRun(id)) {
  81. this.get('staredRuns').push(this.getRunById(id));
  82. }
  83. else {
  84. var key = this.get('staredRuns').indexOf(this.getRunById(id));
  85. if (key != -1) {
  86. this.get('staredRuns').splice(key, 1);
  87. }
  88. }
  89. this.set('staredRunsLength', this.get('staredRuns').length);
  90. this.set('lastStarClicked', id);
  91. return false;
  92. }
  93. })