Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<ng-container *ngVar="(bitstreamsRD$ | async) as bitstreamsRD">
<div class="file-section my-3 justify-content-center">
<div class="w-100 file-section-header mb-3">
<h3 [innerText]="label | translate"></h3>
</div>
<div class="file-section-table">
<div class="row heading mx-0">
<div class="col-6">
<h4 [innerText]="'file.section.name' | translate"></h4>
</div>
<div class="col-3">
<h4 [innerText]="'file.section.type' | translate"></h4>
</div>
<div class="col-2">
<h4 [innerText]="'file.section.size' | translate"></h4>
</div>
<div class="col-1">
</div>
</div>
<div class="mx-1">
@if (bitstreamsRD?.payload?.totalElements > 0) {
<ds-pagination
[paginationOptions]="pageConfig"
[collectionSize]="bitstreamsRD?.payload?.totalElements"
[hideGear]="true"
[hidePagerWhenSinglePage]="true"
[retainScrollPosition]="true">
<div class="entries">
@for (file of bitstreamsRD?.payload?.page; track file) {
<div class="row file-section-entry mx-0">
<div class="col-6">
<span [innerHTML]="dsoNameService.getName(file)"></span>
</div>
<div class="col-3">
<span>{{ (bitstreamFormatDataService.findByBitstream(file) | async).payload?.shortDescription }}</span>
</div>
<div class="col-2">
<span> {{ (file?.sizeBytes) | dsFileSize }}</span>
</div>
<div class="col-1 text-center">
<ds-file-download-link [bitstream]="file" [item]="item">
<i class="fa fa-download"></i>
</ds-file-download-link>
</div>
</div>
}
</div>
</ds-pagination>
}
</div>
</div>
</div>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@import '../../../../../styles/variables.scss';

.file-section {
padding: 1rem;
background-color: var(--bs-gray-200);

.file-section-header {
border-bottom: 4px solid var(--bs-primary);
}

.file-section-table {
.row {
padding: 0.4em 0.75em;
}
.entries {
.file-section-entry {
background-color: var(--bs-300);
&:nth-child(2n + 1) {
background-color: var(--bs-gray-100);
}
}
}
.heading {
border-bottom: 1px solid var(--bs-gray-900);
background-color: var(--bs-gray-400);
font-size: 1.25em;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import {
ComponentFixture,
TestBed,
waitForAsync,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ActivatedRoute } from '@angular/router';
import { APP_CONFIG } from '@dspace/config/app-config.interface';
import { BitstreamDataService } from '@dspace/core/data/bitstream-data.service';
import { BitstreamFormatDataService } from '@dspace/core/data/bitstream-format-data.service';
import { LocaleService } from '@dspace/core/locale/locale.service';
import { NotificationsService } from '@dspace/core/notification-system/notifications.service';
import { PaginationService } from '@dspace/core/pagination/pagination.service';
import { Bitstream } from '@dspace/core/shared/bitstream.model';
import { BitstreamFormat } from '@dspace/core/shared/bitstream-format.model';
import { Item } from '@dspace/core/shared/item.model';
import { ActivatedRouteStub } from '@dspace/core/testing/active-router.stub';
import { NotificationsServiceStub } from '@dspace/core/testing/notifications-service.stub';
import { PaginationServiceStub } from '@dspace/core/testing/pagination-service.stub';
import { TranslateLoaderMock } from '@dspace/core/testing/translate-loader.mock';
import { createPaginatedList } from '@dspace/core/testing/utils.test';
import { createSuccessfulRemoteDataObject$ } from '@dspace/core/utilities/remote-data.utils';
import { XSRFService } from '@dspace/core/xsrf/xsrf.service';
import { provideMockStore } from '@ngrx/store/testing';
import {
TranslateLoader,
TranslateModule,
} from '@ngx-translate/core';
import { of } from 'rxjs';

import { environment } from '../../../../../environments/environment';
import { ThemedFileDownloadLinkComponent } from '../../../../shared/file-download-link/themed-file-download-link.component';
import { PaginationComponent } from '../../../../shared/pagination/pagination.component';
import { SearchConfigurationService } from '../../../../shared/search/search-configuration.service';
import { getMockThemeService } from '../../../../shared/theme-support/test/theme-service.mock';
import { ThemeService } from '../../../../shared/theme-support/theme.service';
import { FileSizePipe } from '../../../../shared/utils/file-size-pipe';
import { VarDirective } from '../../../../shared/utils/var.directive';
import { ExtendedFileSectionComponent } from './extended-file-section.component';

describe('ExtendedFileSectionComponent', () => {
let component: ExtendedFileSectionComponent;
let fixture: ComponentFixture<ExtendedFileSectionComponent>;
let localeService: any;
const languageList = ['en;q=1', 'de;q=0.8'];
const mockLocaleService = jasmine.createSpyObj('LocaleService', {
getCurrentLanguageCode: jasmine.createSpy('getCurrentLanguageCode'),
getLanguageCodeList: of(languageList),
});

const paginationServiceStub = new PaginationServiceStub();

const mockItem = Object.assign(new Item(), {
id: 'test-item-id',
uuid: 'test-item-id',
_links: {
self: { href: 'test-item-selflink' },
},
});

const mockBitstream = Object.assign(new Bitstream(), {
id: 'test-bitstream-id',
uuid: 'test-bitstream-id',
name: 'test-bitstream.pdf',
sizeBytes: 1024,
_links: {
self: { href: 'test-bitstream-selflink' },
},
});

const mockBitstreamFormat = Object.assign(new BitstreamFormat(), {
resourceType: 'testResourceType',
shortDescription: 'testShortDescription',
description: 'testDescription',
mimetype: 'test/mimeType',
});

const paginatedList = createPaginatedList([mockBitstream]);

paginatedList.pageInfo.elementsPerPage = environment.item.bitstream.pageSize;

const bitstreamDataService = jasmine.createSpyObj('bitstreamDataService', {
findAllByItemAndBundleName: createSuccessfulRemoteDataObject$(paginatedList),
});

const bitstreamFormatDataService = jasmine.createSpyObj('bitstreamFormatDataService', {
findByBitstream: createSuccessfulRemoteDataObject$(mockBitstreamFormat),
});

beforeEach(waitForAsync(() => {

TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderMock,
},
}),
BrowserAnimationsModule,
ExtendedFileSectionComponent,
VarDirective,
FileSizePipe,
],
providers: [
provideMockStore(),
{ provide: XSRFService, useValue: {} },
{ provide: BitstreamDataService, useValue: bitstreamDataService },
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: BitstreamFormatDataService, useValue: bitstreamFormatDataService },
{ provide: ThemeService, useValue: getMockThemeService() },
{ provide: SearchConfigurationService, useValue: jasmine.createSpyObj(['getCurrentConfiguration']) },
{ provide: PaginationService, useValue: paginationServiceStub },
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
{ provide: LocaleService, useValue: mockLocaleService },
{ provide: APP_CONFIG, useValue: environment },
],
schemas: [NO_ERRORS_SCHEMA],
}).overrideComponent(ExtendedFileSectionComponent, {
remove: {
imports: [
PaginationComponent,
ThemedFileDownloadLinkComponent,
],
},
}).compileComponents();
}));

