a0cb51f1874a6d394fd988b628031245205f49a1.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. BemsWebApplication.Water_HAnalysis = function (params, viewInfo) {
  2. "use strict";
  3. var initialized = false,
  4. shouldReload = false,
  5. datagrid = null,
  6. currentTabIndex = ko.observable(0),
  7. facilityViewModel = new BWA.CmFacilityViewModel(),
  8. dataSource;
  9. var m_Facility;
  10. var multiViewItems = [{
  11. template: 'mainCharts'
  12. }, {
  13. template: 'subCharts'
  14. }
  15. ];
  16. var facilityDataSource = BWA.db.createDataSource('CmFacility'),
  17. facilitiesForSearch = ko.observableArray(),
  18. facilityCodeForSearch = ko.observable(0),
  19. deferredForSearch = new $.Deferred();
  20. var visiblePopup = ko.observable(false);
  21. var dataCalorie = ko.observableArray(),
  22. dataAtfw = ko.observableArray(),
  23. dataTemperatureCalorie = ko.observableArray(),
  24. dataTemperatureElectricity = ko.observableArray();
  25. var formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId());
  26. //var timeBoxForSearch = BWA.SearchView.createDateTimeBox();
  27. // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
  28. var timeBoxForSearch = BWA.SearchView.createDateTimeBox($G.TimeTypesForHourOnly, null, false);
  29. var chartEffi = BWA.Chart.Instance('chartEffiWHA', 'dxChart');
  30. var chartLayout = new BWA.ChartLayout({
  31. divs: [[{
  32. id: 'WaterHDetail'
  33. }, {
  34. id: 'effi',
  35. chartId: 'chartEffiWHA'
  36. }
  37. ]],
  38. multiViewOptions: {
  39. viewIndex: currentTabIndex,
  40. viewCount: 1
  41. }
  42. });
  43. var m = moment();
  44. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  45. // 팝업창뷰 보이기 속성 제어용 변수 선언
  46. var DataGridPopup_Visible = ko.observable(false);
  47. // 그래프 출력 이후 엑셀출력을 위한 팝업창을 위해 임시 저장용 배열 선언
  48. var dataArrayresult = ko.observableArray();
  49. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  50. dataCalorie([
  51. { DateTime: new Date(m.year(), m.month(), 1), Value: 50 },
  52. { DateTime: new Date(m.year(), m.month(), 2), Value: 50 },
  53. { DateTime: new Date(m.year(), m.month(), 3), Value: 60 },
  54. { DateTime: new Date(m.year(), m.month(), 4), Value: 80 },
  55. { DateTime: new Date(m.year(), m.month(), 5), Value: 100 },
  56. { DateTime: new Date(m.year(), m.month(), 6), Value: 40, },
  57. { DateTime: new Date(m.year(), m.month(), 7), Value: 120 },
  58. { DateTime: new Date(m.year(), m.month(), 31), Value: 120 }
  59. ]);
  60. // 추가 2015 04 20 hcLee ->
  61. var CODE = $Code,
  62. FuelType = CODE.FuelType,
  63. FT = CODE.FacilityType,
  64. FC = CODE.FacilityCode,
  65. F = CODE.Formula,
  66. TIT = CODE.TimeIntervalType;
  67. // 추가 2015 04 20 hcLee <-
  68. //dataMonthForBar(dataDayForBar());
  69. //dataDayForPie([
  70. // { FuelTypeName: '전기', Value: 320 },
  71. // { FuelTypeName: '가스', Value: 350 },
  72. // { FuelTypeName: '수도', Value: 360 },
  73. //]);
  74. //dataMonthForPie(dataDayForPie());
  75. function handleViewShown() {
  76. if (initialized === false) {
  77. var chartOption = BWA.ChartOptions.WaterHAnalysis;
  78. chartEffi = chartEffi(chartOption.getChartEffiOptions($Code.TimeType.HOUR));
  79. initialized = true;
  80. }
  81. //hcLee 2016 07 12
  82. timeBoxForSearch.setDefaultDate();
  83. var eq = BWA.DataUtil.constructEqualFilter;
  84. facilityDataSource.filter([
  85. eq('SiteId', BWA.UserInfo.SiteId()),
  86. 'and',
  87. eq('FacilityTypeId', $Code.FacilityType.WATER_H)
  88. ]);
  89. facilityDataSource.load().done(function (facilities) {
  90. facilitiesForSearch(facilities);
  91. if (_.isEmpty(facilities) === false) {
  92. var f = facilities[0];
  93. handleSelectedFacilityInSearchView(f);
  94. handleSearchInSearchView();
  95. var datagrid = $('#WaterHDataGridViewInSearchView').dxDataGrid('instance');
  96. if (_.has(datagrid, 'selectRows')) {
  97. datagrid.selectRows(f);
  98. }
  99. }
  100. });
  101. }
  102. if (shouldReload) {
  103. //shouldReload = false;
  104. //dataSource.pageIndex(0);
  105. //dataSource.load();
  106. }
  107. function handleViewHidden() {
  108. var paging = BWA.ChartLayout.Paging;
  109. paging.sideOverlayVisible(false);
  110. $SearchView.visibleObservable(false); // hcLee 2015 03 23
  111. visiblePopup(false);
  112. }
  113. function handleViewShowing() {
  114. }
  115. function refreshList() {
  116. //dataSource.pageIndex(0);
  117. //dataSource.load();
  118. }
  119. var searchViewOptions = {
  120. searchViewItems: [
  121. { id: 'FacilityCode', ignoreValue: 0, defaultValue: 0, value: facilityCodeForSearch, dataSource: facilitiesForSearch },
  122. ],
  123. promiseDataInSearchView: deferredForSearch.promise()
  124. };
  125. function handleSelectedFacilityInSearchView(facility) {
  126. m_Facility = facility;
  127. return;
  128. }
  129. function handleSearchInSearchView(filter, searchViewItems) {
  130. if (m_Facility == null) return;
  131. var f = m_Facility.toJS();
  132. facilityViewModel.fromJS(f);
  133. //var timeIntervalType = $Code.TimeIntervalType.QUARTERMIN;
  134. var timeIntervalType = timeBoxForSearch.type();
  135. var formula = $Code.Formula[$Code.FacilityType.WATER_H];
  136. var formulaIds = _.values(formula);
  137. var date = timeBoxForSearch.getDate();
  138. visiblePopup(true);
  139. $("#large-indicator").dxLoadIndicator({
  140. height: 60,
  141. width: 60
  142. });
  143. // var startDate = moment().
  144. var promises = [];
  145. _.each(formulaIds, function (formulaId) {
  146. var p = formulaGet.apiGet({
  147. FacilityTypeId: f.FacilityTypeId,
  148. FacilityCode: f.FacilityCode,
  149. FormulaId: formulaId,
  150. TimeIntervalType: timeIntervalType,
  151. StartDate: date.startDate,
  152. EndDate: date.endDate
  153. });
  154. promises.push(p);
  155. });
  156. /*
  157. // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20 ->
  158. var commonParameters = {
  159. TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
  160. StartDate: date.startDate,
  161. EndDate: date.endDate
  162. };
  163. var temperatureParameters = {
  164. FacilityTypeId: FT.OUTDOOR,
  165. FacilityCode: FC.OUTDOOR,
  166. FormulaId: F[FT.OUTDOOR].TEMPERATURE,
  167. };
  168. promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)));
  169. */ // 보일러는 필요 없다
  170. $.when.apply(this, promises)
  171. .done(function (sw, hw, lev) {
  172. sw = sw[0];
  173. hw = hw[0];
  174. lev = lev[0];
  175. var maxValue = 0;
  176. _.each(sw, function (x) {
  177. if (maxValue < x.Value) maxValue = x.Value;
  178. });
  179. _.each(hw, function (x) {
  180. if (maxValue < x.Value) maxValue = x.Value;
  181. });
  182. // chart 1
  183. var EffiDataArray = [];
  184. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  185. var dataArray_Temp = [];
  186. var dataArray_Temp1 = [];
  187. var dataArray_Temp2 = [];
  188. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  189. _.each(sw, function (x) {
  190. dataArray_Temp.push({
  191. //DateTime: moment(x.DateTime).toDate(),
  192. DateTime: BWA.Chart.getCustermTimeArgumentAxisString($Code.TimeType.QUARTERMIN, moment(x.DateTime).toDate()),
  193. sw: x.Value //보충
  194. });
  195. });
  196. _.each(hw, function (x) {
  197. dataArray_Temp1.push({
  198. //DateTime: moment(x.DateTime).toDate(),
  199. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  200. hw: x.Value //중수
  201. });
  202. });
  203. _.each(lev, function (x) {
  204. dataArray_Temp2.push({
  205. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  206. lev: x.Value //수위
  207. });
  208. });
  209. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  210. // 배열을 하나로 합치자
  211. var array_length_size = Math.max(dataArray_Temp.length, dataArray_Temp1.length, dataArray_Temp2.length);
  212. // 크기가 동일한 경우에만 허용함 (예외 방어용)
  213. if ((dataArray_Temp.length == dataArray_Temp1.length) && (dataArray_Temp.length == dataArray_Temp2.length)) {
  214. for (var i = 0; i < array_length_size; i++) {
  215. EffiDataArray.push(
  216. {
  217. DateTime: dataArray_Temp[i].DateTime,
  218. sw: dataArray_Temp[i].sw,
  219. hw: dataArray_Temp1[i].hw,
  220. lev: dataArray_Temp2[i].lev
  221. });
  222. }
  223. }
  224. dataArrayresult = EffiDataArray;
  225. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  226. //chartEffi().option('dataSource', EffiDataArray);
  227. var options = BWA.ChartOptions.WaterHAnalysis.getChartEffiOptions(timeBoxForSearch.type());
  228. options.valueAxis[0].tickInterval = Math.round(maxValue / 9 * 100) / 100;
  229. //options.valueAxis[0].tickInterval = maxValue / 10;
  230. //chartEffi().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
  231. options.dataSource = EffiDataArray;
  232. chartEffi().option(options);
  233. visiblePopup(false);
  234. /* msgbox.
  235. $("#large-indicator").dxLoadIndicator({
  236. height: 60,
  237. width: 60
  238. });*/
  239. //chartTemperatureCalorie().option('dataSource', calories.concat(OUTtemperatures));
  240. //chartTemperatureElectricity2().option('dataSource', electricityDataArray.concat(OUTtemperatures));
  241. })
  242. .fail(function (error) {
  243. //alert(error);
  244. visiblePopup(false);
  245. });
  246. }
  247. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  248. function DataGridPopup_ButtonClick() {
  249. DataGridPopup_Visible(true);
  250. }
  251. function handlePopupShown() {
  252. // 데이타소스 업데이트
  253. $("#WaterHAnalysisDataGrid_Container").dxDataGrid("instance").option("dataSource", dataArrayresult);
  254. // 팝업창 갱신
  255. DataGridPopup_Visible(true);
  256. }
  257. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  258. var viewModel = $.extend(BWA.CommonView.create(
  259. params, viewInfo, searchViewOptions, ko.observable(null),
  260. handleViewShown, null, handleSearchInSearchView, undefined,
  261. chartLayout), {
  262. // facility: facilityViewModel,
  263. refreshList: refreshList,
  264. viewHidden: handleViewHidden, // hcLee 2015 06 03
  265. viewShowing: handleViewShowing,
  266. scrolling: { mode: 'infinite' },
  267. WaterHDataGridOptions: {
  268. dataSource: facilitiesForSearch,
  269. columns: [
  270. { dataField: 'Name', caption: $G('facilityName'), width: '100%', alignment: 'left' }
  271. ],
  272. filterRow: {
  273. visible: true,
  274. showOperationChooser: false
  275. },
  276. selection: {
  277. mode: 'single'
  278. },
  279. rowClick: function (clickRow) {
  280. handleSelectedFacilityInSearchView(clickRow.data);
  281. }
  282. },
  283. contentReadyAction: function (e) {
  284. datagrid = e.component;
  285. }
  286. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  287. , WaterHAnalysisDataGridPopup_ButtonClicked: DataGridPopup_ButtonClick
  288. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  289. });
  290. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  291. viewModel.WaterHAnalysisDataGridPopupOptions = {
  292. width: '550px',
  293. height: '830px', // cyim 2017.05.30 : 테스트 결과 Devextreme 버그임. px 로 지정하면 초기 출력시 정확하게 가운데에 있지만, auto 설정시 화면아래에 위치하게 됨
  294. contentTemplate: "content",
  295. showTitle: true,
  296. title: "도표",
  297. visible: DataGridPopup_Visible,
  298. dragEnabled: true,
  299. closeOnOutsideClick: true,
  300. shownAction: handlePopupShown,
  301. animation: window.utils.popup.createAnimation(),
  302. shading: false
  303. };
  304. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  305. viewModel.popupOptions = {
  306. width: 300,
  307. height: 100,
  308. contentTemplate: "info",
  309. showTitle: false,
  310. title: "메세지",
  311. visible: visiblePopup,
  312. dragEnabled: false,
  313. shading: false,
  314. closeOnOutsideClick: false
  315. };
  316. viewModel.timeBoxForSearch = timeBoxForSearch;
  317. viewModel.currentTabIndex = currentTabIndex;
  318. viewModel.multiViewItems = [{
  319. facility: facilityViewModel,
  320. template: 'mainCharts'
  321. }, {
  322. template: 'subCharts'
  323. }
  324. ];
  325. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  326. // 주석이 너무 없음. 나중에 변경 작업을 진행하는 누군가가 시간 소비를 하지 않기 위해...남김
  327. // 시간 포맷은 그래프에 귀속해야 되므로 포맷은 변경하지 않는 것이 유리함
  328. // 전기,가스,수도 와 같이 선택적으로 변경해야 된다면 아래와 같이 캡션은 고정하지 말것
  329. viewModel.WaterHAnalysisDataGridOptions = {
  330. dataSource: dataArrayresult,
  331. columns: [
  332. { dataField: 'DateTime', caption: "날짜", width: '40%', alignment: 'center', format: 'fixedPoint', precision: 2 },
  333. { dataField: 'lev', caption: "중수조 수위", width: '30%', alignment: 'center', format: 'fixedPoint', precision: 2 },
  334. { dataField: 'hw', caption: "중수 사용량", width: '30%', alignment: 'center', format: 'fixedPoint', precision: 2 },
  335. { dataField: 'sw', caption: "보충 시수량", width: '30%', alignment: 'center', format: 'fixedPoint', precision: 2 }
  336. ],
  337. // 엑셀 출력
  338. "export": {
  339. enabled: true,
  340. fileName: '중수조 성능분석'
  341. }
  342. };
  343. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  344. return viewModel;
  345. };