Skip to content

Commit

Permalink
refactor: separate jinja and js code
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Feb 21, 2024
1 parent e7e5340 commit f297817
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 482 deletions.
46 changes: 23 additions & 23 deletions web/b3desk/endpoints/meeting_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,29 @@ def edit_meeting_files(meeting, owner):
)


@bp.route("/meeting/files/<meeting:meeting>", methods=["POST"])
@auth.oidc_auth("default")
@meeting_owner_needed
def add_meeting_files(meeting, owner):
data = request.get_json()
is_default = False
if len(meeting.files) == 0:
is_default = True

if data["from"] == "nextcloud":
return add_meeting_file_nextcloud(data["value"], meeting.id, is_default)

if data["from"] == "URL":
return add_meeting_file_URL(data["value"], meeting.id, is_default)

if data["from"] == "dropzone":
return add_meeting_file_dropzone(
secure_filename(data["value"]), meeting.id, is_default
)

return jsonify("no file provided")


@bp.route("/meeting/files/<meeting:meeting>/")
@bp.route("/meeting/files/<meeting:meeting>/<int:file_id>")
@auth.oidc_auth("default")
Expand Down Expand Up @@ -413,29 +436,6 @@ def add_external_meeting_file_nextcloud(path, meeting_id):
return externalMeetingFile.id


@bp.route("/meeting/files/<meeting:meeting>", methods=["POST"])
@auth.oidc_auth("default")
@meeting_owner_needed
def add_meeting_files(meeting, owner):
data = request.get_json()
is_default = False
if len(meeting.files) == 0:
is_default = True

if data["from"] == "nextcloud":
return add_meeting_file_nextcloud(data["value"], meeting.id, is_default)

if data["from"] == "URL":
return add_meeting_file_URL(data["value"], meeting.id, is_default)

if data["from"] == "dropzone":
return add_meeting_file_dropzone(
secure_filename(data["value"]), meeting.id, is_default
)

return jsonify("no file provided")


# for dropzone multiple files uploading at once
@bp.route("/meeting/files/<meeting:meeting>/dropzone", methods=["POST"])
@auth.oidc_auth("default")
Expand Down
14 changes: 13 additions & 1 deletion web/b3desk/templates/meeting/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,17 @@
{% endblock %}

{% block js %}
{% include 'meeting/js_script.html' %}
<script type="application/javascript">
const nc_locator = "{{ user.nc_locator }}";
const nc_login = "{{ user.nc_login }}";
const nc_token = "{{ user.nc_token }}";
const meeting_id = "{{ meeting.id }}";
const toggle_download_url = "{{ url_for("meeting_files.toggledownload", meeting=meeting) }}";
const set_default_file_url = "{{ url_for("meeting_files.set_meeting_default_file", meeting=meeting) }}";
const download_meeting_file_url = "{{ url_for("meeting_files.download_meeting_files", meeting=meeting, _external=True) }}";
const add_meeting_files_url = "{{ url_for("meeting_files.add_meeting_files", meeting=meeting) }}";
const delete_meeting_file_url = "{{ url_for("meeting_files.delete_meeting_file") }}";
const accepted_files = "{{ config.ACCEPTED_FILES_CLIENT_SIDE }}";
{% include 'meeting/meeting.js' %}
</script>
{% endblock %}
2 changes: 1 addition & 1 deletion web/b3desk/templates/meeting/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
src="{{ url_for('static', filename='js/dropzone-min.js') }}">
</script>

<h1 class="fr-h2">Gestion des {{ meeting_presentation }}s associées à <em>{{meeting.name }}</em></h1>
<h1 class="fr-h2">Gestion des {{ meeting_presentation }}s associées à <em>{{ meeting.name }}</em></h1>

<div class="fr-mt-4w fr-mb-4w">
<a href="{{ url_for("public.welcome") }}"><span aria-hidden="true" class="fr-fi-arrow-left-line"></span>Retour à mes {{ meeting_label }}s</a>
Expand Down
14 changes: 13 additions & 1 deletion web/b3desk/templates/meeting/filesform.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,17 @@
{% endblock %}

{% block js %}
{% include 'meeting/js_script.html' %}
<script type="application/javascript">
const nc_locator = "{{ user.nc_locator }}";
const nc_login = "{{ user.nc_login }}";
const nc_token = "{{ user.nc_token }}";
const meeting_id = "{{ meeting.id }}";
const toggle_download_url = "{{ url_for("meeting_files.toggledownload", meeting=meeting) }}";
const set_default_file_url = "{{ url_for("meeting_files.set_meeting_default_file", meeting=meeting) }}";
const download_meeting_file_url = "{{ url_for("meeting_files.download_meeting_files", meeting=meeting, _external=True) }}";
const add_meeting_files_url = "{{ url_for("meeting_files.add_meeting_files", meeting=meeting) }}";
const delete_meeting_file_url = "{{ url_for("meeting_files.delete_meeting_file") }}";
const accepted_files = "{{ config.ACCEPTED_FILES_CLIENT_SIDE }}";
{% include 'meeting/meeting.js' %}
</script>
{% endblock %}
Loading

0 comments on commit f297817

Please sign in to comment.