| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 | 
							- BemsWebApplication.Water_HAnalysis = function (params, viewInfo) {
 
-     "use strict";
 
-     var initialized = false,
 
-         shouldReload = false,
 
-         datagrid = null,
 
-         currentTabIndex = ko.observable(0),
 
-         facilityViewModel = new BWA.CmFacilityViewModel(),
 
-         dataSource;
 
-     var m_Facility;
 
-     var multiViewItems = [{
 
-         template: 'mainCharts'
 
-     }, {
 
-         template: 'subCharts'
 
-     }
 
-     ];
 
-     var facilityDataSource = BWA.db.createDataSource('CmFacility'),
 
-         facilitiesForSearch = ko.observableArray(),
 
-         facilityCodeForSearch = ko.observable(0),
 
-         deferredForSearch = new $.Deferred();
 
-     var visiblePopup = ko.observable(false);
 
-     var dataCalorie = ko.observableArray(),
 
-         dataAtfw = ko.observableArray(),
 
-         dataTemperatureCalorie = ko.observableArray(),
 
-         dataTemperatureElectricity = ko.observableArray();
 
-     var formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId());
 
-     //var timeBoxForSearch = BWA.SearchView.createDateTimeBox();
 
-     // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
 
-     var timeBoxForSearch = BWA.SearchView.createDateTimeBox($G.TimeTypesForHourOnly, null, false);
 
-     var chartEffi = BWA.Chart.Instance('chartEffiWHA', 'dxChart');
 
-     var chartLayout = new BWA.ChartLayout({
 
-         divs: [[{
 
-             id: 'WaterHDetail'
 
-         }, {
 
-             id: 'effi',
 
-             chartId: 'chartEffiWHA'
 
-         }
 
-         ]],
 
-         multiViewOptions: {
 
-             viewIndex: currentTabIndex,
 
-             viewCount: 1
 
-         }
 
-     });
 
-     var m = moment();
 
-     //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-     // 팝업창뷰 보이기 속성 제어용 변수 선언
 
-     var DataGridPopup_Visible = ko.observable(false);
 
-     // 그래프 출력 이후 엑셀출력을 위한 팝업창을 위해 임시 저장용 배열 선언
 
-     var dataArrayresult = ko.observableArray();
 
-     //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-     dataCalorie([
 
-         { DateTime: new Date(m.year(), m.month(), 1), Value: 50 },
 
-         { DateTime: new Date(m.year(), m.month(), 2), Value: 50 },
 
-         { DateTime: new Date(m.year(), m.month(), 3), Value: 60 },
 
-         { DateTime: new Date(m.year(), m.month(), 4), Value: 80 },
 
-         { DateTime: new Date(m.year(), m.month(), 5), Value: 100 },
 
-         { DateTime: new Date(m.year(), m.month(), 6), Value: 40, },
 
-         { DateTime: new Date(m.year(), m.month(), 7), Value: 120 },
 
-         { DateTime: new Date(m.year(), m.month(), 31), Value: 120 }
 
-     ]);
 
-     // 추가 2015 04 20 hcLee ->
 
-     var CODE = $Code,
 
-     FuelType = CODE.FuelType,
 
-     FT = CODE.FacilityType,
 
-     FC = CODE.FacilityCode,
 
-     F = CODE.Formula,
 
-     TIT = CODE.TimeIntervalType;
 
-     // 추가 2015 04 20 hcLee  <-
 
-     //dataMonthForBar(dataDayForBar());
 
-     //dataDayForPie([
 
-     //    { FuelTypeName: '전기', Value: 320 },
 
-     //    { FuelTypeName: '가스', Value: 350 },
 
-     //    { FuelTypeName: '수도', Value: 360 },
 
-     //]);
 
-     //dataMonthForPie(dataDayForPie());
 