beforeEach(waitForAsync(() => {
localeService = TestBed.inject(LocaleService);
localeService.getCurrentLanguageCode.and.returnValue(of('en'));
fixture = TestBed.createComponent(ExtendedFileSectionComponent);
component = fixture.componentInstance;
component.item = mockItem;
fixture.detectChanges();
}));

it('should create', () => {
expect(component).toBeTruthy();
});

it('should set pageSize from appConfig', () => {
expect(component.pageSize).toEqual(environment.item.bitstream.pageSize);
});

describe('when the extended file section gets loaded with bitstreams available', () => {
it('should contain a list with bitstream', () => {
const fileSection = fixture.debugElement.queryAll(By.css('.file-section-entry'));
expect(fileSection.length).toEqual(1);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { AsyncPipe } from '@angular/common';
import {
Component,
Inject,
Input,
OnInit,
} from '@angular/core';
import {
APP_CONFIG,
AppConfig,
} from '@dspace/config/app-config.interface';
import { DSONameService } from '@dspace/core/breadcrumbs/dso-name.service';
import { BitstreamDataService } from '@dspace/core/data/bitstream-data.service';
import { BitstreamFormatDataService } from '@dspace/core/data/bitstream-format-data.service';
import { PaginatedList } from '@dspace/core/data/paginated-list.model';
import { RemoteData } from '@dspace/core/data/remote-data';
import { PaginationService } from '@dspace/core/pagination/pagination.service';
import { PaginationComponentOptions } from '@dspace/core/pagination/pagination-component-options.model';
import { Bitstream } from '@dspace/core/shared/bitstream.model';
import { followLink } from '@dspace/core/shared/follow-link-config.model';
import { Item } from '@dspace/core/shared/item.model';
import { TranslateModule } from '@ngx-translate/core';
import {
from,
Observable,
} from 'rxjs';
import { switchMap } from 'rxjs/operators';

import { ThemedFileDownloadLinkComponent } from '../../../../shared/file-download-link/themed-file-download-link.component';
import { PaginationComponent } from '../../../../shared/pagination/pagination.component';
import { FileSizePipe } from '../../../../shared/utils/file-size-pipe';
import { VarDirective } from '../../../../shared/utils/var.directive';

@Component({
selector: 'ds-extended-file-section',
imports: [
AsyncPipe,
FileSizePipe,
PaginationComponent,
ThemedFileDownloadLinkComponent,
TranslateModule,
VarDirective,
],
templateUrl: './extended-file-section.component.html',
styleUrl: './extended-file-section.component.scss',
})
export class ExtendedFileSectionComponent implements OnInit {

@Input() item: Item;

@Input() bundleName = 'ORIGINAL';

@Input() label = 'item.page.extended-file-section';

bitstreamsRD$: Observable<RemoteData<PaginatedList<Bitstream>>>;

pageSize = this.appConfig.item.bitstream.pageSize;


/**
* The current pagination configuration for the page
*/
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
id: 'efs',
currentPage: 1,
pageSize: this.appConfig.item.bitstream.pageSize,
});


constructor(
protected bitstreamDataService: BitstreamDataService,
protected bitstreamFormatDataService: BitstreamFormatDataService,
public dsoNameService: DSONameService,
@Inject(APP_CONFIG) protected appConfig: AppConfig,
private paginationService: PaginationService,
) {
this.bitstreamsRD$ = from([]);
}

ngOnInit(): void {
this.bitstreamsRD$ = this.paginationService.getCurrentPagination(this.pageConfig.id, this.pageConfig).pipe(
switchMap((options: PaginationComponentOptions) => {
return this.bitstreamDataService.findAllByItemAndBundleName(
this.item,
this.bundleName,
{ elementsPerPage: options.pageSize, currentPage: options.currentPage },
true,
true,
followLink('format'),
followLink('accessStatus'),
);
}),
);
}


}
Loading
Loading