cmdbCtrl.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. 'use strict';
  2. app.controller('cmdbCtrl', ["$rootScope","$scope", "$state", "$timeout", "$interval", 'i18nService',"SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", function ($rootScope, $scope, $state, $timeout, $interval,i18nService, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain) {
  3. var pdKey = $state.current.pdKey;
  4. $scope.langs=i18nService.getAllLangs();
  5. $scope.lang = 'zh-cn';
  6. i18nService.setCurrentLang($scope.lang);
  7. $scope.gridOptions = {};
  8. $scope.gridOptions.data = 'myData';
  9. $scope.gridOptions.enableColumnResizing = true;
  10. $scope.gridOptions.enableFiltering = true;
  11. $scope.gridOptions.enableGridMenu = true;
  12. $scope.gridOptions.enableRowSelection = true;
  13. $scope.gridOptions.showGridFooter = true;
  14. $scope.gridOptions.showColumnFooter = true;
  15. $scope.gridOptions.fastWatch = true;
  16. $scope.gridOptions.useExternalPagination = true;
  17. $scope.gridOptions.paginationPageSizes = [10];
  18. $scope.gridOptions.paginationPageSize = 10;
  19. $scope.gridOptions.multiSelect = false;
  20. // $scope.gridOptions.rowTemplate= "<div ng-dblclick=\"grid.appScope.pdList.onDblClick(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>";
  21. //
  22. $scope.gridOptions.rowIdentity = function(row) {
  23. return row.id;
  24. };
  25. $scope.gridOptions.getRowIdentity = function(row) {
  26. return row.id;
  27. };
  28. // '<a class="btn btn-sm btn-warning" ng-click="grid.appScope.pdList.removeRowFunction(row.entity)">' + '<i class="fa fa-trash"/></a>'
  29. $scope.gridOptions.columnDefs = [
  30. { name:'configuresign', displayName:'资产流水号', width:140, enableFiltering:false},
  31. { name:'configureName', displayName:'资产标题', width:140},
  32. { name:'initUser.name', displayName:'创建人', width:100, enableFiltering:false},
  33. { name:'registrationTime', displayName:'登记时间', width:100, enableFiltering:false},
  34. { name:'configureClassfy.name', displayName:'资产分类', width:100, enableFiltering:false},
  35. { name:'configureStage.name', displayName:'状态', width:100, enableFiltering:false},
  36. { name:'操作', cellTemplate:'<cmdbcpertor item="row.entity" colobject="col">', width:100,enableFiltering:false}];
  37. // cellTemplate:'<a class="btn btn-sm btn-info" ' +
  38. // 'ng-click="grid.appScope.pdList.selectRowFunction(row.entity)">' +
  39. // '<i class="fa fa-pencil-square-o"/></a>' , enableFiltering:false}
  40. // ];
  41. // $scope.gridOptions.importerDataAddCallback = function( grid, newObjects ) {
  42. // $scope.myData = $scope.myData.concat( newObjects );
  43. // console.log($scope);
  44. // };
  45. $scope.gridOptions.onRegisterApi = function(gridApi){
  46. $scope.gridApi = gridApi;
  47. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  48. console.log(newPage);
  49. console.log(pageSize);
  50. $scope.refreshData('expand-right',{"assignee":$rootScope.user.id, "idx":newPage-1,"sum":pageSize});
  51. });
  52. gridApi.selection.on.rowSelectionChanged($scope, function(data){
  53. //$scope.selected.item = data.entity;
  54. console.log(data);
  55. });
  56. };
  57. // $scope.gridOptions.appScopeProvider = {
  58. // onDblClick : function(row) {
  59. // $state.go('app.form.detail',{data:row, formKey:'changeDetail', pdKey:'change'});
  60. // //var url = '//google.com';
  61. // //$window.open(url, "_blank", "height=600,width=800,toolbar=no,location=no,menubar=no,titlebar=no");
  62. // }
  63. // };
  64. $scope.selectRowFunction = function(data){
  65. console.log(data);
  66. // $state.go('app.process.modeler',{modelId:data.id});
  67. $state.go('app.cmdb.modeler',{taskId:data.taskId,processInstanceId: data.processInstanceId});
  68. };
  69. $scope.onDblClick = function(data){
  70. $state.go('app.detail', { formKey:'cmdbDetail', pdKey:'configure', dataId: data.id,processInstanceId: data.processInstanceId});
  71. };
  72. /*
  73. appScopeProvider: {
  74. onDblClick : function(row) {
  75. var url = '//google.com';
  76. $window.open(url, "_blank", "height=600,width=800,toolbar=no,location=no,menubar=no,titlebar=no");
  77. }
  78. },
  79. rowTemplate: "<div ng-dblclick=\"grid.appScope.onDblClick(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" ui-grid-cell ></div>"
  80. */
  81. this.removeRowFunction = function(data){
  82. //TODO $translate('key')
  83. SweetAlert.swal({
  84. title: "确认删除?",
  85. text: "删除以后,你将不能恢复该数据!",
  86. type: "warning",
  87. cancelButtonText: "取消",
  88. showCancelButton: true,
  89. confirmButtonColor: "#DD6B55",
  90. confirmButtonText: "确认删除!"
  91. }, function (isConfirm) {
  92. if (isConfirm) {
  93. // api_bpm_domain.removemodel(data.id).then(function(response){
  94. // if(response){
  95. // $scope.refreshData();
  96. // SweetAlert.swal({
  97. // title: "删除成功!",
  98. // confirmButtonColor: "#007AFF"
  99. // });
  100. // }
  101. // });
  102. }else{
  103. }
  104. });
  105. }
  106. //$scope.callsPending = 0;
  107. //var i = 0;
  108. var defaultFilterData = {
  109. "assignee":$rootScope.user.id,
  110. "idx":0,
  111. "sum":10,
  112. };
  113. if(angular.isDefined($rootScope['searchcmdb'])){
  114. defaultFilterData['searchType']=$rootScope['searchcmdb'];
  115. $scope.searchTypes=$rootScope['searchcmdb'];
  116. }
  117. $scope.ldloading = {};
  118. $scope.refreshData = function(style, filterData){
  119. $scope.ldloading[style.replace('-', '_')] = true;
  120. console.log($scope.ldloading.expand_right)
  121. if(angular.isUndefined(filterData)){
  122. filterData = defaultFilterData;
  123. }
  124. if(angular.isDefined($scope.searchTypes)){
  125. filterData['searchType'] = $scope.searchTypes;
  126. $rootScope['searchcmdb']=$scope.searchTypes;
  127. }
  128. $scope.myData = [];
  129. //var start = new Date();
  130. //var sec = $interval(function () {
  131. //$scope.callsPending++;
  132. api_bpm_domain.fetchtask(pdKey,filterData).then(function(data){
  133. $scope.callsPending--;
  134. var myData = Restangular.stripRestangular(data);
  135. $scope.gridOptions.totalItems = myData.resultCount;
  136. $scope.myData = myData.data;
  137. $scope.ldloading[style.replace('-', '_')] = false;
  138. },function(){
  139. $scope.ldloading[style.replace('-', '_')] = false;
  140. });
  141. //}, 200, 1);
  142. // var timeout = $timeout(function() {
  143. // $interval.cancel(sec);
  144. // $scope.left = '';
  145. // }, 2000);
  146. // $scope.$on('$destroy', function(){
  147. // $timeout.cancel(timeout);
  148. // $interval.cancel(sec);
  149. // });
  150. };
  151. $scope.refreshData('expand-right', defaultFilterData);
  152. }]);
  153. app.controller('CmdbOperCtrl', ['$rootScope','$http', '$scope', function ($rootScope,$http, $scope, $event) {
  154. // console.log($scope.item);
  155. if( $scope.item.handlerUser!=null){
  156. if ($rootScope.user.id==$scope.item.handlerUser.id) {
  157. $scope.item.chaozuoPower=true;
  158. }
  159. }
  160. $scope.view = function(){
  161. $scope.colobject.grid.appScope.onDblClick($scope.item);
  162. }
  163. $scope.edit = function(){
  164. $scope.colobject.grid.appScope.selectRowFunction($scope.item);
  165. // $scope.doEdit($scope.item.id);
  166. }
  167. }]);
  168. app.directive('cmdbcpertor', function () {
  169. return {
  170. restrict: 'E',
  171. scope:
  172. {
  173. item: '=',
  174. colobject: '='
  175. },
  176. controller: 'CmdbOperCtrl',
  177. template: '<div class="links cl-effect-1">' +
  178. '<a ng-click="view()" tooltip="查看" tooltip-placement="left"><i class="ti-eye"></i></a>'+
  179. '<a ng-click="edit()" ng-show="{{item.chaozuoPower}}" tooltip="编辑" tooltip-placement="left"><i class="fa fa-pencil-square-o"></i></a>'+
  180. '</div>'
  181. };
  182. });