Working on it...

This commit is contained in:
Joachim Nielandt 2018-03-04 14:46:53 +01:00
parent e6810b476f
commit 29828e6838
6 changed files with 59 additions and 4 deletions

View File

@ -9,6 +9,8 @@ import { PostComponent } from './components/post/post.component';
import { DataloaderService } from 'app/services/dataloader.service'; import { DataloaderService } from 'app/services/dataloader.service';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { CvComponent } from './components/cv/cv.component'; import { CvComponent } from './components/cv/cv.component';
import { PostpipePipe } from './pipes/postpipe.pipe';
import { PosttypepipePipe } from './pipes/posttypepipe.pipe';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -16,7 +18,9 @@ import { CvComponent } from './components/cv/cv.component';
HomeComponent, HomeComponent,
PostsComponent, PostsComponent,
PostComponent, PostComponent,
CvComponent CvComponent,
PostpipePipe,
PosttypepipePipe
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

View File

@ -1,9 +1,13 @@
<div class="alert alert-secondary" role="alert"> <!-- <div class="alert alert-secondary" role="alert">
All the previously made posts are shown below. All the previously made posts are shown below.
</div> </div>
-->
<div class="btn-group" role="group" aria-label="Categories">
<button type="button" class="btn btn-secondary">All</button>
<button *ngFor='let postType of postTypes | async' type="button" class="btn btn-secondary">{{postType}}</button>
</div>
<!-- <div *ngFor='let post of posts | async'> {{post.filename}} </div> -->
<div> <div>
<app-post *ngFor='let post of posts | async' [post]="post"></app-post> <app-post *ngFor='let post of posts | async' [post]="post"></app-post>
</div> </div>

View File

@ -3,6 +3,12 @@ import { DataloaderService } from 'app/services/dataloader.service';
import { Post } from '../../model/post'; import { Post } from '../../model/post';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/merge';
import 'rxjs/add/operator/concatMap';
import 'rxjs/add/observable/from';
import 'rxjs/add/operator/distinct';
@Component({ @Component({
selector: 'app-posts', selector: 'app-posts',
templateUrl: './posts.component.html', templateUrl: './posts.component.html',
@ -10,6 +16,7 @@ import { Observable } from 'rxjs/Observable';
}) })
export class PostsComponent implements OnInit { export class PostsComponent implements OnInit {
postTypes: Observable<String[]>;
posts:Observable<Post[]>; posts:Observable<Post[]>;
constructor(private dataloaderService:DataloaderService) { } constructor(private dataloaderService:DataloaderService) { }
@ -17,6 +24,25 @@ export class PostsComponent implements OnInit {
ngOnInit() { ngOnInit() {
//fetch the posts //fetch the posts
this.posts = this.dataloaderService.getPosts(); this.posts = this.dataloaderService.getPosts();
this.postTypes = this.getPostTypes();
this.postTypes.subscribe(test=>{
console.log('result of subscribe: '+test);
});
} }
getPostTypes():Observable<String[]> {
return this.posts.map(posts=>{
let result = new Set<String>();
for(let post of posts) {
result.add(post.type);
}
console.log('got these post types!');
console.log(result);
return Array.from(result);
});
}
filterOnType(type:String): void {
}
} }

View File

@ -0,0 +1,8 @@
import { PosttypepipePipe } from './posttypepipe.pipe';
describe('PosttypepipePipe', () => {
it('create an instance', () => {
const pipe = new PosttypepipePipe();
expect(pipe).toBeTruthy();
});
});

View File

@ -0,0 +1,13 @@
import { Pipe, PipeTransform } from '@angular/core';
import { Post } from 'app/model/post';
@Pipe({
name: 'posttypepipe'
})
export class PosttypepipePipe implements PipeTransform {
transform(posts: Post[], args?: any): any {
return posts.filter(post=>post.type == args);
}
}

View File

@ -1,3 +1,3 @@
<p>It's been on my mind for a while now to create an oldschool homepage. So, here it is. An homage to the old and tried Web 1.0, whoever thought static webpages were done and dusted is <em>wrong</em>! This will be a collection of some technical things I want to remind myself about so I don't have to look them up again and again, miscellaneous pictures of projects (in-progress or done) or anything that comes to mind I'd like to share on something other than the usual social media suspects.</p> <p>It's been on my mind for a while now to create an oldschool homepage. So, here it is. An homage to the old and tried Web 1.0, whoever thought static webpages were done and dusted is <em>wrong</em>! This will be a collection of some technical things I want to remind myself about so I don't have to look them up again and again, miscellaneous pictures of projects (in-progress or done) or anything that comes to mind I'd like to share on something other than the usual social media suspects.</p>
<p>Besides, it's nice to have an Angular2/Bootstrap playground to test some stuff out. I'll probably update this thing once in a while. Maybe even use a database, wouldn't that be something...</p> <p>Besides, it's nice to have a minimalistic Angular2/Bootstrap playground to test some stuff out. I'll probably update this thing once in a while. Maybe even use a database, wouldn't that be something...</p>