apps_controller.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. staredRuns: [],
  24. filteredRuns: [],
  25. clearFilteredRuns: function() {
  26. this.set('filteredRuns', []);
  27. this.set('filteredRunsLength', 0);
  28. },
  29. addFilteredRun: function(id) {
  30. this.get('filteredRuns').push(this.getRunById(id));
  31. this.set('filteredRunsLength', this.get('filteredRuns').length);
  32. },
  33. /**
  34. * Get run by id
  35. * @param id run identifier (NOT runId)
  36. * @return {*} run if exists, undefined - not exists
  37. */
  38. getRunById: function(id) {
  39. return this.get('content').findProperty('id', id);
  40. },
  41. /**
  42. * Check if run with such id exists
  43. * @param id run identifier (NOT runId)
  44. * @return {Boolean} true - record with this id exists, false - not exists
  45. */
  46. issetStaredRun: function(id) {
  47. return this.get('staredRuns').someProperty('id', id);
  48. },
  49. /**
  50. * Identifier of the last starred/unstarred run
  51. */
  52. lastStarClicked: -1,
  53. /**
  54. * Click on star on table row
  55. * @return {Boolean} false for prevent default event handler
  56. */
  57. starClick: function(event) {
  58. $(event.target).closest('table').find('.containerRow').remove(); // hack for valid "turning-off" star in table, where graphs row where enabled. We remove it
  59. event.target.classList.toggle('stared');
  60. var id = jQuery(event.target).parent().parent().parent().find('.appId').text();
  61. if (!this.issetStaredRun(id)) {
  62. this.get('staredRuns').push(this.getRunById(id));
  63. }
  64. else {
  65. var key = this.get('staredRuns').indexOf(this.getRunById(id));
  66. if (key != -1) {
  67. this.get('staredRuns').splice(key, 1);
  68. }
  69. }
  70. this.set('staredRunsLength', this.get('staredRuns').length);
  71. this.set('lastStarClicked', id);
  72. return false;
  73. }
  74. })