started implementation of projects page. currently need to work out cors

This commit is contained in:
Solomon Laing 2021-04-18 21:07:04 +09:30
parent 9d568df286
commit 9a1d147073
17 changed files with 233 additions and 9 deletions

View File

@ -8,8 +8,8 @@ import { Pages } from './shared/models/pages.model';
const routes: Routes = [
{ path: Pages.HOME, component: HomeComponent },
{ path: Pages.PROJECTS, component: ProjectsComponent },
// { path: AppRoutes.CORE, loadChildren: () => import('./galler/gallery.module').then((m) => m.GalleryModule) }, // for future use
{ path: Pages.PROJECTS, loadChildren: () => import('./projects/projects.module').then((m) => m.ProjectsModule) },
// { path: AppRoutes.CORE, loadChildren: () => import('./galler/gallery.module').then((m) => m.GalleryModule) }, // for future use maybe
{ path: Pages.LINKS, component: LinksComponent },
{ path: Pages.PET, component: PetComponent },
{ path: '**', redirectTo: Pages.HOME, pathMatch: 'full' }];

View File

@ -9,8 +9,8 @@ import { FooterComponent } from './footer/footer.component';
import { SharedModule } from './shared/shared.module';
import { HomeComponent } from './home/home.component';
import { LinksComponent } from './links/links.component';
import { ProjectsComponent } from './projects/projects.component';
import { PetComponent } from './pet/pet.component';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
@ -20,13 +20,13 @@ import { PetComponent } from './pet/pet.component';
FooterComponent,
HomeComponent,
LinksComponent,
ProjectsComponent,
PetComponent
],
imports: [
SharedModule,
BrowserModule,
AppRoutingModule
AppRoutingModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]

View File

@ -0,0 +1 @@
<p>project-card works!</p>

View File

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProjectCardComponent } from './project-card.component';
describe('ProjectCardComponent', () => {
let component: ProjectCardComponent;
let fixture: ComponentFixture<ProjectCardComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ProjectCardComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ProjectCardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-project-card',
templateUrl: './project-card.component.html',
styleUrls: ['./project-card.component.scss']
})
export class ProjectCardComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}

View File

@ -0,0 +1 @@
<p>project works!</p>

View File

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProjectComponent } from './project.component';
describe('ProjectComponent', () => {
let component: ProjectComponent;
let fixture: ComponentFixture<ProjectComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ProjectComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ProjectComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-project',
templateUrl: './project.component.html',
styleUrls: ['./project.component.scss']
})
export class ProjectComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}

View File

@ -0,0 +1,21 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ProjectComponent } from './project/project.component';
import { ProjectsComponent } from './projects.component';
const routes: Routes = [
{
path: '',
component: ProjectsComponent
},
{
path: ':id',
component: ProjectComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class ProjectsRoutingModule {}

View File

@ -1 +1,5 @@
<p>projects works!</p>
<h2>Projects on git</h2>
<p>These are my projects as can be found on my <a href="https://gitlab.inkletblot.com/explore">gitlab</a>. Mainly my programming projects that are quality enough for me to be happy for the world to see them. There are more in the works but they are currently private.</p>
<h2>Projects of a personal nature</h2>
<p>This is (will be) a summary of my personal projects be they my homelab, general electronics projects, or anything else.</p>

View File

@ -1,18 +1,37 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Subject } from 'rxjs/internal/Subject';
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 {
export class ProjectsComponent implements OnInit, OnDestroy {
_unsubscribe$: Subject<boolean> = new Subject();
constructor(private navService:NavService) { }
uncategorizedProjects: 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.uncategorizedProjects = result;
});
this.projectsService.getInvoicesToApprove();
}
ngOnDestroy(): void {
this._unsubscribe$.next(false);
this._unsubscribe$.complete();
}
}

View File

@ -0,0 +1,16 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ProjectCardComponent } from './project-card/project-card.component';
import { ProjectComponent } from './project/project.component';
import { ProjectsComponent } from './projects.component';
import { ProjectsRoutingModule } from './projects-routing.module';
@NgModule({
declarations: [ProjectsComponent, ProjectCardComponent, ProjectComponent],
imports: [
CommonModule,
ProjectsRoutingModule
],
providers: []
})
export class ProjectsModule { }

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ProjectsService } from './projects.service';
describe('ProjectsService', () => {
let service: ProjectsService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ProjectsService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,60 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Project } from '../shared/models/project.model';
@Injectable({
providedIn: 'root'
})
export class ProjectsService {
private _allProjects = new BehaviorSubject<Array<Project>>([]);
readonly allProjects$ = this._allProjects.asObservable();
private set allProjects(projects: Array<Project>) {
this._allProjects.next(projects);
}
private get allProjects(): Array<Project> {
return this._allProjects.getValue();
}
private _apiErrored = new BehaviorSubject<boolean>(false);
readonly apiErrored$ = this._apiErrored.asObservable();
private set apiErrored(errored: boolean) {
this._apiErrored.next(errored);
}
private get apiErrored(): boolean {
return this._apiErrored.getValue();
}
/**
* I am actively avoiding any kind of environment management, this is a very basic site and currently this is the only api call.
*/
private PROJECT_API_URL = "https://cms.inkletblot.com/"
constructor(private http: HttpClient) { }
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
getInvoicesToApprove(): void {
this.http
.get(`${this.PROJECT_API_URL}`, this.httpOptions)
.subscribe(
(response: Project[]) => {
if (response) {
this.allProjects = response;
// filter out different categories here currently only one
}
},
(error) => {
this.apiErrored = true;
}
);
}
}

View File

@ -0,0 +1,6 @@
export interface Project {
title: string,
description: string,
ct: string,
body: string
}