Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for 76 search_filters and create_spatial_views sql files #1356

Open
wants to merge 8 commits into
base: 76_upgrade
Choose a base branch
from
4 changes: 4 additions & 0 deletions arches_her/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class Migration(migrations.Migration):
("models", "9945_file_thumbnail_bin_file_thumbnail_text"),
]

run_before = [
("models", "9946_alter_notification_context"),
]

def add_plugins(apps, schema_editor):
Plugin = apps.get_model("models", "Plugin")

Expand Down
170 changes: 170 additions & 0 deletions arches_her/migrations/0002_move_pkg_sql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
from django.db import migrations, models
from django.utils.translation import gettext as _


class Migration(migrations.Migration):

dependencies = [
("arches_her", "0001_initial"),
("models", "11499_add_editlog_resourceinstance_idx")
]

def add_map_layers(apps, schema_editor):
MapLayer = apps.get_model("models", "MapLayer")

# Add/update map layers previously in preliminary_sql/search_overlays.sql
# Previously layers were added using random uuid1, so name is only primary identifier

existing_map = MapLayer.objects.filter(layerdefinitions__contains=[{"source":"search-results-hashes"}])
if not existing_map:
MapLayer.objects.update_or_create(
maplayerid="ede8a6af-110a-4dab-9d0b-f0eccb4cef86",
name="Search Results Heat Map",
layerdefinitions=[
{
"source": "search-results-hashes",
"paint": {
"heatmap-intensity": ["interpolate", ["linear"], ["zoom"], 0, 1, 20, 5],
"heatmap-weight": ["interpolate", ["linear"], ["get", "doc_count"], 0, 0, 6, 1],
"heatmap-color": [
"interpolate",
["linear"],
["heatmap-density"],
0,
"#ffffb2",
0.2,
"#fed976",
0.4,
"#feb24c",
0.6,
"#fd8d3c",
0.8,
"#f03b20",
0.9,
"#fff",
1,
"#bd0026",
],
"heatmap-radius": ["interpolate", ["linear"], ["zoom"], 0, 2, 9, 40, 15, 90, 20, 190],
"heatmap-opacity": 0.6,
},
"minzoom": 9,
"maxzoom": 17,
"type": "heatmap",
"id": "search-results-heat",
}
],
isoverlay=True,
icon="ion-search",
activated=True,
addtomap=False,
searchonly=True,
sortorder=0,
ispublic=True,
)

existing_map = MapLayer.objects.filter(layerdefinitions__contains=[{"source":"search-results-points"}])
if not existing_map:
MapLayer.objects.update_or_create(
maplayerid="77ec30f0-3dda-499a-a126-c67d41f7ba3a",
name="Map Markers",
layerdefinitions=[
{
"layout": {"icon-image": "marker-15", "icon-allow-overlap": True, "icon-offset": [0, -6], "icon-size": 1},
"source": "search-results-points",
"filter": ["all", ["==", "$type", "Point"], ["!=", "highlight", True]],
"paint": {},
"type": "symbol",
"id": "search-results-points-markers",
},
{
"layout": {"icon-image": "marker-15", "icon-allow-overlap": True, "icon-offset": [0, -6], "icon-size": 1.3},
"source": "search-results-points",
"filter": ["all", ["==", "$type", "Point"], ["==", "highlight", True]],
"paint": {},
"type": "symbol",
"id": "search-results-points-markers-highlighted",
},
{
"layout": {"visibility": "visible"},
"source": "search-results-points",
"filter": ["all", ["==", "$type", "Point"], ["==", "highlight", True]],
"paint": {"circle-translate": [0, -25], "circle-color": "rgba(0,0,0,0)", "circle-radius": 16},
"type": "circle",
"id": "search-results-points-markers-point-highlighted",
},
{
"layout": {"visibility": "visible"},
"source": "search-results-points",
"filter": ["all", ["==", "$type", "Point"]],
"paint": {"circle-translate": [0, -16], "circle-color": "rgba(0,0,0,0)", "circle-radius": 11},
"type": "circle",
"id": "search-results-points-markers-point",
},
],
isoverlay=True,
icon="ion-location",
activated=True,
addtomap=True,
searchonly=True,
sortorder=0,
ispublic=True,
)

