Skip to content

Commit

Permalink
add selection of projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Borys91 committed Apr 26, 2024
1 parent 407584c commit 4fd6969
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
</mat-form-field>
<mat-form-field class="dark-theme">
<mat-label>Responsible</mat-label>
<mat-select formControlName="users">
@for (user of (users$ | async); track user) {
<mat-option [value]="user">{{ user }}</mat-option>
<mat-select formControlName="users" multiple panelClass="panel-bg">
@for (user of (users$ | async); track user.id) {
<mat-option [value]="user.identifier">{{ user.identifier }}</mat-option>
}
</mat-select>
</mat-form-field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ mat-form-field {
button {
margin: 5px;
}

::ng-deep .panel-bg.mat-mdc-select-panel {
background: black;
opacity: 0.85;
}

::ng-deep .mat-pseudo-checkbox-full {
border-color: var(--primary-color) !important;
}

mat-option {
color: var(--primary-color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import {
} from '@angular/forms';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { provideNativeDateAdapter } from '@angular/material/core';
import { ProjectUserGet } from '../../generated-client/generated-client';

export interface IFilters {
status: FormControl<string>;
type: FormControl<string>;
users: FormControl<string>;
users: FormControl<string[]>;
issueRange: FormGroup<{
start: FormControl<Date | null>;
end: FormControl<Date | null>;
Expand Down Expand Up @@ -69,11 +70,10 @@ export class IssueFiltersComponent {
})
issueTypes$!: Observable<Set<string>>;

//TODO replace type any
@Input({
required: true,
})
users$!: Observable<any>;
users$!: Observable<ProjectUserGet[]>;

@Output()
acceptedFilters = new EventEmitter<FormGroup<IFilters>>();
Expand All @@ -85,7 +85,7 @@ export class IssueFiltersComponent {
this.filtersForm = this.fb.group({
status: new FormControl<string>('', { nonNullable: true }),
type: new FormControl<string>('', { nonNullable: true }),
users: new FormControl<string>('', { nonNullable: true }),
users: new FormControl<string[]>([], { nonNullable: true }),
issueRange: new FormGroup({
start: new FormControl<Date | null>(null),
end: new FormControl<Date | null>(null),
Expand All @@ -98,7 +98,7 @@ export class IssueFiltersComponent {
}

clearFilters(): void {
this.filtersForm.reset()
this.filtersForm.reset();
this.acceptedFilters.emit(this.filtersForm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { MatButtonModule } from '@angular/material/button';
import { MatExpansionModule } from '@angular/material/expansion';
import { MatIconModule } from '@angular/material/icon';
import { ConfirmDialogComponent } from '../confirm-dialog/confirm-dialog.component';
import { UsersService } from '../../services/users.service';
@Component({
selector: 'bcfier-project-details',
standalone: true,
Expand Down Expand Up @@ -65,7 +66,8 @@ export class ProjectDetailsComponent {
private projectUsersClient: ProjectUsersClient,
private fb: FormBuilder,
private cdr: ChangeDetectorRef,
private matDialog: MatDialog
private matDialog: MatDialog,
private usersService: UsersService
) {
if (data) {
this.projectDetailsForm.patchValue({
Expand Down Expand Up @@ -95,7 +97,8 @@ export class ProjectDetailsComponent {
identifier: this.identifier,
})
.pipe(
tap(() => {
tap((u) => {
this.usersService.setUsers(u);
this.identifier = '';
this.cdr.detectChanges();
})
Expand All @@ -112,10 +115,9 @@ export class ProjectDetailsComponent {
.afterClosed()
.subscribe((confirm) => {
if (confirm) {
this.users$ = this.projectUsersClient.deleteProjectUser(
this.data.id,
userId
);
this.users$ = this.projectUsersClient
.deleteProjectUser(this.data.id, userId)
.pipe(tap((u) => this.usersService.setUsers(u)));
this.cdr.detectChanges();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,22 @@
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let row">
<mat-icon
color="warn"
(click)="$event.stopPropagation(); deleteProject(row.id)"
>delete</mat-icon
>
<div class="action-btn-container">
<mat-icon
[color]="row.id === selectedProject?.id ? 'primary' : 'accent'"
(click)="$event.stopPropagation(); setSelectedProject(row)"
>
@if(row.id === selectedProject?.id) { bookmark } @else {
bookmark_border }
</mat-icon>

<mat-icon
color="warn"
(click)="$event.stopPropagation(); deleteProject(row.id)"
>
delete
</mat-icon>
</div>
</td>
</ng-container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ mat-icon {
tr.project-row:hover {
background: whitesmoke;
}

.action-btn-container {
display: flex;
gap: 5px;
align-items: center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
OnDestroy,
OnInit,
ViewChild,
inject,
} from '@angular/core';
Expand All @@ -17,7 +19,14 @@ import {
ProjectUsersClient,
ProjectsClient,
} from '../../generated-client/generated-client';
import { combineLatestWith, filter, switchMap } from 'rxjs';
import {
Subject,
combineLatestWith,
filter,
switchMap,
takeUntil,
tap,
} from 'rxjs';

import { ConfirmDialogComponent } from '../confirm-dialog/confirm-dialog.component';
import { FormsModule } from '@angular/forms';
Expand All @@ -30,6 +39,7 @@ import { NotificationsService } from '../../services/notifications.service';
import { ProjectDetailsComponent } from '../project-details/project-details.component';
import { ProjectsService } from '../../services/light-query/projects.service';
import { SettingsMessengerService } from '../../services/settings-messenger.service';
import { SelectedProjectMessengerService } from '../../services/selected-project-messenger.service';

@Component({
selector: 'bcfier-projects-table',
Expand All @@ -51,26 +61,49 @@ import { SettingsMessengerService } from '../../services/settings-messenger.serv
styleUrl: './projects-table.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ProjectsTableComponent implements AfterViewInit {
export class ProjectsTableComponent
implements AfterViewInit, OnDestroy, OnInit
{
@ViewChild(MatPaginator) paginator!: MatPaginator;
@ViewChild(MatSort) sort!: MatSort;

projectsService = inject(ProjectsService);
settingsMessengerService = inject(SettingsMessengerService);
notificationsService = inject(NotificationsService);
selectedProjectMessengerService = inject(SelectedProjectMessengerService);
projectsClient = inject(ProjectsClient);
projectUsersClient = inject(ProjectUsersClient);
matDialog = inject(MatDialog);
cdr = inject(ChangeDetectorRef);

private destroyed$ = new Subject<void>();
dataSource!: MatTableDataSource<ProjectGet>;
displayedColumns = ['name', 'created', 'actions'];
filter = '';
selectedProject: ProjectGet | null = null;

constructor() {
this.projectsService.connect().subscribe((projects) => {
this.dataSource = new MatTableDataSource(projects);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
});
this.projectsService
.connect()
.pipe(takeUntil(this.destroyed$))
.subscribe((projects) => {
this.dataSource = new MatTableDataSource(projects);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
});
}

ngOnInit(): void {
this.selectedProjectMessengerService.selectedProject
.pipe(takeUntil(this.destroyed$))
.subscribe((p) => {
this.selectedProject = p;
});
}

ngOnDestroy(): void {
this.destroyed$.next();
this.destroyed$.complete();
}

ngAfterViewInit() {
Expand Down Expand Up @@ -109,7 +142,8 @@ export class ProjectsTableComponent implements AfterViewInit {
})
)
.subscribe({
next: () => {
next: (p) => {
this.selectedProjectMessengerService.setSelectedProject(p);
this.projectsService.forceRefresh();
if (this.filter) {
this.applyFilter(this.filter);
Expand All @@ -136,11 +170,18 @@ export class ProjectsTableComponent implements AfterViewInit {
.createProject(newProject)
.pipe(combineLatestWith(this.settingsMessengerService.settings));
}),
switchMap(([p, s]) =>
this.projectUsersClient.addUserToProject(p.id, {
identifier: s.username,
})
)

switchMap(([p, s]) => {
return this.projectUsersClient
.addUserToProject(p.id, {
identifier: s.username,
})
.pipe(
tap(() => {
this.selectedProjectMessengerService.setSelectedProject(p);
})
);
})
)
.subscribe({
next: () => {
Expand Down Expand Up @@ -177,4 +218,12 @@ export class ProjectsTableComponent implements AfterViewInit {
error: () => {},
});
}

setSelectedProject(p: ProjectGet): void {
if (p.id === this.selectedProject?.id) {
this.selectedProjectMessengerService.setSelectedProject(null);
return;
}
this.selectedProjectMessengerService.setSelectedProject(p);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
Help
</button>
</div>
<div class="project-name">
<span>{{ (selectedProject$ | async)?.name | uppercase }}</span>
</div>
<div>
<span class="version-label">
<strong>IPA.</strong>BCFier v{{ version }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
.version-label {
font-size: small;
}

.project-name {
font-size: 16px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@ import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { BackendService } from '../../services/BackendService';
import { BcfFileWrapper } from '../../generated-client/generated-client';
import { BcfFilesMessengerService } from '../../services/bcf-files-messenger.service';
import { Component } from '@angular/core';
import { Component, inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { NotificationsService } from '../../services/notifications.service';
import { SettingsComponent } from '../settings/settings.component';
import { version } from '../../version';
import { AsyncPipe, UpperCasePipe } from '@angular/common';
import { SelectedProjectMessengerService } from '../../services/selected-project-messenger.service';

@Component({
selector: 'bcfier-top-menu',
standalone: true,
imports: [MatIconModule, MatButtonModule, MatDialogModule],
imports: [
MatIconModule,
MatButtonModule,
MatDialogModule,
UpperCasePipe,
AsyncPipe,
],
templateUrl: './top-menu.component.html',
styleUrl: './top-menu.component.scss',
})
export class TopMenuComponent {
version = version.version;

selectedProject$ = inject(SelectedProjectMessengerService).selectedProject;
constructor(
private backendService: BackendService,
private notificationsService: NotificationsService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
</mat-select>
</mat-form-field>

<!-- TODO connected it with model and saving after choose or maybe get if from topic.users-->
<mat-form-field class="dark-theme">
<mat-label>Responsible</mat-label>
<mat-select (selectionChange)="changeIssue()">
@for (user of (users$ | async)?.values(); track user) {
<mat-option [value]="user">{{ user }}</mat-option>
<mat-select
[(value)]="topic.assignedTo"
(selectionChange)="changeIssue()"
>
@for (user of (users$ | async)?.values(); track user.id) {
<mat-option [value]="user.identifier">{{ user.identifier }}</mat-option>
}
</mat-select>
</mat-form-field>
Expand Down
15 changes: 10 additions & 5 deletions src/ipa-bcfier-ui/src/app/services/issue-filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class IssueFilterService {
issues: BcfTopic[],
status: string,
type: string,
users: any,
users: string[],
dateStart: Date | null,
dateEnd: Date | null
): BcfTopic[] {
Expand All @@ -31,10 +31,15 @@ export class IssueFilterService {
passesType = false;
}

//TODO add filter by user
// if (users && users.length > 0 && !users.includes(issue.user)) {
// passesUsers = false;
// }
if (
(users &&
users.length > 0 &&
issue.assignedTo &&
!users.includes(issue.assignedTo)) ||
(users.length > 0 && !issue.assignedTo)
) {
passesUsers = false;
}

if (
!!issue.dueDate &&
Expand Down
Loading

0 comments on commit 4fd6969

Please sign in to comment.