84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
import { Component, input, signal } from '@angular/core';
|
|
import { FundingProject, FundingProjectPage, ProjectType } from '../../api';
|
|
import { MatDividerModule } from '@angular/material/divider';
|
|
import { MatIconModule } from '@angular/material/icon';
|
|
import { MatCardModule } from '@angular/material/card';
|
|
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
|
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { DatePipe, UpperCasePipe } from '@angular/common';
|
|
import { MatChipListboxChange, MatChipsModule } from '@angular/material/chips';
|
|
import { QueryParamInputComponent } from '../../shared/ui/query-param-input/query-param-input.component';
|
|
import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component';
|
|
import {
|
|
QueryParamSelectorComponent,
|
|
SelectorOption,
|
|
} from '../../shared/ui/query-param-selector/query-param-selector.component';
|
|
|
|
@Component({
|
|
selector: 'app-projects',
|
|
imports: [
|
|
MatDividerModule,
|
|
MatIconModule,
|
|
MatCardModule,
|
|
RouterModule,
|
|
MatButtonModule,
|
|
UpperCasePipe,
|
|
DatePipe,
|
|
MatChipsModule,
|
|
QueryParamInputComponent,
|
|
QueryParamPaginatorComponent,
|
|
QueryParamSelectorComponent,
|
|
],
|
|
templateUrl: './projects.component.html',
|
|
styleUrl: './projects.component.scss',
|
|
})
|
|
export class ProjectsComponent {
|
|
fundingProjectPage = input.required<FundingProjectPage>();
|
|
|
|
urlChips = signal<ProjectType[]>(['eu', 'bund', 'dfg']);
|
|
|
|
sortingOptions: SelectorOption[] = [{ value: 'title', display_name: 'Name' }];
|
|
sortingDirectionOptions: SelectorOption[] = [
|
|
{ value: 'asc', display_name: 'Aufsteigend' },
|
|
{ value: 'desc', display_name: 'Absteigend' },
|
|
];
|
|
|
|
constructor(
|
|
private readonly activatedRoute: ActivatedRoute,
|
|
private readonly router: Router,
|
|
) {
|
|
this.activatedRoute.queryParams
|
|
.pipe(takeUntilDestroyed())
|
|
.subscribe((params) => {
|
|
this.urlChips.set(
|
|
(params['selected_project_types'] || 'eu,bund,dfg').split(','),
|
|
);
|
|
});
|
|
}
|
|
|
|
handleChipBoxChange(change: MatChipListboxChange): void {
|
|
const selectedValues = change.value as string[];
|
|
|
|
this.router.navigate([], {
|
|
queryParams: {
|
|
selected_project_types: selectedValues.length
|
|
? selectedValues.join(',')
|
|
: null,
|
|
},
|
|
queryParamsHandling: 'merge',
|
|
});
|
|
}
|
|
|
|
getDetaiLink(fundingProject: FundingProject): string | null {
|
|
if (fundingProject.type === 'bund') {
|
|
const encodedId = encodeURIComponent(fundingProject.id);
|
|
return '/projects/bund/' + encodedId;
|
|
} else if (fundingProject.type === 'dfg') {
|
|
return '/projects/dfg/' + fundingProject.id;
|
|
} else if (fundingProject.type === 'eu') {
|
|
return '/projects/eu/' + fundingProject.id;
|
|
} else return null;
|
|
}
|
|
}
|