From eab7b2108d91af1c905f795febf811d5cc404863 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 25 Feb 2021 14:38:12 +0200 Subject: Removed unnecessary variables from request subscriptions --- .../components/profile-settings/profile-settings.component.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index a484665..f3cd4c1 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -56,7 +56,7 @@ export class ProfileSettingsComponent implements OnInit { this.isAdminUser = this.user.roles.map(x => x.name).includes(AppConstants.ADMIN_ROLE_NAME); this.finishUserLoading(); }, - (err: HttpErrorResponse) => { + () => { this._router.navigate(['/not-found']); } ); @@ -89,7 +89,7 @@ export class ProfileSettingsComponent implements OnInit { this.goToProfile(); } }, - (err: HttpErrorResponse) => { + () => { this.logout(); } ); @@ -181,7 +181,7 @@ export class ProfileSettingsComponent implements OnInit { } this._userService.putProfilePictureFromSessionStorageRequest(this.newProfilePicture).subscribe( - (result: object) => { + () => { this.reloadPage(); } ); @@ -196,7 +196,7 @@ export class ProfileSettingsComponent implements OnInit { this.patchTechnologiesControl(); this._userService.putUserFromSessionStorageRequest(this.updateUserFormGroup, this.user.roles, this.user.friends).subscribe( - (result: object) => { + () => { this._successBar.showMsg('Profile updated successfully!'); }, (err: HttpErrorResponse) => { @@ -285,7 +285,7 @@ export class ProfileSettingsComponent implements OnInit { deleteAccount(): void { if (this.deleteAccountConfirm) { this._userService.deleteUserFromSessionStorageRequest().subscribe( - (res: object) => { + () => { this.logout(); }, (err: HttpErrorResponse) => { -- cgit v1.2.3 From a643d5ca122b2546a02ec06e355c0d42661fdf24 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 08:45:45 +0200 Subject: Updated profile and profile-setting's subscriptions to use an observer object --- .../profile-settings/profile-settings.component.ts | 58 +++++++++++----------- src/app/components/profile/profile.component.ts | 38 +++++++------- 2 files changed, 49 insertions(+), 47 deletions(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index f3cd4c1..ba1fbb6 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -50,35 +50,35 @@ export class ProfileSettingsComponent implements OnInit { this.availableTechnologies = []; this.newProfilePicture = new File([], ''); - this._userService.getUserByUsernameRequest(this._urlUsername).subscribe( - (res: object) => { + this._userService.getUserByUsernameRequest(this._urlUsername).subscribe({ + next: (res: object) => { Object.assign(this.user, res); this.isAdminUser = this.user.roles.map(x => x.name).includes(AppConstants.ADMIN_ROLE_NAME); this.finishUserLoading(); }, - () => { + error: () => { this._router.navigate(['/not-found']); } - ); + }); - this._languageService.getAllLanguagesWithSessionStorageRequest().subscribe( - (result: object) => { + this._languageService.getAllLanguagesWithSessionStorageRequest().subscribe({ + next: (result: object) => { this.availableLanguages = result as Language[]; } - ); - this._technologyService.getAllTechnologiesWithSessionStorageRequest().subscribe( - (result: object) => { + }); + this._technologyService.getAllTechnologiesWithSessionStorageRequest().subscribe({ + next: (result: object) => { this.availableTechnologies = result as Technology[]; } - ); + }); } private finishUserLoading(): void { if (sessionStorage.getItem('UserCred')) { const userFromToken: User = this._userService.getDefaultUser(); - this._userService.getUserFromSessionStorageRequest().subscribe( - (tokenRes: object) => { + this._userService.getUserFromSessionStorageRequest().subscribe({ + next: (tokenRes: object) => { Object.assign(userFromToken, tokenRes); if (userFromToken.userName === this._urlUsername) { @@ -89,10 +89,10 @@ export class ProfileSettingsComponent implements OnInit { this.goToProfile(); } }, - () => { + error: () => { this.logout(); } - ); + }); } else { this.goToProfile(); @@ -147,9 +147,11 @@ export class ProfileSettingsComponent implements OnInit { fileUpload: new FormControl('') }); - this.updateUserFormGroup.valueChanges.subscribe(() => { - this._successBar?.hideMsg(); - this._errorBar?.hideError(); + this.updateUserFormGroup.valueChanges.subscribe({ + next: () => { + this._successBar?.hideMsg(); + this._errorBar?.hideError(); + } }); } @@ -180,11 +182,11 @@ export class ProfileSettingsComponent implements OnInit { return; } - this._userService.putProfilePictureFromSessionStorageRequest(this.newProfilePicture).subscribe( - () => { + this._userService.putProfilePictureFromSessionStorageRequest(this.newProfilePicture).subscribe({ + next: () => { this.reloadPage(); } - ); + }); this.dataArrived = false; } @@ -195,14 +197,14 @@ export class ProfileSettingsComponent implements OnInit { this.patchLanguagesControl(); this.patchTechnologiesControl(); - this._userService.putUserFromSessionStorageRequest(this.updateUserFormGroup, this.user.roles, this.user.friends).subscribe( - () => { + this._userService.putUserFromSessionStorageRequest(this.updateUserFormGroup, this.user.roles, this.user.friends).subscribe({ + next: () => { this._successBar.showMsg('Profile updated successfully!'); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } private patchLanguagesControl(): void { @@ -284,14 +286,14 @@ export class ProfileSettingsComponent implements OnInit { deleteAccount(): void { if (this.deleteAccountConfirm) { - this._userService.deleteUserFromSessionStorageRequest().subscribe( - () => { + this._userService.deleteUserFromSessionStorageRequest().subscribe({ + next: () => { this.logout(); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); this.dataArrived = false; } else { diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index eaa1bec..429b9b8 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -52,16 +52,16 @@ export class ProfileComponent implements OnInit { password: new FormControl('') }); - this._userService.getUserByUsernameRequest(this._urlUsername).subscribe( - (res: object) => { + this._userService.getUserByUsernameRequest(this._urlUsername).subscribe({ + next: (res: object) => { Object.assign(this.user, res); this.isAdminUser = this.user.roles.map(x => x.name).includes(AppConstants.ADMIN_ROLE_NAME); this.loadLanguages(); }, - () => { + error: () => { this._router.navigate(['/not-found']); } - ); + }); } private loadLanguages(): void { @@ -91,17 +91,17 @@ export class ProfileComponent implements OnInit { } private loadPosts(): void { - this._feedService.getUserPostsRequest(this.user.userName, this._currentPage++, this._timeLoaded, AppConstants.PAGE_SIZE).subscribe( - (result: object) => { + this._feedService.getUserPostsRequest(this.user.userName, this._currentPage++, this._timeLoaded, AppConstants.PAGE_SIZE).subscribe({ + next: (result: object) => { const resultArr: Post[] = Object.values(result)[0]; this.userPosts.push(...resultArr); this.finishUserLoading(); }, - () => { + error: () => { this._currentPage = -1; this.finishUserLoading(); } - ); + }); } private finishUserLoading(): void { @@ -109,8 +109,8 @@ export class ProfileComponent implements OnInit { this.isUserLoggedIn = true; const userFromToken: User = this._userService.getDefaultUser(); - this._userService.getUserFromSessionStorageRequest().subscribe( - (tokenRes: object) => { + this._userService.getUserFromSessionStorageRequest().subscribe({ + next: (tokenRes: object) => { Object.assign(userFromToken, tokenRes); if (userFromToken.friends.map(x => x.userName).includes(this._urlUsername)) { @@ -121,10 +121,10 @@ export class ProfileComponent implements OnInit { } this.dataArrived = true; }, - () => { + error: () => { this.logout(); } - ); + }); } else { this.dataArrived = true; @@ -156,8 +156,8 @@ export class ProfileComponent implements OnInit { if (this.updatingFriendship) { this.dataArrived = false; - this._userService.getUserFromSessionStorageRequest().subscribe( - (result: object) => { + this._userService.getUserFromSessionStorageRequest().subscribe({ + next: (result: object) => { const loggedInUser: User = result as User; if (this.friendOfUser) { @@ -169,16 +169,16 @@ export class ProfileComponent implements OnInit { loggedInUser.friends.push(newFriend); } - this._userService.putBareUserFromSessionStorageRequest(loggedInUser, this.updateFrienship.get('password')?.value).subscribe( - () => { + this._userService.putBareUserFromSessionStorageRequest(loggedInUser, this.updateFrienship.get('password')?.value).subscribe({ + next: () => { this.reloadPage(); }, - () => { + error: () => { this._router.navigate(['/']); } - ); + }); } - ); + }); } this.updatingFriendship = !this.updatingFriendship; } -- cgit v1.2.3 From 8434044dcf8cec14765aa5d96072feaa2560a823 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 09:06:08 +0200 Subject: Fixed includes (for models) of all components --- src/app/components/admin-panel-page/admin-panel-page.component.ts | 6 +++--- src/app/components/comment-page/comment-page.component.ts | 2 +- src/app/components/comment/comment.component.ts | 4 ++-- src/app/components/feed/feed.component.ts | 4 ++-- src/app/components/post-page/post-page.component.ts | 2 +- src/app/components/post/post.component.ts | 4 ++-- src/app/components/profile-settings/profile-settings.component.ts | 6 +++--- src/app/components/profile/profile.component.ts | 6 +++--- src/app/components/register/register.component.ts | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/admin-panel-page/admin-panel-page.component.ts b/src/app/components/admin-panel-page/admin-panel-page.component.ts index d5ecc71..9beb8bc 100644 --- a/src/app/components/admin-panel-page/admin-panel-page.component.ts +++ b/src/app/components/admin-panel-page/admin-panel-page.component.ts @@ -11,9 +11,9 @@ import { PostService } from 'src/app/services/post.service'; import { TechnologyService } from 'src/app/services/technology.service'; import { TokenService } from 'src/app/services/token.service'; import { UserService } from 'src/app/services/user.service'; -import { User } from 'src/models/identity/user'; -import { Language } from 'src/models/language'; -import { Technology } from 'src/models/technology'; +import { User } from 'src/models/identity/user.model'; +import { Language } from 'src/models/language.model'; +import { Technology } from 'src/models/technology.model'; import { ErrorBarComponent } from '../error-bar/error-bar.component'; import { SuccessBarComponent } from '../success-bar/success-bar.component'; diff --git a/src/app/components/comment-page/comment-page.component.ts b/src/app/components/comment-page/comment-page.component.ts index 9bbdc59..5d256bf 100644 --- a/src/app/components/comment-page/comment-page.component.ts +++ b/src/app/components/comment-page/comment-page.component.ts @@ -5,7 +5,7 @@ import { Router } from '@angular/router'; import { Guid } from 'guid-typescript'; import { CommentService } from 'src/app/services/comment.service'; import { TokenService } from 'src/app/services/token.service'; -import { Comment } from 'src/models/comment'; +import { Comment } from 'src/models/comment.model'; @Component({ selector: 'app-comment-page', diff --git a/src/app/components/comment/comment.component.ts b/src/app/components/comment/comment.component.ts index d4dd9f4..7da896d 100644 --- a/src/app/components/comment/comment.component.ts +++ b/src/app/components/comment/comment.component.ts @@ -3,8 +3,8 @@ import { Router } from '@angular/router'; import { Guid } from 'guid-typescript'; import { CommentService } from 'src/app/services/comment.service'; import { UserService } from 'src/app/services/user.service'; -import { Comment } from 'src/models/comment'; -import { User } from 'src/models/identity/user'; +import { Comment } from 'src/models/comment.model'; +import { User } from 'src/models/identity/user.model'; @Component({ selector: 'app-comment', diff --git a/src/app/components/feed/feed.component.ts b/src/app/components/feed/feed.component.ts index a9a042c..895bf76 100644 --- a/src/app/components/feed/feed.component.ts +++ b/src/app/components/feed/feed.component.ts @@ -1,11 +1,11 @@ import { Component, OnInit } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { Router } from '@angular/router'; -import { User } from 'src/models/identity/user'; +import { User } from 'src/models/identity/user.model'; import { UserService } from '../../services/user.service'; import { AppConstants } from 'src/app/app-constants.module'; import { FeedService } from 'src/app/services/feed.service'; -import { Post } from 'src/models/post'; +import { Post } from 'src/models/post.model'; import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { PostService } from 'src/app/services/post.service'; import { TokenService } from 'src/app/services/token.service'; diff --git a/src/app/components/post-page/post-page.component.ts b/src/app/components/post-page/post-page.component.ts index 7c32ce0..a60f4da 100644 --- a/src/app/components/post-page/post-page.component.ts +++ b/src/app/components/post-page/post-page.component.ts @@ -6,7 +6,7 @@ import { Guid } from 'guid-typescript'; import { CommentService } from 'src/app/services/comment.service'; import { PostService } from 'src/app/services/post.service'; import { TokenService } from 'src/app/services/token.service'; -import { Post } from 'src/models/post'; +import { Post } from 'src/models/post.model'; import { CloudinaryService } from 'src/app/services/cloudinary.service'; @Component({ diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index a46811d..fa5ac2f 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -3,8 +3,8 @@ import { Router } from '@angular/router'; import { Guid } from 'guid-typescript'; import { PostService } from 'src/app/services/post.service'; import { UserService } from 'src/app/services/user.service'; -import { User } from 'src/models/identity/user'; -import { Post } from 'src/models/post'; +import { User } from 'src/models/identity/user.model'; +import { Post } from 'src/models/post.model'; @Component({ selector: 'app-post', diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index ba1fbb6..b856bef 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -6,11 +6,11 @@ import { Router } from '@angular/router'; import { LanguageService } from 'src/app/services/language.service'; import { UserService } from 'src/app/services/user.service'; import { TechnologyService } from 'src/app/services/technology.service'; -import { User } from 'src/models/identity/user'; +import { User } from 'src/models/identity/user.model'; import { ErrorBarComponent } from '../error-bar/error-bar.component'; import { SuccessBarComponent } from '../success-bar/success-bar.component'; -import { Language } from 'src/models/language'; -import { Technology } from 'src/models/technology'; +import { Language } from 'src/models/language.model'; +import { Technology } from 'src/models/technology.model'; import { TokenService } from 'src/app/services/token.service'; import { Title } from '@angular/platform-browser'; import { AppConstants } from 'src/app/app-constants.module'; diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index 73e1e96..ed17f33 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -1,16 +1,16 @@ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { UserService } from 'src/app/services/user.service'; -import { User } from 'src/models/identity/user'; +import { User } from 'src/models/identity/user.model'; import { AppConstants } from 'src/app/app-constants.module'; import { Location } from '@angular/common'; import { LanguageService } from 'src/app/services/language.service'; import { TechnologyService } from 'src/app/services/technology.service'; -import { Post } from 'src/models/post'; +import { Post } from 'src/models/post.model'; import { FeedService } from 'src/app/services/feed.service'; import { TokenService } from 'src/app/services/token.service'; import { Title } from '@angular/platform-browser'; -import { Friend } from 'src/models/identity/friend'; +import { Friend } from 'src/models/identity/friend.model'; import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; @Component({ diff --git a/src/app/components/register/register.component.ts b/src/app/components/register/register.component.ts index b5800ad..07b8976 100644 --- a/src/app/components/register/register.component.ts +++ b/src/app/components/register/register.component.ts @@ -1,6 +1,6 @@ import { HttpErrorResponse } from '@angular/common/http'; import { Component, OnInit, ViewChild } from '@angular/core'; -import { AbstractControl, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { Title } from '@angular/platform-browser'; import { Router } from '@angular/router'; import { TokenService } from 'src/app/services/token.service'; -- cgit v1.2.3 From 7752a79fe5d8dd498ba0b7a842bbae19d38bd963 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 14 Mar 2021 09:26:04 +0200 Subject: Fixed settings page having an outdated link and routing user to outdated profile page when changing username --- src/app/components/profile-settings/profile-settings.component.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index b856bef..b314a9a 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -200,6 +200,12 @@ export class ProfileSettingsComponent implements OnInit { this._userService.putUserFromSessionStorageRequest(this.updateUserFormGroup, this.user.roles, this.user.friends).subscribe({ next: () => { this._successBar.showMsg('Profile updated successfully!'); + + // "Reload" page when changing username + const newUsername = this.updateUserFormGroup.get('username')?.value; + if (newUsername !== this._urlUsername) { + this._router.navigate(['/profile/' + newUsername + '/settings']); + } }, error: (err: HttpErrorResponse) => { this._errorBar.showError(err); -- cgit v1.2.3 From b42156ce3a6c3148ceab4c52e00ac41c7b6400a0 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 22 Mar 2021 15:49:01 +0200 Subject: Logging out of account in profile settings will redirect to login screen (and not profile page) --- src/app/components/profile-settings/profile-settings.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index b314a9a..7863258 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -279,7 +279,7 @@ export class ProfileSettingsComponent implements OnInit { logout(): void { this._tokenService.logoutUserFromSessionStorage(); - this.goToProfile(); + this._router.navigate(['/login']); } toggleLanguages(): void { -- cgit v1.2.3 From e4099fbf0ec62ecf38c9be6eba784cac4e6a3479 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 22 Mar 2021 16:32:51 +0200 Subject: Fixed form errors in profile settings component --- .../profile-settings/profile-settings.component.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index 7863258..44ea8bb 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -50,6 +50,23 @@ export class ProfileSettingsComponent implements OnInit { this.availableTechnologies = []; this.newProfilePicture = new File([], ''); + // Initializing forms with blank (default) values + this.updateUserFormGroup = this._fb.group({ + firstName: new FormControl(''), + lastName: new FormControl(''), + username: new FormControl(''), + email: new FormControl(''), + password: new FormControl(''), + languageInput: new FormControl(''), + languages: new FormControl(''), + technologyInput: new FormControl(''), + technologies: new FormControl('') + }); + this.updateProfilePictureFormGroup = this._fb.group({ + fileUpload: new FormControl('') + }); + + this._userService.getUserByUsernameRequest(this._urlUsername).subscribe({ next: (res: object) => { Object.assign(this.user, res); -- cgit v1.2.3 From 3e34040b286bb41019d20794f19f18b1a94f77af Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 22 Mar 2021 16:53:08 +0200 Subject: Added a button for navigation to admin panel page --- src/app/components/profile-settings/profile-settings.component.html | 5 +++++ src/app/components/profile-settings/profile-settings.component.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.html b/src/app/components/profile-settings/profile-settings.component.html index f5989ef..62513ef 100644 --- a/src/app/components/profile-settings/profile-settings.component.html +++ b/src/app/components/profile-settings/profile-settings.component.html @@ -3,6 +3,11 @@
+
+ +
diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index 44ea8bb..79519aa 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -290,7 +290,7 @@ export class ProfileSettingsComponent implements OnInit { this._router.navigate([this._router.url.substring(0, this._router.url.length - 9)]); } - navigateToAdminPanel(): void { + goToAdminPanel(): void { this._router.navigate(['/admin-panel']); } -- cgit v1.2.3 From f72daa97fd8bfbaba9f7d6874131a61b3e1c49ba Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 29 Mar 2021 14:52:03 +0300 Subject: Added basic effects and skeleton of functionality for clicking available technologies and languages in profile settings --- .../components/profile-settings/profile-settings.component.html | 4 ++-- .../components/profile-settings/profile-settings.component.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.html b/src/app/components/profile-settings/profile-settings.component.html index dd3d186..e792f9f 100644 --- a/src/app/components/profile-settings/profile-settings.component.html +++ b/src/app/components/profile-settings/profile-settings.component.html @@ -81,7 +81,7 @@ Available languages:
-
+
{{ lang.name }}
@@ -103,7 +103,7 @@ Available technologies:
-
+
{{ tech.name }}
diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index 79519aa..b7f2d90 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -286,6 +286,15 @@ export class ProfileSettingsComponent implements OnInit { } } + langClick(name: string): void { + console.log('Language: ' + name); + } + + techClick(name: string): void { + console.log('Technology: ' + name); + } + + goToProfile(): void { this._router.navigate([this._router.url.substring(0, this._router.url.length - 9)]); } -- cgit v1.2.3 From 8c2893557a5a03076746fcc91ca7db1edadae9e8 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 29 Mar 2021 15:11:13 +0300 Subject: Replaced technology and language input fields with arrays and button elements --- .../profile-settings.component.html | 82 +++++++++++++-------- .../profile-settings/profile-settings.component.ts | 85 ++++++++-------------- 2 files changed, 81 insertions(+), 86 deletions(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.html b/src/app/components/profile-settings/profile-settings.component.html index e792f9f..d42ba28 100644 --- a/src/app/components/profile-settings/profile-settings.component.html +++ b/src/app/components/profile-settings/profile-settings.component.html @@ -68,45 +68,63 @@ ▼ Edit Languages ▼
-
- - -
-
- No languages available! -
-
- Available languages: -
-
-
- {{ lang.name }} +
+
+ You haven't chosen any languages!
-
+
+ Chosen languages: +
+
+
+ {{ lang.name }} +
+
+
+
+
+ No languages available! +
+
+ Available languages: +
+
+
+ {{ lang.name }} +
+
+
-
- - -
-
- No technologies available! -
-
- Available technologies: -
-
-
- {{ tech.name }} +
+
+ You haven't chosen any technologies!
-
+
+ Chosen technologies: +
+
+
+ {{ tech.name }} +
+
+
+
+
+ No technologies available! +
+
+ Available technologies: +
+
+
+ {{ tech.name }} +
+
+
diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index b7f2d90..007ce28 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -34,6 +34,8 @@ export class ProfileSettingsComponent implements OnInit { public updateProfilePictureFormGroup: FormGroup; public newProfilePicture: File; public user: User; + public chosenLanguages: Language[]; + public chosenTechnologies: Technology[]; public availableLanguages: Language[]; public availableTechnologies: Technology[]; @@ -57,16 +59,11 @@ export class ProfileSettingsComponent implements OnInit { username: new FormControl(''), email: new FormControl(''), password: new FormControl(''), - languageInput: new FormControl(''), - languages: new FormControl(''), - technologyInput: new FormControl(''), - technologies: new FormControl('') }); this.updateProfilePictureFormGroup = this._fb.group({ fileUpload: new FormControl('') }); - this._userService.getUserByUsernameRequest(this._urlUsername).subscribe({ next: (res: object) => { Object.assign(this.user, res); @@ -77,18 +74,7 @@ export class ProfileSettingsComponent implements OnInit { this._router.navigate(['/not-found']); } }); - - this._languageService.getAllLanguagesWithSessionStorageRequest().subscribe({ - next: (result: object) => { - this.availableLanguages = result as Language[]; - } - }); - this._technologyService.getAllTechnologiesWithSessionStorageRequest().subscribe({ - next: (result: object) => { - this.availableTechnologies = result as Technology[]; - } - }); - } + } private finishUserLoading(): void { if (sessionStorage.getItem('UserCred')) { @@ -99,6 +85,7 @@ export class ProfileSettingsComponent implements OnInit { Object.assign(userFromToken, tokenRes); if (userFromToken.userName === this._urlUsername) { + this.loadUserSecondaryInfo(); this.initForms(); this.dataArrived = true; } @@ -116,6 +103,33 @@ export class ProfileSettingsComponent implements OnInit { } } + private loadUserSecondaryInfo(): void { + // Load languages and tehnologies of user + this._languageService.getFullLanguagesFromIncomplete(this.user.languages).then( + (result) => { + this.chosenLanguages = result as Language[]; + } + ); + + this._technologyService.getFullTechnologiesFromIncomplete(this.user.technologies).then( + (result) => { + this.chosenTechnologies = result as Technology[]; + } + ); + + // Load avaiable languages and technologies + this._languageService.getAllLanguagesWithSessionStorageRequest().subscribe({ + next: (result: object) => { + this.availableLanguages = result as Language[]; + } + }); + this._technologyService.getAllTechnologiesWithSessionStorageRequest().subscribe({ + next: (result: object) => { + this.availableTechnologies = result as Technology[]; + } + }); + } + private initForms(): void { this.updateUserFormGroup = this._fb.group({ firstName: new FormControl(this.user.firstName, [ @@ -139,25 +153,6 @@ export class ProfileSettingsComponent implements OnInit { Validators.minLength(3), Validators.pattern('.*[0-9].*') // Check if password contains atleast one number ]), - - // For language we have two different controls, - // the first one is used for input, the other one for sending data - // because if we edit the control for input, - // we're also gonna change the input field in the HTML - languageInput: new FormControl(''), // The one for input - languages: new FormControl(''), // The one that is sent - - // For technologies it's the same as it is with languages - technologyInput: new FormControl(''), - technologies: new FormControl('') - }); - - this.getLanguagesForShowing().then(value => { - this.updateUserFormGroup.patchValue({ languageInput : value }); - }); - - this.getTechnologiesForShowing().then(value => { - this.updateUserFormGroup.patchValue({ technologyInput : value }); }); this.updateProfilePictureFormGroup = this._fb.group({ @@ -172,24 +167,6 @@ export class ProfileSettingsComponent implements OnInit { }); } - private getLanguagesForShowing(): Promise { - return new Promise(resolve => { - this._languageService.getFullLanguagesFromIncomplete(this.user.languages).then(value => { - this.user.languages = value; - resolve(value.map(x => x.name).join(' ')); - }); - }); - } - - private getTechnologiesForShowing(): Promise { - return new Promise(resolve => { - this._technologyService.getFullTechnologiesFromIncomplete(this.user.technologies).then(value => { - this.user.technologies = value; - resolve(value.map(x => x.name).join(' ')); - }); - }); - } - onFileUpload(event: any): void { this.newProfilePicture = event.target.files[0]; } -- cgit v1.2.3 From 350657be9db0b51c06ccba2dd3e3a4b1702bcfb1 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 29 Mar 2021 15:22:56 +0300 Subject: Fixed loading of avaiable languages and technologies in profile settings page --- .../profile-settings/profile-settings.component.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index 007ce28..4bee52e 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -108,24 +108,34 @@ export class ProfileSettingsComponent implements OnInit { this._languageService.getFullLanguagesFromIncomplete(this.user.languages).then( (result) => { this.chosenLanguages = result as Language[]; + this.loadAvailableLanguages(); } ); this._technologyService.getFullTechnologiesFromIncomplete(this.user.technologies).then( (result) => { this.chosenTechnologies = result as Technology[]; + this.loadAvailableTechnologies(); } ); + } - // Load avaiable languages and technologies + private loadAvailableLanguages(): void { this._languageService.getAllLanguagesWithSessionStorageRequest().subscribe({ next: (result: object) => { - this.availableLanguages = result as Language[]; + const allAvailable = result as Language[]; + // Remove the chosen languages from all of the avaiable ones + this.availableLanguages = allAvailable.filter(a => !this.user.languages.some(l => l.name === a.name)); } }); + } + + private loadAvailableTechnologies(): void { this._technologyService.getAllTechnologiesWithSessionStorageRequest().subscribe({ next: (result: object) => { - this.availableTechnologies = result as Technology[]; + const allAvailable = result as Technology[]; + // Remove the chosen technologies from all of the avaiable ones + this.availableTechnologies = allAvailable.filter(a => !this.user.technologies.some(t => t.name === a.name)); } }); } -- cgit v1.2.3 From bcba82bbbcc55a511de1e126e0741ea6cf9fb505 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 29 Mar 2021 15:40:26 +0300 Subject: Added logic for transferring languages and technologies from available to chosen and back in profile settings --- .../profile-settings/profile-settings.component.ts | 27 +++++++++++++++++++--- src/styles.css | 4 ++++ 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index 4bee52e..4724f02 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -274,13 +274,34 @@ export class ProfileSettingsComponent implements OnInit { } langClick(name: string): void { - console.log('Language: ' + name); + if (this.chosenLanguages.some(c => c.name === name)) { + const index = this.chosenLanguages.findIndex(t => t.name === name); + + this.availableLanguages.push(this.chosenLanguages[index]); + this.chosenLanguages.splice(index, 1); + } + else { + const index = this.availableLanguages.findIndex(t => t.name === name); + + this.chosenLanguages.push(this.availableLanguages[index]); + this.availableLanguages.splice(index, 1); + } } techClick(name: string): void { - console.log('Technology: ' + name); - } + if (this.chosenTechnologies.some(c => c.name === name)) { + const index = this.chosenTechnologies.findIndex(t => t.name === name); + this.availableTechnologies.push(this.chosenTechnologies[index]); + this.chosenTechnologies.splice(index, 1); + } + else { + const index = this.availableTechnologies.findIndex(t => t.name === name); + + this.chosenTechnologies.push(this.availableTechnologies[index]); + this.availableTechnologies.splice(index, 1); + } + } goToProfile(): void { this._router.navigate([this._router.url.substring(0, this._router.url.length - 9)]); diff --git a/src/styles.css b/src/styles.css index 39b6fb1..c9a4f25 100644 --- a/src/styles.css +++ b/src/styles.css @@ -279,6 +279,10 @@ input[type=file]::file-selector-button { padding: 0.1em; } +.padding-right-1 { + padding-right: 1em !important; +} + .padding-right-1dot5 { padding-right: 1.5em !important; } -- cgit v1.2.3 From ab8122e2cbeefe55b7dca1aeeb1cbaf830ed25b5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 29 Mar 2021 15:46:25 +0300 Subject: Fixed update user request in service and in profile settings --- .../profile-settings/profile-settings.component.ts | 2 +- src/app/services/user.service.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index 4724f02..78a57ec 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -201,7 +201,7 @@ export class ProfileSettingsComponent implements OnInit { this.patchLanguagesControl(); this.patchTechnologiesControl(); - this._userService.putUserFromSessionStorageRequest(this.updateUserFormGroup, this.user.roles, this.user.friends).subscribe({ + this._userService.putUserFromSessionStorageRequest(this.updateUserFormGroup, this.chosenLanguages, this.chosenTechnologies, this.user.roles, this.user.friends).subscribe({ next: () => { this._successBar.showMsg('Profile updated successfully!'); diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index 29058b4..10c8c59 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -8,6 +8,8 @@ import { Observable } from 'rxjs'; import { Role } from 'src/models/identity/role.model'; import { Friend } from 'src/models/identity/friend.model'; import { TokenService } from './token.service'; +import { Language } from 'src/models/language.model'; +import { Technology } from 'src/models/technology.model'; @Injectable({ providedIn: 'root' @@ -36,11 +38,11 @@ export class UserService { return this.addFriendToUserRequest(userUserName, token, newFriendUserName); } - putUserFromSessionStorageRequest(updateUserFormGroup: FormGroup, userRoles: Role[], userFriends: Friend[]): Observable { + putUserFromSessionStorageRequest(updateUserFormGroup: FormGroup, languages: Language[], technologies: Technology[], userRoles: Role[], userFriends: Friend[]): Observable { const userId = this._tokenService.getUserIdFromSessionStorageToken(); const token = this._tokenService.getTokenFromSessionStorage(); - return this.putUserRequest(userId, token, updateUserFormGroup, userRoles, userFriends); + return this.putUserRequest(userId, token, updateUserFormGroup, languages, technologies, userRoles, userFriends); } putProfilePictureFromSessionStorageRequest(newPicture: File): Observable { @@ -119,7 +121,7 @@ export class UserService { return this._http.get(AppConstants.API_USER_URL + '/GetUser', options); } - putUserRequest(userId: Guid, authToken: string, updateUserFormGroup: FormGroup, userRoles: Role[], userFriends: Friend[]): Observable { + putUserRequest(userId: Guid, authToken: string, updateUserFormGroup: FormGroup, languages: Language[], technologies: Technology[], userRoles: Role[], userFriends: Friend[]): Observable { const body = { UserName: updateUserFormGroup.get('username')?.value, Email: updateUserFormGroup.get('email')?.value, @@ -128,8 +130,8 @@ export class UserService { Password: updateUserFormGroup.get('password')?.value, Roles: userRoles, Friends: userFriends, - Languages: updateUserFormGroup.get('languages')?.value, - Technologies: updateUserFormGroup.get('technologies')?.value + Languages: languages, + Technologies: technologies }; const options = { params: new HttpParams().set('Id', userId.toString()), -- cgit v1.2.3 From 1059b56781fdd6390c4c44fb00e99cc831971285 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 29 Mar 2021 16:05:06 +0300 Subject: Added show/hide button in profile settings confirm password field --- .../components/profile-settings/profile-settings.component.html | 7 +++++-- src/app/components/profile-settings/profile-settings.component.ts | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.html b/src/app/components/profile-settings/profile-settings.component.html index fd2d0c5..1471859 100644 --- a/src/app/components/profile-settings/profile-settings.component.html +++ b/src/app/components/profile-settings/profile-settings.component.html @@ -116,7 +116,7 @@ -
+
@@ -124,7 +124,10 @@
- + +
diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index 78a57ec..f329942 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -38,6 +38,7 @@ export class ProfileSettingsComponent implements OnInit { public chosenTechnologies: Technology[]; public availableLanguages: Language[]; public availableTechnologies: Technology[]; + public showCurrentPassword = false; constructor(private _titleService: Title, private _router: Router, private _userService: UserService, private _languageService: LanguageService, private _technologyService: TechnologyService, private _tokenService: TokenService, private _fb: FormBuilder, private _location: Location) { this._titleService.setTitle(this._title); @@ -346,4 +347,10 @@ export class ProfileSettingsComponent implements OnInit { this._router.onSameUrlNavigation = 'reload'; this._router.navigate([this._router.url]); } + + toggleShowPassword(index: number): void { + switch (index) { + case 0: this.showCurrentPassword = !this.showCurrentPassword; + } + } } -- cgit v1.2.3 From 10a4896a17495548ed3ce6b333939203b698470b Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 7 Apr 2021 21:22:43 +0300 Subject: Updated profile settings page to use profile picture service --- src/app/components/profile-settings/profile-settings.component.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/app/components/profile-settings/profile-settings.component.ts') diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index f329942..3d6e491 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -14,6 +14,7 @@ import { Technology } from 'src/models/technology.model'; import { TokenService } from 'src/app/services/token.service'; import { Title } from '@angular/platform-browser'; import { AppConstants } from 'src/app/app-constants.module'; +import { ProfilePictureService } from 'src/app/services/profile-picture.service'; @Component({ selector: 'app-profile-settings', @@ -40,7 +41,7 @@ export class ProfileSettingsComponent implements OnInit { public availableTechnologies: Technology[]; public showCurrentPassword = false; - constructor(private _titleService: Title, private _router: Router, private _userService: UserService, private _languageService: LanguageService, private _technologyService: TechnologyService, private _tokenService: TokenService, private _fb: FormBuilder, private _location: Location) { + constructor(private _titleService: Title, private _router: Router, private _userService: UserService, private _profilePictureService: ProfilePictureService, private _languageService: LanguageService, private _technologyService: TechnologyService, private _tokenService: TokenService, private _fb: FormBuilder, private _location: Location) { this._titleService.setTitle(this._title); } @@ -187,7 +188,7 @@ export class ProfileSettingsComponent implements OnInit { return; } - this._userService.putProfilePictureFromSessionStorageRequest(this.newProfilePicture).subscribe({ + this._profilePictureService.putPictureWithSessionStorageRequest(this.newProfilePicture).subscribe({ next: () => { this.reloadPage(); } -- cgit v1.2.3