Skip to content

Commit

Permalink
-> Can't update user settings without a user
Browse files Browse the repository at this point in the history
-> Login must be required for user-accessing views
  • Loading branch information
s-paquette committed Oct 25, 2024
1 parent d9b1ee7 commit 99897ed
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 106 deletions.
63 changes: 20 additions & 43 deletions idc/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###
# Copyright 2015-2021, Institute for Systems Biology
# Copyright 2015-2024, Institute for Systems Biology
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -137,7 +137,7 @@ def news_page(request):


# User details page
#@login_required
@login_required
def user_detail(request, user_id):
if debug: logger.debug('Called ' + sys._getframe().f_code.co_name)

Expand Down Expand Up @@ -222,7 +222,7 @@ def quota_page(request):
return render(request, 'idc/quota.html', {'request': request, 'quota': settings.IMG_QUOTA})


#@login_required
@login_required
def save_ui_hist(request):
status = 200
try:
Expand All @@ -243,28 +243,23 @@ def save_ui_hist(request):

return JsonResponse({}, status=status)



@login_required
def getCartData(request):
response = {}
status = 200
sources = ImagingDataCommonsVersion.objects.get(active=True).get_data_sources(
active=True, source_type=DataSource.SOLR,
aggregate_level="StudyInstanceUID"
)

# @login_required
# def getCartData(request):
# response = {}
# status = 200
# sources = ImagingDataCommonsVersion.objects.get(active=True).get_data_sources(
# active=True, source_type=DataSource.SOLR,
# aggregate_level="StudyInstanceUID"
# )

#def compcartsets(carthist, sel):


def cartsets(carthist):
cartsets = []

for cartfiltset in carhist:
for selection in cartfiltset:
sel = selection['sel']

# def cartsets(carthist):
# cartsets = []
#
# for cartfiltset in carhist:
# for selection in cartfiltset:
# sel = selection['sel']


def cart(request):
Expand All @@ -279,15 +274,8 @@ def cart(request):
offset = json.loads(req.get(offset, 0))

get_cart_data(filtlist,partitions,limit, offset)






i=1


except Exception as e:
logger.error("[ERROR] While attempting to populate the table:")
logger.exception(e)
Expand All @@ -300,9 +288,8 @@ def cart(request):
return JsonResponse(response, status=status)



# returns various metadata mappings for selected projects used in calculating cart selection counts 'on the fly' client side
#@login_required
# returns various metadata mappings for selected projects used in calculating cart selection
# counts 'on the fly' client side
def studymp(request):

response = {}
Expand Down Expand Up @@ -334,13 +321,11 @@ def studymp(request):
mxStudies= int(req.get('mxstudies'))
limit = int(req.get('limit', mxStudies))
offset = int(req.get('offset',0))


casestudymp = dict()
studymp = dict()
projstudymp = dict()


idsEx = get_collex_metadata(
filters, ['collection_id', 'PatientID','StudyInstanceUID', 'SeriesInstanceUID'], record_limit=limit, sources=sources, offset=offset,
records_only=True, custom_facets={}, aux_sources=aux_sources,
Expand Down Expand Up @@ -370,8 +355,6 @@ def studymp(request):
response['casestudymp'] = casestudymp
response['projstudymp'] = projstudymp



except Exception as e:
logger.error("[ERROR] While attempting to get studymp:")
logger.exception(e)
Expand All @@ -384,8 +367,6 @@ def studymp(request):
return JsonResponse(response, status=status)



#@login_required
def populate_tables(request):
response = {}
status = 200
Expand Down Expand Up @@ -429,13 +410,11 @@ def populate_tables(request):
id__in=versions.get_data_sources().filter(source_type=DataSource.SOLR).values_list("id", flat=True)
).distinct()


sources = ImagingDataCommonsVersion.objects.get(active=True).get_data_sources(
active=True, source_type=DataSource.SOLR,
aggregate_level=aggregate_level
)


sortByField = True
#idsReq=[]
custom_facets = None
Expand All @@ -444,7 +423,6 @@ def populate_tables(request):
custom_facets_ex = {"tot_series": {"type": "terms", "field": "PatientID", "limit": limit,
"facet": {"unique_series": "unique(SeriesInstanceUID)"}, "domain": {"query": "*.*"}}}


