switch workspace routes and templates to Flask and Jinja

This commit is contained in:
dandds 2018-08-01 13:15:07 -04:00 committed by richard-dds
parent 0976aed778
commit 3a53fc122d
8 changed files with 86 additions and 35 deletions

View File

@ -10,6 +10,7 @@ from atst.sessions import RedisSessions
from atst.database import db from atst.database import db
from atst.assets import assets from atst.assets import assets
from atst.routes import bp from atst.routes import bp
from atst.routes.workspaces import bp as workspace_routes
ENV = os.getenv("TORNADO_ENV", "dev") ENV = os.getenv("TORNADO_ENV", "dev")
@ -31,6 +32,7 @@ def make_app(config):
assets.init_app(app) assets.init_app(app)
app.register_blueprint(bp) app.register_blueprint(bp)
app.register_blueprint(workspace_routes)
return app return app

31
atst/routes/workspaces.py Normal file
View File

@ -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/<workspace_id>/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/<workspace_id>/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)

View File

@ -1,4 +1,4 @@
{% extends "base.html.to" %} {% extends "base.html" %}
{% block content %} {% block content %}
@ -8,8 +8,8 @@
</div> </div>
<div class='col col--grow'> <div class='col col--grow'>
{% block workspace_content %}{% end %} {% block workspace_content %}{% endblock %}
</div> </div>
</div> </div>
{% end %} {% endblock %}

View File

@ -30,3 +30,15 @@
{% endif %} {% endif %}
</li> </li>
{%- endmacro %} {%- endmacro %}
{% macro EmptyState(self, message, actionLabel, actionHref, icon=None) -%}
<div class='empty-state'>
<p>{{ message }}</p>
{% if icon %}
{{ Icon(icon) }}
{% endif %}
<a href='{{ actionHref }}' class='usa-button usa-button-big'>{{ actionLabel }}</a>
</div>
{%- endmacro %}

View File

@ -1,42 +1,44 @@
{% from "components.html" import SidenavItem %}
<nav class='sidenav workspace-navigation'> <nav class='sidenav workspace-navigation'>
<ul> <ul>
{% module SidenavItem( {{ SidenavItem(
"Projects", "Projects",
href=reverse_url('workspace_projects', '123456'), href=url_for("workspaces.workspace_projects", workspace_id="123456"),
active=matchesPath('\/workspaces\/[A-Za-z0-9]*\/projects'), active=g.matchesPath('\/workspaces\/[A-Za-z0-9]*\/projects'),
subnav=[ subnav=[
{ {
"label": "Add New Project", "label": "Add New Project",
"href":"/", "href":"/",
"active": matchesPath('workspaces/projects/new'), "active": g.matchesPath('workspaces/projects/new'),
"icon": "plus" "icon": "plus"
} }
] ]
)%} )}}
{% module SidenavItem( {{ SidenavItem(
"Members", "Members",
href=reverse_url('workspace_members', '123456'), href="/workspaces/{}/members".format('123456'),
active=matchesPath('\/workspaces\/[A-Za-z0-9]*\/members'), active=g.matchesPath('\/workspaces\/[A-Za-z0-9]*\/members'),
subnav=[ subnav=[
{ {
"label": "Add New Member", "label": "Add New Member",
"href": "", "href": "",
"active": matchesPath('/workspaces/members/new'), "active": g.matchesPath('/workspaces/members/new'),
"icon": "plus" "icon": "plus"
}, },
{ {
"label": "Editing Member", "label": "Editing Member",
"href": "", "href": "",
"active": matchesPath('/workspaces/123456/members/789/edit') "active": g.matchesPath('/workspaces/123456/members/789/edit')
} }
] ]
)%} )}}
{% module SidenavItem( {{ SidenavItem(
"Funding & Reports", "Funding & Reports",
href=reverse_url('workspace_projects', '123456'), href=url_for("workspaces.workspace_projects", workspace_id="123456"),
active=matchesPath('\/workspaces\/[A-Za-z0-9]*\/reports') active=g.matchesPath('\/workspaces\/[A-Za-z0-9]*\/reports')
)%} )}}
</ul> </ul>
</nav> </nav>

