woat 6 vuotta sitten
vanhempi
commit
664fb3031d

+ 21
- 7
package-lock.json Näytä tiedosto

@@ -3705,12 +3705,14 @@
3705 3705
         "balanced-match": {
3706 3706
           "version": "1.0.0",
3707 3707
           "bundled": true,
3708
-          "dev": true
3708
+          "dev": true,
3709
+          "optional": true
3709 3710
         },
3710 3711
         "brace-expansion": {
3711 3712
           "version": "1.1.11",
3712 3713
           "bundled": true,
3713 3714
           "dev": true,
3715
+          "optional": true,
3714 3716
           "requires": {
3715 3717
             "balanced-match": "^1.0.0",
3716 3718
             "concat-map": "0.0.1"
@@ -3725,17 +3727,20 @@
3725 3727
         "code-point-at": {
3726 3728
           "version": "1.1.0",
3727 3729
           "bundled": true,
3728
-          "dev": true
3730
+          "dev": true,
3731
+          "optional": true
3729 3732
         },
3730 3733
         "concat-map": {
3731 3734
           "version": "0.0.1",
3732 3735
           "bundled": true,
3733
-          "dev": true
3736
+          "dev": true,
3737
+          "optional": true
3734 3738
         },
3735 3739
         "console-control-strings": {
3736 3740
           "version": "1.1.0",
3737 3741
           "bundled": true,
3738
-          "dev": true
3742
+          "dev": true,
3743
+          "optional": true
3739 3744
         },
3740 3745
         "core-util-is": {
3741 3746
           "version": "1.0.2",
@@ -3852,7 +3857,8 @@
3852 3857
         "inherits": {
3853 3858
           "version": "2.0.3",
3854 3859
           "bundled": true,
3855
-          "dev": true
3860
+          "dev": true,
3861
+          "optional": true
3856 3862
         },
3857 3863
         "ini": {
3858 3864
           "version": "1.3.5",
@@ -3864,6 +3870,7 @@
3864 3870
           "version": "1.0.0",
3865 3871
           "bundled": true,
3866 3872
           "dev": true,
3873
+          "optional": true,
3867 3874
           "requires": {
3868 3875
             "number-is-nan": "^1.0.0"
3869 3876
           }
@@ -3878,6 +3885,7 @@
3878 3885
           "version": "3.0.4",
3879 3886
           "bundled": true,
3880 3887
           "dev": true,
3888
+          "optional": true,
3881 3889
           "requires": {
3882 3890
             "brace-expansion": "^1.1.7"
3883 3891
           }
@@ -3885,12 +3893,14 @@
3885 3893
         "minimist": {
3886 3894
           "version": "0.0.8",
3887 3895
           "bundled": true,
3888
-          "dev": true
3896
+          "dev": true,
3897
+          "optional": true
3889 3898
         },
3890 3899
         "minipass": {
3891 3900
           "version": "2.2.4",
3892 3901
           "bundled": true,
3893 3902
           "dev": true,
3903
+          "optional": true,
3894 3904
           "requires": {
3895 3905
             "safe-buffer": "^5.1.1",
3896 3906
             "yallist": "^3.0.0"
@@ -3909,6 +3919,7 @@
3909 3919
           "version": "0.5.1",
3910 3920
           "bundled": true,
3911 3921
           "dev": true,
3922
+          "optional": true,
3912 3923
           "requires": {
3913 3924
             "minimist": "0.0.8"
3914 3925
           }
@@ -3989,7 +4000,8 @@
3989 4000
         "number-is-nan": {
3990 4001
           "version": "1.0.1",
3991 4002
           "bundled": true,
3992
-          "dev": true
4003
+          "dev": true,
4004
+          "optional": true
3993 4005
         },
3994 4006
         "object-assign": {
3995 4007
           "version": "4.1.1",
@@ -4001,6 +4013,7 @@
4001 4013
           "version": "1.4.0",
4002 4014
           "bundled": true,
4003 4015
           "dev": true,
4016
+          "optional": true,
4004 4017
           "requires": {
4005 4018
             "wrappy": "1"
4006 4019
           }
@@ -4122,6 +4135,7 @@
4122 4135
           "version": "1.0.2",
4123 4136
           "bundled": true,
4124 4137
           "dev": true,
4138
+          "optional": true,
4125 4139
           "requires": {
4126 4140
             "code-point-at": "^1.0.0",
4127 4141
             "is-fullwidth-code-point": "^1.0.0",

+ 1
- 1
package.json Näytä tiedosto

@@ -3,7 +3,7 @@
3 3
   "version": "0.0.0",
4 4
   "scripts": {
5 5
     "ng": "ng",
6
-    "start": "ng serve",
6
+    "start": "ng serve --proxy-config proxy.conf.json --port 8081",
7 7
     "build": "ng build",
8 8
     "test": "ng test",
9 9
     "lint": "ng lint",

+ 6
- 0
proxy.conf.json Näytä tiedosto

@@ -0,0 +1,6 @@
1
+{
2
+	"/api/*": {
3
+		"target": "http://192.168.1.216:8080",
4
+		"pathRewrite": {"^/api" : ""}
5
+	}
6
+}

+ 15
- 0
src/app/post.service.spec.ts Näytä tiedosto

@@ -0,0 +1,15 @@
1
+import { TestBed, inject } from '@angular/core/testing';
2
+
3
+import { PostService } from './post.service';
4
+
5
+describe('PostService', () => {
6
+  beforeEach(() => {
7
+    TestBed.configureTestingModule({
8
+      providers: [PostService]
9
+    });
10
+  });
11
+
12
+  it('should be created', inject([PostService], (service: PostService) => {
13
+    expect(service).toBeTruthy();
14
+  }));
15
+});

+ 19
- 0
src/app/post.service.ts Näytä tiedosto

@@ -0,0 +1,19 @@
1
+import { Injectable } from '@angular/core';
2
+import { HttpClient, HttpParams } from '@angular/common/http';
3
+
4
+@Injectable({
5
+	providedIn: 'root'
6
+})
7
+
8
+export class PostService {
9
+
10
+	constructor( private http: HttpClient ) {}
11
+
12
+	getAllPosts() {
13
+		return this.http.get('/api/post/all').toPromise();
14
+	}
15
+
16
+	postPost(messageBody, githubId = 'j-n000') {
17
+		this.http.post(`/api/post/${githubId}/new-post`, { body: messageBody }).toPromise();
18
+	}
19
+}

+ 1
- 1
src/app/timeline/post/post.component.css Näytä tiedosto

@@ -3,5 +3,5 @@
3 3
 }
4 4
 
5 5
 .card {
6
-	max-width: 900px;
6
+	width: 500px;
7 7
 }

+ 6
- 7
src/app/timeline/post/post.component.html Näytä tiedosto

@@ -9,17 +9,16 @@
9 9
 			<div class="media-content">
10 10
 				<div class="content">
11 11
 					<p>
12
-						<strong>Barbara Middleton</strong>
12
+						<strong>{{ post.sender }}</strong>
13 13
 						<br>
14
-						Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis porta eros lacus, nec ultricies elit blandit non. Suspendisse pellentesque mauris sit amet dolor blandit rutrum. Nunc in tempus turpis.
14
+						{{ post.body }}
15 15
 						<br>
16
-						<small><a>Like</a> · <a>Reply</a> · 3 hrs</small>
16
+						<small>{{ post.timestamp }}</small>
17 17
 					</p>
18 18
 				</div>
19
-
20
-				<div class="comment">
21
-					<app-comment></app-comment>
22
-				</div>
19
+				<!-- <div class="comment"> -->
20
+				<!-- 	<app-comment></app-comment> -->
21
+				<!-- </div> -->
23 22
 			</div>
24 23
 		</article>
25 24
 	</div>

+ 3
- 1
src/app/timeline/post/post.component.ts Näytä tiedosto

@@ -1,11 +1,13 @@
1
-import { Component, OnInit } from '@angular/core';
1
+import { Component, Input, OnInit } from '@angular/core';
2 2
 
3 3
 @Component({
4 4
   selector: 'app-post',
5 5
   templateUrl: './post.component.html',
6 6
   styleUrls: ['./post.component.css']
7 7
 })
8
+
8 9
 export class PostComponent implements OnInit {
10
+	@Input()post: any;
9 11
 
10 12
   constructor() { }
11 13
 

+ 7
- 7
src/app/timeline/status/status.component.ts Näytä tiedosto

@@ -1,5 +1,6 @@
1 1
 import { Component, OnInit } from '@angular/core';
2 2
 import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
3
+import { PostService } from '../../post.service';
3 4
 
4 5
 @Component({
5 6
 	selector: 'app-status',
@@ -10,16 +11,15 @@ export class StatusComponent implements OnInit {
10 11
 	sender = 'Origin'; // pull web3.address
11 12
 	body: string;
12 13
 
13
-	constructor(private http: HttpClient) { }
14
+	constructor(
15
+		private http: HttpClient,
16
+		private postService: PostService
17
+	) { }
14 18
 
15 19
 	ngOnInit() {
16 20
 	}
17 21
 
18
-	submit() {
19
-		const headers = new HttpHeaders()
20
-			.set('Content-Type', 'application/json');
21
-
22
-		this.http.post(
23
-			`http://192.168.3.202:6969/post?sender=${this.sender}&body=${this.body}`, {headers}).subscribe(console.log);
22
+	async submit() {
23
+		const response = await this.postService.postPost(this.body);
24 24
 	}
25 25
 }

+ 1
- 0
src/app/timeline/timeline.component.css Näytä tiedosto

@@ -1,6 +1,7 @@
1 1
 .hero.is-fullheight .hero-body.no-vcenter {
2 2
 	align-items: flex-start;
3 3
 }
4
+
4 5
 .container.timeline {
5 6
 	display: flex;
6 7
 	flex-direction: column;

+ 1
- 6
src/app/timeline/timeline.component.html Näytä tiedosto

@@ -3,12 +3,7 @@
3 3
 		<div class="container">
4 4
 			<app-status></app-status>
5 5
 			<div class="container timeline">
6
-			<app-post></app-post>
7
-			<app-post></app-post>
8
-			<app-post></app-post>
9
-			<app-post></app-post>
10
-			<app-post></app-post>
11
-			<app-post></app-post>
6
+				<app-post *ngFor="let post of posts" [post]="post"></app-post>
12 7
 			</div>
13 8
 		</div>
14 9
 	</div>

+ 15
- 6
src/app/timeline/timeline.component.ts Näytä tiedosto

@@ -1,15 +1,24 @@
1 1
 import { Component, OnInit } from '@angular/core';
2
+import { PostService } from '../post.service';
2 3
 
3 4
 @Component({
4
-  selector: 'app-timeline',
5
-  templateUrl: './timeline.component.html',
6
-  styleUrls: ['./timeline.component.css']
5
+	selector: 'app-timeline',
6
+	templateUrl: './timeline.component.html',
7
+	styleUrls: ['./timeline.component.css']
7 8
 })
8 9
 export class TimelineComponent implements OnInit {
10
+	posts: any;
9 11
 
10
-  constructor() { }
12
+	constructor( private postService: PostService ) { }
11 13
 
12
-  ngOnInit() {
13
-  }
14
+	ngOnInit() {
15
+		this.getAllPostsFromService();
16
+	}
17
+
18
+	async getAllPostsFromService() {
19
+		const posts = await this.postService.getAllPosts();
20
+		this.posts = posts;
21
+		console.log(posts);
22
+	}
14 23
 
15 24
 }