dashboard.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import Ember from 'ember';
  18. export default Ember.Route.extend({
  19. history: Ember.inject.service(),
  20. errorMessage : "Error",
  21. queryParams: {
  22. jobType: { refreshModel: true },
  23. start: { refreshModel: true },
  24. filter: { refreshModel: true }
  25. },
  26. actions: {
  27. onShowJobDetails : function(params){
  28. this.transitionTo('job',{
  29. queryParams : {
  30. id : params.id,
  31. jobType : params.type,
  32. from: null,
  33. fromType: null
  34. }
  35. });
  36. },
  37. loading: function ( /*transition, originRoute*/ ) {
  38. Ember.$("#loading").css("display", "block");
  39. var app = this.controllerFor('application');
  40. if (app.get('currentRouteName') !== "dashboard") {
  41. return true;
  42. }
  43. return false;
  44. },
  45. error: function() {
  46. },
  47. doSearch (params){
  48. this.get('history').setSearchParams(params);
  49. Ember.$("#loading").css("display", "block");
  50. this.search(params);
  51. }
  52. },
  53. fetchJobs (url){
  54. var deferred = Ember.RSVP.defer();
  55. Ember.$.get(url).done(function(res){
  56. deferred.resolve(res);
  57. }).fail(function(){
  58. deferred.reject();
  59. });
  60. return deferred.promise;
  61. },
  62. search(params){
  63. params = params || {};
  64. var type = params.type || "wf",
  65. start = Number(params.start || 1),
  66. len = Number(params.len || Ember.ENV.PAGE_SIZE),
  67. index = 0,
  68. filter = params.filter || "",
  69. API_URL = Ember.ENV.API_URL,
  70. url = [API_URL,
  71. "/v2/jobs?jobtype=", type,
  72. "&offset=", start,
  73. "&len=", len,
  74. "&filter=", filter
  75. ].join(""),
  76. page = (start - 1) / len + 1;
  77. return this.fetchJobs(url).catch(function(){
  78. this.controllerFor('dashboard').set('model',{error : "Remote API Failed"});
  79. Ember.$("#loading").css("display", "none");
  80. }.bind(this)).then(function (res) {
  81. if(!res){
  82. return;
  83. }
  84. if (typeof res === "string") {
  85. res = JSON.parse(res);
  86. }
  87. res.jobs = [];
  88. if (res.workflows) {
  89. res.areWfs = true;
  90. res.type = "wf";
  91. res.workflows.forEach(function (job) {
  92. job.type = "wf";
  93. res.jobs.push(job);
  94. });
  95. }
  96. if (res.coordinatorjobs) {
  97. res.areCoords = true;
  98. res.type = "coords";
  99. res.coordinatorjobs.forEach(function (job) {
  100. job.type = "coordinatorjobs";
  101. job.id = job.coordJobId;
  102. job.appName = job.coordJobName;
  103. res.jobs.push(job);
  104. });
  105. }
  106. if (res.bundlejobs) {
  107. res.areBundles = true;
  108. res.type = "bundles";
  109. res.bundlejobs.forEach(function (job) {
  110. job.type = "bundlejobs";
  111. job.id = job.bundleJobId;
  112. job.appName = job.bundleJobName;
  113. res.jobs.push(job);
  114. });
  115. }
  116. res.pageSize = len;
  117. res.pages = [];
  118. while (index++ < (res.total / len)) {
  119. res.pages.push({ index: index, active: page === index });
  120. }
  121. res.jobTypeValue = type;
  122. res.filterValue = filter;
  123. res.pageSize = len;
  124. res.totalValue = res.total;
  125. res.page = page;
  126. res.start = start;
  127. res.end = (start + res.jobs.length - 1);
  128. res.time = new Date().getTime();
  129. this.controllerFor('dashboard').set('model', res);
  130. Ember.$("#loading").css("display", "none");
  131. return res;
  132. }.bind(this));
  133. },
  134. afterModel: function (model) {
  135. Ember.$("#loading").css("display", "none");
  136. },
  137. model: function (params) {
  138. }
  139. });