Skip to content

Commit

Permalink
Create /mine page, showing your courses (see #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
qaisjp committed Nov 8, 2017
1 parent 48de0d9 commit 5190ea3
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 29 deletions.
25 changes: 25 additions & 0 deletions _includes/frontpage-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

<div style="text-align: center;">
<!-- <small>Resitting an exam? <a href="http://www.scripts.sasg.ed.ac.uk/registry/examinations/index.cfm">Check when your exam is</a>.</small> -->
</div>

{% if page.url != "/" %}
<a id="sem1-btn" class="btn">view semester 1</a>
<a id="sem2-btn" class="btn">view semester 2</a>
<a id="all-btn" class="btn">view all</a>
{% endif %}

<div id="bi-interactive">
<div class="bi-loading">
<a class="btn" href="#">Loading...</a>
</div>

<div id="login" style="display:none;">
<a class="btn" href="https://weblogin.inf.ed.ac.uk/cosign-bin/cosign.cgi?cosign-betterinformatics.com&https://betterinformatics.com{{ page.url }}">Log in</a>
</div>

<div id="user" style="display:none;">
<a href="/mine" class="btn"><span id="user-name"></span>'s courses</a>
<a href="https://weblogin.inf.ed.ac.uk/cosign-bin/logout" class="btn">Logout</a>
</div>
</div>
2 changes: 1 addition & 1 deletion _includes/sections.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% capture sectionID %}
{% if section.course-acronym != "" %}{{ section.course-acronym }}{% else %}{{ section.title | slugify }}{% endif %}
{% endcapture %}
<section id="{{ sectionID | strip }}" data-semester="{{ section.semester }}" {{ sectionStyle }}>
<section id="{{ sectionID | strip }}" data-semester="{{ section.semester }}" data-pinned="{{ section.pinned }}" data-year="{{ section.year }}" data-course="{{ section.course-acronym }}" {{ sectionStyle }}>
<h3>
{% if section.link %}
<a href="{{ section.link }}">
Expand Down
18 changes: 2 additions & 16 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,9 @@ <h1>Better Informatics</h1>
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>

{% if page.layout == "frontpage" %}
{% if page.layout == "frontpage" or page.url == "/mine.html" %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(() => {
$("#sem1-btn,#sem2-btn,#all-btn").click(btn => {
// First show everything
$("[data-semester]").show();

var sem = btn.target.id.slice(3, 4);
if (sem == "1") {
$("[data-semester='2']").hide();
} else if (sem == "2") {
$("[data-semester='1']").hide();
}
});
})
</script>
<script src="/static/js/main.js"></script>
{% endif %}
</body>
</html>
9 changes: 1 addition & 8 deletions _layouts/frontpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
---
{% include nav.html %}

<div style="text-align: center;">
<!-- <small>Resitting an exam? <a href="http://www.scripts.sasg.ed.ac.uk/registry/examinations/index.cfm">Check when your exam is</a>.</small> -->
</div>

<a href="https://drive.google.com/drive/folders/0AIKEqWfeWuQQUk9PVA" class="btn"><strong>new</strong> team drive</a>
<a id="sem1-btn" class="btn">view semester 1</a>
<a id="sem2-btn" class="btn">view semester 2</a>
<a id="all-btn" class="btn">view all</a>
{% include frontpage-header.html %}

{{ content }}

Expand Down
5 changes: 2 additions & 3 deletions _pages/files.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---
---

### Please don't forget to transfer ownership of Drive files to <strong>betterinformatics@gmail.com</strong>.

Files are moving to the new Team Drives folder. **Do not update the old folders as they will be lost.**
<h1><a href="https://drive.google.com/drive/folders/0AIKEqWfeWuQQUk9PVA">Here is the <strong>new</strong> team drive</a></h1>

<!--
### Adding files
Expand All @@ -21,3 +19,4 @@ Whenever you want to add something to the shared Google Drive folders, do the fo
-->

Please, <u>do not convert PDFs to a Google Doc</u>, leave them as PDF files.
<br>
36 changes: 36 additions & 0 deletions mine.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Your Courses
short-title: Your Courses
layout: default
---
{% include nav.html %}

{% include frontpage-header.html %}

<div class="bi-loading">
<h3>Your courses are loading...</h3>
</div>

<div id="my-sections" style="display: none;">

{% assign len = page.path.size | minus: 3 | minus: 7 %}

<!-- First show pinned sections -->

{% assign sections = site.sections | where: "pinned", true | sort: "title" %}
{% if page.show-archived == false %}
{% assign sections = sections | where: "archived", "false" %}
{% endif %}

{% include sections.html sections=sections hidden=hidden %}

<!-- Then show non-pinned sections -->

{% assign sections = site.sections | where: "pinned", false | sort: "title" %}
{% if page.show-archived == false %}
{% assign sections = sections | where: "archived", "false" %}
{% endif %}

{% include sections.html sections=sections hidden=hidden %}

</div>
11 changes: 10 additions & 1 deletion static/css/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ h1, h2, h3, h4, h5, h6 {

}

#bi-interactive {
text-align: center;
}

