Skip to content

Commit 5c22110

Browse files
sandershihackerDerekTBrown
authored andcommitted
school name
search function
1 parent e2f4d25 commit 5c22110

File tree

10 files changed

+145
-160
lines changed

10 files changed

+145
-160
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<div class="tuxlab-searchview">
22
<div class="md-whiteframe-5dp course-search-list">
33

4-
<h2 id="search-string">Search Results</h2>
4+
<h2 id="search-string">Search Results for '{{ searchQuery }}'</h2>
55

66
<div class="selector">
77
<button md-button (click)="prevPage()" class="right">
88
<md-icon fontIcon="tuxicon-left"></md-icon>
99
Prev
1010
</button>
11+
<!--
1112
<span [innerHTML]="getCurrentInfo()"></span>
13+
-->
1214
<button md-button (click)="nextPage()" class="right">
1315
Next
1416
<md-icon fontIcon="tuxicon-right"></md-icon>
@@ -25,7 +27,7 @@ <h2 id="search-string">Search Results</h2>
2527
</tr>
2628
</thead>
2729
<tbody>
28-
<tr *ngFor="let course of pagedCourses">
30+
<tr *ngFor="let course of searchResults">
2931
<td class="md-text-cell">{{ course.course_number }}</td>
3032
<td class="md-text-cell">{{ course.course_name }}</td>
3133
<td>{{ course.instructor_name }}</td>
@@ -39,7 +41,9 @@ <h2 id="search-string">Search Results</h2>
3941
<md-icon fontIcon="tuxicon-left"></md-icon>
4042
Prev
4143
</button>
44+
<!--
4245
<span [innerHTML]="getCurrentInfo()"></span>
46+
-->
4347
<button md-button (click)="nextPage()" class="right">
4448
Next
4549
<md-icon fontIcon="tuxicon-right"></md-icon>

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

Lines changed: 40 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'zone.js/dist/zone';
66

77
// Angular Imports
8-
import { Component, ViewEncapsulation, provide } from '@angular/core';
8+
import { Component, ViewEncapsulation, provide, Input } from '@angular/core';
99
import { bootstrap } from 'angular2-meteor-auto-bootstrap';
1010
import { APP_BASE_HREF, FORM_DIRECTIVES } from '@angular/common';
1111
import { HTTP_PROVIDERS } from '@angular/http';
@@ -39,83 +39,44 @@
3939

