63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
import { Subject } from 'rxjs';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
import { NavService } from '../nav/nav.service';
|
|
import { Pages } from '../shared/models/pages.model';
|
|
import { Project } from '../shared/models/project.model';
|
|
import { ProjectsService } from './projects.service';
|
|
|
|
@Component({
|
|
selector: 'app-projects',
|
|
templateUrl: './projects.component.html',
|
|
styleUrls: ['./projects.component.scss']
|
|
})
|
|
export class ProjectsComponent implements OnInit, OnDestroy {
|
|
_unsubscribe$: Subject<boolean> = new Subject();
|
|
|
|
allProjects: Array<Project>;
|
|
private _gitlabProjects: Array<Project> = new Array<Project>();
|
|
private _uncategorizedProjects: Array<Project> = new Array<Project>();
|
|
|
|
constructor(private navService: NavService, private projectsService: ProjectsService) { }
|
|
|
|
ngOnInit(): void {
|
|
this.navService.setPageTitle(Pages.PROJECTS);
|
|
|
|
this.projectsService.allProjects$
|
|
.pipe(takeUntil(this._unsubscribe$))
|
|
.subscribe((result: Project[]) => {
|
|
this.allProjects = result;
|
|
});
|
|
|
|
this.projectsService.getProjects();
|
|
}
|
|
|
|
ngOnDestroy(): void {
|
|
this._unsubscribe$.next(false);
|
|
this._unsubscribe$.complete();
|
|
}
|
|
|
|
filterProjects(): void {
|
|
this._gitlabProjects = [];
|
|
this._uncategorizedProjects = [];
|
|
this.allProjects.forEach((project) => {
|
|
if (project.category === 'gitlab') {
|
|
this._gitlabProjects.push(project);
|
|
} else {
|
|
this._uncategorizedProjects.push(project);
|
|
}
|
|
})
|
|
}
|
|
|
|
gitlabProjects(): Array<Project> {
|
|
this.filterProjects();
|
|
return this._gitlabProjects;
|
|
}
|
|
|
|
uncategorizedProjects(): Array<Project> {
|
|
this.filterProjects();
|
|
return this._uncategorizedProjects;
|
|
}
|
|
|
|
}
|