Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time range selector moved to shared-ui #3310

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,50 @@ export interface TimeSettings {
endTime: number;
// deprecated
dynamicSelection?: 15 | 60 | 1440 | 10080 | 43800 | 525600 | -1;
timeSelectionId?: TimeSelectionId;
timeSelectionId?: string;
}

export class TimeSelectionConstants {
static CUSTOM = 'custom';
static LAST_15_MINUTES = 'last-15-minutes';
static LAST_HOUR = 'last-hour';
static CURRENT_HOUR = 'current-hour';
static LAST_DAY = 'last-day';
static CURRENT_DAY = 'current-day';
static LAST_WEEK = 'last-week';
static CURRENT_WEEK = 'current-week';
static LAST_MONTH = 'last-month';
static CURRENT_MONTH = 'current-month';
static LAST_YEAR = 'last-year';
static CURRENT_YEAR = 'current-year';

static getLegacyTimeSelectionID(legacyID: number) {
if (legacyID === 0) {
return TimeSelectionConstants.CUSTOM;
} else if (legacyID === 1) {
return TimeSelectionConstants.LAST_15_MINUTES;
} else if (legacyID === 2) {
return TimeSelectionConstants.LAST_HOUR;
} else if (legacyID === 3) {
return TimeSelectionConstants.CURRENT_HOUR;
} else if (legacyID === 4) {
return TimeSelectionConstants.LAST_DAY;
} else if (legacyID === 5) {
return TimeSelectionConstants.CURRENT_DAY;
} else if (legacyID === 6) {
return TimeSelectionConstants.LAST_WEEK;
} else if (legacyID === 7) {
return TimeSelectionConstants.CURRENT_WEEK;
} else if (legacyID === 8) {
return TimeSelectionConstants.LAST_MONTH;
} else if (legacyID === 9) {
return TimeSelectionConstants.CURRENT_MONTH;
} else if (legacyID === 10) {
return TimeSelectionConstants.LAST_YEAR;
} else if (legacyID === 11) {
return TimeSelectionConstants.CURRENT_YEAR;
}
}
}

