Skip to content

Commit 1e3a802

Browse files
committed
delete sample template
1 parent 3aa8f73 commit 1e3a802

File tree

4 files changed

+76
-8
lines changed

4 files changed

+76
-8
lines changed

qiita_db/metadata_template/base_metadata_template.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -761,21 +761,36 @@ def delete(cls, id_):
761761
conn_handler = SQLConnectionHandler()
762762

763763
# Delete the sample template filepaths
764-
conn_handler.execute(
765-
"DELETE FROM qiita.sample_template_filepath WHERE "
766-
"study_id = %s", (id_, ))
764+
queue = "delete_sample_template_%d" % id_
765+
conn_handler.create_queue(queue)
767766

768-
conn_handler.execute(
769-
"DROP TABLE qiita.{0}".format(table_name))
770-
conn_handler.execute(
767+
conn_handler.add_to_queue(
768+
queue,
769+
"DELETE FROM qiita.sample_template_filepath WHERE study_id = %s",
770+
(id_, ))
771+
772+
conn_handler.add_to_queue(
773+
queue,
774+
"DROP TABLE IF EXISTS qiita.{0}".format(table_name))
775+
776+
conn_handler.add_to_queue(
777+
queue,
778+
"DROP TABLE IF EXISTS qiita.{0}".format(table_name))
779+
780+
conn_handler.add_to_queue(
781+
queue,
771782
"DELETE FROM qiita.{0} where {1} = %s".format(cls._table,
772783
cls._id_column),
773784
(id_,))
774-
conn_handler.execute(
785+
786+
conn_handler.add_to_queue(
787+
queue,
775788
"DELETE FROM qiita.{0} where {1} = %s".format(cls._column_table,
776789
cls._id_column),
777790
(id_,))
778791

792+
conn_handler.execute_queue(queue)
793+
779794
@classmethod
780795
def exists(cls, obj_id):
781796
r"""Checks if already exists a MetadataTemplate for the provided object

qiita_pet/handlers/study_handlers/description_handlers.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,33 @@ def display_template(self, study, user, msg, msg_level, full_access,
640640
sub_tab=sub_tab,
641641
prep_tab=prep_tab)
642642

643+
def delete_sample_template(self, study, user, callback):
644+
"""Delete sample template
645+
646+
Parameters
647+
----------
648+
study : Study
649+
The current study object
650+
user : User
651+
The current user object
652+
callback : function
653+
The callback function to call with the results once the processing
654+
is done
655+
"""
656+
sample_template_id = int(self.get_argument('sample_template_id'))
657+
658+
try:
659+
SampleTemplate.delete(sample_template_id)
660+
msg = ("Sample template %d has been deleted from study: "
661+
"<b><i>%s</i></b>" % (sample_template_id, study.title))
662+
msg_level = "success"
663+
except Exception as e:
664+
msg = "Couldn't remove %d raw data: %s" % (sample_template_id,
665+
str(e))
666+
msg_level = "danger"
667+
668+
callback((msg, msg_level, 'study_information_tab', None, None))
669+
643670
def delete_raw_data(self, study, user, callback):
644671
"""Delete the selected raw data
645672
@@ -781,6 +808,7 @@ def post(self, study_id):
781808
request_approval=self.request_approval,
782809
make_sandbox=self.make_sandbox,
783810
update_investigation_type=self.update_investigation_type,
811+
delete_sample_template=self.delete_sample_template,
784812
delete_raw_data=self.delete_raw_data,
785813
delete_prep_template=self.delete_prep_template,
786814
delete_preprocessed_data=self.delete_preprocessed_data,

qiita_pet/templates/study_description.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@
184184
form.submit();
185185
}
186186

187+
function delete_sample_template(sample_template_id) {
188+
if (confirm('Are you sure you want to delete sample template ID: ' + sample_template_id + '?')) {
189+
var form = $("<form>")
190+
.attr("action", window.location.href)
191+
.attr("method", "post")
192+
.append($("<input>")
193+
.attr("type", "hidden")
194+
.attr("name", "sample_template_id")
195+
.attr("value", sample_template_id))
196+
.append($("<input>")
197+
.attr("type", "hidden")
198+
.attr("name", "action")
199+
.attr("value", "delete_sample_template"));
200+
$("body").append(form);
201+
form.submit();
202+
}
203+
}
204+
187205
function delete_raw_data(raw_data_filetype, raw_data_id) {
188206
if (confirm('Are you sure you want to delete raw data: ' + raw_data_filetype + ' (ID: ' + raw_data_id + ')?')) {
189207
var form = $("<form>")
@@ -537,7 +555,12 @@ <h2><i>{{study_alias}}</i></h2>
537555

538556
<!-- Nav tabs -->
539557
<ul class="nav nav-tabs" role="tablist" id="myTab">
540-
<li class="active"><a href="#study_information_tab" role="tab" data-toggle="tab">Study information</a></li>
558+
<li class="active">
559+
<a href="#study_information_tab" role="tab" data-toggle="tab">
560+
Study information
561+
<button class="close" title="Remove this sample template" type="button" onclick="delete_sample_template({{study.sample_template}})">&nbsp; ×</button>
562+
</a>
563+
</li>
541564
{% if show_data_tabs %}
542565
<li><a href="#raw_data_tab" role="tab" data-toggle="tab">Raw data</a></li>
543566
<li><a href="#preprocessed_data_tab" role="tab" data-toggle="tab">Preprocessed data</a></li>

qiita_pet/templates/study_description_templates/study_information_tab.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343

4444
<table>
4545
<tr>
46+
{% if not sample_templates %}
4647
<td>
4748
<a class="btn btn-primary" onclick="process_sample_template();">Process sample template</a>
4849
</td>
4950
<td>&nbsp; &nbsp;</td>
51+
{% end %}
5052
{% if sample_templates %}
5153
<td>
5254
<a class="btn btn-primary" onclick="update_sample_template();">Update sample template</a>

0 commit comments

Comments
 (0)