eea49cb58ad91b73479e98edc1824e9d45787ba8.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. BemsWebApplication.Water_UAnalysis = 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('chartEffiWUA', 'dxChart');
  30. var chartLayout = new BWA.ChartLayout({
  31. divs: [[{
  32. id: 'WaterUDetail'
  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.WaterUAnalysis;
  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_U)
  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 = $('#WaterUDataGridViewInSearchView').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. visiblePopup(true);
  132. $("#large-indicator").dxLoadIndicator({
  133. height: 60,
  134. width: 60
  135. });
  136. var f = m_Facility.toJS();
  137. facilityViewModel.fromJS(f);
  138. //var timeIntervalType = $Code.TimeIntervalType.QUARTERMIN;
  139. var timeIntervalType = timeBoxForSearch.type();
  140. var formula = $Code.Formula[$Code.FacilityType.WATER_U];
  141. var formulaIds = _.values(formula);
  142. var date = timeBoxForSearch.getDate();
  143. //utils.toast.displayTime=1000000;
  144. //utils.toast.show('공조기 성능분석 중 입니다. 잠시만 기다려 주세요');
  145. // var startDate = moment().
  146. var promises = [];
  147. _.each(formulaIds, function (formulaId) {
  148. var p = formulaGet.apiGet({
  149. FacilityTypeId: f.FacilityTypeId,
  150. FacilityCode: f.FacilityCode,
  151. FormulaId: formulaId,
  152. TimeIntervalType: timeIntervalType,
  153. StartDate: date.startDate,
  154. EndDate: date.endDate
  155. });
  156. promises.push(p);
  157. });
  158. /*
  159. // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20 ->
  160. var commonParameters = {
  161. TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
  162. StartDate: date.startDate,
  163. EndDate: date.endDate
  164. };
  165. var temperatureParameters = {
  166. FacilityTypeId: FT.OUTDOOR,
  167. FacilityCode: FC.OUTDOOR,
  168. FormulaId: F[FT.OUTDOOR].TEMPERATURE,
  169. };
  170. promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)));
  171. */ // 보일러는 필요 없다
  172. $.when.apply(this, promises)
  173. .done(function (sw, lev) {
  174. sw = sw[0];
  175. lev = lev[0];
  176. var maxValue = 0;
  177. _.each(sw, function (x) {
  178. if (maxValue < x.Value) maxValue = x.Value;
  179. });
  180. //sw = sw[0];
  181. //rw = rw[0];
  182. // chart 1
  183. var EffiDataArray = [];
  184. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  185. var dataArray_Temp = [];
  186. var dataArray_Temp1 = [];
  187. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  188. _.each(sw, function (x) {
  189. dataArray_Temp.push({
  190. //DateTime: moment(x.DateTime).toDate(),
  191. DateTime: BWA.Chart.getCustermTimeArgumentAxisString($Code.TimeType.QUARTERMIN, moment(x.DateTime).toDate()),
  192. sw: x.Value //시수사용량
  193. });
  194. });
  195. _.each(lev, function (x) {
  196. dataArray_Temp1.push({
  197. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
  198. lev: x.Value
  199. });
  200. });
  201. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  202. // 배열을 하나로 합치자
  203. var array_length_size = Math.max(dataArray_Temp.length, dataArray_Temp1.length);
  204. // 크기가 동일한 경우에만 허용함 (예외 방어용)
  205. if (dataArray_Temp.length == dataArray_Temp1.length) {
  206. for (var i = 0; i < array_length_size; i++) {
  207. EffiDataArray.push(
  208. {
  209. DateTime: dataArray_Temp[i].DateTime,
  210. sw: dataArray_Temp[i].sw,
  211. lev: dataArray_Temp1[i].lev
  212. });
  213. }
  214. }
  215. dataArrayresult = EffiDataArray;
  216. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  217. //chartEffi().option('dataSource', EffiDataArray);
  218. var options = BWA.ChartOptions.WaterUAnalysis.getChartEffiOptions(timeBoxForSearch.type());
  219. //chartEffi().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
  220. options.valueAxis[0].tickInterval = Math.round(maxValue / 9 * 100) / 100;
  221. options.dataSource = EffiDataArray;
  222. chartEffi().option(options);
  223. visiblePopup(false);
  224. /* msgbox.
  225. $("#large-indicator").dxLoadIndicator({
  226. height: 60,
  227. width: 60
  228. });*/
  229. //chartTemperatureCalorie().option('dataSource', calories.concat(OUTtemperatures));
  230. //chartTemperatureElectricity2().option('dataSource', electricityDataArray.concat(OUTtemperatures));
  231. })
  232. .fail(function (error) {
  233. //alert(error);
  234. visiblePopup(false);
  235. });
  236. }
  237. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  238. function DataGridPopup_ButtonClick() {
  239. DataGridPopup_Visible(true);
  240. }
  241. function handlePopupShown() {
  242. // 데이타소스 업데이트
  243. $("#WaterUAnalysisDataGrid_Container").dxDataGrid("instance").option("dataSource", dataArrayresult);
  244. // 팝업창 갱신
  245. DataGridPopup_Visible(true);
  246. }
  247. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  248. var viewModel = $.extend(BWA.CommonView.create(
  249. params, viewInfo, searchViewOptions, ko.observable(null),
  250. handleViewShown, null, handleSearchInSearchView, undefined,
  251. chartLayout), {
  252. // facility: facilityViewModel,
  253. refreshList: refreshList,
  254. viewHidden: handleViewHidden, // hcLee 2015 06 03
  255. viewShowing: handleViewShowing,
  256. scrolling: { mode: 'infinite' },
  257. WaterUDataGridOptions: {
  258. dataSource: facilitiesForSearch,
  259. columns: [
  260. { dataField: 'Name', caption: $G('facilityName'), width: '100%', alignment: 'left' }
  261. ],
  262. filterRow: {
  263. visible: true,
  264. showOperationChooser: false
  265. },
  266. selection: {
  267. mode: 'single'
  268. },
  269. rowClick: function (clickRow) {
  270. handleSelectedFacilityInSearchView(clickRow.data);
  271. }
  272. },
  273. contentReadyAction: function (e) {
  274. datagrid = e.component;
  275. }
  276. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  277. , WaterUAnalysisDataGridPopup_ButtonClicked: DataGridPopup_ButtonClick
  278. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  279. });
  280. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  281. viewModel.WaterUAnalysisDataGridPopupOptions = {
  282. width: '480px',
  283. height: '830px', // cyim 2017.05.30 : 테스트 결과 Devextreme 버그임. px 로 지정하면 초기 출력시 정확하게 가운데에 있지만, auto 설정시 화면아래에 위치하게 됨
  284. contentTemplate: "content",
  285. showTitle: true,
  286. title: "도표",
  287. visible: DataGridPopup_Visible,
  288. dragEnabled: true,
  289. closeOnOutsideClick: true,
  290. shownAction: handlePopupShown,
  291. animation: window.utils.popup.createAnimation(),
  292. shading: false
  293. };
  294. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  295. viewModel.popupOptions = {
  296. width: 300,
  297. height: 100,
  298. contentTemplate: "info",
  299. showTitle: false,
  300. title: "메세지",
  301. visible: visiblePopup,
  302. dragEnabled: false,
  303. shading: false,
  304. closeOnOutsideClick: false
  305. };
  306. viewModel.timeBoxForSearch = timeBoxForSearch;
  307. viewModel.currentTabIndex = currentTabIndex;
  308. viewModel.multiViewItems = [{
  309. facility: facilityViewModel,
  310. template: 'mainCharts'
  311. }, {
  312. template: 'subCharts'
  313. }
  314. ];
  315. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  316. // 주석이 너무 없음. 나중에 변경 작업을 진행하는 누군가가 시간 소비를 하지 않기 위해...남김
  317. // 시간 포맷은 그래프에 귀속해야 되므로 포맷은 변경하지 않는 것이 유리함
  318. // 전기,가스,수도 와 같이 선택적으로 변경해야 된다면 아래와 같이 캡션은 고정하지 말것
  319. viewModel.WaterUAnalysisDataGridOptions = {
  320. dataSource: dataArrayresult,
  321. columns: [
  322. //{ dataField: 'Value', width: '33%', alignment: 'center', },// dataType: 'date', format: 'yyyy-MM-dd HH:mm' },
  323. { dataField: 'DateTime', caption: "날짜", width: '33%', alignment: 'center', format: 'fixedPoint', precision: 2 },
  324. { dataField: 'lev', caption: "저수조 수위", width: '33%', alignment: 'center', format: 'fixedPoint', precision: 2 },
  325. { dataField: 'sw', caption: "시수 사용량", width: '33%', alignment: 'center', format: 'fixedPoint', precision: 2 }
  326. ],
  327. // 엑셀 출력
  328. "export": {
  329. enabled: true,
  330. fileName: '저수조 성능분석'
  331. }
  332. };
  333. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  334. return viewModel;
  335. };