View File

@ -1,15 +1,17 @@
{% extends "base_workspace.html.to" %} {% from "components.html" import EmptyState %}
{% extends "base_workspace.html" %}
{% block workspace_content %} {% block workspace_content %}
{% if not members %} {% if not members %}
{% module EmptyState( {{ EmptyState(
'There are currently no members in this Workspace.', 'There are currently no members in this Workspace.',
actionLabel='Invite a new Member', actionLabel='Invite a new Member',
actionHref='/members/new', actionHref='/members/new',
icon='avatar' icon='avatar'
)%} )}}
{% else %} {% else %}
@ -59,17 +61,17 @@
{% for m in members %} {% for m in members %}
<tr> <tr>
<td><a href="/workspaces/123456/members/789/edit" class="icon-link icon-link--large">{{ m['first_name'] }} {{ m['last_name'] }}</a></td> <td><a href="/workspaces/123456/members/789/edit" class="icon-link icon-link--large">{{ m['first_name'] }} {{ m['last_name'] }}</a></td>
<td class='table-cell--shrink'>{% if m['num_projects'] == '0' %} <span class="label label--info">No Project Access</span> {% end %}</td> <td class='table-cell--shrink'>{% if m['num_projects'] == '0' %} <span class="label label--info">No Project Access</span> {% endif %}</td>
<td>{{ m['status'] }}</a></td> <td>{{ m['status'] }}</a></td>
<td>{{ m['workspace_role'] }}</a></td> <td>{{ m['workspace_role'] }}</a></td>
</tr> </tr>
{% end %} {% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>
{% end %} {% endif %}
{% end %} {% endblock %}

View File

@ -1,13 +1,15 @@
{% extends "base_workspace.html.to" %} {% from "components.html" import Icon %}
{% extends "base_workspace.html" %}
{% block workspace_content %} {% block workspace_content %}
{% for project in projects %} {% for project in projects %}
<div class='block-list project-list-item'> <div class='block-list project-list-item'>
<header class='block-list__header'> <header class='block-list__header'>
<h2 class='block-list__title'>{{ project['name'] }} ({{ len(project['environments'])}} environments)</h2> <h2 class='block-list__title'>{{ project['name'] }} ({{ project['environments']|length }} environments)</h2>
<a class='icon-link' href='/workspaces/123456/projects/789/edit'> <a class='icon-link' href='/workspaces/123456/projects/789/edit'>
{% module Icon('edit') %} {{ Icon('edit') }}
<span>edit</span> <span>edit</span>
</a> </a>
</header> </header>
@ -15,7 +17,7 @@
{% for environment in project['environments'] %} {% for environment in project['environments'] %}
<li class='block-list__item project-list-item__environment'> <li class='block-list__item project-list-item__environment'>
<a href='/' target='_blank' rel='noopener noreferrer' class='project-list-item__environment__link'> <a href='/' target='_blank' rel='noopener noreferrer' class='project-list-item__environment__link'>
{% module Icon('link') %} {{ Icon('link') }}
<span>{{ environment["name"]}}</span> <span>{{ environment["name"]}}</span>
</a> </a>
@ -24,10 +26,10 @@
<span>members</span> <span>members</span>
</div> </div>
</li> </li>
{% end %} {% endfor %}
</ul> </ul>
</div> </div>
{% end %} {% endfor %}
{% end %} {% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base.html.to" %} {% extends "base.html" %}
{% block content %} {% block content %}
<div class='col'> <div class='col'>
@ -23,9 +23,9 @@
<span class="label">{{ w['user_count'] }}</span><span class='h6'>Users</span> <span class="label">{{ w['user_count'] }}</span><span class='h6'>Users</span>
</td> </td>
</tr> </tr>
{% end %} {% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>
{% end %} {% endblock %}