apps_controller.js 3.1 KB

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