'use strict';
/**
* controller for User Profile Example
*/
// "$aside", "toaster", "api_bpm_domain", "api_configure_data", "api_cmdb", "api_configure_form",
app.controller('fixedCtrl', ["$rootScope", "$scope", "$http", "$state", "$timeout", "$injector", '$parse', "$interval", "$modal", "$stateParams", "$aside", "SweetAlert", "toaster", "FileUploader", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", "api_configure_data", "api_cmdb", "api_configure_form", function($rootScope, $scope, $http, $state, $timeout, $parse, $injector, $interval, $modal, $stateParams, $aside, SweetAlert, toaster, FileUploader, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain, api_configure_data, api_cmdb, api_configure_form) {
$scope.langs = i18nService.getAllLangs();
$scope.lang = 'zh-cn';
i18nService.setCurrentLang($scope.lang);
var loginUser = $rootScope.user;
$scope.showdown = false;
$scope.clickshow = function() {
$scope.showdown = !$scope.showdown;
}
$scope.gridOptions = {};
$scope.gridOptions.data = 'myData';
$scope.gridOptions.enableColumnResizing = true;
$scope.gridOptions.enableFiltering = false;
$scope.gridOptions.enableGridMenu = false;
$scope.gridOptions.enableSelectAll = true;
$scope.gridOptions.enableRowSelection = true;
$scope.gridOptions.showGridFooter = true;
$scope.gridOptions.showColumnFooter = false;
$scope.gridOptions.fastWatch = true;
$scope.gridOptions.enableSorting = true;
$scope.gridOptions.useExternalSorting = true;
$scope.gridOptions.useExternalFiltering = true;
$scope.gridOptions.useExternalPagination = true;
$scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
$scope.gridOptions.paginationPageSize = 10;
$scope.gridOptions.multiSelect = true;
// $scope.gridOptions.enableRowHeaderSelection = true;
// $scope.gridOptions.enableRowSelection = true;
// $scope.gridOptions.enableFullRowSelection = true;
// $scope.gridOptions.enableSelectionBatchEvent = true;
var mun = $scope.gridOptions.paginationPageSize;
$scope.gridOptions.rowTemplate = "
";
$scope.gridOptions.rowIdentity = function(row) {
return row.id;
};
$scope.gridOptions.getRowIdentity = function(row) {
return row.id;
};
$scope.gridOptions.columnDefs = [{
name: 'item',
enableSorting: false,
displayName: '序号',
width: 49,
enableFiltering: false,
cellTemplate: '' +
'
{{row.entity.item}}
' +
'
'
},
{
name: 'uuid',
enableSorting: false,
displayName: '资产编码',
width: 194,
enableFiltering: false,
cellTemplate: '' +
'
{{row.entity.uuid}}
' +
'
'
},
{
name: 'props.hw_mingcheng',
enableSorting: false,
displayName: '资产名称',
width: 148,
enableFiltering: false,
cellTemplate: '' +
'
{{row.entity.props.hw_mingcheng}}
' +
'
'
},
{
name: 'props.hw_state',
enableSorting: false,
displayName: '类型',
width: 120,
enableFiltering: false,
cellTemplate: '' +
'
{{row.entity.props.hw_state}}
' +
'
'
},
// {
// name: 'status',
// enableSorting: false,
// displayName: '资产型号',
// width: 217,
// enableFiltering: false ,
// // cellTemplate: '' +
// // '
{{row.entity.managementUnit.name}}
' +
// // '
'
// },
// {
// name: 'placeBasehw',
// enableSorting: false,
// displayName: '资产地点',
// width: 88,
// enableFiltering: false ,
// // cellTemplate: '' +
// // '
{{row.entity.managementUnit.name}}
' +
// // '
'
// },
{
name: 'createtime',
enableSorting: false,
displayName: '入库时间',
width: 175,
enableFiltering: false,
cellTemplate: '' +
'
{{row.entity.createtime}}
' +
'
'
},
{
name: 'lastupdatetime',
enableSorting: false,
displayName: '最后更新时间',
width: 175,
enableFiltering: false,
cellTemplate: '' +
'
{{row.entity.lastupdatetime}}
' +
'
'
},
// {
// name: 'props.meansmanager',
// enableSorting: false,
// displayName: '资产所有人',
// width: 98,
// enableFiltering: false ,
// // cellTemplate: '' +
// // '
{{row.entity.managementUnit.name}}
' +
// // '
'
// },
{
name: 'props.hw_zherenren',
enableSorting: false,
displayName: '责任人',
width: 104,
enableFiltering: false,
cellTemplate: '' +
'
{{row.entity.props.hw_zherenren}}
' +
'
'
},
{
name: 'props.meansliable',
enableSorting: false,
displayName: '所属项目',
width: 148,
enableFiltering: false,
// cellTemplate: '' +
// '
{{row.entity.managementUnit.name}}
' +
// '
'
},
{
name: 'props.meansliable',
enableSorting: false,
displayName: '是否贴过二维码',
width: 132,
enableFiltering: false,
// cellTemplate: '' +
// '
{{row.entity.managementUnit.name}}
' +
// '
'
},
{
name: '操作',
enableSorting: false,
width: 144,
cellTemplate: '',
enableFiltering: false
},
];
$scope.gridOptions.rowTemplate = "";
//修改
$scope.onClick = function(row) {
// $scope.classify="basehwntwsv";
var data = { "model": row };
$state.go('app.means.bill', { formKey: 'means_edit', service: 'api_cmdb', 'model': JSON.stringify(data) })
};
//查看
$scope.onview = function(row) {
var data = { "model": row };
$state.go('app.means.view', { formKey: 'means_edit', service: 'api_cmdb', 'model': JSON.stringify(data) })
};
$scope.gridOptions.onRegisterApi = function(gridApi) {
$scope.gridApi = gridApi;
gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
var filtersData = $scope.memoryfilterData;
$scope.fenye = newPage - 1;
filtersData.idx = newPage - 1;
filtersData.sum = pageSize;
$scope.refreshData('expand-right', filtersData);
// $scope.refreshData('expand-right', {"assignee":$rootScope.user.id, "candidateGroups":$rootScope.user.group[0].id, "idx":newPage-1,"sum":pageSize});
});
// $scope.sels=[];
gridApi.selection.on.rowSelectionChanged($scope, function(scope, ect) {
if (scope.isSelected) {
scope.grid.appScope.selected.items.push(scope.entity)
} else {
for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
if (scope.grid.appScope.selected.items[i].id == scope.entity.id) {
scope.grid.appScope.selected.items.splice(i, 1);
break;
}
}
}
// var j = 0;
// for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
// if (scope.grid.appScope.selected.items[i] == scope.entity) {
// j++;
// break;
// }
// }
// if (j == 1) {
// scope.grid.appScope.selected.items.splice(i, 1);
// } else {
// scope.grid.appScope.selected.items.push(scope.entity);
// }
$scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
});
gridApi.selection.on.rowSelectionChangedBatch($scope, function(rows) {
// if ($scope.gridApi.grid.api && $scope.gridApi.grid.api.grid.selection.selectAll == true) {
// for (var j = 0; j < rows.length; j++) {
// rows[j].isSelected = false;
// }
// }
var selectitem = [];
selectitem = angular.copy($scope.selected.items);
for (var j = 0; j < rows.length; j++) {
if (rows[j].isSelected == true) {
selectitem.push(rows[j].entity);
} else {
delete selectitem[j];
// rows.splice(j, 1);
}
}
$scope.selected.items = [];
for (var i = 0; i < selectitem.length; i++) {
if (selectitem[i]) {
$scope.selected.items.push(selectitem[i]);
}
}
// $scope.selected.items = $scope.gridApi.selection.getSelectedRows();
// rows.forEach($scope.selected.items);
// $scope.mySelectedRows = $scope.gridApi.selection.getSelectedRows();
// if ($scope.selected.items.length == 0) {
// $scope.selected.items = $scope.mySelectedRows;
// console.log($scope.selected.items);
// } else {
// if ($scope.mySelectedRows.length == 0) {
// for (var i = 0; i < $scope.selected.items.length; i++) {
// for (var j = 0; j < rows.length; j++) {
// if ($scope.selected.items[i].id == rows[j].entity.id) {
// $scope.selected.items.splice(i, 1);
// }
// }
// }
// } else {
// angular.forEach($scope.mySelectedRows, function(item) {
// $scope.selected.items.push(item);
// });
// }
// }
});
};
$scope.searchSolution = function(type, key) {
$scope.gridApi.grid.options.paginationCurrentPage = 1;
var memoryfilterData = {
"idx": 0,
"sum": $scope.gridOptions.paginationPageSize
};
angular.extend($scope.memoryfilterData, memoryfilterData);
$scope.memoryfilterData['searchCriteria'] = type;
$scope.memoryfilterData['keys'] = key;
// $scope.memoryfilterData=defaultFilterData;
// api_cmdb.searchkey(defaultFilterData.type,defaultFilterData.key,defaultFilterData.idx,defaultFilterData.sum).then(function(data){
// var myData = Restangular.stripRestangular(data);
// if(myData.data&&myData.status==200){
// $scope.gridOptions.totalItems = myData.total;
// $scope.myData = myData.data;
// }
// });
$scope.refreshData('expand-right', $scope.memoryfilterData);
}
// 资产状态
$scope.onChangestatus = function(searchType) {
console.log(searchType);
if (searchType == "") {
var all = {
"idx": 0,
"sum": $scope.gridOptions.paginationPageSize
};
$scope.refreshData('expand-right', all);
} else {
// defaultFilterData['status'] = searchType;
$scope.gridApi.grid.options.paginationCurrentPage = 1;
var memoryfilterData = {
"idx": 0,
"sum": $scope.gridOptions.paginationPageSize
};
angular.extend($scope.memoryfilterData, memoryfilterData);
$scope.memoryfilterData['state'] = searchType;
$scope.refreshData('expand-right', $scope.memoryfilterData);
}
}
this.selectRowFunction = function(data) {
$scope.ciId = data.id;
console.log(data);
};
//树形图
var apple_selected, tree, treedata_avm, treedata_geography;
$scope.my_tree_handler = function(branch) {
//var _ref;
var classify = $scope.classify = branch.prefix.toLowerCase() + branch.sign;
api_cmdb.query({ 'sign': classify }).then(function(data) {
var myData = Restangular.stripRestangular(data);
// console.log(myData.data.node);
if (myData.data && myData.status == 200) {
var ret = myData.data;
redrawSvg(myData);
}
});
};
$scope.my_data = [];
function convertListToTree(data, treeMap) {
var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
var root = null; //Initially set our loop to null
var parentNode = null;
//loop over data
for (var i = 0; i < data.length; i++) {
var datum = data[i];
//each node will have children, so let's give it a "children" poperty
datum.children = [];
//add an entry for this node to the map so that any future children can
//lookup the parent
idToNodeMap[datum.id] = datum;
//Does this node have a parent?
if (typeof datum.parent === "undefined" || datum.parent == null) {
//Doesn't look like it, so this node is the root of the tree
root = datum;
treeMap[datum.id] = root;
} else {
//This node has a parent, so let's look it up using the id
parentNode = idToNodeMap[datum.parent.id];
//We don't need this property, so let's delete it.
delete datum.parent;
//Let's add the current node as a child of the parent node.
parentNode.children.push(datum);
}
}
return root;
}
function convertParentToChildList(data) {
var treeMap = {};
var list = [];
convertListToTree(data, treeMap);
angular.forEach(treeMap, function(item) {
list.push(item);
});
return list;
}
$scope.my_tree = tree = {};
$scope.try_async_load = function() {
$scope.my_data = [];
$scope.select_treedata = [];
$scope.doing_async = true;
api_configure_data.fetchDataList('ciclassify', { 'idx': 0, 'sum': 100 }).then(function(result) {
//console.log(result['list']);
$scope.select_treedata = $scope.my_data = convertParentToChildList(result['list']);
$scope.doing_async = false;
// tree.expand_all();
//console.log(treelist);
});
};
$scope.select_treedata = [];
$scope.propTypeOptions = [];
$scope.try_async_load();
$scope.onFilterremove = function(item) {
console.log(item)
}
// 资产分类
$scope.onFilterCallback = function(item) {
//console.log(item);
if (angular.isDefined(item.children) && item.children.length >= 1) {
//not valid
} else {
var tempclassify = item.prefix.toLowerCase() + item.sign;
$scope.gridApi.grid.options.paginationCurrentPage = 1;
$scope.cifilter_classic = tempclassify;
var memoryfilterData = {
"sign": tempclassify,
"idx": 0,
"sum": $scope.gridOptions.paginationPageSize
}
angular.extend($scope.memoryfilterData, memoryfilterData)
// $scope.memoryfilterData=memoryfilterData;
$scope.refreshData('expand-right', $scope.memoryfilterData);
// 专有属性
api_configure_form.renderTabForm(tempclassify).then(function(data) {
var myData = Restangular.stripRestangular(data);
$scope.propTypeOptions = myData[2].form.fields;
// console.log($scope.propTypeOptions)
});
}
}
//关系下载模版
api_configure_data.fetchDataList('ciedgetype', { 'idx': 0, 'sum': 100 }).then(function(response) {
if (response) {
$scope.linktypeOptions = response.list;
// angular.forEach($scope.linktypeOptions,function(item){
// if(item.type==$scope.modelData.name){
// $scope.modelData.linkName=item;
// }
// })
}
})
$scope.rela = {};
$scope.onChange = function(rela) {
$scope.rela = rela;
}
//下载关系属性模版
$scope.openmodel = function() {
var modalInstance = $modal.open({
templateUrl: 'assets/views/means/tpl/relationdown.html',
controller: function($scope, scope, $modalInstance) {
$scope.key = {};
$scope.linktypeOptions = scope.linktypeOptions;
$scope.ok = function(key) {
$modalInstance.close(key);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
scope: function() {
return $scope;
}
}
});
modalInstance.result.then(function(selectedItem) {
if (selectedItem && angular.isDefined(selectedItem.type)) {
// if (angular.isDefined(selectedItem.type)) {
var type = 2;
// api_configure_data.fetchDataList('ciedgetype',{'idx':0,'sum':100}).then(function(data){
// if(data.status==200){
// var myData = Restangular.stripRestangular(data).list;
// for(var i=0;i 1) {
$scope.importUploader.queue.splice(0, 1);
}
};
importUploader.onAfterAddingAll = function(addedFileItems) {
console.info('onAfterAddingAll', addedFileItems);
};
importUploader.onProgressItem = function(fileItem, progress) {
console.info('onProgressItem', fileItem, progress);
};
importUploader.onProgressAll = function(progress) {
console.info('onProgressAll', progress);
};
importUploader.onSuccessItem = function(fileItem, response, status, headers) {
if (response.status == 200) {
SweetAlert.swal({
title: "导入成功!",
confirmButtonColor: "#007AFF",
type: "success"
}, function() {
$rootScope.isMask = false;
// $scope.ldloading.expand_right = false;
});
console.info('onSuccessItem', fileItem, response, status, headers);
} else {
SweetAlert.swal({
title: "导入失败!",
text: response.error,
type: "error"
}, function() {
$rootScope.isMask = false;
// $scope.ldloading.expand_right = false;
});
}
};
importUploader.onErrorItem = function(fileItem, response, status, headers) {
console.info('onErrorItem', fileItem, response, status, headers);
SweetAlert.swal({
title: "系统错误!",
text: "系统错误,请稍候重试!",
type: "error"
}, function() {
// $scope.ldloading.expand_right = false;
$rootScope.isMask = false;
});
};
importUploader.onCancelItem = function(fileItem, response, status, headers) {
console.info('onCancelItem', fileItem, response, status, headers);
};
importUploader.onCompleteItem = function(fileItem, response, status, headers) {
console.info('onCompleteItem', fileItem, response, status, headers);
};
importUploader.onCompleteAll = function() {
console.info('onCompleteAll');
};
$scope.import = function(style) {
// $scope.ldloading[style.replace('-', '_')] = true;
$rootScope.isMask = true;
importUploader.onBeforeUploadItem = function(item) {
angular.extend(item.headers, $rootScope.getSession());
item.formData.push({ 'filename': item.file.name });
console.info('onBeforeUploadItem', item);
};
importUploader.uploadAll();
}
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
importUploader: function() {
return $scope.importUploader;
}
}
});
modalInstance.result.then(function(selectedItem) {
if (selectedItem) {}
})
}
//添加
$scope.addData = function(size) {
$state.go('app.means.editor', { formKey: 'means_editor', service: 'api_bpm_data' });
}
//下载资产模版
$scope.openmeans = function() {
var modalInstance = $modal.open({
templateUrl: 'assets/views/means/tpl/meansdown.html',
controller: function($scope, scope, $modalInstance) {
$scope.item = {};
$scope.headname = "资产模版下载";
$scope.select_treedata = scope.select_treedata;
$scope.ok = function(item) {
$modalInstance.close(item);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
scope: function() {
return $scope;
}
}
});
modalInstance.result.then(function(selectedItem) {
$rootScope.isMask = true;
if (selectedItem) {
// if (angular.isDefined(classfy)) {
var type = 1;
// api_configure_data.fetchDataList('ciclassify', { 'idx': 0, 'sum': 100 }).then(function(data) {
// if (data.status == 200) {
// var myData = Restangular.stripRestangular(data).list;
// for (var i = 0; i < $scope.select_treedata.length; i++) {
// if ((myData[i].prefix.toLowerCase() + myData[i].sign) == classfy) {
$http({
url: api_configure_data.downModels(type, selectedItem.id, selectedItem.label).getRequestedUrl(),
method: 'GET',
headers: {
// 'Content-type' : 'application/xls',
'Accept': '*/*'
},
responseType: 'arraybuffer'
}).success(function(data, status, headers, config) {
$rootScope.isMask = false;
var file = new Blob([data], {
type: 'application/octet-stream'
// type : 'application/vnd.ms-excel'
});
//trick to download store a file having its URL
var fileURL = URL.createObjectURL(file);
var a = document.createElement('a');
a.href = fileURL;
a.target = '_blank';
a.download = "资产属性.xlsx";
document.body.appendChild(a);
a.click();
}).error(function(data, status, headers, config) {
console.log(data);
$rootScope.isMask = false;
});
// break;
// }
// }
// }
// })
} else {
SweetAlert.swal({
title: "未选择资产分类!",
text: "请选择资产分类",
type: "error"
}, function() {
$rootScope.isMask = false;
});
}
// }
});
}
// //导出模版
// $scope.download = function(classfy) {
// if (angular.isDefined(classfy)) {
// var type = 1;
// api_configure_data.fetchDataList('ciclassify', { 'idx': 0, 'sum': 100 }).then(function(data) {
// if (data.status == 200) {
// var myData = Restangular.stripRestangular(data).list;
// for (var i = 0; i < myData.length; i++) {
// if ((myData[i].prefix.toLowerCase() + myData[i].sign) == classfy) {
// $http({
// url: api_configure_data.downModels(type, myData[i].id, myData[i].label).getRequestedUrl(),
// method: 'GET',
// headers: {
// // 'Content-type' : 'application/xls',
// 'Accept': '*/*'
// },
// responseType: 'arraybuffer'
// }).success(function(data, status, headers, config) {
// var file = new Blob([data], {
// type: 'application/octet-stream'
// // type : 'application/vnd.ms-excel'
// });
// //trick to download store a file having its URL
// var fileURL = URL.createObjectURL(file);
// var a = document.createElement('a');
// a.href = fileURL;
// a.target = '_blank';
// a.download = "资产属性.xlsx";
// document.body.appendChild(a);
// a.click();
// }).error(function(data, status, headers, config) {
// console.log(data);
// });
// break;
// }
// }
// }
// })
// } else {
// SweetAlert.swal({
// title: "未选择资产分类!",
// text: "请选择资产分类",
// type: "error"
// })
// }
// }
// $scope.$watch("cifilter_classic",function(val){
// console.log(val)
// })
// $scope.$watch("searchStatus",function(val){
// console.log(val)
// })
// 重置按钮
$scope.reset = function() {
$scope.propTypeOptions = [];
$scope.refreshData('expand-right', defaultFilterData);
$scope.memoryfilterData = {
"idx": 0,
"sum": $scope.gridOptions.paginationPageSize,
}
// $scope.searchStatus="请选择状态";
}
// 新增下拉框
$scope.key1 = {};
$scope.key2 = {};
$scope.key3 = {};
$scope.key4 = {};
$scope.key5 = {};
$scope.key6 = {};
$scope.key7 = {};
$scope.key8 = {};
$scope.key9 = {};
$scope.key10 = {};
$scope.key11 = {};
$scope.key12 = {};
$scope.key13 = {};
$scope.key14 = {};
$scope.key15 = {};
$scope.key16 = {};
$scope.key17 = {};
$scope.key18 = {};
$scope.key19 = {};
$scope.key20 = {};
$scope.new_one = [
{ "keys": "key1.propTypeOptions", "vals": "" },
];
var k = 1;
// 新增按钮
$scope.new_select = function() {
k++;
$scope.new_one.push({ "keys": "key" + k + ".propTypeOptions", "vals": "" })
}
// $scope.dwdw=function(){
// for(var j=0;j<$scope.new_one.length;j++){
// console.log($scope.propTypeOptions.indexOf($scope.new_one[j].keys));
// delete $scope.propTypeOptions[$scope.propTypeOptions.indexOf($scope.new_one[j].keys)];
// }
// console.log($scope.propTypeOptions);
// }
// setInterval(function(){
// // console.log('ok')
// for(var j=0;j<$scope.new_one.length;j++){
// delete $scope.propTypeOptions[$scope.propTypeOptions.indexOf($scope.new_one[j].keys)];
// console.log($scope.propTypeOptions);
// }
// },3000)
// 高级搜索搜索
$scope.gaoji_search = function() {
var sear_data = {
"idx": 0,
"sum": $scope.gridOptions.paginationPageSize,
}
for (var j = 0; j < $scope.new_one.length; j++) {
sear_data[$scope.new_one[j].keys.key] = $scope.new_one[j].vals;
}
$scope.refreshData('expand-right', sear_data);
}
$scope.senior_show = false;
// 高级搜索按钮
$scope.senior_cli = function() {
$scope.senior_show = true;
$scope.new_one = [
{ "keys": "key1.propTypeOptions", "vals": "" },
];
k = 3;
}
// 高级搜索关闭按钮
$scope.close = function() {
$scope.senior_show = false
}
//导出
$scope.exportopen = function() {
var modalInstance = $modal.open({
templateUrl: 'assets/views/means/tpl/meansdown.html',
controller: function($scope, scope, $modalInstance) {
$scope.item = {};
$scope.headname = "资产导出";
$scope.select_treedata = scope.select_treedata;
$scope.ok = function(item) {
$modalInstance.close(item);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
},
size: 'sm',
resolve: {
scope: function() {
return $scope;
}
}
});
modalInstance.result.then(function(selectedItem) {
$rootScope.isMask = true;
if (selectedItem) {
// if (angular.isDefined(classfy)) {
var type = 1;
// api_configure_data.fetchDataList('ciclassify', { 'idx': 0, 'sum': 100 }).then(function(data) {
// if (data.status == 200) {
// var myData = Restangular.stripRestangular(data).list;
// for (var i = 0; i < $scope.select_treedata.length; i++) {
// if ((myData[i].prefix.toLowerCase() + myData[i].sign) == classfy) {
$http({
url: api_cmdb.exportData(selectedItem.label, selectedItem.id).getRequestedUrl(),
method: 'GET',
headers: {
// 'Content-type' : 'application/xls',
'Accept': '*/*'
},
responseType: 'arraybuffer'
}).success(function(data, status, headers, config) {
$rootScope.isMask = false;
var file = new Blob([data], {
type: 'application/octet-stream'
// type : 'application/vnd.ms-excel'
});
//trick to download store a file having its URL
var fileURL = URL.createObjectURL(file);
var a = document.createElement('a');
a.href = fileURL;
a.target = '_blank';
a.download = selectedItem.label + '.xlsx';
document.body.appendChild(a);
a.click();
}).error(function(data, status, headers, config) {
$rootScope.isMask = false;
console.log(data);
});
// break;
// }
// }
// }
// })
} else {
SweetAlert.swal({
title: "未选择资产分类!",
text: "请选择资产分类",
type: "error"
}, function() {
$rootScope.isMask = false;
});
}
// }
});
}
// $scope.export = function(classfy, style) {
// if (angular.isDefined(classfy)) {
// $scope.ldloading[style.replace('-', '_')] = true;
// api_configure_data.fetchDataList('ciclassify', { 'idx': 0, 'sum': 100 }).then(function(data) {
// if (data.status == 200) {
// var myData = Restangular.stripRestangular(data).list;
// for (var i = 0; i < myData.length; i++) {
// if ((myData[i].prefix.toLowerCase() + myData[i].sign) == classfy) {
// $http({
// url: api_cmdb.exportData(myData[i].label, myData[i].id).getRequestedUrl(),
// method: 'GET',
// headers: {
// // 'Content-type' : 'application/xls',
// 'Accept': '*/*'
// },
// responseType: 'arraybuffer'
// }).success(function(data, status, headers, config) {
// $scope.ldloading.zoom_in = false;
// var file = new Blob([data], {
// type: 'application/octet-stream'
// // type : 'application/vnd.ms-excel'
// });
// //trick to download store a file having its URL
// var fileURL = URL.createObjectURL(file);
// var a = document.createElement('a');
// a.href = fileURL;
// a.target = '_blank';
// a.download = myData[i].label + '.xlsx';
// document.body.appendChild(a);
// a.click();
// }).error(function(data, status, headers, config) {
// $scope.ldloading.zoom_in = false;
// console.log(data);
// });
// break;
// }
// }
// }
// })
// } else {
// SweetAlert.swal({
// title: "未选择资产分类!",
// text: "请选择资产分类",
// type: "error"
// })
// }
// }
// }
//导入
var importUploader = $scope.importUploader = new FileUploader({
url: api_cmdb.importData().getRequestedUrl()
});
importUploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/ , filter, options) {
console.info('onWhenAddingFileFailed', item, filter, options);
};
importUploader.onAfterAddingFile = function(fileItem) {
console.info('onAfterAddingFile', fileItem);
};
importUploader.onAfterAddingAll = function(addedFileItems) {
console.info('onAfterAddingAll', addedFileItems);
};
importUploader.onProgressItem = function(fileItem, progress) {
console.info('onProgressItem', fileItem, progress);
};
importUploader.onProgressAll = function(progress) {
console.info('onProgressAll', progress);
};
importUploader.onSuccessItem = function(fileItem, response, status, headers) {
if (response.status == 200) {
SweetAlert.swal({
title: "导入成功!",
confirmButtonColor: "#007AFF",
type: "success"
}, function() {
$rootScope.isMask = false;
});
console.info('onSuccessItem', fileItem, response, status, headers);
} else {
SweetAlert.swal({
title: "导入失败!",
text: response.error,
type: "error"
}, function() {
$rootScope.isMask = false;
});
}
};
importUploader.onErrorItem = function(fileItem, response, status, headers) {
console.info('onErrorItem', fileItem, response, status, headers);
SweetAlert.swal({
title: "系统错误!",
text: "系统错误,请稍候重试!",
type: "error"
}, function() {
$rootScope.isMask = false;
});
};
importUploader.onCancelItem = function(fileItem, response, status, headers) {
console.info('onCancelItem', fileItem, response, status, headers);
};
importUploader.onCompleteItem = function(fileItem, response, status, headers) {
console.info('onCompleteItem', fileItem, response, status, headers);
};
importUploader.onCompleteAll = function() {
console.info('onCompleteAll');
};
$scope.import = function(style) {
$rootScope.isMask = true;
importUploader.onBeforeUploadItem = function(item) {
angular.extend(item.headers, $rootScope.getSession());
item.formData.push({ 'filename': item.file.name });
console.info('onBeforeUploadItem', item);
};
importUploader.uploadAll();
}
$scope.removeData = function() {
var rmvList = $scope.selected.items.id;
// angular.forEach($scope.selected.items,function(item){
// rmvList.push(item.id);
// });
// if(rmvList.length>0){
api_cmdb.put($scope.selected.items, rmvList).then(function(response) {
if (response.status == 200) {
SweetAlert.swal({
title: "删除成功!",
type: "success",
confirmButtonColor: "#007AFF"
}, function() {
$scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList, o.id); });
$scope.selected = {
items: []
};
});
} else {
SweetAlert.swal({
title: "操作异常!",
text: "系统异常,请稍后重试,或者联系管理员!",
type: "error"
});
}
})
// }
}
$scope.selected = {
items: []
}
$scope.editted = {
items: []
}
var defaultFilterData = {
// "assignee":2,
// "sign":"basehwitndl",
"idx": 0,
"sum": $scope.gridOptions.paginationPageSize
};
$scope.memoryfilterData = {
// "assignee":2,
// "sign":"basehwitndl",
"idx": 0,
"sum": $scope.gridOptions.paginationPageSize
}
$scope.ldloading = {};
var pdKey = $state.current.pdKey;
$scope.refreshData = function(style, filterData) {
if (angular.isUndefined(filterData)) {
filterData = defaultFilterData;
}
$scope.myData = [];
// $scope.gridOptions['sum']=filterData.sum;
api_cmdb.query(filterData).then(function(data) {
// $scope.callsPending--;
var myData = Restangular.stripRestangular(data);
$scope.gridOptions['totalItems'] = data.total;
// angular.forEach(myData.data.node,function(item){
// moment(item.createtime).format('YYYY-MM-DD');
// })
for (var i = 0; i < myData.data.node.length; i++) {
myData.data.node[i].createtime = moment(myData.data.node[i].createtime).format('YYYY-MM-DD');
}
$scope.myData = myData.data.node;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
}
}, function() {});
};
$scope.refreshData('expand-right', defaultFilterData);
}]);
app.controller('MeansOperCtrl', ['$rootScope', '$http', '$scope', function($rootScope, $http, $scope) {
// console.log('$rootScope.user3='+JSON.stringify($scope.item));
// if( $scope.item.handlerUser!=null){
// if ($rootScope.user.id==$scope.item.handlerUser.id) {
// $scope.item.chaozuoPower=true;
// }
// }
$scope.look = function() {
$scope.colobject.grid.appScope.lookFunction($scope.item);
// console.log('$scope.item='+JSON.stringify($scope.item));
}
$scope.edit = function() {
$scope.colobject.grid.appScope.selectRowFunction($scope.item);
console.log('$scope.item=' + JSON.stringify($scope.item));
// $scope.doEdit($scope.item.id);
}
}]);
//操作按钮权限控制
app.controller('ywxt_caozuoCtrl', ['$rootScope', '$http', '$scope', '$modal', 'api_cmdb2', 'api_bpm_domain', 'up_down_file', function($rootScope, $http, $scope, $modal, api_cmdb2, api_bpm_domain, up_down_file) {
$scope.edit = function() {
console.log($scope.item);
}
}]);
app.directive('meansoperator', function() {
return {
restrict: 'E',
scope: {
item: '=',
colobject: '='
},
controller: 'MeansOperCtrl',
template: ''
};
});
//操作
app.directive('wt', function() {
return {
restrict: 'E',
scope: {
item: '=',
colobject: '='
},
controller: 'ywxt_caozuoCtrl',
template: ''
};
});