<commit_before>import { Injectable } from '@angular/core';
import { NavigationExtras, Router } from '@angular/router';

import { SearchRequestBuilder } from '../models/search.request.builder';
import { SearchResultsProvider } from '../providers/search-results.provider';


@Injectable()
export class NavigationProvider {
    locationError: string;
    updateSearchCallback: () => void;


    constructor(
        protected _searchResultsProvider: SearchResultsProvider,
        protected _searchRequestBuilder: SearchRequestBuilder,
        protected _router: Router
    ) {}

    initialize() {
        this.locationError = undefined;
    }

    info() {
        this._router.navigate( ['info'] );
    }

    home() {
        // If not on the home page and there's a text search, retain the text search
        if (this._searchResultsProvider.searchRequest 
            && this._searchResultsProvider.searchRequest.searchType === 's'
            && !this._router.isActive('search', false)) {

            let queryParams = { q: this._searchResultsProvider.searchRequest.searchText };
            if (this._searchResultsProvider.searchRequest.drilldown && this._searchResultsProvider.searchRequest.drilldown.length > 0) {
                queryParams['drilldown'] = this._searchResultsProvider.searchRequest.drilldown;
            }

            let navigationExtras: NavigationExtras = { queryParams: queryParams };
            this._router.navigate( ['search'], navigationExtras );
            this._searchResultsProvider.search(null);
        } else {
            this._searchResultsProvider.setEmptyRequest();
            let navigationExtras: NavigationExtras = { queryParams: { } };
            this._router.navigate( ['search'], navigationExtras );
        }
    }

    searchToday() {
        let navigationExtras: NavigationExtras = { queryParams: { } };
        this._router.navigate( ['byday'], navigationExtras );

        // If on the byday page, refresh the search (to clear a different date or page)
        if (this._router.isActive('byday', false)) {
            let today = new Date();
            this._searchResultsProvider.searchRequest.month = today.getMonth() + 1;
            this._searchResultsProvider.searchRequest.day = today.getDate();
            this._searchResultsProvider.searchRequest.first = 1;
            this._searchResultsProvider.search(null);
        }
    }

    searchByDay(month: number, day: number) {
        this._searchResultsProvider.searchRequest.day = day;
        this._searchResultsProvider.searchRequest.month = month;
        this._searchResultsProvider.searchRequest.searchType = 'd';

        let navigationExtras: NavigationExtras = { queryParams: { m: month, d: day } };
        this._router.navigate(['byday'], navigationExtras);
        this.updateSearchCallback();
    }

    searchNearby() {
        this.locationError = undefined;

        if (window.navigator.geolocation) {
            let timer = setTimeout( () => this.locationError = 'Unable to get location: timeout', 5000);

            window.navigator.geolocation.getCurrentPosition(
                (position: Position) => {

                    let navigationExtras: NavigationExtras = {
                        queryParams: { lat: position.coords.latitude, lon: position.coords.longitude }
                    };

                    this._router.navigate( ['bylocation'], navigationExtras);
                },<commit_msg>ByDay page - next/previous day buttons correctly start at the first page<commit_after>import { Injectable } from '@angular/core';
import { NavigationExtras, Router } from '@angular/router';

import { SearchRequestBuilder } from '../models/search.request.builder';
import { SearchResultsProvider } from '../providers/search-results.provider';


@Injectable()
export class NavigationProvider {
    locationError: string;
    updateSearchCallback: () => void;


    constructor(
        protected _searchResultsProvider: SearchResultsProvider,
        protected _searchRequestBuilder: SearchRequestBuilder,
        protected _router: Router
    ) {}

    initialize() {
        this.locationError = undefined;
    }

    info() {
        this._router.navigate( ['info'] );
    }

    home() {
        // If not on the home page and there's a text search, retain the text search
        if (this._searchResultsProvider.searchRequest 
            && this._searchResultsProvider.searchRequest.searchType === 's'
            && !this._router.isActive('search', false)) {

            let queryParams = { q: this._searchResultsProvider.searchRequest.searchText };
            if (this._searchResultsProvider.searchRequest.drilldown && this._searchResultsProvider.searchRequest.drilldown.length > 0) {
                queryParams['drilldown'] = this._searchResultsProvider.searchRequest.drilldown;
            }

            let navigationExtras: NavigationExtras = { queryParams: queryParams };
            this._router.navigate( ['search'], navigationExtras );
            this._searchResultsProvider.search(null);
        } else {
            this._searchResultsProvider.setEmptyRequest();
            let navigationExtras: NavigationExtras = { queryParams: { } };
            this._router.navigate( ['search'], navigationExtras );
        }
    }

    searchToday() {
        let navigationExtras: NavigationExtras = { queryParams: { } };
        this._router.navigate( ['byday'], navigationExtras );

        // If on the byday page, refresh the search (to clear a different date or page)
        if (this._router.isActive('byday', false)) {
            let today = new Date();
            this._searchResultsProvider.searchRequest.month = today.getMonth() + 1;
            this._searchResultsProvider.searchRequest.day = today.getDate();
            this._searchResultsProvider.searchRequest.first = 1;
            this._searchResultsProvider.search(null);
        }
    }

    searchByDay(month: number, day: number) {
        this._searchResultsProvider.searchRequest.day = day;
        this._searchResultsProvider.searchRequest.month = month;
        this._searchResultsProvider.searchRequest.first = 1;
        this._searchResultsProvider.searchRequest.searchType = 'd';

        let navigationExtras: NavigationExtras = { queryParams: { m: month, d: day } };
        this._router.navigate(['byday'], navigationExtras);
        this.updateSearchCallback();
    }

    searchNearby() {
        this.locationError = undefined;

        if (window.navigator.geolocation) {
            let timer = setTimeout( () => this.locationError = 'Unable to get location: timeout', 5000);

            window.navigator.geolocation.getCurrentPosition(
                (position: Position) => {

                    let navigationExtras: NavigationExtras = {
                        queryParams: { lat: position.coords.latitude, lon: position.coords.longitude }
                    };

                    this._router.navigate( ['bylocation'], navigationExtras);
                },
{'fraction_non_alphanumeric': 0.10707157114342743, 'fraction_numerical': 0.00213857998289136, 'mean_word_length': 2.5974358974358975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4153645', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1739, 'n_words': 370}