Skip to content
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
39 changes: 36 additions & 3 deletions app/controllers/main_routes/departmentPortal.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from datetime import datetime

from flask import g, render_template, request, send_file
from flask import flash, g, render_template, request, send_file
from peewee import DoesNotExist

from app.controllers.main_routes import main_bp
from app.logic.download import makePositionDescriptionPDF
from app.logic.getPositions import getPosition, getPositions, getPositionDescriptionSections
from app.logic.getPositions import createPositionRevision, getPosition, getPositions, getPositionDescriptionSections
from app.models.department import Department
from app.models.positionHistory import PositionHistory
from app.models.supervisorDepartment import SupervisorDepartment
Expand Down Expand Up @@ -67,6 +67,39 @@ def downloadPositionDescription(org, account, positionCode):



@main_bp.route('/department/<org>/<account>/positions/<positionCode>/revise', methods=['GET', 'POST'])
def revisePosition(org, account, positionCode):
try:
dept = Department.get(Department.ORG == org, Department.ACCOUNT == account)
except (NameError, DoesNotExist):
return render_template('errors/404.html'), 404

position = getPosition(dept, positionCode)

if not position:
return render_template('errors/404.html'), 404

if request.method == 'POST':
position = createPositionRevision(
position,
g.currentUser.fullName,
request.form.get('positionTitle'),
request.form.get('wls'),
request.form.getlist('sectionTitle[]'),
request.form.getlist('sectionContent[]')
)
flash('Position revision saved.', 'success')

sections = getPositionDescriptionSections(position)

return render_template(
'main/revisepositionpage.html',
department=dept,
position=position,
sections=sections
)


@main_bp.route('/department/<org>/<account>/positions', methods=['GET'])
def managePositions(org, account):
try:
Expand All @@ -87,4 +120,4 @@ def managePositions(org, account):
department = dept,
department_name = dept.DEPT_NAME,
positions = positions
)
)
28 changes: 27 additions & 1 deletion app/logic/getPositions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from app.models.positionHistory import PositionHistory
from app.models.positionDescriptionSection import PositionDescriptionSection
from datetime import date

