@@ -29,6 +29,7 @@ export default class Overview extends Observable {
2929 this . model = model ;
3030
3131 this . clearLogs ( ) ;
32+ this . resetFilters ( false ) ;
3233
3334 this . createdLog = RemoteData . NotAsked ( ) ;
3435 this . title = '' ;
@@ -55,6 +56,18 @@ export default class Overview extends Observable {
5556 const params = {
5657 'page[offset]' : offset ,
5758 'page[limit]' : this . logsPerPage ,
59+ ...this . titleFilterText && {
60+ 'filter[title]' : this . titleFilterText ,
61+ } ,
62+ ...this . authorFilterText && {
63+ 'filter[author]' : this . authorFilterText ,
64+ } ,
65+ ...this . createdFilterFrom && {
66+ 'filter[created][from]' : new Date ( `${ this . createdFilterFrom } T00:00:00.000` ) . getTime ( ) ,
67+ } ,
68+ ...this . createdFilterTo && {
69+ 'filter[created][to]' : new Date ( `${ this . createdFilterTo } T23:59:59.999` ) . getTime ( ) ,
70+ } ,
5871 ...this . tagFilterValues . length > 0 && {
5972 'filter[tag][values]' : this . tagFilterValues . join ( ) ,
6073 'filter[tag][operation]' : this . tagFilterOperation . toLowerCase ( ) ,
@@ -262,6 +275,78 @@ export default class Overview extends Observable {
262275 return this . expandedFilters . includes ( targetKey ) ;
263276 }
264277
278+ /**
279+ * Returns the current title substring filter
280+ * @returns {String } The current title substring filter
281+ */
282+ getTitleFilter ( ) {
283+ return this . titleFilterText ;
284+ }
285+
286+ /**
287+ * Sets the title substring filter if no new inputs were detected for 200 milliseconds
288+ * @param {String } newTitle The title substring to apply to the filter
289+ * @returns {undefined }
290+ */
291+ setTitleFilter ( newTitle ) {
292+ clearTimeout ( this . titleFilterDebounce ) ;
293+ this . titleFilterDebounce = setTimeout ( ( ) => {
294+ this . titleFilterText = newTitle . trim ( ) ;
295+ this . fetchAllLogs ( ) ;
296+ } , 200 ) ;
297+ }
298+
299+ /**
300+ * Returns the current author substring filter
301+ * @returns {String } The current author substring filter
302+ */
303+ getAuthorFilter ( ) {
304+ return this . authorFilterText ;
305+ }
306+
307+ /**
308+ * Sets the author substring filter if no new inputs were detected for 200 milliseconds
309+ * @param {String } newAuthor The author substring to apply to the filter
310+ * @returns {undefined }
311+ */
312+ setAuthorFilter ( newAuthor ) {
313+ clearTimeout ( this . authorFilterDebounce ) ;
314+ this . authorFilterDebounce = setTimeout ( ( ) => {
315+ this . authorFilterText = newAuthor . trim ( ) ;
316+ this . fetchAllLogs ( ) ;
317+ } , 200 ) ;
318+ }
319+
320+ /**
321+ * Returns the current minimum creation datetime
322+ * @returns {Integer } The current minimum creation datetime
323+ */
324+ getCreatedFilterFrom ( ) {
325+ return this . createdFilterFrom ;
326+ }
327+
328+ /**
329+ * Returns the current maximum creation datetime
330+ * @returns {Integer } The current maximum creation datetime
331+ */
332+ getCreatedFilterTo ( ) {
333+ return this . createdFilterTo ;
334+ }
335+
336+ /**
337+ * Set a datetime for the creation datetime filter
338+ * @param {String } key The filter value to apply the datetime to
339+ * @param {Object } date The datetime to be applied to the creation datetime filter
340+ * @param {Boolean } valid Whether the inserted date passes validity check
341+ * @returns {undefined }
342+ */
343+ setCreatedFilter ( key , date , valid ) {
344+ if ( valid ) {
345+ this [ key ] = date ;
346+ this . fetchAllLogs ( ) ;
347+ }
348+ }
349+
265350 /**
266351 * Add a tag to the filter
267352 * @param {string } tag The tag to be added to the filter criteria
@@ -312,6 +397,30 @@ export default class Overview extends Observable {
312397 this . notify ( ) ;
313398 }
314399
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+
315424 /**
316425 * Toggles the visibility of the menu within the log amounts dropdown
317426 * @return {Boolean } The new state of the amounts dropdown
@@ -351,17 +460,13 @@ export default class Overview extends Observable {
351460 }
352461
353462 /**
354- * Sets all data related to the Logs to `NotAsked`.
463+ * Sets all data related to the Logs to `NotAsked` and clears pagination settings .
355464 * @returns {undefined }
356465 */
357466 clearLogs ( ) {
358467 this . logs = RemoteData . NotAsked ( ) ;
359468 this . collapsedColumns = [ ] ;
360-
361469 this . expandedFilters = [ ] ;
362- this . tagFilterValues = [ ] ;
363- this . tagFilterOperation = 'AND' ;
364- this . moreTags = false ;
365470
366471 this . amountDropdownVisible = false ;
367472 this . logsPerPage = 10 ;
0 commit comments