-     function handleViewShown() {
 
-         if (initialized === false) {
 
-             var chartOption = BWA.ChartOptions.WaterHAnalysis;
 
-             chartEffi = chartEffi(chartOption.getChartEffiOptions($Code.TimeType.HOUR));
 
-             initialized = true;
 
-         }
 
-         //hcLee 2016 07 12
 
-         timeBoxForSearch.setDefaultDate();
 
-         var eq = BWA.DataUtil.constructEqualFilter;
 
-         facilityDataSource.filter([
 
-             eq('SiteId', BWA.UserInfo.SiteId()),
 
-             'and',
 
-             eq('FacilityTypeId', $Code.FacilityType.WATER_H)
 
-         ]);
 
-         facilityDataSource.load().done(function (facilities) {
 
-             facilitiesForSearch(facilities);
 
-             if (_.isEmpty(facilities) === false) {
 
-                 var f = facilities[0];
 
-                 handleSelectedFacilityInSearchView(f);
 
-                 handleSearchInSearchView();
 
-                 var datagrid = $('#WaterHDataGridViewInSearchView').dxDataGrid('instance');
 
-                 if (_.has(datagrid, 'selectRows')) {
 
-                     datagrid.selectRows(f);
 
-                 }
 
-             }
 
-         });
 
-     }
 
-     if (shouldReload) {
 
-         //shouldReload = false;
 
-         //dataSource.pageIndex(0);
 
-         //dataSource.load();
 
-     }
 
-     function handleViewHidden() {
 
-         var paging = BWA.ChartLayout.Paging;
 
-         paging.sideOverlayVisible(false);
 
-         $SearchView.visibleObservable(false); // hcLee 2015 03 23
 
-         visiblePopup(false);
 
-     }
 
-     function handleViewShowing() {
 
-     }
 
-     function refreshList() {
 
-         //dataSource.pageIndex(0);
 
-         //dataSource.load();
 
-     }
 
-     var searchViewOptions = {
 
-         searchViewItems: [
 
-             { id: 'FacilityCode', ignoreValue: 0, defaultValue: 0, value: facilityCodeForSearch, dataSource: facilitiesForSearch },
 
-         ],
 
-         promiseDataInSearchView: deferredForSearch.promise()
 
-     };
 
-     function handleSelectedFacilityInSearchView(facility) {
 
-         m_Facility = facility;
 
-         return;
 
-     }
 
