From a9fb796ff1e1e575e5f0ede2bc9005d6c46dd571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 22 Oct 2020 02:11:33 +0300 Subject: [PATCH] Fixed assign members --- .../assign-owner-dialog.component.scss | 5 -- .../assign-owner-dialog.component.ts | 50 ++++++++++--------- apps/red-ui/src/app/dialogs/dialog.service.ts | 2 +- .../file-preview-screen.component.ts | 5 +- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/apps/red-ui/src/app/dialogs/assign-owner-dialog/assign-owner-dialog.component.scss b/apps/red-ui/src/app/dialogs/assign-owner-dialog/assign-owner-dialog.component.scss index 6914bc08f..e69de29bb 100644 --- a/apps/red-ui/src/app/dialogs/assign-owner-dialog/assign-owner-dialog.component.scss +++ b/apps/red-ui/src/app/dialogs/assign-owner-dialog/assign-owner-dialog.component.scss @@ -1,5 +0,0 @@ -@import "../../../assets/styles/red-variables"; - -.owner { - background-color: rgba($primary, 0.1); -} diff --git a/apps/red-ui/src/app/dialogs/assign-owner-dialog/assign-owner-dialog.component.ts b/apps/red-ui/src/app/dialogs/assign-owner-dialog/assign-owner-dialog.component.ts index 07f654725..59cf379c2 100644 --- a/apps/red-ui/src/app/dialogs/assign-owner-dialog/assign-owner-dialog.component.ts +++ b/apps/red-ui/src/app/dialogs/assign-owner-dialog/assign-owner-dialog.component.ts @@ -3,7 +3,7 @@ import { FileStatus, Project, ProjectControllerService, StatusControllerService import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { AppStateService } from '../../state/app-state.service'; import { UserService } from '../../user/user.service'; -import { NotificationService } from '../../notification/notification.service'; +import { NotificationService, NotificationType } from '../../notification/notification.service'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; class DialogData { @@ -36,7 +36,6 @@ export class AssignOwnerDialogComponent { private _loadData() { if (this.data.type === 'project') { const project = this.data.project; - this.usersForm = this._formBuilder.group({ singleUser: [project?.ownerId, Validators.required], userList: [project?.memberIds] @@ -52,37 +51,40 @@ export class AssignOwnerDialogComponent { } async saveUsers() { - if (this.data.type === 'project') { + try { + if (this.data.type === 'project') { - const ownerId = this.usersForm.get('singleUser').value; - const memberIds = this.usersForm.get('userList').value; - const project = this.data.project; + const ownerId = this.usersForm.get('singleUser').value; + const memberIds = this.usersForm.get('userList').value; + const project = this.data.project; + await this._projectControllerService.addMembersToProject({ memberIds: memberIds }, project.projectId).toPromise(); + await this._projectControllerService.assignProjectOwner(project.projectId, ownerId).toPromise(); - await this._projectControllerService.addMembersToProject({ memberIds: memberIds }, project.projectId).toPromise(); - await this._projectControllerService.assignProjectOwner(project.projectId, ownerId).toPromise(); + const updatedProject = await this._projectControllerService.getProject(project.projectId).toPromise(); - const updatedProject = await this._projectControllerService.getProject(project.projectId).toPromise(); + const toRemoveMembers = updatedProject.memberIds.filter(m => memberIds.indexOf(m) < 0); + if (toRemoveMembers.length > 0) { + await this._projectControllerService.deleteMembersToProject({ memberIds: toRemoveMembers }, project.projectId).toPromise(); + } + + project.ownerId = ownerId; + project.memberIds = [...new Set([ownerId, ...memberIds])]; + + this._notificationService.showToastNotification('Successfully assigned ' + this.userService.getNameForId(ownerId) + ' to project: ' + project.projectName); - const toRemoveMembers = updatedProject.memberIds.filter(m => memberIds.indexOf(m) < 0); - if (toRemoveMembers.length > 0) { - await this._projectControllerService.deleteMembersToProject({ memberIds: toRemoveMembers }, project.projectId).toPromise(); } - project.ownerId = ownerId; - project.memberIds = [...new Set([ownerId, ...memberIds])]; + if (this.data.type === 'file') { - this._notificationService.showToastNotification('Successfully assigned ' + this.userService.getNameForId(ownerId) + ' to project: ' + project.projectName); - //this._notificationService.showToastNotification('Failed: ' + error.error.message, null, NotificationType.ERROR); - } + const reviewerId = this.usersForm.get('singleUser').value; - if (this.data.type === 'file') { - - const reviewerId = this.usersForm.get('singleUser').value; - - await this._statusControllerService.assignProjectOwner1(this._appStateService.activeProjectId, this.data.file.fileId, reviewerId).toPromise(); - this.data.file.currentReviewer = reviewerId; - this._notificationService.showToastNotification('Successfully assigned ' + this.userService.getNameForId(reviewerId) + ' to file: ' + this.data.file.filename); + await this._statusControllerService.assignProjectOwner1(this._appStateService.activeProjectId, this.data.file.fileId, reviewerId).toPromise(); + this.data.file.currentReviewer = reviewerId; + this._notificationService.showToastNotification('Successfully assigned ' + this.userService.getNameForId(reviewerId) + ' to file: ' + this.data.file.filename); + } + } catch (error) { + this._notificationService.showToastNotification('Failed: ' + error.error.message, null, NotificationType.ERROR); } this.dialogRef.close(); diff --git a/apps/red-ui/src/app/dialogs/dialog.service.ts b/apps/red-ui/src/app/dialogs/dialog.service.ts index b8bedd947..383cd685d 100644 --- a/apps/red-ui/src/app/dialogs/dialog.service.ts +++ b/apps/red-ui/src/app/dialogs/dialog.service.ts @@ -136,7 +136,7 @@ export class DialogService { $event.stopPropagation(); this._dialog.open(AssignOwnerDialogComponent, { ...dialogConfig, - data: { type: 'project', projectId: project.projectId } + data: { type: 'project', project: project } }); } diff --git a/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts index 474b00579..9e95e7712 100644 --- a/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts @@ -103,9 +103,8 @@ export class FilePreviewScreenComponent implements OnInit { } public openAssignFileOwnerDialog($event: MouseEvent) { - $event.stopPropagation(); - // TODO - console.log('not implemented yet'); + const file = this.appStateService.getFileById(this.projectId, this.fileId); + this._dialogService.openAssignFileOwnerDialog($event, file); } public fileReady(viewer: string) {