Skip to content

Commit

Permalink
Confirm deletion tile/resource and count, #10186
Browse files Browse the repository at this point in the history
  • Loading branch information
njkim committed Oct 25, 2023
1 parent 4547d12 commit 2328043
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 17 deletions.
54 changes: 54 additions & 0 deletions arches/app/etl_modules/bulk_data_deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()) {
Expand Down
3 changes: 3 additions & 0 deletions arches/app/templates/javascript.htm
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"'
Expand All @@ -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 }}"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ <h2>
<p class="pad-btm">
{% blocktrans %}Delete The Selected Resources or Tiles{% endblocktrans %}
</p>
<div class="form-group">
<span class="control-label">{% trans "Delete Resources" %}</span>
<span class="switch switch-small" tabindex="0" role="switch"
data-bind="
css: {'on': deleteTiles()},
click: function(){deleteTiles(!deleteTiles())}
"><small></small></span>
<span class="control-label">{% trans "Delete Tiles" %}</span>
</div>

<section class="etl-module-component">
<div class="etl-module-component-block">
Expand All @@ -37,7 +46,7 @@ <h3>
></select>
</div>

<!-- ko if: nodegroups() -->
<!-- ko if: nodegroups() && deleteTiles() -->
<div class="etl-module-component-block">
<h3>
<label for="node-select" data-bind="text: $root.translations.selectANodegroup"></label>
Expand All @@ -54,26 +63,44 @@ <h3>
</div>
<!-- /ko -->
</section>
<p class="pad-btm">
<!-- ko if: searchUrl() && !selectedGraph() && !selectedNodegroup() -->
{% blocktrans %}This selection will delete the resource instances from search url{% endblocktrans %}
<!-- /ko -->
<!-- ko if: searchUrl() && selectedGraph() && !selectedNodegroup() -->
{% blocktrans %}This selection will delete the resource instances from search url and the selected resource model{% endblocktrans %}
<!-- /ko -->
<!-- ko if: searchUrl() && selectedNodegroup() -->
{% blocktrans %}This selection will delete the tiles in the selected nodegroup from search url{% endblocktrans %}
<div class="etl-module-component-block">
<p class="pad-btm">
<!-- ko if: searchUrl() && !selectedGraph() && !selectedNodegroup() -->
{% blocktrans %}This selection will delete the resource instances from search url{% endblocktrans %}
<!-- /ko -->
<!-- ko if: searchUrl() && selectedGraph() && !selectedNodegroup() -->
{% blocktrans %}This selection will delete the resource instances from search url and the selected resource model{% endblocktrans %}
<!-- /ko -->
<!-- ko if: searchUrl() && selectedNodegroup() -->
{% blocktrans %}This selection will delete the tiles in the selected nodegroup from search url{% endblocktrans %}
<!-- /ko -->
<!-- ko if: !searchUrl() && selectedGraph() && !selectedNodegroup() -->
{% blocktrans %}This selection will delete all the resource instances from the selected resource model{% endblocktrans %}
<!-- /ko -->
<!-- ko if: !searchUrl() && selectedNodegroup() -->
{% blocktrans %}This selection will delete the tiles in the selected nodegroup{% endblocktrans %}
<!-- /ko -->
</p>
<!-- ko if: showCount() && deleteTiles() -->
<p>
<i class="fa fa-info-circle"></i>
<span data-bind="text: $root.translations.deleteTileCount(numberOfTiles(),numberOfResources())"></span>
</p>
<!-- /ko -->
<!-- ko if: !searchUrl() && selectedGraph() && !selectedNodegroup() -->
{% blocktrans %}This selection will delete all the resource instances from the selected resource model{% endblocktrans %}
<!-- ko if: showCount() && !deleteTiles() -->
<p>
<i class="fa fa-info-circle"></i>
<span data-bind="text: $root.translations.deleteResourceCount(numberOfResources())"></span>
</p>
<!-- /ko -->
<!-- ko if: !searchUrl() && selectedNodegroup() -->
{% blocktrans %}This selection will delete the tiles in the selected nodegroup{% endblocktrans %}
<!-- /ko -->
</p>
<button data-bind="click: count, attr: {disabled: !ready()}" class="btn btn-success">
<span data-bind="text: $root.translations.count"></span>
<i class="fa fa-spin fa-spinner" data-bind="visible: counting()"></i>
</button>
</div>
</div>
<div class="tabbed-workflow-footer, etl-module-footer">
<button style="margin-right: 8px;" data-bind="click: write" class="btn btn-success">
<button style="margin-right: 8px;" data-bind="click: count, attr: {disabled: !ready()}" class="btn btn-success">
<span data-bind="text: $root.translations.start"></span>
</button>
</div>
Expand Down

0 comments on commit 2328043

Please sign in to comment.