-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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
changed the title
(Step 4 of issue #1758)
Create the DataObject View (Step 4 of issue #1758)
Sep 12, 2024
There was a problem hiding this comment.
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.
metacatui/src/js/models/SolrResult.js
Lines 373 to 519 in 646cd14
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
approved these changes
Sep 25, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add a View for getting & displaying Data Objects
Modularize downloadWithCredentials in SolrResult