Skip to content

Commit

Permalink
Partially fixes issues raised in #797
Browse files Browse the repository at this point in the history
  • Loading branch information
lawal-olaotan committed Oct 20, 2023
1 parent 4712bd3 commit 4d83934
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 79 deletions.
7 changes: 4 additions & 3 deletions client-base/src/main/webapp/html/javascript/data-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ async function genomeApi (request, requestParams)
// Plus, this is a kindergarten way to do it, there are dedicated
// rond() functions for that
//
let queryseconds = (querytime / 1000).toFixed(2);
data["queryseconds"] = queryseconds;

data["querytime"] = querytime;

return data;
})
Expand Down Expand Up @@ -219,7 +219,8 @@ function genomicViewContent(data, keyword, geneList_size, searchMode,list) {
let genomicViewTitle;
let status;

let { geneCount, geneTable, evidenceTable, gviewer, queryseconds } = data;
let { geneCount, geneTable, evidenceTable, gviewer, querytime } = data;
const queryseconds = ( querytime / 1000).toFixed(2);

if (geneCount == 0) {
status = true;
Expand Down
4 changes: 2 additions & 2 deletions client-base/src/main/webapp/html/javascript/evidence-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ async function openGeneListPopup(conceptId, element)
let accessionCache = new EvidenceAccessionCache('accession-cache');

// TODO: As explained, this is too poor to get into the 5.7
let accessionData = await accessionCache.apiHandler(conceptId);
let accessionData = await accessionCache.get(conceptId);


if ( accessionData ){
var accessionPopup = new AccessionPopupManager(element, conceptId, accessionData);
Expand Down Expand Up @@ -473,7 +474,6 @@ function createEvidenceTableBody ( tableData, doAppend = false )
}
}


// a helper class to manage evidenceview genes Column Popup
class AccessionPopupManager
{
Expand Down
15 changes: 8 additions & 7 deletions client-base/src/main/webapp/html/javascript/example-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,19 @@ const exampleQuery = function () {
var queryRestriction;
var isQueryRestricted = userAccessMgr.requires(minimumUserRole);
var isGeneListRestricted = userAccessMgr.isLimitEnforced();
var userLevel = UserRole.getUserRole();

if (!isQueryRestricted) {
queryRestriction = `<a class='query-restriction-text' onclick="loginModalInit()">(Login)</a>`;
}

/* TODO: NO! roles need to be cheched via can(), see user-access.js
Also, why are you checking minimumUserRole again, if it was already done upon
setting isGeneListRestricted?
*/
if (isGeneListRestricted && minimumUserRole == 'pro') {
/* TODO: NO! roles need to be cheched via can(), see user-access.js
Also, why are you checking minimumUserRole again, if it was already done upon
setting isGeneListRestricted?
*/
if (isGeneListRestricted && userLevel <= 100) {
queryRestriction = `<a class='query-restriction-text' href="https://knetminer.com/pricing-plans" target="_blank" >(Upgrade)</a>`;
}

Expand Down
109 changes: 42 additions & 67 deletions client-base/src/main/webapp/html/javascript/web-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,50 +107,43 @@

class WebCacheWrapper
{
cacheName = null
#cacheName = null

constructor(cacheName){
this.cacheName = cacheName
this.#cacheName = cacheName
}

// Method get cached data if available or calls API endpoints
async requestHandler(request, options){

let data = await this.get(request)

if(!data)
// Method checks request url to determine if it's cached from previous API call.
async get ( requestUrl, options = { data: '', timeout: 100000 } )
{
let result = await caches.match ( requestUrl, options )
if ( result ) return result.json ()

result = await this._apiHandler ( requestUrl, options );

caches.open ( this.#cacheName ).then ( (cache) =>
{
data = await $.get({ url:request, data: '', timeout: 100000 })
.done( response => this.openCache(request,response,options))
.fail(function (xhr, status, errolog) {
jboxNotice('An error occured, kindly try again', 'red', 300, 2000);
return null
})
}

return data;
// TODO: do we need to serialize/unserialize JSON, can't we just store and return 'result'?
//
cache.put ( requestUrl, new Response ( JSON.stringify ( result ), options ) )
})

}


// Method checks request url to determine if it's cached from previous API call.
async get(request){
// if request is cached, cached data is returned
const cachedData = await caches.match(request);

if(!cachedData) return null

const response = cachedData.json();
return response;

return result
}

// Method puts cached data in browser API
openCache(request,response,options)
async _apiHandler ( requestUrl, options )
{
caches.open(this.cacheName).then((cache) => {
cache.put(request,new Response(JSON.stringify(response),options))
})
try {
const result = await $.get( { url:requestUrl, ...options } )
return result
}
catch ( err )
{
// TODO: report the error
jboxNotice ( 'An error occured, kindly try again', 'red', 300, 2000 );
return null
}
}

}
Expand All @@ -160,40 +153,22 @@
{

// gets cached data and calls for API endpoint when cache request is not
async apiHandler(conceptId){
// api request string
let request = api_url+'/genome?keyword=ConceptID:'+ conceptId

// gets cached request
let data = await super.get(request);
async get ( conceptId )
{
return super.get (
api_url + '/genome?keyword=ConceptID:' + conceptId,
{ data: '', timeout: 100000, headers: { 'Content-Type': 'text/plain' } }
)
}

async _apiHandler ( requestUrl, options )
{
let result = await super._apiHandler ( requestUrl, options )
if ( !result ) return result;
let geneTable = formatJsonToTsv(result.geneTable)
geneTable = geneTable.split("\n")

// calls API endpoints when request is not
if(!data)
{
await $.get({url:request,timeout:100000})
.done((response) => {

// TODO: WILL BE REMOVED IN COMING DAYS
// TODO: Sounds like this should stay for the purpose of evidence genes download
// possibly, remove the comments.

let geneTable = formatJsonToTsv(response.geneTable);
geneTable = geneTable.split("\n")


super.openCache(request,geneTable,{headers: {'Content-Type': 'text/plain'}})
data = geneTable

// extended method registers cache request and response objects (geneTable and headers)

})
.fail(function (xhr, status, errolog) {
jboxNotice('An error occured, kindly try again', 'red', 300, 2000);
return null
})
}

return data;
return geneTable
}

}

0 comments on commit 4d83934

Please sign in to comment.