-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
* remove previous useless assets for every build * reproduce instances data to easily test it on Vite * add instances page to build * update instances builder to fit new components : list pairs and form data * form submit working on instances actions
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"type": "card", "containerColumns": {"pc": 6, "tablet": 6, "mobile": 12}, "widgets": [{"type": "Instance", "data": {"pairs": [{"key": "instances_hostname", "value": "bunkerweb"}, {"key": "instances_type", "value": "manual"}, {"key": "instances_status", "value": "instances_active"}], "status": "success", "title": "bunkerweb", "buttons": [{"attrs": {"data-submit-form": "{\"INSTANCE_ID\" : \"bunkerweb\", \"operation\" : \"reload\" }"}, "text": "action_reload", "color": "warning"}, {"attrs": {"data-submit-form": "{\"INSTANCE_ID\" : \"bunkerweb\", \"operation\" : \"stop\" }"}, "text": "action_stop", "color": "error"}]}}]}, {"type": "card", "containerColumns": {"pc": 6, "tablet": 6, "mobile": 12}, "widgets": [{"type": "Instance", "data": {"pairs": [{"key": "instances_hostname", "value": "bunkerweb"}, {"key": "instances_type", "value": "manual"}, {"key": "instances_status", "value": "instances_active"}], "status": "success", "title": "bunkerweb", "buttons": [{"attrs": {"data-submit-form": "{\"INSTANCE_ID\" : \"bunkerweb\", \"operation\" : \"reload\" }"}, "text": "action_reload", "color": "warning"}, {"attrs": {"data-submit-form": "{\"INSTANCE_ID\" : \"bunkerweb\", \"operation\" : \"stop\" }"}, "text": "action_stop", "color": "error"}]}}]}] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import json | ||
|
||
|
||
# Create instance class using keys from the instances list | ||
class Instance: | ||
def __init__(self, _type, health, _id, hostname, name): | ||
self._type = _type | ||
self.health = health | ||
self._id = _id | ||
self.hostname = hostname | ||
self.name = name | ||
|
||
|
||
instances = [ | ||
Instance("manual", True, "bunkerweb", "bunkerweb", "bunkerweb"), | ||
Instance("manual", True, "bunkerweb", "bunkerweb", "bunkerweb"), | ||
] | ||
|
||
|
||
def instances_builder(instances: list): | ||
""" | ||
It returns the home page in JSON format for the Vue.js builder | ||
""" | ||
builder = [] | ||
|
||
for instance in instances: | ||
# setup actions buttons | ||
actions = ( | ||
["restart", "stop"] | ||
if instance._type == "local" and instance.health | ||
else ( | ||
["reload", "stop"] | ||
if not instance._type == "local" and instance.health | ||
else ["start"] if instance._type == "local" and not instance.health else [] | ||
) | ||
) | ||
buttons = [ | ||
{ | ||
"attrs": { | ||
"data-submit-form": f"""{{"INSTANCE_ID" : "{instance._id}", "operation" : "{action}" }}""", | ||
}, | ||
"text": f"action_{action}", | ||
"color": "success" if action == "start" else "error" if action == "stop" else "warning", | ||
} | ||
for action in actions | ||
] | ||
|
||
component = { | ||
"type": "card", | ||
"containerColumns": {"pc": 6, "tablet": 6, "mobile": 12}, | ||
"widgets": [ | ||
{ | ||
"type": "Instance", | ||
"data": { | ||
"pairs": [ | ||
{"key": "instances_hostname", "value": instance.hostname}, | ||
{"key": "instances_type", "value": instance._type}, | ||
{"key": "instances_status", "value": "instances_active" if instance.health else "instances_inactive"}, | ||
], | ||
"status": "success" if instance.health else "error", | ||
"title": instance.name, | ||
"buttons": buttons, | ||
}, | ||
} | ||
], | ||
} | ||
|
||
builder.append(component) | ||
|
||
return builder | ||
|
||
|
||
builder = instances_builder(instances) | ||
|
||
# store on a file | ||
with open("instances.json", "w") as f: | ||
json.dump(builder, f) |
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.