123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- app.controller('offlineTaskCtrl', ['$scope', '$http', '$timeout', '$stateParams', 'uiGridConstants', 'i18nService', 'toaster', 'FileUploader', function ($scope, $http, $timeout, $stateParams, uiGridConstants, i18nService, toaster, FileUploader) {
- i18nService.setCurrentLang("zh-cn");
- var searchKey = $stateParams.searchKey || "";
- $scope.gridOptions = {
- data: 'myData',
- showGridFooter: true, //是否显示grid footer
- //-------- 分页属性 ----------------
- paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
- paginationCurrentPage: 1, //当前页码
- paginationPageSize: 10, //每页显示个数
- totalItems: 0,// 总数量
- useExternalPagination: true,//是否使用分页按钮
- //过滤
- enableFiltering: true,
- columnDefs: [],
- //---------------api---------------------
- onRegisterApi: function (gridApi) {
- $scope.gridApi = gridApi;
- gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
- if ($scope.setPagingData) {
- $scope.getPagedDataAsync(newPage, pageSize);
- }
- });
- }
- };
- //枚举常量
- $scope.enum = {
- status: [
- {value: "PENDING", label: "处理中"},
- {value: "STARTED", label: "已开启"},
- {value: "RETRY", label: "等待重试"},
- {value: "FAILURE", label: "失败"},
- {value: "SUCCESS", label: "成功"},
- {value: "UNKNOWN", label: "未知"}
- ],
- };
- //查询条件
- var condition = $scope.condition = {
- searchKey: searchKey
- };
- function setColumnDefs() {
- $scope.gridOptions.columnDefs = [
- {field: 'type', displayName: '任务类型'},
- {field: 'name', displayName: '任务名称'},
- {field: 'startTime', displayName: '任务执行时间'},
- {
- field: 'status', displayName: '任务状态',
- cellTemplate: '<div class="ui-grid-cell-contents" ng-click="grid.appScope.refreshStatus(row.entity)">{{grid.appScope.formatterStatus(row.entity)}}</div>'
- },
- {
- field: 'operation',
- minWidth: 180,
- displayName: '操作',
- enableFiltering: false,
- enableSorting: false,
- enableHiding: false,//禁止在列选择器中隐藏
- enableColumnMenu: false,// 是否显示列头部菜单按钮
- cellTemplate: '<div class="grid-button">' +
- '<button class="btn btn-sm btn-rounded btn-success" ng-click="grid.appScope.refreshStatus(row.entity)"><i class="fa fa-refresh"></i> 更新状态</button>' +
- '<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>' +
- '</div>'
- },
- ];
- var fields = $scope.gridOptions.columnDefs;
- for (var index in fields) {
- var item = fields[index];
- if (item && item['minWidth'] == null) {
- item['minWidth'] = 100;
- }
- }
- }
- function initDataGrid() {
- //首次加载表格
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }
- $scope.setPagingData = function (data, curPage, pageSize) {
- var pagedData = data.data.dataList;
- $scope.myData = pagedData;
- $scope.gridOptions.totalItems = data.data.total;
- };
- $scope.getPagedDataAsync = function (curPage, pageSize) {
- var params = {
- pageSize: pageSize,
- pageIndex: curPage
- };
- if (condition.searchKey != "") {
- params.searchKey = condition.searchKey
- }
- $http.get('/manager/getOfflineTaskList', {
- params: params
- }).then(function (data) {
- $scope.setPagingData(data.data, curPage, pageSize);
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取数据失败");
- });
- };
- setColumnDefs();
- initDataGrid();
- //事件
- $scope.event = {
- search: function () {
- $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
- }
- };
- $scope.formatterStatus = function (entity) {
- var status = entity.status;
- var statusList = $scope.enum.status;
- var label = "";
- for (var index = 0; index < statusList.length; index++) {
- var item = statusList[index];
- if (item.value == status) {
- label = item.label
- }
- }
- return label;
- };
- //刷新任务状态
- $scope.refreshStatus = function (entity) {
- $http.get('/manager/getOfflineTaskStatus', {
- params: {id: entity.id}
- }).then(function (data) {
- toaster.pop("success", "提示", "操作成功,请等待结果");
- entity.status = data.data.payload;
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取状态失败");
- });
- };
- }]);
|