Skip to content

Commit

Permalink
Merge pull request #10181 from archesproject/10176-default-value-file…
Browse files Browse the repository at this point in the history
…-list

Add `defaultValue` to file-widget default config
  • Loading branch information
chiatt authored Oct 24, 2023
2 parents d1f0357 + 360ffb6 commit 0fb58e8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion arches/app/media/js/viewmodels/file-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define([
'bindings/dropzone'
], function($, ko, _, arches, Dropzone, uuid, WidgetViewModel) {
/**
* A viewmodel used for domain widgets
* A viewmodel used for file widgets
*
* @constructor
* @name FileWidgetViewModel
Expand Down
52 changes: 52 additions & 0 deletions arches/app/models/migrations/10150_add_default_value_file_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 4.2.4 on 2023-10-23 13:50

from django.db import migrations

from arches.app.models.graph import Graph


def using_custom_file_widgets(apps, schema_editor):
CardXNodeXWidget = apps.get_model("models", "CardXNodeXWidget")
return (
CardXNodeXWidget.objects.filter(widget_id="10000000-0000-0000-0000-000000000019").values_list("node__graph", flat=True).distinct()
)


def publish_graph(apps, schema_editor):
for graph in Graph.objects.filter(pk__in=using_custom_file_widgets(apps, schema_editor)):
graph.publish(user=None)


def unpublish_graph(apps, schema_editor):
for graph in Graph.objects.filter(pk__in=using_custom_file_widgets(apps, schema_editor)):
graph.unpublish()


class Migration(migrations.Migration):
dependencies = [
("models", "10149_add_workflow_name_to_workflow_history"),
]

operations = [
# Changes to cards_x_nodes_x_widgets have no effect without republishing graph.
migrations.RunPython(unpublish_graph, publish_graph),
migrations.RunSQL(
sql="""
UPDATE widgets
SET defaultconfig = jsonb_set(defaultconfig, '{defaultValue}', '[]')
WHERE name = 'file-widget';
UPDATE cards_x_nodes_x_widgets
SET config = jsonb_set(config, '{defaultValue}', '[]')
WHERE widgetid = '10000000-0000-0000-0000-000000000019';
""",
reverse_sql="""
UPDATE widgets
SET defaultconfig = defaultconfig - 'defaultValue'
WHERE name = 'file-widget';
UPDATE cards_x_nodes_x_widgets
SET config = config - 'defaultValue'
WHERE widgetid = '10000000-0000-0000-0000-000000000019';
""",
),
migrations.RunPython(publish_graph, unpublish_graph),
]

0 comments on commit 0fb58e8

Please sign in to comment.