Skip to content

Commit

Permalink
fix: added download links to the public files tab
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Feb 6, 2024
1 parent 3c2c143 commit f788f74
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/Models/FileSystemObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ class FileSystemObject extends Model
'has_children',
];

/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['download_url'];

/**
* Get the download URL to the file system object.
*
* @return string
*/
public function getDownloadUrlAttribute()
{
if ($this->model_type == 'study') {
return $this->study->download_url;
}
}

public function children()
{
return $this->hasMany(FileSystemObject::class, 'parent_id', 'id');
Expand Down
1 change: 1 addition & 0 deletions resources/js/Pages/Public/Project/Files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
ref="fsbRef"
:readonly="true"
:height="'h-[calc(100vh-385px)]'"
:project="project.data"
></file-system-browser>
</div>
</div>
Expand Down
49 changes: 48 additions & 1 deletion resources/js/Shared/FileSystemBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,18 @@
/>
Delete
</a>
<a
v-if="
$page.props.selectedFileSystemObject
.id &&
readonly &&
downloadURL
"
:href="downloadURL"
class="ml-4 cursor-pointer relative inline-flex items-center px-4 py-1 rounded-full border border-gray-300 bg-white text-sm font-black text-dark hover:bg-gray-50 focus:z-10 focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 float-right"
>
Download
</a>
</p>
</div>
<ul
Expand Down Expand Up @@ -507,6 +519,7 @@
>
<File-details
:file="$page.props.selectedFileSystemObject"
:project="readonly ? project : null"
></File-details>
</span>
</div>
Expand Down Expand Up @@ -660,7 +673,7 @@ export default {
JetConfirmationModal,
JetDangerButton,
},
props: ["draft", "readonly", "height"],
props: ["draft", "readonly", "height", "project"],
emits: ["loading"],
Expand Down Expand Up @@ -699,6 +712,40 @@ export default {
});
return logsClone;
},
nmriumURL() {
return this.$page.props.nmriumURL
? String(this.$page.props.nmriumURL)
: "//nmriumdev.nmrxiv.org";
},
downloadURL() {
if (this.$page.props.selectedFileSystemObject.download_url) {
return this.$page.props.selectedFileSystemObject.download_url;
} else {
if (this.project) {
if (
this.$page.props.selectedFileSystemObject &&
this.$page.props.selectedFileSystemObject
.relative_url == "/"
) {
return this.project.download_url;
} else {
return (
this.baseURL +
"/" +
this.project.owner.username +
"/download/" +
this.project.slug +
"?key=" +
this.$page.props.selectedFileSystemObject.name +
"&uuid=" +
this.$page.props.selectedFileSystemObject.uuid
);
}
} else {
return null;
}
}
},
},
mounted() {
if (this.draft) {
Expand Down

0 comments on commit f788f74

Please sign in to comment.