Skip to content

Commit f3bc0a2

Browse files
committed
Merge pull request #11 from whytheplatypus/master
highlighting
2 parents c9b2c37 + 1b4b9a3 commit f3bc0a2

File tree

4 files changed

+197
-24
lines changed

4 files changed

+197
-24
lines changed

htdocs/css/library_browser.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ ul.list li{
4545
float:right;
4646
}
4747

48-
.conatains_problem{
49-
backbround: aliceblue;
48+
.contains_problem{
49+
background: aliceblue;
5050
}
5151

5252
.syncing:after{

htdocs/js/apps/LibraryBrowser/library_browser.js

Lines changed: 120 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $(function () {
4141
//We want the problem to render in a `li` since it will be included in a list
4242
tagName:"li",
4343
//Add the 'problem' class to every problem
44-
className: "problem",
44+
//className: "problem",
4545
//This is the template for a problem, the html is defined in SetMaker3.pm
4646
template: _.template($('#problem-template').html()),
4747

@@ -85,7 +85,6 @@ $(function () {
8585
problem.render();
8686
}
8787

88-
this.el.setAttribute('data-path', problem.get('path'));
8988
this.el.id = this.model.cid;
9089

9190

@@ -251,6 +250,124 @@ $(function () {
251250
});
252251

253252

253+
//##The browse View
254+
var BrowseView = Backbone.View.extend({
255+
template:_.template($('#Library-template').html()),
256+
257+
events:{
258+
"click .next_group": "loadNextGroup"
259+
},
260+
261+
initialize: function(){
262+
var self = this;
263+
this.group_size = 25;
264+
this.model.get('problems').on('reset', this.render, this);
265+
this.model.get('problems').on('syncing', function(value){
266+
if(value){
267+
$("[href=#"+self.model.get('name')+"]").addClass("syncing");
268+
} else {
269+
$("[href=#"+self.model.get('name')+"]").removeClass("syncing");
270+
}
271+
}, this);
272+
this.model.get('problems').on('alert', function(message){alert(message);});
273+
274+
if(!(this.model.get('problems').length > 0)){
275+
this.model.get('problems').fetch();
276+
}
277+
},
278+
279+
render: function(){
280+
281+
var self = this;
282+
283+
if ($('#problems_container #' + this.model.get('name')).length == 0) {
284+
$('#problems_container').tabs('add', "#"+this.model.get('name'), this.model.get('name') + " (" + this.model.get('problems').length + ")"); //could move to an after?
285+
this.setElement(document.getElementById(this.model.get('name')));
286+
} else {
287+
//select
288+
$('#problems_container').tabs('select', this.model.get('name'));
289+
$("[href=#"+this.model.get('name')+"]").html(this.model.get('name') + " (" + this.model.get('problems').length + ")");
290+
}
291+
292+
if(self.model.get('problems').syncing){
293+
$("[href=#"+self.model.get('name')+"]").addClass("syncing");
294+
}
295+
296+
this.$el.addClass("library_tab");
297+
this.startIndex = 0;
298+
299+
var jsonInfo = this.model.toJSON();
300+
jsonInfo['group_size'] = this.group_size;
301+
302+
jsonInfo['enough_problems'] = (this.model.get('problems').length > this.startIndex)? "block" : "none";
303+
304+
this.$el.html(this.template(jsonInfo));
305+
306+
this.loadNextGroup();
307+
308+
return this;
309+
},
310+
//Define a new function loadNextGroup so that we can just load a few problems at once,
311+
//otherwise things get unwieldy :P
312+
loadNextGroup: function(){
313+
314+
var problems = this.model.get('problems');
315+
console.log(problems.length);
316+
for(var i = 0; i < this.group_size && this.startIndex < problems.length; i++, this.startIndex++){
317+
console.log("adding a problem");
318+
var problem = problems.at(this.startIndex);
319+
var view = new ProblemView({model: problem, remove_display: true});
320+
this.$(".list").append(view.render().el);
321+
}
322+
323+
if(!(this.model.get('problems').length > this.startIndex)){
324+
this.$(".next_group").css('display', "none");
325+
}
326+
}
327+
328+
});
329+
330+
var BrowseListView = Backbone.View.extend({
331+
tagName:'span',
332+
template:_.template($('#LibraryList-template').html()),
333+
334+
events: {
335+
//'change .list': 'lib_selected'
336+
},
337+
338+
initialize:function () {
339+
var self = this;
340+
this.model.on("change:library_subjects", this.render, this);
341+
this.model.on("change:library_chapters", this.render, this);
342+
this.model.on("change:library_section", this.render, this);
343+
},
344+
345+
render:function () {
346+
347+
var self = this;
348+
if(self.model.syncing){
349+
self.$el.addClass("syncing white");
350+
}
351+
this.$el.html(this.template({name: this.options.name}));
352+
self.$("."+this.options.name+".list").on('change', function(event){self.lib_selected(event)});
353+
this.addAll();
354+
return this;
355+
},
356+
357+
section_selected:function (event) {
358+
var self = this;
359+
self.$el.removeClass("syncing white");
360+
var selectedLib = this.model.getByCid(event.target.value);
361+
if(selectedLib){
362+
var view = new LibraryListView({model:selectedLib.get('children'), name: selectedLib.cid});
363+
this.$('.'+this.options.name+".children").html(view.render().el);
364+
libToLoad = selectedLib;
365+
}
366+
}
367+
368+
});
369+
370+
254371
//##The main Set view
255372
var SetView = Backbone.View.extend({
256373
template:_.template($('#set-template').html()),
@@ -341,7 +458,7 @@ $(function () {
341458
var self = this;
342459
this.model.get('problems').on('all', function(){self.render()}, this);
343460
this.model.get('problems').on('alert', function(message){alert(message);});
344-
this.model.on('highlight', function(){self.$el.addClass("contains_problem")});
461+
this.model.on('highlight', function(){console.log("highlight "+self.model.get('name')); self.$el.addClass("contains_problem")});
345462
},
346463

347464
render:function () {
@@ -506,9 +623,7 @@ $(function () {
506623
highlightSets: function(event) {
507624
switch(event.type){
508625
case "mouseenter":
509-
//console.log(this.getAttribute("data-path"));
510626
var problemPath = event.currentTarget.getAttribute("data-path");
511-
512627
this.homeworkSets.each(function(set){
513628
if(set.get('problems').find(function(problem){return problem.get('path') == problemPath})){
514629
set.trigger('highlight');
Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,67 @@
1+
2+
/**
3+
*
4+
* @constructor
5+
*/
6+
webwork.Browse = Backbone.Model.extend({
7+
8+
defaults:{
9+
name:"",
10+
library_subject:null,
11+
library_chapter:null,
12+
library_section:null
13+
},
14+
15+
initialize: function(){
16+
this.set('problems', new webwork.ProblemList);
17+
this.set('library_subjects', new Array());
18+
this.set('library_chapters', new Array());
19+
this.set('library_section', new Array());
20+
},
21+
22+
go: function () {
23+
this.updateInputs();
24+
this.set(name, this.get('library_subject') + " " + this.get('library_chapter') + " " + this.get('library_section'));
25+
var requestObject = {
26+
xml_command: "searchLib",
27+
subcommand: "getDBListings",
28+
library_subjects: this.get('library_subject'),
29+
library_chapters: this.get('library_chapter'),
30+
library_sections: this.get('library_section')
31+
};
32+
_.defaults(requestObject, this.defaultRequestObject);
33+
var self = this;
34+
$.post(webserviceURL, requestObject, function (data) {
35+
var response = $.parseJSON(data);
36+
var results = response.result_data.split(",");
37+
38+
newSearchResult.problems = new Array();
39+
for (var i = 0; i < results.length; i++) {
40+
newSearchResult.problems.push(new Problem(results[i]));
41+
}
42+
self.get('problems').reset(newSearchResult);
43+
});
44+
},
45+
46+
updateSubcategory: function (section, subcommand) {
47+
var self = this;
48+
var requestObject = {
49+
xml_command: "searchLib",
50+
subcommand: subcommand,
51+
library_subjects: this.get('library_subject'),
52+
library_chapters: this.get('library_chapter'),
53+
library_sections: this.get('library_section')
54+
};
55+
_.defaults(requestObject, this.defaultRequestObject);
56+
$.post(webserviceURL, requestObject, function (data) {
57+
var response = $.parseJSON(data);
58+
self.set(subcommand, response.result_data.split(","));
59+
});
60+
}
61+
});
62+
63+
64+
/*
165
function Search() {
266
this.problems = new Array();
367
this.subjectBox = document.getElementById("subjectBox");
@@ -27,17 +91,13 @@ function Search() {
2791
//update inputs
2892
workAroundTheClosure.updateInputs();
2993
}, false);
30-
/*textbooksBox.addEventListener("change", function() {
31-
//update inputs
32-
workAroundTheClosure.updateInputs();
33-
//update lists
34-
workAroundTheClosure.updateAll();
35-
}, false);*/
94+
3695
this.updateSubjectBox();
3796
this.updateChaptersBox();
3897
this.updateSectionsBox();
3998
4099
}
100+
*/
41101

42102
function SearchResult() {
43103
this.searchName = "search" + generateUniqueID();
@@ -89,7 +149,7 @@ SearchResult.prototype.createPageControls = function () {
89149

90150
}
91151

92-
152+
/*
93153
Search.prototype.go = function () {
94154
this.updateInputs();
95155
listLibRequest.xml_command = "searchLib";
@@ -119,15 +179,10 @@ Search.prototype.go = function () {
119179
newSearchResult.problems.push(new Problem(results[i]));
120180
}
121181
newSearchResult.renderProblems(newSearchResult.topProbIndex, newSearchResult.probsPerPage);
122-
//callback();
123-
/*} catch (err) {
124-
console.log(err);
125-
var myWindow = window.open('', '', 'width=500,height=800');
126-
myWindow.document.write(data);
127-
myWindow.focus();
128-
}*/
182+
129183
});
130184
};
185+
*/
131186

132187
SearchResult.prototype.renderProblems = function (start, limit) {
133188
//$('#'+this.searchName+' a').text("Other text");
@@ -155,6 +210,7 @@ SearchResult.prototype.updateMoveButtons = function () {
155210
}
156211
};
157212

213+
/*
158214
Search.prototype.updateInputs = function () {
159215
listLibRequest.library_subjects = this.subjectBox.options[this.subjectBox.selectedIndex].value;
160216
listLibRequest.library_chapters = this.chaptersBox.options[this.chaptersBox.selectedIndex].value;
@@ -164,8 +220,9 @@ Search.prototype.updateInputs = function () {
164220
// listLibRequest.library_textsection = this.textSectionsBox.options[this.textSectionsBox.selectedIndex].value;
165221
// listLibRequest.library_keywords = this.keywordsBox.value;
166222
};
223+
*/
167224

168-
225+
/*
169226
Search.prototype.updateSubjectBox = function () {
170227
listLibRequest.xml_command = "searchLib";
171228
listLibRequest.subcommand = "getAllDBsubjects";
@@ -222,4 +279,5 @@ Search.prototype.update = function (box, blankName) {
222279
myWindow.focus();
223280
}
224281
});
225-
};
282+
};
283+
*/

lib/WeBWorK/ContentGenerator/Instructor/SetMaker3.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ sub body {
230230
print '<script type="text/template", id="problem-template">',
231231
'<%if(!remove_display){ %><div class="handle"><i class="icon-resize-vertical icon-large"></i></div>',
232232
'<button type="button" class="remove">X</button><%}%>', #replace with twitter bootstrap icons? yeah font awesome :)
233-
' <div class="problem"><%= data %></div>',
233+
' <div class="problem" data-path="<%= path %>" ><%= data %></div>',
234234
'</script>';
235235

236236
print '<script type="text/template", id="setList-template">',

0 commit comments

Comments
 (0)