From 3a53fc122d4b832a3c67e75c77190efaae8ea58c Mon Sep 17 00:00:00 2001 From: dandds Date: Wed, 1 Aug 2018 13:15:07 -0400 Subject: [PATCH] switch workspace routes and templates to Flask and Jinja --- atst/app.py | 2 ++ atst/routes/workspaces.py | 31 ++++++++++++++++++ ..._workspace.html.to => base_workspace.html} | 6 ++-- templates/components.html | 12 +++++++ .../navigation/workspace_navigation.html.to | 32 ++++++++++--------- ...members.html.to => workspace_members.html} | 16 ++++++---- ...ojects.html.to => workspace_projects.html} | 16 ++++++---- .../{workspaces.html.to => workspaces.html} | 6 ++-- 8 files changed, 86 insertions(+), 35 deletions(-) create mode 100644 atst/routes/workspaces.py rename templates/{base_workspace.html.to => base_workspace.html} (70%) rename templates/{workspace_members.html.to => workspace_members.html} (92%) rename templates/{workspace_projects.html.to => workspace_projects.html} (72%) rename templates/{workspaces.html.to => workspaces.html} (91%) diff --git a/atst/app.py b/atst/app.py index 23ad724b..087277fc 100644 --- a/atst/app.py +++ b/atst/app.py @@ -10,6 +10,7 @@ from atst.sessions import RedisSessions from atst.database import db from atst.assets import assets from atst.routes import bp +from atst.routes.workspaces import bp as workspace_routes ENV = os.getenv("TORNADO_ENV", "dev") @@ -31,6 +32,7 @@ def make_app(config): assets.init_app(app) app.register_blueprint(bp) + app.register_blueprint(workspace_routes) return app diff --git a/atst/routes/workspaces.py b/atst/routes/workspaces.py new file mode 100644 index 00000000..1f3b47f2 --- /dev/null +++ b/atst/routes/workspaces.py @@ -0,0 +1,31 @@ +from flask import Blueprint, render_template + +from atst.domain.workspaces import Projects, Members +from atst.database import db + +bp = Blueprint("workspaces", __name__) + +mock_workspaces = [ + { + "name": "Unclassified IaaS and PaaS for Defense Digital Service (DDS)", + "id": "5966187a-eff9-44c3-aa15-4de7a65ac7ff", + "task_order": {"number": 123456}, + "user_count": 23, + } +] + +@bp.route("/workspaces") +def workspaces(): + return render_template("workspaces.html", page=5, workspaces=mock_workspaces) + +@bp.route("/workspaces//projects") +def workspace_projects(workspace_id): + projects_repo = Projects() + projects = projects_repo.get_many(workspace_id) + return render_template("workspace_projects.html", workspace_id=workspace_id, projects=projects) + +@bp.route("/workspaces//members") +def workspace_members(workspace_id): + members_repo = Members() + members = members_repo.get_many(workspace_id) + return render_template("workspace_members.html", workspace_id=workspace_id, members=members) diff --git a/templates/base_workspace.html.to b/templates/base_workspace.html similarity index 70% rename from templates/base_workspace.html.to rename to templates/base_workspace.html index 7803ace8..0ccad5ba 100644 --- a/templates/base_workspace.html.to +++ b/templates/base_workspace.html @@ -1,4 +1,4 @@ -{% extends "base.html.to" %} +{% extends "base.html" %} {% block content %} @@ -8,8 +8,8 @@
- {% block workspace_content %}{% end %} + {% block workspace_content %}{% endblock %}
-{% end %} +{% endblock %} diff --git a/templates/components.html b/templates/components.html index 06d487ea..0bc83991 100644 --- a/templates/components.html +++ b/templates/components.html @@ -30,3 +30,15 @@ {% endif %} {%- endmacro %} + +{% macro EmptyState(self, message, actionLabel, actionHref, icon=None) -%} +
+

{{ message }}

+ + {% if icon %} + {{ Icon(icon) }} + {% endif %} + + {{ actionLabel }} +
+{%- endmacro %} diff --git a/templates/navigation/workspace_navigation.html.to b/templates/navigation/workspace_navigation.html.to index 65a9525b..d516c1b0 100644 --- a/templates/navigation/workspace_navigation.html.to +++ b/templates/navigation/workspace_navigation.html.to @@ -1,42 +1,44 @@ +{% from "components.html" import SidenavItem %} + diff --git a/templates/workspace_members.html.to b/templates/workspace_members.html similarity index 92% rename from templates/workspace_members.html.to rename to templates/workspace_members.html index 0f538b05..989d1d0e 100644 --- a/templates/workspace_members.html.to +++ b/templates/workspace_members.html @@ -1,15 +1,17 @@ -{% extends "base_workspace.html.to" %} +{% from "components.html" import EmptyState %} + +{% extends "base_workspace.html" %} {% block workspace_content %} {% if not members %} - {% module EmptyState( + {{ EmptyState( 'There are currently no members in this Workspace.', actionLabel='Invite a new Member', actionHref='/members/new', icon='avatar' - )%} + )}} {% else %} @@ -59,17 +61,17 @@ {% for m in members %} {{ m['first_name'] }} {{ m['last_name'] }} - {% if m['num_projects'] == '0' %} No Project Access {% end %} + {% if m['num_projects'] == '0' %} No Project Access {% endif %} {{ m['status'] }} {{ m['workspace_role'] }} - {% end %} + {% endfor %} -{% end %} +{% endif %} -{% end %} +{% endblock %} diff --git a/templates/workspace_projects.html.to b/templates/workspace_projects.html similarity index 72% rename from templates/workspace_projects.html.to rename to templates/workspace_projects.html index a9f1a8aa..91826bb6 100644 --- a/templates/workspace_projects.html.to +++ b/templates/workspace_projects.html @@ -1,13 +1,15 @@ -{% extends "base_workspace.html.to" %} +{% from "components.html" import Icon %} + +{% extends "base_workspace.html" %} {% block workspace_content %} {% for project in projects %}
-

{{ project['name'] }} ({{ len(project['environments'])}} environments)

+

{{ project['name'] }} ({{ project['environments']|length }} environments)

- {% module Icon('edit') %} + {{ Icon('edit') }} edit
@@ -15,7 +17,7 @@ {% for environment in project['environments'] %}
  • - {% module Icon('link') %} + {{ Icon('link') }} {{ environment["name"]}} @@ -24,10 +26,10 @@ members
  • - {% end %} + {% endfor %} -{% end %} +{% endfor %} -{% end %} +{% endblock %} diff --git a/templates/workspaces.html.to b/templates/workspaces.html similarity index 91% rename from templates/workspaces.html.to rename to templates/workspaces.html index 21bbad7d..5f407766 100644 --- a/templates/workspaces.html.to +++ b/templates/workspaces.html @@ -1,4 +1,4 @@ -{% extends "base.html.to" %} +{% extends "base.html" %} {% block content %}
    @@ -23,9 +23,9 @@ {{ w['user_count'] }}Users - {% end %} + {% endfor %}
    -{% end %} +{% endblock %}