@media screen and (max-width: 970px) {
.hide-on-small {
visibility: hidden;
Expand All @@ -301,6 +305,11 @@ h1, h2, h3, h4, h5, h6 {
width: 28%;
display: none;
}

#bi-interactive {
float: right;
text-align: initial;
}
}

#title-small {
Expand Down Expand Up @@ -411,7 +420,7 @@ h1, h2, h3, h4, h5, h6 {
.btn {
display: inline-block;
border: 1px solid #ddd;
padding: 10px 15px;
padding: 5px 10px;
font-size: 1rem;
color: #777;
text-align: center;
Expand Down
61 changes: 61 additions & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function loadSemesterButtons() {
$("#sem1-btn,#sem2-btn,#all-btn").click(btn => {
// First show everything
$("[data-semester]").show();

var sem = btn.target.id.slice(3, 4);
if (sem == "1") {
$("[data-semester='2']").hide();
} else if (sem == "2") {
$("[data-semester='1']").hide();
}
});
}

function loadProvider() {
$.ajax({url:"https://provider.betterinformatics.com", xhrFields:{withCredentials:true}})
.done(
(resp) => {
const data = resp.data;

const year = "inf" + (data.Year.slice(2));

if (data.IsStudent && window.location.pathname.slice(0, 5) == "/mine") {
$("section").each(function(_, section) {
section = $(section);

if (section.data("pinned") && (section.data("year") == year)) {
return;
}

if (!data.Modules.includes(section.data("course"))) {
section.remove();
}
});

$("#my-sections").show();
}

$(".bi-loading").hide();
$("#user-name").text(data.Name);
$("#user").show();
}
).fail(
() => {
if (window.location.pathname.slice(0, 5) == "/mine") {
window.location = "https://weblogin.inf.ed.ac.uk/cosign-bin/cosign.cgi?cosign-betterinformatics.com&" + window.location.href;
}

$("#login").show();
$(".bi-loading").hide();
}
);
}

$(() => {
// Load provider
loadProvider();

// Load the semester buttons
loadSemesterButtons();
})

3 comments on commit 5190ea3

@neanias
Copy link
Member

@neanias neanias commented on 5190ea3 Nov 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a monstrously large method for loadProvider(), would it not be better to break it up a bit or extract the fat arrow methods into their own functions?

@rphi
Copy link
Member

@rphi rphi commented on 5190ea3 Nov 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is... glorious
screen shot 2017-11-08 at 13 13 28

Like actually properly awesome [sends internet points]

@qaisjp
Copy link
Member Author

@qaisjp qaisjp commented on 5190ea3 Nov 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neanias that is probably a good idea

Please sign in to comment.