def getActivePositions(dept):
"""
Expand Down Expand Up @@ -52,7 +53,32 @@ def getPositionDescriptionSections(position):
positionDescriptionSections = list(PositionDescriptionSection.select()
.where(PositionDescriptionSection.position == position)
.order_by(PositionDescriptionSection.order.asc()))

return positionDescriptionSections

def createPositionRevision(position, revisedBy, positionTitle, wls, sectionTitles, sectionContents):
"""
Creates a new pending (Requested) revision of a position, copying forward its
department and position code, and replaces its description sections with the
given titles/contents. Returns the newly created PositionHistory row.
"""
newPosition = PositionHistory.create(
positionTitle=positionTitle,
positionCode=position.positionCode,
department=position.department,
status="Requested",
wls=wls,
revisionDate=date.today(),
revisedBy=revisedBy
)

for order, (sectionTitle, sectionContent) in enumerate(zip(sectionTitles, sectionContents)):
PositionDescriptionSection.create(
position=newPosition,
sectionTitle=sectionTitle,
sectionContent=sectionContent,
order=order
)

return newPosition

12 changes: 12 additions & 0 deletions app/static/css/revisepositionpage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Revise position form - styles not covered by Bootstrap */
.description-section-row {
background: #fff;
border: 1px solid #e6e6e6;
padding: 1rem;
border-radius: 6px;
margin-bottom: 1rem;
}

.revise-actions {
margin-top: 1.5rem;
}
14 changes: 14 additions & 0 deletions app/static/js/revisepositionpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$(document).ready(function () {
var sectionsContainer = document.getElementById('sectionsContainer');
var sectionRowTemplate = document.getElementById('sectionRowTemplate');

document.getElementById('addSectionBtn').addEventListener('click', function () {
sectionsContainer.appendChild(sectionRowTemplate.content.cloneNode(true));
});

sectionsContainer.addEventListener('click', function (event) {
if (event.target.classList.contains('remove-section-btn')) {
event.target.closest('.description-section-row').remove();
}
});
});
5 changes: 2 additions & 3 deletions app/templates/main/managePositions.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ <h1 class="text-center">{{ department_name }} Positions</h1>
<td>{{ position.wls }}</td>
<td>{{ position.revisionDate }}</td>
<td>
<a href="/department/{{ department.ORG }}/{{ department.ACCOUNT }}/positions/{{ position.positionCode }}"
class="btn btn-success view-btn">View</a>
<button class="btn btn-primary request-btn" data-position-id="{{ position.id }}">Revise Position</button>
<a href="{{ url_for('main.postionDescription', org=department.ORG, account=department.ACCOUNT, positionCode=position.positionCode) }}" class="btn btn-success">View</a>
<a href="{{ url_for('main.revisePosition', org=department.ORG, account=department.ACCOUNT, positionCode=position.positionCode) }}" class="btn btn-primary">Revise Position</a>
Comment thread
NYABUTOA marked this conversation as resolved.
</td>
</tr>
{% endfor %}
Expand Down
105 changes: 105 additions & 0 deletions app/templates/main/revisepositionpage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{% extends "base.html" %}

{% block scripts %}
{{ super() }}
<script type="text/javascript" src="{{ url_for('static', filename='js/revisepositionpage.js') }}?u={{ lastStaticUpdate }}"></script>
<link rel="stylesheet" type="text/css" href="/static/css/individualPositions.css?u={{ lastStaticUpdate }}" />
<link rel="stylesheet" type="text/css" href="/static/css/revisepositionpage.css?u={{ lastStaticUpdate }}" />
{% endblock %}

{% block app_content %}
<div class="department-header-container">
<h1 class="department-header">Revise {{ position.positionTitle }}</h1>
</div>

<div class="container-fluid position-container">
<div class="row">
<div class="col-12">

<form method="POST" action="{{ url_for('main.revisePosition', org=department.ORG, account=department.ACCOUNT, positionCode=position.positionCode) }}">

<div class="position-information">
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="positionTitle">Position Title:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="positionTitle" name="positionTitle" value="{{ position.positionTitle }}" required>
</div>
</div>

<div class="form-group row">
<label class="col-sm-3 col-form-label">Position Code:</label>
<div class="col-sm-9">
<p class="form-control-static">{{ position.positionCode }}</p>
</div>
</div>

<div class="form-group row">
<label class="col-sm-3 col-form-label" for="wls">WLS Level:</label>
<div class="col-sm-9">
<input type="number" class="form-control" id="wls" name="wls" min="0" value="{{ position.wls }}" required>
</div>
</div>

<div class="form-group row">
<label class="col-sm-3 col-form-label">Last Revision Date:</label>
<div class="col-sm-9">
<p class="form-control-static">{{ position.revisionDate }}</p>
</div>
</div>

<div class="form-group row">
<label class="col-sm-3 col-form-label">Revised By:</label>
<div class="col-sm-9">
<p class="form-control-static">{{ position.revisedBy }}</p>
</div>
</div>
</div>

<h3 class="description-header">Description</h3>
<section id="sectionsContainer">
{%- for section in sections %}
<div class="description-section-row">
<div class="form-group">
<label>Section Title</label>
<input type="text" class="form-control" name="sectionTitle[]" value="{{ section.sectionTitle }}">
</div>
<div class="form-group">
<label>Section Content</label>
<textarea class="form-control" name="sectionContent[]" rows="4">{{ section.sectionContent }}</textarea>
</div>
<button type="button" class="btn btn-danger btn-sm remove-section-btn">Remove Section</button>
</div>
{%- endfor %}
</section>

<button type="button" id="addSectionBtn" class="btn btn-default">Add Section</button>

<div class="row revise-actions">
<div class="col-xs-12 text-left">
<a href="{{ url_for('main.managePositions', org=department.ORG, account=department.ACCOUNT) }}" class="btn btn-default">
Cancel
</a>
<button type="submit" class="btn btn-primary">Save Revision</button>
</div>
</div>

</form>

</div>
</div>
</div>

<template id="sectionRowTemplate">
<div class="description-section-row">
<div class="form-group">
<label>Section Title</label>
<input type="text" class="form-control" name="sectionTitle[]" value="">
</div>
<div class="form-group">
<label>Section Content</label>
<textarea class="form-control" name="sectionContent[]" rows="4"></textarea>
</div>
<button type="button" class="btn btn-danger btn-sm remove-section-btn">Remove Section</button>
</div>
</template>
{% endblock %}