2026-03-01 02:40:42 +04:00
|
|
|
import { Component, OnInit, signal, DestroyRef, inject } from '@angular/core';
|
2026-01-19 23:17:07 +04:00
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
|
import { MatCardModule } from '@angular/material/card';
|
|
|
|
|
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
2026-03-01 02:40:42 +04:00
|
|
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
2026-01-19 23:17:07 +04:00
|
|
|
import { ApiService } from '../../services';
|
|
|
|
|
import { Project } from '../../models';
|
2026-02-20 09:01:02 +04:00
|
|
|
import { LanguageService } from '../../services/language.service';
|
|
|
|
|
import { TranslatePipe } from '../../pipes/translate.pipe';
|
2026-01-19 23:17:07 +04:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-projects-dashboard',
|
|
|
|
|
standalone: true,
|
2026-02-20 09:01:02 +04:00
|
|
|
imports: [CommonModule, MatCardModule, MatProgressSpinnerModule, TranslatePipe],
|
2026-01-19 23:17:07 +04:00
|
|
|
templateUrl: './projects-dashboard.component.html',
|
|
|
|
|
styleUrls: ['./projects-dashboard.component.scss']
|
|
|
|
|
})
|
|
|
|
|
export class ProjectsDashboardComponent implements OnInit {
|
|
|
|
|
projects = signal<Project[]>([]);
|
|
|
|
|
loading = signal(true);
|
|
|
|
|
error = signal<string | null>(null);
|
2026-01-22 00:41:13 +04:00
|
|
|
currentProjectId = signal<string | null>(null);
|
2026-01-19 23:17:07 +04:00
|
|
|
|
2026-03-01 02:40:42 +04:00
|
|
|
private destroyRef = inject(DestroyRef);
|
|
|
|
|
|
2026-01-19 23:17:07 +04:00
|
|
|
constructor(
|
|
|
|
|
private apiService: ApiService,
|
2026-02-20 09:01:02 +04:00
|
|
|
private router: Router,
|
|
|
|
|
public lang: LanguageService
|
2026-01-19 23:17:07 +04:00
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.loadProjects();
|
2026-01-22 00:41:13 +04:00
|
|
|
|
|
|
|
|
// Check if we're currently viewing a project
|
|
|
|
|
const urlSegments = this.router.url.split('/');
|
|
|
|
|
if (urlSegments[1] === 'project' && urlSegments[2]) {
|
|
|
|
|
this.currentProjectId.set(urlSegments[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Listen to route changes
|
2026-03-01 02:40:42 +04:00
|
|
|
this.router.events.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
|
2026-01-22 00:41:13 +04:00
|
|
|
const segments = this.router.url.split('/');
|
|
|
|
|
if (segments[1] === 'project' && segments[2]) {
|
|
|
|
|
this.currentProjectId.set(segments[2]);
|
|
|
|
|
} else {
|
|
|
|
|
this.currentProjectId.set(null);
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-01-19 23:17:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadProjects() {
|
|
|
|
|
this.loading.set(true);
|
|
|
|
|
this.apiService.getProjects().subscribe({
|
|
|
|
|
next: (projects) => {
|
|
|
|
|
this.projects.set(projects);
|
|
|
|
|
this.loading.set(false);
|
|
|
|
|
},
|
|
|
|
|
error: (err) => {
|
|
|
|
|
this.error.set('Failed to load projects');
|
|
|
|
|
this.loading.set(false);
|
|
|
|
|
console.error(err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openProject(projectId: string) {
|
|
|
|
|
this.router.navigate(['/project', projectId]);
|
|
|
|
|
}
|
|
|
|
|
}
|