123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977 |
- 'use strict';
- /**
- * controller for User Profile Example
- */
- // "$aside", "toaster", "api_bpm_domain", "api_configure_data", "api_cmdb", "api_configure_form",
- app.controller('meansCtrl', ["$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 = true;
- $scope.gridOptions.enableGridMenu = true;
- $scope.gridOptions.enableRowSelection = true;
- $scope.gridOptions.enableSelectAll = true;
- $scope.gridOptions.showGridFooter = true;
- $scope.gridOptions.showColumnFooter = true;
- $scope.gridOptions.fastWatch = 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.rowIdentity = function(row) {
- return row.id;
- };
- $scope.gridOptions.getRowIdentity = function(row) {
- return row.id;
- };
- $scope.gridOptions.columnDefs = [{
- name: '操作',
- width: 50,
- enableFiltering: false,
- cellTemplate: '<div class="links cl-effect-1">' +
- '<a ng-click="grid.appScope.onClick(row.entity)" tooltip="编辑" tooltip-placement="right"><i class="fa fa-pencil-square-o"></i></a>' +
- '</div>'
- },
- { name: 'uuid', enableSorting: false, displayName: '内部编码', width: 130, enableFiltering: false },
- { name: 'name', enableSorting: false, displayName: '资产名称', width: 100, enableFiltering: false },
- { name: 'title', enableSorting: false, displayName: '资产类型', width: 100, enableFiltering: false },
- { name: 'status', enableSorting: false, displayName: '资产状态', width: 100, enableFiltering: false },
- { name: 'placeBasehw', enableSorting: false, displayName: '资产地点', width: 80, enableFiltering: false },
- { name: 'createtime', enableSorting: false, displayName: '创建时间', width: 80, enableFiltering: false },
- { name: 'plantime', enableSorting: false, displayName: '预计报废时间', width: 80, enableFiltering: false },
- { name: 'props.meansmanager', enableSorting: false, displayName: '管理员', width: 80, enableFiltering: false },
- { name: 'lastupdatetime', enableSorting: false, displayName: '最后更新时间', width: 100, enableFiltering: false },
- { name: 'props.meansliable', enableSorting: false, displayName: '责任人', width: 80, enableFiltering: false }
- ];
- $scope.gridOptions.rowTemplate = "<div ng-click=\"onview(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
- //修改
- $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;
- filtersData.idx = newPage - 1;
- filtersData.sum = pageSize;
- // $scope.refreshData('expand-right', filtersData);
- $scope.gridApi.grid.selection.selectAll = false;
- $scope.myData = [];
- api_cmdb.query(filtersData).then(function(data) {
- var myData = Restangular.stripRestangular(data);
- $scope.gridOptions['totalItems'] = data.total;
- 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;
- if ($scope.myData.length > 0) {
- var index = 0;
- for (var i = 0; i < $scope.myData.length; i++) {
- for (var j = 0; j < $scope.selected.items.length; j++) {
- if ($scope.myData[i].id == $scope.selected.items[j].id) {
- index++;
- }
- }
- }
- if (index == 10) {
- $scope.gridApi.grid.selection.selectAll = true;
- }
- }
- }, function() {});
- // console.log($scope.gridApi)
- // $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) {
- // defaultFilterData['status'] = searchType;
- $scope.gridApi.grid.options.paginationCurrentPage = 1;
- var memoryfilterData = {
- "idx": 0,
- "sum": $scope.gridOptions.paginationPageSize
- };
- angular.extend($scope.memoryfilterData, memoryfilterData);
- $scope.memoryfilterData['status'] = 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;
- // });
- }
- }
- //关系下载模版
- 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<myData.length;i++){
- $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) {
- 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);
- });
- } else {
- SweetAlert.swal({
- title: "未选择资产关系!",
- text: "请选择资产关系",
- type: "error"
- })
- }
- });
- }
- // $scope.getdown = function() {
- // if (angular.isDefined($scope.rela) && angular.isDefined($scope.rela.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<myData.length;i++){
- // $http({
- // url: api_configure_data.downModels(type, $scope.rela.id, $scope.rela.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.importopen = function() { //导入触发事件
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/import.html',
- controller: function($scope, $modalInstance, FileUploader) {
- var importUploader = $scope.importUploader = new FileUploader({
- url: api_cmdb.importData().getRequestedUrl(),
- alias: "file",
- removeAfterUpload: true
- });
- importUploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/ , filter, options) {
- console.info('onWhenAddingFileFailed', item, filter, options);
- };
- importUploader.onAfterAddingFile = function(fileItem) {
- console.info('onAfterAddingFile', fileItem);
- if ($scope.importUploader.queue.length > 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.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.jry_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;
- }, 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.directive('meansoperator', function() {
- return {
- restrict: 'E',
- scope: {
- item: '=',
- colobject: '='
- },
- controller: 'MeansOperCtrl',
- template: '<div class="links cl-effect-1">' +
- '<a ng-click="look()" tooltip="查看" tooltip-placement="left"><i class="ti-eye"></i></a>' +
- '<a ng-click="edit()" tooltip="修改" tooltip-placement="left"><i class="fa fa-pencil-square-o"></i></a>' +
- '</div>'
- };
- });
|