-     function handleSearchInSearchView(filter, searchViewItems) {
 
-         if (m_Facility == null) return;
 
-         var f = m_Facility.toJS();
 
-         facilityViewModel.fromJS(f);
 
-         //var timeIntervalType = $Code.TimeIntervalType.QUARTERMIN;
 
-         var timeIntervalType = timeBoxForSearch.type();
 
-         var formula = $Code.Formula[$Code.FacilityType.WATER_H];
 
-         var formulaIds = _.values(formula);
 
-         var date = timeBoxForSearch.getDate();
 
-         visiblePopup(true);
 
-         $("#large-indicator").dxLoadIndicator({
 
-             height: 60,
 
-             width: 60
 
-         });
 
-         //        var startDate = moment().
 
-         var promises = [];
 
-         _.each(formulaIds, function (formulaId) {
 
-             var p = formulaGet.apiGet({
 
-                 FacilityTypeId: f.FacilityTypeId,
 
-                 FacilityCode: f.FacilityCode,
 
-                 FormulaId: formulaId,
 
-                 TimeIntervalType: timeIntervalType,
 
-                 StartDate: date.startDate,
 
-                 EndDate: date.endDate
 
-             });
 
-             promises.push(p);
 
-         });
 
-         /*
 
-                 // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20  ->
 
-                 var commonParameters = {
 
-                     TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
 
-                     StartDate: date.startDate,
 
-                     EndDate: date.endDate
 
-                 };
 
-                 var temperatureParameters = {
 
-                     FacilityTypeId: FT.OUTDOOR,
 
-                     FacilityCode: FC.OUTDOOR,
 
-                     FormulaId: F[FT.OUTDOOR].TEMPERATURE,
 
-                 };
 
-                 promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)));
 
-         */  // 보일러는 필요 없다
 
-         $.when.apply(this, promises)
 
-         .done(function (sw, hw, lev) {
 
-             sw = sw[0];
 
-             hw = hw[0];
 
-             lev = lev[0];
 
-             var maxValue = 0;
 
-             _.each(sw, function (x) {
 
-                 if (maxValue < x.Value) maxValue = x.Value;
 
-             });
 
-             _.each(hw, function (x) {
 
-                 if (maxValue < x.Value) maxValue = x.Value;
 
-             });
 
-             // chart 1
 
-             var EffiDataArray = [];
 
-             //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-             var dataArray_Temp = [];
 
-             var dataArray_Temp1 = [];
 
-             var dataArray_Temp2 = [];
 
-             //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-             _.each(sw, function (x) {
 
-                 dataArray_Temp.push({
 
-                     //DateTime: moment(x.DateTime).toDate(),
 
-                     DateTime: BWA.Chart.getCustermTimeArgumentAxisString($Code.TimeType.QUARTERMIN, moment(x.DateTime).toDate()),
 
-                     sw: x.Value //보충
 
-                 });
 
-             });
 
-             _.each(hw, function (x) {
 
-                 dataArray_Temp1.push({
 
-                     //DateTime: moment(x.DateTime).toDate(),
 
-                     DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
 
-                     hw: x.Value //중수
 
-                 });
 
-             });
 
-             _.each(lev, function (x) {
 
-                 dataArray_Temp2.push({
 
-                     DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
 
-                     lev: x.Value //수위
 
-                 });
 
-             });
 
-             //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-             // 배열을 하나로 합치자  
 
-             var array_length_size = Math.max(dataArray_Temp.length, dataArray_Temp1.length, dataArray_Temp2.length);
 
-             // 크기가 동일한 경우에만 허용함 (예외 방어용)
 
-             if ((dataArray_Temp.length == dataArray_Temp1.length) && (dataArray_Temp.length == dataArray_Temp2.length)) {
 
-                 for (var i = 0; i < array_length_size; i++) {
 
-                     EffiDataArray.push(
 
-                         {
 
-                             DateTime: dataArray_Temp[i].DateTime,
 
-                             sw: dataArray_Temp[i].sw,
 
-                             hw: dataArray_Temp1[i].hw,
 
-                             lev: dataArray_Temp2[i].lev
 
-                         });
 
-                 }
 
-             }
 
-             dataArrayresult = EffiDataArray;
 
-             //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-             //chartEffi().option('dataSource', EffiDataArray);
 
-             var options = BWA.ChartOptions.WaterHAnalysis.getChartEffiOptions(timeBoxForSearch.type());
 
-             options.valueAxis[0].tickInterval = Math.round(maxValue / 9 * 100) / 100;
 
-             //options.valueAxis[0].tickInterval = maxValue / 10;
 
-             //chartEffi().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
 
-             options.dataSource = EffiDataArray;
 
-             chartEffi().option(options);
 
-             visiblePopup(false);
 
-             /*            msgbox.
 
-                         $("#large-indicator").dxLoadIndicator({
 
-                             height: 60,
 
-                             width: 60
 
-                         });*/
 
-             //chartTemperatureCalorie().option('dataSource', calories.concat(OUTtemperatures));
 
-             //chartTemperatureElectricity2().option('dataSource', electricityDataArray.concat(OUTtemperatures));
 
-         })
 
-         .fail(function (error) {
 
-             //alert(error);
 
-             visiblePopup(false);
 
-         });
 
-     }
 
-     //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-     function DataGridPopup_ButtonClick() {
 
-         DataGridPopup_Visible(true);
 
-     }
 
-     function handlePopupShown() {
 
-         // 데이타소스 업데이트
 
-         $("#WaterHAnalysisDataGrid_Container").dxDataGrid("instance").option("dataSource", dataArrayresult);
 
-         // 팝업창 갱신
 
-         DataGridPopup_Visible(true);
 
-     }
 
-     //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-     var viewModel = $.extend(BWA.CommonView.create(
 
-             params, viewInfo, searchViewOptions, ko.observable(null),
 
-             handleViewShown, null, handleSearchInSearchView, undefined,
 
