Skip to content

Commit

Permalink
#768 Adds User access to geneview network creation
Browse files Browse the repository at this point in the history
  • Loading branch information
lawal-olaotan committed Sep 6, 2023
1 parent 13e6d22 commit b7abe29
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
25 changes: 9 additions & 16 deletions client-base/src/main/webapp/html/javascript/gene-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ function generateCyJSNetwork(url, requestParams, externalCall) {
$("#loadingNetwork_Div").replaceWith('<div id="loadingNetwork_Div"><b>Loading Network, please wait...</b></div>');

// Show loading spinner on 'tabviewer' div

$.post({
url: url,
timeout: 1000000,
Expand All @@ -183,8 +182,6 @@ function generateCyJSNetwork(url, requestParams, externalCall) {
console.log(server_error.detail);
alert(errorMsg);
}).success(function (data) {


// Network graph: JSON file.
try {
if (!externalCall) {
Expand Down Expand Up @@ -260,6 +257,8 @@ function generateMultiGeneNetwork_forNewNetworkViewer(keyword, targetElement) {

var candidatelist = [];
var knetNotice;
var knetViewLimit = userAccessMgr.getGeneKnetLimit();
var isUserPro = userAccessMgr.isLimitEnforced()

var cb_list = $("input[name=candidates");
var cb_list_len = cb_list.length;
Expand All @@ -268,26 +267,20 @@ function generateMultiGeneNetwork_forNewNetworkViewer(keyword, targetElement) {
candidatelist.push(cb_list[i].value);
}
}
//console.log(candidatelist.length +" gene(s) selected.");
if (candidatelist == "") {
knetNotice = "Please select candidate genes."
jboxNotice(knetNotice, 'red', 300, 2000);

}
else if (candidatelist.length > knetview_limit/*20*/) {
if (enforce_genelist_limit === false) { // Pro plan user
knetNotice = '<span></span><b>Gene networks can only be created for up to max. ' + knetview_limit + ' genes.</b></span>'
//console.log(candidatelist.length +" gene(s) selected.");
if (candidatelist.length > knetViewLimit/*20*/) {

if (!isUserPro) { // Pro plan user
knetNotice = '<span></span>Gene networks can only be created for up to max. ' + knetViewLimit + ' genes.</span>';
}
else { // Free plan user
knetNotice = '<span></span><b>Gene networks can only be created for up to max. ' + knetview_limit + ' genes.</b></span>'
'<span id="loadingNetworkDiv"><b>The KnetMiner Free Plan is limited to a network of ' + knetview_limit + ' genes. <a href="https://knetminer.com/pricing-plans" target="_blank">Upgrade to Pro plan now</a> to create networks for 200 genes</b></span>';

console.log('triggered Here')
knetNotice = '<div><p>The KnetMiner Free Plan is limited to a network of ' + knetViewLimit + ' genes.</p> <a href="https://knetminer.com/pricing-plans" target="_blank">Upgrade to Pro plan now</a> to create networks</div>';
}

jboxNotice(knetNotice, 'red', 300, 2000);
jboxNotice(knetNotice,'black',10 , 10000,400);
resetNetworkCall()

}
else {
generateCyJSNetwork(api_url + '/network', { keyword: keyword, list: candidatelist, isExportPlainJSON: false }, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ let sleep = time => new Promise((resolve) => setTimeout(resolve, time));
* @param {type} yPos
* @returns {jBoxNotice}
*/
function jboxNotice(content, colour, yPos, autoclose) {
function jboxNotice(content, colour, yPos, autoclose, width=autoclose,height=auto) {
new jBox('Notice', {
content: content,
color: colour,
autoClose: autoclose,
position: {
x: 0,
y: yPos
}
},
width:width,
height:height

});
}

Expand Down
7 changes: 7 additions & 0 deletions client-base/src/main/webapp/html/javascript/user-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class UserAccessManager{

#current = null;
#defaultGeneLimit = null;
#defaultKnetViewLimit = null;
#isGeneLimitEnforced = null;

constructor(){
this.#current = 'guest'
this.#defaultGeneLimit = 20;
this.#defaultKnetViewLimit = 10;
this.#isGeneLimitEnforced = true;
}

Expand Down Expand Up @@ -76,6 +78,7 @@ class UserAccessManager{

}else if(this.#current === 'pro'){
this.#isGeneLimitEnforced = false;
this.#defaultKnetViewLimit = 20
// TODO: don't mix business logic and UI
// Have a separated function/component, like refreshUIrestrictions() and
// call it outside of this class, after updates like setUserPlan()
Expand All @@ -88,6 +91,10 @@ class UserAccessManager{
return this.#defaultGeneLimit
}

getGeneKnetLimit(){
return this.#defaultKnetViewLimit
}

// Checks if genes list limit is enforced or not.
// Returns a boolean value to validate example queries restriction.
// Primarily used to check if a user on a free or pro plan.
Expand Down

0 comments on commit b7abe29

Please sign in to comment.