From 2328043c3701a8d20b301052dbd4644c8d916372 Mon Sep 17 00:00:00 2001 From: njkim Date: Tue, 24 Oct 2023 20:19:59 -0700 Subject: [PATCH] Confirm deletion tile/resource and count, #10186 --- arches/app/etl_modules/bulk_data_deletion.py | 54 ++++++++++++++++ .../etl_modules/bulk-data-deletion.js | 30 +++++++++ arches/app/templates/javascript.htm | 3 + .../etl_modules/bulk-data-deletion.htm | 61 +++++++++++++------ 4 files changed, 131 insertions(+), 17 deletions(-) diff --git a/arches/app/etl_modules/bulk_data_deletion.py b/arches/app/etl_modules/bulk_data_deletion.py index 0f50548bb94..91271a19832 100644 --- a/arches/app/etl_modules/bulk_data_deletion.py +++ b/arches/app/etl_modules/bulk_data_deletion.py @@ -18,6 +18,42 @@ class BulkDataDeletion(BaseBulkEditor): + def get_number_of_deletions(self, graph_id, nodegroup_id, resourceids): + resourceids_query = "AND resourceinstanceid IN %(resourceids)s" if resourceids else "" + params = { + "nodegroup_id": nodegroup_id, + "graph_id": graph_id, + "resourceids": resourceids, + } + + tile_deletion_count = """ + SELECT COUNT(DISTINCT resourceinstanceid), COUNT(tileid) + FROM tiles + WHERE nodegroupid = %(nodegroup_id)s + """ + resourceids_query + + resource_deletion_count = """ + SELECT COUNT(resourceinstanceid) + FROM resource_instances + WHERE graphid = %(graph_id)s; + """ + + if nodegroup_id: + with connection.cursor() as cursor: + cursor.execute(tile_deletion_count, params) + row = cursor.fetchone() + print(row) + number_of_resource, number_of_tiles = row + + elif not resourceids: + with connection.cursor() as cursor: + cursor.execute(resource_deletion_count, params) + row = cursor.fetchone() + number_of_resource, = row + number_of_tiles = 0 + + return number_of_resource, number_of_tiles + def delete_resources(self, userid, loadid, graphid, resourceids): result = {"success": False} user = User.objects.get(id=userid) @@ -76,6 +112,24 @@ def index_resource_deletion(self, loadid, resourceids): def index_tile_deletion(self, loadid): index_resources_by_transaction(loadid, quiet=True, use_multiprocessing=False, recalculate_descriptors=True) + def count(self, request): + graph_id = request.POST.get("graph_id", None) + nodegroup_id = request.POST.get("nodegroup_id", None) + resourceids = request.POST.get("resourceids", None) + search_url = request.POST.get("search_url", None) + + if resourceids: + resourceids = json.loads(resourceids) + if search_url: + resourceids = self.get_resourceids_from_search_url(search_url) + if resourceids: + resourceids = tuple(resourceids) + + 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 } + + return { "success": True, "data": result } + def write(self, request): graph_id = request.POST.get("graph_id", None) graph_name = request.POST.get("graph_name", None) 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 b4434e2d9bc..63c44deff4f 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 @@ -45,6 +45,24 @@ define([ this.loadId = params.loadId || uuid.generate(); this.resourceids = ko.observable(); this.searchUrl = ko.observable(); + this.deleteTiles = ko.observable(false); + this.counting = ko.observable(false); + this.numberOfResources = ko.observable(); + this.numberOfTiles = ko.observable(); + this.showCount = ko.observable(false); + + this.deleteTiles.subscribe((val) => { + if (!val){ + self.selectedNodegroup(null); + } + }); + + this.ready = ko.computed(()=>{ + self.showCount(false); + self.numberOfResources(null); + self.numberOfTiles(null); + return (self.searchUrl() && !self.deleteTiles()) || (self.selectedGraph() && !self.deleteTiles()) || (self.selectedNodegroup() && self.deleteTiles()); + }); this.getGraphs = function(){ self.loading(true); @@ -54,6 +72,18 @@ define([ }); }; + this.count = function(){ + self.counting(true); + self.showCount(false); + this.addAllFormData(); + self.submit('count').then(function(response){ + self.numberOfResources(response.result.resource); + self.numberOfTiles(response.result.tile); + self.counting(false); + self.showCount(true); + }); + }; + this.getGraphName = function(graphId){ let graph; if (self.graphs()) { diff --git a/arches/app/templates/javascript.htm b/arches/app/templates/javascript.htm index b29ecbd8c26..84be40d1417 100644 --- a/arches/app/templates/javascript.htm +++ b/arches/app/templates/javascript.htm @@ -749,6 +749,7 @@ filter-tasks='{% trans "Filter Tasks" as filterTasks %} "{{ filterTasks|escapejs }}"' filter-modules='{% trans "Filter Modules" as filterModules %} "{{ filterModules|escapejs }}"' start='{% trans "Start" as start %} "{{ start|escapejs }}"' + count='{% trans "Count" as count %} "{{ count|escapejs }}"' warning='{% trans "Warning" as warning %} "{{ warning|escapejs }}"' etl-reverse-warning-message='{% trans "Are you sure you want to delete this load?" as etlReverseWarningMessage %} "{{ etlReverseWarningMessage|escapejs }}"' undo-import='{% trans "undo" as undoImport %} "{{ undoImport|escapejs }}"' @@ -775,6 +776,8 @@ count-of-tiles-updated='(count) => {return {% trans "Tiles updated: ${count}" as countOfTilesUpdated %} `{{ countOfTilesUpdated|escapejs }}` }' count-of-resources-deleted='(count) => {return {% trans "Resources deleted: ${count}" as countOfResourcesDeleted %} `{{ countOfResourcesDeleted|escapejs }}` }' count-of-tiles-deleted='(count) => {return {% trans "Tiles deleted: ${count}" as countOfTilesDeleted %} `{{ countOfTilesDeleted|escapejs }}` }' + delete-tile-count='(tile, resource) => {return {% trans "${tile} tiles from ${resource} resources will be deleted" as deleteTileCount %} `{{ deleteTileCount|escapejs }}` }' + delete-resource-count='(resource) => {return {% trans "${resource} resources will be deleted" as deleteResourceCount %} `{{ deleteResourceCount|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 }}"' hide='{% trans "hide" as hide %} "{{ hide|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 e6d4cf0fddf..3673865f488 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 @@ -11,6 +11,15 @@

