e602d4ebbf3d6a19c34304b227508997bc8249e4.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. this.set3days = function() {
  155. //this.startDate(dateBySubtract(3, days));
  156. this.startDate(dateBySubtract2(this.endDate(), 3, days));
  157. this.endDate(now());
  158. }.bind(this);
  159. this.set1week = function() {
  160. //this.startDate(dateBySubtract(7, days));
  161. this.startDate(dateBySubtract2(this.endDate(), 7, days));
  162. //this.endDate(now());
  163. }.bind(this);
  164. this.set1month = function() {
  165. //this.startDate(dateBySubtract(1, months));
  166. this.startDate(dateBySubtract2(this.endDate(), 1, months));
  167. //this.endDate(now());
  168. }.bind(this);
  169. this.setThisMonth = function() {
  170. this.startDate(dateStartOf(month));
  171. //this.startTime(dateStartOf(day)); // hcLee
  172. this.endDate(now());
  173. }.bind(this);
  174. this.getStartDate = function () {
  175. this.startDate(BWA.DataUtil.getDateTimeZeroHour(this.startDate()));
  176. return this.startDate();
  177. //return BWA.DataUtil.getDateTimeZeroHour(this.startDate());
  178. }.bind(this);
  179. this.getEndDate = function () {
  180. this.endDate(BWA.DataUtil.getDateTimeMaxHour(this.endDate()));
  181. return this.endDate();
  182. }.bind(this);
  183. this.setThisMonth();
  184. }
  185. function MonthBox(startthisyear) {
  186. this.startDate = ko.observable();
  187. this.endDate = ko.observable();
  188. this.set3months = function() {
  189. //this.startDate(dateBySubtract(2, months));
  190. this.startDate(dateBySubtract2(this.endDate(), 2, months));
  191. //this.endDate(now());
  192. }.bind(this);
  193. this.set6months = function() {
  194. //this.startDate(dateBySubtract(5, months));
  195. this.startDate(dateBySubtract2(this.endDate(), 5, months));
  196. //this.endDate(now());
  197. }.bind(this);
  198. this.set1year = function() {
  199. //this.startDate(dateBySubtract(11, months));
  200. this.startDate(dateBySubtract2(this.endDate(), 11, months));
  201. this.endDate(now());
  202. }.bind(this);
  203. this.setThisYear = function() {
  204. this.startDate(dateStartOf(year));
  205. this.endDate(now());
  206. }.bind(this);
  207. this.getStartDate = function() {
  208. //return this.startDate();
  209. this.startDate(BWA.DataUtil.getDateTimeStartDay(this.startDate()));
  210. return this.startDate();
  211. }.bind(this);
  212. this.getEndDate = function () {
  213. this.endDate(BWA.DataUtil.getDateTimeEndDay(this.endDate()));
  214. return this.endDate();
  215. }.bind(this);
  216. if (startthisyear == null)
  217. this.set1year(); // hcLee 2016 02 26 월별 조회가 기본인 화면들을 위하여 스타트 검색조건을 최근12개월로 변경한다.
  218. else
  219. this.setThisYear(); // // hcLee 2016 04 26 가동시간 비용 속도문제때문에
  220. }
  221. function YearBox() {
  222. this.startYear = ko.observable();
  223. this.endYear = ko.observable();
  224. this.set3years = function() {
  225. this.startYear(dateBySubtract(3, years).getFullYear());
  226. this.endYear(now().getFullYear());
  227. }.bind(this);
  228. this.set5years = function() {
  229. this.startYear(dateBySubtract(5, years).getFullYear());
  230. this.endYear(now().getFullYear());
  231. }.bind(this);
  232. this.set10years = function() {
  233. this.startYear(dateBySubtract(10, years).getFullYear());
  234. this.endYear(now().getFullYear());
  235. }.bind(this);
  236. this.getStartDate = function() {
  237. var year = this.startYear();
  238. return moment([year, 1, 1]).toDate();
  239. }.bind(this);
  240. this.getEndDate = function() {
  241. var year = this.startEnd();
  242. return moment([year, 1, 1]).toDate();
  243. }.bind(this);
  244. this.set3years();
  245. }
  246. var HOUR = $Code.TimeType.HOUR;
  247. var DAY = $Code.TimeType.DAY;
  248. var MONTH = $Code.TimeType.MONTH;
  249. var YEAR = $Code.TimeType.YEAR;
  250. // cyim 2016.08.22 : 생성자에 읽기전용인지 구분자 포함
  251. searchView.createDateTimeBox = function(dataSource, startthisyear, readonly) {
  252. var type = ko.observable();
  253. var isHour = ko.observable();
  254. var isDay = ko.observable();
  255. var isMonth = ko.observable();
  256. var isYear = ko.observable();
  257. var isReadOnly = ko.observable(false); // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
  258. type.subscribe(function(type) {
  259. isHour(type === HOUR);
  260. isDay(type === DAY);
  261. isMonth(type === MONTH);
  262. isYear(type === YEAR);
  263. });
  264. // type(HOUR); 원래코드
  265. // hcLee 2015 06 25 , 요일별 에너지 사용량분석 처럼 검색조건에 '시' 가 필요없는 경우를 처리 하기 위하여
  266. if (dataSource == null)
  267. type(HOUR);
  268. else type(dataSource[0].TimeTypeId);
  269. var dateTimeBox = {
  270. type: type,
  271. typeDataSource: (dataSource == null) ? $G.TimeTypes : dataSource, // hcLee 2015 06 25
  272. //typeDataSource: $G.TimeTypes, // // hcLee 2015 06 25
  273. isHour: isHour,
  274. isDay: isDay,
  275. isMonth: isMonth,
  276. isYear: isYear,
  277. isReadOnly: readonly, // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
  278. hour: new HourBox(),
  279. day: new DayBox(),
  280. month: new MonthBox(startthisyear),
  281. year: new YearBox(),
  282. };
  283. //2016 07 21 hcLee
  284. dateTimeBox.setDefaultDate = function () {
  285. type(HOUR);
  286. this.hour.endTime(now());
  287. this.hour.set24hours();
  288. },
  289. dateTimeBox.getDate = function() {
  290. var timeObject = null;
  291. switch (this.type()) {
  292. case HOUR:
  293. timeObject = this.hour;
  294. break;
  295. case DAY:
  296. timeObject = this.day;
  297. break;
  298. case MONTH:
  299. timeObject = this.month;
  300. break;
  301. case YEAR:
  302. timeObject = this.year;
  303. break;
  304. }
  305. return {
  306. startDate: timeObject.getStartDate(),
  307. endDate: timeObject.getEndDate()
  308. };
  309. }.bind(dateTimeBox);
  310. return dateTimeBox;
  311. }
  312. searchView.createDateTimeBox1 = function (dataSource, startthisyear, readonly) {
  313. var type = ko.observable();
  314. var isHour = ko.observable();
  315. var isDay = ko.observable();
  316. var isMonth = ko.observable();
  317. var isYear = ko.observable();
  318. var isReadOnly = ko.observable(false); // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
  319. type.subscribe(function (type) {
  320. isHour(type === HOUR);
  321. isDay(type === DAY);
  322. isMonth(type === MONTH);
  323. isYear(type === YEAR);
  324. });
  325. // type(HOUR); 원래코드
  326. // hcLee 2015 06 25 , 요일별 에너지 사용량분석 처럼 검색조건에 '시' 가 필요없는 경우를 처리 하기 위하여
  327. if (dataSource == null)
  328. type(HOUR);
  329. else type(dataSource[0].TimeTypeId);
  330. var dateTimeBox = {
  331. type: type,
  332. typeDataSource: (dataSource == null) ? $G.TimeTypes : dataSource, // hcLee 2015 06 25
  333. //typeDataSource: $G.TimeTypes, // // hcLee 2015 06 25
  334. isHour: isHour,
  335. isDay: isDay,
  336. isMonth: isMonth,
  337. isYear: isYear,
  338. isReadOnly: readonly, // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
  339. hour: new HourBox1(),
  340. day: new DayBox(),
  341. month: new MonthBox(startthisyear),
  342. year: new YearBox(),
  343. };
  344. //2016 07 21 hcLee
  345. dateTimeBox.setDefaultDate = function () {
  346. type(HOUR);
  347. this.hour.endTime(now());
  348. this.hour.set24hours();
  349. },
  350. dateTimeBox.getDate = function () {
  351. var timeObject = null;
  352. switch (this.type()) {
  353. case HOUR:
  354. timeObject = this.hour;
  355. break;
  356. case DAY:
  357. timeObject = this.day;
  358. break;
  359. case MONTH:
  360. timeObject = this.month;
  361. break;
  362. case YEAR:
  363. timeObject = this.year;
  364. break;
  365. }
  366. return {
  367. startDate: timeObject.getStartDate(),
  368. endDate: timeObject.getEndDate()
  369. };
  370. }.bind(dateTimeBox);
  371. return dateTimeBox;
  372. }
  373. });