apps_controller.js 2.5 KB

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