yarn-flow-activity.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. import Ember from 'ember';
  19. import TableDef from 'em-table/utils/table-definition';
  20. import ColumnDef from 'em-table/utils/column-definition';
  21. import lodash from 'lodash/lodash';
  22. function _createColumns() {
  23. var columns = [];
  24. columns.push({
  25. id: 'flowName',
  26. headerTitle: 'Flow Name',
  27. contentPath: 'flowName',
  28. observePath: true,
  29. }, {
  30. id: 'user',
  31. headerTitle: 'User',
  32. contentPath: 'user',
  33. observePath: true
  34. }, {
  35. id: 'uid',
  36. headerTitle: 'Flow ID',
  37. contentPath: 'uid',
  38. observePath: true,
  39. cellComponentName: 'em-table-linked-cell',
  40. minWidth: "300px",
  41. getCellContent: function (row) {
  42. return {
  43. routeName: 'yarn-flow.info',
  44. id: row.get('uid'),
  45. displayText: row.get('uid')
  46. };
  47. }
  48. }, {
  49. id: 'lastExecDate',
  50. headerTitle: 'Last Execution Date',
  51. contentPath: 'lastExecDate',
  52. observePath: true
  53. });
  54. return ColumnDef.make(columns);
  55. }
  56. function _getAggregatedFlowsData(flows) {
  57. var aggregatedFlows = [];
  58. flows = flows? flows.get('content') : [];
  59. var aggregated = lodash.groupBy(flows, function(flow) {
  60. return flow.getRecord().get('uid');
  61. });
  62. lodash.forIn(aggregated, function(flows) {
  63. let flowsInAsc = lodash.sortBy(flows, function(flow) {
  64. return flow.getRecord().get('lastExecDate');
  65. });
  66. let flowsInDesc = flowsInAsc.reverse();
  67. aggregatedFlows.push(flowsInDesc[0].getRecord());
  68. });
  69. return aggregatedFlows;
  70. }
  71. function _createRows(flows) {
  72. var data = [],
  73. aggregatedFlows = null,
  74. row = null;
  75. aggregatedFlows = _getAggregatedFlowsData(flows);
  76. aggregatedFlows.forEach(function(flow) {
  77. row = Ember.Object.create({
  78. user: flow.get('user'),
  79. flowName: flow.get('flowName'),
  80. uid: flow.get('uid'),
  81. lastExecDate: flow.get('lastExecDate')
  82. });
  83. data.push(row);
  84. });
  85. return Ember.A(data);
  86. }
  87. export default Ember.Controller.extend({
  88. breadcrumbs: [{
  89. text: "Home",
  90. routeName: 'application'
  91. }, {
  92. text: "Flow Activities",
  93. routeName: 'yarn-flow-activity',
  94. }],
  95. columns: _createColumns(),
  96. rows: Ember.computed('model', function() {
  97. return _createRows(this.get('model'));
  98. }),
  99. tableDefinition: TableDef.create({
  100. sortColumnId: 'lastExecDate',
  101. sortOrder: 'desc'
  102. }),
  103. getLastFlowExecutionInfoByFlowUid: function(uid) {
  104. var aggregatedFlows = _getAggregatedFlowsData(this.get('model'));
  105. var recent = aggregatedFlows.find(function(flow) {
  106. return flow.get('uid') === uid;
  107. });
  108. return recent;
  109. }
  110. });