export interface WidgetTimeSettings {
Expand Down Expand Up @@ -53,7 +96,7 @@ export enum TimeSelectionId {

export interface QuickTimeSelection {
label: string;
timeSelectionId: TimeSelectionId;
timeSelectionId: string;
startTime: (now: Date) => Date;
endTime: (now: Date) => Date;
addDividerAfter?: boolean;
Expand Down
3 changes: 2 additions & 1 deletion ui/projects/streampipes/shared-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"@angular/material": "^17.3.3",
"@angular/router": "^17.3.3",
"@streampipes/platform-services": "0.0.1",
"rxjs": "^7.5.7"
"rxjs": "^7.5.7",
"date-fns": "^3.6.0"
},
"dependencies": {
"tslib": "^2.6.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,27 @@
color="accent"
[matMenuTriggerFor]="menu"
#menuTrigger="matMenuTrigger"
matTooltip="Modify time"
[matTooltip]="labels.timeRangeSelectorTooltip"
data-cy="time-selector-menu"
(menuClosed)="menuTrigger.closeMenu()"
>
<div *ngIf="timeStringMode === 'advanced'">
<div class="formatted-datetime">
<span class="formatted-date">{{
timeString.startDate
}}</span
>&nbsp;
<span class="formatted-time">{{
<div
*ngIf="timeStringMode === 'advanced'"
class="formatted-datetime"
>
<span class="formatted-date">{{ timeString.startDate }}</span>
<span *ngIf="enableTimeChange">
&nbsp;<span class="formatted-time">{{
timeString.startTime
}}</span>
</div>
-
<div class="formatted-datetime">
<span class="formatted-date">{{ timeString.endDate }}</span
>&nbsp;
<span class="formatted-time">{{ timeString.endTime }}</span>
</div>
</span>
<span class="formatted-date">&nbsp;-&nbsp;</span>
<span class="formatted-date">{{ timeString.endDate }}</span>
<span *ngIf="enableTimeChange">
&nbsp;<span class="formatted-time">{{
timeString.endTime
}}</span>
</span>
</div>
<div class="formatted-datetime" *ngIf="timeStringMode === 'simple'">
{{ simpleTimeString }}
Expand All @@ -63,7 +64,11 @@
<sp-time-selector-menu
#timeSelectorMenu
[timeSettings]="timeSettings"
[labels]="labels"
(timeSettingsEmitter)="applyCurrentDateRange($event)"
[quickSelections]="quickSelections"
[enableTimeChange]="enableTimeChange"
[maxDayRange]="maxDayRange"
class="w-100"
>
</sp-time-selector-menu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*
*/

@import '../../../../scss/variables';

.start-date-margin {
margin-right: 5px;
}
Expand Down Expand Up @@ -65,8 +63,9 @@
}

.formatted-datetime {
display: inline;
display: inline-flex;
background: var(--color-bg-2);
border-radius: 5px;
padding: 5px;
white-space: nowrap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import {
ViewEncapsulation,
} from '@angular/core';
import {
TimeSelectionId,
QuickTimeSelection,
TimeSelectionConstants,
TimeSettings,
TimeString,
} from '@streampipes/platform-services';
import { MatMenuTrigger } from '@angular/material/menu';
import { TimeSelectionService } from '../../services/time-selection.service';
import { TimeRangeSelectorMenuComponent } from './time-selector-menu/time-selector-menu.component';
import { TimeSelectorLabel } from './time-selector.model';

@Component({
selector: 'sp-time-range-selector',
Expand All @@ -55,13 +57,41 @@ export class TimeRangeSelectorComponent implements OnInit, OnChanges {
@Input()
showTimeSelector = true;

@Input()
enableTimeChange = true;

@Input()
maxDayRange = 0;

@Input()
quickSelections: QuickTimeSelection[] = [];

@Input()
labels: TimeSelectorLabel = {
quickSelectionLabel: 'Quick Selection',
customLabel: 'Custom',
maxDayRangeErrorLabel:
'Maximum of ${this.maxDayRange} days can be displayed. Please select a smaller range.',
timeRangeSelectorTooltip: 'Modify time range',
};

simpleTimeString: string = '';
timeString: TimeString;
timeStringMode: 'simple' | 'advanced' = 'simple';
dateFormat: Intl.DateTimeFormatOptions = {
weekday: 'short',
year: 'numeric',
month: 'numeric',
day: 'numeric',
};

constructor(private timeSelectionService: TimeSelectionService) {}

ngOnInit() {
this.timeSelectionService.initializeQuickTimeSelection(
this.quickSelections,
);
this.quickSelections = this.timeSelectionService.quickTimeSelections;
this.createDateString();
}

Expand Down Expand Up @@ -112,7 +142,7 @@ export class TimeRangeSelectorComponent implements OnInit, OnChanges {

this.timeSettings.startTime = newStartTime;
this.timeSettings.endTime = newEndTime;
this.timeSettings.timeSelectionId = TimeSelectionId.CUSTOM;
this.timeSettings.timeSelectionId = TimeSelectionConstants.CUSTOM;
this.timeSelectorMenu.triggerDisplayUpdate();
this.createDateString();
this.reloadData();
Expand All @@ -126,7 +156,9 @@ export class TimeRangeSelectorComponent implements OnInit, OnChanges {
}

createDateString(): void {
if (this.timeSettings.timeSelectionId !== TimeSelectionId.CUSTOM) {
if (
this.timeSettings.timeSelectionId !== TimeSelectionConstants.CUSTOM
) {
this.simpleTimeString = this.timeSelectionService.getTimeSelection(
this.timeSettings.timeSelectionId,
).label;
Expand All @@ -135,12 +167,19 @@ export class TimeRangeSelectorComponent implements OnInit, OnChanges {
const startDate = new Date(this.timeSettings.startTime);
const endDate = new Date(this.timeSettings.endTime);
this.timeString = {
startDate: startDate.toLocaleDateString(),
endDate: endDate.toLocaleDateString(),
startDate: this.formatDate(startDate),
endDate: this.formatDate(endDate),
startTime: startDate.toLocaleTimeString(),
endTime: endDate.toLocaleTimeString(),
};

this.timeStringMode = 'advanced';
}
}

private formatDate(date: Date): string {
return this.enableTimeChange
? date.toLocaleDateString()
: date.toLocaleDateString(navigator.language, this.dateFormat);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</mat-calendar>
</mat-card>

<div fxLayout="column" class="mt-10 mr-5">
<div *ngIf="enableTimeChange" fxLayout="column" class="mt-10 mr-5">
<div fxLayout="row" fxLayoutGap="10px">
<div fxFlex="30">
<span
Expand Down Expand Up @@ -73,6 +73,21 @@
</div>
</div>
</div>
<div *ngIf="!enableTimeChange" fxLayout="row" class="mt-10 date-preview">
{{ dateRangeString }}
</div>
<div
fxLayout="row"
class="mt-5 max-date-range-error"
*ngIf="maxDateRangeError"
>
{{
labels.maxDayRangeErrorLabel.replace(
'${this.maxDayRange}',
maxDayRange.toString()
)
}}
</div>
<div fxLayout="row" fxLayoutAlign="end center" class="mt-10">
<ng-content> </ng-content>
<button
Expand All @@ -81,6 +96,7 @@
data-cy="apply-custom-time"
(click)="saveSelection()"
[disabled]="!dateSelectionComplete"
*ngIf="enableTimeChange"
>
Apply
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@
font-family: inherit;
font-size: 11pt;
}

.max-date-range-error {
font-size: 9pt;
color: var(--color-warn);
}
Loading
Loading