Skip to content

Commit

Permalink
Merge branch 'ui-v2' of github.com:IGS/gEAR into ui-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jorvis committed Aug 7, 2024
2 parents e1ec12d + 58b617e commit 6c25fc1
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 10 deletions.
32 changes: 32 additions & 0 deletions lib/geardb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,38 @@ def save(self):
cursor.close()
conn.close()

def remove(self):
"""
Deletes the current display from the database.
"""
conn = Connection()
cursor = conn.get_cursor()

# first remove any layout_display entries
qry = """
DELETE FROM layout_displays
WHERE display_id = %s
"""
cursor.execute(qry, (self.id,))

# Then remove from anly dataset_preference entries
qry = """
DELETE FROM dataset_preference
WHERE display_id = %s
"""
cursor.execute(qry, (self.id,))

# Then remove the display itself
qry = """
DELETE FROM dataset_display
WHERE id = %s
"""
cursor.execute(qry, (self.id,))

cursor.close()
conn.commit()
conn.close()

@dataclass
class Dataset:
id: str
Expand Down
7 changes: 4 additions & 3 deletions www/api/resources/multigene_dash_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,16 @@ def post(self, dataset_id):

try:
ana = geardb.get_analysis(analysis, dataset_id, session_id)
# Using adata with "backed" mode does not work with volcano plot
adata = ana.get_adata(backed=False)
except Exception as e:
import traceback
traceback.print_exc()
return {
'success': -1,
'message': str(e),
}

# Using adata with "backed" mode does not work with volcano plot
adata = ana.get_adata(backed=False)

adata.obs = order_by_time_point(adata.obs)

# get a map of all levels for each column
Expand Down
5 changes: 3 additions & 2 deletions www/api/resources/plotly_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ def post(self, dataset_id):

try:
ana = geardb.get_analysis(analysis, dataset_id, session_id)
adata = ana.get_adata(backed=True)
except Exception as e:
import traceback
traceback.print_exc()
return_dict["success"] = -1
return_dict["message"] = str(e)
return return_dict

adata = ana.get_adata(backed=True)

if projection_id:
try:
adata = create_projection_adata(adata, dataset_id, projection_id)
Expand Down
4 changes: 3 additions & 1 deletion www/api/resources/tsne_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,15 @@ def post(self, dataset_id):

try:
ana = geardb.get_analysis(analysis, dataset_id, session_id)
adata = ana.get_adata(backed=True)
except Exception as e:
import traceback
traceback.print_exc()
return {
"success": -1,
"message": str(e)
}

adata = ana.get_adata(backed=True)

if projection_id:
try:
Expand Down
45 changes: 43 additions & 2 deletions www/cgi/delete_dataset_analysis.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,59 @@ def main():
session_id = form.getvalue('session_id')
user = geardb.get_user_from_session_id(session_id)

if not user:
print('Content-Type: application/json\n\n')
print(json.dumps({'success': 0, 'error': 'User not found'}))
return

source_ana = geardb.Analysis(id=analysis_id, type=analysis_type,
dataset_id=dataset_id, session_id=session_id, user_id=user.id)
source_pipeline_base = source_ana.base_path()

result = {'success': 0}

# verify this analysis belongs to the user
if not os.path.exists(source_pipeline_base):
result = {'success': 0, 'error': 'Analysis not found'}
sys.stdout = original_stdout
print('Content-Type: application/json\n\n')
print(json.dumps(result))
return
if not source_ana.user_id == user.id:
result = {'success': 0, 'error': 'Analysis does not belong to user'}
sys.stdout = original_stdout
print('Content-Type: application/json\n\n')
print(json.dumps(result))
return

try:
# TODO: need to verify ownership here in the future before deleting
#print("DEBUG: would rmtree this:{0}".format(source_pipeline_base), file=sys.stderr)
# move directory to a backup in case of failures
#shutil.move(source_pipeline_base, source_pipeline_base + '.deleted')

# find any dataset displays with this analysis id in the plotly_config
"""
conn = Connection()
cursor = conn.get_cursor()
qry = "SELECT * from dataset_display where plotly_config like '%\"id\":\"{}\"%'".format(analysis_id)
cursor.execute(qry, (self.id,))
for (display_id, user_id, label, plot_type, plotly_config) in cursor:
display = DatasetDisplay(
id=display_id,
dataset_id=self.id,
user_id=user_id,
label=label,
plot_type=plot_type,
plotly_config=plotly_config
)
display.remove()
"""

#shutil.rmtree(source_pipeline_base + '.deleted')
shutil.rmtree(source_pipeline_base)
result = {'success': 1}
except:
# restore the backup
#shutil.move(source_pipeline_base + '.deleted', source_pipeline_base)
result = {'success': 0, 'error': 'Unable to delete dataset'}

sys.stdout = original_stdout
Expand Down
4 changes: 2 additions & 2 deletions www/dataset_explorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@
<div class="field">
<label class="label">Pubmed ID</label>
<div class="control">
<input class="input" readonly>
<input class="input">
</div>
</div>
</div>
Expand All @@ -451,7 +451,7 @@
<div class="field">
<label class="label">GEO ID</label>
<div class="control">
<input class="input" readonly>
<input class="input">
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions www/js/classes/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class Analysis {
document.querySelector(UI.newAnalysisOptionElt).setAttribute("selected", "selected");
document.querySelector(UI.analysisSelect).dispatchEvent(new Event("change"));
await this.getSavedAnalysesList(this.dataset.id, 0);
resetStepperWithHrefs(UI.primaryFilterSection);

} catch (error) {
createToast(`Error deleting analysis: ${error.message}`);
Expand Down
9 changes: 9 additions & 0 deletions www/js/dataset_explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ const addDatasetListEventListeners = () => {
const title = document.querySelector(`${selectorBase}-editable-title`).dataset.originalVal;
document.querySelector(`${selectorBase}-editable-title`).value = title;

const ldesc = document.querySelector(`${selectorBase}-editable-ldesc`).dataset.originalVal;
document.querySelector(`${selectorBase}-editable-ldesc`).value = ldesc;

const pubmedId = document.querySelector(`${selectorBase}-editable-pubmed-id`).dataset.originalVal;
document.querySelector(`${selectorBase}-editable-pubmed-id`).value = pubmedId;

const geoId = document.querySelector(`${selectorBase}-editable-geo-id`).dataset.originalVal;
document.querySelector(`${selectorBase}-editable-geo-id`).value = geoId;

document.querySelector(`${selectorBase} .js-action-links`).classList.remove("is-hidden");

});
Expand Down

0 comments on commit 6c25fc1

Please sign in to comment.