Merge pull request #254 from dod-ccpo/refactor-templates

Refactor templates
This commit is contained in:
patricksmithdds 2018-09-06 15:33:34 -04:00 committed by GitHub
commit 6d4aec3a6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 111 additions and 363 deletions

View File

@ -1,6 +1,9 @@
from atst.database import db from atst.database import db
from atst.models.project import Project from atst.domain.authz import Authorization
from atst.domain.environments import Environments from atst.domain.environments import Environments
from atst.domain.exceptions import NotFoundError
from atst.models.permissions import Permissions
from atst.models.project import Project
class Projects(object): class Projects(object):
@ -13,3 +16,20 @@ class Projects(object):
db.session.commit() db.session.commit()
return project return project
@classmethod
def get(cls, user, workspace, project_id):
# TODO: this should check permission for this particular project
Authorization.check_workspace_permission(
user,
workspace,
Permissions.VIEW_APPLICATION_IN_WORKSPACE,
"view project in workspace",
)
try:
project = db.session.query(Project).filter_by(id=project_id).one()
except NoResultFound:
raise NotFoundError("project")
return project

View File

@ -98,4 +98,4 @@ class RequestsIndex(object):
@requests_bp.route("/requests", methods=["GET"]) @requests_bp.route("/requests", methods=["GET"])
def requests_index(): def requests_index():
context = RequestsIndex(g.current_user).execute() context = RequestsIndex(g.current_user).execute()
return render_template("requests.html", **context) return render_template("requests/index.html", **context)

View File

