@@ -32,29 +32,21 @@ export default class Overview extends Observable {
3232 this . resetFilters ( false ) ;
3333
3434 this . createdLog = RemoteData . NotAsked ( ) ;
35- this . title = '' ;
36- this . text = '' ;
37-
38- this . isPreviewActive = false ;
39- this . editors = [ ] ;
40-
41- this . collapsableColumns = [ ] ;
42- this . collapsedColumns = [ ] ;
35+ this . clearAllEditors ( ) ;
4336 }
4437
4538 /**
4639 * Retrieve every relevant log from the API
47- * @param {Number } offset Pagination offset to include when making the API call
4840 * @returns {undefined } Injects the data object with the response data
4941 */
50- async fetchAllLogs ( offset = 0 ) {
42+ async fetchAllLogs ( ) {
5143 if ( ! this . model . tags . getTags ( ) . isSuccess ( ) ) {
5244 this . logs = RemoteData . loading ( ) ;
5345 this . notify ( ) ;
5446 }
5547
5648 const params = {
57- 'page[offset]' : offset ,
49+ 'page[offset]' : ( this . selectedPage - 1 ) * this . logsPerPage ,
5850 'page[limit]' : this . logsPerPage ,
5951 ...this . titleFilterText && {
6052 'filter[title]' : this . titleFilterText ,
@@ -252,6 +244,51 @@ export default class Overview extends Observable {
252244 return this . createdLog ;
253245 }
254246
247+ /**
248+ * Returns all filters and pagination settings to their default values
249+ * @param {Boolean } fetch Whether to refetch all logs after filters have been reset
250+ * @return {undefined }
251+ */
252+ resetFilters ( fetch = true ) {
253+ this . expandedFilters = [ ] ;
254+
255+ this . titleFilterText = '' ;
256+ this . titleFilterDebounce = null ;
257+
258+ this . authorFilterText = '' ;
259+ this . authorFilterDebounce = null ;
260+
261+ this . createdFilterFrom = '' ;
262+ this . createdFilterTo = '' ;
263+
264+ this . tagFilterOperation = 'AND' ;
265+ this . tagFilterValues = [ ] ;
266+ this . moreTags = false ;
267+
268+ this . amountDropdownVisible = false ;
269+ this . logsPerPage = 10 ;
270+ this . selectedPage = 1 ;
271+ this . totalPages = 1 ;
272+
273+ if ( fetch ) {
274+ this . fetchAllLogs ( ) ;
275+ }
276+ }
277+
278+ /**
279+ * Checks if any filter value has been modified from their default (empty)
280+ * @returns {Boolean } If any filter is active
281+ */
282+ isAnyFilterActive ( ) {
283+ return (
284+ this . titleFilterText !== ''
285+ || this . authorFilterText !== ''
286+ || this . createdFilterFrom !== ''
287+ || this . createdFilterTo !== ''
288+ || this . tagFilterValues . length !== 0
289+ ) ;
290+ }
291+
255292 /**
256293 * Toggle the expansion state (visibility) of a filter menu
257294 * @param {String } targetKey The key of the filter whose visibility should be toggled
@@ -397,30 +434,6 @@ export default class Overview extends Observable {
397434 this . notify ( ) ;
398435 }
399436
400- /**
401- * Returns all filters to their default (empty) values
402- * @param {Boolean } fetch Whether to refetch all logs after filters have been reset
403- * @return {undefined }
404- */
405- resetFilters ( fetch = true ) {
406- this . titleFilterText = '' ;
407- this . titleFilterDebounce = null ;
408-
409- this . authorFilterText = '' ;
410- this . authorFilterDebounce = null ;
411-
412- this . createdFilterFrom = null ;
413- this . createdFilterTo = null ;
414-
415- this . tagFilterOperation = 'AND' ;
416- this . tagFilterValues = [ ] ;
417- this . moreTags = false ;
418-
419- if ( fetch ) {
420- this . fetchAllLogs ( ) ;
421- }
422- }
423-
424437 /**
425438 * Toggles the visibility of the menu within the log amounts dropdown
426439 * @return {Boolean } The new state of the amounts dropdown
@@ -439,11 +452,10 @@ export default class Overview extends Observable {
439452 if ( this . logsPerPage !== amount ) {
440453 this . logsPerPage = amount ;
441454 this . selectedPage = 1 ;
442- this . fetchAllLogs ( ( this . selectedPage - 1 ) * amount ) ;
455+ this . fetchAllLogs ( ) ;
443456 }
444457
445458 this . amountDropdownVisible = false ;
446- this . notify ( ) ;
447459 }
448460
449461 /**
@@ -454,8 +466,7 @@ export default class Overview extends Observable {
454466 setSelectedPage ( page ) {
455467 if ( this . selectedPage !== page ) {
456468 this . selectedPage = page ;
457- this . fetchAllLogs ( ( this . selectedPage - 1 ) * this . logsPerPage ) ;
458- this . notify ( ) ;
469+ this . fetchAllLogs ( ) ;
459470 }
460471 }
461472
@@ -465,13 +476,8 @@ export default class Overview extends Observable {
465476 */
466477 clearLogs ( ) {
467478 this . logs = RemoteData . NotAsked ( ) ;
479+ this . collapsableColumns = [ ] ;
468480 this . collapsedColumns = [ ] ;
469- this . expandedFilters = [ ] ;
470-
471- this . amountDropdownVisible = false ;
472- this . logsPerPage = 10 ;
473- this . selectedPage = 1 ;
474- this . totalPages = 1 ;
475481 }
476482
477483 /**
@@ -484,19 +490,16 @@ export default class Overview extends Observable {
484490 }
485491
486492 /**
487- * Clear the model variables to prevent memory leaks
493+ * Clear all editors in the model
488494 * @returns {undefined }
489495 */
490- flushModel ( ) {
491- this . rootLogId = - 1 ;
492- this . parentLogId = - 1 ;
496+ clearAllEditors ( ) {
493497 this . isPreviewActive = false ;
498+ this . parentLogId = - 1 ;
494499 this . text = '' ;
495500 this . title = '' ;
496501 this . editor = null ;
497502 this . editors = [ ] ;
498- this . collapsedColumns = [ ] ;
499- this . isCollapsed = false ;
500503
501504 // Remove trailing CodeMirror div(s)
502505 removeElement ( '.CodeMirror' ) ;
0 commit comments