Skip to content

Commit dff6c49

Browse files
committed
GUI modifications
1 parent 11e71a5 commit dff6c49

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

qiita_pet/handlers/analysis_handlers.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,54 @@ def get(self, analysis_id):
156156
dropped[data_type].append({'study': Study(study).title,
157157
'samples': samples})
158158

159-
self.render("analysis_results.html",
159+
self.render("analysis_results.html", analysis_id=analysis_id,
160160
jobres=jobres, aname=analysis.name, dropped=dropped,
161161
basefolder=get_db_files_base_dir())
162162

163+
@authenticated
164+
def post(self, analysis_id):
165+
analysis_id = int(analysis_id.split("/")[0])
166+
analysis_id_sent = int(self.get_argument('analysis_id'))
167+
action = self.get_argument('action')
168+
169+
if analysis_id != analysis_id_sent or action != 'delete_analysis':
170+
raise QiitaPetAuthorizationError(
171+
self.current_user.id,
172+
'analysis/results/%d-delete' % analysis_id)
173+
174+
analysis = Analysis(analysis_id)
175+
check_analysis_access(self.current_user, analysis)
176+
177+
try:
178+
Analysis.delete(analysis_id)
179+
msg = ("Analysis <b><i>%s</i></b> has been deleted." % (
180+
analysis.title))
181+
msg_level = "success"
182+
except Exception as e:
183+
print e
184+
msg = ("Couldn't remove <b><i>%s</i></b> analysis: %s" % (
185+
analysis.name, str(e)))
186+
msg_level = "danger"
187+
188+
# redirecting to list of analysis but also passing messages and
189+
# we need to change the request.method to GET
190+
self.request.method = 'GET'
191+
ShowAnalysesHandler(self.application, self.request)._execute(
192+
[t(self.request) for t in self.application.transforms],
193+
message=msg, msg_level=msg_level)
194+
163195

164196
class ShowAnalysesHandler(BaseHandler):
165197
"""Shows the user's analyses"""
166198
@authenticated
167-
def get(self):
199+
def get(self, message='', msg_level=''):
168200
user = self.current_user
169201

170202
analyses = [Analysis(a) for a in
171203
user.shared_analyses | user.private_analyses]
172204

173-
self.render("show_analyses.html", analyses=analyses)
205+
self.render("show_analyses.html", analyses=analyses, message=message,
206+
msg_level=msg_level)
174207

175208

176209
class ResultsHandler(StaticFileHandler, BaseHandler):

qiita_pet/templates/analysis_results.html

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@
1111

1212

1313
<div class="row">
14-
<h1>&nbsp;Analysis: <u>{{aname}}</u></h1>
14+
<table border="0">
15+
<tr>
16+
<td><h1>&nbsp;Analysis: <u>{{aname}}</u></h1></td>
17+
<td width="20px"></td>
18+
<td>
19+
<h1><a class="btn btn-danger glyphicon glyphicon-trash" onclick="delete_analysis();"></a></h1>
20+
</td>
21+
</tr>
22+
</table>
23+
</h1>
1524
</div>
1625

1726

@@ -74,4 +83,27 @@ <h3 style="color:red">ERROR</h3>
7483
<iframe id="resframe" name="resframe" width="100%" height="900" frameBorder=0></iframe>
7584
</div>
7685
</div>
86+
87+
88+
<script>
89+
90+
function delete_analysis() {
91+
if (confirm('Are you sure you want to delete analysis: {{aname}}?')) {
92+
var form = $("<form>")
93+
.attr("action", window.location.href)
94+
.attr("method", "post")
95+
.append($("<input>")
96+
.attr("type", "hidden")
97+
.attr("name", "analysis_id")
98+
.attr("value", {{analysis_id}}))
99+
.append($("<input>")
100+
.attr("type", "hidden")
101+
.attr("name", "action")
102+
.attr("value", "delete_analysis"));
103+
$("body").append(form);
104+
form.submit();
105+
}
106+
}
107+
108+
</script>
77109
{%end%}

0 commit comments

Comments
 (0)