Skip to content

Commit b2a0066

Browse files
committed
Got a working username dropdown that now has better formatting and checks the current user
1 parent 7107971 commit b2a0066

7 files changed

Lines changed: 171 additions & 89 deletions

File tree

api/API/collaborators.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from api.everything import *
2-
from faculty import get_faculty_by_bnumbers
2+
from faculty import *
33

44

55
def getAllCollaborators():
@@ -53,6 +53,8 @@ def getCollaboratorsByProjectId (pID):
5353
else:
5454
return None
5555

56+
57+
# used in AwardLetters
5658
@app.route ("/urcpp/v1/collaborators/get/<username>", methods = ["POST"])
5759
def collaborators_get (username):
5860
""" gets the collaborators of a user
@@ -130,15 +132,15 @@ def delete_non_collaborators(project_id, *collaborators):
130132
).execute()
131133

132134

133-
def add_collaborators(project_id, *collaborator_bnumbers):
135+
def add_collaborators(project_id, *collaborator_usernames):
134136
""" add the collaborators from collaborator bnumbers
135137
136138
Args:
137139
project_id (int): the id of the project that the collabors belong to
138140
collaborator_bnumbers (splat): the collaborators that will be the current collaborators
139141
"""
140142

141-
faculty = get_faculty_by_bnumbers(collaborator_bnumbers)
143+
faculty = getLDAPFaculty(collaborator_usernames)
142144

143145
for professor in faculty:
144146
if get_collaborator(project_id, professor.username) is None:

api/pages/collaborations.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from api.everything import *
22
from ..API.projects import getProject
33
from ..API.collaborators import *
4-
from ..API.faculty import *
5-
6-
7-
4+
from ..API.faculty import getLDAPFaculty
85

96
@app.route("/collaborations", methods = ["POST"])
107
@login_required
@@ -63,7 +60,7 @@ def update_collaborators ():
6360

6461
proj = getProject(g.user.username)
6562

66-
submitted_usernames = request.form.getlist("username[]") #Hailey I think we need this in order for ou
63+
submitted_usernames = request.form.getlist("username[]")
6764

6865
add_collaborators(proj.pID, submitted_usernames)
6966

@@ -73,33 +70,31 @@ def update_collaborators ():
7370

7471
return redirect ( url_for( "irbyn_GET" ))
7572

73+
74+
75+
76+
77+
7678
@app.route("/check_username", methods = ["POST"])
7779
@login_required
7880
def check_username():
79-
"""This function checks to see if a bnumber exists.
81+
"""This function checks to see if a username exists.
8082
It checks the LDAPFaculty table and if finds a User
81-
it marks the bnum as good.
83+
it marks the u_num as good.
8284
Args:
8385
username (str): the user who is currently accessing the application
84-
bnum (str): POST the number that needs to be checked
86+
u_num (str): POST the username that needs to be checked
8587
8688
Returns:
8789
JSON: response that is either OK or NOTFOUND
8890
"""
8991
username = request.json['u_name']
90-
#if bnumber[0] == "b":
91-
# bnumber = "B" + bnumber[1:]
92-
# print ("Replaced Bnum: " + bnumber)
93-
# We are assuming BNumbers are less than 10 characters
94-
if (len(bnumber) < 12) and (bnumber.find("B") == 0):
95-
facQ = (LDAPFaculty.select()
96-
.where (LDAPFaculty.bnumber == bnumber)
97-
)
98-
if facQ.exists():
99-
if facQ[0].username == g.user.username:
100-
return jsonify({"response" : "USER"})
101-
return jsonify({ "response" : "OK" })
102-
else:
103-
return jsonify({ "response" : "NOTFOUND" })
92+
93+
facQ = (LDAPFaculty.select())
94+
95+
if facQ.exists():
96+
if facQ[0].username == g.user.username:
97+
return jsonify({"response" : "USER"})
98+
return jsonify({ "response" : "OK" })
10499
else:
105100
return jsonify({ "response" : "NOTFOUND" })

api/pages/people.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
from ..API.projects import getProject
33
from ..API.collaborators import delete_all_collaborators, getCollaborators
44

5+
@app.route("/deleteCollabs", methods = ["POST", "GET"])
6+
@login_required
7+
def deleteCollabs():
8+
#Function made solely to delete collaborators
9+
10+
delete_all_collaborators(proj.pID)
11+
return redirect(url_for("collaborations_GET"))
512

613

714
@app.route("/people", methods = ["GET"])

