sysQueryViewController.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. var sysQueryViewApp = angular.module('sysQueryViewApp', [ 'baseServices','DataRightsApp' ]);
  2. sysQueryViewApp.controller('sysQueryViewCtrl',['$scope','BaseService','dataRightsService',function($scope,BaseService,dataRightsService){
  3. var service = dataRightsService;
  4. service.noRights = true;
  5. $scope.service = service;
  6. $scope.type = "sysQueryView";
  7. window.setTimeout(function(){
  8. $scope.tab =$("#tab").ligerTab({});
  9. $scope.hasInitTab = true;
  10. $scope.$digest();
  11. $scope.tab.selectTabItem("filterSetting");
  12. var width = $('div[tabid="filterSetting"]').width()- 50;
  13. var height = $("#sql").height();
  14. editor = CodeMirror.fromTextArea(document.getElementById("sql"), {
  15. mode: "text/x-mariadb",
  16. lineWrapping:true,
  17. lineNumbers: true
  18. });
  19. editor.setSize(width,height);
  20. $scope.tab.selectTabItem("baseSetting");
  21. // //初始化日期控件
  22. FormUtil.initCalendar();
  23. $("#ruleDiv").linkdiv({data:$scope.filterFields.conditions,
  24. updateContent:updateContent,
  25. rule2json:rule2json});
  26. $("#sqlTip").qtip({
  27. content:{
  28. text:'<div>该脚本为 groovyScript脚本 ,返回值为可执行的sql语句,' +
  29. '<p>例:String sql ="select ID,field from table where 1=1";<br/>' +
  30. 'if(params.containsKey("CATEGORY"))<br/>' +
  31. '&nbsp;&nbsp;sql += " and CATEGORY like \'%"+CATEGORY+"%\'";<br/>' +
  32. 'return sql; </p>' +
  33. '其中的params为系统所封装的一个Map对象,他封装了上下文查询条件。' +
  34. '</div>'
  35. }
  36. });
  37. $("#sqlTip2").qtip({
  38. content:{
  39. text:'<div>该脚本为sql语句 ,所填写语句会在where 1=1 后面添加,' +
  40. '<p>例:AND USERID = [CUR_USER]' +
  41. '</p>' +
  42. '</div>'
  43. }
  44. });
  45. $scope.$digest();
  46. },500);
  47. service.init($scope);
  48. $scope.save = function(){
  49. if ($scope._validForm()) {
  50. if ($scope.dataRightsJson.id) {
  51. $.ligerDialog.confirm("保存会覆盖模板,如果修改了模板请手动保存模板后再进行保存业务数据模板,是否继续保存?","提示信息",function(rtn) {
  52. if (rtn) service.customFormSubmit(showViewResponse);
  53. });
  54. } else {
  55. service.customFormSubmit(showViewResponse);
  56. }
  57. }
  58. },
  59. showViewResponse =function(responseText){
  60. $.ligerDialog.closeWaitting();
  61. var obj = new com.hotent.form.ResultMessage(responseText);
  62. if (obj.isSuccess()) {
  63. $.ligerDialog.confirm( obj.getMessage()+",是否继续操作","提示信息", function(rtn) {
  64. if(rtn){
  65. var url=location.href.getNewUrl();
  66. if(url.indexOf("?id=")!=-1){
  67. window.location.href = location.href.getNewUrl();
  68. }
  69. else{
  70. var viewId=obj.getCause();
  71. window.location.href =location.href +"&id=" +viewId;
  72. }
  73. }else{
  74. var url="list.ht?sqlId=" +sqlId;
  75. window.location.href = url.getNewUrl();
  76. }
  77. });
  78. } else {
  79. $.ligerDialog.err("提示信息","保存视图失败!",obj.getMessage());
  80. }
  81. },
  82. $scope._validForm = function (){
  83. var form=$('#dataRightsForm');
  84. if(!form.valid()) return false;
  85. //判断排序字段太多报错问题
  86. if($scope.sortFields&&$scope.sortFields.length>3){
  87. $.ligerDialog.error("排序字段不能设置超过3个,请检查!","提示信息");
  88. $scope.tab.selectTabItem("sortSetting");
  89. return false;
  90. }
  91. //判断管理字段
  92. if(service.manageFieldValid($scope.manageFields)){
  93. $.ligerDialog.error("功能按钮出现重复的类型,请检查!","提示信息");
  94. $scope.tab.selectTabItem("manageSetting");
  95. return false;
  96. }
  97. if($scope.dataRightsJson.templateAlias=="") {
  98. $scope.tab.selectTabItem("baseSetting");
  99. form.valid();
  100. return false;
  101. }
  102. return true;
  103. }
  104. //预览
  105. $scope.preview = function (){
  106. var alias = $scope.dataRightsJson.sqlAlias;
  107. var view = $scope.dataRightsJson.alias;
  108. if($.isEmpty(alias)){
  109. $.ligerDialog.error("请设置完信息保存后预览!","提示信息");
  110. return ;
  111. }
  112. var url=__ctx+ "/platform/system/sysQueryView/"+alias+"/"+view+".ht";
  113. url=url.getNewUrl();
  114. $.openFullWindow(url);
  115. }
  116. //编辑模板
  117. $scope.editTemplate = function (){
  118. var id = $scope.dataRightsJson.id;
  119. if($.isEmpty(id)){
  120. $.ligerDialog.error("请设置完信息保存后编辑模板!","提示信息");
  121. return ;
  122. }
  123. var url=__ctx+ "/platform/system/sysQueryView/editTemplate.ht?id="+id;
  124. url=url.getNewUrl();
  125. $.openFullWindow(url);
  126. }
  127. //添加菜单
  128. $scope.addToResource = function () {
  129. var alias = $scope.dataRightsJson.sqlAlias;
  130. var url="/platform/system/sysQueryView/"+alias+"/"+$scope.dataRightsJson.alias+".ht";
  131. AddResourceDialog({addUrl:url});
  132. }
  133. function setGroupText(){
  134. var txt = "";
  135. for(var i = 0 ; i < $scope.groupingView.length ; i++){
  136. txt+=" {"+(i)+"} ";
  137. }
  138. for(var i = 0 ; i < $scope.groupingView.length ; i++){
  139. if(!$scope.groupingView[i].txtChange)
  140. $scope.groupingView[i].groupText = "<b> "+ $scope.groupingView[i].groupDesc +" : {0},数量{1} </b>"
  141. }
  142. }
  143. $scope.selectFieldToGroup = function(field){
  144. $scope.groupingView = $scope.groupingView || [];
  145. if(!field.gchecked){
  146. for(var i = 0 ; i < $scope.groupingView.length ; i++){
  147. if($scope.groupingView[i].groupField == field.name){
  148. $scope.groupingView.splice(i,1);
  149. setGroupText();
  150. return;
  151. }
  152. }
  153. return;
  154. }
  155. for(var i = 0 ; i < $scope.groupingView.length ; i++){
  156. if($scope.groupingView[i].groupField == field.name){
  157. return;
  158. }
  159. }
  160. $scope.groupingView.push({
  161. groupField:field.name,
  162. groupDesc:field.fieldDesc,
  163. groupColumnShow : 1,
  164. groupSummary:1,
  165. groupOrder : "asc"
  166. })
  167. setGroupText();
  168. }
  169. }])
  170. .controller('sysQueryViewSortListCtrl',['$scope','BaseService','dataRightsService',function($scope,BaseService,dataRightsService){
  171. $scope.sysQueryViewList=sysQueryViewList;
  172. $scope.moveTr = dataRightsService.moveTr;
  173. $scope.save = function(){
  174. var params = {},list = [];
  175. for ( var i = 0; i < $scope.sysQueryViewList.length; i++) {
  176. list.push({
  177. id:$scope.sysQueryViewList[i].id,
  178. sn:i
  179. })
  180. }
  181. params.list = JSON.stringify(list);
  182. $.post(__ctx+"/platform/system/sysQueryView/saveSortList.ht", params,function(data){
  183. if(data.success){
  184. frameElement.dialog.get('sucCall')(frameElement.dialog);
  185. }
  186. else
  187. $.ligerDialog.error("保存失败!","提示信息");
  188. });
  189. }
  190. $scope.close = function(){
  191. frameElement.dialog.close();
  192. }
  193. }])
  194. .controller('sysQueryViewExportsCtrl',['$scope','BaseService','dataRightsService',function($scope,BaseService,dataRightsService){
  195. var params = frameElement.dialog.get('conf').param;
  196. $scope.colModels = $.extend(true,[],params.colModel);
  197. $scope.exports = {
  198. type:1
  199. };
  200. $scope.selectAll = function(flag){
  201. for ( var i = 0; i < $scope.colModels.length; i++) {
  202. switch(flag){
  203. case 1:
  204. $scope.colModels[i].gchecked = true;
  205. break;
  206. case 2:
  207. $scope.colModels[i].gchecked = !$scope.colModels[i].gchecked;
  208. break;
  209. case 3:
  210. $scope.colModels[i].gchecked = false;
  211. break;
  212. }
  213. }
  214. }
  215. $scope.close = function(){
  216. frameElement.dialog.close();
  217. }
  218. $scope.toExports = function(){
  219. var exportNames = [];
  220. for ( var i = 0; i < $scope.colModels.length; i++) {
  221. if($scope.colModels[i].gchecked&&$scope.colModels[i].label)
  222. exportNames.push($scope.colModels[i].name)
  223. }
  224. var param = {
  225. viewId : params.viewId,
  226. isAll:$scope.exports.type==1?1:0,
  227. exportNames:exportNames.join(","),
  228. orderSeq:params.sortorder,
  229. sortField:params.sortname
  230. };
  231. param=$.extend({},param,frameElement.dialog.get('conf').searchParams);
  232. switch($scope.exports.type){
  233. case 2:
  234. case "2":
  235. param.paseSize = params.rowNum;
  236. param.page = params.page;
  237. break;
  238. }
  239. var form = $('#form');
  240. form.empty();
  241. for(var key in param){
  242. var input = $("<input type='hidden' name='"+key+"' value='"+param[key]+"'/>");
  243. form.append(input);
  244. }
  245. $.ligerDialog.waitting("正在导出,请稍等!");
  246. form.submit();
  247. /*window.setTimeout(function(){
  248. frameElement.dialog.close();
  249. },2000);*/
  250. }
  251. $scope.hasChecked = function(){
  252. for ( var i = 0; i < $scope.colModels.length; i++) {
  253. if($scope.colModels[i].gchecked) return true;
  254. }
  255. }
  256. $scope.selectAll(1);
  257. }])
  258. //过滤条件隐藏属性<filter-hidden></filter-hidden>
  259. .directive('filterHidden', function() {
  260. return {
  261. restrict : 'E',
  262. replace : true,
  263. template : '<div class="hidden">'+
  264. '<!-- 数字的判断 -->'+
  265. '<span id="judgeCon-1" class="judge-condition" >'+
  266. '<select name="judgeCondition" class="ht-input" style="width:80px; height: 30px;" onchange="judgeConditionChange.apply(this)">'+
  267. '<option value="1">等于</option>'+
  268. '<option value="2">不等于</option>'+
  269. '<option value="3">大于</option>'+
  270. '<option value="4">大于等于</option>'+
  271. '<option value="5">小于</option>'+
  272. '<option value="6">小于等于</option>'+
  273. '<option value="7">等于变量</option>'+
  274. '<option value="8">不等于变量</option>'+
  275. '</select>'+
  276. '</span>'+
  277. '<!-- 字符串的判断 -->'+
  278. '<span id="judgeCon-2" class="judge-condition">'+
  279. '<select name="judgeCondition" class="ht-input" style="width:80px; height: 30px;" onchange="judgeConditionChange.apply(this)">'+
  280. '<option value="1">等于</option>'+
  281. '<option value="3">等于(忽略大小写)</option>'+
  282. '<option value="2">不等于</option>'+
  283. '<option value="4">like</option>'+
  284. '<option value="5">like左</option>'+
  285. '<option value="6">like右</option>'+
  286. '<option value="7">等于变量</option>'+
  287. '<option value="8">不等于变量</option>'+
  288. '</select>'+
  289. '</span>'+
  290. '<!-- 字典的判断 -->'+
  291. '<span id="judgeCon-4" class="judge-condition">'+
  292. '<select name="judgeCondition" class="ht-input" style="width:80px; height: 30px;">'+
  293. '<option value="1">等于</option>'+
  294. '<option value="2">不等于</option>'+
  295. '</select>'+
  296. '</span>'+
  297. '<!-- 选择器的判断 -->'+
  298. '<span id="judgeCon-5" class="judge-condition">'+
  299. '<select name="judgeCondition" onchange="judgeConditionChange.apply(this)" class="ht-input" style="width:80px; height: 30px;">'+
  300. '<option value="1">包含</option>'+
  301. '<option value="2">不包含</option>'+
  302. '<option value="3">等于变量</option>'+
  303. '<option value="4">不等于变量</option>'+
  304. '</select>'+
  305. '</span>'+
  306. '<!-- 默认类型-->'+
  307. '<span id="normal-input" class="judge-value" type="1">'+
  308. '<input class="short-input ht-input" name="judgeValue" type="text" style="width:100px;margin-left: 5px;"/>'+
  309. '</span>'+
  310. '<!-- 日期类型 -->'+
  311. '<span id="date-input" class="judge-value" type="1">'+
  312. '<input id="date-input" type="text" class="Wdate ht-input" style="width:180px;"/>'+
  313. '</span>'+
  314. ''+
  315. '<!-- 用户选择器 -->'+
  316. '<div id="user-div">'+
  317. '<span class="judge-value" type="1">'+
  318. '<input type="hidden" value="" />'+
  319. '<input type="text" readonly="readonly" class="ht-input" style="width:130px;margin-left:5px;" />'+
  320. '<a href="javascript:;" class="link users">选择</a>'+
  321. '</span>'+
  322. '</div>'+
  323. ''+
  324. '<!-- 角色选择器 -->'+
  325. '<div id="role-div">'+
  326. '<span class="judge-value" type="1" >'+
  327. '<input type="hidden" value="" />'+
  328. '<input type="text" readonly="readonly" class="ht-input" style="width:130px;margin-left:5px;" />'+
  329. '<a href="javascript:;" class="link roles">选择</a>'+
  330. '</span>'+
  331. '</div>'+
  332. '<!-- 组织选择器 -->'+
  333. '<div id="org-div">'+
  334. '<span class="judge-value" type="1">'+
  335. '<input type="hidden" value="">'+
  336. '<input type="text" readonly="readonly" class="ht-input" style="width:130px;margin-left:5px;" />'+
  337. '<a href="javascript:;" class="link orgs">选择</a>'+
  338. '</span>'+
  339. '</div>'+
  340. '<!-- 岗位选择器 -->'+
  341. '<div id="position-div">'+
  342. '<span class="judge-value" type="1">'+
  343. '<input type="hidden" value="">'+
  344. '<input type="text" readonly="readonly" class="ht-input" style="width:130px;margin-left:5px;" />'+
  345. '<a href="javascript:;" class="link positions">选择</a>'+
  346. '</span>'+
  347. '</div>'+
  348. '<!--常用变量-->'+
  349. '<span id="commonVar" class="judge-value" type="2">'+
  350. '<select class="ht-input" style="width:100px;height: 30px;margin-left: 5px;">'+
  351. '<option value="{{co.alias}}" ng-repeat="co in commonVars">{{co.name}}[{{co.number?"数字":"字符串"}}]</option>'+
  352. '</select>'+
  353. '</span>'+
  354. '<select id="flowVarsSelect" class="left margin-set ht-input" name="flowVars" onchange="flowVarChange.apply(this)" style="height: 30px; ">'+
  355. '<option value="">--请选择--</option>'+
  356. '<option value="{{f.fieldName}}" datefmt="{{f.dateFormat}}" ctltype="{{f.controlType}}" ftype="{{f.dataType}}" ng-repeat="f in sysQueryMetaFields">{{f.fieldDesc}}</option>'+
  357. '</select>'+
  358. '</div>'
  359. };
  360. })
  361. //过滤条件 , 嵌入式 <filter-include-setting></filter-include-setting>
  362. .directive('filterIncludeSetting', function() {
  363. return {
  364. restrict : 'E',
  365. replace : true,
  366. template : '<table style="margin: auto;width:100%;margin-top: 1px;" class="table-detail" cellpadding="0" cellspacing="0" border="0">'+
  367. '<thead>'+
  368. '<tr style="height: 50px;">'+
  369. '<td colspan="4">'+
  370. '脚本类型:'+
  371. '<select ng-model="filterFields.type" class="ht-input">'+
  372. '<option value="1" >条件脚本</option>'+
  373. '<option value="2" >SQL</option>'+
  374. '<option value="3" >追加SQL</option>'+
  375. '</select>'+
  376. '</td>'+
  377. '</tr>'+
  378. '</thead>'+
  379. '<tbody>'+
  380. '<tr>'+
  381. '<td colspan="4" >'+
  382. '<fieldset style="margin: 5px 0px 5px 0px;" id="filterSetting" ng-show="filterFields.type==1" >'+
  383. '<legend>'+
  384. '<span>条件设置</span>'+
  385. '</legend>'+
  386. '<div class="table-top">'+
  387. '<div class="table-top-right">'+
  388. '<div class="toolBar" style="margin:0;">'+
  389. '<div class="group">'+
  390. '<a class="link add" onclick="addDiv(1)">添加条件</a>'+
  391. '</div>'+
  392. '<div class="l-bar-separator"></div>'+
  393. '<div class="group">'+
  394. '<a class="link switchuser" onclick="assembleDiv()">组合规则</a>'+
  395. '</div>'+
  396. '<div class="l-bar-separator"></div>'+
  397. '<div class="group">'+
  398. '<a class="link switchuser" onclick="splitDiv()">拆分规则</a>'+
  399. '</div>'+
  400. '<div class="l-bar-separator"></div>'+
  401. '<div class="group">'+
  402. '<a class="link del" onclick="removeDiv()">删除</a>'+
  403. '</div>'+
  404. '</div>'+
  405. '</div>'+
  406. '</div>'+
  407. '<div id="ruleDiv" style="border:2px solid #ccc;margin:5px 0 0 0;"></div>'+
  408. '</fieldset>'+
  409. '<fieldset style="margin: 5px 0px 5px 0px;" id="sqlSetting" ng-show="filterFields.type==2||filterFields.type==3" >'+
  410. '<legend ng-show="filterFields.type==2" >'+
  411. '<span>SQL设置</span>'+
  412. '</legend>'+
  413. '<legend ng-show="filterFields.type==3">'+
  414. '<span>追加SQL过滤</span>'+
  415. '</legend>'+
  416. '<table cellpadding="0" cellspacing="0" border="0" style="width: 100%;" class="table-detail" >'+
  417. '<tr>'+
  418. '<td width="5%">'+
  419. '<div id="sqlTip" ng-show="filterFields.type==2">'+
  420. '<a href="javascript:;" class="tipinfo"></a>'+
  421. '</div>'+
  422. '<div id="sqlTip2" ng-show="filterFields.type==3" >'+
  423. '<a href="javascript:;" class="tipinfo"></a>'+
  424. '</div>'+
  425. '<td width="10%">常用变量:</td>'+
  426. '<td>'+
  427. '<select id="varFieldSelect" class="ht-input" name="varFields" onchange="varsChange.apply(this)">'+
  428. '<option value="">--请选择--</option>'+
  429. '<optgroup class="main-table-item" label="sql字段" ></optgroup>'+
  430. '<option class="field-item" value="{{c.name}}" ng-repeat="c in conditionFields">{{c.name}}</option>'+
  431. '<optgroup class="main-table-item" label="常用变量" ></optgroup>'+
  432. '<option value="{{co.alias}}" ng-repeat="co in commonVars">{{co.name}}[{{co.number?"数字":"字符串"}}]</option>'+
  433. '</select>'+
  434. '</td>'+
  435. '</td>'+
  436. '</tr>'+
  437. '<tr>'+
  438. '<td colspan="7">'+
  439. '<textarea id="sql" ng-model="filterFields.sql" style="height: 300px;width:1000px;display:none !important;" class="ht-input border-none margin-none "></textarea>'+
  440. '</td>'+
  441. '</tr>'+
  442. '</table>'+
  443. '</fieldset>'+
  444. '</td>'+
  445. '</tr>'+
  446. '</tbody>'+
  447. '</table>',
  448. link:function(scope){
  449. scope.commonVars = commonVars;
  450. }
  451. };
  452. })