Skip to content

Commit

Permalink
Merge pull request #1138 from ORCID/affiliation-delete
Browse files Browse the repository at this point in the history
Affiliation delete
  • Loading branch information
bobcaprice authored Mar 20, 2024
2 parents d29e5ea + c6ff1e7 commit e097794
Show file tree
Hide file tree
Showing 20 changed files with 3,918 additions and 3,120 deletions.
23 changes: 23 additions & 0 deletions ui/src/app/affiliation/affiliation-delete.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<form name="deleteForm" (ngSubmit)="confirmDelete(affiliation?.id)">
<div class="modal-header">
<h4 class="modal-title" jhiTranslate="entity.delete.title.string">Confirm deletion</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" (click)="clear()">&times;</button>
</div>
<div class="modal-body" id="jhi-delete-assertion-heading">
<app-error-alert></app-error-alert>
<p *ngIf="!affiliation?.addedToORCID" i18n="@@gatewayApp.assertionServiceAssertion.delete.fromPortal.string">
Are you sure you want to delete this affiliation from the portal?
</p>
<p *ngIf="affiliation?.addedToORCID">
{{ message | localize }}
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-primary" data-dismiss="modal" (click)="clear()">
<fa-icon [icon]="faBan"></fa-icon>&nbsp;<span i18n="@@entity.action.cancel.string">Cancel</span>
</button>
<button id="jhi-confirm-delete-assertion" type="submit" class="btn btn-danger">
<fa-icon [icon]="faTimes"></fa-icon>&nbsp;<span i18n="@@entity.action.delete.string">Delete</span>
</button>
</div>
</form>
Empty file.
23 changes: 23 additions & 0 deletions ui/src/app/affiliation/affiliation-delete.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { AffiliationDeletePopupComponent } from './affiliation-delete.component'
import { RouterTestingModule } from '@angular/router/testing'

describe('AffiliationDeleteComponent', () => {
let component: AffiliationDeletePopupComponent
let fixture: ComponentFixture<AffiliationDeletePopupComponent>

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AffiliationDeletePopupComponent],
imports: [RouterTestingModule],
})
fixture = TestBed.createComponent(AffiliationDeletePopupComponent)
component = fixture.componentInstance
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy()
})
})
104 changes: 104 additions & 0 deletions ui/src/app/affiliation/affiliation-delete.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { Component, OnInit, OnDestroy } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'