-             chartLayout), {
 
-                 //        facility: facilityViewModel,
 
-                 refreshList: refreshList,
 
-                 viewHidden: handleViewHidden, // hcLee 2015 06 03
 
-                 viewShowing: handleViewShowing,
 
-                 scrolling: { mode: 'infinite' },
 
-                 WaterHDataGridOptions: {
 
-                     dataSource: facilitiesForSearch,
 
-                     columns: [
 
-                         { dataField: 'Name', caption: $G('facilityName'), width: '100%', alignment: 'left' }
 
-                     ],
 
-                     filterRow: {
 
-                         visible: true,
 
-                         showOperationChooser: false
 
-                     },
 
-                     selection: {
 
-                         mode: 'single'
 
-                     },
 
-                     rowClick: function (clickRow) {
 
-                         handleSelectedFacilityInSearchView(clickRow.data);
 
-                     }
 
-                 },
 
-                 contentReadyAction: function (e) {
 
-                     datagrid = e.component;
 
-                 }
 
-                 //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-         , WaterHAnalysisDataGridPopup_ButtonClicked: DataGridPopup_ButtonClick
 
-                 //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-             });
 
-     //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-     viewModel.WaterHAnalysisDataGridPopupOptions = {
 
-         width: '550px',
 
-         height: '830px', // cyim 2017.05.30 : 테스트 결과 Devextreme 버그임. px 로 지정하면 초기 출력시 정확하게 가운데에 있지만, auto 설정시 화면아래에 위치하게 됨
 
-         contentTemplate: "content",
 
-         showTitle: true,
 
-         title: "도표",
 
-         visible: DataGridPopup_Visible,
 
-         dragEnabled: true,
 
-         closeOnOutsideClick: true,
 
-         shownAction: handlePopupShown,
 
-         animation: window.utils.popup.createAnimation(),
 
-         shading: false
 
-     };
 
-     //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-     viewModel.popupOptions = {
 
-         width: 300,
 
-         height: 100,
 
-         contentTemplate: "info",
 
-         showTitle: false,
 
-         title: "메세지",
 
-         visible: visiblePopup,
 
-         dragEnabled: false,
 
-         shading: false,
 
-         closeOnOutsideClick: false
 
-     };
 
-     viewModel.timeBoxForSearch = timeBoxForSearch;
 
-     viewModel.currentTabIndex = currentTabIndex;
 
-     viewModel.multiViewItems = [{
 
-         facility: facilityViewModel,
 
-         template: 'mainCharts'
 
-     }, {
 
-         template: 'subCharts'
 
-     }
 
-     ];
 
-     //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-     // 주석이 너무 없음. 나중에 변경 작업을 진행하는 누군가가 시간 소비를 하지 않기 위해...남김
 
-     // 시간 포맷은 그래프에 귀속해야 되므로 포맷은 변경하지 않는 것이 유리함
 
-     // 전기,가스,수도 와 같이 선택적으로 변경해야 된다면 아래와 같이 캡션은 고정하지 말것
 
-     viewModel.WaterHAnalysisDataGridOptions = {
 
-         dataSource: dataArrayresult,
 
-         columns: [           
 
-             { dataField: 'DateTime', caption: "날짜", width: '40%', alignment: 'center', format: 'fixedPoint', precision: 2 },
 
-              { dataField: 'lev', caption: "중수조 수위", width: '30%', alignment: 'center', format: 'fixedPoint', precision: 2 },
 
-             { dataField: 'hw', caption: "중수 사용량", width: '30%', alignment: 'center', format: 'fixedPoint', precision: 2 },
 
-             { dataField: 'sw', caption: "보충 시수량", width: '30%', alignment: 'center', format: 'fixedPoint', precision: 2 }
 
-         ],
 
-         // 엑셀 출력
 
-         "export": {
 
-             enabled: true,
 
-             fileName: '중수조 성능분석'
 
-         }
 
-     };
 
-     //  2017.09.08 : 그리드 도표 작업 : 팝업창 추가
 
-     return viewModel;
 
- };
 
 
  |