userPost.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**
  2. * admin/userPost
  3. */
  4. var mcare_admin_userPost = function(){
  5. //상속
  6. mcare_admin.call(this);
  7. var self = this;
  8. //변수
  9. var $grid = $("#grid"),
  10. $chart = $("#chart"),
  11. $legend = $("#chart_legend"),
  12. $crudServiceBaseUrl = contextPath + "/admin/stats";
  13. /**
  14. * 초기화
  15. */
  16. this.init = function(){
  17. initGrid();
  18. //initChart();
  19. addEvent();
  20. };
  21. /**
  22. * 이벤트 등록
  23. */
  24. var addEvent = function(){
  25. };
  26. //데이터소스
  27. var postNoValue = [],
  28. dataCnt = [];
  29. /**
  30. * 데이터소스 설정
  31. */
  32. var setDataSource = function(){
  33. var dataSource = new kendo.data.DataSource({
  34. transport: {
  35. read: {
  36. url: $crudServiceBaseUrl + "/getUserPostnoList.json",
  37. method: "post",
  38. dataType: "json",
  39. contentType: "application/json"
  40. },
  41. parameterMap: getParameterMap
  42. },
  43. schema: {
  44. data : getSchemaData
  45. },
  46. change: function(e) {
  47. // update chart
  48. }
  49. });
  50. /**
  51. * 데이터소스 파라미터맵
  52. * @private
  53. */
  54. function getParameterMap( options, operation ){
  55. var today = new Date();
  56. today.setDate( today.getDate() - 1 );
  57. var param = $.extend(true, {}, options, {
  58. strDate : new Date( today ).setHours(0, 0, 0, 0),
  59. endDate : new Date( today ).setHours(0, 0, 0, 0),
  60. }, null);
  61. return self.util.stringifyJson( param );
  62. };
  63. /**
  64. * 데이터소스 스키마설정
  65. * @private
  66. */
  67. function getSchemaData(e){
  68. if( e.msg !== undefined ){
  69. alert(e.msg);
  70. return [];
  71. }
  72. var userPostList = e.aggUserPostnoList;
  73. var postNoValueArr = postNoValue = new Array(),
  74. dataCntArr = dataCnt = new Array();
  75. var param = [];
  76. if( userPostList.length <= 0 ){
  77. postNoValueArr.push( "없음" );
  78. dataCntArr.push( 0 );
  79. param.push({
  80. "postNoValue" : "없음",
  81. // "postNoDesc" : "없음",
  82. "dataCnt" : 0
  83. });
  84. } else {
  85. for( var i = 0 ; i < userPostList.length; i++ ) {
  86. var item = userPostList[i];
  87. postNoValueArr.push( item["postnoValue"] );
  88. dataCntArr.push( item["dataCnt"] );
  89. param.push({
  90. // "postNoValue" : item["postnoValue"],
  91. "postNoValue" : item["postnoValue"] == "" ? "기간계 데이터오류" : item["postnoValue"],
  92. // "postNoDesc" : item["postnoValue"]!=="000" ? item["postnoDesc"] : "알 수 없음",
  93. "dataCnt" : item["dataCnt"]
  94. });
  95. }
  96. }
  97. return param;
  98. };
  99. return dataSource;
  100. };
  101. var dataSource = setDataSource();
  102. /**
  103. * 그리드 초기화
  104. */
  105. var initGrid = function(){
  106. // 그리드 옵션
  107. var option = {
  108. dataSource: dataSource,
  109. //그리드 데이터 받아온 뒤 차트 초기화
  110. dataBound: initChart,
  111. pageable: false,
  112. selectable: true,
  113. height : 215,
  114. columns : [
  115. // {
  116. // field : "postNoValue",
  117. // title : "시군구코드",
  118. // width: 252,
  119. // attributes: {
  120. // "class": "table-cell",
  121. // style: "text-align: center;"
  122. // }
  123. // },
  124. {
  125. field : "postNoValue",
  126. title : "지역",
  127. width: 252,
  128. attributes: {
  129. "class": "table-cell",
  130. style: "text-align: center;"
  131. }
  132. },
  133. {
  134. field : "dataCnt",
  135. title : "인원수",
  136. width: 152,
  137. template: "#= kendo.toString(data.dataCnt,'n0')# 명",
  138. attributes: {
  139. "class": "table-cell",
  140. style: "text-align: center;"
  141. }
  142. }
  143. ]
  144. };
  145. //그리드 초기화 - mcare_admin
  146. self.grid( $grid, option );
  147. };
  148. /**
  149. * 차트 초기화
  150. */
  151. var initChart = function(){
  152. // 차트 옵션 TODO: chartjs로 변경한다
  153. var data = { labels: postNoValue,
  154. datasets: [
  155. {
  156. label: "지역",
  157. fillColor: "rgba(151,187,205,0.0)",
  158. strokeColor: "rgba(151,187,205,1)",
  159. pointColor: "rgba(151,187,205,1)",
  160. pointStrokeColor: "#fff",
  161. pointHighlightFill: "#fff",
  162. pointHighlightStroke: "rgba(151,187,205,1)",
  163. data: dataCnt
  164. }
  165. ]
  166. };
  167. var option = {
  168. tooltipTemplate: "<%= value %> 명",
  169. //tooltip 표시 감지 거리 px
  170. pointHitDetectionRadius : 1
  171. };
  172. //차트 초기화 mcare_admin
  173. self.chart( $chart, "line", option, data, $legend );
  174. };
  175. };