Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ufal/fe-item-view-license-box #427

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 12 additions & 10 deletions src/app/item-page/simple/item-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,31 @@
<ds-view-tracker [object]="item"></ds-view-tracker>
<ds-listable-object-component-loader *ngIf="!item.isWithdrawn || (isAdmin$|async)" [object]="item" [viewMode]="viewMode"></ds-listable-object-component-loader>
<ds-item-versions class="mt-2" [item]="item" [displayActions]="false"></ds-item-versions>
<ds-clarin-license-info class="mt-3 d-block" [item]="item"></ds-clarin-license-info>
<h6><i class="fa fa-paperclip">&nbsp;</i>{{'item.page.files.head' | translate}}</h6>
<div class="pb-3">
<div *ngIf="(hasFiles | async) === true">
<ds-clarin-license-info class="mt-3 d-block" [item]="item"></ds-clarin-license-info>
<h6><i class="fa fa-paperclip">&nbsp;</i>{{'item.page.files.head' | translate}}</h6>
<div class="pb-3">
<span class="pr-1">
<a class="btn btn-download" (click)="setCommandline()" style="text-decoration: none"
*ngIf="canShowCurlDownload">
<i class="fa fa-download fa-3x" style="display: block">&nbsp;</i>
{{'item.page.download.button.command.line' | translate}}
</a>
</span>
<div id="command-div" *ngIf="isCommandLineVisible">
<button class="repo-copy-btn pull-right" data-clipboard-target="#command-div"></button>
<pre style="background-color: #d9edf7; color: #3a87ad">{{ command }}</pre>
</div>
<span>
<div id="command-div" *ngIf="isCommandLineVisible">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

<button class="repo-copy-btn pull-right" data-clipboard-target="#command-div"></button>
<pre style="background-color: #d9edf7; color: #3a87ad">{{ command }}</pre>
</div>
<span>
<a *ngIf="canDownloadAllFiles" class="btn btn-download" id="download-all-button" (click)="downloadFiles()"
style="visibility: visible">
style="visibility: visible">
<i style="display: block" class="fa fa-download fa-3x">&nbsp;</i>
{{'item.page.download.button.all.files.zip' | translate}} ({{ totalFileSizes }})
</a>
</span>
</div>
<ds-preview-section [item]="item"></ds-preview-section>
</div>
<ds-preview-section [item]="item"></ds-preview-section>
</div>
</div>
<ds-error *ngIf="itemRD?.hasFailed" message="{{'error.item' | translate}}"></ds-error>
Expand Down
20 changes: 19 additions & 1 deletion src/app/item-page/simple/item-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ import { MetadataBitstreamDataService } from 'src/app/core/data/metadata-bitstre
import { getMockTranslateService } from 'src/app/shared/mocks/translate.service.mock';
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
import { MetadataValue } from '../../core/shared/metadata.models';

const mockItem: Item = Object.assign(new Item(), {
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
metadata: [],
metadata: {
'local.has.files': [Object.assign(new MetadataValue(), {
value: 'yes',
language: undefined
})]
},
relationships: createRelationshipsObservable()
});

Expand Down Expand Up @@ -207,4 +213,16 @@ describe('ItemPageComponent', () => {
});
});

describe('when the item has the file', () => {
it('should display license and files section', waitForAsync(async () => {
comp.itemRD$ = createSuccessfulRemoteDataObject$(mockItem);
fixture.detectChanges();

void fixture.whenStable().then(() => {
const objectLoader = fixture.debugElement.query(By.css('ds-clarin-license-info'));
expect(objectLoader.nativeElement).toBeDefined();
});
}));
});

});
25 changes: 22 additions & 3 deletions src/app/item-page/simple/item-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AuthorizationDataService } from '../../core/data/feature-authorization/
import { redirectOn4xx } from '../../core/shared/authorized.operators';
import { RegistryService } from 'src/app/core/registry/registry.service';
import { MetadataBitstream } from 'src/app/core/metadata/metadata-bitstream.model';
import { Observable} from 'rxjs';
import { BehaviorSubject, Observable } from 'rxjs';
import { HALEndpointService } from '../../core/shared/hal-endpoint.service';

/**
Expand Down Expand Up @@ -103,6 +103,11 @@ export class ItemPageComponent implements OnInit {

canShowCurlDownload = false;

/**
* True if the item has files, false otherwise.
*/
hasFiles: BehaviorSubject<boolean> = new BehaviorSubject(false);

constructor(
protected route: ActivatedRoute,
private router: Router,
Expand All @@ -127,7 +132,7 @@ export class ItemPageComponent implements OnInit {
map((item) => getItemPageRoute(item))
);

this.showTombstone();
this.processItem();

this.registryService
.getMetadataBitstream(this.itemHandle, 'ORIGINAL,TEXT,THUMBNAIL')
Expand All @@ -139,6 +144,14 @@ export class ItemPageComponent implements OnInit {
});
}

/**
* Check if the item has files and assign the result into the `hasFiles` variable.
* */
private checkIfItemHasFiles(item: Item) {
const hasFilesMetadata = item.metadata?.['local.has.files']?.[0]?.value;
this.hasFiles.next(hasFilesMetadata !== 'no');
}

sumFileSizes() {
const sizeUnits = {
B: 1,
Expand Down Expand Up @@ -167,7 +180,10 @@ export class ItemPageComponent implements OnInit {
this.totalFileSizes = totalBytes.toFixed(2) + ' ' + finalUnit;
}

showTombstone() {
/**
* Process the tombstone of the Item and check if it has files or not.
*/
processItem() {
// if the item is withdrawn
let isWithdrawn = false;
// metadata value from `dc.relation.isreplacedby`
Expand All @@ -181,6 +197,9 @@ export class ItemPageComponent implements OnInit {
this.itemHandle = item.handle;
isWithdrawn = item.isWithdrawn;
isReplaced = item.metadata['dc.relation.isreplacedby']?.[0]?.value;

// check if the item has files
this.checkIfItemHasFiles(item);
});

// do not show tombstone for non withdrawn items
Expand Down
Loading