1
1
import { Component , HostBinding } from '@angular/core' ;
2
2
3
3
import { UpgradableComponent } from 'theme/components/upgradable' ;
4
+ import { TablesService } from './tables.service' ;
4
5
5
6
@Component ( {
6
7
selector : 'app-tables' ,
@@ -18,210 +19,56 @@ export class TablesComponent extends UpgradableComponent {
18
19
@HostBinding ( 'class.mdl-cell--top' ) private readonly mdlCellTop = true ;
19
20
@HostBinding ( 'class.ui-tables' ) private readonly uiTables = true ;
20
21
21
- public headers = [
22
- '#' ,
23
- 'Book title' ,
24
- 'Author' ,
25
- 'First published' ,
26
- 'Status' ,
27
- ] ;
22
+ public constructor ( private tablesService : TablesService ) {
23
+ super ( ) ;
24
+ }
28
25
29
- public simpleTable = [
30
- [
31
- '1' ,
32
- 'To Kill a Mockingbird' ,
33
- 'Harper Lee' ,
34
- '1960' ,
35
- 'read' ,
36
- ] ,
37
- [
38
- '2' ,
39
- 'Pride and Prejudice' ,
40
- 'Jane Austen' ,
41
- '1813' ,
42
- 'unread' ,
43
- ] ,
44
- [
45
- '3' ,
46
- 'The Great Gatsby' ,
47
- 'F. Scott Fitzgerald' ,
48
- '1925' ,
49
- 'read' ,
50
- ] ,
51
- [
52
- '4' ,
53
- 'Crime and Punishment' ,
54
- 'Fyodor Dostoyevsky' ,
55
- '1866' ,
56
- 'read' ,
57
- ] ,
58
- ] ;
59
-
60
- public borderedTable = [
61
- [
62
- '23' ,
63
- 'Gone with the Wind' ,
64
- 'Margaret Mitchell' ,
65
- '1936' ,
66
- 'unread' ,
67
- ] ,
68
- [
69
- '24' ,
70
- 'The Count of Monte Cristo' ,
71
- 'Alexandre Dumas' ,
72
- '1845' ,
73
- 'unread' ,
74
- ] ,
75
- [
76
- '25' ,
77
- 'Lolita' ,
78
- 'Vladimir Nabokov' ,
79
- '1955' ,
80
- 'read' ,
81
- ] ,
82
- [
83
- '26' ,
84
- 'The Hobbit' ,
85
- 'J.R.R. Tolkien' ,
86
- '1937' ,
87
- 'unread' ,
88
- ] ,
89
- ] ;
90
-
91
- public strippedTable = [
92
- [
93
- '54' ,
94
- 'The Hitchhiker\'s Guide to th...' ,
95
- 'Douglas Adams' ,
96
- '1979' ,
97
- 'unavailable' ,
98
- ] ,
99
- [
100
- '55' ,
101
- 'Madame Bovary' ,
102
- 'Gustave Flaubert' ,
103
- '1856' ,
104
- 'available' ,
105
- ] ,
106
- [
107
- '56' ,
108
- 'David Copperfield' ,
109
- 'Charles Dickens' ,
110
- '1850' ,
111
- 'available' ,
112
- ] ,
113
- [
114
- '57' ,
115
- 'War and Peace' ,
116
- 'Leo Tolstoy' ,
117
- '1869' ,
118
- 'available' ,
119
- ] ,
120
- ] ;
121
-
122
- public borderlessTable = [
123
- [
124
- '31' ,
125
- 'The Little Prince' ,
126
- 'Antoine de Saint-Exupery' ,
127
- '1943' ,
128
- 'available' ,
129
- ] ,
130
- [
131
- '32' ,
132
- 'Les Miserables' ,
133
- 'Victor Hugo' ,
134
- '1862' ,
135
- 'unavailable' ,
136
- ] ,
137
- [
138
- '33' ,
139
- 'Alice in Wonderland' ,
140
- 'Lewis Carroll' ,
141
- '1865' ,
142
- 'available' ,
143
- ] ,
144
- [
145
- '34' ,
146
- 'Anne of Green Gables' ,
147
- 'L.M. Montgomery' ,
148
- '1908' ,
149
- 'available' ,
150
- ] ,
151
- ] ;
152
-
153
- public advancedHeaders = [
154
- '#' ,
155
- 'Book title' ,
156
- 'Author' ,
157
- 'Genre' ,
158
- 'Year' ,
159
- 'Originally published' ,
160
- 'Language' ,
161
- 'Original Language' ,
162
- 'Availability' ,
163
- ] ;
164
-
165
- public advancedTableFullData = [
166
- [
167
- '5' ,
168
- 'Life of Pi' ,
169
- 'Yann Martel' ,
170
- [
171
- 'Fiction' ,
172
- ] ,
173
- '2016' ,
174
- '2001' ,
175
- 'English' ,
176
- 'English' ,
177
- 4 ,
178
- ] ,
179
- [
180
- '6' ,
181
- 'The secret Garden' ,
182
- 'Frances Hodgson Burnett' ,
183
- [
184
- 'Childeren\'s literature' ,
185
- ] ,
186
- '2017' ,
187
- '1911' ,
188
- 'English' ,
189
- 'English' ,
190
- 1 ,
191
- ] ,
192
- [
193
- '7' ,
194
- 'Rebecca' ,
195
- 'Daphne du Maurier' ,
196
- [
197
- 'Gothic fiction' ,
198
- ] ,
199
- '2016' ,
200
- '1938' ,
201
- 'English' ,
202
- 'English' ,
203
- 2 ,
204
- ] ,
205
- [
206
- '8' ,
207
- 'Dracula' ,
208
- 'Bram Stoker' ,
209
- [
210
- 'Gothic fiction' ,
211
- 'Horror fiction' ,
212
- ] ,
213
- '2015' ,
214
- '1897' ,
215
- 'English' ,
216
- 'English' ,
217
- 0 ,
218
- ] ,
219
- ] ;
26
+ public readonly sortOrder = {
27
+ asc : 1 ,
28
+ desc : - 1 ,
29
+ } ;
220
30
31
+ public headers = this . tablesService . getHeaders ( ) ;
32
+ public simpleTable = this . tablesService . getSimpleTable ( ) ;
33
+ public borderedTable = this . tablesService . getBorderedTable ( ) ;
34
+ public strippedTable = this . tablesService . getStrippedTable ( ) ;
35
+ public borderlessTable = this . tablesService . getBorderlessTable ( ) ;
36
+ public advancedHeaders = this . tablesService . getAdvancedHeaders ( ) ;
221
37
public genreColors = {
222
38
'Childeren\'s literature' : 'orange' ,
223
39
'Gothic fiction' : 'purple' ,
224
40
'Horror fiction' : 'dark-gray' ,
225
41
'Fiction' : 'green' ,
42
+ 'Novel' : 'teal' ,
43
+ 'Fantasy' : 'red' ,
44
+ 'Adventure' : 'light-blue' ,
226
45
} ;
46
+
47
+ public currentPage = 1 ;
48
+ private countPerPage = 4 ;
49
+ public numPage = this . tablesService . getAdvancedTableNumOfPage ( this . countPerPage ) ;
50
+
51
+ public advancedTable = this . tablesService . getAdvancedTablePage ( 1 , this . countPerPage ) ;
52
+
53
+ public changePage ( page , force = false ) {
54
+ if ( page !== this . currentPage || force ) {
55
+ this . currentPage = page ;
56
+ this . advancedTable = this . tablesService . getAdvancedTablePage ( page , this . countPerPage ) ;
57
+ }
58
+ }
59
+
60
+ /* available sort value:
61
+ -1 - desc; 0 - no sorting; 1 - asc; null - disabled */
62
+ public changeSorting ( header , index ) {
63
+ const current = header . sort ;
64
+ if ( current !== null ) {
65
+ this . advancedHeaders . forEach ( ( cell ) => {
66
+ cell . sort = ( cell . sort !== null ) ? 0 : null ;
67
+ } ) ;
68
+ header . sort = ( current === 1 ) ? - 1 : 1 ;
69
+ this . tablesService . changeAdvanceSorting ( header . sort , index ) ;
70
+ this . changePage ( 1 , true ) ;
71
+ }
72
+ }
73
+
227
74
}
0 commit comments