Skip to content

Commit 36e386f

Browse files
Added functionality to conditional form and actions
1 parent d7d858f commit 36e386f

File tree

9 files changed

+146
-51
lines changed

9 files changed

+146
-51
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

conditional/templates/conditional.html

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
{% block title %}
33
Conditionals
44
{% endblock %}
5-
{% block extraFooter %}
6-
<script src="../static/js/conditional.js"></script>
7-
{% endblock %}
85
{% block body %}
96
<div class="container main">
107
<div class="panel panel-default">
118
<div class="panel-heading">
129
<h3 class="panel-title">
1310
Conditionals
1411
{% if is_eval_director %}
15-
<button type="button" class="btn btn-primary btn-sm btn-conditional" data-toggle="modal" data-target="#createConditional">
12+
<button type="button" class="btn btn-primary btn-sm btn-conditional pull-right" data-toggle="modal" data-target="#createConditional">
1613
<span class="glyphicon glyphicon-plus"></span> Add
1714
</button>
1815
{% endif %}
@@ -23,36 +20,31 @@ <h3 class="panel-title">
2320
{% if conditionals_len == 0 %}
2421
<div class="alert alert-info" style="margin:15px;">No conditionals.</div>
2522
{% else %}
26-
<table class="table table-striped no-bottom-margin">
27-
<tbody id="conditionals">
28-
<tr>
29-
<th>Name</th>
30-
<th>Date Created</th>
31-
<th>Date Due</th>
32-
<th>Description</th>
33-
{% if is_eval_director %}
34-
<th>Controls</th>
35-
{% endif %}
36-
</tr>
37-
<!-- ng-repeat="conditional in conditionals.data"-->
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>
3836
{% for c in conditionals %}
3937
<tr id="conditional-{{ c['id'] }}" conditional_id="{{ c['id'] }}">
40-
<td>{{ c['name'] }}</td> <!-- If showing all users -->
38+
<td>{{ c['name'] }}</td>
4139
<td>{{ c['date_created'] }}</td>
4240
<td>{{ c['date_due'] }}</td>
4341
<td>{{ c['description'] }}</td>
4442
{% if is_eval_director %}
45-
<th>
46-
<button role="button" class="btn btn-raised btn-primary btn-success"
47-
style="width:100%;" id="pass-{{ c['id'] }}">
48-
Pass
49-
</button>
50-
<button role="button" class="btn btn-raised btn-primary btn-danger"
51-
style="width:100%;" id="fail-{{ c['id'] }}">
52-
Fail
53-
</button>
54-
55-
</th>
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>
5648
{% endif %}
5749
</tr>
5850
{% endfor %}
@@ -71,26 +63,26 @@ <h3 class="panel-title">
7163
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
7264
<h4 class="modal-title" id="editUserTitle">Conditional</h4>
7365
</div>
74-
<div class="modal-body">
75-
<div class="row user-edit-row">
76-
<label class="control-label" for="memberName">Member Name</label>
77-
<input type="text" name="attendees" class="form-control" data-module="memberSelect" data-src="cm_members"/>
78-
</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>
7972

80-
<div class="row user-edit-row">
81-
<label class="control-label" for="memberName">Due Date</label>
82-
<input type="text" name="date" class="form-control" value="{{ date }}" data-module="datepicker" />
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>
8381
</div>
84-
<div class="row user-edit-row">
85-
<label class="control-label" for="memberName">Requirement</label>
86-
<input class="form-control" id="memberName" name="name" type="text">
82+
<div class="modal-footer">
83+
<input type="submit" class="btn btn-primary" value="Create">
8784
</div>
88-
</div>
89-
<div class="modal-footer">
90-
<button type="button" class="btn btn-success save-btn pull-left">Pass</button>
91-
<button type="button" class="btn btn-danger save-btn pull-left">Fail</button>
92-
<button type="button" class="btn btn-primary save-btn">Save</button>
93-
</div>
85+
</form>
9486
</div>
9587
</div>
9688
</div>
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
.btn-conditional {
5858
float: right;
5959
margin-top: -4px;
60-
padding: 3px 7px;
6160
box-shadow: none;
62-
61+
padding: 3px 7px;
6362
}

0 commit comments

Comments
 (0)