@ -47,13 +47,13 @@ def workspace():
@bp.route("/workspaces") @bp.route("/workspaces")
def workspaces(): def workspaces():
workspaces = Workspaces.get_many(g.current_user) workspaces = Workspaces.get_many(g.current_user)
return render_template("workspaces.html", page=5, workspaces=workspaces) return render_template("workspaces/index.html", page=5, workspaces=workspaces)
@bp.route("/workspaces/<workspace_id>/projects") @bp.route("/workspaces/<workspace_id>/projects")
def workspace_projects(workspace_id): def workspace_projects(workspace_id):
workspace = Workspaces.get(g.current_user, workspace_id) workspace = Workspaces.get(g.current_user, workspace_id)
return render_template("workspace_projects.html", workspace=workspace) return render_template("workspaces/projects/index.html", workspace=workspace)
@bp.route("/workspaces/<workspace_id>") @bp.route("/workspaces/<workspace_id>")
@ -64,7 +64,7 @@ def show_workspace(workspace_id):
@bp.route("/workspaces/<workspace_id>/members") @bp.route("/workspaces/<workspace_id>/members")
def workspace_members(workspace_id): def workspace_members(workspace_id):
workspace = Workspaces.get(g.current_user, workspace_id) workspace = Workspaces.get(g.current_user, workspace_id)
return render_template("workspace_members.html", workspace=workspace) return render_template("workspaces/members/index.html", workspace=workspace)
@bp.route("/workspaces/<workspace_id>/reports") @bp.route("/workspaces/<workspace_id>/reports")
@ -86,7 +86,7 @@ def workspace_reports(workspace_id):
two_months_ago = prev_month - timedelta(days=28) two_months_ago = prev_month - timedelta(days=28)
return render_template( return render_template(
"workspace_reports.html", "workspaces/reports/index.html",
workspace_totals=Reports.workspace_totals(alternate_reports), workspace_totals=Reports.workspace_totals(alternate_reports),
monthly_totals=Reports.monthly_totals(alternate_reports), monthly_totals=Reports.monthly_totals(alternate_reports),
current_month=current_month, current_month=current_month,
@ -99,11 +99,13 @@ def workspace_reports(workspace_id):
def new_project(workspace_id): def new_project(workspace_id):
workspace = Workspaces.get_for_update(g.current_user, workspace_id) workspace = Workspaces.get_for_update(g.current_user, workspace_id)
form = NewProjectForm() form = NewProjectForm()
return render_template("workspace_project_new.html", workspace=workspace, form=form) return render_template(
"workspaces/projects/new.html", workspace=workspace, form=form
)
@bp.route("/workspaces/<workspace_id>/projects/new", methods=["POST"]) @bp.route("/workspaces/<workspace_id>/projects/new", methods=["POST"])
def update_project(workspace_id): def create_project(workspace_id):
workspace = Workspaces.get_for_update(g.current_user, workspace_id) workspace = Workspaces.get_for_update(g.current_user, workspace_id)
form = NewProjectForm(http_request.form) form = NewProjectForm(http_request.form)
@ -120,15 +122,32 @@ def update_project(workspace_id):
) )
else: else:
return render_template( return render_template(
"workspace_project_new.html", workspace=workspace, form=form "workspaces/projects/new.html", workspace=workspace, form=form
) )
@bp.route("/workspaces/<workspace_id>/projects/<project_id>/edit")
def edit_project(workspace_id, project_id):
workspace = Workspaces.get_for_update(g.current_user, workspace_id)
project = Projects.get(g.current_user, workspace, project_id)
form = NewProjectForm(
name=project.name,
environment_names=[env.name for env in project.environments],
description=project.description,
)
return render_template(
"workspaces/projects/edit.html", workspace=workspace, project=project, form=form
)
@bp.route("/workspaces/<workspace_id>/members/new") @bp.route("/workspaces/<workspace_id>/members/new")
def new_member(workspace_id): def new_member(workspace_id):
workspace = Workspaces.get(g.current_user, workspace_id) workspace = Workspaces.get(g.current_user, workspace_id)
form = NewMemberForm() form = NewMemberForm()
return render_template("member_new.html", workspace=workspace, form=form) return render_template(
"workspaces/members/new.html", workspace=workspace, form=form
)
@bp.route("/workspaces/<workspace_id>/members/new", methods=["POST"]) @bp.route("/workspaces/<workspace_id>/members/new", methods=["POST"])
@ -146,7 +165,9 @@ def create_member(workspace_id):
) )
) )
else: else:
return render_template("member_new.html", workspace=workspace, form=form) return render_template(
"workspaces/members/new.html", workspace=workspace, form=form
)
@bp.route("/workspaces/<workspace_id>/members/<member_id>/member_edit") @bp.route("/workspaces/<workspace_id>/members/<member_id>/member_edit")
@ -161,7 +182,7 @@ def view_member(workspace_id, member_id):
member = WorkspaceUsers.get(workspace_id, member_id) member = WorkspaceUsers.get(workspace_id, member_id)
form = EditMemberForm(workspace_role=member.role) form = EditMemberForm(workspace_role=member.role)
return render_template( return render_template(
"member_edit.html", form=form, workspace=workspace, member=member "workspaces/members/edit.html", form=form, workspace=workspace, member=member
) )
@ -195,5 +216,8 @@ def update_member(workspace_id, member_id):
) )
else: else:
return render_template( return render_template(
"member_edit.html", form=form, workspace=workspace, member=member "workspaces/members/edit.html",
form=form,
workspace=workspace,
member=member,
) )

View File

