Skip to content

Commit

Permalink
When a portal doesn't have a seriesId, get it via pid instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenwalker committed Aug 20, 2019
1 parent 3703916 commit 4f98727
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/js/models/CollectionModel.js
Expand Up @@ -129,6 +129,7 @@ define(["jquery",
dataType: "text",
success: function(response){
model.set(DataONEObject.prototype.parse.call(model, response));
model.trigger("systemMetadataSync");
},
error: function(){
model.trigger('error');
Expand Down
15 changes: 13 additions & 2 deletions src/js/models/DataONEObject.js
Expand Up @@ -1212,9 +1212,11 @@ define(['jquery', 'underscore', 'backbone', 'uuid', 'he', 'collections/AccessPol
//If there is no system metadata, then retrieve it first
if(!this.get("sysMetaXML")){
this.once("sync", this.findLatestVersion);
this.once("systemMetadataSync", this.findLatestVersion);
this.fetch({
url: MetacatUI.appModel.get("metaServiceUrl") + encodeURIComponent(this.get("id")),
dataType: "text"
dataType: "text",
systemMetadataOnly: true
});
return;
}
Expand All @@ -1233,6 +1235,10 @@ define(['jquery', 'underscore', 'backbone', 'uuid', 'he', 'collections/AccessPol
// attribute was actually changed
this.trigger("latestVersionFound", this);

//Remove the listeners now that we found the latest version
this.stopListening("sync", this.findLatestVersion);
this.stopListening("systemMetadataSync", this.findLatestVersion);

return;
}

Expand All @@ -1251,9 +1257,14 @@ define(['jquery', 'underscore', 'backbone', 'uuid', 'he', 'collections/AccessPol
if(obsoletedBy)
model.findLatestVersion(possiblyNewer, obsoletedBy);
//If there isn't a newer version, then this is it
else
else{
model.set("latestVersion", possiblyNewer);

//Remove the listeners now that we found the latest version
model.stopListening("sync", model.findLatestVersion);
model.stopListening("systemMetadataSync", model.findLatestVersion);
}

},
error: function(xhr){
//If this newer version isn't accessible, link to the latest version that is
Expand Down
42 changes: 32 additions & 10 deletions src/js/models/project/ProjectModel.js
Expand Up @@ -69,9 +69,9 @@ define(["jquery",
// The MapModel
mapModel: gmaps ? new MapModel() : null,
// Project view colors, as specified in the project document options
primaryColor: "",
secondaryColor: "",
accentColor: "",
primaryColor: "#999999",
secondaryColor: "#666666",
accentColor: "#497ba7",
primaryColorRGB: null,
secondaryColorRGB: null,
accentColorRGB: null,
Expand Down Expand Up @@ -110,7 +110,7 @@ define(["jquery",
*/
url: function() {
return MetacatUI.appModel.get("objectServiceUrl") +
encodeURIComponent(this.get("seriesId"));
encodeURIComponent(this.get("seriesId") || this.get("id"));
},

/**
Expand All @@ -127,11 +127,21 @@ define(["jquery",
else var options = _.clone(options);

//If the seriesId has not been found yet, get it from Solr
if( !this.get("seriesId") && this.get("label") ){
if( !this.get("id") && !this.get("seriesId") && this.get("label") ){
this.once("change:seriesId", this.fetch);
this.once("latestVersionFound", this.fetch);
this.getSeriesIdByName();
return;
}
//If we found the latest version in this pid version chain,
else if( this.get("id") && this.get("latestVersion") ){
//Set it as the id of this model
this.set("id", this.get("latestVersion"));

//Stop listening to the change of seriesId and the latest version found
this.stopListening("change:seriesId", this.fetch);
this.stopListening("latestVersionFound", this.fetch);
}

//Fetch the system metadata
if( !options.objectOnly || options.systemMetadataOnly ){
Expand Down Expand Up @@ -174,8 +184,8 @@ define(["jquery",

var requestSettings = {
url: MetacatUI.appModel.get("queryServiceUrl") +
"q=projectName:\"" + this.get("label") + "\"" +
"&fl=seriesId,projectName" +
"q=label:\"" + this.get("label") + "\"" +
"&fl=seriesId,id,label" +
"&sort=dateUploaded%20asc" +
"&rows=1" +
"&wt=json",
Expand All @@ -189,8 +199,20 @@ define(["jquery",
success: function(response){
if( response.response.numFound > 0 ){

model.set("label", response.response.docs[0].projectName);
model.set("seriesId", response.response.docs[0].seriesId);
model.set("label", response.response.docs[0].label);

//Save the seriesId, if one is found
if( response.response.docs[0].seriesId ){
model.set("seriesId", response.response.docs[0].seriesId);
}
//If this portal doesn't have a seriesId,
else{
//Save the id
model.set("id", response.response.docs[0].id);

//Find the latest version in this version chain
model.findLatestVersion(response.response.docs[0].id);
}

}
else{
Expand Down Expand Up @@ -220,7 +242,7 @@ define(["jquery",

// Iterate over each root XML node to find the project node
$(response).children().each(function(i, el) {
if (el.tagName.indexOf("project") > -1) {
if (el.tagName.indexOf("portal") > -1) {
projectNode = el;
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions src/js/views/project/ProjectView.js
Expand Up @@ -105,6 +105,10 @@ define(["jquery",

$("body").addClass("ProjectView");

this.$el.html(this.loadingTemplate({
msg: "Loading..."
}));

// Create a new Project model
this.model = new Project({
seriesId: this.projectId,
Expand Down

0 comments on commit 4f98727

Please sign in to comment.