Skip to content

Commit bf15ee8

Browse files
committed
Display Pivotal Education related courseware
This change adds a new "Related Courseware" section in the side container; this section lists links to courses and talks that are relevant to the current project page. Relevant content is fetched by the browser, with an AJAX request sent to the Pivotal Education LMS API. This API uses the Referrer HTTP header as input parameter to its content selection algorithm. Note that CORS HTTP headers are also used to allow/disallow AJAX cross domain requests.
1 parent 1690b17 commit bf15ee8

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

_includes/widget_templates.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@
2929
</div>
3030
</script>
3131

32+
<script type="text/html" id="project-courses-widget-template">
33+
<h2>Related Courseware</h2>
34+
{@ if(hasCourses) { @}
35+
<h3 id="education">Pivotal Education</h3>
36+
<ul>
37+
{@ _.each(courses, function(course) { @}
38+
<li><a href="{@= course.url @}">{@= course.name @}</a></li>
39+
{@ }); @}
40+
</ul>
41+
{@ } @}
42+
{@ if(hasTalks) { @}
43+
<h3 id="talks">Engineering Talks</h3>
44+
<ul>
45+
{@ _.each(talks, function(talk) { @}
46+
<li><a href="{@= talk.url @}">{@= talk.name @}</a></li>
47+
{@ }); @}
48+
</ul>
49+
{@ } @}
50+
</script>
51+
3252
<script type="text/html" id="project-download-widget-controls-template">
3353
<div class="js-download-widget-selector">
3454
<select class='selector selectpicker'>

js/projectDocumentationWidget.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ Spring.ProjectDocumentationWidget = function () {
1111
var quickStartEl = $('[data-download-widget-controls]');
1212
var mavenWidgetEl = $('.js-download-maven-widget');
1313
var documentationEl = $('.js-documentation-widget');
14+
var resourcesEl = $('.project-sidebar-resource--wrapper');
1415

1516
var projectUrl = apiBaseUrl + "/project_metadata/" + projectId;
1617
var promise = Spring.loadProject(projectUrl);
18+
var coursesPromise = Spring.loadCourses("https://pivotallms.biglms.com/api/courses");
1719

1820
promise.then(function (project) {
1921
Spring.buildDocumentationWidget(documentationEl, project);
2022
Spring.buildQuickStartWidget(quickStartEl, mavenWidgetEl, project);
2123
});
24+
coursesPromise.then(function(courseware) {
25+
Spring.buildCoursesWidget(resourcesEl, courseware);
26+
});
2227
};
2328

2429
Spring.buildDocumentationWidget = function (documentationEl, project) {
@@ -29,6 +34,17 @@ Spring.buildDocumentationWidget = function (documentationEl, project) {
2934
}).render();
3035

3136
}
37+
Spring.buildCoursesWidget = function (resourcesEl, courseware) {
38+
if(courseware.hasContent) {
39+
var tpl = $("#project-courses-widget-template").text();
40+
var view = new Spring.CoursesWidgetView({
41+
el: resourcesEl,
42+
model: courseware,
43+
template: $("#project-courses-widget-template").text()
44+
});
45+
view.render();
46+
}
47+
}
3248
Spring.buildQuickStartWidget = function (quickStartEl, mavenWidgetEl, project) {
3349
new Spring.QuickStartSelectorView({
3450
el: quickStartEl,
@@ -47,6 +63,13 @@ Spring.loadProject = function (url) {
4763
});
4864
}
4965

66+
Spring.loadCourses = function (url) {
67+
return $.getJSON(url)
68+
.then(function(data) {
69+
return new Spring.Courseware(data);
70+
});
71+
}
72+
5073
Spring.Release = function (data) {
5174
_.extend(this, data);
5275
}
@@ -63,6 +86,15 @@ Spring.Release.prototype = {
6386
}
6487
}
6588

89+
Spring.Courseware = function (data) {
90+
this.courses = data["edu1"];
91+
this.talks = data["eng1"];
92+
this.hasCourses = this.courses != null;
93+
this.hasTalks = this.talks != null;
94+
this.hasContent = this.hasTalks || this.hasCourses;
95+
return this;
96+
};
97+
6698
Spring.Project = function (data) {
6799
_.extend(this, data);
68100
var self = this;
@@ -87,6 +119,20 @@ Spring.DocumentationWidgetView = Backbone.View.extend({
87119
}
88120
});
89121

122+
Spring.CoursesWidgetView = Backbone.View.extend({
123+
initialize: function () {
124+
this.template = _.template(this.options.template);
125+
_.bindAll(this, "render");
126+
},
127+
128+
render: function () {
129+
this.$el.append(
130+
this.template(this.model)
131+
);
132+
return this;
133+
}
134+
});
135+
90136
Spring.SnippetView = Backbone.View.extend({
91137
initialize: function () {
92138
var snippetType = this.options.snippetType;

0 commit comments

Comments
 (0)