Skip to content

Commit

Permalink
Fixed all mistakes in the Search page (#537)
Browse files Browse the repository at this point in the history
* Composing of the Item's date was refactored and moved into shared service.

* The item view box was refactored. The item view box is different for the search result. The label title is triggered on mouse hover.

* Show workspace items in the `/mydspace` - there were problem with filtering `dsoTypes` in the `clarin-search.component`

* Use Vanilla file size in the Item View and search results in the item view box.

* Updated sorting option names

* Updated search filter head messages

* Defined search options in the themed-search.component.ts following CLARIN requirements.

* Default configuration list must be set to null instead of empty array, because it shows empty space.

* Use homepage configuration which contains searching by dc.date.accessioned

* Updated border in  the item view box

* Updated `Has files` filter messages

* Show Item type in the Item view from the `emd.type`

* Fixed searching by publisher.

* Added languages for `Community` and `Rights` filtering.

* Updated `Search all of DSpace` button color.

* Fixed showing license label icons when there is czech translation.

* Updated messages on sidebar search and results header.

* Updated RSS Feed description button and css

* Prettied Copy button of handle in the Item View page

* Updated favicon icon

* Update item view box: Fixed occurrences when the author is null.

* Remove `DSpace Repository ::` from the browser page title.

* Use `LINDAT/CLARIAH-CZ Repository title prefix`

* Fixed unit tests

* Fixed linting errors

* Commented out check for view options in the Search page - for CLARIN that options was disabled.

* Fixed Verify SSR - do not check if there is DSpace in the title
  • Loading branch information
milanmajchrak committed Jun 19, 2024
1 parent d581c36 commit 8a7329a
Show file tree
Hide file tree
Showing 32 changed files with 204 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
run: |
result=$(wget -O- -q http://127.0.0.1:4000/home)
echo "$result"
echo "$result" | grep -oE "<meta name=\"title\" [^>]*>" | grep DSpace
echo "$result" | grep -oE "<meta name=\"title\" [^>]*>" | grep Home
- name: Stop running app
run: kill -9 $(lsof -t -i:4000)
Expand Down
7 changes: 4 additions & 3 deletions cypress/e2e/my-dspace.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ describe('My DSpace page', () => {

cy.get('ds-my-dspace-page').should('be.visible');

// CLARIN
// This test was commented out because there are no options for a detailed view in the CLARIN-search component
// it is e.g., `Grid` or `List` view
// Click button in sidebar to display detailed view
cy.get('ds-search-sidebar [data-test="detail-view"]').click();
// cy.get('ds-search-sidebar [data-test="detail-view"]').click();

// CLARIN
// CLARIN-search component show only Items, so there are no records in the /mydspace page
// cy.get('ds-object-detail').should('be.visible');
// CLARIN

// Analyze <ds-search-page> for accessibility issues
// CLARIN
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/metadata/metadata-bitstream.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class MetadataBitstream extends ListableObject implements HALResource {
* The fileSize of this bitstream
*/
@autoserialize
fileSize: string;
fileSize: number;

/**
* The checksum of this bitstream
Expand Down
2 changes: 0 additions & 2 deletions src/app/home-page/home-page.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,12 @@
color: #797dd4;
border-bottom: 5px solid #797dd4;
font-size: 110%;
margin-top: -10px;
}

.top-items-head {
color: #ccab28;
border-bottom: 5px solid #ccab28;
font-size: 120%;
margin-top: -10px;
}

@media (max-width: 991.98px) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/home-page/home-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ export class HomePageComponent implements OnInit {
});

const sortConfiguration = new SortOptions('dc.date.accessioned', SortDirection.DESC);

this.searchService.search(
new PaginatedSearchOptions({
configuration: 'homepage',
pagination: paginationOptions,
sort: sortConfiguration,
dsoTypes: [DSpaceObjectType.ITEM]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h6><i class="fa fa-paperclip">&nbsp;</i>{{'item.page.files.head' | translate}}<
<a *ngIf="canDownloadAllFiles" class="btn btn-download" id="download-all-button" (click)="downloadFiles()"
style="visibility: visible">
<i style="display: block" class="fa fa-download fa-3x">&nbsp;</i>
{{'item.page.download.button.all.files.zip' | translate}} ({{ totalFileSizes }})
{{'item.page.download.button.all.files.zip' | translate}} ({{ totalFileSizes | dsFileSize }})
</a>
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ClarinFilesSectionComponent', () => {
metadatabitstream.id = 123;
metadatabitstream.name = 'test';
metadatabitstream.description = 'test';
metadatabitstream.fileSize = '1MB';
metadatabitstream.fileSize = 1024;
metadatabitstream.checksum = 'abc';
metadatabitstream.type = new ResourceType('item');
metadatabitstream.fileInfo = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ClarinFilesSectionComponent implements OnInit {
/**
* total size of list of files uploaded by users to this item
*/
totalFileSizes: string;
totalFileSizes: number;

/**
* list of files uploaded by users to this item
Expand Down Expand Up @@ -96,30 +96,10 @@ export class ClarinFilesSectionComponent implements OnInit {
}

sumFileSizes() {
const sizeUnits = {
B: 1,
KB: 1000,
MB: 1000 * 1000,
GB: 1000 * 1000 * 1000,
TB: 1000 * 1000 * 1000 * 1000,
};

let totalBytes = this.listOfFiles.reduce((total, file) => {
const [valueStr, unit] = file.fileSize.split(' ');
const value = parseFloat(valueStr);
const bytes = value * sizeUnits[unit.toUpperCase()];
return total + bytes;
}, 0);

let finalUnit = 'B';
for (const unit of ['KB', 'MB', 'GB', 'TB']) {
if (totalBytes < 1000) {
break;
}
totalBytes /= 1000;
finalUnit = unit;
}

this.totalFileSizes = totalBytes.toFixed(2) + ' ' + finalUnit;
let totalBytes = 0;
this.listOfFiles.forEach((file) => {
totalBytes += file.fileSize;
});
this.totalFileSizes = totalBytes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
<div [ngClass]="isCsLocale() ? 'd-inline-flex': ''">
<a [href]="licenseURI" class="pl-1">{{license}}</a>
</div>
<div class="d-inline" *ngFor="let icon of (licenseLabelIcons | async)">
<img class="mr-1" [src]="secureImageData(icon)" alt="" width="24px">
<div>
<img class="mr-1"
*ngFor="let lli of (licenseLabelIcons | async)"
[src]="secureImageData(lli.icon)"
[ngbTooltip]="lli?.title"
placement="bottom"
triggers="mouseenter:mouseleave"
alt="" width="24px">
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class ClarinLicenseInfoComponent implements OnInit {
.subscribe(clarinLicense => {
let iconsList = [];
clarinLicense.extendedClarinLicenseLabels.forEach(extendedCll => {
iconsList.push(extendedCll?.icon);
iconsList.push(extendedCll);
});
this.licenseLabelIcons.next(iconsList);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { TranslateModule } from '@ngx-translate/core';
import { Item } from '../../../../core/shared/item.model';
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
import { createPaginatedList } from '../../../../shared/testing/utils.test';
import { ClarinDateService } from '../../../../shared/clarin-date.service';

describe('ClarinDateItemFieldComponent', () => {
let component: ClarinDateItemFieldComponent;
let fixture: ComponentFixture<ClarinDateItemFieldComponent>;
let clarinDateService: ClarinDateService;

const mockItem: Item = Object.assign(new Item(), {
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
Expand All @@ -23,9 +25,15 @@ describe('ClarinDateItemFieldComponent', () => {
});

beforeEach(async () => {
clarinDateService = jasmine.createSpyObj('clarinDateService', {
composeItemDate: '2020-01-01' });

await TestBed.configureTestingModule({
imports: [ TranslateModule.forRoot() ],
declarations: [ ClarinDateItemFieldComponent ]
declarations: [ ClarinDateItemFieldComponent ],
providers: [
{ provide: ClarinDateService, useValue: clarinDateService }
]
})
.compileComponents();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { Item } from '../../../../core/shared/item.model';
import { BehaviorSubject } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';

const MULTIPLE_DATE_VALUES_SEPARATOR = ',';
import { ClarinDateService } from '../../../../shared/clarin-date.service';

@Component({
selector: 'ds-clarin-date-item-field',
Expand All @@ -12,7 +10,7 @@ const MULTIPLE_DATE_VALUES_SEPARATOR = ',';
})
export class ClarinDateItemFieldComponent implements OnInit {

constructor(private translateService: TranslateService) {
constructor(private clarinDateService: ClarinDateService) {
}

/**
Expand All @@ -23,38 +21,6 @@ export class ClarinDateItemFieldComponent implements OnInit {
updatedDateValue: BehaviorSubject<string> = new BehaviorSubject<string>('');

ngOnInit(): void {
let localDateValue = this.item.allMetadataValues('local.approximateDate.issued');
let dateValue = this.item.allMetadataValues('dc.date.issued');

// There is no local date value - show only one date metadata value
if (localDateValue.length === 0) {
// Date value is not empty
if (dateValue.length !== 0) {
this.updatedDateValue.next(dateValue[0]);
} else {
console.error('There is no date value for the item');
}
return;
}

// There is local date value - that values could be different and should be shown differently
localDateValue = localDateValue[0]?.split(MULTIPLE_DATE_VALUES_SEPARATOR);

if (localDateValue.length === 1) {
this.updatedDateValue.next(this.updateOneValue(localDateValue));
} else {
this.updatedDateValue.next(this.updateMoreValues(localDateValue));
}
}

updateOneValue(localDateValue: string[]) {
const ccaMessage = this.translateService.instant('item.page.date.cca.message');
return ccaMessage + ' (' + localDateValue[0] + ')';
}

updateMoreValues(localDateValue: string[]) {
const composedMessage = this.translateService.instant('item.page.date.composed.message');
const dateValues = localDateValue.join(MULTIPLE_DATE_VALUES_SEPARATOR);
return composedMessage + ' ' + dateValues;
this.updatedDateValue.next(this.clarinDateService.composeItemDate(this.item));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div *ngFor="let identifier of (identifiers | async)">
<div class="justify-content-between d-flex">
<a [href]="identifier">{{identifier}}</a>
<i class="far fa-copy pr-5 cursor-pointer"
<i class="far fa-copy cursor-pointer"
(click)="copyToClipboard(identifier)"
[ngbTooltip]="'Copied!'" #copyButton="ngbTooltip"></i>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</dd>
<dt>{{'item.file.description.size' | translate}}</dt>
<dd>
{{ fileInput.fileSize }}
{{ fileInput.fileSize | dsFileSize }}
</dd>
<dt>{{'item.file.description.format' | translate}}</dt>
<dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import { FileDescriptionComponent } from './file-description.component';
import { createSuccessfulRemoteDataObject$ } from '../../../../../shared/remote-data.utils';
import { ConfigurationProperty } from '../../../../../core/shared/configuration-property.model';
import { ConfigurationDataService } from '../../../../../core/data/configuration-data.service';
import { getMockTranslateService } from '../../../../../shared/mocks/translate.service.mock';
import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateLoaderMock } from '../../../../../shared/mocks/translate-loader.mock';
import { RouterTestingModule } from '@angular/router/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HALEndpointService } from '../../../../../core/shared/hal-endpoint.service';
import { FileSizePipe } from '../../../../../shared/utils/file-size-pipe';

describe('FileDescriptionComponent', () => {
let component: FileDescriptionComponent;
let fixture: ComponentFixture<FileDescriptionComponent>;
let translateService: TranslateService;
let halService: HALEndpointService;

beforeEach(async () => {
Expand All @@ -33,15 +32,14 @@ describe('FileDescriptionComponent', () => {
getRootHref: 'root url',
});

translateService = getMockTranslateService();
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderMock
}
}), RouterTestingModule.withRoutes([]), BrowserAnimationsModule],
declarations: [FileDescriptionComponent],
declarations: [FileDescriptionComponent, FileSizePipe],
providers: [
{ provide: ConfigurationDataService, useValue: configurationDataService },
{ provide: HALEndpointService, useValue: halService }
Expand All @@ -58,7 +56,7 @@ describe('FileDescriptionComponent', () => {
fileInput.id = 123;
fileInput.name = 'testFile';
fileInput.description = 'test description';
fileInput.fileSize = '5MB';
fileInput.fileSize = 2048;
fileInput.checksum = 'abc';
fileInput.type = new ResourceType('item');
fileInput.fileInfo = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('PreviewSectionComponent', () => {
metadatabitstream.id = 123;
metadatabitstream.name = 'test';
metadatabitstream.description = 'test';
metadatabitstream.fileSize = '1MB';
metadatabitstream.fileSize = 1024;
metadatabitstream.checksum = 'abc';
metadatabitstream.type = new ResourceType('item');
metadatabitstream.fileInfo = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
[type]="'date'">
</ds-clarin-generic-item-field>
<ds-clarin-generic-item-field [item]="object"
[fields]="['dc.type', 'metashare.ResourceInfo#ContentInfo.mediaType']"
[fields]="['dc.type', 'metashare.ResourceInfo#ContentInfo.mediaType', 'edm.type']"
[label]="'item.page.type'"
[iconName]="'fa-tag'"
[separator]="','"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
[type]="'date'">
</ds-clarin-generic-item-field>
<ds-clarin-generic-item-field [item]="object"
[fields]="['dc.type', 'metashare.ResourceInfo#ContentInfo.mediaType']"
[fields]="['dc.type', 'metashare.ResourceInfo#ContentInfo.mediaType', 'edm.type']"
[label]="'item.page.type'"
[iconName]="'fa-tag'"
[separator]="','"
Expand Down
51 changes: 51 additions & 0 deletions src/app/shared/clarin-date.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Item } from '../core/shared/item.model';

const MULTIPLE_DATE_VALUES_SEPARATOR = ',';

@Injectable()
export class ClarinDateService {
constructor(private translateService: TranslateService) {}

/**
* Compose date value for the item. The date value could be fetched from the local metadata or from the
* default metadata. The date value could be a single value or multiple values (local metadata).
* @param item
*/
composeItemDate(item: Item): string {
let localDateValue = item.allMetadataValues('local.approximateDate.issued');
let dateValue = item.allMetadataValues('dc.date.issued');

// There is no local date value - show only one date metadata value
if (localDateValue.length === 0) {
// Date value is not empty
if (dateValue.length !== 0) {
return dateValue[0];
} else {
console.error('There is no date value for the item');
return '';
}
}

// There is local date value - that values could be different and should be shown differently
localDateValue = localDateValue[0]?.split(MULTIPLE_DATE_VALUES_SEPARATOR);

if (localDateValue.length === 1) {
return this.updateOneValue(localDateValue);
} else {
return this.updateMoreValues(localDateValue);
}
}

updateOneValue(localDateValue: string[]) {
const ccaMessage = this.translateService.instant('item.page.date.cca.message');
return ccaMessage + ' (' + localDateValue[0] + ')';
}

updateMoreValues(localDateValue: string[]) {
const composedMessage = this.translateService.instant('item.page.date.composed.message');
const dateValues = localDateValue.join(MULTIPLE_DATE_VALUES_SEPARATOR);
return composedMessage + ' ' + dateValues;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div>
<div *ngIf="itemAuthors.value.length">
<div class="pt-1"><strong>{{'item.view.box.author.message' | translate}}</strong></div>
<div *ngIf="itemAuthors.value.length <= 5" class="item-author-wrapper pb-1">
<span *ngFor="let author of (itemAuthors | async); let i = index">
<span *ngIf="i > 0 && i < itemAuthors.value.length -1">; </span>
Expand Down
Loading

0 comments on commit 8a7329a

Please sign in to comment.