reportCtrl.js 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442
  1. 'use strict';
  2. app.controller('reportCtrl', ["$scope","$rootScope", "$state", "$timeout", "$interval", "$http", "$cookieStore", "moment", "SweetAlert", "Restangular", "api_report", "api_statistic", function ($scope, $rootScope, $state, $timeout, $interval, $http, $cookieStore, moment, SweetAlert, Restangular, api_report, api_statistic) {
  3. var ROWS = "ROWS";
  4. var COLUMNS = "COLUMNS";
  5. $scope.treeshow=true;
  6. $scope.headers = "请选择事件树形列表!";
  7. api_report.getLicenseKey().then(function(response){
  8. $cookieStore.put('Auth-Token',response.token);
  9. $scope.try_async_load();
  10. });
  11. var apple_selected, tree, treedata_avm, treedata_geography;
  12. var workspace = {};
  13. $scope.parameters = {};
  14. $scope.reportName = "HBZY报表";
  15. $scope.allheight=100;
  16. $scope.my_tree_handler = function (branch) {
  17. $scope.treeshow=false;
  18. if(branch.type=='FILE'){
  19. console.log(branch);
  20. $scope.reportName=branch.label;
  21. var path=$scope.mdxpath=branch.path;
  22. queryUUID=genUUID();
  23. api_report.getMdx(path,queryUUID).then(function(response){
  24. var mdxquery = Restangular.stripRestangular(response);
  25. workspace.query = mdxquery;
  26. var starttime,endtime
  27. // starttime=moment().startOf('week').format('YYYYMMDD');
  28. // endtime=moment().endOf('week').format('YYYYMMDD');
  29. // starttime=moment().startOf('month').format('YYYYMMDD');
  30. starttime="20161001"
  31. endtime=moment().format('YYYYMMDD');
  32. // var year=new Date().getFullYear();
  33. // var month=new Date().getMonth()+1;
  34. // var day=new Date().getDate();
  35. // var days=0;
  36. // for(var i=0;i<month;i++){
  37. // switch(i){
  38. // case 1:{
  39. // days+=31;break;
  40. // }
  41. // case 3:{
  42. // days+=31;break;
  43. // }
  44. // case 5:{
  45. // days+=31;break;
  46. // }
  47. // case 7:{
  48. // days+=31;break;
  49. // }
  50. // case 8:{
  51. // days+=31;break;
  52. // }
  53. // case 10:{
  54. // days+=31;break;
  55. // }
  56. // case 12:{
  57. // days+=31;break;
  58. // }
  59. // case 4:{
  60. // days+=30;break;
  61. // }
  62. // case 6:{
  63. // days+=30;break;
  64. // }
  65. // case 9:{
  66. // days+=30;break;
  67. // }
  68. // case 11:{
  69. // days+=30;break;
  70. // }
  71. // case 2:{
  72. // if((year%4==0&&year%100!=0)||(year%400==0)){
  73. // days+=29
  74. // }else{days+=28}
  75. // break;
  76. // }
  77. // }
  78. // }
  79. // days+=day;
  80. // // var dayss='';
  81. // var date0=new Date(year,0,1);
  82. // var oneDayWeek=date0.getDay()==0?7:date0.getDay();
  83. // var oneWeekDay=7-oneDayWeek+1;
  84. // var shengdays=days-oneWeekDay;
  85. // var nthOfWeek=Math.ceil(shengdays/7)+1;
  86. // var weeks=shengdays%7;
  87. // // if(day){}
  88. // var dayss=day-weeks+1-6;
  89. // var dayl=day-weeks;
  90. // var month1=month;
  91. // var month2=month;
  92. // var year1=year;
  93. // var year2=year;
  94. // switch(month){
  95. // case 1:{
  96. // if((day-weeks+1-6)<=0){dayss=25+day-weeks;month1=month-1}else{
  97. // if(dayss>31){dayss=dayss-31;month1=month+1;}}
  98. // if((day-weeks)<=0){dayl=day+31-weeks;month2=month-1;}else{
  99. // if(dayl>31){dayl=dayl-31;month2=month+1;}
  100. // }
  101. // break;
  102. // }
  103. // case 3:{
  104. // if((year%4==0&&year%100!=0)||(year%400==0)){
  105. // if((day-weeks+1-6)<=0){dayss=23+day-weeks;month1=month-1}else{
  106. // if(dayss>31){dayss=dayss-31;month1=month+1;}}
  107. // if((day-weeks)<=0){dayl=day+29-weeks;month2=month-1;}else{
  108. // if(dayl>31){dayl=dayl-31;month2=month+1;}
  109. // }
  110. // }else{
  111. // if((day-weeks+1-6)<=0){dayss=22+day-weeks;month1=month-1}else{
  112. // if(dayss>31){dayss=dayss-31;month1=month+1;}}
  113. // if((day-weeks)<=0){dayl=day+28-weeks;month2=month-1;}else{
  114. // if(dayl>31){dayl=dayl-31;month2=month+1;}
  115. // }
  116. // }
  117. // break;
  118. // }
  119. // case 5:{
  120. // if((day-weeks+1-6)<=0){dayss=24+day-weeks;month1=month-1}else{
  121. // if(dayss>31){dayss=dayss-31;month1=month+1;}}
  122. // if((day-weeks)<=0){dayl=day+30-weeks;month2=month-1;}else{
  123. // if(dayl>31){dayl=dayl-31;month2=month+1;}
  124. // }
  125. // break;
  126. // }
  127. // case 7:{
  128. // if((day-weeks+1-6)<=0){dayss=24+day-weeks;month1=month-1}else{
  129. // if(dayss>31){dayss=dayss-31;month1=month+1;}}
  130. // if((day-weeks)<=0){dayl=day+30-weeks;month2=month-1;}else{
  131. // if(dayl>31){dayl=dayl-31;month2=month+1;}
  132. // }
  133. // break;
  134. // }
  135. // case 8:{
  136. // if((day-weeks+1-6)<=0){dayss=25+day-weeks;month1=month-1}else{
  137. // if(dayss>31){dayss=dayss-31;month1=month+1;}}
  138. // if((day-weeks)<=0){dayl=day+31-weeks;month2=month-1;}else{
  139. // if(dayl>31){dayl=dayl-31;month2=month+1;}
  140. // }
  141. // break;
  142. // }
  143. // case 10:{
  144. // if((day-weeks+1-6)<=0){dayss=24+day-weeks;month1=month-1}else{
  145. // if(dayss>31){dayss=dayss-31;month1=month+1;}}
  146. // if((day-weeks)<=0){dayl=day+30-weeks;month2=month-1;}else{
  147. // if(dayl>31){dayl=dayl-31;month2=month+1;}
  148. // }
  149. // break;
  150. // }
  151. // case 12:{
  152. // if((day-weeks+1-6)<=0){dayss=24+day-weeks;month1=month-1}else{
  153. // if(dayss>31){dayss=dayss-31;month1=month+1;}}
  154. // if((day-weeks)<=0){dayl=day+30-weeks;month2=month-1;}else{
  155. // if(dayl>31){dayl=dayl-31;month2=month+1;}
  156. // }
  157. // break;
  158. // // if(dayss>31){dayss=dayss-30;
  159. // // month1=month+1;if(month>12){month1=month-12;year1=year+1}}
  160. // // if(dayl>31){dayl=dayl-31;
  161. // // month2=month+1;if(month>12){month2=month-12;year2=year+1}}
  162. // // break;
  163. // }
  164. // case 4:{
  165. // if((day-weeks+1-6)<=0){dayss=25+day-weeks;month1=month-1}else{
  166. // if(dayss>30){dayss=dayss-30;month1=month+1;}}
  167. // if((day-weeks)<=0){dayl=day+31-weeks;month2=month-1;}else{
  168. // if(dayl>30){dayl=dayl-30;month2=month+1;}
  169. // }
  170. // break;
  171. // }
  172. // case 6:{
  173. // if((day-weeks+1-6)<=0){dayss=25+day-weeks;month1=month-1}else{
  174. // if(dayss>30){dayss=dayss-30;month1=month+1;}}
  175. // if((day-weeks)<=0){dayl=day+31-weeks;month2=month-1;}else{
  176. // if(dayl>30){dayl=dayl-30;month2=month+1;}
  177. // }
  178. // break;
  179. // }
  180. // case 9:{
  181. // if((day-weeks+1-6)<=0){dayss=25+day-weeks;month1=month-1}else{
  182. // if(dayss>30){dayss=dayss-30;month1=month+1;}}
  183. // if((day-weeks)<=0){dayl=day+31-weeks;month2=month-1;}else{
  184. // if(dayl>30){dayl=dayl-30;month2=month+1;}
  185. // }
  186. // break;
  187. // // if(dayss>30){dayss=dayss-31;month1=month+1;}
  188. // // if(dayl>30){dayl=dayl-30;month2=month+1;}
  189. // // break;
  190. // }
  191. // case 11:{
  192. // if((day-weeks+1-6)<=0){dayss=25+day-weeks;month1=month-1}else{
  193. // if(dayss>30){dayss=dayss-30;month1=month+1;}}
  194. // if((day-weeks)<=0){dayl=day+31-weeks;month2=month-1;}else{
  195. // if(dayl>30){dayl=dayl-30;month2=month+1;}
  196. // }
  197. // break;
  198. // }
  199. // case 2:{
  200. // if((year%4==0&&year%100!=0)||(year%400==0)){
  201. // if((day-weeks+1-6)<=0){dayss=25+day-weeks;month1=month-1}else{
  202. // if(dayss>29){dayss=dayss-29;month1=month+1;}}
  203. // if((day-weeks)<=0){dayl=day+31-weeks;month2=month-1;}else{
  204. // if(dayl>29){dayl=dayl-29;month2=month+1;}
  205. // }
  206. // break;
  207. // // if(dayss>29){dayss=dayss-31;month1=month+1;}
  208. // // if(dayl>29){dayl=dayl-29;month2=month+1;}
  209. // // break;
  210. // }else{
  211. // if((day-weeks+1-6)<=0){dayss=25+day-weeks;month1=month-1}else{
  212. // if(dayss>28){dayss=dayss-28;month1=month+1;}}
  213. // if((day-weeks)<=0){dayl=day+31-weeks;month2=month-1;}else{
  214. // if(dayl>28){dayl=dayl-28;month2=month+1;}
  215. // }
  216. // break;
  217. // // if(dayss>28){dayss=dayss-31;month1=month+1;}
  218. // // if(dayl>28){dayl=dayl-28;month2=month+1;}
  219. // // break;
  220. // }
  221. // break;
  222. // }
  223. // }
  224. // var mom1=month1.toString();
  225. // var mom2=month2.toString();
  226. // var da1=dayss.toString();
  227. // var da2=dayl.toString();
  228. // if(month1.toString().length<2){mom1="0"+month1.toString()};
  229. // if(month2.toString().length<2){mom2="0"+month2.toString()};
  230. // if(dayss.toString().length<2){da1="0"+dayss.toString()}
  231. // if(dayl.toString().length<2){da2="0"+dayl.toString()}
  232. // workspace.query.parameters.paramDateFrom=year.toString()+mom1+da1;
  233. // workspace.query.parameters.paramDateTo=year.toString()+mom2+da2;
  234. // $scope.parameters = parseDateParameter(workspace.query.parameters);
  235. // $scope.disabledParentGroup=false;
  236. // $scope.shows=false;
  237. workspace.query.parameters.paramDateFrom=starttime;
  238. workspace.query.parameters.paramDateTo=endtime;
  239. $scope.parameters = parseDateParameter(workspace.query.parameters);
  240. if(workspace.query.parameters.reportUUID){
  241. $scope.rptUUID = workspace.query.parameters.reportUUID;
  242. delete workspace.query.parameters.reportUUID;
  243. $scope.parameters = parseDateParameter(workspace.query.parameters);
  244. api_statistic.query(workspace.query.parameters,$scope.rptUUID).then(function(data){
  245. $scope.rheaders = [];
  246. $scope.rRows = [];
  247. var reportData = Restangular.stripRestangular(data);
  248. if(reportData.cellset.length<2){
  249. reportData.cellset=null;
  250. $scope.shows=true;$scope.empty="数据为空!"
  251. }
  252. var tableContent = render(reportData);
  253. })
  254. }else{
  255. $scope.rptUUID = undefined;
  256. api_report.execute(mdxquery).then(function(data){
  257. $scope.rheaders = [];
  258. $scope.rRows = [];
  259. var reportData = Restangular.stripRestangular(data);
  260. // if($scope.reportName=="事件工作回顾"&&reportData.cellset.length<4){
  261. // reportData.cellset=null;
  262. // }
  263. // if($scope.reportName=="事件解决率统计"&&reportData.cellset.length<4){
  264. // reportData.cellset=null;
  265. // }
  266. if(reportData.cellset==null||reportData.cellset.length==0){$scope.shows=true;$scope.empty="数据为空!"}
  267. //console.log(reportData);
  268. var tableContent = render(reportData);
  269. renderChart(reportData);
  270. //console.log(tableContent);
  271. //console.log($scope.rheaders);
  272. })
  273. }
  274. //http://localhost:9008/api/statistic/unidimensional/d75e22c1-7f60-4e22-affd-23742a475407
  275. });
  276. }
  277. }
  278. $scope.my_data = [];
  279. $scope.my_tree = tree = {};
  280. $scope.try_async_load = function () {
  281. $scope.my_data = [];
  282. $scope.select_treedata = [];
  283. api_report.list().then(function(response){
  284. var dataList = Restangular.stripRestangular(response);
  285. getRepoRoot(dataList, '/homes/home:admin/HBZY报表');
  286. convertRepoObject($scope.repoRoot);
  287. $scope.my_data.push($scope.repoRoot);
  288. });
  289. };
  290. $scope.repoRoot = null;
  291. function getRepoRoot(repo, path){
  292. angular.forEach(repo, function(value, key){
  293. if(value.path==path){
  294. $scope.repoRoot=value;
  295. }else{
  296. if($scope.repoRoot==null&&angular.isDefined(value.repoObjects)){
  297. getRepoRoot(value.repoObjects, path);
  298. }else{
  299. }
  300. }
  301. });
  302. }
  303. function convertRepoObject(repo) {
  304. if(angular.isArray(repo)){
  305. angular.forEach(repo, function(value, key){
  306. convertRepoObject(value);
  307. })
  308. }else{
  309. if(angular.isDefined(repo.name)){
  310. if(repo.name.indexOf(".")>=0){
  311. repo.label = repo.name.substr(0, repo.name.lastIndexOf("."));
  312. }else{
  313. repo.label = repo.name;
  314. }
  315. //delete repo.name;
  316. }
  317. if(angular.isDefined(repo.repoObjects)){
  318. repo.children = [];
  319. repo.children = repo.repoObjects;
  320. delete repo.repoObjects;
  321. convertRepoObject(repo.children);
  322. }
  323. }
  324. }
  325. function convertListToTree(data, treeMap){
  326. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  327. var root = null; //Initially set our loop to null
  328. var parentNode = null;
  329. //loop over data
  330. for(var i = 0; i < data.length; i++) {
  331. var datum = data[i];
  332. //each node will have children, so let's give it a "children" poperty
  333. datum.children = [];
  334. //add an entry for this node to the map so that any future children can
  335. //lookup the parent
  336. idToNodeMap[datum.id] = datum;
  337. //Does this node have a parent?
  338. if(typeof datum.parent === "undefined" || datum.parent == null) {
  339. //Doesn't look like it, so this node is the root of the tree
  340. root = datum;
  341. treeMap[datum.id] = root;
  342. } else {
  343. //This node has a parent, so let's look it up using the id
  344. parentNode = idToNodeMap[datum.parent.id];
  345. //We don't need this property, so let's delete it.
  346. delete datum.parent;
  347. //Let's add the current node as a child of the parent node.
  348. parentNode.children.push(datum);
  349. }
  350. }
  351. return root;
  352. }
  353. function convertParentToChildList(data){
  354. var treeMap = {};
  355. var list=[];
  356. convertListToTree(data, treeMap);
  357. angular.forEach(treeMap,function(item){
  358. list.push(item);
  359. });
  360. return list;
  361. }
  362. function parseDateParameter(parameters){
  363. var result=undefined;
  364. if(angular.isArray(parameters)){
  365. // angular.forEach(parmeters,function(param){
  366. // param.
  367. // })
  368. }else{
  369. result = {};
  370. for(var k in parameters){
  371. if(k.indexOf("Date")>0){
  372. if(angular.isString(parameters[k])){
  373. result[k] = moment(parameters[k], "YYYYMMDD").format("YYYY-MM-DD");
  374. //result[k] = ''+parameters[k]+'';//= moment(parameters[k], "YYYYMMDD").toDate();
  375. }
  376. }
  377. }
  378. }
  379. return result;
  380. }
  381. function ConvertDateParameter(parameters){
  382. var result=undefined;
  383. if(angular.isArray(parameters)){
  384. //
  385. }else{
  386. result={};
  387. for(var k in parameters){
  388. if(k.indexOf("Date")>0){
  389. if(angular.isDate(parameters[k])){
  390. result[k]=moment(parameters[k]).format("YYYYMMDD");
  391. }else if(angular.isString(parameters[k])){
  392. result[k]=parameters[k];
  393. }
  394. }
  395. }
  396. }
  397. return result;
  398. }
  399. $scope.open = function ($event) {
  400. $event.preventDefault();
  401. $event.stopPropagation();
  402. $scope.opened = !$scope.opened;
  403. };
  404. $scope.endOpen = function ($event) {
  405. $event.preventDefault();
  406. $event.stopPropagation();
  407. $scope.startOpened = false;
  408. $scope.endOpened = !$scope.endOpened;
  409. };
  410. $scope.startOpen = function ($event) {
  411. $event.preventDefault();
  412. $event.stopPropagation();
  413. $scope.endOpened = false;
  414. $scope.startOpened = !$scope.startOpened;
  415. };
  416. $scope.mdxquery = function () {
  417. $scope.shows=false;
  418. if(angular.isDefined(workspace.query)){
  419. if($scope.rptUUID){
  420. workspace.query.parameters=ConvertDateParameter($scope.parameters);
  421. workspace.query.parameters.paramDateFrom=workspace.query.parameters.paramDateFrom.replace(/-/g,"");
  422. workspace.query.parameters.paramDateTo=workspace.query.parameters.paramDateTo.replace(/-/g,"");
  423. api_statistic.query(workspace.query.parameters,$scope.rptUUID).then(function(data){
  424. $scope.rheaders = [];
  425. $scope.rRows = [];
  426. var reportData = Restangular.stripRestangular(data);
  427. if(reportData.cellset.length<2){
  428. reportData.cellset=null;
  429. $scope.shows=true;$scope.empty="数据为空!"
  430. }
  431. var tableContent = render(reportData);
  432. })
  433. }else{
  434. $scope.rptUUID = undefined;
  435. workspace.query.parameters=ConvertDateParameter($scope.parameters);
  436. if(angular.isDefined($scope.parameters.paramDateFrom)&&angular.isDefined($scope.parameters.paramDateTo)){
  437. workspace.query.parameters.paramDateFrom=workspace.query.parameters.paramDateFrom.replace(/-/g,"");
  438. workspace.query.parameters.paramDateTo=workspace.query.parameters.paramDateTo.replace(/-/g,"");
  439. // workspace.query.parameters=ConvertDateParameter($scope.parameters);
  440. api_report.execute(workspace.query).then(function(data){
  441. console.log($scope.reportName)
  442. $scope.rheaders = [];
  443. $scope.rRows = [];
  444. var reportData = Restangular.stripRestangular(data);
  445. // if($scope.reportName=="事件工作回顾"&&reportData.cellset.length<4){
  446. // reportData.cellset=null;
  447. // }
  448. // if($scope.reportName=="事件解决率统计"&&reportData.cellset.length<4){
  449. // reportData.cellset=null;
  450. // }
  451. if(reportData.cellset==null||reportData.cellset.length==0){$scope.shows=true;$scope.empty="数据为空!"}
  452. console.log(reportData);
  453. var tableContent =
  454. render(reportData);
  455. renderChart(reportData);
  456. console.log($scope.rheaders);
  457. })
  458. }
  459. }
  460. }
  461. }
  462. $scope.execute = function () {
  463. api_report.list($scope.token).then(function(response){
  464. $scope.select_treedata = $scope.my_data = response;
  465. });
  466. }
  467. $scope.searchOptions = function(){
  468. if(angular.isDefined(workspace.query)){
  469. var queryParameters = workspace.query.parameters;
  470. for(var parm in queryParameters){
  471. if(parm=='Week'){
  472. }else{
  473. }
  474. }
  475. }
  476. }
  477. $scope.activeParentGroup = false;
  478. $scope.disabledParentGroup = false;
  479. $scope.toggleParentGroup = function(){
  480. if(workspace.query){
  481. // if($scope.activeParentGroup){
  482. // workspace.query.properties['saiku.olap.result.formatter']='flat';
  483. // $scope.activeParentGroup=!$scope.activeParentGroup;
  484. // }else{
  485. workspace.query.properties['saiku.olap.result.formatter']='flattened';
  486. // $scope.activeParentGroup=!$scope.activeParentGroup;
  487. // }
  488. //console.log(workspace.query);
  489. executeQuery(workspace.query);
  490. }
  491. }
  492. var process_data_tree = function (args, flat, setdata) {
  493. var self = this;
  494. var data = {};
  495. if (flat) {
  496. data.resultset = [];
  497. data.metadata = [];
  498. data.height = 0;
  499. data.width = 0;
  500. }
  501. var currentDataPos = data;
  502. if (typeof args == "undefined" || typeof args.data == "undefined") {
  503. return;
  504. }
  505. if (args.data !== null && args.data.error !== null) {
  506. return;
  507. }
  508. // Check to see if there is data
  509. if (args.data === null || (args.data.cellset && args.data.cellset.length === 0)) {
  510. return;
  511. }
  512. var cellset = args.data.cellset;
  513. if (cellset && cellset.length > 0) {
  514. var lowest_level = 0;
  515. var data_start = 0;
  516. var hasStart = false;
  517. var row,
  518. rowLen,
  519. labelCol,
  520. reduceFunction = function (memo, num) {
  521. return memo + num;
  522. };
  523. for (row = 0, rowLen = cellset.length; data_start === 0 && row < rowLen; row++) {
  524. for (var field = 0, fieldLen = cellset[row].length; field < fieldLen; field++) {
  525. if (!hasStart) {
  526. while (cellset[row][field].type == "COLUMN_HEADER" && cellset[row][field].value == "null") {
  527. row++;
  528. }
  529. }
  530. hasStart = true;
  531. if (cellset[row][field].type == "ROW_HEADER_HEADER") {
  532. while (cellset[row][field].type == "ROW_HEADER_HEADER") {
  533. if (flat) {
  534. data.metadata.push({
  535. colIndex: field,
  536. colType: "String",
  537. colName: cellset[row][field].value
  538. });
  539. }
  540. field++;
  541. }
  542. lowest_level = field - 1;
  543. }
  544. if (cellset[row][field].type == "COLUMN_HEADER") {
  545. var lowest_col_header = 0;
  546. var colheader = [];
  547. while (lowest_col_header <= row) {
  548. if (cellset[lowest_col_header][field].value !== "null") {
  549. colheader.push(cellset[lowest_col_header][field].value);
  550. }
  551. lowest_col_header++;
  552. }
  553. if (flat) {
  554. data.metadata.push({
  555. colIndex: field,
  556. colType: "Numeric",
  557. colName: colheader.join(' ~ ')
  558. });
  559. }
  560. data_start = row + 1;
  561. }
  562. }
  563. }
  564. var labelsSet = {};
  565. var rowlabels = [];
  566. for (labelCol = 0; labelCol <= lowest_level; labelCol++) {
  567. rowlabels.push(null);
  568. }
  569. for (row = data_start, rowLen = cellset.length; row < rowLen; row++) {
  570. if (cellset[row][0].value !== "") {
  571. var record = [];
  572. var flatrecord = [];
  573. var parent = null;
  574. var rv = null;
  575. for (labelCol = 0; labelCol <= lowest_level; labelCol++) {
  576. if (cellset[row] && cellset[row][labelCol].value === 'null') {
  577. currentDataPos = data;
  578. var prevLabel = 0;
  579. for (; prevLabel < lowest_level && cellset[row][prevLabel].value === 'null'; prevLabel++) {
  580. currentDataPos = currentDataPos[rowlabels[prevLabel]];
  581. }
  582. if (prevLabel > labelCol) {
  583. labelCol = prevLabel;
  584. }
  585. }
  586. if (cellset[row] && cellset[row][labelCol].value !== 'null') {
  587. if (labelCol === 0) {
  588. for (var xx = 0; xx <= lowest_level; xx++) {
  589. rowlabels[xx] = null;
  590. }
  591. }
  592. if (typeof currentDataPos == "number") {
  593. parent[rv] = {};
  594. currentDataPos = parent[rv];
  595. }
  596. rv = cellset[row][labelCol].value;
  597. rowlabels[labelCol] = rv;
  598. if (!currentDataPos.hasOwnProperty(rv)) {
  599. currentDataPos[rv] = {};
  600. }
  601. parent = currentDataPos;
  602. currentDataPos = currentDataPos[rv];
  603. }
  604. }
  605. flatrecord = _.clone(rowlabels);
  606. for (var col = lowest_level + 1, colLen = cellset[row].length; col < colLen; col++) {
  607. var cell = cellset[row][col];
  608. var value = cell.value || 0;
  609. var maybePercentage = (value !== 0);
  610. // check if the resultset contains the raw value, if not try to parse the given value
  611. var raw = cell.properties.raw;
  612. if (raw && raw !== "null") {
  613. value = parseFloat(raw);
  614. } else if (typeof(cell.value) !== "number" && parseFloat(cell.value.replace(/[^a-zA-Z 0-9.]+/g, ''))) {
  615. value = parseFloat(cell.value.replace(/[^a-zA-Z 0-9.]+/g, ''));
  616. maybePercentage = false;
  617. }
  618. if (value > 0 && maybePercentage) {
  619. value = cell.value && cell.value.indexOf('%') >= 0 ? value * 100 : value;
  620. }
  621. record.push(value);
  622. flatrecord.push({f: cell.value, v: value});
  623. }
  624. if (flat) data.resultset.push(flatrecord);
  625. var sum = _.reduce(record, reduceFunction, 0);
  626. rv = (rv === null ? "null" : rv);
  627. parent[rv] = sum;
  628. currentDataPos = data;
  629. }
  630. }
  631. if (setdata) {
  632. self.rawdata = args.data;
  633. self.data = data;
  634. self.hasProcessed = true;
  635. self.data.height = self.data.resultset.length;
  636. }
  637. return data;
  638. } else {
  639. //no result
  640. //$(self.el).find('.canvas_wrapper').text("No results").show();
  641. }
  642. };
  643. function randColor() {
  644. tmpHSV=randomHSV(tmpHSV);
  645. return colorToHex(HSVToRGB(tmpHSV.h,tmpHSV.s, tmpHSV.v));
  646. // console.log()
  647. };
  648. function highlightColor(){
  649. var highlight = {
  650. h:tmpHSV.h+5.5,
  651. s:0.55,
  652. v:0.5
  653. };
  654. return colorToHex(HSVToRGB(highlight.h,highlight.s, highlight.v));
  655. }
  656. var renderChart = function(reportData){
  657. var data = process_data_tree({data:reportData});
  658. var _ = window._;
  659. var dataChart = undefined;
  660. $scope.chartData = [];
  661. // tmpHSV=undefined;
  662. if(workspace.query){
  663. if(workspace.query.properties['saiku.ui.render.type']=="sunburst"){
  664. $scope.chartType="pie";
  665. dataChart = [];
  666. var total=0;
  667. var i=0;
  668. _.forIn(data, function(value, key) {
  669. total+=value;
  670. i++;
  671. dataChart.push({
  672. label:key,
  673. value:value,
  674. color:randColor()
  675. });
  676. });
  677. // function randColor(){
  678. // if(i%4==1){return '#01A2D9'}
  679. // else if(i%4==2){return '#71BBDE'}
  680. // else if(i%4==3){return '#FF9122'}
  681. // else if(i%4==0){return '#F8B705'}
  682. // }
  683. console.log(total);
  684. // for(var i=0;i<dataChart.length;i++){
  685. // dataChart[i].value=dataChart[i].value*100/total
  686. // dataChart[i].value=dataChart[i].value.toFixed(2);
  687. // }
  688. $scope.chartData = dataChart;
  689. $scope.chartOptions = {
  690. // responsive: true,
  691. // //Boolean - Whether we should show a stroke on each segment
  692. segmentShowStroke : true,
  693. // //String - The colour of each segment stroke
  694. // segmentStrokeColor : '#fff',
  695. // //Number - The width of each segment stroke
  696. segmentStrokeWidth : 2,
  697. // //Number - The percentage of the chart that we cut out of the middle
  698. // percentageInnerCutout : 0, // This is 0 for Pie charts
  699. // //Number - Amount of animation steps
  700. // animationSteps : 100,
  701. // //String - Animation easing effect
  702. // animationEasing : 'easeOutBounce',
  703. // //Boolean - Whether we animate the rotation of the Doughnut
  704. // animateRotate : true,
  705. // //Boolean - Whether we animate scaling the Doughnut from the centre
  706. // animateScale : false,
  707. // //String - A legend template
  708. legendTemplate : '<ul class="tc-chart-js-legend col-md-2.5 " style="float:right;margin-top:-250px;z-index: 999;"><% for (var i=0; i<Math.min(segments.length,5); i++){%><li><span style="background-color:<%=segments[i].fillColor%>"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>',
  709. //showTooltips:false,
  710. //tooltipEvents:[],
  711. onAnimationComplete: function(){
  712. this.showTooltip(this.segments, true);
  713. console.log(this.segments)
  714. }
  715. };
  716. }else if(workspace.query.properties['saiku.ui.render.type']=="stackedBar"){
  717. $scope.chartType="bar";
  718. dataChart = {};
  719. var labels=[];
  720. var barData =[];
  721. _.forIn(data, function(value, key) {
  722. labels.push(key);
  723. barData.push(value);
  724. });
  725. dataChart={
  726. labels:labels,
  727. datasets:[]
  728. };
  729. dataChart.datasets.push({
  730. //label:'事件数',
  731. fillColor: '#0E7EC5',
  732. strokeColor: 'rgba(220,220,220,0.8)',
  733. highlightFill: 'rgba(220,220,220,0.75)',
  734. highlightStroke: 'rgba(220,220,220,1)',
  735. data:barData
  736. });
  737. $scope.chartData = dataChart;
  738. $scope.chartOptions = {};
  739. }
  740. //"line"
  741. //"bar"
  742. //"radar"
  743. //"polararea"
  744. //"pie"
  745. //"doughnut"
  746. }
  747. }
  748. var queryUUID;
  749. function genUUID(){
  750. var uuid = 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
  751. function (c) {
  752. var r = Math.random() * 16 | 0,
  753. v = c == 'x' ? r : (r & 0x3 | 0x8);
  754. return v.toString(16);
  755. }).toUpperCase();
  756. return uuid;
  757. }
  758. function exportMdxBefore(path,uuid, callback){
  759. var rdata = 'file='+path+'&formatter=flattened&language=zh';
  760. $http({
  761. url: api_report.queryMdxUri(uuid).getRequestedUrl(),
  762. method: 'POST',
  763. data: rdata,
  764. headers: {
  765. 'Content-Type': 'application/x-www-form-urlencoded',
  766. 'X-Auth-Token' : $cookieStore.get('Auth-Token')||null
  767. }
  768. }).success(function(data, status, headers, config) {
  769. if(status==200){
  770. if(callback){
  771. callback(data.name, path);
  772. }
  773. }
  774. //console.log(status);
  775. //console.log(data);
  776. });
  777. }
  778. $scope.exportData = function(uuid){
  779. //var url=api_report.exportData($scope.mdxpath).getRequestedUrl();
  780. if(!uuid&&queryUUID){
  781. uuid=queryUUID;
  782. }
  783. var name = $scope.mdxpath;
  784. // if(workspace.query.name!=undefined){
  785. // exportMdxBefore(name,uuid, function(queryName,path){
  786. // var filename = path.substring(path.lastIndexOf('/')+1).slice(0, -5);
  787. // $http({
  788. // url : api_report.exportData('flat', queryName, encodeURIComponent(filename)).getRequestedUrl(),
  789. // method : 'GET',
  790. // params : {},
  791. // headers : {
  792. // //'Content-type' : 'application/xls',
  793. // 'Accept': 'application/vnd.ms-excel',
  794. // 'X-Auth-Token' : $cookieStore.get('Auth-Token')||null
  795. // },
  796. // responseType : 'arraybuffer'
  797. // }).success(function(data, status, headers, config) {
  798. // var file = new Blob([ data ], {
  799. // type : 'application/vnd.ms-excel'
  800. // });
  801. // //trick to download store a file having its URL
  802. // var fileURL = URL.createObjectURL(file);
  803. // var a = document.createElement('a');
  804. // a.href = fileURL;
  805. // a.target = '_blank';
  806. // a.download = filename+"xls";
  807. // document.body.appendChild(a);
  808. // a.click();
  809. // }).error(function(data, status, headers, config) {
  810. // console.log(data);
  811. // });
  812. // });
  813. // }
  814. // return;
  815. //return url;
  816. if(workspace.query.name!=undefined){
  817. var filename = name.substring(name.lastIndexOf('/')+1).slice(0, -5);
  818. if(filename=="事件详细资料."){
  819. // api_statistic.unidimensionalExport(workspace.query.parameters,$scope.rptUUID).then(function(data){
  820. // var file = new Blob([ data ], {
  821. // type : 'application/vnd.ms-excel;charset=utf-8;'
  822. // });
  823. // //trick to download store a file having its URL
  824. // var fileURL = URL.createObjectURL(file);
  825. // var a = document.createElement('a');
  826. // a.href = fileURL;
  827. // a.target = '_blank';
  828. // a.download = filename+"xls";
  829. // document.body.appendChild(a);
  830. // a.click();
  831. // })
  832. $http({
  833. url : api_statistic.unidimensionalExport($scope.rptUUID).getRequestedUrl(),
  834. method : 'POST',
  835. data : workspace.query.parameters,
  836. headers : {
  837. //'Content-type' : 'application/xls',
  838. 'Accept': '*/*'
  839. },
  840. responseType : 'arraybuffer'
  841. }).success(function(data, status, headers, config) {
  842. var file = new Blob([ data ], {
  843. type : 'application/vnd.ms-excel'
  844. });
  845. //trick to download store a file having its URL
  846. var fileURL = URL.createObjectURL(file);
  847. var a = document.createElement('a');
  848. a.href = fileURL;
  849. a.target = '_blank';
  850. a.download = filename+"xls";
  851. document.body.appendChild(a);
  852. a.click();
  853. }).error(function(data, status, headers, config) {
  854. console.log(data);
  855. });
  856. }else{
  857. $http({
  858. url : api_report.exportData('flat', uuid, encodeURIComponent(filename)).getRequestedUrl(),
  859. method : 'POST',
  860. data : workspace.query,
  861. headers : {
  862. //'Content-type' : 'application/xls',
  863. 'Accept': 'application/vnd.ms-excel',
  864. 'X-Auth-Token' : $cookieStore.get('Auth-Token')||null
  865. },
  866. responseType : 'arraybuffer'
  867. }).success(function(data, status, headers, config) {
  868. var file = new Blob([ data ], {
  869. type : 'application/vnd.ms-excel'
  870. });
  871. //trick to download store a file having its URL
  872. var fileURL = URL.createObjectURL(file);
  873. var a = document.createElement('a');
  874. a.href = fileURL;
  875. a.target = '_blank';
  876. a.download = filename+"xls";
  877. document.body.appendChild(a);
  878. a.click();
  879. }).error(function(data, status, headers, config) {
  880. console.log(data);
  881. });
  882. }
  883. }
  884. /*
  885. if(workspace.query.name!=undefined){
  886. var filename = name.substring(name.lastIndexOf('/')+1).slice(0, -5);
  887. window.location=api_report.exportData('flat', encodeURIComponent(filename)).getRequestedUrl();
  888. }*/
  889. // if(workspace.query.name!=undefined){
  890. // var filename = name.substring(name.lastIndexOf('/')+1).slice(0, -5);
  891. // //var win = window.open('_blank');
  892. // downFile(api_report.exportData('flat', encodeURIComponent(filename)).getRequestedUrl(), function(blob){
  893. // var url = URL.createObjectURL(blob);
  894. // window.location = url;
  895. // });
  896. // }
  897. }
  898. function downFile(url, success){
  899. var xhr = new XMLHttpRequest();
  900. xhr.open('GET', url, true);
  901. xhr.setRequestHeader("X-Auth-Token", $cookieStore.get('Auth-Token'))
  902. xhr.responseType = "blob";
  903. xhr.onreadystatechange = function(){
  904. if(xhr.readyState == 4){
  905. if(success) success(xhr.response);
  906. }
  907. }
  908. }
  909. $scope.rheaders = [];
  910. $scope.rRows = [];
  911. function executeQuery(mdxquery){
  912. api_report.execute(mdxquery).then(function(data){
  913. $scope.rheaders = [];
  914. $scope.rRows = [];
  915. var reportData = Restangular.stripRestangular(data);
  916. //console.log(reportData);
  917. var tableContent = render(reportData);
  918. //console.log(tableContent);
  919. //console.log($scope.rheaders);
  920. })
  921. }
  922. function render(data){
  923. return internalRenderTable(data);
  924. }
  925. function internalRenderTable(allData){
  926. var tableContent = "";
  927. var rowContent = "";
  928. var data = allData.cellset;
  929. var table = data ? data : [];
  930. var colSpan;
  931. var colValue;
  932. var isHeaderLowestLvl;
  933. var isBody = false;
  934. var firstColumn;
  935. var isLastColumn, isLastRow;
  936. var nextHeader;
  937. var processedRowHeader = false;
  938. var lowestRowLvl = 0;
  939. var rowGroups = [];
  940. var batchSize = null;
  941. var batchStarted = false;
  942. var isColHeader = false, isColHeaderDone = false;
  943. var resultRows = [];
  944. var wrapContent = true;
  945. var colHeaders = [];
  946. var rowHeaders = [];
  947. var rowDatas = [];
  948. var allDatas = [];
  949. // if (options) {
  950. // batchSize = options.hasOwnProperty('batchSize') ? options.batchSize : null;
  951. // wrapContent = options.hasOwnProperty('wrapContent') ? options.wrapContent : true;
  952. // }
  953. var totalsLists = {};
  954. totalsLists[COLUMNS] = allData.rowTotalsLists;
  955. totalsLists[ROWS] = allData.colTotalsLists;
  956. var scanSums = {};
  957. var scanIndexes = {};
  958. var dirs = [ROWS, COLUMNS];
  959. for (var i = 0; i < dirs.length; i++) {
  960. scanSums[dirs[i]] = new Array();
  961. scanIndexes[dirs[i]] = new Array();
  962. }
  963. if (totalsLists[COLUMNS])
  964. for (var i = 0; i < totalsLists[COLUMNS].length; i++) {
  965. scanIndexes[COLUMNS][i] = 0;
  966. scanSums[COLUMNS][i] = totalsLists[COLUMNS][i][scanIndexes[COLUMNS][i]].width;
  967. }
  968. for (var row = 0, rowLen = table.length; row < rowLen; row++) {
  969. var rowShifted = row - allData.topOffset;
  970. colSpan = 1;
  971. colValue = "";
  972. isHeaderLowestLvl = false;
  973. isLastColumn = false;
  974. isLastRow = false;
  975. isColHeader = false;
  976. var headerSame = false;
  977. if (totalsLists[ROWS])
  978. for (var i = 0; i < totalsLists[ROWS].length; i++) {
  979. scanIndexes[ROWS][i] = 0;
  980. scanSums[ROWS][i] = totalsLists[ROWS][i][scanIndexes[ROWS][i]].width;
  981. }
  982. rowContent = "<tr>";
  983. if ( row === 0) {
  984. rowContent = "<thead>" + rowContent;
  985. }
  986. for (var col = 0, colLen = table[row].length; col < colLen; col++) {
  987. var colShifted = col - allData.leftOffset;
  988. var header = data[row][col];
  989. if (header.type === "COLUMN_HEADER") {
  990. isColHeader = true;
  991. }
  992. // If the cell is a column header and is null (top left of table)
  993. if (header.type === "COLUMN_HEADER" && header.value === "null" && (firstColumn == null || col < firstColumn)) {
  994. rowContent += '<th class="all_null">&nbsp;</th>';
  995. var headerObject = { thclass: 'all_null', value: '\u00A0/\u00A0'};
  996. colHeaders.push(headerObject);
  997. } // If the cell is a column header and isn't null (column header of table)
  998. else if (header.type === "COLUMN_HEADER") {
  999. if (firstColumn == null) {
  1000. firstColumn = col;
  1001. }
  1002. if (table[row].length == col+1)
  1003. isLastColumn = true;
  1004. else
  1005. nextHeader = data[row][col+1];
  1006. if (isLastColumn) {
  1007. // Last column in a row...
  1008. if (header.value == "null") {
  1009. rowContent += '<th class="col_null">&nbsp;</th>';
  1010. var headerObject = { thclass: 'all_null', value: '\u00A0/\u00A0'};
  1011. colHeaders.push(headerObject);
  1012. } else {
  1013. if (totalsLists[ROWS])
  1014. colSpan = totalsLists[ROWS][row + 1][scanIndexes[ROWS][row + 1]].span;
  1015. rowContent += '<th class="col" style="text-align: center;" colspan="' + colSpan + '" title="' + header.value + '">'
  1016. + (wrapContent ? '<div rel="' + row + ":" + col +'">' + header.value + '</div>' : header.value)
  1017. + '</th>';
  1018. var headerObject = { thclass: 'col', colspan:''+colSpan+'', title:header.value};
  1019. if(wrapContent){
  1020. headerObject.value = { rel: row+":"+col, value: header.value };
  1021. }else{
  1022. headerObject.value = header.value;
  1023. }
  1024. colHeaders.push(headerObject);
  1025. }
  1026. } else {
  1027. // All the rest...
  1028. var groupChange = (col > 1 && row > 1 && !isHeaderLowestLvl && col > firstColumn) ?
  1029. data[row-1][col+1].value != data[row-1][col].value || data[row-1][col+1].properties.uniquename != data[row-1][col].properties.uniquename
  1030. : false;
  1031. var maxColspan = colSpan > 999 ? true : false;
  1032. if (header.value != nextHeader.value || nextParentsDiffer(data, row, col) || isHeaderLowestLvl || groupChange || maxColspan) {
  1033. if (header.value == "null") {
  1034. rowContent += '<th class="col_null" colspan="' + colSpan + '">&nbsp;</th>';
  1035. var headerObject = { thclass: 'col_null', colspan:colSpan, value:"&nbsp;"};
  1036. colHeaders.push(headerObject);
  1037. } else {
  1038. if (totalsLists[ROWS])
  1039. colSpan = totalsLists[ROWS][row + 1][scanIndexes[ROWS][row + 1]].span;
  1040. rowContent += '<th class="col" style="text-align: center;" colspan="' + (colSpan == 0 ? 1 : colSpan) + '" title="' + header.value + '">'
  1041. + (wrapContent ? '<div rel="' + row + ":" + col +'">' + header.value + '</div>' : header.value)
  1042. + '</th>';
  1043. var headerObject = { thclass: 'col', colspan:(colSpan == 0 ? 1 : colSpan), title:header.value};
  1044. if(wrapContent){
  1045. headerObject.value = { rel: row+":"+col, value: header.value };
  1046. }else{
  1047. headerObject.value = header.value;
  1048. }
  1049. colHeaders.push(headerObject);
  1050. }
  1051. colSpan = 1;
  1052. } else {
  1053. colSpan++;
  1054. }
  1055. }
  1056. if (totalsLists[ROWS])
  1057. rowContent += genTotalHeaderCells(col - allData.leftOffset + 1, row + 1, scanSums[ROWS], scanIndexes[ROWS], totalsLists[ROWS], wrapContent);
  1058. //TODO
  1059. } // If the cell is a row header and is null (grouped row header)
  1060. else if (header.type === "ROW_HEADER" && header.value === "null") {
  1061. rowContent += '<th class="row_null">&nbsp;</th>';
  1062. var headerObject = { thclass: 'row_null', value:header.value};
  1063. colHeaders.push();
  1064. } // If the cell is a row header and isn't null (last row header)
  1065. else if (header.type === "ROW_HEADER") {
  1066. if (lowestRowLvl == col)
  1067. isHeaderLowestLvl = true;
  1068. else
  1069. nextHeader = data[row][col+1];
  1070. var previousRow = data[row - 1];
  1071. var headerObject = {};
  1072. var same = !headerSame && !isHeaderLowestLvl && (col == 0 || !topParentsDiffer(data, row, col)) && header.value === previousRow[col].value;
  1073. headerSame = !same;
  1074. var value = (same ? "<div>&nbsp;</div>" : '<div rel="' + row + ":" + col +'">' + header.value + '</div>');
  1075. if(same){
  1076. headerObject.value = {
  1077. value:'\u00A0/\u00A0'
  1078. }
  1079. }else{
  1080. headerObject.value = {
  1081. value:header.value,
  1082. rel:row + ":" + col
  1083. }
  1084. }
  1085. if (!wrapContent) {
  1086. value = (same ? "&nbsp;" : header.value );
  1087. if(same){
  1088. headerObject.value='\u00A0/\u00A0';
  1089. }else{
  1090. headerObject.value=header.value;
  1091. }
  1092. }
  1093. var tipsy = "";
  1094. var cssclass = (same ? "row_null" : "row");
  1095. var colspan = 0;
  1096. if (!isHeaderLowestLvl && (typeof nextHeader == "undefined" || nextHeader.value === "null")) {
  1097. colspan = 1;
  1098. var group = header.properties.dimension;
  1099. var level = header.properties.level;
  1100. var groupWidth = (group in rowGroups ? rowGroups[group].length - rowGroups[group].indexOf(level) : 1);
  1101. for (var k = col + 1; colspan < groupWidth && k <= (lowestRowLvl+1) && data[row][k] !== "null"; k++) {
  1102. colspan = k - col;
  1103. }
  1104. col = col + colspan -1;
  1105. }
  1106. rowContent += '<th class="' + cssclass + '" ' + (colspan > 0 ? ' colspan="' + colspan + '"' : "") + tipsy + '>' + value + '</th>';
  1107. headerObject.thclass=cssclass;
  1108. if(colspan>0){
  1109. console.log("colspan:"+colspan);
  1110. headerObject.colspan = colspan;
  1111. }
  1112. console.log("-----");
  1113. console.log(headerObject);
  1114. rowDatas.push(headerObject);
  1115. }
  1116. else if (header.type === "ROW_HEADER_HEADER") {
  1117. rowContent += '<th class="row_header">' + (wrapContent ? '<div>' + header.value + '</div>' : header.value) + '</th>';
  1118. var headerObject = { thclass: 'row_header', value:header.value};
  1119. if(wrapContent){
  1120. headerObject.value = {
  1121. value:header.value
  1122. }
  1123. }else{
  1124. headerObject.value=header.value;
  1125. }
  1126. colHeaders.push(headerObject);
  1127. isHeaderLowestLvl = true;
  1128. processedRowHeader = true;
  1129. lowestRowLvl = col;
  1130. if (header.properties.hasOwnProperty("dimension")) {
  1131. var group = header.properties.dimension;
  1132. if (!(group in rowGroups)) {
  1133. rowGroups[group] = [];
  1134. }
  1135. rowGroups[group].push(header.properties.level);
  1136. }
  1137. } // If the cell is a normal data cell
  1138. else if (header.type === "DATA_CELL") {
  1139. batchStarted = true;
  1140. var color = "";
  1141. var val = header.value;
  1142. var arrow = "";
  1143. var rowEntity = {};
  1144. if (header.properties){
  1145. if (header.properties.hasOwnProperty('image')) {
  1146. var img_height = header.properties.hasOwnProperty('image_height') ? " height='" + header.properties.image_height + "'" : "";
  1147. var img_width = header.properties.hasOwnProperty('image_width') ? " width='" + header.properties.image_width + "'" : "";
  1148. val = "<img " + img_height + " " + img_width + " style='padding-left: 5px' src='" + header.properties.image + "' border='0'>";
  1149. }
  1150. if (header.properties.hasOwnProperty('style')) {
  1151. color = " style='background-color: " + header.properties.style + "' ";
  1152. rowEntity.rowStyle={'background-color':header.properties.style};
  1153. }
  1154. if (header.properties.hasOwnProperty('link')) {
  1155. val = "<a target='__blank' href='" + header.properties.link + "'>" + val + "</a>";
  1156. //rowEntity.value=
  1157. }
  1158. if (header.properties.hasOwnProperty('arrow')) {
  1159. arrow = "<img height='10' width='10' style='padding-left: 5px' src='./images/arrow-" + header.properties.arrow + ".gif' border='0'>";
  1160. //rowEntity.arrow=
  1161. }
  1162. }else{
  1163. header.properties = {};
  1164. }
  1165. rowContent += '<td class="data" ' + color + '>'
  1166. + (wrapContent ? '<div class="datadiv" alt="' + header.properties.raw + '" rel="' + header.properties.position + '">' : "")
  1167. + val + arrow
  1168. + (wrapContent ? '</div>' : '') + '</td>';
  1169. if(wrapContent){
  1170. rowEntity.value={
  1171. alt:header.properties.raw,
  1172. rel:header.properties.position,
  1173. value:val
  1174. }
  1175. }else{
  1176. rowEntity.value=val;
  1177. }
  1178. rowDatas.push(rowEntity);
  1179. if (totalsLists[ROWS])
  1180. rowContent += genTotalDataCells(colShifted + 1, rowShifted, scanSums[ROWS], scanIndexes[ROWS], totalsLists, wrapContent);
  1181. }
  1182. }
  1183. rowContent += "</tr>";
  1184. if(colHeaders.length!=0&&colHeaders[0].value.value=="(All)"){colHeaders=colHeaders.splice(1,6)}
  1185. $scope.rheaders.push(colHeaders);
  1186. // $scope.rheaders=$scope.rheaders[0].splice(1,1)
  1187. colHeaders = [];
  1188. if(rowDatas.length>1){
  1189. if(rowDatas.length!=0&&rowDatas[0].value.value=="所有状态"){rowDatas[0].colspan=""}
  1190. if(rowDatas.length!=0&&rowDatas[0].thclass=="row_null"){rowDatas=rowDatas.splice(1,6)}
  1191. $scope.rRows.push(rowDatas);
  1192. rowDatas = [];
  1193. }
  1194. console.log($scope.rRows)
  1195. var totals = "";
  1196. if (totalsLists[COLUMNS] && rowShifted >= 0) {
  1197. totals += genTotalHeaderRowCells(rowShifted + 1, scanSums, scanIndexes, totalsLists, wrapContent);
  1198. }
  1199. if (batchStarted && batchSize) {
  1200. if (row <= batchSize) {
  1201. if (!isColHeader && !isColHeaderDone) {
  1202. tableContent += "</thead><tbody>";
  1203. isColHeaderDone = true;
  1204. }
  1205. tableContent += rowContent;
  1206. if (totals.length > 0) {
  1207. tableContent += totals;
  1208. }
  1209. } else {
  1210. resultRows.push(rowContent);
  1211. if (totals.length > 0) {
  1212. resultRows.push(totals);
  1213. }
  1214. }
  1215. } else {
  1216. if (!isColHeader && !isColHeaderDone) {
  1217. tableContent += "</thead><tbody>";
  1218. isColHeaderDone = true;
  1219. }
  1220. tableContent += rowContent;
  1221. if (totals.length > 0) {
  1222. tableContent += totals;
  1223. }
  1224. }
  1225. }
  1226. // if($scope.reportName=="事件详细资料"){
  1227. // var hmainCol=53*$scope.rRows.length;
  1228. // $scope.allheight=hmainCol+160;
  1229. // // }else if($scope.reportName=="事件解决率统计"){
  1230. // // var hmainCol=35*($scope.rRows.length+2);
  1231. // // $scope.allheight=hmainCol+570;
  1232. // }else if($scope.reportName=="事件工作回顾"||$scope.reportName=="事件解决率统计"){
  1233. // var hmainCol=35*($scope.rRows.length);
  1234. // $scope.allheight=hmainCol+140;
  1235. // }else{
  1236. var hmainCol=35*$scope.rRows.length;
  1237. $scope.allheight=hmainCol+570;
  1238. // }
  1239. // if (options) {
  1240. // options['batchResult'] = resultRows;
  1241. // options['hasBatchResult'] = resultRows.length > 0;
  1242. // }
  1243. return "<table>" + tableContent + "</tbody></table>";
  1244. }
  1245. // $scope.rheaders=$scope.rheaders.splice(1,1)
  1246. function nextParentsDiffer(data, row, col) {
  1247. while (row-- > 0) {
  1248. if (data[row][col].properties.uniquename != data[row][col + 1].properties.uniquename)
  1249. return true;
  1250. }
  1251. return false;
  1252. }
  1253. // $scope.chartType="doughnut";
  1254. // //chart view
  1255. // $scope.chartData = [
  1256. // { value : 50, color : "#F7464A" },
  1257. // { value : 90, color : "#E2EAE9" },
  1258. // { value : 75, color : "#D4CCC5" },
  1259. // { value : 30, color : "#949FB1"}
  1260. // ];
  1261. // $scope.chartOptions = {
  1262. // // Chart.js options can go here.
  1263. // };
  1264. $scope.onChartClick = function (event) {
  1265. console.log(event);
  1266. };
  1267. var tmpHSV=undefined;
  1268. function randomHSV(hsv){
  1269. if(angular.isUndefined(hsv)){
  1270. return {
  1271. h:0,
  1272. s:0.75,
  1273. v:0.8
  1274. };
  1275. }else{
  1276. return {
  1277. h:hsv.h+51.5,
  1278. s:0.75,
  1279. v:0.8
  1280. }
  1281. }
  1282. }
  1283. function HSVToRGB(h,s,v){
  1284. var i;
  1285. var f, p, q, t;
  1286. var r,g,b;
  1287. if( s == 0 ) {
  1288. v = Math.floor(v*255);
  1289. return {
  1290. r:v,
  1291. g:v,
  1292. b:v
  1293. };
  1294. }
  1295. h /= 60;
  1296. i = Math.floor( h );
  1297. f = h - i;
  1298. p = v * ( 1 - s );
  1299. q = v * ( 1 - s * f );
  1300. t = v * ( 1 - s * ( 1 - f ) );
  1301. switch( i ) {
  1302. case 0:r = v;g = t;b = p;break;
  1303. case 1:r = q;g = v;b = p; break;
  1304. case 2: r = p;g = v;b = t;break;
  1305. case 3:r = p;g = q;b = v;break;
  1306. case 4:r = t;g = p;b = v;break;
  1307. default:r = v;g = p;b = q;break;
  1308. }
  1309. return {
  1310. r:r*255,
  1311. g:g*255,
  1312. b:b*255
  1313. };
  1314. };
  1315. function colorToHex(color) {
  1316. var red = color.r;
  1317. var green = color.g;
  1318. var blue = color.b;
  1319. var rgb = blue | (green << 8) | (red << 16);
  1320. return '#' + rgb.toString(16);
  1321. };
  1322. }]);