|
@@ -1,23 +1,64 @@
|
1
|
|
-import { Component } from '@angular/core';
|
|
1
|
+import { Component, OnInit } from '@angular/core';
|
2
|
2
|
import { PostService } from 'app/entities/post';
|
3
|
3
|
import { IPost } from 'app/shared/model/post.model';
|
4
|
|
-import { IUser } from 'app/core';
|
|
4
|
+import { IUser, Principal } from 'app/core';
|
5
|
5
|
import { Observable } from 'rxjs';
|
6
|
6
|
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
|
7
|
+import { JhiAlertService } from 'ng-jhipster';
|
7
|
8
|
|
8
|
9
|
@Component({
|
9
|
10
|
selector: 'jhi-profile-head',
|
10
|
11
|
templateUrl: './profile-head.component.html',
|
11
|
12
|
styleUrls: ['profile-head.css']
|
12
|
13
|
})
|
13
|
|
-export class ProfileHeadComponent {
|
|
14
|
+export class ProfileHeadComponent implements OnInit {
|
14
|
15
|
str: string;
|
15
|
16
|
post: IPost;
|
16
|
17
|
user: IUser;
|
17
|
18
|
isSaving: boolean;
|
18
|
19
|
testPost: IPost;
|
|
20
|
+ posts: IPost[];
|
19
|
21
|
|
20
|
|
- constructor(private postService: PostService) {}
|
|
22
|
+ constructor(private postService: PostService, private jhiAlertService: JhiAlertService) {}
|
|
23
|
+
|
|
24
|
+ ngOnInit() {
|
|
25
|
+ this.loadAll();
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ trackId(index: number, item: IPost) {
|
|
29
|
+ return item.id;
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ loadAll() {
|
|
33
|
+ this.postService.query().subscribe(
|
|
34
|
+ (res: HttpResponse<IPost[]>) => {
|
|
35
|
+ this.posts = res.body;
|
|
36
|
+ },
|
|
37
|
+ (res: HttpErrorResponse) => this.onError(res.message)
|
|
38
|
+ );
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ private onError(errorMessage: string) {
|
|
42
|
+ this.jhiAlertService.error(errorMessage, null, null);
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ getPost(): void {
|
|
46
|
+ console.log('2');
|
|
47
|
+ this.testPost = new class implements IPost {
|
|
48
|
+ content: string;
|
|
49
|
+ dislikes: number;
|
|
50
|
+ id: number;
|
|
51
|
+ likes: number;
|
|
52
|
+ numberOfComments: number;
|
|
53
|
+ owner: IUser;
|
|
54
|
+ }();
|
|
55
|
+ this.testPost.content = 'This is a test';
|
|
56
|
+ this.testPost.numberOfComments = 0;
|
|
57
|
+ this.testPost.likes = 0;
|
|
58
|
+ this.testPost.dislikes = 0;
|
|
59
|
+ this.testPost.id = 0;
|
|
60
|
+ // this.testPosts.push(this.testPost);
|
|
61
|
+ }
|
21
|
62
|
|
22
|
63
|
submitPost(): void {
|
23
|
64
|
this.post = new class implements IPost {
|
|
@@ -32,15 +73,19 @@ export class ProfileHeadComponent {
|
32
|
73
|
this.post.dislikes = 0;
|
33
|
74
|
this.post.likes = 0;
|
34
|
75
|
this.post.numberOfComments = 0;
|
35
|
|
- if (this.post.content.length > 1) {
|
36
|
|
- this.save(this.post);
|
37
|
|
- }
|
|
76
|
+ this.save(this.post);
|
|
77
|
+ this.str = '';
|
38
|
78
|
}
|
39
|
79
|
|
40
|
80
|
save(post: IPost) {
|
41
|
81
|
this.isSaving = true;
|
42
|
|
- this.subscribeToSaveResponse(this.postService.create(post));
|
43
|
|
- console.log('post created');
|
|
82
|
+ const self = this;
|
|
83
|
+ this.postService
|
|
84
|
+ .create(post)
|
|
85
|
+ .toPromise()
|
|
86
|
+ .then(function(response) {
|
|
87
|
+ self.loadAll();
|
|
88
|
+ });
|
44
|
89
|
}
|
45
|
90
|
|
46
|
91
|
private subscribeToSaveResponse(result: Observable<HttpResponse<IPost>>) {
|