mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 04:53:06 +00:00
118223: Remove unused item-edit-bitstream component
This commit is contained in:
@@ -15,7 +15,6 @@ import { ItemPrivateComponent } from './item-private/item-private.component';
|
|||||||
import { ItemPublicComponent } from './item-public/item-public.component';
|
import { ItemPublicComponent } from './item-public/item-public.component';
|
||||||
import { ItemDeleteComponent } from './item-delete/item-delete.component';
|
import { ItemDeleteComponent } from './item-delete/item-delete.component';
|
||||||
import { ItemBitstreamsComponent } from './item-bitstreams/item-bitstreams.component';
|
import { ItemBitstreamsComponent } from './item-bitstreams/item-bitstreams.component';
|
||||||
import { ItemEditBitstreamComponent } from './item-bitstreams/item-edit-bitstream/item-edit-bitstream.component';
|
|
||||||
import { SearchPageModule } from '../../search-page/search-page.module';
|
import { SearchPageModule } from '../../search-page/search-page.module';
|
||||||
import { ItemCollectionMapperComponent } from './item-collection-mapper/item-collection-mapper.component';
|
import { ItemCollectionMapperComponent } from './item-collection-mapper/item-collection-mapper.component';
|
||||||
import { ItemRelationshipsComponent } from './item-relationships/item-relationships.component';
|
import { ItemRelationshipsComponent } from './item-relationships/item-relationships.component';
|
||||||
@@ -78,7 +77,6 @@ import {
|
|||||||
ItemRelationshipsComponent,
|
ItemRelationshipsComponent,
|
||||||
ItemBitstreamsComponent,
|
ItemBitstreamsComponent,
|
||||||
ItemVersionHistoryComponent,
|
ItemVersionHistoryComponent,
|
||||||
ItemEditBitstreamComponent,
|
|
||||||
ItemEditBitstreamBundleComponent,
|
ItemEditBitstreamBundleComponent,
|
||||||
EditRelationshipComponent,
|
EditRelationshipComponent,
|
||||||
EditRelationshipListComponent,
|
EditRelationshipListComponent,
|
||||||
|
@@ -1,51 +0,0 @@
|
|||||||
<ng-template #bitstreamView>
|
|
||||||
<div class="{{columnSizes.columns[0].buildClasses()}} row-element d-flex">
|
|
||||||
<ng-content select="[slot=drag-handle]"></ng-content>
|
|
||||||
<div class="float-left d-flex align-items-center overflow-hidden">
|
|
||||||
<span class="text-truncate">
|
|
||||||
{{ bitstreamName }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="{{columnSizes.columns[1].buildClasses()}} row-element d-flex align-items-center">
|
|
||||||
<div class="w-100">
|
|
||||||
<div class="text-truncate" [tooltipClass]="'larger-tooltip'" placement="bottom"
|
|
||||||
[ngbTooltip]="bitstream?.firstMetadataValue('dc.description')">
|
|
||||||
{{ bitstream?.firstMetadataValue('dc.description') }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="{{columnSizes.columns[2].buildClasses()}} row-element d-flex align-items-center">
|
|
||||||
<div class="text-center w-100">
|
|
||||||
<span class="text-truncate">
|
|
||||||
{{ (format$ | async)?.shortDescription }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="{{columnSizes.columns[3].buildClasses()}} row-element d-flex align-items-center">
|
|
||||||
<div class="text-center w-100">
|
|
||||||
<div class="btn-group relationship-action-buttons">
|
|
||||||
<a *ngIf="bitstreamDownloadUrl != null" [href]="bitstreamDownloadUrl"
|
|
||||||
class="btn btn-outline-primary btn-sm"
|
|
||||||
title="{{'item.edit.bitstreams.edit.buttons.download' | translate}}"
|
|
||||||
[attr.data-test]="'download-button' | dsBrowserOnly">
|
|
||||||
<i class="fas fa-download fa-fw"></i>
|
|
||||||
</a>
|
|
||||||
<button [routerLink]="['/bitstreams/', bitstream.id, 'edit']" class="btn btn-outline-primary btn-sm"
|
|
||||||
title="{{'item.edit.bitstreams.edit.buttons.edit' | translate}}">
|
|
||||||
<i class="fas fa-edit fa-fw"></i>
|
|
||||||
</button>
|
|
||||||
<button [disabled]="!canRemove()" (click)="remove()"
|
|
||||||
class="btn btn-outline-danger btn-sm"
|
|
||||||
title="{{'item.edit.bitstreams.edit.buttons.remove' | translate}}">
|
|
||||||
<i class="fas fa-trash-alt fa-fw"></i>
|
|
||||||
</button>
|
|
||||||
<button [disabled]="!canUndo()" (click)="undo()"
|
|
||||||
class="btn btn-outline-warning btn-sm"
|
|
||||||
title="{{'item.edit.bitstreams.edit.buttons.undo' | translate}}">
|
|
||||||
<i class="fas fa-undo-alt fa-fw"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</ng-template>
|
|
@@ -1,145 +0,0 @@
|
|||||||
import { ItemEditBitstreamComponent } from './item-edit-bitstream.component';
|
|
||||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
|
||||||
import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service';
|
|
||||||
import { of as observableOf } from 'rxjs';
|
|
||||||
import { Bitstream } from '../../../../core/shared/bitstream.model';
|
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
|
||||||
import { VarDirective } from '../../../../shared/utils/var.directive';
|
|
||||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
|
||||||
import { BitstreamFormat } from '../../../../core/shared/bitstream-format.model';
|
|
||||||
import { ResponsiveTableSizes } from '../../../../shared/responsive-table-sizes/responsive-table-sizes';
|
|
||||||
import { ResponsiveColumnSizes } from '../../../../shared/responsive-table-sizes/responsive-column-sizes';
|
|
||||||
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
|
|
||||||
import { getBitstreamDownloadRoute } from '../../../../app-routing-paths';
|
|
||||||
import { By } from '@angular/platform-browser';
|
|
||||||
import { BrowserOnlyMockPipe } from '../../../../shared/testing/browser-only-mock.pipe';
|
|
||||||
|
|
||||||
let comp: ItemEditBitstreamComponent;
|
|
||||||
let fixture: ComponentFixture<ItemEditBitstreamComponent>;
|
|
||||||
|
|
||||||
const columnSizes = new ResponsiveTableSizes([
|
|
||||||
new ResponsiveColumnSizes(2, 2, 3, 4, 4),
|
|
||||||
new ResponsiveColumnSizes(2, 3, 3, 3, 3),
|
|
||||||
new ResponsiveColumnSizes(2, 2, 2, 2, 2),
|
|
||||||
new ResponsiveColumnSizes(6, 5, 4, 3, 3)
|
|
||||||
]);
|
|
||||||
|
|
||||||
const format = Object.assign(new BitstreamFormat(), {
|
|
||||||
shortDescription: 'PDF'
|
|
||||||
});
|
|
||||||
const bitstream = Object.assign(new Bitstream(), {
|
|
||||||
uuid: 'bitstreamUUID',
|
|
||||||
name: 'Fake Bitstream',
|
|
||||||
bundleName: 'ORIGINAL',
|
|
||||||
description: 'Description',
|
|
||||||
_links: {
|
|
||||||
content: { href: 'content-link' }
|
|
||||||
},
|
|
||||||
|
|
||||||
format: createSuccessfulRemoteDataObject$(format)
|
|
||||||
});
|
|
||||||
const fieldUpdate = {
|
|
||||||
field: bitstream,
|
|
||||||
changeType: undefined
|
|
||||||
};
|
|
||||||
const date = new Date();
|
|
||||||
const url = 'thisUrl';
|
|
||||||
|
|
||||||
let objectUpdatesService: ObjectUpdatesService;
|
|
||||||
|
|
||||||
describe('ItemEditBitstreamComponent', () => {
|
|
||||||
beforeEach(waitForAsync(() => {
|
|
||||||
objectUpdatesService = jasmine.createSpyObj('objectUpdatesService',
|
|
||||||
{
|
|
||||||
getFieldUpdates: observableOf({
|
|
||||||
[bitstream.uuid]: fieldUpdate,
|
|
||||||
}),
|
|
||||||
getFieldUpdatesExclusive: observableOf({
|
|
||||||
[bitstream.uuid]: fieldUpdate,
|
|
||||||
}),
|
|
||||||
saveRemoveFieldUpdate: {},
|
|
||||||
removeSingleFieldUpdate: {},
|
|
||||||
saveAddFieldUpdate: {},
|
|
||||||
discardFieldUpdates: {},
|
|
||||||
reinstateFieldUpdates: observableOf(true),
|
|
||||||
initialize: {},
|
|
||||||
getUpdatedFields: observableOf([bitstream]),
|
|
||||||
getLastModified: observableOf(date),
|
|
||||||
hasUpdates: observableOf(true),
|
|
||||||
isReinstatable: observableOf(false),
|
|
||||||
isValidPage: observableOf(true)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
imports: [TranslateModule.forRoot()],
|
|
||||||
declarations: [
|
|
||||||
ItemEditBitstreamComponent,
|
|
||||||
VarDirective,
|
|
||||||
BrowserOnlyMockPipe,
|
|
||||||
],
|
|
||||||
providers: [
|
|
||||||
{ provide: ObjectUpdatesService, useValue: objectUpdatesService }
|
|
||||||
], schemas: [
|
|
||||||
NO_ERRORS_SCHEMA
|
|
||||||
]
|
|
||||||
}).compileComponents();
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(ItemEditBitstreamComponent);
|
|
||||||
comp = fixture.componentInstance;
|
|
||||||
comp.fieldUpdate = fieldUpdate;
|
|
||||||
comp.bundleUrl = url;
|
|
||||||
comp.columnSizes = columnSizes;
|
|
||||||
comp.ngOnChanges(undefined);
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when remove is called', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
comp.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call saveRemoveFieldUpdate on objectUpdatesService', () => {
|
|
||||||
expect(objectUpdatesService.saveRemoveFieldUpdate).toHaveBeenCalledWith(url, bitstream);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when undo is called', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
comp.undo();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call removeSingleFieldUpdate on objectUpdatesService', () => {
|
|
||||||
expect(objectUpdatesService.removeSingleFieldUpdate).toHaveBeenCalledWith(url, bitstream.uuid);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when canRemove is called', () => {
|
|
||||||
it('should return true', () => {
|
|
||||||
expect(comp.canRemove()).toEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when canUndo is called', () => {
|
|
||||||
it('should return false', () => {
|
|
||||||
expect(comp.canUndo()).toEqual(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the component loads', () => {
|
|
||||||
it('should contain download button with a valid link to the bitstreams download page', () => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
const downloadBtnHref = fixture.debugElement.query(By.css('[data-test="download-button"]')).nativeElement.getAttribute('href');
|
|
||||||
expect(downloadBtnHref).toEqual(comp.bitstreamDownloadUrl);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the bitstreamDownloadUrl property gets populated', () => {
|
|
||||||
it('should contain the bitstream download page route', () => {
|
|
||||||
expect(comp.bitstreamDownloadUrl).not.toEqual(bitstream._links.content.href);
|
|
||||||
expect(comp.bitstreamDownloadUrl).toEqual(getBitstreamDownloadRoute(bitstream));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,117 +0,0 @@
|
|||||||
import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild, ViewContainerRef } from '@angular/core';
|
|
||||||
import { Bitstream } from '../../../../core/shared/bitstream.model';
|
|
||||||
import cloneDeep from 'lodash/cloneDeep';
|
|
||||||
import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service';
|
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { BitstreamFormat } from '../../../../core/shared/bitstream-format.model';
|
|
||||||
import { getRemoteDataPayload, getFirstSucceededRemoteData } from '../../../../core/shared/operators';
|
|
||||||
import { ResponsiveTableSizes } from '../../../../shared/responsive-table-sizes/responsive-table-sizes';
|
|
||||||
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
|
|
||||||
import { FieldUpdate } from '../../../../core/data/object-updates/field-update.model';
|
|
||||||
import { FieldChangeType } from '../../../../core/data/object-updates/field-change-type.model';
|
|
||||||
import { getBitstreamDownloadRoute } from '../../../../app-routing-paths';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'ds-item-edit-bitstream',
|
|
||||||
styleUrls: ['../item-bitstreams.component.scss'],
|
|
||||||
templateUrl: './item-edit-bitstream.component.html',
|
|
||||||
})
|
|
||||||
/**
|
|
||||||
* Component that displays a single bitstream of an item on the edit page
|
|
||||||
* Creates an embedded view of the contents
|
|
||||||
* (which means it'll be added to the parents html without a wrapping ds-item-edit-bitstream element)
|
|
||||||
*/
|
|
||||||
export class ItemEditBitstreamComponent implements OnChanges, OnInit {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The view on the bitstream
|
|
||||||
*/
|
|
||||||
@ViewChild('bitstreamView', {static: true}) bitstreamView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current field, value and state of the bitstream
|
|
||||||
*/
|
|
||||||
@Input() fieldUpdate: FieldUpdate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The url of the bundle
|
|
||||||
*/
|
|
||||||
@Input() bundleUrl: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The bootstrap sizes used for the columns within this table
|
|
||||||
*/
|
|
||||||
@Input() columnSizes: ResponsiveTableSizes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The bitstream of this field
|
|
||||||
*/
|
|
||||||
bitstream: Bitstream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The bitstream's name
|
|
||||||
*/
|
|
||||||
bitstreamName: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The bitstream's download url
|
|
||||||
*/
|
|
||||||
bitstreamDownloadUrl: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The format of the bitstream
|
|
||||||
*/
|
|
||||||
format$: Observable<BitstreamFormat>;
|
|
||||||
|
|
||||||
constructor(private objectUpdatesService: ObjectUpdatesService,
|
|
||||||
private dsoNameService: DSONameService,
|
|
||||||
private viewContainerRef: ViewContainerRef) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
|
||||||
this.viewContainerRef.createEmbeddedView(this.bitstreamView);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the current bitstream and its format on changes
|
|
||||||
* @param changes
|
|
||||||
*/
|
|
||||||
ngOnChanges(changes: SimpleChanges): void {
|
|
||||||
this.bitstream = cloneDeep(this.fieldUpdate.field) as Bitstream;
|
|
||||||
this.bitstreamName = this.dsoNameService.getName(this.bitstream);
|
|
||||||
this.bitstreamDownloadUrl = getBitstreamDownloadRoute(this.bitstream);
|
|
||||||
this.format$ = this.bitstream.format.pipe(
|
|
||||||
getFirstSucceededRemoteData(),
|
|
||||||
getRemoteDataPayload()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a new remove update for this field to the object updates service
|
|
||||||
*/
|
|
||||||
remove(): void {
|
|
||||||
this.objectUpdatesService.saveRemoveFieldUpdate(this.bundleUrl, this.bitstream);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels the current update for this field in the object updates service
|
|
||||||
*/
|
|
||||||
undo(): void {
|
|
||||||
this.objectUpdatesService.removeSingleFieldUpdate(this.bundleUrl, this.bitstream.uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a user should be allowed to remove this field
|
|
||||||
*/
|
|
||||||
canRemove(): boolean {
|
|
||||||
return this.fieldUpdate.changeType !== FieldChangeType.REMOVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a user should be allowed to cancel the update to this field
|
|
||||||
*/
|
|
||||||
canUndo(): boolean {
|
|
||||||
return this.fieldUpdate.changeType >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user