Skip to content

Commit

Permalink
ui: change the table of file_indices, to include the description of t…
Browse files Browse the repository at this point in the history
…he dataset and one extra button to download the file in json
  • Loading branch information
psaiz committed Jan 30, 2025
1 parent 72dbe49 commit 8fed763
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
5 changes: 4 additions & 1 deletion cernopendata/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ def __init__(self):
self._number_files = 0
self._size = 0
self._files = []
self._description = ""

def __repr__(self):
"""Representation of the object."""
return str(self.dumps())

@classmethod
def create(cls, record, file_object):
def create(cls, record, file_object, description=""):
"""Method to create a FileIndex."""
rb = cls()
rb.model = record.model
Expand All @@ -106,6 +107,7 @@ def create(cls, record, file_object):

rb._index_file_name = index_file_name
rb._bucket = Bucket.create()
rb._description = description
BucketTag.create(rb._bucket, "index_name", index_file_name)
BucketTag.create(rb._bucket, "record", record.model.id)
print(f"The file index contains {len(index_content)} entries.")
Expand Down Expand Up @@ -166,6 +168,7 @@ def dumps(self):
"number_files": self._number_files,
"size": self._size,
"files": files,
"description": self._description,
}

def flush(self):
Expand Down
4 changes: 3 additions & 1 deletion cernopendata/modules/fixtures/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def _handle_record_files(record, data):
file.get("uri"),
)
# We don't need to store the index
FileIndexMetadata.create(record, f)
FileIndexMetadata.create(
record, f, description=file.get("description", filename)
)
print("File index created")
f.delete()
elif "type" in file and file["type"] == "index.txt":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ export default function FileTable({ items, table_type }) {
const [openDownloadModal, setOpenDownloadModal] = useState(false);
const [selectedFile, setSelectedFile] = useState();

const getFileUri = (table_type, fileKey) => {
const getFileUri = (table_type, fileKey, format) => {
var url= `/record/${config.pidValue}/${table_type}/${fileKey}`;
if (table_type=='file_index')
if (table_type=='file_index' && format== 'txt')
url = url.replace('.json', '.txt');
return url};
return (
<Table singleLine>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Filename</Table.HeaderCell>
<Table.HeaderCell>Size</Table.HeaderCell>
<Table.HeaderCell>{table_type=='file_index' ? 'Index description' : 'Filename'}</Table.HeaderCell>
<Table.HeaderCell>{table_type=='file_index' ? 'Index size' : 'Size'}</Table.HeaderCell>
<Table.HeaderCell></Table.HeaderCell>
</Table.Row>
</Table.Header>
Expand All @@ -63,15 +63,14 @@ export default function FileTable({ items, table_type }) {
},
}
: { href: getFileUri(table_type, file.key) };
const label= table_type=='file_index' ? 'index' : '';
return (
<Table.Row key={file.version_id}>
<Table.Cell className="filename-cell">{file.key}</Table.Cell>
<Table.Cell className="filename-cell">{table_type=='file_index' ? file.description :file.key}</Table.Cell>
<Table.Cell collapsing>
{toHumanReadableSize(file.size)}
</Table.Cell>
<Table.Cell collapsing>
{table_type === "file_index" && (
{table_type === "file_index" ? ( <>
<Button
icon
size="mini"
Expand All @@ -82,10 +81,17 @@ export default function FileTable({ items, table_type }) {
>
<Icon name="list" /> List files
</Button>
)}
<Button as="a" icon size="mini" primary {...downloadProp}>
<Icon name="download" /> Download {label}
</Button>
<Button as="a" icon size="mini" primary href={getFileUri(table_type, file.key, 'txt') } >
<Icon name="download" /> Download txt
</Button>
<Button as="a" icon size="mini" primary href={getFileUri(table_type, file.key) }>
<Icon name="download" /> Download json
</Button></>
) :
<Button as="a" icon size="mini" primary {...downloadProp}>
<Icon name="download" /> Download
</Button>
}
</Table.Cell>
</Table.Row>
);
Expand Down

0 comments on commit 8fed763

Please sign in to comment.