Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/allow multiple notes #182

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions signac_dashboard/modules/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# All rights reserved.
# This software is licensed under the BSD 3-Clause License.
import flask_login
from flask import abort, render_template, request
from flask import Blueprint, abort, render_template, request
from jinja2.exceptions import TemplateNotFound
from markupsafe import escape

from signac_dashboard.module import Module

Expand Down Expand Up @@ -39,20 +40,27 @@ def __init__(
)
self.key = key

self.note_blueprint = Blueprint(
name=key,
import_name=key,
url_prefix=f"/module/notes/{escape(key)}",
template_folder=template,
)

def get_cards(self, job):
note_text = job.document.get(self.key, "")
return [
{
"name": self.name,
"content": render_template(
self.template, note_text=note_text, jobid=job._id
self.template, note_text=note_text, jobid=job.id, note_key=self.key
),
}
]

def register(self, dashboard):
# Register routes
@dashboard.app.route("/module/notes/update", methods=["POST"])
@self.note_blueprint.route("/update", methods=["POST"])
@flask_login.login_required
def notes_update():
note_text = request.form.get("note_text")
Expand All @@ -61,7 +69,7 @@ def notes_update():
job.document[self.key] = note_text
return "Saved."

@dashboard.app.route("/module/notes/<path:filename>")
@self.note_blueprint.route("/<path:filename>")
@flask_login.login_required
def notes_asset(filename):
path = f"notes/{filename}"
Expand All @@ -76,6 +84,9 @@ def notes_asset(filename):
dashboard.register_module_asset(
{
"file": f"templates/notes/{asset_file}",
"url": f"/module/notes/{asset_file}",
"url": f"/module/notes/{self.key}/{asset_file}",
}
)

# register Blueprint
dashboard.app.register_blueprint(self.note_blueprint)
2 changes: 1 addition & 1 deletion signac_dashboard/templates/cards/notes.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form class="notes-form" method="POST" action="{{ url_for('notes_update') }}">
<form class="notes-form" method="POST" action="{{ url_for(note_key + '.notes_update') }}">
<input type="hidden" name="redirect" value="{{ request.url }}">
<input type="hidden" name="jobid" value="{{ jobid }}">
<div class="field">
Expand Down