From 86fd154444ae4ce7d3ca9ece4ceab83eed2e113e Mon Sep 17 00:00:00 2001 From: Sven Hansen Date: Fri, 1 Oct 2021 11:00:53 +0200 Subject: [PATCH 01/26] Created transfer project ownership (confirm) modals --- src/app/app.module.ts | 6 ++- ...ner-user-email-confirmation.component.html | 33 +++++++++++++ ...ner-user-email-confirmation.component.scss | 11 +++++ ...owner-user-email-confirmation.component.ts | 27 ++++++++++ ...ential-new-owner-user-email.component.html | 37 ++++++++++++++ ...ential-new-owner-user-email.component.scss | 11 +++++ ...otential-new-owner-user-email.component.ts | 26 ++++++++++ .../settings-dropdown.component.html | 3 ++ .../settings-dropdown.component.ts | 49 ++++++++++++++++++- .../modal-highlight-form.component.ts | 1 - src/app/services/project.service.ts | 9 +++- 11 files changed, 208 insertions(+), 5 deletions(-) create mode 100644 src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.html create mode 100644 src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.scss create mode 100644 src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.ts create mode 100644 src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.html create mode 100644 src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.scss create mode 100644 src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 19c6be9a..df7704a4 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -40,6 +40,8 @@ import { AlertModule } from 'ngx-bootstrap/alert'; import { BsDropdownModule } from 'ngx-bootstrap/dropdown'; import { ModalModule } from 'ngx-bootstrap/modal'; import { QuillModule } from 'ngx-quill'; +import { ModalPotentialNewOwnerUserEmailComponent } from './components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component'; +import { ModalPotentialNewOwnerUserEmailConfirmationComponent } from './components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component'; @NgModule({ @@ -52,7 +54,9 @@ import { QuillModule } from 'ngx-quill'; PrivacyPolicyComponent, NotFoundComponent, ModalDeleteGenericComponent, - SearchComponent + SearchComponent, + ModalPotentialNewOwnerUserEmailComponent, + ModalPotentialNewOwnerUserEmailConfirmationComponent ], imports: [ BsDropdownModule.forRoot(), diff --git a/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.html b/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.html new file mode 100644 index 00000000..7a85f738 --- /dev/null +++ b/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.html @@ -0,0 +1,33 @@ + + + diff --git a/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.scss b/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.scss new file mode 100644 index 00000000..5351576c --- /dev/null +++ b/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.scss @@ -0,0 +1,11 @@ +.modal-body { + + h6 { + width: 90%; + margin-bottom: 10px; + } + + button { + margin-right: 10px; + } +} diff --git a/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.ts b/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.ts new file mode 100644 index 00000000..8f5b0548 --- /dev/null +++ b/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.ts @@ -0,0 +1,27 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { BsModalRef } from 'ngx-bootstrap/modal'; + +@Component({ + selector: 'app-modal-potential-new-owner-user-email-confirmation', + templateUrl: './modal-potential-new-owner-user-email-confirmation.component.html', + styleUrls: ['./modal-potential-new-owner-user-email-confirmation.component.scss'] +}) +export class ModalPotentialNewOwnerUserEmailConfirmationComponent { + + @Input() email: string; + @Output() didConfirmEvent = new EventEmitter(); + + constructor( + public bsModalRef: BsModalRef, + ) { } + + /** + * Method which triggers when accept is clicked. + * Emits true via the output property and closes the modal. + */ + public onAcceptClicked(): void { + this.didConfirmEvent.emit(true); + this.bsModalRef.hide(); + } + +} diff --git a/src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.html b/src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.html new file mode 100644 index 00000000..17e40097 --- /dev/null +++ b/src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.html @@ -0,0 +1,37 @@ + + + diff --git a/src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.scss b/src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.scss new file mode 100644 index 00000000..23f253ed --- /dev/null +++ b/src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.scss @@ -0,0 +1,11 @@ +.modal-body { + + input { + width: 90%; + margin-bottom: 10px; + } + + button { + margin-right: 10px; + } +} diff --git a/src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.ts b/src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.ts new file mode 100644 index 00000000..5da6a747 --- /dev/null +++ b/src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component.ts @@ -0,0 +1,26 @@ +import { Component, EventEmitter, Output } from '@angular/core'; +import { BsModalRef } from 'ngx-bootstrap/modal'; + +@Component({ + selector: 'app-modal-potential-new-owner-user-email', + templateUrl: './modal-potential-new-owner-user-email.component.html', + styleUrls: ['./modal-potential-new-owner-user-email.component.scss'] +}) +export class ModalPotentialNewOwnerUserEmailComponent { + + public potentialNewOwnerUserEmail: string; + @Output() potentialNewOwnerUserEmailEvent = new EventEmitter(); + + constructor( + public bsModalRef: BsModalRef, + ) { } + + /** + * Method which triggers when continue is clicked. + * Emits true via the output property and closes the modal. + */ + public onClickContinue(): void { + this.bsModalRef.hide(); + this.potentialNewOwnerUserEmailEvent.emit(this.potentialNewOwnerUserEmail); + } +} diff --git a/src/app/modules/project/details/bottom-drawer/settings-dropdown/settings-dropdown.component.html b/src/app/modules/project/details/bottom-drawer/settings-dropdown/settings-dropdown.component.html index 0f69d77b..19bf5b8e 100644 --- a/src/app/modules/project/details/bottom-drawer/settings-dropdown/settings-dropdown.component.html +++ b/src/app/modules/project/details/bottom-drawer/settings-dropdown/settings-dropdown.component.html @@ -12,5 +12,8 @@ Delete project + + Transfer Ownership + diff --git a/src/app/modules/project/details/bottom-drawer/settings-dropdown/settings-dropdown.component.ts b/src/app/modules/project/details/bottom-drawer/settings-dropdown/settings-dropdown.component.ts index aa6574dc..3159fdec 100644 --- a/src/app/modules/project/details/bottom-drawer/settings-dropdown/settings-dropdown.component.ts +++ b/src/app/modules/project/details/bottom-drawer/settings-dropdown/settings-dropdown.component.ts @@ -10,7 +10,7 @@ import { HighlightFormResult, ModalHighlightFormComponent } from '../../../modal import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { Router } from '@angular/router'; import { BsModalService, ModalOptions } from 'ngx-bootstrap/modal'; -import { EMPTY } from 'rxjs'; +import { BehaviorSubject, EMPTY } from 'rxjs'; import { switchMap } from 'rxjs/operators'; import { ModalDeleteGenericComponent } from 'src/app/components/modals/modal-delete-generic/modal-delete-generic.component'; import { Project } from 'src/app/models/domain/project'; @@ -20,6 +20,8 @@ import { AuthService } from 'src/app/services/auth.service'; import { HighlightService } from 'src/app/services/highlight.service'; import { HighlightByProjectIdService } from 'src/app/services/highlightid.service'; import { ProjectService } from 'src/app/services/project.service'; +import { ModalPotentialNewOwnerUserEmailComponent } from 'src/app/components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component'; +import { ModalPotentialNewOwnerUserEmailConfirmationComponent } from 'src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component'; @Component({ selector: 'app-settings-dropdown', @@ -34,6 +36,11 @@ export class SettingsDropdownComponent implements OnInit { public displayEditButton = false; public displayDeleteProjectButton = false; public displayHighlightButton = false; + public displayTransferProjectOwnershipButton = false; + + public potentialNewOwnerUserEmail = ""; + private emailFilledIn = false; + private didConfirm = false; constructor(private projectService: ProjectService, private authService: AuthService, @@ -170,6 +177,44 @@ export class SettingsDropdownComponent implements OnInit { }); } + /** + * Method to initiate a transfer project ownership. + */ + public onClickTransferProjectOwnership(): void { + // Display modal + const modalRefEmail = this.modalService.show(ModalPotentialNewOwnerUserEmailComponent); + + // Wait for modal to emit true + modalRefEmail.content.potentialNewOwnerUserEmailEvent.subscribe((potentialNewOwnerUserEmail: string) => { + this.potentialNewOwnerUserEmail = potentialNewOwnerUserEmail + this.showConfirmModal(); + }); + } + + /** + * Method for asking user to confirm filled in potential new owner user email. + */ + private showConfirmModal() { + var email = this.potentialNewOwnerUserEmail; + + // Display modal + const modalRefEmailConfirm = this.modalService.show(ModalPotentialNewOwnerUserEmailConfirmationComponent, {initialState: {email}}); + + // Wait for modal to emit true + modalRefEmailConfirm.content.didConfirmEvent.subscribe(() => { + this.initiateTransferProjectOwnership(); + }); + } + + /** + * + */ + private initiateTransferProjectOwnership(): void { + // this.projectService.initiateTransferProjectOwnership(this.project.id).subscribe(text => { + // console.log(text); + // }); + } + /** * Method to display the edit project button based on the current user and the project user. * If the user either has the ProjectWrite scope or is the creator of the project @@ -178,12 +223,14 @@ export class SettingsDropdownComponent implements OnInit { if (this.currentUser == null || this.project == null || this.project.user == null) { this.displayEditButton = false; this.displayDeleteProjectButton = false; + this.displayTransferProjectOwnershipButton = false; return; } if (this.project.user.id === this.currentUser.id || this.authService.currentBackendUserHasScope(scopes.AdminProjectWrite)) { this.displayEditButton = true; this.displayDeleteProjectButton = true; + this.displayTransferProjectOwnershipButton = true; } } diff --git a/src/app/modules/project/modal-highlight-form/modal-highlight-form.component.ts b/src/app/modules/project/modal-highlight-form/modal-highlight-form.component.ts index bf2c1d22..495c59d2 100644 --- a/src/app/modules/project/modal-highlight-form/modal-highlight-form.component.ts +++ b/src/app/modules/project/modal-highlight-form/modal-highlight-form.component.ts @@ -52,7 +52,6 @@ export class ModalHighlightFormComponent implements OnInit, AfterViewInit { @ViewChild(FileUploaderComponent) fileUploader: FileUploaderComponent; - public highlightProjectForm: FormGroup; public dateFieldsEnabled = true; public validationErrorMessage: string = null; diff --git a/src/app/services/project.service.ts b/src/app/services/project.service.ts index 8c5f19e0..c778913a 100644 --- a/src/app/services/project.service.ts +++ b/src/app/services/project.service.ts @@ -27,6 +27,7 @@ import { CallToActionIconsConfig } from 'src/app/config/call-to-action-icons-con import { Project } from 'src/app/models/domain/project'; import { ProjectAdd } from 'src/app/models/resources/project-add'; import { ProjectUpdate } from 'src/app/models/resources/project-update'; +import { ThisReceiver } from '@angular/compiler'; @Injectable({ providedIn: 'root', @@ -36,7 +37,7 @@ export class ProjectService extends HttpBaseService { + public get(id: number): Observable { return super.get(id) .pipe( map(project => { @@ -56,7 +57,11 @@ export class ProjectService extends HttpBaseService { + public initiateTransferProjectOwnership(projectId: number, potentialNewOwnerUserEmail: string, ): Observable { + return this.http.get(this.url + '/transfer/' + projectId, { params: { potentialNewOwnerUserEmail: potentialNewOwnerUserEmail }}); + } + + private addLikes(project: any): Promise { return this.authService.getBackendUser() .then(currentUser => { project.likeCount = project.likes?.length ? project.likes.length : 0; From 4e129cf80721b60c4fd722df8dd7ed7c6aa6ea0d Mon Sep 17 00:00:00 2001 From: Sven Hansen Date: Tue, 5 Oct 2021 13:19:33 +0200 Subject: [PATCH 02/26] Added Delete Transfer Request functionality, still 'errors' present. API calls being executed twice --- .vscode/launch.json | 4 +- src/app/app.module.ts | 5 +- ...ner-user-email-confirmation.component.html | 6 +- ...ner-user-email-confirmation.component.scss | 20 +++++- ...owner-user-email-confirmation.component.ts | 1 - ...ential-new-owner-user-email.component.html | 4 +- ...ential-new-owner-user-email.component.scss | 20 +++++- .../settings-dropdown.component.html | 2 +- .../settings-dropdown.component.ts | 65 ++++++++++++------- .../modules/project/project-routing.module.ts | 2 + .../transfer-ownership.component.html | 14 ++++ .../transfer-ownership.component.scss | 17 +++++ .../transfer-ownership.component.ts | 38 +++++++++++ src/app/services/project.service.ts | 25 +++++-- 14 files changed, 179 insertions(+), 44 deletions(-) create mode 100644 src/app/modules/project/transfer-ownership/transfer-ownership.component.html create mode 100644 src/app/modules/project/transfer-ownership/transfer-ownership.component.scss create mode 100644 src/app/modules/project/transfer-ownership/transfer-ownership.component.ts diff --git a/.vscode/launch.json b/.vscode/launch.json index 561adf4c..312cde9e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,8 +8,8 @@ "type": "chrome", "request": "attach", "name": "Attach to Chrome localhost", - "port": 9222, + "port": 4200, "webRoot": "${workspaceFolder}" } ] -} \ No newline at end of file +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index df7704a4..8f92e561 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -42,7 +42,7 @@ import { ModalModule } from 'ngx-bootstrap/modal'; import { QuillModule } from 'ngx-quill'; import { ModalPotentialNewOwnerUserEmailComponent } from './components/modals/modal-potential-new-owner-user-email/modal-potential-new-owner-user-email.component'; import { ModalPotentialNewOwnerUserEmailConfirmationComponent } from './components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component'; - +import { TransferOwnershipComponent } from './modules/project/transfer-ownership/transfer-ownership.component'; @NgModule({ declarations: [ @@ -56,7 +56,8 @@ import { ModalPotentialNewOwnerUserEmailConfirmationComponent } from './componen ModalDeleteGenericComponent, SearchComponent, ModalPotentialNewOwnerUserEmailComponent, - ModalPotentialNewOwnerUserEmailConfirmationComponent + ModalPotentialNewOwnerUserEmailConfirmationComponent, + TransferOwnershipComponent ], imports: [ BsDropdownModule.forRoot(), diff --git a/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.html b/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.html index 7a85f738..1d1c3682 100644 --- a/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.html +++ b/src/app/components/modals/modal-potential-new-owner-user-email-confirmation/modal-potential-new-owner-user-email-confirmation.component.html @@ -16,11 +16,9 @@ If not, see https://www.gnu.org/licenses/lgpl-3.0.txt --> +
-