Working on it...
This commit is contained in:
parent
e6810b476f
commit
29828e6838
@ -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,
|
||||||
|
|||||||
@ -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>
|
||||||
@ -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 {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
src/app/pipes/posttypepipe.pipe.spec.ts
Normal file
8
src/app/pipes/posttypepipe.pipe.spec.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { PosttypepipePipe } from './posttypepipe.pipe';
|
||||||
|
|
||||||
|
describe('PosttypepipePipe', () => {
|
||||||
|
it('create an instance', () => {
|
||||||
|
const pipe = new PosttypepipePipe();
|
||||||
|
expect(pipe).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
13
src/app/pipes/posttypepipe.pipe.ts
Normal file
13
src/app/pipes/posttypepipe.pipe.ts
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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>
|
||||||
Loading…
Reference in New Issue
Block a user