summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Hernandez <jhernandez@soleta.eu>2024-01-10 11:23:36 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-01-10 11:31:08 +0100
commit695fcfe6255fd53b19b416e8375b48d2dc5595e4 (patch)
tree72927876587a1ca19b2e8cc6172346fa133ceb96
parent58b5b2eca00acc14510dbf2c741f12d7e799a264 (diff)
src: Add support for adding folders
Add support to create a folder able to contain multiple computers. Add support for adding a folder able to contain rooms
-rw-r--r--ogcp/forms/action_forms.py7
-rw-r--r--ogcp/templates/actions/folder_add.html19
-rw-r--r--ogcp/templates/scopes.html11
-rw-r--r--ogcp/views.py41
4 files changed, 77 insertions, 1 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index 64b292a..9110913 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -105,6 +105,13 @@ class RepoForm(FlaskForm):
ip = StringField(label=_l('IP'))
submit = SubmitField(label=_l('Submit'))
+class FolderForm(FlaskForm):
+ server = HiddenField()
+ room = HiddenField()
+ center = HiddenField()
+ name = StringField(label=_l('Name'))
+ submit = SubmitField(label=_l('Submit'))
+
class ClientDetailsForm(FlaskForm):
server = HiddenField()
name = StringField(label=_l('Name'))
diff --git a/ogcp/templates/actions/folder_add.html b/ogcp/templates/actions/folder_add.html
new file mode 100644
index 0000000..70f7e57
--- /dev/null
+++ b/ogcp/templates/actions/folder_add.html
@@ -0,0 +1,19 @@
+{% extends 'scopes.html' %}
+{% import "bootstrap/wtf.html" as wtf %}
+
+{% set sidebar_state = 'disabled' %}
+{% set btn_back = true %}
+
+{% block nav_folder %} active{% endblock %}
+{% block nav_folder_add %} active{% endblock %}
+{% block content %}
+
+<h1 class="m-5">{{_('Add folder')}}</h1>
+
+{{ wtf.quick_form(form,
+ method='post',
+ button_map={'submit': 'primary'},
+ extra_classes="mx-5") }}
+
+{% endblock %}
+
diff --git a/ogcp/templates/scopes.html b/ogcp/templates/scopes.html
index 8a0701f..ecc8433 100644
--- a/ogcp/templates/scopes.html
+++ b/ogcp/templates/scopes.html
@@ -56,6 +56,17 @@
form="scopesForm" formaction="{{ url_for('action_center_delete') }}" formmethod="get">
</div>
</div>
+
+ <div class="dropdown btn">
+ <button class="btn btn-secondary btn-light dropdown-toggle {% block nav_folder %}{% endblock %}" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-expanded="false">
+ {{ _('Folder') }}
+ </button>
+ <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
+ <input class="btn btn-light dropdown-item {% block nav_folder_add %}{% endblock %}" type="submit" value="{{ _('Add folder') }}"
+ form="scopesForm" formaction="{{ url_for('action_folder_add') }}" formmethod="get">
+ </div>
+ </div>
+
{% endif %}
{% if btn_back %}
<button class="btn btn-danger ml-3" type="button" id="backButton" onclick="history.back()">
diff --git a/ogcp/views.py b/ogcp/views.py
index b124287..bd179cd 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -13,7 +13,7 @@ from ogcp.forms.action_forms import (
SessionForm, ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm,
RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm, OgliveForm,
GenericForm, SelectClientForm, ImageUpdateForm, ImportClientsForm,
- ServerForm, DeleteRepositoryForm, RepoForm
+ ServerForm, DeleteRepositoryForm, RepoForm, FolderForm
)
from flask_login import (
current_user, LoginManager,
@@ -990,6 +990,45 @@ def action_client_update():
return render_template('actions/client_details.html', form=form,
parent="scopes.html", scopes=scopes)
+@app.route('/action/folder/add', methods=['GET'])
+@login_required
+def action_folder_add():
+ form = FolderForm()
+ params = request.args.to_dict()
+ room = params.get('scope-room')
+ center = params.get('scope-center')
+ if room and center:
+ flash(_('Please, select either a room or a center'), category='error')
+ return redirect(url_for('scopes'))
+ if not room and not center:
+ flash(_('Please, select a room or a center'), category='error')
+ return redirect(url_for('scopes'))
+ form.server.data = params['scope-server']
+ form.room.data = room
+ form.center.data = center
+ form.submit.render_kw = {"formaction": url_for('action_folder_add_post')}
+ scopes, _ = get_scopes()
+ return render_template('actions/folder_add.html', form=form,
+ parent="scopes.html", scopes=scopes)
+
+@app.route('/action/folder/add', methods=['POST'])
+def action_folder_add_post():
+ form = FolderForm(request.form)
+ payload = {"name": form.name.data}
+ if form.center.data:
+ payload["center"] = int(form.center.data)
+ if form.room.data:
+ payload["room"] = int(form.room.data)
+
+ server = get_server_from_ip_port(form.server.data)
+ r = server.post('/folder/add', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('ogServer: error adding folder'),
+ category='error')
+ else:
+ flash(_('Folder added successfully'), category='info')
+ return redirect(url_for("scopes"))
+
@app.route('/action/client/add', methods=['GET', 'POST'])
@login_required
def action_client_add():