Skip to content

Commit

Permalink
Add option to filter for topics without a given value
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgDangl committed Jun 12, 2024
1 parent 73a1c66 commit a388f2c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,22 @@ export class BcfFileComponent {
}

filterIssues(filters: FormGroup<IFilters>): void {
const { status, type, users, issueRange } = filters.value;
const {
withoutStatus,
status,
withoutType,
type,
withoutUser,
users,
issueRange,
} = filters.value;
if (
status === undefined ||
type === undefined ||
users === undefined ||
withoutStatus === undefined ||
(!withoutStatus && status === undefined) ||
withoutType === undefined ||
(!withoutType && type === undefined) ||
withoutUser === undefined ||
(!withoutUser && users === undefined) ||
issueRange === undefined ||
issueRange?.start === undefined ||
issueRange?.end === undefined
Expand All @@ -163,15 +174,25 @@ export class BcfFileComponent {
}

const isValuePresentInFilters =
!!status || !!type || !!users || !!issueRange.start || !!issueRange.end;
withoutStatus ||
withoutType ||
withoutUser ||
!!status ||
!!type ||
!!users ||
!!issueRange.start ||
!!issueRange.end;

this.filteredTopics = isValuePresentInFilters
? [
...this.issueFilterService.filterIssue(
this.bcfFile.topics,
status,
type,
users,
withoutStatus,
status || '',
withoutType,
type || '',
withoutUser,
users || [],
issueRange?.start,
issueRange?.end
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="container" [formGroup]="filtersForm">
<div class="container_filters">
<mat-checkbox formControlName="withoutStatus">Without Status</mat-checkbox>
<mat-form-field class="dark-theme">
<mat-label>Status</mat-label>
<mat-select formControlName="status">
Expand All @@ -8,6 +9,7 @@
}
</mat-select>
</mat-form-field>
<mat-checkbox formControlName="withoutType">Without Type</mat-checkbox>
<mat-form-field class="dark-theme">
<mat-label>Type</mat-label>
<mat-select formControlName="type">
Expand All @@ -16,6 +18,9 @@
}
</mat-select>
</mat-form-field>
<mat-checkbox formControlName="withoutUser"
>Without Responsible</mat-checkbox
>
<mat-form-field class="dark-theme">
<mat-label>Responsible</mat-label>
<mat-select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

import { AsyncPipe } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
Expand All @@ -23,8 +24,11 @@ import { ProjectUserGet } from '../../generated-client/generated-client';
import { ProjectUsersService } from '../../services/project-users.service';

export interface IFilters {
withoutStatus: FormControl<boolean>;
status: FormControl<string>;
withoutType: FormControl<boolean>;
type: FormControl<string>;
withoutUser: FormControl<boolean>;
users: FormControl<string[]>;
issueRange: FormGroup<{
start: FormControl<Date | null>;
Expand All @@ -42,6 +46,7 @@ export interface IFilters {
AsyncPipe,
ReactiveFormsModule,
MatDatepickerModule,
MatCheckboxModule,
],
styleUrl: './issue-filters.component.scss',
templateUrl: './issue-filters.component.html',
Expand Down Expand Up @@ -72,14 +77,46 @@ export class IssueFiltersComponent {
filtersForm: FormGroup<IFilters>;
constructor() {
this.filtersForm = this.fb.group({
withoutStatus: new FormControl<boolean>(false, { nonNullable: true }),
status: new FormControl<string>('', { nonNullable: true }),
withoutType: new FormControl<boolean>(false, { nonNullable: true }),
type: new FormControl<string>('', { nonNullable: true }),
withoutUser: new FormControl<boolean>(false, { nonNullable: true }),
users: new FormControl<string[]>([], { nonNullable: true }),
issueRange: new FormGroup({
start: new FormControl<Date | null>(null),
end: new FormControl<Date | null>(null),
}),
});

this.filtersForm.valueChanges.subscribe((value) => {
if (value.withoutStatus && this.filtersForm.controls.status.enabled) {
this.filtersForm.controls.status.disable();
} else if (
!value.withoutStatus &&
this.filtersForm.controls.status.disabled
) {
this.filtersForm.controls.status.enable();
}

if (value.withoutType && this.filtersForm.controls.type.enabled) {
this.filtersForm.controls.type.disable();
} else if (
!value.withoutType &&
this.filtersForm.controls.type.disabled
) {
this.filtersForm.controls.type.enable();
}

if (value.withoutUser && this.filtersForm.controls.users.enabled) {
this.filtersForm.controls.users.disable();
} else if (
!value.withoutUser &&
this.filtersForm.controls.users.disabled
) {
this.filtersForm.controls.users.enable();
}
});
}

acceptFilters(): void {
Expand Down
16 changes: 12 additions & 4 deletions src/ipa-bcfier-ui/src/app/services/issue-filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { BcfTopic } from '../generated-client/generated-client';
export class IssueFilterService {
filterIssue(
issues: BcfTopic[],
withoutStatus: boolean,
status: string,
withoutType: boolean,
type: string,
withoutUser: boolean,
users: string[],
dateStart: Date | null,
dateEnd: Date | null
Expand All @@ -23,15 +26,21 @@ export class IssueFilterService {
let passesUsers = true;
let passesDate = true;

if (status && issue.topicStatus !== status) {
if (withoutStatus) {
passesStatus = !issue.topicStatus;
} else if (status && issue.topicStatus !== status) {
passesStatus = false;
}

if (type && issue.topicType !== type) {
if (withoutType) {
passesType = !issue.topicType;
} else if (type && issue.topicType !== type) {
passesType = false;
}

if (
if (withoutUser) {
passesUsers = !issue.assignedTo;
} else if (
(users &&
users.length > 0 &&
issue.assignedTo &&
Expand Down Expand Up @@ -60,7 +69,6 @@ export class IssueFilterService {
if ((dateStart || dateEnd) && !issue.dueDate) {
passesDate = false;
}

return passesStatus && passesType && passesDate && passesUsers;
});
}
Expand Down

0 comments on commit a388f2c

Please sign in to comment.