Skip to content

Commit

Permalink
Shoe tiledata as preview, #10186
Browse files Browse the repository at this point in the history
  • Loading branch information
njkim committed Oct 27, 2023
1 parent c0af038 commit 70e38f7
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
47 changes: 43 additions & 4 deletions arches/app/etl_modules/bulk_data_deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions arches/app/templates/javascript.htm
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,36 @@ <h3>
<span data-bind="text: $root.translations.preview"></span>
<i class="fa fa-spin fa-spinner" data-bind="visible: previewing()"></i>
</button>
<!-- ko if: showPreview() && activeTab() === "TilesDeletion" -->
<p>
<!-- ko if: showPreview() && activeTab() === "TileDeletion" -->
<!-- ko if: numberOfTiles() === 0 -->
<h3 style="margin-top: 0px;">
<span style="margin: 2px;" class="fa fa-info-circle"></span><span data-bind="text: $root.translations.noDataToPreview"></span>
</h3>
<!-- /ko -->
<!-- ko if: numberOfTiles() > 0 -->
<p style="margin-top: 15px;">
<i class="fa fa-info-circle"></i>
<span data-bind="text: $root.translations.deleteTileCount(numberOfTiles(),numberOfResources())"></span>
<span data-bind="text: $root.translations.previewCountStats(5,numberOfTiles(),numberOfResources())"></span>
</p>
<table class="table table-striped csv-mapping-table">
<thead>
<tr>
<th style="border-bottom: 1px solid #ddd; vertical-align: top;">
<span data-bind="text: $root.translations.toBeDeletedTiles"></span>
</th>
</tr>
</thead>
<tbody>
<!-- ko foreach: { data: previewValue(), as: "value" } -->
<tr>
<td style="vertical-align: text-top;" data-bind="text: value"></td>
</tr>
<!-- /ko -->
</tbody>
</table>
<!-- /ko -->
<!-- /ko -->
<!-- ko if: showPreview() && activeTab() !== "TilesDeletion" -->
<!-- ko if: showPreview() && activeTab() !== "TileDeletion" -->
<p style="margin-top: 15px;" >
<i class="fa fa-info-circle"></i>
<span data-bind="text: $root.translations.followingResourcesBeDeleted"></span>
Expand Down

0 comments on commit 70e38f7

Please sign in to comment.