Skip to content

Commit 2d9e9f5

Browse files
Merge pull request #68 from ComputerScienceHouse/conditional-form
Add conditional creation and actions
2 parents dcd7890 + 36e386f commit 2d9e9f5

File tree

9 files changed

+196
-53
lines changed

9 files changed

+196
-53
lines changed

conditional/blueprints/conditional.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def create_conditional():
6161

6262
uid = post_data['uid']
6363
description = post_data['description']
64-
due_date = datetime.strptime(post_data['due_date'], "%Y-%m-%d")
64+
due_date = datetime.strptime(post_data['dueDate'], "%Y-%m-%d")
6565

6666
db.session.add(Conditional(uid, description, due_date))
6767
db.session.flush()
@@ -97,3 +97,21 @@ def conditional_review():
9797
db.session.flush()
9898
db.session.commit()
9999
return jsonify({"success": True}), 200
100+
101+
102+
@conditionals_bp.route('/conditionals/delete/<cid>', methods=['DELETE'])
103+
def conditional_delete(cid):
104+
log = logger.new(user_name=request.headers.get("x-webauth-user"),
105+
request_id=str(uuid.uuid4()))
106+
log.info('api', action='delete conditional')
107+
108+
user_name = request.headers.get('x-webauth-user')
109+
if ldap_is_eval_director(user_name):
110+
Conditional.query.filter(
111+
Conditional.id == cid
112+
).delete()
113+
db.session.flush()
114+
db.session.commit()
115+
return jsonify({"success": True}), 200
116+
else:
117+
return "Must be evals director to delete!", 401
Lines changed: 81 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,90 @@
11
{% extends "nav.html" %}
22
{% block title %}
3-
Conditionals
4-
{% endblock %}
5-
{% block extraFooter %}
6-
<script src="../static/js/conditional.js"></script>
3+
Conditionals
74
{% endblock %}
85
{% block body %}
9-
<div class="container main">
10-
<div class="panel panel-default">
11-
<div class="panel-heading">
12-
<h3 class="panel-title">Conditionals</h3>
6+
<div class="container main">
7+
<div class="panel panel-default">
8+
<div class="panel-heading">
9+
<h3 class="panel-title">
10+
Conditionals
11+
{% if is_eval_director %}
12+
<button type="button" class="btn btn-primary btn-sm btn-conditional pull-right" data-toggle="modal" data-target="#createConditional">
13+
<span class="glyphicon glyphicon-plus"></span> Add
14+
</button>
15+
{% endif %}
16+
</h3>
17+
</div>
18+
<div class="panel-body table-fill">
19+
<div class="table-responsive">
20+
{% if conditionals_len == 0 %}
21+
<div class="alert alert-info" style="margin:15px;">No conditionals.</div>
22+
{% else %}
23+
<table class="table table-striped no-bottom-margin" data-module="table">
24+
<thead>
25+
<tr>
26+
<th>Name</th>
27+
<th>Date Created</th>
28+
<th>Date Due</th>
29+
<th>Description</th>
30+
{% if is_eval_director %}
31+
<th>Actions</th>
32+
{% endif %}
33+
</tr>
34+
</thead>
35+
<tbody>
36+
{% for c in conditionals %}
37+
<tr id="conditional-{{ c['id'] }}" conditional_id="{{ c['id'] }}">
38+
<td>{{ c['name'] }}</td>
39+
<td>{{ c['date_created'] }}</td>
40+
<td>{{ c['date_due'] }}</td>
41+
<td>{{ c['description'] }}</td>
42+
{% if is_eval_director %}
43+
<td data-module="conditionalActions" data-id="{{ c['id'] }}">
44+
<button role="button" class="btn btn-sm btn-success" data-action="pass">Pass</button>
45+
<button role="button" class="btn btn-sm btn-danger" data-action="fail">Fail</button>
46+
<button role="button" class="btn btn-sm btn-default" data-action="delete"><span class="glyphicon glyphicon-trash"></span> Delete</button>
47+
</td>
48+
{% endif %}
49+
</tr>
50+
{% endfor %}
51+
</tbody>
52+
</table>
53+
{% endif %}
54+
</div>
55+
</div>
1356
</div>
14-
<div class="panel-body table-fill">
15-
<div class="table-responsive">
16-
{% if conditionals_len == 0 %}
17-
<div class="alert alert-info" style="margin:15px;">No conditionals.</div>
18-
{% else %}
19-
<table class="table table-striped no-bottom-margin">
20-
<tbody id="conditionals">
21-
<tr>
22-
<th>Name</th>
23-
<th>Date Created</th>
24-
<th>Date Due</th>
25-
<th>Description</th>
26-
{% if is_eval_director %}
27-
<th>Controls</th>
28-
{% endif %}
29-
</tr>
30-
<!-- ng-repeat="conditional in conditionals.data"-->
31-
{% for c in conditionals %}
32-
<tr id="conditional-{{c['id']}}" conditional_id="{{c['id']}}">
33-
<td>{{c['name']}}</td> <!-- If showing all users -->
34-
<td>{{c['date_created']}}</td>
35-
<td>{{c['date_due']}}</td>
36-
<td>{{c['description']}}</td>
37-
{% if is_eval_director %}
38-
<th>
39-
<button role="button" class="btn btn-raised btn-primary btn-success" style="width:100%;" id="pass-{{c['id']}}">
40-
Pass
41-
</button>
42-
<button role="button" class="btn btn-raised btn-primary btn-danger" style="width:100%;" id="fail-{{c['id']}}">
43-
Fail
44-
</button>
57+
</div>
58+
<div class="modal fade" id="createConditional" tabindex="-1">
59+
<div class="vertical-alignment-helper">
60+
<div class="modal-dialog vertical-align-center">
61+
<div class="modal-content">
62+
<div class="modal-header">
63+
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
64+
<h4 class="modal-title" id="editUserTitle">Conditional</h4>
65+
</div>
66+
<form data-module="conditionalForm" method="post">
67+
<div class="modal-body">
68+
<div class="row user-edit-row">
69+
<label class="control-label" for="memberName">Member Name</label>
70+
<select name="uid" id="memberName" class="form-control" data-module="memberSelect" data-src="cm_members"></select>
71+
</div>
4572

