From 9a9b815d8fc9810600668ca358f72e0130e37d8f Mon Sep 17 00:00:00 2001 From: Qiang Gu Date: Thu, 15 Nov 2018 11:48:46 -0800 Subject: [PATCH 1/3] add datatype sniff button in edit dataset attributes page --- .../mvc/dataset/dataset-edit-attributes.js | 8 ++++++++ .../webapps/galaxy/controllers/dataset.py | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js b/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js index f81fa6b8a1c..ba95a756415 100644 --- a/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js +++ b/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js @@ -172,6 +172,14 @@ var View = Backbone.View.extend({ onclick: function() { self._submit("datatype", form); } + }), + submit_datatype_sniff: new Ui.ButtonIcon({ + tooltip: _l("Sniff the datatype and change it."), + title: _l("Sniff datatype"), + icon: "fa-undo", + onclick: function() { + self._submit("datatype_sniff", form); + } }) } }); diff --git a/lib/galaxy/webapps/galaxy/controllers/dataset.py b/lib/galaxy/webapps/galaxy/controllers/dataset.py index 46d5cf204c5..32a4369e8b9 100644 --- a/lib/galaxy/webapps/galaxy/controllers/dataset.py +++ b/lib/galaxy/webapps/galaxy/controllers/dataset.py @@ -18,6 +18,7 @@ from galaxy import ( web ) from galaxy.datatypes.display_applications.util import decode_dataset_user, encode_dataset_user +from galaxy.datatypes import sniff from galaxy.exceptions import RequestParameterInvalidException from galaxy.model.item_attrs import UsesAnnotations, UsesItemRatings from galaxy.util import ( @@ -25,6 +26,7 @@ from galaxy.util import ( sanitize_text, smart_str ) +from galaxy.util.checkers import check_binary from galaxy.util.sanitize_html import sanitize_html from galaxy.web import form_builder from galaxy.web.base.controller import BaseUIController, ERROR, SUCCESS, url_for, UsesExtendedMetadataMixin @@ -459,6 +461,24 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE message = 'Changed the type to %s.' % datatype else: return self.message_exception(trans, 'You are unable to change datatypes in this manner. Changing %s to %s is not allowed.' % (data.extension, datatype)) + elif operation == 'datatype_sniff': + # The user clicked the Sniff button on the 'Change data type' form + if data.datatype.allow_datatype_change: + # prevent modifying datatype when dataset is queued or running as input/output + if not __ok_to_edit_metadata(data.id): + return self.message_exception(trans, 'This dataset is currently being used as input or output. You cannot change datatype until the jobs have completed or you have canceled them.') + else: + path = data.dataset.file_name + is_binary = check_binary(path) + datatype = sniff.guess_ext(path, trans.app.datatypes_registry.sniff_order, is_binary=is_binary) + trans.app.datatypes_registry.change_datatype(data, datatype) + trans.sa_session.flush() + trans.app.datatypes_registry.set_external_metadata_tool.tool_action.execute( + trans.app.datatypes_registry.set_external_metadata_tool, trans, incoming={'input1': data}, + overwrite=False) # overwrite is False as per existing behavior + message = 'Sniffed and changed the type to %s.' % datatype + else: + return self.message_exception(trans, 'Changing datatype %s is not allowed.' % (data.extension)) elif operation == 'autodetect': # The user clicked the Auto-detect button on the 'Edit Attributes' form # prevent modifying metadata when dataset is queued or running as input/output From 170ed2a8c2a4d324ceac6fabf2a115d6eb801c16 Mon Sep 17 00:00:00 2001 From: Qiang Gu Date: Thu, 15 Nov 2018 12:33:21 -0800 Subject: [PATCH 2/3] fix style and wording --- .../scripts/mvc/dataset/dataset-edit-attributes.js | 8 ++++---- lib/galaxy/webapps/galaxy/controllers/dataset.py | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js b/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js index ba95a756415..8b97b11fb46 100644 --- a/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js +++ b/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js @@ -173,12 +173,12 @@ var View = Backbone.View.extend({ self._submit("datatype", form); } }), - submit_datatype_sniff: new Ui.ButtonIcon({ - tooltip: _l("Sniff the datatype and change it."), - title: _l("Sniff datatype"), + submit_datatype_detect: new Ui.ButtonIcon({ + tooltip: _l("Detect the datatype and change it."), + title: _l("Detect datatype"), icon: "fa-undo", onclick: function() { - self._submit("datatype_sniff", form); + self._submit("datatype_detect", form); } }) } diff --git a/lib/galaxy/webapps/galaxy/controllers/dataset.py b/lib/galaxy/webapps/galaxy/controllers/dataset.py index 32a4369e8b9..1fe7c3facfe 100644 --- a/lib/galaxy/webapps/galaxy/controllers/dataset.py +++ b/lib/galaxy/webapps/galaxy/controllers/dataset.py @@ -17,8 +17,8 @@ from galaxy import ( util, web ) -from galaxy.datatypes.display_applications.util import decode_dataset_user, encode_dataset_user from galaxy.datatypes import sniff +from galaxy.datatypes.display_applications.util import decode_dataset_user, encode_dataset_user from galaxy.exceptions import RequestParameterInvalidException from galaxy.model.item_attrs import UsesAnnotations, UsesItemRatings from galaxy.util import ( @@ -461,8 +461,8 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE message = 'Changed the type to %s.' % datatype else: return self.message_exception(trans, 'You are unable to change datatypes in this manner. Changing %s to %s is not allowed.' % (data.extension, datatype)) - elif operation == 'datatype_sniff': - # The user clicked the Sniff button on the 'Change data type' form + elif operation == 'datatype_detect': + # The user clicked the 'Detect datatype' button on the 'Change data type' form if data.datatype.allow_datatype_change: # prevent modifying datatype when dataset is queued or running as input/output if not __ok_to_edit_metadata(data.id): @@ -476,9 +476,9 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE trans.app.datatypes_registry.set_external_metadata_tool.tool_action.execute( trans.app.datatypes_registry.set_external_metadata_tool, trans, incoming={'input1': data}, overwrite=False) # overwrite is False as per existing behavior - message = 'Sniffed and changed the type to %s.' % datatype + message = 'Detection was finished and changed the datatype to %s.' % datatype else: - return self.message_exception(trans, 'Changing datatype %s is not allowed.' % (data.extension)) + return self.message_exception(trans, 'Changing datatype "%s" is not allowed.' % (data.extension)) elif operation == 'autodetect': # The user clicked the Auto-detect button on the 'Edit Attributes' form # prevent modifying metadata when dataset is queued or running as input/output From 4ff3c95e38d1c62a5d1b85994e2dde909a2f7e38 Mon Sep 17 00:00:00 2001 From: Qiang Gu Date: Mon, 19 Nov 2018 22:20:32 -0800 Subject: [PATCH 3/3] fix a typo error --- client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js b/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js index 8b97b11fb46..e3b8e0558cf 100644 --- a/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js +++ b/client/galaxy/scripts/mvc/dataset/dataset-edit-attributes.js @@ -173,7 +173,7 @@ var View = Backbone.View.extend({ self._submit("datatype", form); } }), - submit_datatype_detect: new Ui.ButtonIcon({ + submit_datatype_detect: new Ui.Button({ tooltip: _l("Detect the datatype and change it."), title: _l("Detect datatype"), icon: "fa-undo",