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

Final misc. tasks to support data previews (Step 6 of issue #1758) #2523

Merged
merged 12 commits into from
Sep 26, 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
27 changes: 25 additions & 2 deletions src/css/metacatui-common.css
Original file line number Diff line number Diff line change
Expand Up @@ -3519,11 +3519,13 @@ add font awesome close icon */
height: 100%;
overflow: hidden;
box-sizing: border-box;
padding: 1rem;
padding: 0.7rem;
display: flex;
flex-direction: column;
}

.table-editor .spreadsheet {
margin: 1rem 0 0.5rem 0;
margin: 0.7rem 0 0.5rem 0;
width: 100%;
max-width: 90vw;
height: 100%;
Expand All @@ -3533,6 +3535,12 @@ add font awesome close icon */
border-radius: 5px;
}

.table-editor .alert {
margin: -10px 0 0 0;
padding: 0.2rem 0.5rem;
font-size: 0.85rem;
}

.table-editor .table {
/* undo bootstrap margin */
margin-bottom: 0;
Expand Down Expand Up @@ -9656,4 +9664,19 @@ body > #extension-is-installed {
******************************************/
.object-view {
height: 100%;
display: grid;
align-items: center;
> .notification {
font-size: 1.6rem;
margin: 3rem;
}
> .alert-container {
margin: 3rem;
}
> .btn.download {
grid-row: 2;
justify-self: right;
margin-right: 1rem;
margin-top: 1rem;
}
}
86 changes: 58 additions & 28 deletions src/js/models/SolrResult.js
robyngit marked this conversation as resolved.
Show resolved Hide resolved
robyngit marked this conversation as resolved.
Show resolved Hide resolved
robyngit marked this conversation as resolved.
Show resolved Hide resolved
robyngit marked this conversation as resolved.
Show resolved Hide resolved
robyngit marked this conversation as resolved.
Show resolved Hide resolved
robyngit marked this conversation as resolved.
Show resolved Hide resolved
robyngit marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -281,36 +281,14 @@ define(["jquery", "underscore", "backbone"], ($, _, Backbone) => {
/**
* Download this object while sending the user's auth token in the
* request.
* @returns {Promise} A promise that resolves to the response object
* @since 0.0.0
*/
async downloadWithCredentials() {
const model = this;

// Call the new getBlob method and handle the response
const response = await this.fetchDataObjectWithCredentials();
const blob = await response.blob();
const filename = this.getFileNameFromResponse(response);

// For IE, we need to use the navigator API
if (navigator && navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(blob, filename);
} else {
// Other browsers can download it via a link
const a = document.createElement("a");
a.href = window.URL.createObjectURL(blob);
a.download = filename;
a.style.display = "none";
document.body.appendChild(a);
a.click();
a.remove();
}

// Track this event
model.trigger("downloadComplete");
MetacatUI.analytics?.trackEvent(
"download",
"Download DataONEObject",
model.get("id"),
);
return this.fetchDataObjectWithCredentials()
.then((response) => this.downloadFromResponse(response))
.catch((error) => this.handleDownloadError(error));
},

/**
Expand Down Expand Up @@ -370,6 +348,58 @@ define(["jquery", "underscore", "backbone"], ($, _, Backbone) => {
return filename;
},

/**
* Download data onto the user's computer from the response object
* @param {Response} response - The response object from the fetch request
* @returns {Response} The response object
* @since 0.0.0
*/
async downloadFromResponse(response) {
const model = this;
const blob = await response.blob();
const filename = this.getFileNameFromResponse(response);

// For IE, we need to use the navigator API
if (navigator && navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(blob, filename);
} else {
// Other browsers can download it via a link
const a = document.createElement("a");
const url = URL.createObjectURL(blob);
a.href = url;
a.download = filename;
a.click();
a.remove();
URL.revokeObjectURL(url);
}

// Track this event
model.trigger("downloadComplete");
MetacatUI.analytics?.trackEvent(
"download",
"Download DataONEObject",
model.get("id"),
);

return response;
},

/**
* Handle an error that occurs when downloading the object
* @param {Error} e - The error that occurred
* @since 0.0.0
*/
handleDownloadError(e) {
const model = this;
model.trigger("downloadError");
// Track the error
MetacatUI.analytics?.trackException(
`Download DataONEObject error: ${e || ""}`,
model.get("id"),
true,
);
},

getInfo: function (fields) {
robyngit marked this conversation as resolved.
Show resolved Hide resolved
var model = this;
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <no-var> reported by reviewdog 🐶
Unexpected var, use let or const instead.

Suggested change
var model = this;
let model = this;


Expand Down Expand Up @@ -550,7 +580,7 @@ define(["jquery", "underscore", "backbone"], ($, _, Backbone) => {
model.set("size", $(data).find("size").text() || "");

//Get the entity name
robyngit marked this conversation as resolved.
Show resolved Hide resolved
model.set("filename", $(data).find("filename").text() || "");
model.set("fileName", $(data).find("filename").text() || "");

//Check if this is a metadata doc
robyngit marked this conversation as resolved.
Show resolved Hide resolved
var formatId = $(data).find("formatid").text() || "",
Expand Down
3 changes: 3 additions & 0 deletions src/js/templates/tableEditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
</tbody>
</table>
</section>
<!-- if view mode -->
<% if (!viewMode) { %>
<section class="<%= controlsClass %>">
<button class="btn btn-danger btn-small"
id="reset">
Clear & reset table
</button>
</section>
<% } %>
<!-- </div>
<div class="tab-pane" id="insert-table-csv-<%=cid%>">
<textarea class="table-text"></textarea>
Expand Down
Loading
Loading