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();
-
-
- var DataGridPopup_Visible = ko.observable(false);
-
- var dataArrayresult = ko.observableArray();
-
- 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 }
- ]);
-
- var CODE = $Code,
- FuelType = CODE.FuelType,
- FT = CODE.FacilityType,
- FC = CODE.FacilityCode,
- F = CODE.Formula,
- TIT = CODE.TimeIntervalType;
-
-
-
-
-
-
-
-
- function handleViewShown() {
- if (initialized === false) {
- var chartOption = BWA.ChartOptions.GreenEnergy;
-
- chartElec = chartElec(chartOption.getChartElecOptions(timeBoxForSearch.type()));
- chartElecConsume = chartElecConsume(chartOption.getChartElecConsumeOptions(timeBoxForSearch.type()));
- measureSelect = measureSelect(chartOption.getMeasureSelectOptions());
- $("#measureSelect").dxSelectBox("instance").option('value', '생산량');
-
-
- 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)]
- ]);
- 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(arrayRV);
- if (_.isEmpty(arrayRV) === false) {
- var f = arrayRV[0];
- handleSelectedFacilityInSearchView(f);
- handleSearchInSearchView();
- var datagrid = $('#GreenEnergyDataGridViewInSearchView').dxDataGrid('instance');
- if (_.has(datagrid, 'selectRows')) {
- datagrid.selectRows(f);
- }
- }
- });
-
- }
- if (shouldReload) {
-
-
-
- }
- function handleViewHidden() {
- $SearchView.visibleObservable(false);
-
-
-
- }
- function handleViewShowing() {
- }
- function refreshList() {
-
-
- }
- 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();
-
-
- visiblePopup(true);
-
- 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);
- });
-
-
- $.when.apply(this, promises)
- .done(function (E1, E2, E3, E4, E5, green) {
-
- var ElecDataArray = [];
- var ElecDataArray_temp = [];
- _.each(green[0], function (x) {
- ElecDataArray.push({
-
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- kcal: x.Value,
-
- });
- });
- _.each(green[0], function (x) {
- ElecDataArray_temp.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- kcal: x.Value,
- });
- });
-
-
- dataArrayresult = ElecDataArray_temp;
- var options = BWA.ChartOptions.GreenEnergy.getChartKcalOptions(timeBoxForSearch.type());
-
-
-
-
-
- options.dataSource = ElecDataArray;
- chartElec().option(options);
- chartElecConsume().option(options);
- visiblePopup(false);
- })
- .fail(function (error) {
-
- visiblePopup(false);
- });
- }
- function handleSearchInSearchView(filter, searchViewItems) {
- console.log(filter);
- console.log(searchViewItems);
-
- var f = m_Facility.toJS();
- facilityViewModel.fromJS(f);
-
- if (m_Facility.FacilityTypeId() == $Code.FacilityType.EARTH) {
- Process7();
- return;
- }
-
- var timeIntervalType = timeBoxForSearch.type();
- var formula = $Code.Formula[$Code.FacilityType.GREEN_ENERGY];
- var formulaIds = _.values(formula);
- var date = timeBoxForSearch.getDate();
-
-
- visiblePopup(true);
-
- 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);
- });
-
-
- $.when.apply(this, promises)
- .done(function (elec) {
-
-
-
- var ElecDataArray = [];
- var ElecDataArray_temp = [];
- _.each(elec, function (x) {
- ElecDataArray.push({
-
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- elec: x.Value,
-
- });
- });
- _.each(elec, function (x) {
- ElecDataArray_temp.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- elec: x.Value,
- });
- });
-
-
- dataArrayresult = ElecDataArray_temp;
- var options = BWA.ChartOptions.GreenEnergy.getChartElecOptions(timeBoxForSearch.type());
- var optionsConsume = BWA.ChartOptions.GreenEnergy.getChartElecConsumeOptions(timeBoxForSearch.type());
-
-
-
-
-
- options.dataSource = ElecDataArray;
- optionsConsume.dataSource = ElecDataArray;
- chartElec().option(options);
- chartElecConsume().option(optionsConsume);
- visiblePopup(false);
- })
- .fail(function (error) {
-
- visiblePopup(false);
- });
- }
-
- function DataGridPopup_ButtonClick() {
- DataGridPopup_Visible(true);
- }
- function handlePopupShown() {
-
- $("#GreenEnergyDataGrid_Container").dxDataGrid("instance").option("dataSource", dataArrayresult);
-
- DataGridPopup_Visible(true);
- }
-
- var viewModel = $.extend(BWA.CommonView.create(
- params, viewInfo, searchViewOptions, ko.observable(null),
- handleViewShown, null, handleSearchInSearchView, undefined,
- chartLayout), {
-
- refreshList: refreshList,
- viewShowing: handleViewShowing,
- viewHidden: handleViewHidden,
- 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;
- }
-
- , GreenEnergyDataGridPopup_ButtonClicked: DataGridPopup_ButtonClick
-
- });
-
- viewModel.GreenEnergyDataGridPopupOptions = {
- width: '480px',
- height: '750px',
- contentTemplate: "content",
- showTitle: true,
- title: "도표",
- visible: DataGridPopup_Visible,
- dragEnabled: true,
- closeOnOutsideClick: true,
- shownAction: handlePopupShown,
- animation: window.utils.popup.createAnimation()
- };
-
- timeBoxForSearch.type($Code.TimeType.HOUR);
- viewModel.timeBoxForSearch = timeBoxForSearch;
- viewModel.currentTabIndex = currentTabIndex;
- viewModel.multiViewItems = [{
- facility: facilityViewModel,
- template: 'mainCharts',
- viewCount: 1
- },
-
- ];
- $HourGlassPopup(viewModel, visiblePopup);
-
-
-
-
- viewModel.GreenEnergyDataGridOptions = {
- dataSource: dataArrayresult,
- paging: { pageSize: 17 },
- columns: [
- { dataField: 'DateTime', caption: "날짜", width: '50%', alignment: 'center', },
- { dataField: 'elec', caption: "생산열량", width: '50%', alignment: 'center', format: 'fixedPoint', precision: 2 }
- ],
-
- "export": {
- enabled: true,
- fileName: '신재생에너지'
- }
- };
-
- return viewModel;
- };
|