46-
</th>
47-
{% endif %}
48-
</tr>
49-
{% endfor %}
50-
</tbody>
51-
</table>
52-
{% endif %}
73+
<div class="row user-edit-row">
74+
<label class="control-label" for="due_date">Due Date</label>
75+
<input type="text" id="due_date" name="due_date" class="form-control" data-module="datepicker" />
76+
</div>
77+
<div class="row user-edit-row">
78+
<label class="control-label" for="requirement">Requirement</label>
79+
<input type="text" class="form-control" id="requirement" name="description">
80+
</div>
81+
</div>
82+
<div class="modal-footer">
83+
<input type="submit" class="btn btn-primary" value="Create">
84+
</div>
85+
</form>
5386
</div>
5487
</div>
5588
</div>
56-
<div >
57-
</div>
58-
{% endblock %}
89+
</div>
90+
{% endblock %}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import FetchUtil from '../utils/fetchUtil';
2+
3+
export default class ConditionalActions {
4+
constructor(actions) {
5+
this.actions = actions;
6+
this.id = this.actions.dataset.id;
7+
this.endpoint = '/conditionals/review';
8+
this.deleteEndpoint = '/conditionals/delete/' + this.id;
9+
this.render();
10+
}
11+
12+
render() {
13+
this.actions.querySelectorAll('button').forEach(btn => {
14+
btn.addEventListener('click', e => this._handleAction(e));
15+
});
16+
}
17+
18+
_handleAction(e) {
19+
const action = e.target.dataset.action;
20+
21+
if (action === "delete") {
22+
FetchUtil.fetchWithWarning(this.deleteEndpoint, {
23+
method: 'DELETE',
24+
warningText: "Are you sure you want to delete this conditional?",
25+
successText: "The conditional has been deleted."
26+
}, () => {
27+
$(e.target.closest("tr")).hide();
28+
});
29+
} else {
30+
const actionExt = (action === "pass") ? "Passed" : "Failed";
31+
32+
let payload = {
33+
id: this.id,
34+
status: actionExt
35+
};
36+
37+
FetchUtil.postWithWarning(this.endpoint, payload, {
38+
warningText: "Are you sure you want to " + action +
39+
" this conditional?",
40+
successText: "The conditional has been marked as " +
41+
actionExt.toLowerCase() + "."
42+
});
43+
}
44+
}
45+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import FetchUtil from "../utils/fetchUtil";
2+
3+
export default class ConditionalForm {
4+
constructor(form) {
5+
this.form = form;
6+
this.endpoint = '/conditionals/create';
7+
this.render();
8+
}
9+
10+
render() {
11+
this.form.querySelector('input[type=submit]')
12+
.addEventListener('click', e => this._submitForm(e));
13+
}
14+
15+
_submitForm(e) {
16+
e.preventDefault();
17+
18+
let payload = {
19+
uid: this.form.querySelector('select[name=uid]').value,
20+
description: this.form.querySelector('input[name=description]').value,
21+
dueDate: this.form.querySelector('input[name=due_date]').value
22+
};
23+
24+
FetchUtil.postWithWarning(this.endpoint, payload, {
25+
warningText: "Are you sure you want to create this conditional?",
26+
successText: "The conditional has been created."
27+
}, () => {
28+
$(this.form.closest('.modal')).modal('hide');
29+
location.reload();
30+
});
31+
}
32+
}

frontend/javascript/modules/majorProjectStatus.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class MajorProjectStatus {
1010
this.control = control;
1111
this.id = this.control.dataset.id;
1212
this.endpoint = '/major_project/review';
13-
this.deleteEndpoint = '/major_project/delete/';
13+
this.deleteEndpoint = '/major_project/delete/' + this.id;
1414
this.render();
1515
}
1616

@@ -33,7 +33,7 @@ export default class MajorProjectStatus {
3333

3434
_changeStatus(option) {
3535
if (option === "Delete") {
36-
FetchUtil.fetchWithWarning(this.deleteEndpoint + this.id, {
36+
FetchUtil.fetchWithWarning(this.deleteEndpoint, {
3737
method: 'DELETE',
3838
warningText: 'This action cannot be undone.',
3939
successText: 'Major project deleted.'

frontend/javascript/modules/memberSelect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default class MemberSelect {
3535
}
3636

3737
render() {
38-
window.$(this.element).selectize({
38+
$(this.element).selectize({
3939
persist: false,
4040
openOnFocus: false,
4141
closeAfterSelect: true,

frontend/stylesheets/components/_flat-buttons.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ $btn-flat-hover-bg: rgba(153, 153, 153, .2);
1818
box-shadow: 2px 2px 4px rgba(0, 0, 0, .4);
1919
background: darken($btn-flat-hover-bg, 20%) radial-gradient(circle, #7a1158 10%, #b0197e 11%) no-repeat;
2020
background-size: 1000% 1000%;
21+
color: #fff;
2122
}
2223
}

frontend/stylesheets/components/_select.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ $selectize-arrow-offset: $selectize-padding-x + 5px !default;
145145
}
146146
}
147147

148+
&.single {
149+
.item,
150+
input {
151+
margin-top: 11px !important;
152+
font-size: 16px;
153+
}
154+
}
155+
148156
&.form-control {
149157
@include selectize-border-radius (0);
150158
@include selectize-box-shadow (inset 0 -1px 0 #ddd);

frontend/stylesheets/pages/_evals.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@
5353
text-align: center;
5454
}
5555
}
56+
57+
.btn-conditional {
58+
float: right;
59+
margin-top: -4px;
60+
box-shadow: none;
61+
padding: 3px 7px;
62+
}

0 commit comments

Comments
 (0)