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

BucketExplorer view files and breadcrumb paths #1696

Merged
merged 5 commits into from
Nov 14, 2024
Merged
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
Expand Up @@ -77,7 +77,7 @@
:items-per-page="-1"
:items-per-page-options="[10, 20, 50, 100, -1]"
v-model:sort-by="sortBy"
@click:row="fileClick"
@click:row.stop="fileClick"
multi-sort
density="compact"
hover
Expand All @@ -91,27 +91,33 @@
icon="mdi-chevron-left-box-outline"
variant="text"
density="compact"
class="mt-1"
@click="backArrow"
class="ml-3 mt-1"
@click.stop="backArrow"
data-test="be-nav-back"
/>
<span class=".text-body-1 ma-2 font-size" data-test="file-path">
/{{ path }}
<a
v-for="(part, index) in breadcrumbPath"
:key="index"
@click.prevent="gotoPath(part.path)"
style="cursor: pointer"
>/&nbsp;{{ part.name }}&nbsp;
</a>
</span>
<v-spacer />
<div class="pa-1 font-size">
<div class="ma-2 font-size">
Folder Size: {{ folderTotal }}
<span class="small-font-size">(not recursive)</span>
</div>

<v-spacer />
<div style="display: flex" v-if="mode === 'bucket'">
<span class="pa-1 font-size">Upload File</span>
<div class="ma-2" style="display: flex" v-if="mode === 'bucket'">
<span class="font-size">Upload File</span>
<v-file-input
v-model="file"
hide-input
hide-details
class="file-input"
class="mr-1 file-input"
prepend-icon="mdi-upload"
data-test="upload-file"
/>
Expand All @@ -127,9 +133,17 @@
</template>
<template v-slot:item.action="{ item }">
<v-icon
v-if="item.icon === 'mdi-file' && isText(item.name)"
@click="viewFile(item.name)"
class="mr-3"
data-test="view-file"
>
mdi-eye
</v-icon>
<v-icon
v-if="item.icon === 'mdi-file'"
@click="downloadFile(item.name)"
class="mr-3"
data-test="download-file"
>
mdi-download-box
Expand Down Expand Up @@ -217,17 +231,28 @@
</v-card-text>
</v-card>
</v-dialog>
<output-dialog
type="File"
:content="dialogContent"
:name="dialogName"
:filename="dialogFilename"
v-model="showDialog"
v-if="showDialog"
@submit="showDialog = false"
/>
</div>
</template>

<script>
import TopBar from '@openc3/tool-common/src/components/TopBar'
import OutputDialog from '@openc3/tool-common/src/components/OutputDialog'
import Api from '@openc3/tool-common/src/services/api'
import axios from 'axios'

export default {
components: {
TopBar,
OutputDialog,
},
data() {
return {
Expand All @@ -241,9 +266,14 @@ export default {
optionsDialog: false,
refreshInterval: 60,
updater: null,
updating: false,
path: '',
file: null,
files: [],
showDialog: false,
dialogName: '',
dialogContent: '',
dialogFilename: '',
sortBy: [
{
key: 'modified',
Expand All @@ -255,6 +285,7 @@ export default {
title: 'Name',
value: 'name',
sortable: true,
nowrap: true,
},
{
title: 'Size',
Expand All @@ -269,6 +300,8 @@ export default {
{
title: 'Action',
value: 'action',
align: 'end',
nowrap: true,
},
],
menus: [
Expand All @@ -293,6 +326,13 @@ export default {
.reduce((a, b) => a + (b.size ? b.size : 0), 0)
.toLocaleString()
},
breadcrumbPath() {
const parts = this.path.split('/')
return parts.map((part, index) => ({
name: part,
path: parts.slice(0, index + 1).join('/') + '/',
}))
},
},
created() {
Api.get('/openc3-api/storage/buckets').then((response) => {
Expand All @@ -302,6 +342,7 @@ export default {
this.volumes = response.data
})
if (this.$route.params.path?.length) {
this.updating = true
let parts = this.$route.params.path[0].split('/')
if (parts[0] === '') {
this.mode = 'volume'
Expand Down Expand Up @@ -332,7 +373,38 @@ export default {
},
},
methods: {
isText(filename) {
if (['Rakefile', 'Dockerfile'].includes(filename)) {
return true
}
let ext = filename.split('.').pop()
// Add some common COSMOS text file extensions
return [
'txt',
'md',
'rb',
'py',
'pyi',
'cfg',
'html',
'js',
'json',
'info',
'vue',
'sh',
'bat',
'csv',
].includes(ext)
},
gotoPath(path) {
if (!this.updating) {
this.updating = true
this.path = path
this.update()
}
},
update() {
this.updating = true
this.$router.push({
name: 'Bucket Explorer',
params: {
Expand All @@ -357,31 +429,43 @@ export default {
}
},
selectBucket(bucket) {
this.mode = 'bucket'
this.root = bucket
this.path = ''
this.update()
if (!this.updating) {
this.updating = true
this.mode = 'bucket'
this.root = bucket
this.path = ''
this.update()
}
},
selectVolume(volume) {
this.mode = 'volume'
this.root = volume
this.path = ''
this.update()
if (!this.updating) {
this.updating = true
this.mode = 'volume'
this.root = volume
this.path = ''
this.update()
}
},
backArrow() {
// Nothing to do if we're at the root so return
if (this.path === '') return
let parts = this.path.split('/')
this.path = parts.slice(0, parts.length - 2).join('/')
// Only append the last slash if we're not at the root
// The root is 2 because it's the path before clicking back
if (parts.length > 2) {
this.path += '/'
if (!this.updating) {
this.updating = true
let parts = this.path.split('/')
this.path = parts.slice(0, parts.length - 2).join('/')
// Only append the last slash if we're not at the root
// The root is 2 because it's the path before clicking back
if (parts.length > 2) {
this.path += '/'
}
this.update()
}
this.update()
},
fileClick(_, { item }) {
if (item.icon === 'mdi-folder') {
// Nothing to do if they click on a file
if (item.icon !== 'mdi-folder') return
if (!this.updating) {
this.updating = true
if (this.root === '') {
// initial root click
this.root = item.name
Expand All @@ -391,6 +475,23 @@ export default {
this.update()
}
},
viewFile(filename) {
let root = this.root.toUpperCase()
if (this.mode === 'volume') {
root = root.slice(1)
}
Api.get(
`/openc3-api/storage/download_file/${encodeURIComponent(
this.path,
)}${filename}?${this.mode}=OPENC3_${root}_${this.mode.toUpperCase()}`,
).then((response) => {
this.dialogName = filename
this.dialogFilename = filename
// Decode Base64 string
this.dialogContent = window.atob(response.data.contents)
this.showDialog = true
})
},
downloadFile(filename) {
let root = this.root.toUpperCase()
let api = 'download'
Expand Down Expand Up @@ -503,6 +604,7 @@ export default {
}
}),
)
this.updating = false
})
.catch(({ response }) => {
this.files = []
Expand All @@ -515,6 +617,7 @@ export default {
title: response.message,
})
}
this.updating = false
})
},
},
Expand Down
Loading
Loading