TSK-468 Add remove distribution target button and endpoint.

This commit is contained in:
Martin Rojas Miguel Angel 2018-05-02 11:58:56 +02:00 committed by Holger Hagen
parent a3090ad058
commit ec33a7a1ff
7 changed files with 46 additions and 12 deletions

View File

@ -242,7 +242,7 @@ public class WorkbasketController extends AbstractPagingController {
@DeleteMapping(path = "/distribution-targets/{workbasketId}")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<Resources<DistributionTargetResource>> setDistributionTargetsForWorkbasketId(
public ResponseEntity<Resources<DistributionTargetResource>> removeDistributionTargetForWorkbasketId(
@PathVariable(value = "workbasketId") String targetWorkbasketId)
throws WorkbasketNotFoundException, NotAuthorizedException {
List<WorkbasketSummary> sourceWorkbaskets = workbasketService.getDistributionSources(targetWorkbasketId);

View File

@ -55,6 +55,7 @@ public class WorkbasketMapper {
resource.add(linkTo(methodOn(WorkbasketController.class).getWorkbasketAccessItems(wb.getId()))
.withRel("accessItems"));
resource.add(linkTo(WorkbasketController.class).withRel("allWorkbaskets"));
resource.add(linkTo(methodOn(WorkbasketController.class).removeDistributionTargetForWorkbasketId(wb.getId())).withRel("removeDistributionTargets"));
return resource;
}
}

View File

@ -138,6 +138,11 @@ export class WorkbasketService {
Observable<WorkbasketDistributionTargetsResource> {
return this.httpClient.put<WorkbasketDistributionTargetsResource>(url, distributionTargetsIds, this.httpOptions);
}
// DELETE
removeDistributionTarget(url: string) {
return this.httpClient.delete<string>(url, this.httpOptions);
}
// #endregion
// #region "Service extras"

View File

@ -4,6 +4,9 @@
<div class="pull-right">
<button type="button" [disabled]="!WorkbasketForm.form.valid" (click)="onSave()" class="btn btn-default btn-primary">Save</button>
<button type="button" (click)="onClear()" class="btn btn-default">Undo</button>
<button type="button" (click)="removeDistributionTargets()" data-toggle="tooltip" title="remove distribuition target" class="btn btn-default remove">
<span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span>
</button>
<button type="button" (click)="copyWorkbasket()" data-toggle="tooltip" title="copy" class="btn btn-default">
<span class="glyphicon glyphicon-copy green-blue" aria-hidden="true"></span>
</button>

View File

@ -45,7 +45,7 @@ const routes: Routes = [
describe('InformationComponent', () => {
let component: WorkbasketInformationComponent;
let fixture: ComponentFixture<WorkbasketInformationComponent>;
let debugElement, workbasketService, alertService, savingWorkbasketService;
let debugElement, workbasketService, alertService, savingWorkbasketService, requestInProgressService;
beforeEach(async(() => {
TestBed.configureTestingModule({
@ -71,6 +71,8 @@ describe('InformationComponent', () => {
workbasketService = TestBed.get(WorkbasketService);
alertService = TestBed.get(AlertService);
savingWorkbasketService = TestBed.get(SavingWorkbasketService);
requestInProgressService = TestBed.get(RequestInProgressService);
spyOn(alertService, 'triggerAlert');
}));
@ -175,15 +177,24 @@ describe('InformationComponent', () => {
expect(savingWorkbasketService.triggerAccessItemsSaving).toHaveBeenCalled();
});
it('should trigger requestInProgress service true before and requestInProgress false after remove a workbasket', () => {
const workbasket = new Workbasket(undefined, 'created', 'keyModified', 'domain', ICONTYPES.TOPIC,
'modified', 'name', 'description', 'owner', 'custom1', 'custom2',
'custom3', 'custom4', 'orgLevel1', 'orgLevel2',
'orgLevel3', 'orgLevel4', new Links({ 'href': 'someUrl' }, undefined, undefined, undefined, { 'href': 'someUrl' }));
component.workbasket = workbasket;
spyOn(workbasketService, 'removeDistributionTarget').and.returnValue(Observable.of(''));
const requestInProgressServiceSpy = spyOn(requestInProgressService, 'setRequestInProgress');
component.removeDistributionTargets();
expect(requestInProgressServiceSpy).toHaveBeenCalledWith(true);
workbasketService.removeDistributionTarget().subscribe(() => {
}, error => { }, complete => {
expect(requestInProgressServiceSpy).toHaveBeenCalledWith(false);
});
})
// it('should call to workbasket service to remove workbasket after click on remove workbasket', () => {
// const spy = spyOn(router, 'navigate');
// component.removeWorkbasket();
// expect(requestInProgressService.setRequestInProgress).toHaveBeenCalledWith(true);
// expect(workbasketService.deleteWorkbasket).toHaveBeenCalledWith('selfLink');
// expect(requestInProgressService.setRequestInProgress).toHaveBeenCalledWith(false);
// expect(workbasketService.triggerWorkBasketSaved).toHaveBeenCalled();
// expect(spy.calls.first().args[0][0]).toBe('/workbaskets');
// });
});

View File

@ -119,6 +119,19 @@ export class WorkbasketInformationComponent implements OnInit, OnChanges, OnDest
this.router.navigate([{ outlets: { detail: ['copy-workbasket'] } }], { relativeTo: this.route.parent });
}
removeDistributionTargets() {
this.requestInProgressService.setRequestInProgress(true);
this.workbasketService.removeDistributionTarget(this.workbasket._links.removeDistributionTargets.href).subscribe(reponse => {
this.requestInProgressService.setRequestInProgress(false);
this.alertService.triggerAlert(
new AlertModel(AlertType.SUCCESS, `DistributionTarget for workbasketID: ${this.workbasket.workbasketId} was removed successfully`))
}, error => {
this.errorModalService.triggerError(
new ErrorModel(`There was an error removing distribution target for ${this.workbasket.workbasketId}.`, error))
this.requestInProgressService.setRequestInProgress(false);
});
}
private beforeRequest() {
this.requestInProgressService.setRequestInProgress(true);

View File

@ -3,6 +3,7 @@ export class Links {
public self: { 'href': string } = undefined,
public distributionTargets: { 'href': string } = undefined,
public accessItems: { 'href': string } = undefined,
public allWorkbasketUrl: { 'href': string } = undefined
public allWorkbasketUrl: { 'href': string } = undefined,
public removeDistributionTargets: {'href': string} = undefined
) { }
}