123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- BemsWebApplication.GreenEnergy = function (params, viewInfo) {
- "use strict";
- var factorCo2 = null;
- var factorCo2DataSource = BemsWebApplication.db.createDataSource('BemsFactorCo2');
- var factorToe = null;
- var factorToeDataSource = BemsWebApplication.db.createDataSource('BemsFactorToe');
- var initialized = false,
- shouldReload = false,
- datagrid = null,
- currentTabIndex = ko.observable(0),
- facilityViewModel = new BWA.CmFacilityViewModel(),
- dataSource;
- 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 m_Facility;
- 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();
- var chartElec = BWA.Chart.Instance('chartGreenElec', 'dxChart');
- var chartElecConsume = BWA.Chart.Instance('chartGreenElecConsume', 'dxChart');
- var measureSelect = BWA.Chart.Instance('measureSelect', 'dxSelectBox');
- var chartLayout = new BWA.ChartLayout({
- divs: [{
- id: 'GreenEnergyDetail'
- }, {
- id: 'elec',
- chartId: 'chartGreenElec'
- }, {
- id: 'elec',
- chartId: 'chartGreenElecConsume'
- },
- {
- id: 'elec',
- chartId: 'measureSelect'
- }
- ],
- multiViewOptions: {
- viewIndex: currentTabIndex,
- viewCount: 1,
- swipeEnabled: false,
- }
- });
- var m = moment();
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- // 팝업창뷰 보이기 속성 제어용 변수 선언
- var DataGridPopup_Visible = ko.observable(false);
- // 그래프 출력 이후 엑셀출력을 위한 팝업창을 위해 임시 저장용 배열 선언
- var dataArrayresult = ko.observableArray();
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- 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.GreenEnergy;
- //chartElec = chartElec(chartOption.getChartElecOptions($Code.TimeType.HOUR));
- chartElec = chartElec(chartOption.getChartElecOptions(timeBoxForSearch.type()));
- chartElecConsume = chartElecConsume(chartOption.getChartElecConsumeOptions(timeBoxForSearch.type()));
- measureSelect = measureSelect(chartOption.getMeasureSelectOptions());
- $("#measureSelect").dxSelectBox("instance").option('value', '생산량');
- //$("#chartGreenElecConsume").hide();
- //var options = BWA.ChartOptions.GreenEnergy.getChartElecOptions(timeBoxForSearch.type());
- initialized = true;
- }
- var eq = BWA.DataUtil.constructEqualFilter;
- facilityDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- [eq('FacilityTypeId', $Code.FacilityType.GREEN_ENERGY), 'or', eq('FacilityTypeId', 22)] // GREEN_ENERGY -> 22(신재생 발전)
- ]);
- var whenPromise = $.when(factorCo2DataSource.load(), facilityDataSource.load(), factorToeDataSource.load())
- .then(function (dbfactorsCo2, facilities, dbfactorsToe) {
- factorCo2 = BWA.Bems.refineFactorCo2DataArray(dbfactorsCo2[0]);
- factorToe = BWA.Bems.refineFactorToeDataArray(dbfactorsToe[0]);
- var arrayRV = [];
- for (var i = facilities[0].length - 1; i >= 0; i--)
- arrayRV.push(facilities[0][i])
- //facilitiesForSearch(facilities[0]);
- //if (_.isEmpty(facilities[0]) === false) {
- facilitiesForSearch(arrayRV);
- if (_.isEmpty(arrayRV) === false) {
- var f = arrayRV[0];
- handleSelectedFacilityInSearchView(f);
- handleSearchInSearchView();
- var datagrid = $('#GreenEnergyDataGridViewInSearchView').dxDataGrid('instance');
- if (_.has(datagrid, 'selectRows')) {
- datagrid.selectRows(f);
- }
- }
- });
- /*
- facilityDataSource.load().done(function(facilities) {
- facilitiesForSearch(facilities);
- if (_.isEmpty(facilities) === false) {
- var f = facilities[0];
-
- handleSelectedFacilityInSearchView(f);
- handleSearchInSearchView();
-
- var datagrid = $('#GreenEnergyDataGridViewInSearchView').dxDataGrid('instance');
- if (_.has(datagrid, 'selectRows')) {
- datagrid.selectRows(f);
- }
- }
- });*/
- }
- if (shouldReload) {
- //shouldReload = false;
- //dataSource.pageIndex(0);
- //dataSource.load();
- }
- function handleViewHidden() {
- $SearchView.visibleObservable(false); // hcLee 2015 03 23
- //hideOverlay();
- // var dataGrid = $('#gridContainer').dxDataGrid('instance');
- // dataGrid.clearSelection();
- }
- 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 Process7() {
- var f = m_Facility.toJS();
- facilityViewModel.fromJS(f);
- var timeIntervalType = timeBoxForSearch.type();
- var formula = $Code.Formula[$Code.FacilityType.EARTH];
- var formulaIds = _.values(formula);
- var date = timeBoxForSearch.getDate();
- //utils.toast.displayTime=1000000;
- //utils.toast.show('공조기 성능분석 중 입니다. 잠시만 기다려 주세요');
- visiblePopup(true);
- // 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 (E1, E2, E3, E4, E5, green) {
- // chart 1
- var ElecDataArray = [];
- var ElecDataArray_temp = [];
- _.each(green[0], function (x) {
- ElecDataArray.push({
- //DateTime: moment(x.DateTime).toDate(),
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- kcal: x.Value,
- //co2: factorCo2.calculate((x.Value / factorToe[$Code.FuelType.GAS].KCAL), $Code.FuelType.GAS) * 1000, // 2016 04 12 추가
- });
- });
- _.each(green[0], function (x) {
- ElecDataArray_temp.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- kcal: x.Value,
- });
- });
- //chartElec().option('dataSource', ElecDataArray);
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- dataArrayresult = ElecDataArray_temp;
- var options = BWA.ChartOptions.GreenEnergy.getChartKcalOptions(timeBoxForSearch.type());
- //chartElec().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
- //chart().cle
- //chart().option(null);
- //options.dataSource = null;
- //chart().option(options);
- options.dataSource = ElecDataArray;
- chartElec().option(options);
- chartElecConsume().option(options);
- visiblePopup(false);
- })
- .fail(function (error) {
- //alert(error);
- visiblePopup(false);
- });
- }
- function handleSearchInSearchView(filter, searchViewItems) {
- console.log(filter);
- console.log(searchViewItems);
- //alert(m_Facility.FacilityTypeId());
- var f = m_Facility.toJS();
- facilityViewModel.fromJS(f);
- // 지열시스템은 아래 함수에서 리턴
- if (m_Facility.FacilityTypeId() == $Code.FacilityType.EARTH) {
- Process7();
- return;
- }
- //var timeIntervalType = $Code.TimeIntervalType.HOUR;
- var timeIntervalType = timeBoxForSearch.type();
- var formula = $Code.Formula[$Code.FacilityType.GREEN_ENERGY];
- var formulaIds = _.values(formula);
- var date = timeBoxForSearch.getDate();
- //utils.toast.displayTime=1000000;
- //utils.toast.show('공조기 성능분석 중 입니다. 잠시만 기다려 주세요');
- visiblePopup(true);
- // 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 (elec) {
- //sw = sw[0];
- //rw = rw[0];
- // chart 1
- var ElecDataArray = [];
- var ElecDataArray_temp = [];
- _.each(elec, function (x) {
- ElecDataArray.push({
- //DateTime: moment(x.DateTime).toDate(),
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- elec: x.Value,
- //co2: factorCo2.calculate(x.Value, $Code.FuelType.ELECTRICITY) * 1000,
- });
- });
- _.each(elec, function (x) {
- ElecDataArray_temp.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- elec: x.Value,
- });
- });
- //chartElec().option('dataSource', ElecDataArray);
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- dataArrayresult = ElecDataArray_temp;
- var options = BWA.ChartOptions.GreenEnergy.getChartElecOptions(timeBoxForSearch.type());
- var optionsConsume = BWA.ChartOptions.GreenEnergy.getChartElecConsumeOptions(timeBoxForSearch.type());
- //chartElec().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
- //chart().cle
- //chart().option(null);
- //options.dataSource = null;
- //chart().option(options);
- options.dataSource = ElecDataArray;
- optionsConsume.dataSource = ElecDataArray;
- chartElec().option(options);
- chartElecConsume().option(optionsConsume);
- visiblePopup(false);
- })
- .fail(function (error) {
- //alert(error);
- visiblePopup(false);
- });
- }
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- function DataGridPopup_ButtonClick() {
- DataGridPopup_Visible(true);
- }
- function handlePopupShown() {
- // 데이타소스 업데이트
- $("#GreenEnergyDataGrid_Container").dxDataGrid("instance").option("dataSource", dataArrayresult);
- // 팝업창 갱신
- DataGridPopup_Visible(true);
- }
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- var viewModel = $.extend(BWA.CommonView.create(
- params, viewInfo, searchViewOptions, ko.observable(null),
- handleViewShown, null, handleSearchInSearchView, undefined,
- chartLayout), {
- // facility: facilityViewModel,
- refreshList: refreshList,
- viewShowing: handleViewShowing,
- viewHidden: handleViewHidden, // hcLee 2015 03 23
- scrolling: { mode: 'infinite' },
- GreenEnergyDataGridOptions_menu: {
- 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.11 : 그리드 도표 작업 : 팝업창 추가
- , GreenEnergyDataGridPopup_ButtonClicked: DataGridPopup_ButtonClick
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- });
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- viewModel.GreenEnergyDataGridPopupOptions = {
- width: '480px',
- height: '750px', // 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()
- };
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- timeBoxForSearch.type($Code.TimeType.HOUR);
- viewModel.timeBoxForSearch = timeBoxForSearch;
- viewModel.currentTabIndex = currentTabIndex;
- viewModel.multiViewItems = [{
- facility: facilityViewModel,
- template: 'mainCharts',
- viewCount: 1
- },
- /*{
- template: 'subCharts'
- }*/
- ];
- $HourGlassPopup(viewModel, visiblePopup);
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- // 주석이 너무 없음. 나중에 변경 작업을 진행하는 누군가가 시간 소비를 하지 않기 위해...남김
- // 시간 포맷은 그래프에 귀속해야 되므로 포맷은 변경하지 않는 것이 유리함
- // 전기,가스,수도 와 같이 선택적으로 변경해야 된다면 아래와 같이 캡션은 고정하지 말것
- viewModel.GreenEnergyDataGridOptions = {
- dataSource: dataArrayresult,
- paging: { pageSize: 17 },
- columns: [
- { dataField: 'DateTime', caption: "날짜", width: '50%', alignment: 'center', },// dataType: 'date', format: 'yyyy-MM-dd HH:mm' },
- { dataField: 'elec', caption: "생산열량", width: '50%', alignment: 'center', format: 'fixedPoint', precision: 2 }
- ],
- // 엑셀 출력
- "export": {
- enabled: true,
- fileName: '신재생에너지'
- }
- };
- // 2017.09.11 : 그리드 도표 작업 : 팝업창 추가
- return viewModel;
- };
|