import { NgbActiveModal, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'

import { AffiliationService } from './service/affiliations.service'
import { EventService } from 'src/app/shared/service/event.service'
import { AlertService } from 'src/app/shared/service/alert.service'
import { IAffiliation } from './model/affiliation.model'
import { AFFILIATION_STATUS } from 'src/app/shared/constants/orcid-api.constants'
import { AlertType, EventType } from 'src/app/app.constants'
import { Event } from 'src/app/shared/model/event.model'
import { faBan, faTimes } from '@fortawesome/free-solid-svg-icons'

@Component({
selector: 'app-affiliation-delete-dialog',
templateUrl: './affiliation-delete.component.html',
})
export class AffiliationDeleteDialogComponent implements OnInit {
inOrcid: string = AFFILIATION_STATUS.IN_ORCID
userRevokedAccess: string = AFFILIATION_STATUS.USER_REVOKED_ACCESS
affiliation: IAffiliation | undefined
errorUserRevoked = false
faTimes = faTimes
faBan = faBan
message = ''

constructor(
protected affiliationService: AffiliationService,
public activeModal: NgbActiveModal,
protected eventService: EventService,
private alertService: AlertService
) {}

clear() {
this.activeModal.dismiss(true)
}

ngOnInit(): void {
this.message = $localize`:@@gatewayApp.assertionServiceAssertion.delete.fromPortalAndRegistry.string:Are you sure you want to delete this affiliation for ${this.affiliation?.email}? The affiliation will be deleted from the portal and
the user's ORCID record`
}

confirmDelete(id: string | undefined) {
console.log(id)

if (id) {
this.affiliationService.delete(id).subscribe((response) => {
if (response.body.deleted) {
this.eventService.broadcast(new Event(EventType.AFFILIATION_LIST_MODIFICATION, 'Deleted an affiliation'))
this.alertService.broadcast(AlertType.AFFILIATION_DELETED)
} else {
this.eventService.broadcast(
new Event(EventType.AFFILIATION_LIST_MODIFICATION, 'Failed to delete an affiliation')
)
this.alertService.broadcast(AlertType.AFFILIATION_DELETE_FAILURE)
}
this.activeModal.dismiss(true)
})
}
}
}

@Component({
selector: 'app-affiliation-delete-popup',
template: '',
})
export class AffiliationDeletePopupComponent implements OnInit, OnDestroy {
protected ngbModalRef: NgbModalRef | undefined

constructor(
protected activatedRoute: ActivatedRoute,
protected router: Router,
protected modalService: NgbModal
) {}

ngOnInit() {
this.activatedRoute.data.subscribe(({ affiliation }) => {
console.log(affiliation)

setTimeout(() => {
this.ngbModalRef = this.modalService.open(AffiliationDeleteDialogComponent as Component, {
size: 'lg',
backdrop: 'static',
})
this.ngbModalRef.componentInstance.affiliation = affiliation
this.ngbModalRef.result.then(
(result) => {
this.router.navigate(['/affiliations', { outlets: { popup: null } }])
this.ngbModalRef = undefined
},
(reason) => {
this.router.navigate(['/affiliations', { outlets: { popup: null } }])
this.ngbModalRef = undefined
}
)
}, 0)
})
}

ngOnDestroy() {
this.ngbModalRef = undefined
}
}
9 changes: 5 additions & 4 deletions ui/src/app/affiliation/affiliation-update.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
COUNTRIES,
ORG_ID_TYPES,
DEFAULT_LATEST_YEAR_INCREMENT,
AlertType,
} from '../app.constants'
import { AlertService } from '../shared/service/alert.service'
import { faBan, faSave } from '@fortawesome/free-solid-svg-icons'
Expand Down Expand Up @@ -177,8 +178,8 @@ export class AffiliationUpdateComponent implements OnInit {
this.startDaysList = this.dateUtilService.getDaysList()
this.endDaysList = this.dateUtilService.getDaysList()
this.isSaving = false
this.activatedRoute.data.subscribe(({ assertion }) => {
this.updateForm(assertion)
this.activatedRoute.data.subscribe(({ affiliation }) => {
this.updateForm(affiliation)
})

this.onChanges()
Expand Down Expand Up @@ -253,7 +254,7 @@ export class AffiliationUpdateComponent implements OnInit {
this.affiliationService.update(assertion).subscribe({
next: () => {
this.onSaveSuccess()
this.alertService.broadcast('assertionServiceApp.affiliation.updated.string')
this.alertService.broadcast(AlertType.AFFILIATION_UPDATED)
},
error: (err) => this.onSaveError(err),
})
Expand All @@ -262,7 +263,7 @@ export class AffiliationUpdateComponent implements OnInit {
next: () => {
this.onSaveSuccess()
// TODO: add alerttype
this.alertService.broadcast('assertionServiceApp.affiliation.created.string')
this.alertService.broadcast(AlertType.AFFILIATION_CREATED)
},
error: (err) => this.onSaveError(err),
})
Expand Down
14 changes: 12 additions & 2 deletions ui/src/app/affiliation/affiliation.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,27 @@ import { AffiliationDetailComponent } from './affiliation-detail.component'
import {
AffiliationImportDialogComponent,
AffiliationImportPopupComponent,
} from './affiliation-import-dialog.component';
} from './affiliation-import-dialog.component'
import { AffiliationDeleteDialogComponent, AffiliationDeletePopupComponent } from './affiliation-delete.component'
import { AffiliationUpdateComponent } from './affiliation-update.component'

@NgModule({
imports: [CommonModule, FormsModule, ReactiveFormsModule, SharedModule, RouterModule.forChild(affiliationRoutes), ClipboardModule],
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
SharedModule,
RouterModule.forChild(affiliationRoutes),
ClipboardModule,
],
declarations: [
AffiliationsComponent,
AffiliationDetailComponent,
AffiliationImportDialogComponent,
AffiliationImportPopupComponent,
AffiliationUpdateComponent,
AffiliationDeleteDialogComponent,
AffiliationDeletePopupComponent,
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
Expand Down
16 changes: 15 additions & 1 deletion ui/src/app/affiliation/affiliation.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AffiliationsComponent } from './affiliations.component'
import { AffiliationDetailComponent } from './affiliation-detail.component'
import { AffiliationImportPopupComponent } from './affiliation-import-dialog.component'
import { AffiliationUpdateComponent } from './affiliation-update.component'
import { AffiliationDeletePopupComponent } from './affiliation-delete.component'

export const AffiliationResolver: ResolveFn<Affiliation | null> = (
route: ActivatedRouteSnapshot,
Expand Down Expand Up @@ -48,6 +49,19 @@ export const affiliationRoutes: Routes = [
canActivate: [AuthGuard],
outlet: 'popup',
},
{
path: ':id/delete',
component: AffiliationDeletePopupComponent,
resolve: {
affiliation: AffiliationResolver,
},
data: {
authorities: ['ASSERTION_SERVICE_ENABLED'],
pageTitle: 'gatewayApp.assertionServiceAssertion.home.title.string',
},
canActivate: [AuthGuard],
outlet: 'popup',
},
],
},
{
Expand Down Expand Up @@ -75,7 +89,7 @@ export const affiliationRoutes: Routes = [
path: ':id/edit',
component: AffiliationUpdateComponent,
resolve: {
assertion: AffiliationResolver,
affiliation: AffiliationResolver,
},
data: {
authorities: ['ASSERTION_SERVICE_ENABLED'],
Expand Down
4 changes: 4 additions & 0 deletions ui/src/app/app.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export enum AlertType {
USER_CREATED = 'User created. Invite sent.',
USER_UPDATED = 'User updated successfully',
USER_DELETED = 'User deleted successfully',
AFFILIATION_CREATED = 'Affiliation created',
AFFILIATION_UPDATED = 'Affiliation updated',
AFFILIATION_DELETED = 'Affiliation deleted',
AFFILIATION_DELETE_FAILURE = 'There was a problem deleting the affiliation',
}

export const EMAIL_NOT_FOUND_TYPE = 'https://www.jhipster.tech/problem/email-not-found'
Expand Down
8 changes: 8 additions & 0 deletions ui/src/app/shared/pipe/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export class LocalizePipe implements PipeTransform {
return $localize`:@@userServiceApp.user.updated.string:User updated successfully`
case AlertType.USER_DELETED:
return $localize`:@@userServiceApp.user.deleted.string:User deleted successfully`
case AlertType.AFFILIATION_CREATED:
return $localize`:@@assertionServiceApp.affiliation.created.string:Affiliation created`
case AlertType.AFFILIATION_UPDATED:
return $localize`:@@assertionServiceApp.affiliation.updated.string:Affiliation updated`
case AlertType.AFFILIATION_DELETED:
return $localize`:@@assertionServiceApp.affiliation.deleted.string:Affiliation deleted`
case AlertType.AFFILIATION_DELETE_FAILURE:
return $localize`:@@assertionServiceApp.affiliation.problemDeleting.string:There was a problem deleting the affiliation`

// Affiliation pretty statuses

Expand Down
Loading

0 comments on commit e097794

Please sign in to comment.