offlineTaskCtrl.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. app.controller('offlineTaskCtrl', ['$scope', '$http', '$timeout', '$stateParams', 'uiGridConstants', 'i18nService', 'toaster', 'FileUploader', function ($scope, $http, $timeout, $stateParams, uiGridConstants, i18nService, toaster, FileUploader) {
  2. i18nService.setCurrentLang("zh-cn");
  3. var searchKey = $stateParams.searchKey || "";
  4. $scope.gridOptions = {
  5. data: 'myData',
  6. showGridFooter: true, //是否显示grid footer
  7. //-------- 分页属性 ----------------
  8. paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
  9. paginationCurrentPage: 1, //当前页码
  10. paginationPageSize: 10, //每页显示个数
  11. totalItems: 0,// 总数量
  12. useExternalPagination: true,//是否使用分页按钮
  13. //过滤
  14. enableFiltering: true,
  15. columnDefs: [],
  16. //---------------api---------------------
  17. onRegisterApi: function (gridApi) {
  18. $scope.gridApi = gridApi;
  19. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  20. if ($scope.setPagingData) {
  21. $scope.getPagedDataAsync(newPage, pageSize);
  22. }
  23. });
  24. }
  25. };
  26. //枚举常量
  27. $scope.enum = {
  28. status: [
  29. {value: "PENDING", label: "处理中"},
  30. {value: "STARTED", label: "已开启"},
  31. {value: "RETRY", label: "等待重试"},
  32. {value: "FAILURE", label: "失败"},
  33. {value: "SUCCESS", label: "成功"},
  34. {value: "UNKNOWN", label: "未知"}
  35. ],
  36. };
  37. //查询条件
  38. var condition = $scope.condition = {
  39. searchKey: searchKey
  40. };
  41. function setColumnDefs() {
  42. $scope.gridOptions.columnDefs = [
  43. {field: 'type', displayName: '任务类型'},
  44. {field: 'name', displayName: '任务名称'},
  45. {field: 'startTime', displayName: '任务执行时间'},
  46. {
  47. field: 'status', displayName: '任务状态',
  48. cellTemplate: '<div class="ui-grid-cell-contents" ng-click="grid.appScope.refreshStatus(row.entity)">{{grid.appScope.formatterStatus(row.entity)}}</div>'
  49. },
  50. {
  51. field: 'operation',
  52. minWidth: 180,
  53. displayName: '操作',
  54. enableFiltering: false,
  55. enableSorting: false,
  56. enableHiding: false,//禁止在列选择器中隐藏
  57. enableColumnMenu: false,// 是否显示列头部菜单按钮
  58. cellTemplate: '<div class="grid-button">' +
  59. '<button class="btn btn-sm btn-rounded btn-success" ng-click="grid.appScope.refreshStatus(row.entity)"><i class="fa fa-refresh"></i> 更新状态</button>' +
  60. '<a target="_blank" ng-if="row.entity.link" class="btn btn-sm btn-rounded btn-info" ng-disabled="row.entity.status!=\'SUCCESS\'" href="{{row.entity.link}}"><i class="fa fa-link"></i> 下载结果</a>' +
  61. '</div>'
  62. },
  63. ];
  64. var fields = $scope.gridOptions.columnDefs;
  65. for (var index in fields) {
  66. var item = fields[index];
  67. if (item && item['minWidth'] == null) {
  68. item['minWidth'] = 100;
  69. }
  70. }
  71. }
  72. function initDataGrid() {
  73. //首次加载表格
  74. $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
  75. }
  76. $scope.setPagingData = function (data, curPage, pageSize) {
  77. var pagedData = data.data.dataList;
  78. $scope.myData = pagedData;
  79. $scope.gridOptions.totalItems = data.data.total;
  80. };
  81. $scope.getPagedDataAsync = function (curPage, pageSize) {
  82. var params = {
  83. pageSize: pageSize,
  84. pageIndex: curPage
  85. };
  86. if (condition.searchKey != "") {
  87. params.searchKey = condition.searchKey
  88. }
  89. $http.get('/manager/getOfflineTaskList', {
  90. params: params
  91. }).then(function (data) {
  92. $scope.setPagingData(data.data, curPage, pageSize);
  93. }).catch(function (data) {
  94. toaster.pop("error", "提示", "获取数据失败");
  95. });
  96. };
  97. setColumnDefs();
  98. initDataGrid();
  99. //事件
  100. $scope.event = {
  101. search: function () {
  102. $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
  103. }
  104. };
  105. $scope.formatterStatus = function (entity) {
  106. var status = entity.status;
  107. var statusList = $scope.enum.status;
  108. var label = "";
  109. for (var index = 0; index < statusList.length; index++) {
  110. var item = statusList[index];
  111. if (item.value == status) {
  112. label = item.label
  113. }
  114. }
  115. return label;
  116. };
  117. //刷新任务状态
  118. $scope.refreshStatus = function (entity) {
  119. $http.get('/manager/getOfflineTaskStatus', {
  120. params: {id: entity.id}
  121. }).then(function (data) {
  122. toaster.pop("success", "提示", "操作成功,请等待结果");
  123. entity.status = data.data.payload;
  124. }).catch(function (data) {
  125. toaster.pop("error", "提示", "获取状态失败");
  126. });
  127. };
  128. }]);