From ccca39f910a0859de43fcb7d7480acf835de16b1 Mon Sep 17 00:00:00 2001 From: rb28z2 Date: Fri, 29 Oct 2021 02:15:08 +0000 Subject: [PATCH 1/4] add edit button --- instances/templates/instances/instances.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instances/templates/instances/instances.html b/instances/templates/instances/instances.html index 93fc5453..b53a84ca 100644 --- a/instances/templates/instances/instances.html +++ b/instances/templates/instances/instances.html @@ -90,6 +90,8 @@
Server instances

+ + {% endif %} From c459783f5aa964a4be9966eb82f246482653672f Mon Sep 17 00:00:00 2001 From: rb28z2 Date: Fri, 29 Oct 2021 02:20:36 +0000 Subject: [PATCH 2/4] re-populates the form with data pulled from the config belonging to instance being edited. currently does nothing with it --- .../templates/instances/instance_form.html | 37 ++++++++++++++ instances/templates/instances/instances.html | 49 +++++-------------- instances/urls.py | 1 + instances/views.py | 23 +++++++++ 4 files changed, 73 insertions(+), 37 deletions(-) create mode 100644 instances/templates/instances/instance_form.html diff --git a/instances/templates/instances/instance_form.html b/instances/templates/instances/instance_form.html new file mode 100644 index 00000000..1581245b --- /dev/null +++ b/instances/templates/instances/instance_form.html @@ -0,0 +1,37 @@ +
+ {% load material_form %} +
Instance config
+
{% csrf_token %} + {% form form=form %}{% endform %} +
    +
  • +
    Settings
    +
    + {% form form=form.settings %}{% endform %} +
    +
  • +
  • +
    Configuration
    +
    + {% form form=form.configuration %}{% endform %} +
    +
  • +
  • +
    AssistRules
    +
    + {% form form=form.assistRules %}{% endform %} +
    +
  • +
  • +
    EventRules
    +
    + {% form form=form.eventRules %}{% endform %} +
    +
  • +
+ + + +
+
\ No newline at end of file diff --git a/instances/templates/instances/instances.html b/instances/templates/instances/instances.html index b53a84ca..734dc30d 100644 --- a/instances/templates/instances/instances.html +++ b/instances/templates/instances/instances.html @@ -21,44 +21,8 @@ {% endfor %} {% endif %} -
- {% load material_form %} -
Instance config
-
{% csrf_token %} - {% form form=form %}{% endform %} -
    -
  • -
    Settings
    -
    - {% form form=form.settings %}{% endform %} -
    -
  • -
  • -
    Configuration
    -
    - {% form form=form.configuration %}{% endform %} -
    -
  • -
  • -
    AssistRules
    -
    - {% form form=form.assistRules %}{% endform %} -
    -
  • -
  • -
    EventRules
    -
    - {% form form=form.eventRules %}{% endform %} -
    -
  • -
- - - -
+ {% include "instances/instance_form.html" %} -
@@ -136,5 +100,16 @@
Server instances

$('tr#row'+el.id.replace('delete','')).remove(); }); } + function edit(el, name) { + //el.disabled = true; + $.post("/instances/"+name+"/edit", function(html) { + $('div#config_card').replaceWith(html); + $('button#create_instance').text('Save Changes') + $('.collapsible').collapsible(); + $('form[name=instance_form]').attr('action', 'edit_instance') + + }) + + } {% endblock %} diff --git a/instances/urls.py b/instances/urls.py index c52478f5..f8dc9d5f 100644 --- a/instances/urls.py +++ b/instances/urls.py @@ -9,6 +9,7 @@ path('/start', views.start, name='start'), path('/stop', views.stop, name='stop'), path('/delete', views.delete, name='delete'), + path('/edit', views.edit, name='edit'), path('/stderr', views.stderr, name='stderr'), path('/stdout', views.stdout, name='stdout'), path('/serverlog', views.serverlog, name='serverlog'), diff --git a/instances/views.py b/instances/views.py index 7c051086..28366b65 100644 --- a/instances/views.py +++ b/instances/views.py @@ -196,6 +196,14 @@ def render_from(request, form): } return HttpResponse(template.render(context, request)) +#TODO: change name to better suit this +def render_settings(request, form): + template = loader.get_template('instances/instance_form.html') + context = { + 'form': form, + 'executors': executors + } + return HttpResponse(template.render(context, request)) def write_config(name, inst_dir, form): ### use the values of the default *.json as basis @@ -325,3 +333,18 @@ def index(request): return render_from(request, InstanceForm(cfg)) +@login_required +def edit(request, name): + + cfg = json.load(open(os.path.join( + settings.DATA_DIR, 'instances', name, 'cfg', 'configuration.json'), 'r', encoding='utf-16' + )) + cfg.update(json.load(open(os.path.join( + settings.DATA_DIR, 'instances', name, 'cfg', 'settings.json'), 'r', encoding='utf-16'))) + cfg.update(json.load(open(os.path.join( + settings.DATA_DIR, 'instances', name, 'cfg', 'assistRules.json'), 'r', encoding='utf-16'))) + cfg.update(json.load(open(os.path.join( + settings.DATA_DIR, 'instances', name, 'cfg', 'eventRules.json'), 'r', encoding='utf-16'))) + + cfg['instanceName'] = name + return render_settings(request, InstanceForm(cfg)) From b9a37d3426e21b31584d30e35b4558879d7dc695 Mon Sep 17 00:00:00 2001 From: rb28z2 Date: Fri, 29 Oct 2021 02:22:59 +0000 Subject: [PATCH 3/4] setup methods to overwrite / save changes --- instances/urls.py | 3 ++- instances/views.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/instances/urls.py b/instances/urls.py index f8dc9d5f..fa2b5f93 100644 --- a/instances/urls.py +++ b/instances/urls.py @@ -5,7 +5,8 @@ urlpatterns = [ path('', views.index, name='instances'), path('start', views.create, name='start'), - path('/', views.instance, name='instance'), + path('edit_instance', views.edit_instance, name='edit_instance'), + path('/', views.instance, name='instance'), path('/start', views.start, name='start'), path('/stop', views.stop, name='stop'), path('/delete', views.delete, name='delete'), diff --git a/instances/views.py b/instances/views.py index 28366b65..ac59e1d2 100644 --- a/instances/views.py +++ b/instances/views.py @@ -348,3 +348,7 @@ def edit(request, name): cfg['instanceName'] = name return render_settings(request, InstanceForm(cfg)) + +@login_required +def edit_instance(request, name): + pass \ No newline at end of file From 2763fa86aed358f61fd8b16eeb087b325f4b685e Mon Sep 17 00:00:00 2001 From: rb28z2 Date: Fri, 29 Oct 2021 02:25:06 +0000 Subject: [PATCH 4/4] add todo --- instances/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instances/views.py b/instances/views.py index ac59e1d2..15c0a356 100644 --- a/instances/views.py +++ b/instances/views.py @@ -299,7 +299,7 @@ def random_word(): return s -def index(request): +def index(request, name=None): # read defaults from files cfg = json.load(open(os.path.join( settings.ACCSERVER, 'cfg', 'configuration.json'), 'r', encoding='utf-16')) @@ -351,4 +351,5 @@ def edit(request, name): @login_required def edit_instance(request, name): + #TODO: basic methodology - validate config, stop running instance, unlink/delete exiting config dirs, call create method, restart server pass \ No newline at end of file