b73a3d8f0031e7ab7a7f6ff180ae56300e390597.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. $(function() {
  2. 'use strict';
  3. var searchView = BWA.SearchView = BWA.SearchView || {};
  4. var day = 'day',
  5. days = 'days',
  6. month = 'month',
  7. months = 'months',
  8. year = 'year',
  9. years = 'years';
  10. // hcLee 2016 04 04
  11. function dateBySubtract2(date, number, unit) {
  12. return moment(date).subtract(number, unit).toDate();
  13. }
  14. function dateBySubtract(number, unit) {
  15. return moment().subtract(number, unit).toDate();
  16. }
  17. function dateStartOf(unit) {
  18. return moment().startOf(unit).toDate();
  19. }
  20. // hcLee 2016 04 04
  21. function dateStartOf2(date, unit) {
  22. return moment(date).startOf(unit).toDate();
  23. }
  24. function now() {
  25. return new Date();
  26. }
  27. function HourBox() {
  28. this.startDate = ko.observable();
  29. this.startTime = ko.observable();
  30. this.endDate = ko.observable();
  31. this.endTime = ko.observable();
  32. /*
  33. this.startDate = new Date();
  34. this.startTime = new Date();
  35. this.endDate = new Date();
  36. this.endTime = new Date();*/
  37. this.timeChange = function () {
  38. alert('1');
  39. }.bind(this);
  40. this.set24hours = function () {
  41. //this.startDate(dateBySubtract(1, days));
  42. this.startDate(dateBySubtract2(this.endDate(), 1, days));
  43. this.startTime(this.endTime());
  44. //this.endDate();
  45. //this.endTime();
  46. }.bind(this);
  47. this.set3days = function() {
  48. //this.startDate(dateBySubtract(3, days));
  49. this.startDate(dateBySubtract2(this.endDate(), 3, days));
  50. //this.startTime(now());
  51. this.startTime(dateStartOf(day));
  52. //this.endDate(now());
  53. //this.endTime(now());
  54. }.bind(this);
  55. this.setToday = function() {
  56. this.startDate(now());
  57. this.startTime(dateStartOf(day));
  58. this.endDate(now());
  59. this.endTime(now());
  60. }.bind(this);
  61. this.getStartDate = function () {
  62. /*this.startDate(BWA.DataUtil.getDateTimeZeroMin(
  63. this.startDate(),
  64. this.startTime()));*/
  65. this.startTime(BWA.DataUtil.getDateTimeZeroMin( //getDateTimeZeroSecond
  66. this.startDate(),
  67. this.startTime()));
  68. return BWA.DataUtil.getDateTimeFromDateAndTime(this.startDate(), this.startTime());
  69. /*
  70. return BWA.DataUtil.getDateTimeZeroMin(
  71. this.startDate(),
  72. this.startTime());*/
  73. }.bind(this);
  74. this.getEndDate = function () {
  75. /*
  76. this.endTime(BWA.DataUtil.getDateTimeZeroMin(
  77. this.endDate(),
  78. this.endTime()));
  79. return BWA.DataUtil.getDateTimeFromDateAndTime(
  80. this.endDate(),
  81. this.endTime()); */
  82. this.endTime(BWA.DataUtil.getDateTimeZeroMin(
  83. this.endDate(),
  84. this.endTime()));
  85. return BWA.DataUtil.getDateTimeFromDateAndTime(this.endDate(), this.endTime());
  86. }.bind(this);
  87. this.setToday();
  88. }
  89. function HourBox1() {
  90. this.startDate = ko.observable();
  91. this.startTime = ko.observable();
  92. this.endDate = ko.observable();
  93. this.endTime = ko.observable();
  94. /*
  95. this.startDate = new Date();
  96. this.startTime = new Date();
  97. this.endDate = new Date();
  98. this.endTime = new Date();*/
  99. this.timeChange = function () {
  100. alert('1');
  101. }.bind(this);
  102. this.set24hours = function () {
  103. //this.startDate(dateBySubtract(1, days));
  104. this.startDate(dateBySubtract2(this.endDate(), 1, days));
  105. this.startTime(this.endTime());
  106. //this.endDate();
  107. //this.endTime();
  108. }.bind(this);
  109. this.set3days = function () {
  110. //this.startDate(dateBySubtract(3, days));
  111. this.startDate(dateBySubtract2(this.endDate(), 3, days));
  112. //this.startTime(now());
  113. this.startTime(dateStartOf(day));
  114. //this.endDate(now());
  115. //this.endTime(now());
  116. }.bind(this);
  117. this.setToday = function () {
  118. this.startDate(now());
  119. this.startTime(dateStartOf(day));
  120. this.endDate(now());
  121. this.endTime(now());
  122. }.bind(this);
  123. this.getStartDate = function () {
  124. /*this.startDate(BWA.DataUtil.getDateTimeZeroMin(
  125. this.startDate(),
  126. this.startTime()));*/
  127. this.startTime(BWA.DataUtil.getDateTimeZeroSecond( //getDateTimeZeroSecond
  128. this.startDate(),
  129. this.startTime()));
  130. return BWA.DataUtil.getDateTimeFromDateAndTime(this.startDate(), this.startTime());
  131. /*
  132. return BWA.DataUtil.getDateTimeZeroMin(
  133. this.startDate(),
  134. this.startTime());*/
  135. }.bind(this);
  136. this.getEndDate = function () {
  137. /*
  138. this.endTime(BWA.DataUtil.getDateTimeZeroMin(
  139. this.endDate(),
  140. this.endTime()));
  141. return BWA.DataUtil.getDateTimeFromDateAndTime(
  142. this.endDate(),
  143. this.endTime()); */
  144. this.endTime(BWA.DataUtil.getDateTimeZeroSecond(
  145. this.endDate(),
  146. this.endTime()));
  147. return BWA.DataUtil.getDateTimeFromDateAndTime(this.endDate(), this.endTime());
  148. }.bind(this);
  149. this.setToday();
  150. }
  151. function DayBox() {
  152. this.startDate = ko.observable();
  153. this.endDate = ko.observable();
  154. // 추가 2020.05 kgpark
  155. this.setToday = function () {
  156. this.startDate(now());
  157. this.endDate(now());
  158. }.bind(this);
  159. this.set3days = function() {
  160. //this.startDate(dateBySubtract(3, days));
  161. this.startDate(dateBySubtract2(this.endDate(), 3, days));
  162. this.endDate(now());
  163. }.bind(this);
  164. this.set1week = function() {
  165. //this.startDate(dateBySubtract(7, days));
  166. this.startDate(dateBySubtract2(this.endDate(), 7, days));
  167. //this.endDate(now());
  168. }.bind(this);
  169. this.set1month = function() {
  170. //this.startDate(dateBySubtract(1, months));
  171. this.startDate(dateBySubtract2(this.endDate(), 1, months));
  172. //this.endDate(now());
  173. }.bind(this);
  174. this.setThisMonth = function() {
  175. this.startDate(dateStartOf(month));
  176. //this.startTime(dateStartOf(day)); // hcLee
  177. this.endDate(now());
  178. }.bind(this);
  179. this.getStartDate = function () {
  180. this.startDate(BWA.DataUtil.getDateTimeZeroHour(this.startDate()));
  181. return this.startDate();
  182. //return BWA.DataUtil.getDateTimeZeroHour(this.startDate());
  183. }.bind(this);
  184. this.getEndDate = function () {
  185. this.endDate(BWA.DataUtil.getDateTimeMaxHour(this.endDate()));
  186. return this.endDate();
  187. }.bind(this);
  188. this.setThisMonth();
  189. }
  190. function MonthBox(startthisyear) {
  191. this.startDate = ko.observable();
  192. this.endDate = ko.observable();
  193. this.set3months = function() {
  194. //this.startDate(dateBySubtract(2, months));
  195. this.startDate(dateBySubtract2(this.endDate(), 2, months));
  196. //this.endDate(now());
  197. }.bind(this);
  198. this.set6months = function() {
  199. //this.startDate(dateBySubtract(5, months));
  200. this.startDate(dateBySubtract2(this.endDate(), 5, months));
  201. //this.endDate(now());
  202. }.bind(this);
  203. this.set1year = function() {
  204. //this.startDate(dateBySubtract(11, months));
  205. this.startDate(dateBySubtract2(this.endDate(), 11, months));
  206. this.endDate(now());
  207. }.bind(this);
  208. this.setThisYear = function() {
  209. this.startDate(dateStartOf(year));
  210. this.endDate(now());
  211. }.bind(this);
  212. this.getStartDate = function() {
  213. //return this.startDate();
  214. this.startDate(BWA.DataUtil.getDateTimeStartDay(this.startDate()));
  215. return this.startDate();
  216. }.bind(this);
  217. this.getEndDate = function () {
  218. this.endDate(BWA.DataUtil.getDateTimeEndDay(this.endDate()));
  219. return this.endDate();
  220. }.bind(this);
  221. if (startthisyear == null)
  222. this.set1year(); // hcLee 2016 02 26 월별 조회가 기본인 화면들을 위하여 스타트 검색조건을 최근12개월로 변경한다.
  223. else
  224. this.setThisYear(); // // hcLee 2016 04 26 가동시간 비용 속도문제때문에
  225. }
  226. function YearBox() {
  227. this.startYear = ko.observable();
  228. this.endYear = ko.observable();
  229. this.set3years = function() {
  230. this.startYear(dateBySubtract(3, years).getFullYear());
  231. this.endYear(now().getFullYear());
  232. }.bind(this);
  233. this.set5years = function() {
  234. this.startYear(dateBySubtract(5, years).getFullYear());
  235. this.endYear(now().getFullYear());
  236. }.bind(this);
  237. this.set10years = function() {
  238. this.startYear(dateBySubtract(10, years).getFullYear());
  239. this.endYear(now().getFullYear());
  240. }.bind(this);
  241. this.getStartDate = function() {
  242. var year = this.startYear();
  243. return moment([year, 1, 1]).toDate();
  244. }.bind(this);
  245. this.getEndDate = function() {
  246. var year = this.startEnd();
  247. return moment([year, 1, 1]).toDate();
  248. }.bind(this);
  249. this.set3years();
  250. }
  251. var HOUR = $Code.TimeType.HOUR;
  252. var DAY = $Code.TimeType.DAY;
  253. var MONTH = $Code.TimeType.MONTH;
  254. var YEAR = $Code.TimeType.YEAR;
  255. // cyim 2016.08.22 : 생성자에 읽기전용인지 구분자 포함
  256. searchView.createDateTimeBox = function(dataSource, startthisyear, readonly) {
  257. var type = ko.observable();
  258. var isHour = ko.observable();
  259. var isDay = ko.observable();
  260. var isMonth = ko.observable();
  261. var isYear = ko.observable();
  262. var isReadOnly = ko.observable(false); // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
  263. type.subscribe(function(type) {
  264. isHour(type === HOUR);
  265. isDay(type === DAY);
  266. isMonth(type === MONTH);
  267. isYear(type === YEAR);
  268. });
  269. // type(HOUR); 원래코드
  270. // hcLee 2015 06 25 , 요일별 에너지 사용량분석 처럼 검색조건에 '시' 가 필요없는 경우를 처리 하기 위하여
  271. if (dataSource == null)
  272. type(HOUR);
  273. else type(dataSource[0].TimeTypeId);
  274. var dateTimeBox = {
  275. type: type,
  276. typeDataSource: (dataSource == null) ? $G.TimeTypes : dataSource, // hcLee 2015 06 25
  277. //typeDataSource: $G.TimeTypes, // // hcLee 2015 06 25
  278. isHour: isHour,
  279. isDay: isDay,
  280. isMonth: isMonth,
  281. isYear: isYear,
  282. isReadOnly: readonly, // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
  283. hour: new HourBox(),
  284. day: new DayBox(),
  285. month: new MonthBox(startthisyear),
  286. year: new YearBox(),
  287. };
  288. //2016 07 21 hcLee
  289. dateTimeBox.setDefaultDate = function () {
  290. type(HOUR);
  291. this.hour.endTime(now());
  292. this.hour.set24hours();
  293. },
  294. // 추가 2020.05 kgpark
  295. dateTimeBox.setDefaultDateToday = function () {
  296. type(DAY);
  297. this.day.setToday();
  298. },
  299. dateTimeBox.getDate = function() {
  300. var timeObject = null;
  301. switch (this.type()) {
  302. case HOUR:
  303. timeObject = this.hour;
  304. break;
  305. case DAY:
  306. timeObject = this.day;
  307. break;
  308. case MONTH:
  309. timeObject = this.month;
  310. break;
  311. case YEAR:
  312. timeObject = this.year;
  313. break;
  314. }
  315. return {
  316. startDate: timeObject.getStartDate(),
  317. endDate: timeObject.getEndDate()
  318. };
  319. }.bind(dateTimeBox);
  320. return dateTimeBox;
  321. }
  322. searchView.createDateTimeBox1 = function (dataSource, startthisyear, readonly) {
  323. var type = ko.observable();
  324. var isHour = ko.observable();
  325. var isDay = ko.observable();
  326. var isMonth = ko.observable();
  327. var isYear = ko.observable();
  328. var isReadOnly = ko.observable(false); // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
  329. type.subscribe(function (type) {
  330. isHour(type === HOUR);
  331. isDay(type === DAY);
  332. isMonth(type === MONTH);
  333. isYear(type === YEAR);
  334. });
  335. // type(HOUR); 원래코드
  336. // hcLee 2015 06 25 , 요일별 에너지 사용량분석 처럼 검색조건에 '시' 가 필요없는 경우를 처리 하기 위하여
  337. if (dataSource == null)
  338. type(HOUR);
  339. else type(dataSource[0].TimeTypeId);
  340. var dateTimeBox = {
  341. type: type,
  342. typeDataSource: (dataSource == null) ? $G.TimeTypes : dataSource, // hcLee 2015 06 25
  343. //typeDataSource: $G.TimeTypes, // // hcLee 2015 06 25
  344. isHour: isHour,
  345. isDay: isDay,
  346. isMonth: isMonth,
  347. isYear: isYear,
  348. isReadOnly: readonly, // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
  349. hour: new HourBox1(),
  350. day: new DayBox(),
  351. month: new MonthBox(startthisyear),
  352. year: new YearBox(),
  353. };
  354. //2016 07 21 hcLee
  355. dateTimeBox.setDefaultDate = function () {
  356. type(HOUR);
  357. this.hour.endTime(now());
  358. this.hour.set24hours();
  359. },
  360. dateTimeBox.getDate = function () {
  361. var timeObject = null;
  362. switch (this.type()) {
  363. case HOUR:
  364. timeObject = this.hour;
  365. break;
  366. case DAY:
  367. timeObject = this.day;
  368. break;
  369. case MONTH:
  370. timeObject = this.month;
  371. break;
  372. case YEAR:
  373. timeObject = this.year;
  374. break;
  375. }
  376. return {
  377. startDate: timeObject.getStartDate(),
  378. endDate: timeObject.getEndDate()
  379. };
  380. }.bind(dateTimeBox);
  381. return dateTimeBox;
  382. }
  383. });