4040
// Export Explore Class
4141
export class SearchView extends MeteorComponent {
42+
@Input() searchQuery;
43+
@Input() searchResults;
44+
currentPage = 1;
45+
resultsPerPage = 2;
46+
constructor(mdIconRegistry: MdIconRegistry) {
47+
super();
48+
// Create Icon Font
49+
mdIconRegistry.registerFontClassAlias('tux', 'tuxicon');
50+
mdIconRegistry.setDefaultFontSetClass('tuxicon');
51+
}
4252

43-
courses: Array<any> = [];
44-
pagination = {
45-
currentPage: 1,
46-
itemsPerPage: 15,
47-
totalItems: this.courses.length
48-
};
49-
pagedCourses: Array<any> = [];
50-
51-
constructor(mdIconRegistry: MdIconRegistry) {
52-
super();
53-
54-
// Create Icon Font
55-
mdIconRegistry.registerFontClassAlias('tux', 'tuxicon');
56-
mdIconRegistry.setDefaultFontSetClass('tuxicon');
57-
58-
// Subscribe Courses Database
59-
//this.getCourses();
60-
this.subscribe('all-courses', () => {
61-
this.courses = courses.find().fetch();
62-
this.pagination.totalItems = this.courses.length;
63-
this.refreshCourses();
64-
}, true);
65-
}
66-
67-
// Refresh Courses List
68-
refreshCourses() {
69-
let start = (this.pagination.currentPage - 1) * this.pagination.itemsPerPage;
70-
let end = start + this.pagination.itemsPerPage;
71-
this.pagedCourses = this.courses.slice(start, end);
72-
}
73-
74-
// Display the infomation of current state of pagination
75-
getCurrentInfo() {
76-
// This is the number of the first item on the current page
77-
let start = (this.pagination.currentPage - 1) * this.pagination.itemsPerPage + 1;
78-
79-
// Set the end number to be the number of the last item on the page
80-
// Check in case there are less than itemsPerPage items on the page
81-
let end = 0;
82-
if ((start + this.pagination.itemsPerPage - 1) > this.pagination.totalItems) {
83-
end = this.pagination.totalItems;
84-
}
85-
else {
86-
end = start + this.pagination.itemsPerPage - 1;
87-
}
88-
89-
return start.toString() + "-" + end.toString() + " of " + this.pagination.totalItems.toString();
90-
}
91-
92-
// Go to next page function
93-
nextPage() {
94-
95-
// Get the current page
96-
let currentPage = this.pagination.currentPage;
97-
98-
// Get the last possible page
99-
let lastPage = Math.ceil(this.pagination.totalItems / this.pagination.itemsPerPage);
100-
101-
// Check if the current page is the last page
102-
if (currentPage !== lastPage) {
103-
this.pagination.currentPage ++;
104-
this.refreshCourses();
105-
}
106-
}
107-
108-
// Go to previous page function
109-
prevPage() {
110-
111-
// Get the current page
112-
let currentPage = this.pagination.currentPage;
113-
114-
// Check if the current page is the first page
115-
if (currentPage !== 1) {
116-
this.pagination.currentPage --;
117-
this.refreshCourses();
118-
}
119-
}
120-
}
53+
// Go to next page function
54+
nextPage() {
55+
let self = this;
56+
this.currentPage++;
57+
Meteor.call('search_courses', this.searchQuery, this.resultsPerPage, this.currentPage, function(error, result) {
58+
if(error) {
59+
console.log(error);
60+
}
61+
else {
62+
self.searchResults = result;
63+
}
64+
});
65+
}
12166

67+
// Go to previous page function
68+
prevPage() {
69+
let self = this;
70+
if(this.currentPage > 1) {
71+
this.currentPage--;
72+
Meteor.call('search_courses', this.searchQuery, this.resultsPerPage, this.currentPage, function(error, result) {
73+
if(error) {
74+
console.log(error);
75+
}
76+
else {
77+
self.searchResults = result;
78+
}
79+
});
80+
}
81+
}
82+
}

client/imports/ui/pages/account/account.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<img src="{{ user.profile.picture }}">
66
</div>
77
<div class="account-display-name">
8-
<h2>{{ user.profile.name }}</h2>
8+
<h2>{{ user.profile.nickname }}</h2>
99
<p>{{ user.profile.school }}</p>
1010
<p>{{ user.profile.email }}</p>
1111
</div>

