Skip to content

Commit

Permalink
Use resolve service url for portal docs and images in the D1 theme only
Browse files Browse the repository at this point in the history
Also hide the edit button in the portal list view in the dataone theme

Relates to issue #1244
  • Loading branch information
robyngit committed May 28, 2020
1 parent e90c0e6 commit ce0e295
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/js/models/UserModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ define(['jquery', 'underscore', 'backbone', 'jws', 'models/Search', "collections
return;
}

//If creating portals has bbeen disabled app-wide, then set to false
//If creating portals has been disabled app-wide, then set to false
if( MetacatUI.appModel.get("enableCreatePortals") === false ){
this.set("isAuthorizedCreatePortal", false);
return;
Expand Down
8 changes: 7 additions & 1 deletion src/js/models/portals/PortalImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ define(["jquery",
modelJSON.identifier = $objectDOM.children("identifier").text();
if( modelJSON.identifier ){
if( modelJSON.identifier.substring(0, 4) !== "http" ){
modelJSON.imageURL = MetacatUI.appModel.get("resolveServiceUrl") + modelJSON.identifier;

// use the resolve service if there is no object service url
// (e.g. in DataONE theme)
var urlBase = MetacatUI.appModel.get("objectServiceUrl") ||
MetacatUI.appModel.get("resolveServiceUrl");

modelJSON.imageURL = urlBase + modelJSON.identifier;
}
else{
modelJSON.imageURL = modelJSON.identifier;
Expand Down
12 changes: 9 additions & 3 deletions src/js/models/portals/PortalModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,20 @@ define(["jquery",
* @return {string} The portal URL
*/
url: function() {

// use the resolve service if there is no object service url
// (e.g. in DataONE theme)
var urlBase = MetacatUI.appModel.get("objectServiceUrl") ||
MetacatUI.appModel.get("resolveServiceUrl");

//If this object is being updated, use the old pid in the URL
if ( !this.isNew() && this.get("oldPid") ) {
return MetacatUI.appModel.get("objectServiceUrl") +
return urlBase +
encodeURIComponent(this.get("oldPid"));
}
//If this object is new, use the new pid in the URL
else{
return MetacatUI.appModel.get("objectServiceUrl") +
else {
return urlBase +
encodeURIComponent(this.get("seriesId") || this.get("id"));
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/js/themes/dataone/models/AppModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ define(['jquery', 'underscore', 'backbone'],
metaServiceUrl: null,
metacatBaseUrl: null,
metacatServiceUrl: null,
objectServiceUrl: null,
// objectServiceUrl: null,
resolveServiceUrl: null,
d1LogServiceUrl: null,
nodeServiceUrl: null,
Expand Down Expand Up @@ -396,7 +396,7 @@ define(['jquery', 'underscore', 'backbone'],
this.set('authServiceUrl', this.get('baseUrl') + this.get('d1Service') + '/isAuthorized/');
this.set('queryServiceUrl', this.get('baseUrl') + this.get('d1Service') + '/query/solr/?');
this.set('metaServiceUrl', this.get('baseUrl') + this.get('d1Service') + '/meta/');
this.set('objectServiceUrl', this.get('baseUrl') + this.get('d1Service') + '/object/');
// this.set('objectServiceUrl', this.get('baseUrl') + this.get('d1Service') + '/object/');
this.set('resolveServiceUrl', this.get('d1CNBaseUrl') + this.get('d1Service') + '/resolve/');
this.set('nodeServiceUrl', this.get('baseUrl') + this.get('d1Service') + '/node');
this.set("reserveServiceUrl", this.get("d1CNBaseUrl") + this.get("d1CNService") + "/reserve");
Expand Down
21 changes: 18 additions & 3 deletions src/js/views/portals/PortalListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,31 @@ define(["jquery",
var logo = "";
if( searchResult.get("logo") ){
if( !searchResult.get("logo").startsWith("http") ){
searchResult.set("logo", MetacatUI.appModel.get("resolveServiceUrl") + searchResult.get("logo"));

// use the resolve service if there is no object service url
// (e.g. in DataONE theme)
var urlBase = MetacatUI.appModel.get("objectServiceUrl") ||
MetacatUI.appModel.get("resolveServiceUrl");

searchResult.set("logo", urlBase + searchResult.get("logo") );

}
logo = $(document.createElement("img")).attr("src", searchResult.get("logo"));

logo = $(document.createElement("img"))
.attr("src", searchResult.get("logo"))
.attr("alt", searchResult.get("title") + " logo");
}

//Create an Edit buttton
var buttons = $(document.createElement("a")).attr("href",
var buttons = "";
if(Object.values(MetacatUI.uiRouter.routes).includes("renderPortalEditor")){

buttons = $(document.createElement("a")).attr("href",
MetacatUI.root + "/edit/"+ MetacatUI.appModel.get("portalTermPlural") +"/" + (searchResult.get("label") || searchResult.get("seriesId") || searchResult.get("id")) )
.text("Edit")
.addClass("btn");
}


//Create a link to the portal view with the title as the text
var titleLink = $(document.createElement("a"))
Expand Down

0 comments on commit ce0e295

Please sign in to comment.