if table_type =="collections":
custom_facets = {"per_id": {"type": "terms", "field": "collection_id", "limit": limit,
"facet": {"unique_patient":"unique(PatientID)", "unique_study": "unique(StudyInstanceUID)",
Expand All @@ -459,7 +437,6 @@ def populate_tables(request):
sortByField= True
sort="collection_id"


if table_type == 'cases':
custom_facets = {"per_id": {"type": "terms", "field": "PatientID", "limit": limit,
"facet": {"unique_study": "unique(StudyInstanceUID)",
Expand Down Expand Up @@ -1100,7 +1077,7 @@ def test_page(request, mtch):


# User dashboard, where saved cohorts (and, in the future, uploaded/indexed data) are listed
#@login_required
@login_required
def dashboard_page(request):
context = {'request': request}

Expand Down
107 changes: 44 additions & 63 deletions static/js/image_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ require([
}
}


window.changePage = function(wrapper){
var elem=$('#'+wrapper);
var valStr = elem.find('.dataTables_controls').find('.goto-page-number').val();
Expand All @@ -631,7 +630,6 @@ require([
catch(err){
console.log(err);
}

}


Expand Down Expand Up @@ -662,7 +660,6 @@ require([
studymp[studyid] = []
}
studymp[studyid].push(seriesid)

}
if ("studymp" in sessionStorage) {
var studymp = JSON.parse(sessionStorage.getItem("studymp"));
Expand All @@ -675,8 +672,6 @@ require([

}



cartutils.updateGlobalCart(false, studymp, 'series')
window.updateTableCounts(1);
var gtotals = cartutils.getGlobalCounts();
Expand All @@ -700,8 +695,6 @@ require([
$('#export-manifest-cart').attr('disabled','disabled');
$('#view-cart').attr('disabled','disabled');
}


}
else if ("cartHist" in localStorage){
localStorage.removeItem("cartHist");
Expand All @@ -713,14 +706,13 @@ require([
sessionStorage.removeItem("studymp");
}
if ("seriesdel" in sessionStorage) {
sessionStorage.removeItem("seriesdel");
}
sessionStorage.removeItem("seriesdel");
}
}

$(document).ready(function () {
window.pageid = Math.random().toString(36).substr(2,8);


tables.initializeTableData();
filterItemBindings('access_set');
filterItemBindings('program_set');
Expand Down Expand Up @@ -793,10 +785,9 @@ require([
if (!setCartHist){
window.cartHist = new Array();
}*/
window.cartHist = new Array();
window.cartHist = new Array();
window.cartHist.push(cartSel);


/*
if ('cartHist' in localStorage){
cartutils.refreshCartAndFiltersFromScratch(true);
Expand All @@ -806,7 +797,6 @@ require([
}
*/


filterutils.load_preset_filters();
$('.hide-filter-uri').on('click',function() {
$(this).hide();
Expand Down Expand Up @@ -845,54 +835,47 @@ require([
});

window.onbeforeunload = function(){

console.log("beforeunload called");
let hs = new Object();
hs['hz'] = new Object();
hs['sorter'] = new Object();
$('body').find('.hide-zeros').each(function(){
let pfar = $(this).closest('.collection-list, .search-configuration, #analysis_set ');
let pid = pfar[0].id;
let checked = pfar.find('.hide-zeros')[0].checked;
hs['hz'][pid] = checked;
});

$('body').find('.sorter').each(function(){
let pfar = $(this).closest('.collection-list, .list-group-item__body ');
let pid = pfar[0].id;
let sort = $(this).find('input:checked').val()
hs['sorter'][pid] = sort;
});


let url = encodeURI('/uihist/')
let nhs = {'his':JSON.stringify(hs)}
let csrftoken = $.getCookie('csrftoken');
let deferred = $.Deferred();

$.ajax({
url: url,
data: nhs,
dataType: 'json',
type: 'post',
contentType: 'application/x-www-form-urlencoded',
beforeSend: function(xhr){xhr.setRequestHeader("X-CSRFToken", csrftoken);},
success: function (data) {
},
error: function(data){
console.debug('Error saving ui preferences.');
},
complete: function(data) {
deferred.resolve();
}
});

// was saving cart data in local storage. Not feasible to maintain global cart
//cartutils.setLocalFromCartHistWin();
//sessionStorage.setItem("cartHist", JSON.stringify(window.cartHist));
//localStorage.setItem("cartDetails", JSON.stringify(window.cartDetails));
//sessionStorage.setItem("glblcart", JSON.stringify(window.glblcart));
//localStorage.setItem("src", "explore_page");
// User history can only be saved on the database if there is a user
if(user_is_auth) {
let hs = new Object();
hs['hz'] = new Object();
hs['sorter'] = new Object();
$('body').find('.hide-zeros').each(function(){
let pfar = $(this).closest('.collection-list, .search-configuration, #analysis_set ');
let pid = pfar[0].id;
let checked = pfar.find('.hide-zeros')[0].checked;
hs['hz'][pid] = checked;
});

$('body').find('.sorter').each(function(){
let pfar = $(this).closest('.collection-list, .list-group-item__body ');
let pid = pfar[0].id;
let sort = $(this).find('input:checked').val()
hs['sorter'][pid] = sort;
});

let url = encodeURI('/uihist/')
let nhs = {'his':JSON.stringify(hs)}
let csrftoken = $.getCookie('csrftoken');
let deferred = $.Deferred();

$.ajax({
url: url,
data: nhs,
dataType: 'json',
type: 'post',
contentType: 'application/x-www-form-urlencoded',
beforeSend: function(xhr){xhr.setRequestHeader("X-CSRFToken", csrftoken);},
success: function (data) {
},
error: function(data){
console.debug('Error saving ui preferences.');
},
complete: function(data) {
deferred.resolve();
}
});
}

var maxSeries=0;
var maxStudies=0;
Expand All @@ -904,7 +887,6 @@ require([
maxStudies = maxStudies + window.selProjects[proj]['mxstudies'];
projA.push(proj);
}

}

if (projA.length>0){
Expand All @@ -926,7 +908,6 @@ require([
}

window.onpageshow = function (){
//alert('show');
if ("cartcleared" in localStorage){
localStorage.removeItem("cartcleared");
window.resetCart();
Expand Down

0 comments on commit 99897ed

Please sign in to comment.