3d9570184a6792bbbff6e9e7f15b907e45a675cd.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. BemsWebApplication.AnalysisChart = 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 facilityDataSource = BWA.db.createDataSource('CmFacility'),
  11. facilitiesForSearch = ko.observableArray(),
  12. facilityCodeForSearch = ko.observable(0),
  13. facilityTypeDataSource = BWA.db.createDataSource('BemsFacilityType'),
  14. facilityTypes = ko.observableArray(),
  15. formulaDataSource = BWA.db.createDataSource('BemsFormulaBase'),
  16. formulas = ko.observableArray(),
  17. deferredForSearch = new $.Deferred();
  18. var visiblePopup = ko.observable(false);
  19. var formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId());
  20. var timeBoxForSearch = BWA.SearchView.createDateTimeBox($G.TimeTypesForHourOnly, null, false);
  21. // 추가 2015 04 20 hcLee ->
  22. var CODE = $Code,
  23. FuelType = CODE.FuelType,
  24. FT = CODE.FacilityType,
  25. FC = CODE.FacilityCode,
  26. F = CODE.Formula,
  27. TIT = CODE.TimeIntervalType;
  28. // 추가 2015 04 20 hcLee <-
  29. //dataMonthForBar(dataDayForBar());
  30. //dataDayForPie([
  31. // { FuelTypeName: '전기', Value: 320 },
  32. // { FuelTypeName: '가스', Value: 350 },
  33. // { FuelTypeName: '수도', Value: 360 },
  34. //]);
  35. //dataMonthForPie(dataDayForPie());
  36. function handleViewShown() {
  37. window.$SearchView.isNotUse(true);
  38. //popupSearchViewVisible(false);
  39. if (initialized === false) {
  40. timeBoxForSearch.setDefaultDate();
  41. facilityTypeDataSource.filter([
  42. ['FacilityTypeId', '<', 20]/*,
  43. 'and',
  44. ['FacilityTypeId', '<>', 1],
  45. 'and',
  46. ['FacilityTypeId', '<>', 2],
  47. 'and',
  48. ['FacilityTypeId', '<>', 8],*/
  49. ]);
  50. //$.when(facilityDataSource.load(), facilityTypeDataSource.load())
  51. $.when(facilityTypeDataSource.load())
  52. .done(function (facilityTypes) {
  53. //var facilities = facilities[0];
  54. //facilitiesForSearch(facilities);
  55. facilityTypes = facilityTypes;
  56. ($("#acFacilityTypeCombo").dxSelectBox("instance")).option('dataSource', facilityTypes);
  57. ($("#acFacilityTypeCombo").dxSelectBox("instance")).option('value', facilityTypes[0].FacilityTypeId());
  58. /*
  59. $("#acFacilityTypeCombo").dxSelectBox({
  60. //placeholder: "설비 타입",
  61. dataSource: facilityTypes,
  62. displayExpr: "Name",
  63. valueExpr: "FacilityTypeId"
  64. });*/
  65. //handleSelectedFacilityInSearchView(f);
  66. //handleSearchInSearchView();
  67. //$SearchView.visibleObservable(true);
  68. //$SearchView.toggleSearchView();
  69. });
  70. initialized = true;
  71. }
  72. //$SearchView.visibleObservable(true);
  73. //$SearchView.toggleSearchView();
  74. //$SearchView.setPopupVisibleObservable(null);
  75. }
  76. if (shouldReload) {
  77. //shouldReload = false;
  78. //dataSource.pageIndex(0);
  79. //dataSource.load();
  80. }
  81. function handleViewHidden() {
  82. //paging.hideNextButton(true);
  83. //paging.hidePrevButton(true);
  84. //$SearchView.visibleObservable(false); // hcLee 2015 03 23
  85. visiblePopup(false);
  86. }
  87. function handleViewShowing() {
  88. }
  89. function refreshList() {
  90. //dataSource.pageIndex(0);
  91. //dataSource.load();
  92. }
  93. /*
  94. var searchViewOptions = {
  95. searchViewItems: [],
  96. promiseDataInSearchView: deferredForSearch.promise()
  97. };*/
  98. function handleChangedValueFT(e) {
  99. facilityDataSource.filter([['FacilityTypeId', '=', e.value]]);
  100. formulaDataSource.filter([['FacilityTypeId', '=', e.value]]);
  101. $.when(facilityDataSource.load(), formulaDataSource.load())
  102. .done(function (facilities, fs) {
  103. facilitiesForSearch = facilities[0];
  104. formulas = fs[0];
  105. formulas.unshift({ FormulaId: 0, Name: '미선택' });
  106. ($("#acFacilityCombo").dxSelectBox("instance")).option('dataSource', facilitiesForSearch);
  107. ($("#acFacilityCombo").dxSelectBox("instance")).option('value', facilitiesForSearch[0].FacilityCode());
  108. ($("#acLeftFormulaCombo").dxSelectBox("instance")).option('dataSource', formulas);
  109. ($("#acRightFormulaCombo").dxSelectBox("instance")).option('dataSource', formulas);
  110. ($("#acLeftFormulaCombo").dxSelectBox("instance")).option('value', 0);
  111. ($("#acRightFormulaCombo").dxSelectBox("instance")).option('value', 0);
  112. });
  113. }
  114. function handleChangedValueFC(e) {
  115. /*
  116. $.when(facilityDataSource.load())
  117. .done(function (facilities) {
  118. facilitiesForSearch = facilities;
  119. ($("#acFacilityCombo").dxSelectBox("instance")).option('dataSource', facilitiesForSearch);
  120. });*/
  121. }
  122. function handleChangedValueFM(e) {
  123. /*
  124. $.when(facilityDataSource.load())
  125. .done(function (facilities) {
  126. facilitiesForSearch = facilities;
  127. ($("#acFacilityCombo").dxSelectBox("instance")).option('dataSource', facilitiesForSearch);
  128. });*/
  129. }
  130. function ChartProcess(DataArray, valueAx, seriesF) {
  131. $("#acChart").dxChart({
  132. dataSource: DataArray,
  133. palette: "Pastel",
  134. legend: {
  135. visible: true,
  136. verticalAlignment: 'top',
  137. horizontalAlignment: 'center'
  138. },
  139. commonAxisSettings: {
  140. title: {
  141. valueMarginsEnabled: true,
  142. margin: 20,
  143. font: {
  144. color: "black",
  145. size: 18,
  146. weight: 600,
  147. family: "Nanum Gothic",
  148. },
  149. },
  150. axisDivisionFactor: 50,
  151. grid: {
  152. visible: true,
  153. }
  154. },
  155. commonSeriesSettings: {
  156. argumentField: "DateTime",
  157. selectionStyle: {
  158. hatching: {
  159. direction: "left"
  160. }
  161. }
  162. },
  163. valueAxis: valueAx,
  164. series: seriesF,
  165. crosshair: {
  166. enabled: true,
  167. width: 1,
  168. horizontalLine: {
  169. color: '#452d11',
  170. dashStyle: 'dash',
  171. visible: true
  172. },
  173. verticalLine: {
  174. color: '#452d11',
  175. dashStyle: 'dash',
  176. visible: true
  177. },
  178. label: {
  179. visible: true,
  180. backgroundColor: "#452d11",
  181. font: {
  182. color: "white",
  183. size: 12,
  184. weight: 600,
  185. }
  186. }
  187. },
  188. tooltip: {
  189. enabled: true,
  190. color: "#3e1717",
  191. format: 'fixedPoint',
  192. precision: 2,
  193. font: {
  194. color: "white",
  195. size: 12,
  196. weight: 600,
  197. },
  198. argumentFormat: 'shortDate',
  199. customizeText: function () {
  200. return {
  201. text: [this.argumentText, ': ', this.valueText].join('')
  202. };
  203. }
  204. },
  205. });
  206. }
  207. function LeftProcess(promises, LeftFormulaName, Y_Left_ChartType) {
  208. /*
  209. // 외기 온도와 습도를 위해 추가 hcLee 2015 04 20 ->
  210. var commonParameters = {
  211. TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
  212. StartDate: date.startDate,
  213. EndDate: date.endDate
  214. };
  215. var temperatureParameters = {
  216. FacilityTypeId: FT.OUTDOOR,
  217. FacilityCode: FC.OUTDOOR,
  218. FormulaId: F[FT.OUTDOOR].TEMPERATURE,
  219. };
  220. promises.push(formulaGet.apiGet(_.extend(temperatureParameters, commonParameters)));
  221. */ // 보일러는 필요 없다
  222. $.when.apply(this, promises)
  223. .done(function (data) {
  224. var DataArray = [];
  225. var maxValue = 0;
  226. _.each(data, function (x) {
  227. if (maxValue < x.Value) maxValue = x.Value;
  228. DataArray.push({
  229. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(2, moment(x.DateTime).toDate()),
  230. value1: x.Value
  231. });
  232. });
  233. var valueAx = {};
  234. $.extend(valueAx, {
  235. //pane: 'topPane',
  236. name: 'left',
  237. position: 'left',
  238. label: {
  239. visible: true,
  240. format: 'fixedPoint',
  241. precision: 0,
  242. },
  243. title: { text: LeftFormulaName },
  244. tickInterval: Math.round(maxValue / 5) + 1,
  245. });
  246. var seriesF = {};
  247. $.extend(seriesF, {
  248. type: Y_Left_ChartType,
  249. axis: 'left',
  250. valueField: 'value1',
  251. name: LeftFormulaName,
  252. });
  253. ChartProcess(DataArray, valueAx, seriesF);
  254. visiblePopup(false);
  255. })
  256. .fail(function (error) {
  257. //alert(error);
  258. visiblePopup(false);
  259. });
  260. visiblePopup(false);
  261. }
  262. function RightProcess(promises, RightFormulaName, Y_Right_ChartType) {
  263. $.when.apply(this, promises)
  264. .done(function (data) {
  265. var DataArray = [];
  266. var maxValue = 0;
  267. _.each(data, function (x) {
  268. if (maxValue < x.Value) maxValue = x.Value;
  269. DataArray.push({
  270. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(2, moment(x.DateTime).toDate()),
  271. value1: x.Value
  272. });
  273. });
  274. var valueAx = {};
  275. $.extend(valueAx, {
  276. //pane: 'topPane',
  277. name: 'right',
  278. position: 'right',
  279. label: {
  280. visible: true,
  281. format: 'fixedPoint',
  282. precision: 0,
  283. },
  284. title: { text: RightFormulaName },
  285. tickInterval: Math.round(maxValue / 5) + 1,
  286. });
  287. var seriesF = {};
  288. $.extend(seriesF, {
  289. type: Y_Right_ChartType,
  290. axis: 'right',
  291. valueField: 'value1',
  292. name: RightFormulaName,
  293. });
  294. ChartProcess(DataArray, valueAx, seriesF);
  295. visiblePopup(false);
  296. })
  297. .fail(function (error) {
  298. //alert(error);
  299. visiblePopup(false);
  300. });
  301. visiblePopup(false);
  302. }
  303. function BothProcess(promises, LeftFormulaName, Y_Left_ChartType, RightFormulaName, Y_Right_ChartType) {
  304. $.when.apply(this, promises)
  305. .done(function (dataL, dataR) {
  306. var DataArray = [];
  307. var maxValueL = 0;
  308. var maxValueR = 0;
  309. _.each(dataL[0], function (x) {
  310. if (maxValueL < x.Value) maxValueL = x.Value;
  311. DataArray.push({
  312. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(2, moment(x.DateTime).toDate()),
  313. valueL: x.Value
  314. });
  315. });
  316. _.each(dataR[0], function (x) {
  317. if (maxValueR < x.Value) maxValueR = x.Value;
  318. DataArray.push({
  319. DateTime: BWA.Chart.getCustermTimeArgumentAxisString(2, moment(x.DateTime).toDate()),
  320. valueR: x.Value
  321. });
  322. });
  323. var valueAx = [
  324. {
  325. name: 'left',
  326. position: 'left',
  327. label: { visible: true, },
  328. title: { text: LeftFormulaName },
  329. tickInterval: Math.round(maxValueL / 5) + 1,
  330. },
  331. {
  332. name: 'right',
  333. position: 'right',
  334. label: { visible: true, },
  335. title: { text: RightFormulaName },
  336. tickInterval: Math.round(maxValueR / 5) + 1,
  337. }];
  338. var seriesF = [
  339. {
  340. type: Y_Left_ChartType,
  341. axis: 'left',
  342. valueField: 'valueL',
  343. name: LeftFormulaName,
  344. },
  345. {
  346. type: Y_Right_ChartType,
  347. axis: 'right',
  348. valueField: 'valueR',
  349. name: RightFormulaName,
  350. }];
  351. ChartProcess(DataArray, valueAx, seriesF);
  352. visiblePopup(false);
  353. })
  354. .fail(function (error) {
  355. //alert(error);
  356. visiblePopup(false);
  357. });
  358. visiblePopup(false);
  359. }
  360. function handleSearchInSearchView(filter, searchViewItems) {
  361. var facilityTypeId = $("#acFacilityTypeCombo").dxSelectBox('instance').option('value');
  362. var facilityCode = $("#acFacilityCombo").dxSelectBox('instance').option('value');
  363. var LeftFormulaId = $("#acLeftFormulaCombo").dxSelectBox('instance').option('value');
  364. var LeftFormulaName = $("#acLeftFormulaCombo").dxSelectBox('instance').option('text');
  365. var Y_Left_ChartType = $("#acLeftChartTypeCombo").dxSelectBox('instance').option('text');
  366. var RightFormulaId = $("#acRightFormulaCombo").dxSelectBox('instance').option('value');
  367. var RightFormulaName = $("#acRightFormulaCombo").dxSelectBox('instance').option('text');
  368. var Y_Right_ChartType = $("#acRightChartTypeCombo").dxSelectBox('instance').option('text');
  369. if (facilityTypeId == null || facilityCode == null) {
  370. utils.toast.show('설비 타입과 설비 선택은 필수 입니다!', 'error');
  371. return;
  372. }
  373. if (LeftFormulaId == 0 && RightFormulaId == 0) {
  374. utils.toast.show('분석식을 하나 이상 선택해야 합니다.', 'error');
  375. return;
  376. }
  377. //var f = m_Facility.toJS();
  378. //facilityViewModel.fromJS(f);
  379. var timeIntervalType = timeBoxForSearch.type();
  380. var date = timeBoxForSearch.getDate();
  381. visiblePopup(true);
  382. $("#large-indicator").dxLoadIndicator({
  383. height: 60,
  384. width: 60
  385. });
  386. var promises = [];
  387. if (LeftFormulaId > 0 && RightFormulaId > 0) {
  388. var p = formulaGet.apiGet({
  389. FacilityTypeId: facilityTypeId,
  390. FacilityCode: facilityCode,
  391. FormulaId: LeftFormulaId,
  392. TimeIntervalType: timeIntervalType,
  393. StartDate: date.startDate,
  394. EndDate: date.endDate
  395. });
  396. promises.push(p);
  397. p = formulaGet.apiGet({
  398. FacilityTypeId: facilityTypeId,
  399. FacilityCode: facilityCode,
  400. FormulaId: RightFormulaId,
  401. TimeIntervalType: timeIntervalType,
  402. StartDate: date.startDate,
  403. EndDate: date.endDate
  404. });
  405. promises.push(p);
  406. BothProcess(promises, LeftFormulaName, Y_Left_ChartType, RightFormulaName, Y_Right_ChartType);
  407. }
  408. else if (LeftFormulaId > 0) {
  409. var p = formulaGet.apiGet({
  410. FacilityTypeId: facilityTypeId,
  411. FacilityCode: facilityCode,
  412. FormulaId: LeftFormulaId,
  413. TimeIntervalType: timeIntervalType,
  414. StartDate: date.startDate,
  415. EndDate: date.endDate
  416. });
  417. promises.push(p);
  418. LeftProcess(promises, LeftFormulaName, Y_Left_ChartType);
  419. }
  420. else if (RightFormulaId > 0) {
  421. var p = formulaGet.apiGet({
  422. FacilityTypeId: facilityTypeId,
  423. FacilityCode: facilityCode,
  424. FormulaId: RightFormulaId,
  425. TimeIntervalType: timeIntervalType,
  426. StartDate: date.startDate,
  427. EndDate: date.endDate
  428. });
  429. promises.push(p);
  430. RightProcess(promises,RightFormulaName, Y_Right_ChartType);
  431. }
  432. }
  433. var viewModel = $.extend(BWA.CommonView.create(
  434. params, viewInfo, null, ko.observable(null),
  435. handleViewShown, null, handleSearchInSearchView, undefined), {
  436. // facility: facilityViewModel,
  437. refreshList: refreshList,
  438. viewHidden: handleViewHidden, // hcLee 2015 06 03
  439. viewShowing: handleViewShowing,
  440. contentReadyAction: function(e) {
  441. datagrid = e.component;
  442. }
  443. });
  444. viewModel.popupOptions = {
  445. width: 300,
  446. height: 100,
  447. contentTemplate: "info",
  448. showTitle: false,
  449. title: "메세지",
  450. visible: visiblePopup,
  451. dragEnabled: false,
  452. shading:false,
  453. closeOnOutsideClick: false
  454. };
  455. viewModel.timeBoxForSearch = timeBoxForSearch;
  456. viewModel.currentTabIndex = currentTabIndex;
  457. viewModel.facilityTypes = facilityTypes;
  458. viewModel.handleChangedValueFT = handleChangedValueFT;
  459. viewModel.handleChangedValueFC = handleChangedValueFC;
  460. viewModel.handleChangedValueFM = handleChangedValueFM;
  461. viewModel.facilitiesForSearch = facilitiesForSearch;
  462. viewModel.formulas = formulas;
  463. return viewModel;
  464. };