Skip to content

Commit 13f7da4

Browse files
committed
Fix the teachers bulk creation page
1 parent 16e75d0 commit 13f7da4

File tree

4 files changed

+55
-45
lines changed

4 files changed

+55
-45
lines changed

static/scss/snapcloud.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
--navbar-height: 64px;
1919
/* this is the minimum I think w/ all 5 columns of links */
2020
--estimated-footer-height: 450px;
21+
--white-hamburger: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath strok;e='rgba%28255,255,255,1%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
2122
}
2223

2324
// We often use 1/5 width items.
@@ -34,7 +35,7 @@
3435
[data-bs-theme=dark] {
3536
/* Ensure the hamburger icon is solid white. Seems to be no easier way to fix this. */
3637
& .navbar-toggler-icon {
37-
--bs-navbar-toggler-icon-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 1%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
38+
--bs-navbar-toggler-icon-bg: var(--white-hamburger);
3839
}
3940
}
4041

static/style/compiled/snapcloud.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/style/compiled/snapcloud.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

views/teacher/bulk.etlua

+51-42
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h1><%- locale.get('bulk_tile') %></h1>
44

55
<div class="row">
6-
<div class="col js-bulkCreation">
6+
<div class="col">
77
<p><%- locale.get('bulk_text') %></p>
88
<div>
99
<p>Example:</p>
@@ -15,7 +15,8 @@ myclass-student2,sentences-make-good-passwords</pre>
1515
</div>
1616
</div>
1717

18-
<div class="row">
18+
<!-- This section contains all the controls used for JS / manipulating CSVs, etc. -->
19+
<div class="row js-bulkCreation">
1920
<div class="col-md-6 col-sm-12">
2021
<p><strong>Upload a CSV file:</strong></p>
2122
<div class="input-group mb-3">
@@ -30,7 +31,7 @@ myclass-student2,sentences-make-good-passwords</pre>
3031
style="font-family: monospace"></textarea>
3132
</details>
3233
<p>
33-
<div class="form-check form-switch">
34+
<div class="form-check form-switch js-createCollection">
3435
<input id="add_collection"
3536
type="checkbox" class="add-collection form-check-input" name="add_collection"
3637
onchange="document.querySelector('div.collection').hidden =
@@ -45,49 +46,57 @@ myclass-student2,sentences-make-good-passwords</pre>
4546
<input id="collection_name" name="collection_name" class="collection_name form-control" />
4647
</div>
4748
</p>
48-
<button class="btn btn-primary" onclick="
49-
var div = document.querySelector('div.js-bulkCreation'),
50-
collection_name =
51-
div.querySelector('input.add-collection').checked ?
52-
div.querySelector('.collection_name').value :
53-
null,
54-
file = div.querySelector('.csv').files[0],
55-
csv_text = div.querySelector('#csv_text').value;
56-
57-
if (file) {
58-
file.text().then(data => processCSV(data));
59-
} else if (csv_text) {
60-
processCSV(csv_text);
61-
}
62-
63-
function processCSV (csv_data) {
64-
if (csv_data.substring(0,8) !== 'username') {
65-
csv_data = 'username,password\n' + csv_data;
66-
}
67-
Papa.parse(
68-
csv_data,
69-
{
70-
skipEmptyLines: true,
71-
header: true,
72-
complete: (results) => {
73-
let post_body = { users: results.data };
74-
if (collection_name) {
75-
post_body.collection_name = collection_name;
76-
}
77-
cloud.post(
78-
'/users/create_learners',
79-
null,
80-
post_body
81-
);
82-
}
83-
}
84-
);
85-
};
86-
"><%- locale.get('bulk_create') %></button>
49+
<button type="button"
50+
class="btn btn-primary js-createLearners"><%- locale.get('bulk_create') %></button>
8751
<script>
8852
document.querySelector('div.collection').hidden =
8953
!document.querySelector('input.add-collection').checked;
9054
</script>
9155
</div>
9256
</div>
9357
</div>
58+
59+
<script type="text/javascript">
60+
window.onload = () => {
61+
let create_learners = function() {
62+
var div = document.querySelector('div.js-bulkCreation'),
63+
collection_name =
64+
div.querySelector('input.add-collection').checked ?
65+
div.querySelector('.collection_name').value :
66+
null,
67+
file = div.querySelector('.csv').files[0],
68+
csv_text = div.querySelector('#csv_text').value;
69+
70+
if (file) {
71+
file.text().then(data => processCSV(data));
72+
} else if (csv_text) {
73+
processCSV(csv_text);
74+
}
75+
76+
function processCSV (csv_data) {
77+
if (csv_data.trim().substring(0,8) !== 'username') {
78+
csv_data = 'username,password\n' + csv_data;
79+
}
80+
Papa.parse(
81+
csv_data,
82+
{
83+
skipEmptyLines: true,
84+
header: true,
85+
complete: (results) => {
86+
let post_body = { users: results.data };
87+
if (collection_name) {
88+
post_body.collection_name = collection_name;
89+
}
90+
cloud.post(
91+
'/users/create_learners',
92+
null,
93+
post_body
94+
);
95+
}
96+
}
97+
);
98+
};
99+
};
100+
document.querySelector('.js-createLearners').addEventListener('click', create_learners);
101+
}
102+
</script>

0 commit comments

Comments
 (0)