client/imports/ui/pages/course/mainview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
// Create Icon Font
5757
mdIconRegistry.registerFontClassAlias('tux', 'tuxicon');
5858
mdIconRegistry.setDefaultFontSetClass('tuxicon');
59-
59+
6060
// Subscribe to courses database and set current course
6161
this.subscribe('user-courses', this.courseNumber, () => {
6262
this.course = courses.findOne({ course_number: this.courseNumber });

client/imports/ui/pages/explore/explore.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929

3030
<!-- Search View -->
3131
<div id="search-view">
32-
<tuxlab-searchview></tuxlab-searchview>
32+
<tuxlab-searchview [searchQuery]="searchQuery" [searchResults]="searchResults"></tuxlab-searchview>
3333
</div>
3434
</div>

client/imports/ui/pages/explore/explore.ts

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'zone.js/dist/zone';
66

77
// Angular Imports
8-
import { Component, ViewEncapsulation, provide } from '@angular/core';
8+
import { Component, ViewEncapsulation, provide, Input } from '@angular/core';
99
import { bootstrap } from 'angular2-meteor-auto-bootstrap';
1010
import { APP_BASE_HREF } from '@angular/common';
1111
import { HTTP_PROVIDERS } from '@angular/http';
@@ -48,35 +48,42 @@
4848

4949
// Export Explore Class
5050
export default class Explore extends MeteorComponent {
51+
searchQuery: string;
52+
searchResults: Array<Object>;
53+
54+
constructor(mdIconRegistry: MdIconRegistry) {
55+
super();
56+
// Create Icon Font
57+
mdIconRegistry.registerFontClassAlias('tux', 'tuxicon');
58+
mdIconRegistry.setDefaultFontSetClass('tuxicon');
59+
}
5160

52-
constructor(mdIconRegistry: MdIconRegistry) {
53-
super();
54-
// Create Icon Font
55-
mdIconRegistry.registerFontClassAlias('tux', 'tuxicon');
56-
mdIconRegistry.setDefaultFontSetClass('tuxicon');
57-
58-
// Set maximum width to full width for search bar
59-
document.getElementById('tux-content').style.maxWidth = "100%";
60-
}
61-
62-
// Find Course
63-
findCourse() {
64-
let searchQuery = (<HTMLInputElement>document.getElementById('search-input')).value;
65-
if (searchQuery !== '') {
66-
document.getElementById('explore-view').style.display = 'none';
67-
document.getElementById('search-view').style.display = 'block';
68-
document.getElementById('search-input').blur();
69-
document.getElementById('search-string').innerHTML = "Search Results for \'" + searchQuery + "\'";
70-
}
71-
else {
72-
document.getElementById('explore-view').style.display = 'block';
73-
document.getElementById('search-view').style.display = 'none';
74-
}
75-
}
76-
77-
// Search icon button
78-
searchFocus() {
79-
document.getElementById('search-input').focus();
80-
}
61+
// Find Course
62+
findCourse() {
63+
let searchQuery = (<HTMLInputElement>document.getElementById('search-input')).value;
64+
if (searchQuery !== '') {
65+
document.getElementById('explore-view').style.display = 'none';
66+
document.getElementById('search-view').style.display = 'block';
67+
document.getElementById('search-input').blur();
68+
this.searchQuery = searchQuery;
69+
let self = this;
70+
Meteor.call('search_courses', this.searchQuery, 2, 1, function(err, res) {
71+
if(err) {
72+
console.log(err);
73+
}
74+
else {
75+
self.searchResults = res;
76+
}
77+
});
78+
}
79+
else {
80+
document.getElementById('explore-view').style.display = 'block';
81+
document.getElementById('search-view').style.display = 'none';
82+
}
83+
}
8184

85+
// Search icon button
86+
searchFocus() {
87+
document.getElementById('search-input').focus();
88+
}
8289
}

collections/courses.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ courses.allow({
111111
// Check if userId indeed corresponds to a user in the database
112112
let user = Meteor.users.findOne(this.userId);
113113
if (typeof user !== "undefined") {
114-
114+
115115
// Get course ids of courses that the student is enroled in
116116
let studentCourseIds = (_.unzip((<any>user).roles.student))[0];
117117
if (typeof studentCourseIds !== "undefined") {
118118

119119
// Concatenate with the courseIds that the instructor is teaching
120120
let course_ids = studentCourseIds.concat((<any>user).roles.instructor);
121-
121+
122122
// Publish matching courses
123123
return courses.find({ _id: { $in:course_ids } });
124124
}

collections/users.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Meteor } from 'meteor/meteor';
55
SCHEMA
66
***/
77
declare var SimpleSchema: any;
8+
declare var nconf: any
89

910
if (Meteor.isServer){
1011
Meteor.startup(function(){
@@ -25,7 +26,8 @@ if (Meteor.isServer){
2526
},
2627
school: {
2728
type: String,
28-
optional: true
29+
optional: true,
30+
defaultValue: nconf.get('domain_school')
2931
},
3032
email: {
3133
type: String

private/settings.domain.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"domain_root" : "cmu.tuxlab.org"
2+
"domain_root" : "cmu.tuxlab.org",
3+
"domain_school" : "Carnegie Mellon University"
34
}

0 commit comments

Comments
 (0)