Files
market-backOfficce/src/app/pages/projects-dashboard/projects-dashboard.component.ts

69 lines
2.1 KiB
TypeScript
Raw Normal View History

2026-01-19 23:17:07 +04:00
import { Component, OnInit, signal } from '@angular/core';
import { Router } from '@angular/router';
import { CommonModule } from '@angular/common';
import { MatCardModule } from '@angular/material/card';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
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
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
this.router.events.subscribe(() => {
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]);
}
}