3636 viewProviders : [ MdIconRegistry ] ,
3737 encapsulation : ViewEncapsulation . None
3838 } )
39-
39+
4040// Export Explore Class
4141export 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-
0 commit comments