projects.component.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @file Provides a component for the project list page.
  3. * @author Inigo Valentin
  4. * @since 4.0.0
  5. */
  6. import {Component} from '@angular/core';
  7. import {NgFor} from '@angular/common';
  8. import {TranslateModule} from "@ngx-translate/core";
  9. import {UserService} from '../../services/user.service';
  10. import {MetaService} from '../../services/meta.service';
  11. import {Project} from '../../models/project';
  12. import {ProjectsService} from '../../services/projects.service';
  13. import {ProjectPreviewComponent} from '../../components/project-preview/project-preview.component';
  14. @Component({
  15. selector: 'app-projects',
  16. standalone: true,
  17. imports: [NgFor, ProjectPreviewComponent, TranslateModule],
  18. templateUrl: './projects.component.html'
  19. })
  20. /**
  21. * The component for the project list page.
  22. */
  23. export class ProjectsComponent {
  24. /**
  25. * The list of projects to show in the list.
  26. */
  27. protected projects: Project[] = [];
  28. /**
  29. * The error message.
  30. */
  31. protected errorMessage!: string;
  32. /**
  33. * The constructor.
  34. *
  35. * @param metaService Service that handles HTML meta tags.
  36. * @param userService Service that handles user information.
  37. * @param projectsService Service that handles projects.
  38. */
  39. public constructor(private metaService: MetaService, private userService: UserService, private projectsService: ProjectsService){}
  40. /**
  41. * Loads on component initialization.
  42. */
  43. private ngOnInit(){
  44. this.userService.getUser().subscribe({
  45. error: (error) => {this.errorMessage = error;},
  46. next: (user) => {
  47. this.metaService.setTitle("Projects - " + user.firstName + " " + user.lastName);
  48. this.metaService.setMetaTag("description", "List of projects by " + user.firstName + " " + user.lastName);
  49. },
  50. });
  51. this.projectsService.getAllProjects().subscribe({
  52. next: (projects) => {this.projects = projects;},
  53. error: (error) => {this.errorMessage = error;},
  54. });
  55. }
  56. }