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: '
{{grid.appScope.formatterStatus(row.entity)}}
'
},
{
field: 'operation',
minWidth: 180,
displayName: '操作',
enableFiltering: false,
enableSorting: false,
enableHiding: false,//禁止在列选择器中隐藏
enableColumnMenu: false,// 是否显示列头部菜单按钮
cellTemplate: ''
},
];
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", "提示", "获取状态失败");
});
};
}]);