a7a094fdd8f6887dbb578c102b31b35e8b0101c6.svn-base 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. BemsWebApplication.RealtimeEnergyConsumption = function (params, viewInfo) {
  2. "use strict";
  3. var BUILDING_DEPTH = 1,
  4. FLOOR_DEPTH = 2,
  5. ZONE_DEPTH = 3;
  6. var CODE = $Code,
  7. FuelType = CODE.FuelType,
  8. FT = CODE.FacilityType,
  9. FC = CODE.FacilityCode,
  10. F = CODE.Formula,
  11. TIT = CODE.TimeIntervalType;
  12. var checkBox_value = true, checkBox_temperature = true, checkBox_humidity = true; // 수정
  13. var visiblePopup = ko.observable(false);
  14. var timer;
  15. var initialized = false,
  16. shouldReload = false,
  17. dataSource;
  18. var pointHistoryGet = new BWA.Chart.PointHistoryGet(BWA.UserInfo.SiteId()),
  19. formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId());
  20. //var buildingDataSource = BemsWebApplication.db.createDataSource('CmBuilding', true, true),
  21. var buildingDataSource = BemsWebApplication.db.createDataSource('CmBuilding', [('SiteId', '=', BWA.UserInfo.SiteId())]),
  22. floorDataSource = BemsWebApplication.db.createDataSource('CmFloor'),
  23. zoneDataSource = BemsWebApplication.db.createDataSource('CmZone'),
  24. fuelTypesDataSource = BemsWebApplication.db.createDataSource('BemsFuelType'),
  25. //check_input = ko.observable(false),
  26. //check_input2 = ko.observable(false),
  27. buildings = ko.observableArray(),
  28. floorsForSearch = ko.observableArray(),
  29. zonesForSearch = ko.observableArray(),
  30. fuelTypesForSearch = ko.observableArray(),
  31. buildingIdForSearch = ko.observable(),
  32. buildingNameForSearch = ko.observable(),
  33. floorIdForSearch = ko.observable(),
  34. floorNameForSearch = ko.observable(),
  35. zoneIdForSearch = ko.observable(),
  36. zoneNameForSearch = ko.observable(),
  37. fuelTypeIdForSearch = ko.observable(),
  38. deferredForSearch = new $.Deferred();
  39. var deferredForLoadData = new $.Deferred();
  40. var chart = BWA.Chart.Instance('chartRT', 'dxChart');
  41. var locationEnableForSearch = ko.observable(true);
  42. var chartDataArray = ko.observableArray();
  43. var value_name; //추가
  44. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  45. // 팝업창뷰 보이기 속성 제어용 변수 선언
  46. var DataGridPopup_Visible = ko.observable(false);
  47. // 그래프 출력 이후 엑셀출력을 위한 팝업창을 위해 임시 저장용 배열 선언
  48. var dataArrayresult = ko.observableArray();
  49. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  50. chartDataArray([
  51. { DateTime: new Date(2014, 11, 16, 0), OutdoorTemperature: -3.4, OutdoorHumidity: 40, Value: 30 },
  52. { DateTime: new Date(2014, 11, 16, 0, 15), OutdoorTemperature: -1.1, OutdoorHumidity: 44, Value: 32 },
  53. { DateTime: new Date(2014, 11, 16, 0, 30), OutdoorTemperature: 3, OutdoorHumidity: 48, Value: 33 },
  54. { DateTime: new Date(2014, 11, 16, 0, 45), OutdoorTemperature: 4, OutdoorHumidity: 55, Value: 34 },
  55. { DateTime: new Date(2014, 11, 16, 1), OutdoorTemperature: 8, OutdoorHumidity: 54, Value: 50 },
  56. { DateTime: new Date(2014, 11, 16, 2), OutdoorTemperature: 10, OutdoorHumidity: 53, Value: 60 },
  57. { DateTime: new Date(2014, 11, 16, 3), OutdoorTemperature: 11, Value: 80 },
  58. { DateTime: new Date(2014, 11, 16, 4), OutdoorTemperature: 12, OutdoorHumidity: 48, Value: 100 },
  59. { DateTime: new Date(2014, 11, 16, 5), OutdoorTemperature: 12, OutdoorHumidity: 40 },
  60. { DateTime: new Date(2014, 11, 16, 6), Value: 120 }
  61. ]);
  62. var goalUpperBound = ko.observable(40);
  63. function handleClickTreeItem(element, data) {
  64. var eq = BWA.DataUtil.constructEqualFilter;
  65. var depth = data.depth;
  66. //data = data.data;
  67. switch (depth) {
  68. case BUILDING_DEPTH: // building
  69. data = data.data;
  70. buildingIdForSearch(data.BuildingId());
  71. buildingNameForSearch(data.Name());
  72. floorIdForSearch(null);
  73. floorNameForSearch('');
  74. zoneIdForSearch(null);
  75. zoneNameForSearch('');
  76. break;
  77. case FLOOR_DEPTH: // floor
  78. buildingNameForSearch(data.parentData.data.Name());
  79. //alert(buildingIdForSearch());
  80. data = data.data;
  81. buildingIdForSearch(data.BuildingId());
  82. floorIdForSearch(data.FloorId());
  83. floorNameForSearch(data.Name());
  84. zoneIdForSearch(null);
  85. zoneNameForSearch('');
  86. break;
  87. case ZONE_DEPTH: // zone
  88. floorNameForSearch(data.parentData.data.Name());
  89. buildingNameForSearch(data.parentData.parentData.data.Name());
  90. data = data.data;
  91. buildingIdForSearch(data.BuildingId());
  92. //alert(buildingIdForSearch());
  93. //buildingNameForSearch(data.Name());
  94. floorIdForSearch(data.FloorId());
  95. //alert(floorIdForSearch());
  96. //floorNameForSearch(data.parent.data.Name());
  97. zoneIdForSearch(data.ZoneId());
  98. zoneNameForSearch(data.Name());
  99. break;
  100. }
  101. }
  102. function handleSearchViewInitializeUpdate() {
  103. //alert('handleSearchViewInitializeUpdate');
  104. $('#locationTreeViewInSearchView1').cwTreeView({
  105. width: '40%',
  106. height: '100%',
  107. onClickTreeItem: handleClickTreeItem,
  108. delegateDataSource: BWA.DataUtil.getLocationDataSourceDelegateForTreeView(
  109. buildingDataSource,
  110. floorDataSource,
  111. zoneDataSource
  112. )
  113. });
  114. }
  115. function handleViewShown() {
  116. //alert('handleViewShown'); // 2
  117. switch (fuelTypeIdForSearch()) {
  118. case $Code.FuelType.ELECTRICITY:
  119. goalUpperBound(500000);
  120. value_name = "전기";//추가
  121. break;
  122. case $Code.FuelType.GAS:
  123. goalUpperBound(180);
  124. value_name = "가스";
  125. break;
  126. case $Code.FuelType.WATER:
  127. goalUpperBound(40);
  128. value_name = "수도";
  129. break;
  130. }
  131. if (initialized === false) {
  132. //alert('handleViewShown1'); // 3
  133. chart = chart(BWA.ChartOptions.RealtimeEnergyConsumption.getChartOptions($Code.TimeType.QUARTERMIN, goalUpperBound));
  134. //chart = chart(BWA.ChartOptions.RealtimeEnergyConsumption.getSeriesOptions($Code.TimeType.QUARTERMIN, goalUpperBound));
  135. floorNameForSearch('');
  136. zoneNameForSearch('');
  137. check_button();//추가
  138. initialized = true;
  139. }
  140. if (shouldReload) {
  141. //shouldReload = false;
  142. //dataSource.pageIndex(0);
  143. //dataSource.load();
  144. }
  145. timer = setInterval(function () {
  146. //alert('timer'); // For Debugging
  147. var now = new Date();
  148. if ((now.getMinutes() % 15 == 0) && (now.getSeconds() == 58)) {
  149. //alert('timer'); // For Debugging
  150. handleSearchInSearchView();
  151. }
  152. }, 1000);
  153. }
  154. function check_button() { //추가
  155. $("#checkBox_value").dxCheckBox({
  156. text: (value_name == "전기") ? "전기" : ((value_name == '수도') ? "수도" : "가스"),
  157. value: true,
  158. onValueChanged: function (e) {
  159. switch (e.value) {
  160. case true:
  161. checkBox_value = true;
  162. break;
  163. case false:
  164. checkBox_value = false;
  165. break;
  166. }
  167. Data_fliter();
  168. }
  169. });
  170. $("#checkBox_temperature").dxCheckBox({
  171. text: "온도",
  172. value: true,
  173. onValueChanged: function (e) {
  174. switch (e.value) {
  175. case true:
  176. checkBox_temperature = true;
  177. break;
  178. case false:
  179. checkBox_temperature = false;
  180. break;
  181. }
  182. Data_fliter();
  183. }
  184. });
  185. $("#checkBox_humidity").dxCheckBox({
  186. text: "습도",
  187. value: true,
  188. onValueChanged: function (e) {
  189. switch (e.value) {
  190. case true:
  191. checkBox_humidity = true;
  192. break;
  193. case false:
  194. checkBox_humidity = false;
  195. break;
  196. }
  197. Data_fliter();
  198. }
  199. });
  200. }
  201. function Data_fliter() {//추가
  202. visiblePopup(true);
  203. var dataArray = [];
  204. var commonParameters = {
  205. TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
  206. StartDate: moment().startOf('day'),
  207. EndDate: moment()
  208. };
  209. var pointHistoryParameters = {
  210. BuildingId: buildingIdForSearch(),
  211. FloorId: floorIdForSearch(),
  212. ZoneId: zoneIdForSearch(),
  213. FuelTypeId: fuelTypeIdForSearch()
  214. };
  215. var temperatureParameters = {
  216. FacilityTypeId: FT.OUTDOOR,
  217. FacilityCode: FC.OUTDOOR,
  218. FormulaId: F[FT.OUTDOOR].TEMPERATURE,
  219. };
  220. var humidityParameters = _.extend({}, temperatureParameters, {
  221. FormulaId: F[FT.OUTDOOR].HUMIDITY,
  222. });
  223. $.when(
  224. pointHistoryGet.apiGet(_.extend(pointHistoryParameters, commonParameters)),
  225. formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)),
  226. formulaGet.apiGet(_.extend(humidityParameters, commonParameters)))
  227. .done(function (values, temperatures, humidities) {
  228. var maxValue = 0;
  229. var dataArray_Temp = [];
  230. var dataArray_Temp1 = [];
  231. var dataArray_Temp2 = [];
  232. var dataArray_Temp3 = [];
  233. if (checkBox_value) {//1
  234. if (checkBox_temperature) {//2
  235. if (checkBox_humidity) {//5
  236. value_input(values);
  237. temperatures_input(temperatures);
  238. humidities_input(humidities);
  239. }
  240. else {
  241. value_input(values);
  242. temperatures_input(temperatures);
  243. }
  244. }
  245. else {
  246. if (checkBox_humidity) {//1,5
  247. value_input(values);
  248. humidities_input(humidities);
  249. }
  250. else {
  251. value_input(values);
  252. }
  253. }
  254. }
  255. else {
  256. if (checkBox_temperature) {//2
  257. if (checkBox_humidity) {//5
  258. temperatures_input(temperatures);
  259. humidities_input(humidities);
  260. }
  261. else {
  262. temperatures_input(temperatures);
  263. }
  264. }
  265. else {
  266. if (checkBox_humidity) {//5
  267. humidities_input(humidities);
  268. }
  269. else {
  270. }
  271. }
  272. }
  273. function value_input(values) {
  274. _.each(values[0], function (x) {
  275. dataArray.push({
  276. DateTime: moment(x.DateTime).toDate(),
  277. Value: x.Value
  278. });
  279. });
  280. }
  281. function temperatures_input(temperatures) {
  282. if (temperatures[0].length > 0) { // 2017 02 17
  283. if (temperatures[0][temperatures[0].length - 1].Value == 0 && humidities[0][humidities[0].length - 1].Value == 0 &&
  284. temperatures[0][temperatures[0].length - 1].DateTime == humidities[0][humidities[0].length - 1].DateTime) {
  285. temperatures[0].splice(temperatures[0].length - 1, 1);
  286. humidities[0].splice(humidities[0].length - 1, 1);
  287. }
  288. }
  289. _.each(temperatures[0], function (x) {
  290. dataArray.push({
  291. DateTime: moment(x.DateTime).toDate(),
  292. Temperature: x.Value
  293. });
  294. });
  295. }
  296. function humidities_input(humidities) {
  297. _.each(humidities[0], function (x) {
  298. dataArray.push({
  299. DateTime: moment(x.DateTime).toDate(),
  300. Humidity: x.Value
  301. })
  302. });
  303. }
  304. switch (fuelTypeIdForSearch()) {
  305. case $Code.FuelType.ELECTRICITY:
  306. goalUpperBound(500000);
  307. value_name = "전기";
  308. break;
  309. case $Code.FuelType.GAS:
  310. goalUpperBound(180);
  311. value_name = "가스";
  312. break;
  313. case $Code.FuelType.WATER:
  314. goalUpperBound(40);
  315. value_name = "수도";
  316. break;
  317. }
  318. var options = BWA.ChartOptions.RealtimeEnergyConsumption.getSeriesOptions(
  319. fuelTypeIdForSearch(), goalUpperBound()
  320. );
  321. options.valueAxis[1].min = -19;
  322. options.valueAxis[1].max = 39;
  323. options.valueAxis[2].max = 100;
  324. options.valueAxis[2].min = 0;
  325. options.dataSource = dataArray;
  326. chart().option(options);
  327. $('#st').text('에너지 사용량 트랜드' + " : " + buildingNameForSearch() + " - " +
  328. floorNameForSearch() + " - " + zoneNameForSearch());
  329. visiblePopup(false);
  330. })
  331. .fail(function (error) {
  332. visiblePopup(false);
  333. });
  334. }
  335. function handleViewHidden() {
  336. $SearchView.visibleObservable(false); // hcLee 2015 03 23
  337. //alert('1');
  338. // $SearchView.hide(); // hcLee 2015 03 23
  339. //$SearchView.toggleSearchView();
  340. //$SearchView.toggleSearchView();
  341. visiblePopup(false);
  342. //if ($SearchView.visibleObservable()) $SearchView.toggleSearchView();
  343. clearInterval(timer); // hcLee 2015 06 12
  344. //hideOverlay();
  345. // var dataGrid = $('#gridContainer').dxDataGrid('instance');
  346. // dataGrid.clearSelection();
  347. }
  348. function handleViewShowing() {
  349. //alert('handleViewShowing'); // 1
  350. $.when(fuelTypesDataSource.load(), buildingDataSource.load()).done(function (fuelTypes, dbBuildings) {
  351. //handleSearchViewInitializeUpdate();
  352. fuelTypes = fuelTypes[0];
  353. dbBuildings = dbBuildings[0];
  354. fuelTypesForSearch(_.rest(fuelTypes));
  355. deferredForSearch.resolve();
  356. if (_.isEmpty(dbBuildings) === false) {
  357. buildingIdForSearch(dbBuildings[0].BuildingId());
  358. buildingNameForSearch(dbBuildings[0].Name());
  359. handleSearchInSearchView();
  360. }
  361. });
  362. }
  363. function refreshList() {
  364. //dataSource.pageIndex(0);
  365. //dataSource.load();
  366. }
  367. var searchViewOptions = {
  368. searchViewItems: [
  369. { id: 'FuelTypeId', ignoreValue: 0, defaultValue: $Code.FuelType.ELECTRICITY, value: fuelTypeIdForSearch, dataSource: fuelTypesForSearch }
  370. ],
  371. promiseDataInSearchView: deferredForSearch.promise()
  372. };
  373. function handleSearchInSearchView() {
  374. visiblePopup(true);
  375. var dataArray = [];
  376. //document.getElementById('header').innerHTML = '기다려';
  377. /*$("#large-indicator").dxLoadIndicator({
  378. height: 60,
  379. width: 60
  380. });*/
  381. //alert('handleSearchInSearchView');
  382. var commonParameters = {
  383. TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
  384. StartDate: moment().startOf('day'),
  385. EndDate: moment()
  386. };
  387. //commonParameters.EndDate._d = commonParameters.EndDate._d.getMinutes() + 1;
  388. var pointHistoryParameters = {
  389. BuildingId: buildingIdForSearch(),
  390. FloorId: floorIdForSearch(),
  391. ZoneId: zoneIdForSearch(),
  392. FuelTypeId: fuelTypeIdForSearch()
  393. };
  394. var temperatureParameters = {
  395. FacilityTypeId: FT.OUTDOOR,
  396. FacilityCode: FC.OUTDOOR,
  397. FormulaId: F[FT.OUTDOOR].TEMPERATURE,
  398. };
  399. var humidityParameters = _.extend({}, temperatureParameters, {
  400. FormulaId: F[FT.OUTDOOR].HUMIDITY,
  401. });
  402. $.when(
  403. //pointHistoryGet.apiGet(_.extend(pointHistoryParameters, commonParameters)))
  404. pointHistoryGet.apiGet(_.extend(pointHistoryParameters, commonParameters)),
  405. formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)),
  406. formulaGet.apiGet(_.extend(humidityParameters, commonParameters)))
  407. .done(function (values, temperatures, humidities) {
  408. var maxValue = 0;
  409. var dataArray_Temp = [];
  410. var dataArray_Temp1 = [];
  411. var dataArray_Temp2 = [];
  412. var dataArray_Temp3 = [];
  413. _.each(values[0], function (x) {
  414. dataArray.push({
  415. DateTime: moment(x.DateTime).toDate(),
  416. Value: x.Value
  417. });
  418. });
  419. if (temperatures[0].length > 0) { // 2017 02 17
  420. if (temperatures[0][temperatures[0].length - 1].Value == 0 && humidities[0][humidities[0].length - 1].Value == 0 &&
  421. temperatures[0][temperatures[0].length - 1].DateTime == humidities[0][humidities[0].length - 1].DateTime) {
  422. temperatures[0].splice(temperatures[0].length - 1, 1);
  423. humidities[0].splice(humidities[0].length - 1, 1);
  424. }
  425. }
  426. _.each(temperatures[0], function (x) {
  427. dataArray.push({
  428. DateTime: moment(x.DateTime).toDate(),
  429. Temperature: x.Value
  430. });
  431. });
  432. _.each(humidities[0], function (x) {
  433. dataArray.push({
  434. DateTime: moment(x.DateTime).toDate(),
  435. Humidity: x.Value
  436. })
  437. });
  438. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  439. _.each(values[0], function (x) {
  440. dataArray_Temp.push({
  441. DateTime: BWA.Chart.getCustermTimeArgumentAxisString($Code.TimeType.QUARTERMIN, moment(x.DateTime).toDate()),
  442. Value: x.Value,
  443. });
  444. });
  445. _.each(values[0], function (x) {
  446. if (maxValue < x.Value) {
  447. maxValue = x.Value;
  448. }
  449. });
  450. _.each(temperatures[0], function (x) {
  451. dataArray_Temp1.push({
  452. DateTime: moment(x.DateTime).toDate(),
  453. Temperature: x.Value
  454. });
  455. });
  456. _.each(humidities[0], function (x) {
  457. dataArray_Temp2.push({
  458. DateTime: moment(x.DateTime).toDate(),
  459. Humidity: x.Value
  460. })
  461. });
  462. // 배열을 하나로 합치자
  463. var array_length_size = Math.max(dataArray_Temp.length, dataArray_Temp1.length, dataArray_Temp2.length);
  464. // 크기가 동일한 경우에만 허용함 (예외 방어용)
  465. if ((dataArray_Temp.length == dataArray_Temp1.length) && (dataArray_Temp.length == dataArray_Temp2.length)) {
  466. for (var i = 0; i < array_length_size; i++) {
  467. dataArray_Temp3.push(
  468. {
  469. DateTime: dataArray_Temp[i].DateTime,
  470. Value: dataArray_Temp[i].Value,
  471. Temperature: dataArray_Temp1[i].Temperature,
  472. Humidity: dataArray_Temp2[i].Humidity
  473. });
  474. }
  475. // 만약 일렬로 병합을 원한다면 아래코드를 사용
  476. //dataArray_Temp = dataArray_Temp1.concat(dataArray_Temp2);
  477. }
  478. dataArrayresult = dataArray_Temp3;
  479. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  480. switch (fuelTypeIdForSearch()) {
  481. case $Code.FuelType.ELECTRICITY:
  482. goalUpperBound(500000);
  483. value_name = "전기"; //추가
  484. break;
  485. case $Code.FuelType.GAS:
  486. goalUpperBound(180);
  487. value_name = "가스";
  488. break;
  489. case $Code.FuelType.WATER:
  490. goalUpperBound(40);
  491. value_name = "수도";
  492. break;
  493. }
  494. check_button(); //추가
  495. var options = BWA.ChartOptions.RealtimeEnergyConsumption.getSeriesOptions(
  496. fuelTypeIdForSearch(), goalUpperBound()
  497. );
  498. //var chart = BWA.Chart.Instance('chart', 'dxChart');
  499. //var chart = $('#chartCoolingApproach').dxChart('instance');
  500. //options.valueAxis[0].tickInterval = parseInt(maxValue / 19);
  501. options.valueAxis[1].min = -19;
  502. options.valueAxis[1].max = 39;
  503. options.valueAxis[2].max = 100;
  504. options.valueAxis[2].min = 0;
  505. options.dataSource = dataArray;
  506. chart().option(options);
  507. // chart().option('dataSource', dataArray);
  508. // chart().option('dataSource', chartDataArray());
  509. // chartDataArray(values);
  510. $('#st').text('에너지 사용량 트랜드' + " : " + buildingNameForSearch() + " - " +
  511. floorNameForSearch() + " - " + zoneNameForSearch());
  512. visiblePopup(false);
  513. })
  514. .fail(function (error) {
  515. //alert(error);
  516. visiblePopup(false);
  517. });
  518. //buildingNameForSearch
  519. //$SearchView.visibleObservable(false);
  520. }
  521. function handleMenuItemClick(e) {
  522. var chartIntance = chart();
  523. var chartOptions = chartIntance._options;
  524. var series = chartIntance.getAllSeries();
  525. var table = [];
  526. var columns = [chartOptions.argumentAxis.title];
  527. var values = {};
  528. _.each(chartOptions.valueAxis, function (a) {
  529. columns.push(a.title.text);
  530. });
  531. _.each(series, function (s, i) {
  532. _.each(s.pointsByArgument, function (point, argument) {
  533. var array = values[argument];
  534. if (_.isArray(array) === false) {
  535. array = values[argument] = [];
  536. }
  537. array[i] = point.value;
  538. });
  539. });
  540. var csvRows = [columns.join(',')];
  541. _.each(values, function (values, argument) {
  542. csvRows.push([$G.dateTime(moment(Number(argument))), values.join(',')].join(','));
  543. });
  544. var csvContent = csvRows.join("\r\n");
  545. var agent = navigator.userAgent.toLowerCase();
  546. if (window.navigator.msSaveOrOpenBlob) {
  547. var fileData = ['\uFEFF' + csvContent];
  548. var blobObject = new Blob(fileData);
  549. window.navigator.msSaveOrOpenBlob(blobObject, 'export.csv');
  550. }
  551. else {
  552. var csvString = 'data:text/csv;utf-8,\uFEFF' + encodeURI(csvContent);
  553. var a = $('#csvExporter');
  554. a.attr({
  555. 'href': csvString,
  556. 'target': '_blank',
  557. 'download': 'export.csv'
  558. });
  559. // a.trigger('click');
  560. var aa = document.getElementById('csvExporter');
  561. aa.click();
  562. }
  563. }
  564. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  565. function DataGridPopup_ButtonClick() {
  566. // DevExpress.ui.notify("날짜가 일치하지 않는 데이타가 존재합니다", "fail", 1000);
  567. DataGridPopup_Visible(true);
  568. }
  569. function handlePopupShown() {
  570. // 컬럼명 업데이트
  571. var ColumnCaptionName = "";
  572. switch (fuelTypeIdForSearch()) {
  573. case $Code.FuelType.ELECTRICITY:
  574. ColumnCaptionName = "전기";
  575. break;
  576. case $Code.FuelType.GAS:
  577. ColumnCaptionName = "가스";
  578. break;
  579. case $Code.FuelType.WATER:
  580. ColumnCaptionName = "수도";
  581. break;
  582. }
  583. viewModel.RealtimeEnergyConsumptionDataGridOptions.columns[1].caption = ColumnCaptionName;
  584. // 데이타소스 업데이트
  585. $("#RealtimeEnergyConsumptionDataGrid_Container").dxDataGrid("instance").option("dataSource", dataArrayresult);
  586. // 팝업창 갱신
  587. DataGridPopup_Visible(true);
  588. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  589. }
  590. /*
  591. check_input.subscribe(checkboxTest);
  592. check_input2.subscribe(checkboxTest);
  593. function checkboxTest() {
  594. //dayEnergyUsageChart().option('series', series);
  595. alert(check_input());
  596. }*/
  597. var viewModel = $.extend(BWA.CommonView.create(
  598. params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null,
  599. handleSearchInSearchView, handleSearchViewInitializeUpdate), {
  600. refreshList: refreshList,
  601. viewShowing: handleViewShowing,
  602. viewHidden: handleViewHidden, // hcLee 2015 03 23
  603. //viewDisposing: handleViewHidden, // hcLee 2015 03 23
  604. locationEnableForSearch: locationEnableForSearch,
  605. handleMenuItemClick: handleMenuItemClick,
  606. menuItems: [{
  607. text: '엑셀(csv) 내보내기'
  608. }]
  609. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  610. , RealtimeEnergyConsumptionDataGridPopup_ButtonClicked: DataGridPopup_ButtonClick
  611. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  612. });
  613. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  614. // 그래프 도표 팝업창
  615. viewModel.RealtimeEnergyConsumptionDataGridPopupOptions = {
  616. width: '480px',
  617. height: '830px', // cyim 2017.05.30 : 테스트 결과 Devextreme 버그임. px 로 지정하면 초기 출력시 정확하게 가운데에 있지만, auto 설정시 화면아래에 위치하게 됨
  618. contentTemplate: "content",
  619. showTitle: true,
  620. title: "도표",
  621. visible: DataGridPopup_Visible,
  622. dragEnabled: true,
  623. closeOnOutsideClick: true,
  624. shownAction: handlePopupShown,
  625. animation: window.utils.popup.createAnimation(),
  626. shading: false
  627. };
  628. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  629. $HourGlassPopup(viewModel, visiblePopup);
  630. //viewModel.check_input = check_input;
  631. //viewModel.check_input2 = check_input2;
  632. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  633. // 주석이 너무 없음. 나중에 변경 작업을 진행하는 누군가가 시간 소비를 하지 않기 위해...남김
  634. // 시간 포맷은 그래프에 귀속해야 되므로 포맷은 변경하지 않는 것이 유리함
  635. // 전기,가스,수도 와 같이 선택적으로 변경해야 된다면 아래와 같이 캡션은 고정하지 말것
  636. viewModel.RealtimeEnergyConsumptionDataGridOptions = {
  637. dataSource: dataArrayresult,
  638. columns: [
  639. { dataField: 'DateTime', caption: "날짜", width: '40%', alignment: 'center' },// dataType: 'date', format: 'yyyy-MM-dd HH:mm' },
  640. { dataField: 'Value', width: '32%', alignment: 'center', format: 'fixedPoint', precision: 2 },
  641. { dataField: 'Temperature', caption: "외기온도", width: '32%', alignment: 'center', format: 'fixedPoint', precision: 2 },
  642. { dataField: 'Humidity', caption: "외기습도", width: '32%', alignment: 'center', format: 'fixedPoint', precision: 2 }
  643. ],
  644. // 엑셀 출력
  645. "export": {
  646. enabled: true,
  647. fileName: '에너지 사용량 트랜드'
  648. }
  649. };
  650. /// 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  651. return viewModel;
  652. };