Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Add basic support for date-range filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
ppacher committed Sep 6, 2023
1 parent 13a33db commit 3ff2846
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
18 changes: 18 additions & 0 deletions modules/portmaster/src/app/shared/netquery/netquery.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ <h3 class="flex items-center gap-2 px-3 py-0.5 mb-0 border-b border-gray-300 tex

<div class="flex-grow"></div>

<nz-range-picker *ngIf="useHistory" [nzShowTime]="true" class="py-0" [nzRenderExtraFooter]="customTimeRange"
[(ngModel)]="dateFilter" [nzBorderless]="true">
</nz-range-picker>
<ng-template #customTimeRange>
<span class="py-2 uppercase text-xxs text-secondary">Quick Settings</span>
<ul class="grid grid-flow-row grid-cols-3 py-2 text-xs">
<li
class="cursor-pointer text-secondary hover:text-primary px-2 py-1.5 hover:bg-gray-500 hover:bg-opacity-50 rounded-md">
Last 24 Hours</li>
<li
class="cursor-pointer text-secondary hover:text-primary px-2 py-1.5 hover:bg-gray-500 hover:bg-opacity-50 rounded-md">
Last Week</li>
<li
class="cursor-pointer text-secondary hover:text-primary px-2 py-1.5 hover:bg-gray-500 hover:bg-opacity-50 rounded-md">
Last Month</li>
</ul>
</ng-template>

<div class="flex flex-row items-center gap-3">
<!--
Group-By selection
Expand Down
20 changes: 18 additions & 2 deletions modules/portmaster/src/app/shared/netquery/netquery.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export class SfngNetqueryViewer implements OnInit, OnDestroy, AfterViewInit {
/** The value of the free-text search */
textSearch: string = '';

/** The date filter */
dateFilter: Date[] = []

/** a list of allowed group-by keys */
readonly allowedGroupBy = groupByKeys;

Expand Down Expand Up @@ -402,11 +405,10 @@ export class SfngNetqueryViewer implements OnInit, OnDestroy, AfterViewInit {
),

totalConnCount: this.netquery.query({
...query,
select: {
$count: { field: '*', as: 'totalConnCount' }
},
query: this.mergeFilter || {},
databases: this.databases,
})
})
}),
Expand Down Expand Up @@ -914,6 +916,7 @@ export class SfngNetqueryViewer implements OnInit, OnDestroy, AfterViewInit {
}

let normalizedQuery = mergeConditions(query, this.mergeFilter || {})
normalizedQuery = this.mergeDateFilter(normalizedQuery)

let orderBy: string[] | OrderBy[] = this.orderByKeys;
if (!orderBy || orderBy.length === 0) {
Expand All @@ -939,6 +942,19 @@ export class SfngNetqueryViewer implements OnInit, OnDestroy, AfterViewInit {
}
}

private mergeDateFilter(condition: Condition): Condition {
if (this.dateFilter?.length) {
condition = mergeConditions(condition, {
started: {
$ge: Math.floor(this.dateFilter[0].getTime() / 1000),
$le: Math.ceil(this.dateFilter[1].getTime() / 1000),
}
})
}

return condition
}

/** @private Updates the current model form all values emited by the tag-bar. */
onTagbarChange(tagKinds: SfngTagbarValue[]) {
objKeys(this.models).forEach(key => {
Expand Down
2 changes: 2 additions & 0 deletions modules/portmaster/src/app/shared/netquery/netquery.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
import { SfngAccordionModule, SfngDropDownModule, SfngPaginationModule, SfngSelectModule, SfngTipUpModule, SfngToggleSwitchModule, SfngTooltipModule } from "@safing/ui";
import { NzDatePickerModule } from 'ng-zorro-antd/date-picker';
import { SfngAppIconModule } from "../app-icon";
import { CountIndicatorModule } from "../count-indicator";
import { CountryFlagModule } from "../country-flag";
Expand Down Expand Up @@ -47,6 +48,7 @@ import { SfngNetqueryTagbarComponent } from "./tag-bar";
FontAwesomeModule,
CommonPipesModule,
SPNModule,
NzDatePickerModule,
],
exports: [
SfngNetqueryViewer,
Expand Down
4 changes: 4 additions & 0 deletions modules/portmaster/src/theme.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

// Custom Theming for NG-ZORRO
// For more information: https://ng.ant.design/docs/customize-theme/en
@import "../node_modules/ng-zorro-antd/ng-zorro-antd.dark.less";

0 comments on commit 3ff2846

Please sign in to comment.