jobs_view.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. var filters = require('views/common/filter_view');
  20. var sort = require('views/common/sort_view');
  21. App.MainJobsView = App.TableView.extend({
  22. templateName: require('templates/main/jobs'),
  23. content: [],
  24. /**
  25. * If no jobs table rows to show.
  26. */
  27. noDataToShow:true,
  28. filterCondition:[],
  29. /*
  30. If no jobs to display set noDataToShow to true, else set emptyData to false.
  31. */
  32. noDataToShowObserver: function () {
  33. if(this.get("controller.content.length") > 0){
  34. this.set("noDataToShow",false);
  35. }else{
  36. this.set("noDataToShow",true);
  37. }
  38. }.observes("controller.content.length"),
  39. willInsertElement: function () {
  40. var self = this;
  41. var name = this.get('controller.name');
  42. var colPropAssoc = this.get('colPropAssoc');
  43. var filterConditions = App.db.getFilterConditions(name);
  44. if (filterConditions) {
  45. this.set('filterConditions', filterConditions);
  46. var childViews = this.get('childViews');
  47. filterConditions.forEach(function(condition) {
  48. var view = childViews.findProperty('column', condition.iColumn);
  49. if (view) {
  50. //self.get('controller.filterObject').set(colPropAssoc[condition.iColumn], condition.value);
  51. view.set('value', condition.value);
  52. if(view.get('setPropertyOnApply')){
  53. view.setValueOnApply();
  54. }
  55. Em.run.next(function() {
  56. view.showClearFilter();
  57. });
  58. }
  59. });
  60. } else {
  61. this.clearFilters();
  62. }
  63. this.onApplyIdFilter();
  64. this.set('tableFilteringComplete', true);
  65. },
  66. didInsertElement: function () {
  67. if(!this.get('controller.sortingColumn')){
  68. var columns = this.get('childViews')[0].get('childViews')
  69. if(columns && columns.findProperty('name', 'startTime')){
  70. columns.findProperty('name','startTime').set('status', 'sorting_desc');
  71. this.get('controller').set('sortingColumn', columns.findProperty('name','startTime'))
  72. }
  73. }
  74. },
  75. onApplyIdFilter: function() {
  76. var isIdFilterApplied = this.get('controller.filterObject.isIdFilterApplied');
  77. this.get('childViews').forEach(function(childView) {
  78. if (childView['clearFilter'] && childView.get('column') != 1) {
  79. if(isIdFilterApplied){
  80. childView.clearFilter();
  81. }
  82. var childOfChild = childView.get('childViews')[0];
  83. if(childOfChild){
  84. Em.run.next(function() {
  85. childOfChild.set('disabled', isIdFilterApplied);
  86. })
  87. }
  88. }
  89. });
  90. }.observes('controller.filterObject.isIdFilterApplied'),
  91. saveFilter: function () {
  92. if(this.get('tableFilteringComplete')){
  93. this.updateFilter(1, this.get('controller.filterObject.id'), 'string');
  94. this.updateFilter(2, this.get('controller.filterObject.user'), 'string');
  95. this.updateFilter(4, this.get('controller.filterObject.windowEnd'), 'date');
  96. }
  97. }.observes(
  98. 'controller.filterObject.id',
  99. 'controller.filterObject.user',
  100. 'controller.filterObject.windowEnd'
  101. ),
  102. sortView: sort.wrapperView,
  103. idSort: sort.fieldView.extend({
  104. column: 1,
  105. name: 'id',
  106. displayName: Em.I18n.t('jobs.column.id'),
  107. type: 'string'
  108. }),
  109. userSort: sort.fieldView.extend({
  110. column: 2,
  111. name: 'user',
  112. displayName: Em.I18n.t('jobs.column.user'),
  113. type: 'string'
  114. }),
  115. startTimeSort: sort.fieldView.extend({
  116. column: 3,
  117. name: 'startTime',
  118. displayName: Em.I18n.t('jobs.column.start.time'),
  119. type: 'number'
  120. }),
  121. endTimeSort: sort.fieldView.extend({
  122. column: 4,
  123. name: 'endTime',
  124. displayName: Em.I18n.t('jobs.column.end.time'),
  125. type: 'number'
  126. }),
  127. durationSort: sort.fieldView.extend({
  128. column: 5,
  129. name: 'duration',
  130. displayName: Em.I18n.t('jobs.column.duration'),
  131. type: 'number'
  132. }),
  133. /**
  134. * Select View with list of "rows-per-page" options
  135. * @type {Ember.View}
  136. */
  137. rowsPerPageSelectView: Em.Select.extend({
  138. content: ['10', '25', '50', '100', "250", "500"],
  139. valueBinding: "controller.filterObject.jobsLimit",
  140. change: function () {
  141. this.get('parentView').saveDisplayLength();
  142. }
  143. }),
  144. /**
  145. * return filtered number of all content number information displayed on the page footer bar
  146. * @returns {String}
  147. */
  148. filteredJobs: function () {
  149. return Em.I18n.t('jobs.filtered.jobs').format(this.get('content').get('length'), this.get('controller.totalOfJobs'));
  150. }.property('content.length', 'filteredContent.length', 'controller.totalOfJobs'),
  151. pageContentObserver: function () {
  152. if (!$.browser.mozilla) {
  153. $('.job-link').on('mouseleave', function() {
  154. $('.tooltip').remove();
  155. });
  156. };
  157. if (!this.get('controller.loading')) {
  158. if ($('.tooltip').length) {
  159. Ember.run.later(this, function() {
  160. if ($('.tooltip').length > 1) {
  161. $('.tooltip').first().remove();
  162. };
  163. }, 500);
  164. };
  165. };
  166. }.observes('controller.loading'),
  167. init: function() {
  168. this._super();
  169. App.tooltip($('body'), {
  170. selector: '[rel="tooltip"]',
  171. template: '<div class="tooltip jobs-tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
  172. placement: 'bottom'
  173. });
  174. },
  175. willDestroyElement : function() {
  176. $('.tooltip').remove();
  177. },
  178. /**
  179. * Filter-field for Jobs ID.
  180. * Based on <code>filters</code> library
  181. */
  182. jobsIdFilterView: filters.createTextView({
  183. column: 1,
  184. showApply: true,
  185. setPropertyOnApply: 'controller.filterObject.id'
  186. }),
  187. /**
  188. * Filter-list for User.
  189. * Based on <code>filters</code> library
  190. */
  191. userFilterView: filters.createTextView({
  192. column: 2,
  193. fieldType: 'input-small',
  194. showApply: true,
  195. setPropertyOnApply: 'controller.filterObject.user'
  196. }),
  197. /**
  198. * Filter-field for Start Time.
  199. * Based on <code>filters</code> library
  200. */
  201. startTimeFilterView: filters.createSelectView({
  202. fieldType: 'input-120',
  203. column: 3,
  204. content: ['Any', 'Past 1 hour', 'Past 1 Day', 'Past 2 Days', 'Past 7 Days', 'Past 14 Days', 'Past 30 Days', 'Custom'],
  205. valueBinding: "controller.filterObject.startTime",
  206. onChangeValue: function () {
  207. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'date');
  208. }
  209. }),
  210. /**
  211. * associations between content (jobs list) property and column index
  212. */
  213. colPropAssoc: function () {
  214. var associations = [];
  215. associations[1] = 'id';
  216. associations[2] = 'user';
  217. associations[3] = 'startTime';
  218. associations[4] = 'endTime';
  219. return associations;
  220. }.property(),
  221. clearFilters: function() {
  222. this.get('childViews').forEach(function(childView) {
  223. if (childView['clearFilter']) {
  224. childView.clearFilter();
  225. }
  226. });
  227. },
  228. jobFailMessage: function() {
  229. return Em.I18n.t('jobs.table.job.fail');
  230. }.property()
  231. })