From 70e38f71951bcc6e541e1ddf034b0db167f2b9cd Mon Sep 17 00:00:00 2001 From: njkim Date: Thu, 26 Oct 2023 21:55:59 -0700 Subject: [PATCH] Shoe tiledata as preview, #10186 --- arches/app/etl_modules/bulk_data_deletion.py | 47 +++++++++++++++++-- .../etl_modules/bulk-data-deletion.js | 2 + arches/app/templates/javascript.htm | 1 + .../etl_modules/bulk-data-deletion.htm | 31 ++++++++++-- 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/arches/app/etl_modules/bulk_data_deletion.py b/arches/app/etl_modules/bulk_data_deletion.py index 85dcc590cc2..f9eee84c8bf 100644 --- a/arches/app/etl_modules/bulk_data_deletion.py +++ b/arches/app/etl_modules/bulk_data_deletion.py @@ -27,11 +27,11 @@ def get_number_of_deletions(self, graph_id, nodegroup_id, resourceids): "language_code": settings.LANGUAGE_CODE, } - resourceids_query = "AND r.resourceinstanceid IN %(resourceids)s" if resourceids else "" + resourceids_query = "AND resourceinstanceid IN %(resourceids)s" if resourceids else "" tile_deletion_count = """ - SELECT g.name ->> %(language_code)s, COUNT(DISTINCT t.resourceinstanceid), COUNT(t.tileid) - FROM tiles t, graphs g - WHERE t.nodegroupid = %(nodegroup_id)s + SELECT COUNT(DISTINCT resourceinstanceid), COUNT(tileid) + FROM tiles + WHERE nodegroupid = %(nodegroup_id)s """ + resourceids_query resource_deletion_count = """ @@ -70,6 +70,41 @@ def get_number_of_deletions(self, graph_id, nodegroup_id, resourceids): return number_of_resource, number_of_tiles + def get_sample_data(self, nodegroup_id, resourceids): + params = { + "nodegroup_id": nodegroup_id, + "resourceids": resourceids, + } + + resourceids_query = "AND resourceinstanceid IN %(resourceids)s" if resourceids else "" + get_sample_resource_ids = """ + SELECT DISTINCT resourceinstanceid + FROM tiles + WHERE nodegroupid = %(nodegroup_id)s + """ + resourceids_query + """ + LIMIT 5 + """ + + get_sample_tiledata = """ + SELECT tiledata + FROM tiles + WHERE nodegroupid = %(nodegroup_id)s + """ + resourceids_query + """ + LIMIT 5 + """ + + with connection.cursor() as cursor: + cursor.execute(get_sample_resource_ids, params) + rows = cursor.fetchall() + smaple_resource_ids = [row[0] for row in rows] + + with connection.cursor() as cursor: + cursor.execute(get_sample_tiledata, params) + rows = cursor.fetchall() + sample_data = [row[0] for row in rows] + + return sample_data + def delete_resources(self, userid, loadid, graphid, resourceids): result = {"success": False} user = User.objects.get(id=userid) @@ -150,6 +185,10 @@ def preview(self, request): number_of_resource, number_of_tiles = self.get_number_of_deletions(graph_id, nodegroup_id, resourceids) result = { "resource": number_of_resource, "tile": number_of_tiles } + if nodegroup_id: + sample_data = self.get_sample_data(nodegroup_id, resourceids) + result["preview"] = sample_data + return { "success": True, "data": result } def delete(self, request): diff --git a/arches/app/media/js/views/components/etl_modules/bulk-data-deletion.js b/arches/app/media/js/views/components/etl_modules/bulk-data-deletion.js index f8f8f9954f1..573d4f3b527 100644 --- a/arches/app/media/js/views/components/etl_modules/bulk-data-deletion.js +++ b/arches/app/media/js/views/components/etl_modules/bulk-data-deletion.js @@ -37,6 +37,7 @@ define([ this.numberOfResources = ko.observable(); this.numberOfTiles = ko.observable(); this.showPreview = ko.observable(false); + this.previewValue = ko.observable(); this.activeTab = ko.observable("TileDeletion"); this.activeTab.subscribe(() => { @@ -69,6 +70,7 @@ define([ self.submit('preview').then(function(response){ self.numberOfResources(response.result.resource); self.numberOfTiles(response.result.tile); + self.previewValue(response.result.preview); self.showPreview(true); }).fail( function(err) { self.alert( diff --git a/arches/app/templates/javascript.htm b/arches/app/templates/javascript.htm index 9e07c84f17c..493f5a00171 100644 --- a/arches/app/templates/javascript.htm +++ b/arches/app/templates/javascript.htm @@ -780,6 +780,7 @@ delete-resource-count='(resource) => {return {% trans "${resource} resources will be deleted" as deleteResourceCount %} `{{ deleteResourceCount|escapejs }}` }' delete-tiles='{% trans "Delete Tiles" as deleteTiles %} "{{ deleteTiles|escapejs }}"' delete-resources='{% trans "Delete Resources" as deleteResources %} "{{ deleteResources|escapejs }}"' + to-be-deleted-tiles='{% trans "To Be Deleted Tiles" as toBeDeletedTiles %} "{{ toBeDeletedTiles|escapejs }}"' following-resources-be-deleted='{% trans "The following resources will be deleted" as followingResourcesBeDeleted %} "{{ followingResourcesBeDeleted|escapejs }}"' bulk-edit-limit-warning='(limit) => {return {% trans "For safety, only ${limit} bulk edits are allowed at a time. If you need to edit more than ${limit} entries, you will need to perform the operation multiple times." as bulkEditLimitWarning %} `{{ bulkEditLimitWarning|escapejs }}`}' show='{% trans "show" as show %} "{{ show|escapejs }}"' diff --git a/arches/app/templates/views/components/etl_modules/bulk-data-deletion.htm b/arches/app/templates/views/components/etl_modules/bulk-data-deletion.htm index b73f9f7741b..499fa354c98 100644 --- a/arches/app/templates/views/components/etl_modules/bulk-data-deletion.htm +++ b/arches/app/templates/views/components/etl_modules/bulk-data-deletion.htm @@ -111,13 +111,36 @@

- -

+ + +

+ +

+ + +

- +

+ + + + + + + + + + + + + +
+ +
+ - +