apps_view.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 date = require('utils/date');
  20. App.MainAppsView = Em.View.extend({
  21. templateName:require('templates/main/apps'),
  22. classNames:['table', 'dataTable'],
  23. oTable:null,
  24. types:function () {
  25. var result = new Array();
  26. var content = this.get('content');
  27. content.forEach(function (item) {
  28. result.push(item.get('type'));
  29. });
  30. return result;
  31. }.property('content'),
  32. uniqueTypes:function () {
  33. return this.get('controller').get('arrayUnique')(this.get('types'));
  34. }.property('types'),
  35. filterTypesView:Em.CollectionView.extend({
  36. tagName:'span',
  37. parentView:null,
  38. content:function () {
  39. var content = new Array();
  40. this.set('parentView', this._parentView);
  41. content.push({label:'All', active:'active'});
  42. for (var i = 0; i < this._parentView.get('uniqueTypes').length; i++) {
  43. content.push({
  44. label:this._parentView.get('uniqueTypes')[i],
  45. active:''
  46. })
  47. }
  48. return content;
  49. }.property('view.uniqueTypes'),
  50. filterByType:function (event) {
  51. var type = (event.context.label === 'All') ? '' : event.context.label;
  52. event.view._parentView.get('parentView').get('oTable').fnFilter(type, 1);
  53. },
  54. itemViewClass:Em.View.extend({
  55. tagName:'span',
  56. classNames:['btn', 'btn-link'],
  57. filterByType:function (event) {
  58. event.view._parentView.get('filterByType')(event);
  59. },
  60. template:Ember.Handlebars.compile('<a {{action "filterByType" view.content target="view"}}>{{view.content.label}}</a><p></p>')
  61. })
  62. }),
  63. didInsertElement:function () {
  64. var oTable = this.$('#dataTable').dataTable({
  65. "aoColumns":[
  66. null,
  67. null,
  68. null,
  69. null,
  70. null,
  71. { "sType":"ambari-date" },
  72. null
  73. ]
  74. });
  75. this.set('oTable', oTable);
  76. },
  77. content:function () {
  78. var content = App.router.get('mainAppsController.content');
  79. content.forEach(function (item) {
  80. item.set('numRuns', item.get('runs').get('content').length);
  81. item.set('executionTime', date.dateFormat(item.get('executionTime')));
  82. });
  83. return content;
  84. }.property('App.router.mainAppsController.content')
  85. });