@@ -21,133 +21,134 @@ import { Observable } from '/js/src/index.js';
2121 * Model representing handlers for homePage.js
2222 */
2323export default class Overview extends Observable {
24- /**
25- * @param {Object } model
26- */
27- constructor ( model ) {
28- super ( ) ;
29- this . model = model ;
30- this . date = new Date ( ) . toDateString ( ) ;
31- this . filterCriteria = [ ] ;
32- this . data = [
33- {
34- authorID : 'Batman' ,
35- title : 'Run1' ,
36- creationTime : this . date ,
37- tags : [ 'Tag1' , 'Tag2' ] ,
38- } ,
39- {
40- authorID : 'Joker' ,
41- title : 'Run2' ,
42- creationTime : this . date ,
43- tags : [ 'Tag2' ] ,
44- } ,
45- {
46- authorID : 'Anonymous' ,
47- title : 'Run5' ,
48- creationTime : this . date ,
49- tags : [ 'Tag3' ] ,
50- } ,
51- ] ;
52- this . filtered = [ ...this . data ] ;
53- this . headers = [ 'ID' , 'Author ID' , 'Title' , 'Creation Time' ] ;
54- }
55- /**
56- * @returns {Array } headers
57- */
58- getHeaders ( ) {
59- return this . headers ;
60- }
24+ /**
25+ * @param {Object } model
26+ */
27+ constructor ( model ) {
28+ super ( ) ;
29+ this . model = model ;
30+ this . date = new Date ( ) . toDateString ( ) ;
31+ this . filterCriteria = [ ] ;
32+ this . data = [
33+ {
34+ authorID : 'Batman' ,
35+ title : 'Run1' ,
36+ creationTime : this . date ,
37+ tags : [ 'Tag1' , 'Tag2' ] ,
38+ } ,
39+ {
40+ authorID : 'Joker' ,
41+ title : 'Run2' ,
42+ creationTime : this . date ,
43+ tags : [ 'Tag2' ] ,
44+ } ,
45+ {
46+ authorID : 'Anonymous' ,
47+ title : 'Run5' ,
48+ creationTime : this . date ,
49+ tags : [ 'Tag3' ] ,
50+ } ,
51+ ] ;
52+ this . filtered = [ ...this . data ] ;
53+ this . headers = [ 'ID' , 'Author ID' , 'Title' , 'Creation Time' ] ;
54+ }
55+ /**
56+ * @returns {Array } headers
57+ */
58+ getHeaders ( ) {
59+ return this . headers ;
60+ }
6161
62- /**
63- * @returns {Array } subentries
64- */
65- getTableData ( ) {
66- const subentries = this . filtered . map ( entry => {
67- const filter = Object . keys ( entry ) . map ( subkey => {
68- if ( subkey !== 'tags' ) {
69- return entry [ subkey ] ;
70- }
71- } ) ;
62+ /**
63+ * @returns {Array } subentries
64+ */
65+ getTableData ( ) {
66+ const subentries = this . filtered . map ( entry => {
67+ const filter = Object . keys ( entry ) . map ( subkey => {
68+ if ( subkey !== 'tags' ) {
69+ return entry [ subkey ] ;
70+ }
71+ } ) ;
7272
73- return filter ;
74- } ) ;
73+ return filter ;
74+ } ) ;
7575
76- return subentries ;
77- }
76+ return subentries ;
77+ }
7878
79- /**
80- * Add filter to the selection
81- * @param {string } tag
82- */
83- addFilter ( tag ) {
84- this . filterCriteria = [ ...this . filterCriteria , tag ] ;
85- this . getFilteredData ( ) ;
86- }
87-
88- /**
89- * Remove filter from the selection
90- * @param {string } condition
91- */
92- removeFilter ( condition ) {
93- this . filterCriteria = this . filterCriteria . filter ( tag => tag !== condition ) ;
94- this . getFilteredData ( ) ;
95- }
79+ /**
80+ * Add filter to the selection
81+ * @param {string } tag
82+ */
83+ addFilter ( tag ) {
84+ this . filterCriteria = [ ...this . filterCriteria , tag ] ;
85+ this . getFilteredData ( ) ;
86+ }
9687
97- /**
98- * Filter the data
99- */
100- getFilteredData ( ) {
101- this . filterCriteria . length !== 0
102- ? this . filterByTags ( )
103- : ( this . filtered = [ ...this . data ] ) ;
88+ /**
89+ * Remove filter from the selection
90+ * @param {string } condition
91+ */
92+ removeFilter ( condition ) {
93+ this . filterCriteria = this . filterCriteria . filter ( tag => tag !== condition ) ;
94+ this . getFilteredData ( ) ;
95+ }
10496
105- this . notify ( ) ;
106- }
107- /**
108- * Filter data by tags if applicable
97+ /**
98+ * Filter the data
10999 */
110- filterByTags ( ) {
111- this . filtered = this . data
112- . map ( entry => {
113- let match = this . checkExistingTag ( entry ) ;
100+ getFilteredData ( ) {
101+ this . filterCriteria . length !== 0
102+ ? this . filterByTags ( )
103+ : ( this . filtered = [ ... this . data ] ) ;
114104
115- if ( match ) {
116- return entry ;
117- }
105+ this . notify ( ) ;
106+ }
118107
119- return null ;
120- } )
121- . filter ( entry => entry !== null ) ;
122- }
108+ /**
109+ * Filter data by tags if applicable
110+ */
111+ filterByTags ( ) {
112+ this . filtered = this . data
113+ . map ( entry => {
114+ let match = this . checkExistingTag ( entry ) ;
123115
124- /**
125- * Check for an existing tag
126- * @param {object } entry
127- * @return {bool }
128- */
129- checkExistingTag ( entry ) {
130- const check = this . filterCriteria . map ( tag => {
131- const match = entry . tags . includes ( tag ) ;
132- if ( match ) {
133- return 'Match' ;
134- }
135- return 'No Match' ;
136- } ) ;
116+ if ( match ) {
117+ return entry ;
118+ }
137119
138- return check . includes ( 'Match' ) ;
139- }
120+ return null ;
121+ } )
122+ . filter ( entry => entry !== null ) ;
123+ }
140124
141- /**
142- * Counts the tags with their total appearances
143- * @return {object }
144- */
145- getTagCounts ( ) {
146- return this . data . reduce ( ( accumulator , currentValue ) => {
147- currentValue . tags . forEach ( tag => {
148- accumulator [ tag ] = ( accumulator [ tag ] || 0 ) + 1 ;
149- } ) ;
150- return accumulator ;
151- } , { } ) ;
152- }
125+ /**
126+ * Check for an existing tag
127+ * @param {object } entry
128+ * @return {bool }
129+ */
130+ checkExistingTag ( entry ) {
131+ const check = this . filterCriteria . map ( tag => {
132+ const match = entry . tags . includes ( tag ) ;
133+ if ( match ) {
134+ return 'Match' ;
135+ }
136+ return 'No Match' ;
137+ } ) ;
138+
139+ return check . includes ( 'Match' ) ;
140+ }
141+
142+ /**
143+ * Counts the tags with their total appearances
144+ * @return {object }
145+ */
146+ getTagCounts ( ) {
147+ return this . data . reduce ( ( accumulator , currentValue ) => {
148+ currentValue . tags . forEach ( tag => {
149+ accumulator [ tag ] = ( accumulator [ tag ] || 0 ) + 1 ;
150+ } ) ;
151+ return accumulator ;
152+ } , { } ) ;
153+ }
153154}
0 commit comments