diff --git a/src/components/basis/flight/schedule/FlightScheduleGrid.js b/src/components/basis/flight/schedule/FlightScheduleGrid.js index b9a4b76..9cf7841 100644 --- a/src/components/basis/flight/schedule/FlightScheduleGrid.js +++ b/src/components/basis/flight/schedule/FlightScheduleGrid.js @@ -1,10 +1,9 @@ -import { useRef } from 'react'; +import { useRef, useState } from 'react'; import { GridDatabase } from '@src/components/crud/grid/GridDatatable'; -import { Row, Col, Card } from 'reactstrap'; +import { Row, Col, Card, Spinner } from 'reactstrap'; import FlightScheduleRealTime from './FlightScheduleRealTime'; import { useSelector } from 'react-redux'; import moment from 'moment'; -import DataTable from 'react-data-table-component'; const KR_TIME_DIFF = 9 * 60 * 60 * 1000; @@ -17,9 +16,7 @@ function FlightScheduleGrid() { const timeRef = useRef(null); const { scheduleList } = useSelector(state => state.flightState); - // const [list, setList] = useState( - // new Array(10).fill({ groupNm: 'test', groupNm: 'test' }) - // ); + const { loading } = useSelector(state => state.loadingReducer); const fillZero = (width, str) => { return str.length >= width @@ -36,24 +33,6 @@ function FlightScheduleGrid() { cell: row => { return row.groupNm; } - // conditionalCellStyles: [ - // { - // when: row => { - // return true; - // }, - // style: row => { - // let color; - // if (row.statusCd === 's') { - // color = '#82868B'; - // } - - // return { - // backgroundColor: '#82868B', - // color: 'white' - // }; - // } - // } - // ] }, { name: '기체 소유자', @@ -118,17 +97,20 @@ function FlightScheduleGrid() { const endDate = new Date(row.schFltEndDt); const startDate = new Date(row.schFltStDt); - const a = endDate - startDate; - let time = fillZero( + const timeDiff = endDate - startDate; + + let hours = fillZero( 2, - String(Math.floor((a % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))) + String( + Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)) + ) ); - let hore = fillZero( + let minute = fillZero( 2, - String(Math.floor((a % (1000 * 60 * 60)) / (1000 * 60))) + String(Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60))) ); - return `${time}:${hore}`; + return `${hours}:${minute}`; } }, { @@ -148,13 +130,142 @@ function FlightScheduleGrid() { } } ]; + /** + * 비행상태가 완료이면 회색 + + 비행전 || 비행중 + 비행시작시간이 현재시간 10분 지연이거나 || 비행종료시간이 현재시간 10분 초과시 + 노란색 + */ const conditionalRowStyles = [ + { + when: row => row.statusCd === 'S', + classNames: ['secondary'] + }, + { + when: row => { + if (row.statusCd !== 'S') { + // 현재시간 + const currTime = timeRef.current.lastChild.data + .replace(/\:/g, '') + .substring(0, 4); + // 현재날짜 + const currDay = Number(moment().format('YYYYMMDD')); + + // 데이터 시작날짜 + // const itemStartDay = Number(moment(row.schFltStDt).format('YYYYMMDD')); + // 데이터 종료날짜 + const itemEndDay = Number(moment(row.schFltEndDt).format('YYYYMMDD')); + + const itemStartTime = moment(row.schFltStDt).format('HHmm'); + const itemEndTime = moment(row.schFltEndDt).format('HHmm'); + + // 현재날짜 - 종료날짜 + if (currDay - itemEndDay > 0) { + return false; + } + if (row.statusCd === 'B') { + if (currTime - itemStartTime <= 10) { + return true; + } + return false; + } + if (row.statusCd === 'F') { + if (itemEndTime - currTime <= -19) { + return true; + } + return false; + } + return false; + } + return false; + }, + classNames: ['yellow'] + }, { when: row => { - return true; + if (row.statusCd !== 'S') { + // 현재시간 + const currTime = timeRef.current.lastChild.data + .replace(/\:/g, '') + .substring(0, 4); + // 현재날짜 + const currDay = Number(moment().format('YYYYMMDD')); + + // 데이터 시작날짜 + // const itemStartDay = Number(moment(row.schFltStDt).format('YYYYMMDD')); + // 데이터 종료날짜 + const itemEndDay = Number(moment(row.schFltEndDt).format('YYYYMMDD')); + + const itemStartTime = moment(row.schFltStDt).format('HHmm'); + const itemEndTime = moment(row.schFltEndDt).format('HHmm'); + + // 현재날짜 - 종료날짜 + if (currDay - itemEndDay > 0) { + return false; + } + // 비행전 체크 + if (row.statusCd === 'B') { + if (currTime - itemStartTime <= 20) { + return true; + } + return false; + } + // 비행중 체크 + if (row.statusCd === 'F') { + if (itemEndTime - currTime <= -29) { + return true; + } + return false; + } + return false; + } + return false; + }, + classNames: ['warning'] + }, + { + when: row => { + if (row.statusCd !== 'S') { + // 현재시간 + const currTime = timeRef.current.lastChild.data + .replace(/\:/g, '') + .substring(0, 4); + // 현재날짜 + const currDay = Number(moment().format('YYYYMMDD')); + + // 데이터 시작날짜 + // const itemStartDay = Number(moment(row.schFltStDt).format('YYYYMMDD')); + // 데이터 종료날짜 + const itemEndDay = Number(moment(row.schFltEndDt).format('YYYYMMDD')); + + const itemStartTime = moment(row.schFltStDt).format('HHmm'); + const itemEndTime = moment(row.schFltEndDt).format('HHmm'); + + // 현재날짜 - 종료날짜 + if (currDay - itemEndDay > 0) { + return true; + } + // 비행전 체크 + if (row.statusCd === 'B') { + if (currTime - itemStartTime <= 30) { + return true; + } + return false; + } + // 비행중 체크 + if (row.statusCd === 'F') { + if (itemEndTime - currTime <= -39) { + return true; + } + return false; + } + return false; + } + return false; }, - classNames: ['primary'] + classNames: ['danger'] } ]; @@ -183,6 +294,14 @@ function FlightScheduleGrid() {
+ {loading ? ( +
+
+ + Loading... +
+
+ ) : null} { + setIsSearch(false); + }, [date]); + useInterval(() => { if (isSearch) { dispatch(FLIGHT_SCHEDULE_LIST.request(date));