|
@@ -8,6 +8,10 @@ import { MatIconModule } from '@angular/material/icon';
|
|
|
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
|
import { webConfig } from '../config';
|
|
import { webConfig } from '../config';
|
|
|
import { CreateActivityDialogComponent } from '../components/activity-dialog/create-activity-dialog.component';
|
|
import { CreateActivityDialogComponent } from '../components/activity-dialog/create-activity-dialog.component';
|
|
|
|
|
+import { MatInputModule } from '@angular/material/input';
|
|
|
|
|
+import { MatFormFieldModule } from '@angular/material/form-field';
|
|
|
|
|
+import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
|
|
|
|
+import { ReactiveFormsModule, FormControl } from '@angular/forms';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'app-activity',
|
|
selector: 'app-activity',
|
|
@@ -20,6 +24,10 @@ import { CreateActivityDialogComponent } from '../components/activity-dialog/cre
|
|
|
MatTableModule,
|
|
MatTableModule,
|
|
|
MatIconModule,
|
|
MatIconModule,
|
|
|
MatProgressSpinnerModule,
|
|
MatProgressSpinnerModule,
|
|
|
|
|
+ MatFormFieldModule,
|
|
|
|
|
+ MatInputModule,
|
|
|
|
|
+ MatAutocompleteModule,
|
|
|
|
|
+ ReactiveFormsModule,
|
|
|
CreateActivityDialogComponent,
|
|
CreateActivityDialogComponent,
|
|
|
],
|
|
],
|
|
|
templateUrl: './activity.component.html',
|
|
templateUrl: './activity.component.html',
|
|
@@ -28,6 +36,11 @@ import { CreateActivityDialogComponent } from '../components/activity-dialog/cre
|
|
|
export class ActivityComponent implements OnInit {
|
|
export class ActivityComponent implements OnInit {
|
|
|
private http = inject(HttpClient);
|
|
private http = inject(HttpClient);
|
|
|
private dialog = inject(MatDialog);
|
|
private dialog = inject(MatDialog);
|
|
|
|
|
+ searchControl = new FormControl('');
|
|
|
|
|
+ dataSource: any[] = [];
|
|
|
|
|
+ filteredActivities: any[] = [];
|
|
|
|
|
+ uniqueActivityNames: string[] = [];
|
|
|
|
|
+
|
|
|
|
|
|
|
|
displayedColumns: string[] = [
|
|
displayedColumns: string[] = [
|
|
|
'name',
|
|
'name',
|
|
@@ -36,18 +49,51 @@ export class ActivityComponent implements OnInit {
|
|
|
'dateEnd',
|
|
'dateEnd',
|
|
|
'actions',
|
|
'actions',
|
|
|
];
|
|
];
|
|
|
- dataSource: any[] = [];
|
|
|
|
|
loading = false;
|
|
loading = false;
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
ngOnInit() {
|
|
|
this.loadActivities();
|
|
this.loadActivities();
|
|
|
|
|
+
|
|
|
|
|
+ this.searchControl.valueChanges.subscribe((value) => {
|
|
|
|
|
+ const search = value?.toLowerCase() || '';
|
|
|
|
|
+
|
|
|
|
|
+ // Filter for table
|
|
|
|
|
+ this.filteredActivities = this.dataSource.filter((activity) =>
|
|
|
|
|
+ activity.name.toLowerCase().includes(search)
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // Extract unique names for the dropdown
|
|
|
|
|
+ this.uniqueActivityNames = [
|
|
|
|
|
+ ...new Set(
|
|
|
|
|
+ this.dataSource
|
|
|
|
|
+ .filter((activity) =>
|
|
|
|
|
+ activity.name.toLowerCase().includes(search)
|
|
|
|
|
+ )
|
|
|
|
|
+ .map((a) => a.name)
|
|
|
|
|
+ ),
|
|
|
|
|
+ ];
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ refresh() {
|
|
|
|
|
+ this.loadActivities();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ clearSearch() {
|
|
|
|
|
+ this.searchControl.setValue('');
|
|
|
|
|
+ this.filteredActivities = [...this.dataSource];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
loadActivities() {
|
|
loadActivities() {
|
|
|
this.loading = true;
|
|
this.loading = true;
|
|
|
- this.http.get(`${webConfig.exposedUrl}/api/activity`).subscribe({
|
|
|
|
|
- next: (data: any) => {
|
|
|
|
|
|
|
+ this.http.get<any[]>(`${webConfig.exposedUrl}/api/activity`).subscribe({
|
|
|
|
|
+ next: (data) => {
|
|
|
this.dataSource = data;
|
|
this.dataSource = data;
|
|
|
|
|
+ this.filteredActivities = [...data];
|
|
|
|
|
+
|
|
|
|
|
+ // ✅ Extract unique names for the autocomplete dropdown
|
|
|
|
|
+ this.uniqueActivityNames = [...new Set(data.map(a => a.name))];
|
|
|
|
|
+
|
|
|
this.loading = false;
|
|
this.loading = false;
|
|
|
},
|
|
},
|
|
|
error: (err) => {
|
|
error: (err) => {
|
|
@@ -57,6 +103,14 @@ export class ActivityComponent implements OnInit {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ applyFilter(value: string) {
|
|
|
|
|
+ const filterValue = value.toLowerCase();
|
|
|
|
|
+ this.filteredActivities = this.dataSource.filter((activity) =>
|
|
|
|
|
+ activity.name.toLowerCase().includes(filterValue)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
onRowClick(row: any): void {
|
|
onRowClick(row: any): void {
|
|
|
console.log('Clicked row:', row);
|
|
console.log('Clicked row:', row);
|
|
|
this.openEditDialog(row);
|
|
this.openEditDialog(row);
|