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

Create the DataObject View (Step 4 of issue #1758) #2521

Merged
merged 5 commits into from
Sep 25, 2024

Conversation

robyngit
Copy link
Member

@robyngit robyngit commented Sep 12, 2024

Add a View for getting & displaying Data Objects

  • This is an MVP version
  • It supports CSVs only, displaying them in a table
  • Still needs to show loading & error messages

Modularize downloadWithCredentials in SolrResult

  • Need to fetch, but not download, the data object from the Solr results model.
  • To avoid duplicating logic separated out the logic for fetching the data from downloading the data (onto the user's machine).
  • Added a tests for the new functions

- Separate out the logic for getting the data from DataONE from the logic for downloading that data onto the user's machine.
- Allows us to use the same data fetching logic in other parts of the app, i.e. the DataONEObjectView.
- Also separate out the logic for getting the file name.
- Add a tests for the new functions

Issue #1758
- MVP, shows CSVs in a table (no other file types yet, no loading spinner, or error handling)
- Ensure TableEditorView returns the view from render()

Issue #1758
@robyngit robyngit changed the title (Step 4 of issue #1758) Create the DataObject View (Step 4 of issue #1758) Sep 12, 2024
src/js/models/SolrResult.js Show resolved Hide resolved
src/js/models/SolrResult.js Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [eslint] <object-shorthand> reported by reviewdog 🐶
Expected method shorthand.

getInfo: function (fields) {
var model = this;
if (!fields)
var fields =
"abstract,id,seriesId,fileName,resourceMap,formatType,formatId,obsoletedBy,isDocumentedBy,documents,title,origin,keywords,attributeName,pubDate,eastBoundCoord,westBoundCoord,northBoundCoord,southBoundCoord,beginDate,endDate,dateUploaded,archived,datasource,replicaMN,isAuthorized,isPublic,size,read_count_i,isService,serviceTitle,serviceEndpoint,serviceOutput,serviceDescription,serviceType,project,dateModified";
var escapeSpecialChar = MetacatUI.appSearchModel.escapeSpecialChar;
var query = "q=";
//If there is no seriesId set, then search for pid or sid
if (!this.get("seriesId"))
query +=
'(id:"' +
escapeSpecialChar(encodeURIComponent(this.get("id"))) +
'" OR seriesId:"' +
escapeSpecialChar(encodeURIComponent(this.get("id"))) +
'")';
//If a seriesId is specified, then search for that
else if (this.get("seriesId") && this.get("id").length > 0)
query +=
'(seriesId:"' +
escapeSpecialChar(encodeURIComponent(this.get("seriesId"))) +
'" AND id:"' +
escapeSpecialChar(encodeURIComponent(this.get("id"))) +
'")';
//If only a seriesId is specified, then just search for the most recent version
else if (this.get("seriesId") && !this.get("id"))
query +=
'seriesId:"' +
escapeSpecialChar(encodeURIComponent(this.get("id"))) +
'" -obsoletedBy:*';
query +=
"&fl=" +
fields + //Specify the fields to return
"&wt=json&rows=1000" + //Get the results in JSON format and get 1000 rows
"&archived=archived:*"; //Get archived or unarchived content
var requestSettings = {
url: MetacatUI.appModel.get("queryServiceUrl") + query,
type: "GET",
success: function (data, response, xhr) {
//If the Solr response was not as expected, trigger and error and exit
if (!data || typeof data.response == "undefined") {
model.set("indexed", false);
model.trigger("getInfoError");
return;
}
var docs = data.response.docs;
if (docs.length == 1) {
docs[0].resourceMap = model.parseResourceMapField(docs[0]);
model.set(docs[0]);
model.trigger("sync");
}
//If we searched by seriesId, then let's find the most recent version in the series
else if (docs.length > 1) {
//Filter out docs that are obsoleted
var mostRecent = _.reject(docs, function (doc) {
return typeof doc.obsoletedBy !== "undefined";
});
//If there is only one doc that is not obsoleted (the most recent), then
// set this doc's values on this model
if (mostRecent.length == 1) {
mostRecent[0].resourceMap = model.parseResourceMapField(
mostRecent[0],
);
model.set(mostRecent[0]);
model.trigger("sync");
} else {
//If there are multiple docs without an obsoletedBy statement, then
// retreive the head of the series via the system metadata
var sysMetaRequestSettings = {
url:
MetacatUI.appModel.get("metaServiceUrl") +
encodeURIComponent(docs[0].seriesId),
type: "GET",
success: function (sysMetaData) {
//Get the identifier node from the system metadata
var seriesHeadID = $(sysMetaData).find("identifier").text();
//Get the doc from the Solr results with that identifier
var seriesHead = _.findWhere(docs, { id: seriesHeadID });
//If there is a doc in the Solr results list that matches the series head id
if (seriesHead) {
seriesHead.resourceMap =
model.parseResourceMapField(seriesHead);
//Set those values on this model
model.set(seriesHead);
}
//Otherwise, just fall back on the first doc in the list
else if (mostRecent.length) {
mostRecent[0].resourceMap = model.parseResourceMapField(
mostRecent[0],
);
model.set(mostRecent[0]);
} else {
docs[0].resourceMap = model.parseResourceMapField(
docs[0],
);
model.set(docs[0]);
}
model.trigger("sync");
},
error: function (xhr, textStatus, errorThrown) {
// Fall back on the first doc in the list
if (mostRecent.length) {
model.set(mostRecent[0]);
} else {
model.set(docs[0]);
}
model.trigger("sync");
},
};
$.ajax(
_.extend(
sysMetaRequestSettings,
MetacatUI.appUserModel.createAjaxSettings(),
),
);
}
} else {
model.set("indexed", false);
//Try getting the system metadata as a backup
model.getSysMeta();
}
},
error: function (xhr, textStatus, errorThrown) {
model.set("indexed", false);
model.trigger("getInfoError");
},
};
$.ajax(
_.extend(
requestSettings,
MetacatUI.appUserModel.createAjaxSettings(),
),
);
},

@rushirajnenuji rushirajnenuji merged commit 8f3de73 into develop Sep 25, 2024
1 check failed
@robyngit robyngit deleted the feature-1758-data-table-previews-4 branch September 26, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants