- file download inside search detail page

This commit is contained in:
Arno Kaimbacher 2021-12-15 13:22:32 +01:00
parent 6cb6f178a9
commit 3e73b91cf0
3 changed files with 22 additions and 12 deletions

View File

@ -141,13 +141,13 @@ export class DbDataset {
}
public hasEmbargoPassed(): boolean {
const embargoDate = moment(this.embargo_date);
if (embargoDate == null) {
if (this.embargo_date === null) {
return true;
}
const embargoDate = moment(this.embargo_date);
const todayDate = moment.now();
// Embargo has passed on the day after the specified date
// Embargo has passed on the day after the specified date
if (embargoDate.isBefore(todayDate)) {
return true;
} else {

View File

@ -53,6 +53,21 @@ export default class DatasetDetailComponent extends Vue {
this.$router.go(-1);
}
public getExtension(filename: string): string {
return filename.substring(filename.lastIndexOf(".") + 1, filename.length) || filename;
}
public formatSize(file_size: number, precision = 1) {
let size = file_size;
const unit = ["Byte", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
let i;
for (i = 0; size >= 1024 && i < unit.length - 1; i++) {
size = size / 1024;
}
// return Math.round((size * precision) / precision) + " " + unit[i];
return Math.round((size + Number.EPSILON) * 100) / 100 + " " + unit[i];
}
public getHumanDate(date: string): string {
return moment(date).format("DD.MM.YYYY HH:mm");
// return moment(date).format("MMM Do YYYY");

View File

@ -55,7 +55,7 @@
<div class="columns">
<div class="column is-3-desktop is-4-tablet">Downloads/<br />downloads:</div>
<div class="column is-9-desktop is-8-tablet" v-if="dataset.files.length > 0">
<table id="items" v-if="dataset.hasEmbargoPassed()" class="pure-table pure-table-horizontal">
<table id="items" v-if="dataset.hasEmbargoPassed()" class="table is-bordered is-striped">
<thead>
<tr>
<th>Path Name</th>
@ -66,18 +66,13 @@
<tbody>
<tr v-for="file in dataset.files" :key="file.id">
<td>
{{ file.path_name }}
<!-- @if($file->exists() === true)
<a target="_blank" href="{{ route('file.download', ['id' => $file->id]) }}"> {{ $file->label }} </a>
@else
<span class="alert">missing file: {{ $file->path_name }}</span>
@endif -->
<a target="_blank" v-bind:href="'portal/file/download/' + file.id"> {{ file.label }} </a>
</td>
<td>
<!-- <span>{{ pathinfo($file->path_name, PATHINFO_EXTENSION) }}</span> -->
<span>{{ getExtension(file.path_name) }}</span>
</td>
<td>
<!-- <span>{{ $file->formatSize(2) }}</span> -->
<span>{{ formatSize(file.file_size, 2) }}</span>
</td>
</tr>
</tbody>