From 1f008dfc777022582e5e0cf0823175e66c2790cf Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sat, 6 Mar 2021 14:43:32 +0200 Subject: starting development of rating system --- .vs/slnx.sqlite | Bin 0 -> 155648 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .vs/slnx.sqlite (limited to '.vs/slnx.sqlite') diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..fb0acc2 Binary files /dev/null and b/.vs/slnx.sqlite differ -- cgit v1.2.3 From fe4c9eaeac345c63e0c08c43b9dc3185d07716e8 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Thu, 11 Mar 2021 21:09:47 +0200 Subject: Post rating shows current rating(not static number) --- .vs/DevHive-Angular/v16/.suo | Bin 23552 -> 32256 bytes .vs/VSWorkspaceState.json | 9 +++++++-- .vs/slnx.sqlite | Bin 155648 -> 167936 bytes src/app/components/post/post.component.ts | 2 +- src/models/post.ts | 11 ++++++++++- 5 files changed, 18 insertions(+), 4 deletions(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo index 6166dc6..c5248df 100644 Binary files a/.vs/DevHive-Angular/v16/.suo and b/.vs/DevHive-Angular/v16/.suo differ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index 5023c47..6e9e1ba 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -1,8 +1,13 @@ { "ExpandedNodes": [ "", - "\\src" + "\\e2e\\src", + "\\src", + "\\src\\app", + "\\src\\app\\components", + "\\src\\app\\components\\post", + "\\src\\app\\services" ], - "SelectedNode": "\\src\\main.ts", + "SelectedNode": "\\src\\app\\services\\rating.service.ts", "PreviewInSolutionExplorer": false } \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index fb0acc2..d413bfa 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index 39391ad..f813d8c 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -31,7 +31,7 @@ export class PostComponent implements OnInit { (result: object) => { Object.assign(this.post, result); this.post.fileURLs = Object.values(result)[7]; - this.votesNumber = 23; + this.votesNumber = this.post.currentRating; this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB'); this.loadUser(); diff --git a/src/models/post.ts b/src/models/post.ts index 8e58bea..8c1890a 100644 --- a/src/models/post.ts +++ b/src/models/post.ts @@ -11,8 +11,9 @@ export class Post { private _timeCreated: Date; private _comments: PostComment[]; private _fileURLs: string[]; + private _currentRating: number; - constructor(postId: Guid, creatorFirstName: string, creatorLastName: string, creatorUsername: string, message: string, timeCreated: Date, comments: PostComment[], fileURLs: string[]) { + constructor(postId: Guid, creatorFirstName: string, creatorLastName: string, creatorUsername: string, message: string, timeCreated: Date, comments: PostComment[], fileURLs: string[], currentRating: number) { this.postId = postId; this.creatorFirstName = creatorFirstName; this.creatorLastName = creatorLastName; @@ -21,6 +22,7 @@ export class Post { this.timeCreated = timeCreated; this.comments = comments; this.fileURLs = fileURLs; + this.currentRating = currentRating; } public get postId(): Guid { @@ -78,4 +80,11 @@ export class Post { public set fileURLs(v: string[]) { this._fileURLs = v; } + + public get currentRating(): number { + return this._currentRating; + } + public set currentRating(v: number) { + this._currentRating = v; + } } -- cgit v1.2.3 From 051da12e0edd5408c902695fbc45ddd15d7972b1 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Thu, 11 Mar 2021 21:57:16 +0200 Subject: added upvote post functionality --- .vs/DevHive-Angular/v16/.suo | Bin 32256 -> 32256 bytes .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/app-constants.module.ts | 1 + src/app/components/post/post.component.ts | 17 +++++++++++++++-- src/app/services/post.service.ts | 2 +- src/app/services/rating.service.ts | 20 ++++++++++++++++++++ 6 files changed, 37 insertions(+), 3 deletions(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo index c5248df..eb32805 100644 Binary files a/.vs/DevHive-Angular/v16/.suo and b/.vs/DevHive-Angular/v16/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index d413bfa..a563275 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/app-constants.module.ts b/src/app/app-constants.module.ts index d72af53..f8722f7 100644 --- a/src/app/app-constants.module.ts +++ b/src/app/app-constants.module.ts @@ -9,6 +9,7 @@ export class AppConstants { public static API_TECHNOLOGY_URL = AppConstants.BASE_API_URL + '/Technology'; public static API_POST_URL = AppConstants.BASE_API_URL + '/Post'; + public static API_RATING_URL = AppConstants.BASE_API_URL + '/Rating'; public static API_FEED_URL = AppConstants.BASE_API_URL + '/Feed'; public static API_COMMENT_URL = AppConstants.BASE_API_URL + '/Comment'; diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index f813d8c..0f48337 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -6,6 +6,7 @@ import { RatingService } from 'src/app/services/rating.service'; import { UserService } from 'src/app/services/user.service'; import { User } from 'src/models/identity/user'; import { Post } from 'src/models/post'; +import { TokenService } from '../../services/token.service'; @Component({ selector: 'app-post', @@ -19,11 +20,14 @@ export class PostComponent implements OnInit { public votesNumber: number; public timeCreated: string; @Input() paramId: string; + public loggedIn = false; - constructor(private _postService: PostService, private _ratingServe: RatingService, private _userService: UserService, private _router: Router) + constructor(private _postService: PostService, private _ratingServe: RatingService, private _userService: UserService, private _router: Router, private _tokenService: TokenService) { } ngOnInit(): void { + this.loggedIn = this._tokenService.getTokenFromSessionStorage() !== ''; + this.post = this._postService.getDefaultPost(); this.user = this._userService.getDefaultUser(); @@ -57,6 +61,15 @@ export class PostComponent implements OnInit { } upVotePost(): void { - + if (!this.loggedIn) { + this._router.navigate(['/login']); + return; + } + + this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe( + () => { + this.votesNumber++; + } + ); } } diff --git a/src/app/services/post.service.ts b/src/app/services/post.service.ts index 7b2a539..d582085 100644 --- a/src/app/services/post.service.ts +++ b/src/app/services/post.service.ts @@ -15,7 +15,7 @@ export class PostService { { } getDefaultPost(): Post { - return new Post(Guid.createEmpty(), 'Gosho', 'Trapov', 'gosho_trapov', 'Your opinion on my idea?', new Date(), [], []); + return new Post(Guid.createEmpty(), 'Gosho', 'Trapov', 'gosho_trapov', 'Your opinion on my idea?', new Date(), [], [], 0); } /* Requests from session storage */ diff --git a/src/app/services/rating.service.ts b/src/app/services/rating.service.ts index 630a43c..5a86b67 100644 --- a/src/app/services/rating.service.ts +++ b/src/app/services/rating.service.ts @@ -14,4 +14,24 @@ import { TokenService } from './token.service'; export class RatingService { constructor(private _http: HttpClient, private _tokenService: TokenService) { } + + createRatingWithSessionStorageRequest(postId: Guid, isLike: boolean): Observable { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.createRatingRequest(userId, token, postId, isLike); + } + + createRatingRequest(userId: Guid, authToken: string, postId: Guid, isLike: boolean): Observable { + const body = { + postId: postId.toString(), + isLike: isLike + }; + const options = { + params: new HttpParams().set('UserId', userId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + + return this._http.post(AppConstants.API_RATING_URL, body, options); + } } -- cgit v1.2.3 From afeba5e832d87bc659d72e7d945a78821bd7e7b8 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Fri, 12 Mar 2021 21:16:34 +0200 Subject: adding downVote functionality --- .vs/DevHive-Angular/v16/.suo | Bin 32256 -> 52736 bytes .vs/VSWorkspaceState.json | 5 ++-- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/post/post.component.html | 2 +- src/app/components/post/post.component.ts | 35 ++++++++++++++++++++++++++++ src/app/services/rating.service.ts | 27 +++++++++++++++++---- 6 files changed, 61 insertions(+), 8 deletions(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo index eb32805..ceaae10 100644 Binary files a/.vs/DevHive-Angular/v16/.suo and b/.vs/DevHive-Angular/v16/.suo differ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index 6e9e1ba..c78c053 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -1,12 +1,11 @@ { "ExpandedNodes": [ "", - "\\e2e\\src", "\\src", "\\src\\app", "\\src\\app\\components", - "\\src\\app\\components\\post", - "\\src\\app\\services" + "\\src\\app\\services", + "\\src\\models" ], "SelectedNode": "\\src\\app\\services\\rating.service.ts", "PreviewInSolutionExplorer": false diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index a563275..5dcda80 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/components/post/post.component.html b/src/app/components/post/post.component.html index 4584591..830fa75 100644 --- a/src/app/components/post/post.component.html +++ b/src/app/components/post/post.component.html @@ -36,7 +36,7 @@ {{ votesNumber }} - diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index 0f48337..168b6a3 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -66,10 +66,45 @@ export class PostComponent implements OnInit { return; } + this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe( + () => { + this.votesNumber += 2; + }, + () => { + this.crateUpVoteRating(); + } + ); + } + + crateUpVoteRating(): void { this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe( () => { this.votesNumber++; } ); } + + downVotePost(): void { + if (!this.loggedIn) { + this._router.navigate(['/login']); + return; + } + + this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe( + () => { + this.votesNumber -= 2; + }, + () => { + this.crateDownVoteRating(); + } + ); + } + + crateDownVoteRating(): void { + this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe( + () => { + this.votesNumber--; + } + ); + } } diff --git a/src/app/services/rating.service.ts b/src/app/services/rating.service.ts index 5a86b67..9403575 100644 --- a/src/app/services/rating.service.ts +++ b/src/app/services/rating.service.ts @@ -22,16 +22,35 @@ export class RatingService { return this.createRatingRequest(userId, token, postId, isLike); } + putRatingWithSessionStorageRequest(postId: Guid, isLike: boolean): Observable { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.putRatingRequest(userId, token, postId, isLike); + } + createRatingRequest(userId: Guid, authToken: string, postId: Guid, isLike: boolean): Observable { + const options = { + params: new HttpParams().set('UserId', userId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; const body = { postId: postId.toString(), isLike: isLike - }; + }; + + return this._http.post(AppConstants.API_RATING_URL, body, options); + } + + putRatingRequest(userId: Guid, authToken: string, postId: Guid, isLike: boolean): Observable { const options = { - params: new HttpParams().set('UserId', userId.toString()), - headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + params: new HttpParams().set('UserId', userId.toString()).set('PostId', postId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + const body = { + isLike: isLike }; - return this._http.post(AppConstants.API_RATING_URL, body, options); + return this._http.put(AppConstants.API_RATING_URL, body, options); } } -- cgit v1.2.3 From 531ce1bbda5f3909a0701b14377ae08b5c1993cb Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Fri, 12 Mar 2021 21:30:18 +0200 Subject: adding functionality to get rating by userid and postId in rating service --- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/services/rating.service.ts | 16 ++++++++++++++++ 2 files changed, 16 insertions(+) (limited to '.vs/slnx.sqlite') diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 5dcda80..9e7e654 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/services/rating.service.ts b/src/app/services/rating.service.ts index 9403575..f3e3265 100644 --- a/src/app/services/rating.service.ts +++ b/src/app/services/rating.service.ts @@ -29,6 +29,13 @@ export class RatingService { return this.putRatingRequest(userId, token, postId, isLike); } + getRatingByUserAndPostWithSessionStorageRequest(postId: Guid): Observable { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.getRatingByUserAndPostRequest(userId, token, postId); + } + createRatingRequest(userId: Guid, authToken: string, postId: Guid, isLike: boolean): Observable { const options = { params: new HttpParams().set('UserId', userId.toString()), @@ -53,4 +60,13 @@ export class RatingService { return this._http.put(AppConstants.API_RATING_URL, body, options); } + + getRatingByUserAndPostRequest(userId: Guid, authToken: string, postId: Guid): Observable { + const options = { + params: new HttpParams().set('UserId', userId.toString()).set('PostId', postId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + + return this._http.get(AppConstants.API_RATING_URL + 'GetByUserAndPost', options); + } } -- cgit v1.2.3 From 2ea7a39c3f8eaf90ec28f8fd6fc465f215a0d99b Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sat, 13 Mar 2021 11:46:57 +0200 Subject: upVote functionality is finished --- .vs/DevHive-Angular/v16/.suo | Bin 52736 -> 62976 bytes .vs/VSWorkspaceState.json | 3 +- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/post/post.component.ts | 71 ++++++++++++++++++++---------- src/app/services/rating.service.ts | 18 +++++++- 5 files changed, 66 insertions(+), 26 deletions(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo index ceaae10..6b50c82 100644 Binary files a/.vs/DevHive-Angular/v16/.suo and b/.vs/DevHive-Angular/v16/.suo differ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index c78c053..9d81b57 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -4,9 +4,10 @@ "\\src", "\\src\\app", "\\src\\app\\components", + "\\src\\app\\components\\post", "\\src\\app\\services", "\\src\\models" ], - "SelectedNode": "\\src\\app\\services\\rating.service.ts", + "SelectedNode": "\\src\\app\\components\\post\\post.component.ts", "PreviewInSolutionExplorer": false } \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 9e7e654..e79a43d 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index 168b6a3..68bf161 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -22,8 +22,7 @@ export class PostComponent implements OnInit { @Input() paramId: string; public loggedIn = false; - constructor(private _postService: PostService, private _ratingServe: RatingService, private _userService: UserService, private _router: Router, private _tokenService: TokenService) - { } + constructor(private _postService: PostService, private _ratingServe: RatingService, private _userService: UserService, private _router: Router, private _tokenService: TokenService) { } ngOnInit(): void { this.loggedIn = this._tokenService.getTokenFromSessionStorage() !== ''; @@ -66,45 +65,69 @@ export class PostComponent implements OnInit { return; } - this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe( - () => { - this.votesNumber += 2; + this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe( + (x: object) => { + if (Object.values(x)[3]) { + this.deleteUpVoteRating(Object.values(x)[0]); + } + else { + this.putUpVoteRating(); + } }, () => { this.crateUpVoteRating(); } - ); - } - - crateUpVoteRating(): void { - this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe( - () => { - this.votesNumber++; - } ); } - - downVotePost(): void { - if (!this.loggedIn) { - this._router.navigate(['/login']); - return; + + crateUpVoteRating(): void { + this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe( + () => { + this.votesNumber++; } + ); +} - this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe( + putUpVoteRating(): void { + this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe( () => { - this.votesNumber -= 2; + this.votesNumber += 2; }, () => { - this.crateDownVoteRating(); + this.crateUpVoteRating(); } - ); + ); } - crateDownVoteRating(): void { - this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe( + deleteUpVoteRating(ratingId: string): void { + this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(ratingId)).subscribe( () => { this.votesNumber--; } ); } + + downVotePost(): void { + if(!this.loggedIn) { + this._router.navigate(['/login']); + return; +} + +this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe( + () => { + this.votesNumber -= 2; + }, + () => { + this.crateDownVoteRating(); + } +); + } + + crateDownVoteRating(): void { + this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe( + () => { + this.votesNumber--; + } + ); +} } diff --git a/src/app/services/rating.service.ts b/src/app/services/rating.service.ts index f3e3265..58ff1f4 100644 --- a/src/app/services/rating.service.ts +++ b/src/app/services/rating.service.ts @@ -36,6 +36,13 @@ export class RatingService { return this.getRatingByUserAndPostRequest(userId, token, postId); } + deleteRatingFromSessionStorageRequest(ratingId: Guid): Observable { + const userId = this._tokenService.getUserIdFromSessionStorageToken(); + const token = this._tokenService.getTokenFromSessionStorage(); + + return this.deleteRatingRequest(userId, token, ratingId); + } + createRatingRequest(userId: Guid, authToken: string, postId: Guid, isLike: boolean): Observable { const options = { params: new HttpParams().set('UserId', userId.toString()), @@ -67,6 +74,15 @@ export class RatingService { headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) }; - return this._http.get(AppConstants.API_RATING_URL + 'GetByUserAndPost', options); + return this._http.get(AppConstants.API_RATING_URL + '/GetByUserAndPost', options); + } + + deleteRatingRequest(userId: Guid, authToken: string, ratingId: Guid): Observable { + const options = { + params: new HttpParams().set('UserId', userId.toString()).set('RatingId', ratingId.toString()), + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + + return this._http.delete(AppConstants.API_RATING_URL, options); } } -- cgit v1.2.3 From 98d4f0e3a0fc8fd8d753617a2b681a18f8a60e2b Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sat, 13 Mar 2021 12:02:56 +0200 Subject: adding downVote functionality --- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/post/post.component.ts | 75 ++++++++++++++---------------- 2 files changed, 35 insertions(+), 40 deletions(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index e79a43d..2061481 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index 68bf161..1ec9232 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -68,66 +68,61 @@ export class PostComponent implements OnInit { this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe( (x: object) => { if (Object.values(x)[3]) { - this.deleteUpVoteRating(Object.values(x)[0]); + this.deleteRating(Object.values(x)[0], true); } else { - this.putUpVoteRating(); + this.putRating(true); } }, () => { - this.crateUpVoteRating(); + this.crateRating(true); } ); } - - crateUpVoteRating(): void { - this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe( - () => { - this.votesNumber++; + + downVotePost(): void { + if (!this.loggedIn) { + this._router.navigate(['/login']); + return; } - ); -} - putUpVoteRating(): void { - this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), true).subscribe( - () => { - this.votesNumber += 2; + this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe( + (x: object) => { + if (!Object.values(x)[3]) { + this.deleteRating(Object.values(x)[0], false); + } + else { + this.putRating(false); + } }, () => { - this.crateUpVoteRating(); + this.crateRating(false); } ); } - deleteUpVoteRating(ratingId: string): void { - this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(ratingId)).subscribe( + crateRating(isLike: boolean): void { + this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), isLike).subscribe( + () => { + this.votesNumber += -1 + Number(isLike) * 2; + } + ); +} + + putRating(isLike: boolean): void { + this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), isLike).subscribe( () => { - this.votesNumber--; + // when false -2 + 0 wjen true -2 + 4 + this.votesNumber += -2 + Number(isLike) * 4; } ); } - downVotePost(): void { - if(!this.loggedIn) { - this._router.navigate(['/login']); - return; -} - -this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe( - () => { - this.votesNumber -= 2; - }, - () => { - this.crateDownVoteRating(); - } -); + deleteRating(ratingId: string, isLike: boolean): void { + this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(ratingId)).subscribe( + () => { + this.votesNumber += 1 - Number(isLike) * 2; + } + ); } - - crateDownVoteRating(): void { - this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), false).subscribe( - () => { - this.votesNumber--; - } - ); -} } -- cgit v1.2.3 From 341aafe72c96cad41bc5b8f1bdf665c4f2cd5319 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sat, 13 Mar 2021 12:08:44 +0200 Subject: improved rating system --- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/post/post.component.html | 4 ++-- src/app/components/post/post.component.ts | 31 +++++----------------------- 3 files changed, 7 insertions(+), 28 deletions(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 2061481..6561dfb 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/components/post/post.component.html b/src/app/components/post/post.component.html index 830fa75..1603ebf 100644 --- a/src/app/components/post/post.component.html +++ b/src/app/components/post/post.component.html @@ -30,13 +30,13 @@
- {{ votesNumber }} -
diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index 1ec9232..0be3c43 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -59,7 +59,7 @@ export class PostComponent implements OnInit { this._router.navigate(['/post/' + this.post.postId]); } - upVotePost(): void { + votePost(isLike: boolean): void { if (!this.loggedIn) { this._router.navigate(['/login']); return; @@ -67,36 +67,15 @@ export class PostComponent implements OnInit { this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe( (x: object) => { - if (Object.values(x)[3]) { - this.deleteRating(Object.values(x)[0], true); + if (Object.values(x)[3] === isLike) { + this.deleteRating(Object.values(x)[0], isLike); } else { - this.putRating(true); + this.putRating(isLike); } }, () => { - this.crateRating(true); - } - ); - } - - downVotePost(): void { - if (!this.loggedIn) { - this._router.navigate(['/login']); - return; - } - - this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe( - (x: object) => { - if (!Object.values(x)[3]) { - this.deleteRating(Object.values(x)[0], false); - } - else { - this.putRating(false); - } - }, - () => { - this.crateRating(false); + this.crateRating(isLike); } ); } -- cgit v1.2.3 From 986ca08271fe0b8fed9e7934d3fd221c2e8b5495 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sat, 13 Mar 2021 12:46:13 +0200 Subject: added functionality to hightlit the rating button clicked by the user --- .vs/DevHive-Angular/v16/.suo | Bin 62976 -> 62976 bytes .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/post/post.component.ts | 21 ++++++++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo index 6b50c82..7c63106 100644 Binary files a/.vs/DevHive-Angular/v16/.suo and b/.vs/DevHive-Angular/v16/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 6561dfb..c62291d 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index 0be3c43..b2742c0 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -21,6 +21,7 @@ export class PostComponent implements OnInit { public timeCreated: string; @Input() paramId: string; public loggedIn = false; + private voteBtns: HTMLCollectionOf; constructor(private _postService: PostService, private _ratingServe: RatingService, private _userService: UserService, private _router: Router, private _tokenService: TokenService) { } @@ -36,8 +37,10 @@ export class PostComponent implements OnInit { this.post.fileURLs = Object.values(result)[7]; this.votesNumber = this.post.currentRating; + this.voteBtns = document.getElementsByClassName('vote') as HTMLCollectionOf; + this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB'); - this.loadUser(); + this.loadUser(); } ); } @@ -69,18 +72,26 @@ export class PostComponent implements OnInit { (x: object) => { if (Object.values(x)[3] === isLike) { this.deleteRating(Object.values(x)[0], isLike); + + this.voteBtns.item(Number(!isLike))!.style.backgroundColor = 'white'; + this.voteBtns.item(Number(isLike))!.style.backgroundColor = 'white'; } else { this.putRating(isLike); + + this.voteBtns.item(Number(!isLike))!.style.backgroundColor = 'lightblue'; + this.voteBtns.item(Number(isLike))!.style.backgroundColor = 'white'; } }, () => { - this.crateRating(isLike); + this.createRating(isLike); + + this.voteBtns.item(Number(!isLike))!.style.backgroundColor = 'lightblue'; } ); } - crateRating(isLike: boolean): void { + private createRating(isLike: boolean): void { this._ratingServe.createRatingWithSessionStorageRequest(Guid.parse(this.paramId), isLike).subscribe( () => { this.votesNumber += -1 + Number(isLike) * 2; @@ -88,7 +99,7 @@ export class PostComponent implements OnInit { ); } - putRating(isLike: boolean): void { + private putRating(isLike: boolean): void { this._ratingServe.putRatingWithSessionStorageRequest(Guid.parse(this.paramId), isLike).subscribe( () => { // when false -2 + 0 wjen true -2 + 4 @@ -97,7 +108,7 @@ export class PostComponent implements OnInit { ); } - deleteRating(ratingId: string, isLike: boolean): void { + private deleteRating(ratingId: string, isLike: boolean): void { this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(ratingId)).subscribe( () => { this.votesNumber += 1 - Number(isLike) * 2; -- cgit v1.2.3 From 8419a8e403abf5b25e3b53655cfafabf4eb30a3e Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sat, 13 Mar 2021 12:54:58 +0200 Subject: Updated the highlight functionality --- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/post/post.component.ts | 13 ++++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index c62291d..6863014 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index b2742c0..bf43a83 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -73,20 +73,18 @@ export class PostComponent implements OnInit { if (Object.values(x)[3] === isLike) { this.deleteRating(Object.values(x)[0], isLike); - this.voteBtns.item(Number(!isLike))!.style.backgroundColor = 'white'; - this.voteBtns.item(Number(isLike))!.style.backgroundColor = 'white'; + this.changeColorOfVoteButton(false, false); } else { this.putRating(isLike); - this.voteBtns.item(Number(!isLike))!.style.backgroundColor = 'lightblue'; - this.voteBtns.item(Number(isLike))!.style.backgroundColor = 'white'; + this.changeColorOfVoteButton(isLike, !isLike); } }, () => { this.createRating(isLike); - this.voteBtns.item(Number(!isLike))!.style.backgroundColor = 'lightblue'; + this.changeColorOfVoteButton(isLike, !isLike); } ); } @@ -115,4 +113,9 @@ export class PostComponent implements OnInit { } ); } + + private changeColorOfVoteButton(isUpvoted: boolean, isDownvoted: boolean): void { + this.voteBtns.item(0)!.style.backgroundColor = (isUpvoted) ? 'lightblue' : 'white'; + this.voteBtns.item(1)!.style.backgroundColor = (isDownvoted) ? 'lightblue' : 'white'; + } } -- cgit v1.2.3 From 07c30c0896de316119b188c9e62f4666bf0cb2a9 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sun, 14 Mar 2021 20:03:39 +0200 Subject: added functionality to highlight buttons on init --- .vs/DevHive-Angular/v16/.suo | Bin 62976 -> 65024 bytes .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/post/post.component.ts | 24 ++++++++++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/DevHive-Angular/v16/.suo b/.vs/DevHive-Angular/v16/.suo index 7c63106..60e79b7 100644 Binary files a/.vs/DevHive-Angular/v16/.suo and b/.vs/DevHive-Angular/v16/.suo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 6863014..8f7e0c6 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index bf43a83..572ad9c 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -34,15 +34,23 @@ export class PostComponent implements OnInit { this._postService.getPostRequest(Guid.parse(this.paramId)).subscribe( (result: object) => { Object.assign(this.post, result); + + console.log(this.post.postId); + this.post.fileURLs = Object.values(result)[7]; this.votesNumber = this.post.currentRating; this.voteBtns = document.getElementsByClassName('vote') as HTMLCollectionOf; - this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB'); + this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB'); + this.loadUser(); } ); + + window.addEventListener("load", () => { + this.highlightButtonsOnInit(); + }); } private loadUser(): void { @@ -107,7 +115,7 @@ export class PostComponent implements OnInit { } private deleteRating(ratingId: string, isLike: boolean): void { - this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(ratingId)).subscribe( + this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(this.paramId)).subscribe( () => { this.votesNumber += 1 - Number(isLike) * 2; } @@ -118,4 +126,16 @@ export class PostComponent implements OnInit { this.voteBtns.item(0)!.style.backgroundColor = (isUpvoted) ? 'lightblue' : 'white'; this.voteBtns.item(1)!.style.backgroundColor = (isDownvoted) ? 'lightblue' : 'white'; } + + private highlightButtonsOnInit(): void { + this._ratingServe.getRatingByUserAndPostWithSessionStorageRequest(Guid.parse(this.paramId)).subscribe( + (x: object) => { + const isLike: boolean = Object.values(x)[3]; + + console.log(this.voteBtns); + + this.changeColorOfVoteButton(isLike, !isLike); + } + ); + } } -- cgit v1.2.3 From b428eaddb497ac0edc97020c310fa72eeab82e7e Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sun, 14 Mar 2021 20:04:36 +0200 Subject: fixed a bug when rating should be deleted --- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/post/post.component.ts | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 8f7e0c6..8b6d17b 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index 572ad9c..89620d7 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -115,7 +115,7 @@ export class PostComponent implements OnInit { } private deleteRating(ratingId: string, isLike: boolean): void { - this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(this.paramId)).subscribe( + this._ratingServe.deleteRatingFromSessionStorageRequest(Guid.parse(ratingId)).subscribe( () => { this.votesNumber += 1 - Number(isLike) * 2; } -- cgit v1.2.3 From afe30ab78432d16c42b2f19e3bd8355e3f27a0e1 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Sun, 14 Mar 2021 21:06:33 +0200 Subject: fixed rating not beeing highlighted on init and and added capability of rating to handle multiple posts --- .vs/slnx.sqlite | Bin 167936 -> 167936 bytes src/app/components/feed/feed.component.html | 4 ++-- src/app/components/post/post.component.ts | 20 ++++++++------------ src/app/components/profile/profile.component.html | 4 ++-- 4 files changed, 12 insertions(+), 16 deletions(-) (limited to '.vs/slnx.sqlite') diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 8b6d17b..36ca8dd 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/src/app/components/feed/feed.component.html b/src/app/components/feed/feed.component.html index 230c27b..5ff2dca 100644 --- a/src/app/components/feed/feed.component.html +++ b/src/app/components/feed/feed.component.html @@ -40,8 +40,8 @@ None of your friends have posted anything yet!
Try refreshing your page! -
- +
+
diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index 89620d7..a38d507 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -20,6 +20,7 @@ export class PostComponent implements OnInit { public votesNumber: number; public timeCreated: string; @Input() paramId: string; + @Input() index: number; public loggedIn = false; private voteBtns: HTMLCollectionOf; @@ -33,9 +34,7 @@ export class PostComponent implements OnInit { this._postService.getPostRequest(Guid.parse(this.paramId)).subscribe( (result: object) => { - Object.assign(this.post, result); - - console.log(this.post.postId); + Object.assign(this.post, result); this.post.fileURLs = Object.values(result)[7]; this.votesNumber = this.post.currentRating; @@ -46,17 +45,16 @@ export class PostComponent implements OnInit { this.loadUser(); } - ); - - window.addEventListener("load", () => { - this.highlightButtonsOnInit(); - }); + ); } private loadUser(): void { this._userService.getUserByUsernameRequest(this.post.creatorUsername).subscribe( (result: object) => { Object.assign(this.user, result); + + this.highlightButtonsOnInit(); + this.loaded = true; } ); @@ -123,8 +121,8 @@ export class PostComponent implements OnInit { } private changeColorOfVoteButton(isUpvoted: boolean, isDownvoted: boolean): void { - this.voteBtns.item(0)!.style.backgroundColor = (isUpvoted) ? 'lightblue' : 'white'; - this.voteBtns.item(1)!.style.backgroundColor = (isDownvoted) ? 'lightblue' : 'white'; + this.voteBtns.item(this.index * 2)!.style.backgroundColor = (isUpvoted) ? 'lightblue' : 'white'; + this.voteBtns.item((this.index * 2) + 1)!.style.backgroundColor = (isDownvoted) ? 'lightblue' : 'white'; } private highlightButtonsOnInit(): void { @@ -132,8 +130,6 @@ export class PostComponent implements OnInit { (x: object) => { const isLike: boolean = Object.values(x)[3]; - console.log(this.voteBtns); - this.changeColorOfVoteButton(isLike, !isLike); } ); diff --git a/src/app/components/profile/profile.component.html b/src/app/components/profile/profile.component.html index 0e5f633..5c21cee 100644 --- a/src/app/components/profile/profile.component.html +++ b/src/app/components/profile/profile.component.html @@ -52,8 +52,8 @@
{{ user.firstName }} {{ user.lastName }} hasn't posted anything yet!
-
- +
+
-- cgit v1.2.3