@ -1,30 +1,20 @@
{% from "components/icon.html" import Icon %} {% from "components/icon.html" import Icon %}
{% from "components/modal.html" import Modal %} {% from "components/modal.html" import Modal %}
{% from "components/text_input.html" import TextInput %} {% from "components/text_input.html" import TextInput %}
{% from "components/tooltip.html" import Tooltip %}
{% from "components/alert.html" import Alert %} {% from "components/alert.html" import Alert %}
{% extends "base_workspace.html" %}
{% block workspace_content %}
{% set modalName = "newProjectConfirmation" %}
{% if request.args.get("newWorkspace") %}
{{ Alert('Workspace created!',
message="\
<p>You are now ready to create projects and environments within the JEDI Cloud.</p>
",
level='success'
) }}
{% endif %}
<new-project inline-template v-bind:initial-data='{{ form.data|tojson }}'> <new-project inline-template v-bind:initial-data='{{ form.data|tojson }}'>
<form method="POST" action="{{ url_for('workspaces.update_project', workspace_id=workspace.id) }}" > {% set new_project = project is not defined %}
{% set form_action = url_for('workspaces.create_project', workspace_id=workspace.id) if new_project else url_for('workspaces.edit_project', workspace_id=workspace.id, project_id=project.id) %}
{% set action_text = 'Create' if new_project else 'Update' %}
{% set title_text = 'Add a new project' if new_project else 'Edit {} project'.format(project.name) %}
<form method="POST" action="{{ form_action }}" >
{% call Modal(name=modalName, dismissable=False) %} {% call Modal(name=modalName, dismissable=False) %}
<h1>Create project !{ name }</h1> <h1>{{ action_text }} project !{ name }</h1>
<p> <p>
When you click <em>Create Project</em>, the environments When you click <em>{{ action_text }} Project</em>, the environments
<span v-for="(environment, index) in environments"> <span v-for="(environment, index) in environments">
<strong>!{environment.name}</strong><template v-if="index < (environments.length - 1)">, </template> <strong>!{environment.name}</strong><template v-if="index < (environments.length - 1)">, </template>
</span> </span>
@ -32,7 +22,7 @@
</p> </p>
<div class='action-group'> <div class='action-group'>
<button type='submit' class='action-group__action usa-button' tabindex='0'>Create Project</button> <button type='submit' class='action-group__action usa-button' tabindex='0'>{{ action_text }} Project</button>
<button type='button' v-on:click="closeModal('{{ modalName }}')" class='icon-link action-group__action' tabindex='0'>Cancel</button> <button type='button' v-on:click="closeModal('{{ modalName }}')" class='icon-link action-group__action' tabindex='0'>Cancel</button>
</div> </div>
{% endcall %} {% endcall %}
@ -40,7 +30,7 @@
{{ form.csrf_token }} {{ form.csrf_token }}
<div class="panel"> <div class="panel">
<div class="panel__heading panel__heading--grow"> <div class="panel__heading panel__heading--grow">
<h1>Add a new project</h1> <h1>{{ title_text }}</h1>
</div> </div>
<div class="panel__content"> <div class="panel__content">
@ -86,11 +76,11 @@
<div class="action-group"> <div class="action-group">
<button v-on:click="openModal('{{ modalName }}')" class="usa-button usa-button-primary" tabindex="0" type="button">Create Project</button> <button v-on:click="openModal('{{ modalName }}')" class="usa-button usa-button-primary" tabindex="0" type="button">{{ action_text }} Project</button>
</div> </div>
</div> </div>
</form> </form>
</new-project> </new-project>
{% endblock %}

View File