{% blocktrans %}Delete The Selected Resources or Tiles{% endblocktrans %}

+
+ {% trans "Delete Resources" %} + + {% trans "Delete Tiles" %} +
@@ -37,7 +46,7 @@

>

- +

@@ -54,26 +63,44 @@

-

- - {% blocktrans %}This selection will delete the resource instances from search url{% endblocktrans %} - - - {% blocktrans %}This selection will delete the resource instances from search url and the selected resource model{% endblocktrans %} - - - {% blocktrans %}This selection will delete the tiles in the selected nodegroup from search url{% endblocktrans %} +

+

+ + {% blocktrans %}This selection will delete the resource instances from search url{% endblocktrans %} + + + {% blocktrans %}This selection will delete the resource instances from search url and the selected resource model{% endblocktrans %} + + + {% blocktrans %}This selection will delete the tiles in the selected nodegroup from search url{% endblocktrans %} + + + {% blocktrans %}This selection will delete all the resource instances from the selected resource model{% endblocktrans %} + + + {% blocktrans %}This selection will delete the tiles in the selected nodegroup{% endblocktrans %} + +

+ +

+ + +

- - {% blocktrans %}This selection will delete all the resource instances from the selected resource model{% endblocktrans %} + +

+ + +

- - {% blocktrans %}This selection will delete the tiles in the selected nodegroup{% endblocktrans %} - -

+ +