UI: Refactoring; Add current hour

This commit is contained in:
Vladyslav_Prykhodko 2021-03-16 14:55:56 +02:00
parent 0ebbee02db
commit 8f8613db99
3 changed files with 28 additions and 17 deletions

View File

@ -50,7 +50,7 @@ export class QuickTimeIntervalComponent implements OnInit, ControlValueAccessor
get intervals() { get intervals() {
if (this.onlyCurrentInterval) { if (this.onlyCurrentInterval) {
return this.allIntervals.filter(interval => interval.startsWith('TODAY') || interval.startsWith('CURRENT_')); return this.allIntervals.filter(interval => interval.startsWith('CURRENT_'));
} }
return this.allIntervals; return this.allIntervals;
} }

View File

@ -131,8 +131,9 @@ export enum QuickTimeInterval {
PREVIOUS_WEEK = 'PREVIOUS_WEEK', PREVIOUS_WEEK = 'PREVIOUS_WEEK',
PREVIOUS_MONTH = 'PREVIOUS_MONTH', PREVIOUS_MONTH = 'PREVIOUS_MONTH',
PREVIOUS_YEAR = 'PREVIOUS_YEAR', PREVIOUS_YEAR = 'PREVIOUS_YEAR',
TODAY = 'TODAY', CURRENT_HOUR = 'CURRENT_HOUR',
TODAY_SO_FAR = 'TODAY_SO_FAR', CURRENT_DAY = 'CURRENT_DAY',
CURRENT_DAY_SO_FAR = 'CURRENT_DAY_SO_FAR',
CURRENT_WEEK = 'CURRENT_WEEK', CURRENT_WEEK = 'CURRENT_WEEK',
CURRENT_WEEK_SO_FAR = 'CURRENT_WEEK_SO_WAR', CURRENT_WEEK_SO_FAR = 'CURRENT_WEEK_SO_WAR',
CURRENT_MONTH = 'CURRENT_MONTH', CURRENT_MONTH = 'CURRENT_MONTH',
@ -148,8 +149,9 @@ export const QuickTimeIntervalTranslationMap = new Map<QuickTimeInterval, string
[QuickTimeInterval.PREVIOUS_WEEK, 'timeinterval.predefined.previous-week'], [QuickTimeInterval.PREVIOUS_WEEK, 'timeinterval.predefined.previous-week'],
[QuickTimeInterval.PREVIOUS_MONTH, 'timeinterval.predefined.previous-month'], [QuickTimeInterval.PREVIOUS_MONTH, 'timeinterval.predefined.previous-month'],
[QuickTimeInterval.PREVIOUS_YEAR, 'timeinterval.predefined.previous-year'], [QuickTimeInterval.PREVIOUS_YEAR, 'timeinterval.predefined.previous-year'],
[QuickTimeInterval.TODAY, 'timeinterval.predefined.today'], [QuickTimeInterval.CURRENT_HOUR, 'timeinterval.predefined.current-hour'],
[QuickTimeInterval.TODAY_SO_FAR, 'timeinterval.predefined.today-so-far'], [QuickTimeInterval.CURRENT_DAY, 'timeinterval.predefined.current-day'],
[QuickTimeInterval.CURRENT_DAY_SO_FAR, 'timeinterval.predefined.current-day-so-far'],
[QuickTimeInterval.CURRENT_WEEK, 'timeinterval.predefined.current-week'], [QuickTimeInterval.CURRENT_WEEK, 'timeinterval.predefined.current-week'],
[QuickTimeInterval.CURRENT_WEEK_SO_FAR, 'timeinterval.predefined.current-week-so-far'], [QuickTimeInterval.CURRENT_WEEK_SO_FAR, 'timeinterval.predefined.current-week-so-far'],
[QuickTimeInterval.CURRENT_MONTH, 'timeinterval.predefined.current-month'], [QuickTimeInterval.CURRENT_MONTH, 'timeinterval.predefined.current-month'],
@ -181,7 +183,7 @@ export function defaultTimewindow(timeService: TimeService): Timewindow {
realtimeType: RealtimeWindowType.LAST_INTERVAL, realtimeType: RealtimeWindowType.LAST_INTERVAL,
interval: SECOND, interval: SECOND,
timewindowMs: MINUTE, timewindowMs: MINUTE,
quickInterval: QuickTimeInterval.TODAY quickInterval: QuickTimeInterval.CURRENT_DAY
}, },
history: { history: {
historyType: HistoryWindowType.LAST_INTERVAL, historyType: HistoryWindowType.LAST_INTERVAL,
@ -191,7 +193,7 @@ export function defaultTimewindow(timeService: TimeService): Timewindow {
startTimeMs: currentTime - DAY, startTimeMs: currentTime - DAY,
endTimeMs: currentTime endTimeMs: currentTime
}, },
quickInterval: QuickTimeInterval.TODAY quickInterval: QuickTimeInterval.CURRENT_DAY
}, },
aggregation: { aggregation: {
type: AggregationType.AVG, type: AggregationType.AVG,
@ -405,8 +407,10 @@ export function createSubscriptionTimewindow(timewindow: Timewindow, stDiff: num
function getSubscriptionRealtimeWindowFromTimeInterval(interval: QuickTimeInterval): number { function getSubscriptionRealtimeWindowFromTimeInterval(interval: QuickTimeInterval): number {
const currentDate = moment(); const currentDate = moment();
switch (interval) { switch (interval) {
case QuickTimeInterval.TODAY: case QuickTimeInterval.CURRENT_HOUR:
case QuickTimeInterval.TODAY_SO_FAR: return currentDate.diff(currentDate.clone().startOf('hour'))
case QuickTimeInterval.CURRENT_DAY:
case QuickTimeInterval.CURRENT_DAY_SO_FAR:
return currentDate.diff(currentDate.clone().startOf('day')); return currentDate.diff(currentDate.clone().startOf('day'));
case QuickTimeInterval.CURRENT_WEEK: case QuickTimeInterval.CURRENT_WEEK:
case QuickTimeInterval.CURRENT_WEEK_SO_FAR: case QuickTimeInterval.CURRENT_WEEK_SO_FAR:
@ -441,7 +445,9 @@ export function calculateIntervalEndTime(interval: QuickTimeInterval, endTs = 0,
case QuickTimeInterval.PREVIOUS_YEAR: case QuickTimeInterval.PREVIOUS_YEAR:
currentDate.subtract(1, 'years'); currentDate.subtract(1, 'years');
return currentDate.endOf('year').valueOf(); return currentDate.endOf('year').valueOf();
case QuickTimeInterval.TODAY: case QuickTimeInterval.CURRENT_HOUR:
return currentDate.endOf('hour').valueOf();
case QuickTimeInterval.CURRENT_DAY:
return currentDate.endOf('day').valueOf(); return currentDate.endOf('day').valueOf();
case QuickTimeInterval.CURRENT_WEEK: case QuickTimeInterval.CURRENT_WEEK:
return currentDate.endOf('week').valueOf(); return currentDate.endOf('week').valueOf();
@ -449,7 +455,7 @@ export function calculateIntervalEndTime(interval: QuickTimeInterval, endTs = 0,
return currentDate.endOf('month').valueOf(); return currentDate.endOf('month').valueOf();
case QuickTimeInterval.CURRENT_YEAR: case QuickTimeInterval.CURRENT_YEAR:
return currentDate.endOf('year').valueOf(); return currentDate.endOf('year').valueOf();
case QuickTimeInterval.TODAY_SO_FAR: case QuickTimeInterval.CURRENT_DAY_SO_FAR:
case QuickTimeInterval.CURRENT_WEEK_SO_FAR: case QuickTimeInterval.CURRENT_WEEK_SO_FAR:
case QuickTimeInterval.CURRENT_MONTH_SO_FAR: case QuickTimeInterval.CURRENT_MONTH_SO_FAR:
case QuickTimeInterval.CURRENT_YEAR_SO_FAR: case QuickTimeInterval.CURRENT_YEAR_SO_FAR:
@ -480,8 +486,10 @@ export function calculateIntervalStartTime(interval: QuickTimeInterval, startTS
case QuickTimeInterval.PREVIOUS_YEAR: case QuickTimeInterval.PREVIOUS_YEAR:
currentDate.subtract(1, 'years'); currentDate.subtract(1, 'years');
return currentDate.startOf('year').valueOf(); return currentDate.startOf('year').valueOf();
case QuickTimeInterval.TODAY: case QuickTimeInterval.CURRENT_HOUR:
case QuickTimeInterval.TODAY_SO_FAR: return currentDate.startOf('hour').valueOf();
case QuickTimeInterval.CURRENT_DAY:
case QuickTimeInterval.CURRENT_DAY_SO_FAR:
return currentDate.startOf('day').valueOf(); return currentDate.startOf('day').valueOf();
case QuickTimeInterval.CURRENT_WEEK: case QuickTimeInterval.CURRENT_WEEK:
case QuickTimeInterval.CURRENT_WEEK_SO_FAR: case QuickTimeInterval.CURRENT_WEEK_SO_FAR:
@ -499,11 +507,13 @@ export function calculateIntervalStartTime(interval: QuickTimeInterval, startTS
export function quickTimeIntervalPeriod(interval: QuickTimeInterval): number { export function quickTimeIntervalPeriod(interval: QuickTimeInterval): number {
switch (interval) { switch (interval) {
case QuickTimeInterval.CURRENT_HOUR:
return HOUR;
case QuickTimeInterval.YESTERDAY: case QuickTimeInterval.YESTERDAY:
case QuickTimeInterval.DAY_BEFORE_YESTERDAY: case QuickTimeInterval.DAY_BEFORE_YESTERDAY:
case QuickTimeInterval.THIS_DAY_LAST_WEEK: case QuickTimeInterval.THIS_DAY_LAST_WEEK:
case QuickTimeInterval.TODAY: case QuickTimeInterval.CURRENT_DAY:
case QuickTimeInterval.TODAY_SO_FAR: case QuickTimeInterval.CURRENT_DAY_SO_FAR:
return DAY; return DAY;
case QuickTimeInterval.PREVIOUS_WEEK: case QuickTimeInterval.PREVIOUS_WEEK:
case QuickTimeInterval.CURRENT_WEEK: case QuickTimeInterval.CURRENT_WEEK:

View File

@ -2119,8 +2119,9 @@
"previous-week": "Previous week", "previous-week": "Previous week",
"previous-month": "Previous month", "previous-month": "Previous month",
"previous-year": "Previous year", "previous-year": "Previous year",
"today": "Today", "current-hour": "Current hour",
"today-so-far": "Today so far", "current-day": "Current day",
"current-day-so-far": "Current day so far",
"current-week": "Current week", "current-week": "Current week",
"current-week-so-far": "Current week so far", "current-week-so-far": "Current week so far",
"current-month": "Current month", "current-month": "Current month",