@ -1,108 +0,0 @@
{% extends "base_workspace.html.to" %}
{% from "components/alert.html" import Alert %}
{% block template_vars %}
{% set is_new_project = False %}
{% set project_name = "Code.mil" %}
{% set project_id = "789" %}
{% end %}
{% block workspace_content %}
{{ Alert(
"UI Mock",
message="<p>Please note, this screen is a non-functional UI mockup.</p>",
level="warning"
) }}
<form action=''>
<div class='panel'>
<div class='panel__heading'>
<h1 class='h2'>
{% if is_new_project %}
Add a new project
{% else %}
{{ project_name }}
<span class='subtitle'>Edit project</span>
{% end %}
</h1>
</div>
<div class='panel__content'>
<div class='usa-input'>
<label for='project-name'>Project Name</label>
<input id='project-name' type='text'/>
</div>
<div class='usa-input'>
<label for='project-description'>Description</label>
<textarea id='project-description'></textarea>
</div>
</div>
</div>
<section class='block-list'>
<header class='block-list__header'>
<h2 class='block-list__title'>Project Environments</h2>
</header>
{# All instances of .usa-input groups here should be replaced with {% module TextInput(wtforms.fields.Field) %} #}
<ul>
<li class='block-list__item project-edit__env-list-item'>
<div class='usa-input'>
<label for='environment-name-1'>Environment Name</label>
<input id='environment-name-1' type='text' placeholder="Environment 1" />
</div>
<button class='project-edit__env-list-item__remover'>
{% module Icon('trash') %}
<span>Remove</span>
</button>
</li>
<li class='block-list__item project-edit__env-list-item'>
<div class='usa-input'>
<label for='environment-name-2'>Environment Name</label>
<input id='environment-name-2' type='text' placeholder="Environment 2" />
</div>
<button class='project-edit__env-list-item__remover '>
{% module Icon('trash') %}
<span>Remove</span>
</button>
</li>
<li class='block-list__item project-edit__env-list-item'>
<div class='usa-input'>
<label for='environment-name-3'>Environment Name</label>
<input id='environment-name-3' type='text' placeholder="Environment 3" />
</div>
<button class='project-edit__env-list-item__remover'>
{% module Icon('trash') %}
<span>Remove</span>
</button>
</li>
</ul>
<footer class='block-list__footer'>
<a href='/' class='icon-link'>
{% module Icon('plus') %}
<span class="icon-link">Add another environment</span>
</a>
</footer>
</section>
<div class='action-group'>
<a href='/styleguide' class='action-group__action usa-button usa-button-big'>
{% if is_new_project %}Create{% else %}Save{% end %} Project
</a>
<a href='/styleguide' class='action-group__action icon-link'>
{% module Icon('x') %}
<span>Cancel</span>
</a>
</div>
</form>
{% end %}

View File

@ -1,12 +0,0 @@
{% extends '../requests_new.html.to' %}
{% block form %}
<h2>New JEDI Request</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus error omnis a, tenetur similique quo officiis voluptates eum recusandae dolorem minus dignissimos, magni consequatur, maxime debitis reprehenderit sint non iusto?</p>
<a class='usa-button usa-button-secondary' href='{{ url_for('requests.request_form_new',next_screen) }}'>New Application</a>
<a class='usa-button usa-button-secondary' href='{{ url_for('requests.request_form_new',next_screen) }}'>Existing Application</a>
<a class='usa-button usa-button-secondary' href='{{ url_for('requests.request_form_new',next_screen) }}'>Sandbox Environment</a>
{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends 'requests_new.html' %} {% extends 'requests/_new.html' %}
{% from "components/alert.html" import Alert %} {% from "components/alert.html" import Alert %}
{% from "components/text_input.html" import TextInput %} {% from "components/text_input.html" import TextInput %}

View File

@ -1,4 +1,4 @@
{% extends 'requests_new.html' %} {% extends 'requests/_new.html' %}
{% from "components/alert.html" import Alert %} {% from "components/alert.html" import Alert %}
{% from "components/text_input.html" import TextInput %} {% from "components/text_input.html" import TextInput %}

View File

@ -1,4 +1,4 @@
{% extends 'requests_new.html' %} {% extends 'requests/_new.html' %}
{% from "components/alert.html" import Alert %} {% from "components/alert.html" import Alert %}
{% from "components/text_input.html" import TextInput %} {% from "components/text_input.html" import TextInput %}

View File

@ -2,7 +2,7 @@
<span class='label label--error'>Response Required</span> <span class='label label--error'>Response Required</span>
{%- endmacro %} {%- endmacro %}
{% extends 'requests_new.html' %} {% extends 'requests/_new.html' %}
{% from "components/alert.html" import Alert %} {% from "components/alert.html" import Alert %}
{% from "components/text_input.html" import TextInput %} {% from "components/text_input.html" import TextInput %}

View File

@ -1,200 +0,0 @@
{% extends '../requests_new.html.to' %}
{% from "components/alert.html" import Alert %}
{% block form %}
{% if f.errors %}
{{ Alert('There were some errors',
message="<p>Please complete all the fields before submitting.</p>",
level='error'
) }}
{% endif %}
<h2 id="financial-verification">Financial Verification</h2>
<p>In order to get you access to the JEDI Cloud, we will need you to enter the details below that will help us verify and account for your Task Order.</p>
{{ f.task_order_number.label }}
{{ f.task_order_number(placeholder="Example: 1234567899C0001") }}
{% for e in f.task_order_number.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.uii_ids.label }}
{{ f.uii_ids(placeholder="Example: \nDI 0CVA5786950 \nUN1945326361234786950") }}
{% for e in f.uii_ids.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.pe_id.label }}
{{ f.pe_id(placeholder="Example: 0203752A") }}
{% for e in f.pe_id.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.treasury_code.label }}
{{ f.treasury_code(placeholder="Example: 1200") }}
{% for e in f.treasury_code.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.ba_code.label }}
{{ f.ba_code(placeholder="Example: 02") }}
{% for e in f.ba_code.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
<!-- KO Information -->
<h3>Contracting Officer (KO) Information</h3>
{{ f.fname_co.label }}
{{ f.fname_co(placeholder="Contracting Officer first name") }}
{% for e in f.fname_co.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.lname_co.label }}
{{ f.lname_co(placeholder="Contracting Officer last name") }}
{% for e in f.lname_co.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.email_co.label }}
{{ f.email_co(placeholder="jane@mail.mil") }}
{% for e in f.email_co.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.office_co.label }}
{{ f.office_co(placeholder="Example: WHS") }}
{% for e in f.office_co.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
<!-- COR Information -->
<h3>Contracting Officer Representative (COR) Information</h3>
{{ f.fname_cor.label }}
{{ f.fname_cor(placeholder="Contracting Officer Representative first name") }}
{% for e in f.fname_cor.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.lname_cor.label }}
{{ f.lname_cor(placeholder="Contracting Officer Representative last name") }}
{% for e in f.lname_cor.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.email_cor.label }}
{{ f.email_cor(placeholder="jane@mail.mil") }}
{% for e in f.email_cor.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.office_cor.label }}
{{ f.office_cor(placeholder="Example: WHS") }}
{% for e in f.office_cor.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
<br><hr>
<em>&darr; FIELDS NEEDED FOR MANUAL ENTRY OF TASK ORDER INFORMATION (only necessary if EDA info not available)</em>
{{ f.funding_type.label }}
{{ f.funding_type }}
{% for e in f.funding_type.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.funding_type_other.label }}
{{ f.funding_type_other(placeholder="") }}
{% for e in f.funding_type_other.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.clin_0001.label }}
{{ f.clin_0001(placeholder="50,000") }}
{% for e in f.clin_0001.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.clin_0003.label }}
{{ f.clin_0003(placeholder="13,000") }}
{% for e in f.clin_0003.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.clin_1001.label }}
{{ f.clin_1001(placeholder="30,000") }}
{% for e in f.clin_1001.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.clin_1003.label }}
{{ f.clin_1003(placeholder="7,000") }}
{% for e in f.clin_1003.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.clin_2001.label }}
{{ f.clin_2001(placeholder="30,000") }}
{% for e in f.clin_2001.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{{ f.clin_2003.label }}
{{ f.clin_2003(placeholder="7,000") }}
{% for e in f.clin_2003.errors %}
<div class="usa-input-error-message">
{{ e }}
</div>
{% endfor %}
{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_workspace.html" %} {% extends "workspaces/base.html" %}
{% from "components/empty_state.html" import EmptyState %} {% from "components/empty_state.html" import EmptyState %}
{% from "components/alert.html" import Alert %} {% from "components/alert.html" import Alert %}

View File

@ -0,0 +1,17 @@
{% extends "workspaces/base.html" %}
{% from "components/alert.html" import Alert %}
{% from "components/icon.html" import Icon %}
{% block workspace_content %}
{{ Alert(
"UI Mock",
message="<p>Please note, this screen is a non-functional UI mockup.</p>",
level="warning"
) }}
{% set modalName = "updateProjectConfirmation" %}
{% include "fragments/edit_project_form.html" %}
{% endblock %}

View File

@ -2,7 +2,7 @@
{% from "components/alert.html" import Alert %} {% from "components/alert.html" import Alert %}
{% from "components/empty_state.html" import EmptyState %} {% from "components/empty_state.html" import EmptyState %}
{% extends "base_workspace.html" %} {% extends "workspaces/base.html" %}
{% block workspace_content %} {% block workspace_content %}
@ -25,7 +25,7 @@
<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 }} ({{ project.environments|length }} 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='{{ url_for("workspaces.edit_project", workspace_id=workspace.id, project_id=project.id) }}'>
{{ Icon('edit') }} {{ Icon('edit') }}
<span>edit</span> <span>edit</span>
</a> </a>

View File

@ -0,0 +1,17 @@
{% extends "workspaces/base.html" %}
{% block workspace_content %}
{% set modalName = "newProjectConfirmation" %}
{% if request.args.get("newWorkspace") %}
{{ Alert('Workspace created!',
message="\
<p>You are now ready to create projects and environments within the JEDI Cloud.</p>
",
level='success'
) }}
{% endif %}
{% include "fragments/edit_project_form.html" %}
{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "base_workspace.html" %} {% extends "workspaces/base.html" %}
{% from "components/alert.html" import Alert %} {% from "components/alert.html" import Alert %}
{% from "components/icon.html" import Icon %} {% from "components/icon.html" import Icon %}