Skip to content

Commit 06803b1

Browse files
amortensonDerekTBrown
authored andcommitted
Labfile markdown (#111)
* added labfile with markdown * added course search method
1 parent 51a806a commit 06803b1

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

client/imports/ui/components/explore/search.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
viewProviders: [ MdIconRegistry ],
3737
encapsulation: ViewEncapsulation.None
3838
})
39-
39+
4040
// Export Explore Class
4141
export class SearchView extends MeteorComponent {
4242

@@ -47,30 +47,29 @@ export class SearchView extends MeteorComponent {
4747
totalItems: this.courses.length
4848
};
4949
pagedCourses: Array<any> = [];
50-
50+
5151
constructor(mdIconRegistry: MdIconRegistry) {
5252
super();
53-
53+
5454
// Create Icon Font
5555
mdIconRegistry.registerFontClassAlias('tux', 'tuxicon');
5656
mdIconRegistry.setDefaultFontSetClass('tuxicon');
57-
58-
// Subscribe Courses Database
59-
//this.getCourses();
57+
58+
// Subscribe Courses Database
6059
this.subscribe('all-courses', () => {
6160
this.courses = courses.find().fetch();
6261
this.pagination.totalItems = this.courses.length;
6362
this.refreshCourses();
6463
}, true);
6564
}
66-
65+
6766
// Refresh Courses List
6867
refreshCourses() {
6968
let start = (this.pagination.currentPage - 1) * this.pagination.itemsPerPage;
7069
let end = start + this.pagination.itemsPerPage;
7170
this.pagedCourses = this.courses.slice(start, end);
7271
}
73-
72+
7473
// Display the infomation of current state of pagination
7574
getCurrentInfo() {
7675
// This is the number of the first item on the current page
@@ -88,34 +87,33 @@ export class SearchView extends MeteorComponent {
8887

8988
return start.toString() + "-" + end.toString() + " of " + this.pagination.totalItems.toString();
9089
}
91-
90+
9291
// Go to next page function
9392
nextPage() {
94-
93+
9594
// Get the current page
9695
let currentPage = this.pagination.currentPage;
97-
96+
9897
// Get the last possible page
9998
let lastPage = Math.ceil(this.pagination.totalItems / this.pagination.itemsPerPage);
100-
99+
101100
// Check if the current page is the last page
102101
if (currentPage !== lastPage) {
103102
this.pagination.currentPage ++;
104103
this.refreshCourses();
105104
}
106105
}
107-
106+
108107
// Go to previous page function
109108
prevPage() {
110-
109+
111110
// Get the current page
112111
let currentPage = this.pagination.currentPage;
113-
112+
114113
// Check if the current page is the first page
115114
if (currentPage !== 1) {
116115
this.pagination.currentPage --;
117116
this.refreshCourses();
118117
}
119118
}
120119
}
121-

collections/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ The following document describes the MongoDB Schema used by the TuxLab app:
6060
course_number: "15-131",
6161
course_name: "Great Practical Ideas for Computer Scientists",
6262
instructor_name: "Tom Cortina",
63+
hidden: true, // Course is invisible to students. Default is true.
64+
disabled: false, // Enrollment in course is still open. Default is true.
6365
course_description: {
6466
content: "This is the course description.",
6567
syllabus: "This is the course syllabus"

server/imports/lab/methods.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1+
import { Meteor } from 'meteor/meteor';
2+
import { Mongo } from 'meteor/mongo';
3+
import { check } from 'meteor/check';
4+
15
declare var Collections : any;
6+
27
Meteor.methods({
38
'prepareLab': function(courseId : String,labId : Number){
49
console.log("here");
510
// var course = Collections.courses.findOne({_id: courseId}).fetch();
611
//var t = require('../api/labExec.js');
712
// return course.labs.find((l) => { return l._id == labId; });
8-
}
13+
},
14+
'search_courses': function(text : String){
15+
var courses = Collections.courses;
16+
17+
var search_pattern = new RegExp(text,"i");
18+
19+
var number_search = {"course_number" : search_pattern};
20+
var alternate_number_search = {$where: "this.course_number.replace(/[ .-]/g,'') == '"+text+"'"};
21+
var name_results = {"course_name" : search_pattern};
22+
23+
var results = courses.find({$and : [{"visible" : true}, {$or : [number_search, alternate_number_search, name_results]}}).limit(15);
24+
25+
return results;
26+
}
927
});
1028

0 commit comments

Comments
 (0)