jobs_view.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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/mirroring/jobs'),
  23. content: function () {
  24. return this.get('controller.jobs');
  25. }.property('controller.jobs'),
  26. didInsertElement: function () {
  27. var mainMirroringController = App.router.get('mainMirroringController');
  28. if (!mainMirroringController.get('isLoaded')) {
  29. mainMirroringController.loadDatasets();
  30. }
  31. },
  32. dataset: function () {
  33. return this.get('controller.content');
  34. }.property('controller.content'),
  35. sortView: sort.wrapperView,
  36. idSort: sort.fieldView.extend({
  37. name: 'name',
  38. displayName: Em.I18n.t('mirroring.table.jobId'),
  39. type: 'string'
  40. }),
  41. startSort: sort.fieldView.extend({
  42. name: 'startDate',
  43. displayName: Em.I18n.t('mirroring.table.start'),
  44. type: 'number'
  45. }),
  46. endSort: sort.fieldView.extend({
  47. name: 'endDate',
  48. displayName: Em.I18n.t('mirroring.table.end'),
  49. type: 'number'
  50. }),
  51. /**
  52. * Filter view for name column
  53. * Based on <code>filters</code> library
  54. */
  55. idFilterView: filters.createTextView({
  56. fieldType: 'input-small',
  57. column: 1,
  58. onChangeValue: function () {
  59. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'number');
  60. }
  61. }),
  62. startFilterView: filters.createSelectView({
  63. fieldType: 'input-small',
  64. column: 2,
  65. content: ['Any', 'Past 1 Day', 'Past 2 Days', 'Past 7 Days', 'Past 14 Days', 'Past 30 Days'],
  66. onChangeValue: function () {
  67. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'date');
  68. }
  69. }),
  70. endFilterView: filters.createSelectView({
  71. fieldType: 'input-medium',
  72. column: 3,
  73. content: ['Any', 'Past 1 Day', 'Past 2 Days', 'Past 7 Days', 'Past 14 Days', 'Past 30 Days'],
  74. onChangeValue: function () {
  75. this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'date');
  76. }
  77. }),
  78. JobView: Em.View.extend({
  79. content: null,
  80. tagName: 'tr',
  81. canActionBeTaken: function () {
  82. var job_status = this.get('content.status');
  83. if (job_status == "RUNNING" || job_status == "SUSPENDED") {
  84. return true;
  85. }
  86. return false;
  87. }.property('content.status'),
  88. isKilled: function () {
  89. var job_status = this.get('content.status');
  90. return job_status == 'KILLED';
  91. }.property(),
  92. statusClass: function () {
  93. var job_status = this.get('content.status');
  94. switch (job_status) {
  95. case 'RUNNING' :
  96. return "btn btn-success dropdown-toggle";
  97. break;
  98. case 'SUSPENDED' :
  99. return "btn btn-warning dropdown-toggle";
  100. break;
  101. case 'SUCCEEDED' :
  102. return "label label-success";
  103. break;
  104. case 'KILLED' :
  105. return "label label-important";
  106. break;
  107. case 'WAITING' :
  108. return "label";
  109. break;
  110. case 'KILLED' :
  111. case 'FAILED' :
  112. case 'ERROR' :
  113. return "label label-important";
  114. break;
  115. default :
  116. return "label";
  117. break;
  118. }
  119. }.property('content.status'),
  120. listOfOptions: function () {
  121. var listOfActions = [];
  122. var status = this.get('content.status');
  123. switch (status) {
  124. case 'RUNNING' :
  125. listOfActions.push({title: 'Suspend', value: 'Suspend'});
  126. listOfActions.push({title: 'Abort', value: 'Abort'});
  127. break;
  128. case 'SUSPENDED' :
  129. listOfActions.push({title: 'Resume', value: 'Resume'});
  130. listOfActions.push({title: 'Abort', value: 'Abort'});
  131. break;
  132. }
  133. return listOfActions;
  134. }.property('content.status'),
  135. changeStatus: function (event) {
  136. var selected = event.context;
  137. var self = this;
  138. App.showConfirmationPopup(function () {
  139. switch (selected.title) {
  140. case 'Suspend' :
  141. self.set('content.status', 'SUSPENDED');
  142. break;
  143. case 'Resume' :
  144. self.set('content.status', 'RUNNING');
  145. break;
  146. case 'Abort' :
  147. self.set('content.status', 'KILLED');
  148. break;
  149. }
  150. });
  151. }
  152. }),
  153. /**
  154. * associations between dataset property and column index
  155. */
  156. colPropAssoc: function () {
  157. var associations = [];
  158. associations[1] = 'name';
  159. associations[2] = 'startDate';
  160. associations[3] = 'endDate';
  161. return associations;
  162. }.property()
  163. });