Skip to content

Commit

Permalink
added latter pages to admin panel and basic edit pages
Browse files Browse the repository at this point in the history
  • Loading branch information
desmatter authored and jnoowin committed May 24, 2021
1 parent 2f92858 commit 6775df5
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 85 deletions.
12 changes: 12 additions & 0 deletions models/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ function getDailyTasks(courseID, callback) {
let db = client.db(config.mongoDBs[courseID]);
db.collection("daily_task")
.find()
.sort({ _id: 1 })
.toArray()
.then((data) => callback(null, data))
.catch((err) => callback(err, null));
}

function getLuckyBonuses(courseID, callback) {
let db = client.db(config.mongoDBs[courseID]);
db.collection("lucky_bonuses")
.find()
.sort({ _id: 1 })
.toArray()
.then((data) => callback(null, data))
.catch((err) => callback(err, null));
Expand Down Expand Up @@ -158,6 +169,7 @@ module.exports = {
getHomepageUpdates,
getHomepageVideos,
getDailyTasks,
getLuckyBonuses,
getModule,
getModules,
getUserProgress,
Expand Down
5 changes: 3 additions & 2 deletions public/js/middleman.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ function writeBadges(badgeData) {
}

$("#recent_badges").html(
badgeHTML +
`<br><div class="clear"><p><a href="/badges" target="_blank">Click here to view all badges</a></p>`
badgeHTML + `<br><a href="#" target="_blank">Click here to view all badges</a>`
);
}

Expand All @@ -232,6 +231,8 @@ function writeUpdates(updates) {
); // Write updates to DOM

// Life on Grounds information
$("#b_link").text(`Click here to view all badges!`); // Write Life on Grounds name to DOM
$("#b_link").prop("href", updates.badges_link); // Write Life on Grounds link to DOM
$("#LoG_title").text(updates.life_on_grounds_title); // Write Life on Grounds name to DOM
$("#LoG_link").text(`Click here to see all ${updates.life_on_grounds_title} videos!`); // Write Life on Grounds name to DOM
$("#LoG_link").prop("href", updates.life_on_grounds_link); // Write Life on Grounds link to DOM
Expand Down
140 changes: 107 additions & 33 deletions public/js/middleman_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ $(document).ready(async function () {
.fail((err) => console.log("module retrieval failed"))
.always(() => hideLoadingBar());
}
if (needs.includes("daily")) {
$.get(`${herokuAPI}/dailies`, {
hostname: window.location.hostname,
courseID,
})
.done((data) => writeDailiesTaskInfo(data))
.fail((err) => console.log("dailies retrieval failed"))
.always(() => hideLoadingBar());
}
if (needs.includes("lucky")) {
$.get(`${herokuAPI}/lucky`, {
hostname: window.location.hostname,
courseID,
})
.done((data) => writeLuckyInfo(data))
.fail((err) => console.log("lucky retrieval failed"))
.always(() => hideLoadingBar());
}

if (needs.includes("testInfo")) {
$.get(`${herokuAPI}/testInfo`, {
Expand Down Expand Up @@ -246,6 +264,62 @@ function writeDailyTaskInfo(daily) {
$("#dti").val(daily.img);
}

function writeDailiesTaskInfo(daily) {
if (edit) {
let dailyToEdit = daily.filter((daily) => daily._id == dailyID)[0];
$("#daily_id").text(`Editing Daily ${dailyToEdit._id}`);
$("#assignment_id").val(dailyToEdit.assignment_id);
} else {
let content = daily.reduce((content, daily) => {
return (
content +
`<tr>
<td>${daily._id}</td>
<td>${daily.assignment_id}</td>
<td>
<a class="btn btn-dark"
href="dailyTasks/edit/${daily._id}">
Edit
</a>
</td>
</tr>`
);
}, ``);
$("#dailyTable").append(content);
}
}

function prettyDate(dateString) {
var date = new Date(dateString);
return date.toLocaleDateString("en-US", {
weekday: "long",
year: "numeric",
month: "short",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
});
}

function writeLuckyInfo(lucky) {
let content = lucky.reduce((content, lucky) => {
return (
content +
`<tr>
<td>Bonus ${lucky._id}</td>
<td>Date ${prettyDate(lucky.time)}</td>
<td>
<a class="btn btn-dark"
href="lucky/edit/${lucky._id}">
Edit
</a>
</td>
</tr>`
);
}, ``);
$("#luckyTable").append(content);
}

/**
* Writes coachinfo, lifeongrounds, posttest, welcome information from Mongo
* @param { [{page: string, src, string, _id: string,}, ...] } data
Expand Down Expand Up @@ -346,6 +420,39 @@ function writeBadges(badges) {
}
}

function writeModules(modules) {
let content = modules.reduce((content, module) => {
return (
content +
`<tr>
<td>${module._id}</td>
<td>${module.primary_title}</td>
<td>${module.secondary_title}</td>
<td>
<input type='checkbox' ${
module.open === "true" ? "checked" : ""
}/>
</td>
<td>
<input type='checkbox' ${
module.due === "true" ? "checked" : ""
}/>
</td>
<td>${module.practice_link}</td>
<td>${module.quiz_link}</td>
<td>${module.reflection_link}</td>
<td>
<a class="btn btn-dark"
href="modules/edit/${module._id}">
Edit
</a>
</td>
</tr>`
);
}, ``);
$("#moduleTable").append(content);
}

/////////////////////////////////////////////////////////////////////////////////////
// AJAX shortcut helpers
function updateHome(field, value) {
Expand Down Expand Up @@ -417,39 +524,6 @@ function updateBadge() {
});
}

function writeModules(modules) {
let content = modules.reduce((content, module) => {
return (
content +
`<tr>
<td>${module._id}</td>
<td>${module.primary_title}</td>
<td>${module.secondary_title}</td>
<td>
<input type='checkbox' ${
module.open === "true" ? "checked" : ""
}/>
</td>
<td>
<input type='checkbox' ${
module.due === "true" ? "checked" : ""
}/>
</td>
<td>${module.practice_link}</td>
<td>${module.quiz_link}</td>
<td>${module.reflection_link}</td>
<td>
<a class="btn btn-dark"
href="modules/edit/${module._id}">
Edit
</a>
</td>
</tr>`
);
}, ``);
$("#moduleTable").append(content);
}

/////////////////////////////////////////////////////////////////////////////////////
// Keep the preview up to date
function copyToPreview() {
Expand Down
43 changes: 32 additions & 11 deletions routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ router.get("/homeVidEdit/:id", (req, res) => {
});
});

// router.get("/modules/edit/:id", (req, res) => {
// res.render("admin/moduleEdit", {
// title: `Editing module ${req.params.id}`,
// heroku: config.herokuAppName,
// id: req.params.id,
// courseID: Object.keys(req.session.course_id)[0],
// });
// });
router.get("/modules/edit/:id", (req, res) => {
res.render("admin/moduleEdit", {
title: `Editing module ${req.params.id}`,
heroku: config.herokuAppName,
id: req.params.id,
courseID: Object.keys(req.session.course_id)[0],
});
});

router.get("/badges", (req, res) => {
res.render("admin/badges", {
Expand All @@ -71,15 +71,36 @@ router.get("/badges/edit/:id", (req, res) => {
});

router.get("/dailyTasks", (req, res) => {
res.send("This page has not yet been implemented.");
res.render("admin/dailies", {
title: "Daily Tasks",
heroku: config.herokuAppName,
courseID: Object.keys(req.session.course_id)[0],
});
});

router.get("/dailyTasks/edit/:id", (req, res) => {
res.render("admin/dailyEdit", {
title: `Editing daily ${req.params.id}`,
heroku: config.herokuAppName,
id: req.params.id,
courseID: Object.keys(req.session.course_id)[0],
});
});

router.get("/luckyBonuses", (req, res) => {
res.send("This page has not yet been implemented.");
res.render("admin/lucky", {
title: "Lucky Bonuses",
heroku: config.herokuAppName,
courseID: Object.keys(req.session.course_id)[0],
});
});

router.get("/unifiedGradebook", (req, res) => {
res.send("This page has not yet been implemented.");
res.render("admin/gradebook", {
title: "Gradebook",
heroku: config.herokuAppName,
courseID: Object.keys(req.session.course_id)[0],
});
});

router.post("/", (req, res) => {
Expand Down
43 changes: 42 additions & 1 deletion routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,51 @@ router.get("/modules", (req, res) => {
}
});

router.get("/badges", (req, res) => {
router.get("/dailies", (req, res) => {
if (!req.session.user_id)
res.status(403).send("403 - Forbidden. You must be logged in to make this request.");
else {
try {
authorize(req);
assert(Object.keys(req.session.course_id).includes(req.query.courseID)); // prevent cross track cookie usage
assert(req.query.hostname);
mongo.getDailyTasks(req.query.courseID, (err, data) => {
if (err)
res.status(500).send("500 - Internal Server Error. Home data could not be retrieved.");
else res.status(200).header(access, getDst(req.query.hostname)).send(data);
});
} catch (e) {
console.log(e);
res.status(406).send("406 - Your request could not be processed.");
}
}
});

router.get("/lucky", (req, res) => {
if (!req.session.user_id)
res.status(403).send("403 - Forbidden. You must be logged in to make this request.");
else {
try {
authorize(req);
assert(Object.keys(req.session.course_id).includes(req.query.courseID)); // prevent cross track cookie usage
assert(req.query.hostname);
mongo.getLuckyBonuses(req.query.courseID, (err, data) => {
if (err)
res.status(500).send("500 - Internal Server Error. Home data could not be retrieved.");
else res.status(200).header(access, getDst(req.query.hostname)).send(data);
});
} catch (e) {
console.log(e);
res.status(406).send("406 - Your request could not be processed.");
}
}
});

router.use("/badges", (req, res) => {
if (!req.session.user_id) {
console.log("id :" + req.session.user_id);
res.status(403).send("403 - Forbidden. You must be logged in to make this reques");
} else {
try {
authorize(req);
assert(Object.keys(req.session.course_id).includes(req.query.courseID)); // prevent cross track cookie usage
Expand Down
24 changes: 16 additions & 8 deletions views/admin/dailies.pug
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
extends ../layout

block content

script.
const herokuAPI = "/api",
edit = false,
courseID = "!{courseID}";
needs=["courseTitle", "daily", "testInfo"];
script(src="/js/courseIDGrabber.js")
script(src="/js/middleman_admin.js")
br
div.container
div.row
div.form.form-inline
a.btn.btn-lg(href='/admin?course-id='+course_id+'&course-title='+course_title+'&user-id='+user_id)
.container(style="margin-top: 25px;")
.row
.col-md-1
.col.form-inline
a.btn.btn-lg(href='/admin')
i.fa.fa-chevron-left
h2='Editing ' + course_title + ' Daily Tasks'
h2#adminPanelTitle='Loading title...'
.col-md-1
if fixed_id
script.
alert("The system detected you submitted a quiz ID. This was automatically corrected to the corresponding assignment ID (so what you typed may not be in the table).");
Expand All @@ -32,12 +40,12 @@ block content
p Watch the homepage as the next available daily task is linked to in the top left! If no daily task is found, the generic 404 / Missing resource page will be linked on the homepage. In the case that the next daily task is not open yet, the generic not-open page is displayed.
hr
div.row
table(class="admin_table")
table#dailyTable.admin_table(style="margin-bottom:100px;")
tr
th Row
th Assignment ID
th Edit Item
each daily in dailies
//each daily in dailies
if(daily._id == last_edited)
tr(style="background-color:#ff99cc;")
td=daily._id
Expand Down
Loading

0 comments on commit 6775df5

Please sign in to comment.