api/static/css/collaborations.css

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
select {
2+
text-transform:lowercase
3+
width: 200px;
4+
height: 30px;
5+
background-color: #141414 !important;
6+
border-style: solid;
7+
border-left-width: 3px;
8+
border-left-color: #00DDDD;
9+
border-top: none;
10+
border-bottom: none;
11+
border-right: none; ,
12+
color: white;
13+
font-size: 18px;
14+
font-weight: 200;
15+
padding-left: 6px;
16+
-webkit-appearance: none;
17+
-moz-appearance: none;
18+
appearance: none;
19+
}
20+
.selectpicker{
21+
width: 200px;
22+
height: 30px;
23+
background-color: #141414 !important;
24+
border-style: solid;
25+
border-left-width: 3px;
26+
border-left-color: #00DDDD;
27+
border-top: none;
28+
border-bottom: none;
29+
border-right: none;
30+
color: white;
31+
font-size: 18px;
32+
font-weight: 200;
33+
padding-left: 6px;
34+
-webkit-appearance: none;
35+
-moz-appearance: none;
36+
appearance: none;
37+
}
38+
select::-ms-expand { /* for IE 11 */
39+
display: none;
40+
}
41+
.selectpicker form-controls {
42+
width: 200px;
43+
height: 30px;
44+
background-color: #141414 !important;
45+
border-style: solid;
46+
border-left-width: 3px;
47+
border-left-color: #00DDDD;
48+
border-top: none;
49+
border-bottom: none;
50+
border-right: none;
51+
color: white;
52+
font-size: 18px;
53+
font-weight: 200;
54+
padding-left: 6px;
55+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
api = urcpp("v1")
2+
0
3+
// In milliseconds
4+
var USERNAMECHECKDELAY = 250;
5+
6+
var numCollabsChecked = 0;
7+
8+
var delay = (function(){
9+
var timer = 0;
10+
return function(callback, ms){
11+
clearTimeout (timer);
12+
timer = setTimeout(callback, ms);
13+
};
14+
})();
15+
16+
function setUsernameStatus (id) {
17+
return function (data) {
18+
// console.log("Response: " + data["response"]);
19+
// console.log("BNumber Status: " + JSON.stringify(data));
20+
var selector = "#cgroup" + id;
21+
var wrong_alert = '<div class="alert alert-danger col-sm-4" id="wrong-id-'+id+'"role="alert">Faculty Not Found</div>'
22+
var user_alert = '<div class="alert alert-danger col-sm-4" id="user-'+id+'"role="alert">You are already a collaborator</div>'
23+
$('#user-'+id).remove()
24+
$('#wrong-id-'+id).remove();
25+
if (data["response"] == "OK") {
26+
$(selector).removeClass("has-error");
27+
$(selector).addClass("has-success");
28+
numCollabsChecked += 1;
29+
// console.log(numCollabsChecked);
30+
/* global numCollabs */
31+
if (numCollabsChecked >= numCollabs) {
32+
// console.log("Probably enough good B-numbers"); //This is a weak solution.
33+
//If the user deletes a good B-number and re-enters another good B-numb
34+
// (same or different), they could potentially leave a B-number box blank
35+
// Instead, a better solution should actually check the dom for all $(selector)'s
36+
// and ensure they all have the class "has-success" applied'
37+
$("#submit").prop('disabled', false);
38+
}
39+
} else if (data["response"] == "USER") {
40+
$(selector).removeClass( "has-success");
41+
$(selector).addClass("has-error");
42+
$(selector).append(user_alert);
43+
44+
} else {
45+
$(selector).removeClass("has-success");
46+
$(selector).addClass("has-error");
47+
$(selector).append(wrong_alert);
48+
}
49+
};};
50+
51+
function checkValidUsername (id) {
52+
/* global api */
53+
var username = $("#cusername" + id);
54+
console.log("About to check " + username);
55+
56+
var post = aja()
57+
.method ('POST')
58+
.url ("/check_username")
59+
.body({ 'u_name' : username })
60+
.type('json')
61+
.on ('success', setUsernameStatus(id) )
62+
.go();
63+
64+
};

api/templates/pages/collaborations.html

Lines changed: 16 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{% set currentPage = "Collaborations" %}
44

55
{% block body %}
6+
67
<ol class="breadcrumb">
78
<li><a href="/">Home</a></li>
89
<li><a href="/create">Create</a></li>
@@ -21,86 +22,44 @@ <h1>Faculty Collaborator(s) </h1>
2122
method = "POST"
2223
>
2324

24-
<!-- <form action="/addCommitteeMember" method="post">
25-
<select class="selectpicker form-control" data-role="chosen" id="addCommitteeMember" multiple="" name="addCommitteeMember">
26-
{% for committeeMember in notCommittee %}
27-
<option value="{{committeeMember.fID}}">{{committeeMember.firstname}} {{committeeMember.lastname}}</option>
28-
{% endfor %}
29-
</select>
30-
31-
-->
32-
3325
{% for id in range (0, numCollab) %}
3426
<div class = 'form-group' id = "cgroup{{id}}" style="margin-left:100px;">
3527
<h4> <b> Collaborator #{{id + 1}} </b> </h4>
36-
37-
<label for='firstname{{id}}' class = 'col-sm-2 control-label'>
38-
First Name:
39-
</label>
40-
<div class = 'col-sm-7'>
41-
<input name = 'firstname[]'
42-
id = 'firstname{{id}}'
43-
type = 'text'
44-
class = 'form-control'
45-
placeholder = 'John'
46-
required
47-
/>
48-
</div>
49-
</div>
50-
51-
<div class = 'form-group' id = "cgroup{{id}}" style="margin-left:100px;">
52-
<label for='lastname{{id}}' class = 'col-sm-2 control-label'>
53-
Last Name:
54-
</label>
55-
<div class = 'col-sm-7'>
56-
<input name = 'lastname[]'
57-
id = 'lastname{{id}}'
58-
type = 'text'
59-
class = 'form-control'
60-
placeholder = 'Doe'
61-
required
62-
/>
63-
</div>
64-
</div>
28+
</div>
6529

6630
<div class = 'form-group' id = "cgroup{{id}}" style = "margin-left:100px;">
6731
<label for='username{{id}}' class = 'col-sm-2 control-label'>
6832
Username:
6933
</label>
7034
<div class = 'col-sm-7'>
71-
<select class = "selectpicker form-control" data-live-search="true" id = "getCollabUsernames" name = "getCollabUsernames">
72-
<option disabled selected> --- </option>
35+
<select required class = "selectpicker form-control" data-live-search="true" id = "getCollabUsernames" name = "getCollabUsernames" data-style="btn-primary">
36+
<option disabled selected value=""> doej; Jane Doe </option>
7337
{% for faculty in allFaculty %}
74-
{% if faculty.lastname != "" %}
75-
<option value="{{faculty.fID}}">{{faculty.username}}</option>
76-
<!-- <option value="" disabled selected>doej</option> -->
38+
{% if faculty.lastname != "" %} <!-- needed to remove test users -->
39+
{% if faculty.username != g.user.username %}
40+
<option title={{faculty.username}} value="{{faculty.fID}}">{{faculty.username}}; {{faculty.firstname}} {{faculty.lastname}}</option>
41+
{% endif %}
7742
{% endif %}
7843
{% endfor %}
7944
</select>
80-
<!-- <input name = 'username[]'
81-
id = 'username{{id}}'
82-
type = 'text'
83-
class = 'form-control'
84-
placeholder = 'doej'
85-
required
86-
/> -->
8745
</div>
8846
</div>
8947
{% endfor %}
9048

9149
<div class="row">
9250
<div class = "form-group" >
9351
<div class = "col-sm-1">
94-
<input type="button" value="Back" onclick="window.history.back()" class="btn btn-primary"/>
52+
<input type="button" value="Back" onclick="window.history.back()" class="btn btn-succeess"/>
9553
</input>
9654
</div>
9755

9856

9957
<div class = "col-sm-offset-9 col-sm-2" id = "submitButton">
10058
<button id = "submit"
10159
type = "submit"
102-
class="btn btn-block btn-primary form-control"
103-
type="submit"/>
60+
class="btn btn-block btn-success form-control"
61+
type="submit"
62+
/>
10463
Submit
10564
</button>
10665
</div>
@@ -115,12 +74,6 @@ <h4> <b> Collaborator #{{id + 1}} </b> </h4>
11574

11675

11776

118-
119-
120-
121-
122-
123-
12477
<script>
12578
var numCollabs = parseInt("{{numCollab}}");
12679
var username = "{{username}}";
@@ -130,11 +83,11 @@ <h4> <b> Collaborator #{{id + 1}} </b> </h4>
13083
{% block footer_imports %}
13184
{% for id in range (0, numCollab) %}
13285
<script type = "text/javascript">
133-
/* global delay, checkValidBNumber, BNUMBERCHECKDELAY */
134-
$("#cbnumber{{id}}").keyup ( function() {
86+
/* global delay, checkValidUsername, USERNAMECHECKDELAY */
87+
$("#cusername {{id}}").keyup ( function() {
13588
delay( function () {
136-
checkValidBNumber("{{id}}");
137-
}, BNUMBERCHECKDELAY);
89+
checkValidUsername("{{id}}");
90+
}, USERNAMECHECKDELAY);
13891
});
13992
</script>
14093
{% endfor %}

0 commit comments

Comments
 (0)