apps_controller.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. 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. * Click on star on table row
  71. * @return {Boolean} false for prevent default event handler
  72. */
  73. starClick: function() {
  74. event.srcElement.classList.toggle('stared');
  75. var id = parseInt(event.srcElement.parentNode.childNodes[1].innerText);
  76. if (!this.issetStaredRun(id)) {
  77. this.get('staredRuns').push(this.getRunById(id));
  78. }
  79. else {
  80. var key = this.get('staredRuns').indexOf(this.getRunById(id));
  81. if (key != -1) {
  82. this.get('staredRuns').splice(key, 1);
  83. }
  84. }
  85. this.set('staredRunsLength', this.get('staredRuns').length);
  86. return false;
  87. },
  88. /**
  89. * Flush all starred runs
  90. */
  91. clearStars: function() {
  92. this.set('staredRuns', []);
  93. this.set('staredRunsLength', 0);
  94. }
  95. })