existing_map = MapLayer.objects.filter(layerdefinitions__contains=[{"source":"search-results-hex"}])
if not existing_map:
MapLayer.objects.update_or_create(
maplayerid="604bd229-85ca-42db-a7ef-eb2ed81e8537",
name="Hex",
layerdefinitions=[
{
"layout": {},
"source": "search-results-hex",
"filter": ["==", "id", ""],
"paint": {
"fill-extrusion-color": "#54278f",
"fill-extrusion-height": {"property": "doc_count", "type": "exponential", "stops": [[0, 0], [500, 5000]]},
"fill-extrusion-opacity": 0.85,
},
"type": "fill-extrusion",
"id": "search-results-hex-outline-highlighted",
},
{
"layout": {},
"source": "search-results-hex",
"filter": ["all", [">", "doc_count", 0]],
"paint": {
"fill-extrusion-color": {
"property": "doc_count",
"stops": [[1, "#f2f0f7"], [5, "#cbc9e2"], [10, "#9e9ac8"], [20, "#756bb1"], [50, "#54278f"]],
},
"fill-extrusion-height": {"property": "doc_count", "type": "exponential", "stops": [[0, 0], [500, 5000]]},
"fill-extrusion-opacity": 0.5,
},
"type": "fill-extrusion",
"id": "search-results-hex",
},
],
isoverlay=True,
icon="ion-funnel",
activated=True,
addtomap=False,
searchonly=True,
sortorder=0,
ispublic=True,
)

def remove_map_layers(apps, schema_editor):
MapLayer = apps.get_model("models", "MapLayer")

for map_layers in MapLayer.objects.filter(name__in=[
"Search Results Heat Map",
"Map Markers",
"Hex"
]):
map_layers.delete()


operations = [
migrations.RunPython(add_map_layers, remove_map_layers),
]
72 changes: 72 additions & 0 deletions arches_her/migrations/0003_add_bng_search_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from django.db import migrations, models
from django.utils.translation import gettext as _


class Migration(migrations.Migration):

dependencies = [
("arches_her", "0002_move_pkg_sql")
]

def add_bng_component_to_search_view(apps, scheme_editor):
SearchComponent = apps.get_model("models", "SearchComponent")

standard_search_view = SearchComponent.objects.get(searchcomponentid="69695d63-6f03-4536-8da9-841b07116381")
standard_search_view.config["linkedSearchFilters"].append(
{
"componentname": "bng-filter",
"layoutSortorder": 1,
"searchcomponentid": "25ca3536-9eb4-4fd5-b2a5-badfd9a266de"
}
)
standard_search_view.save()

def remove_bng_component_from_search_view(apps, scheme_editor):
SearchComponent = apps.get_model("models", "SearchComponent")

standard_search_view = SearchComponent.objects.get(searchcomponentid="69695d63-6f03-4536-8da9-841b07116381")
for search_filter in standard_search_view.config["linkedSearchFilters"]:
if search_filter["searchcomponentid"] == "25ca3536-9eb4-4fd5-b2a5-badfd9a266de":
standard_search_view.config["linkedSearchFilters"].remove(search_filter)
standard_search_view.save()


def apply_bng_layout_type(apps, scheme_editor):
SearchComponent = apps.get_model("models", "SearchComponent")

SearchComponent.objects.update_or_create(
searchcomponentid="25ca3536-9eb4-4fd5-b2a5-badfd9a266de",
name="BNG Filter",
icon="fa fa-compass",
modulename="bng-filter.py",
classname="BngFilter",
componentpath="views/components/search/bng-filter",
componentname="bng-filter",
defaults={
"config":{"layoutType": "popup"}, # add previous layout type into new config
"type":"bng-filter-type" # previously "popup" which has now moved
}
)

def revert_bng_layout_type(apps, scheme_editor):
SearchComponent = apps.get_model("models", "SearchComponent")

# Revert BNG search component to how it used to be
SearchComponent.objects.update_or_create(
searchcomponentid="25ca3536-9eb4-4fd5-b2a5-badfd9a266de",
name="BNG Filter",
icon="fa fa-compass",
modulename="bng-filter.py",
classname="BngFilter",
componentpath="views/components/search/bng-filter",
componentname="bng-filter",
defaults={
"config":{},
"type":"popup"
}
)

operations = [
migrations.RunPython(add_bng_component_to_search_view, remove_bng_component_from_search_view),
migrations.RunPython(apply_bng_layout_type, revert_bng_layout_type)
]
Loading
Loading