<commit_before>import { Component, ElementRef, OnInit, ViewChild } from "@angular/core";
import { ActivatedRoute } from "@angular/router";

import { GastroLocation } from "../model/gastro-location";
import { GastroQuery } from "../model/gastro-query";
import { ShoppingLocation } from "../model/shopping-location";
import { ShoppingQuery } from "../model/shopping-query";
import { GoogleMapComponent } from "../google-map/google-map.component";
import { I18nService } from "../i18n.service";
import { Location } from "../model/location";
import { LocationService } from "../location.service";
import { ResultsListComponent } from "../results-list/results-list.component";
import { SearchComponent } from "../search/search.component";
import { SearchService } from "../search.service";
import { SortOrder } from "../sort/sort-order";

@Component({
    selector: "app-main",
    templateUrl: "./main.component.html",
    styleUrls: [ "./main.component.scss" ],
})
export class MainComponent implements OnInit {

    constructor(
        private readonly route: ActivatedRoute,
        private readonly i18nService: I18nService,
        private readonly locationService: LocationService,
        private readonly searchService: SearchService,
    ) {}

    @ViewChild(SearchComponent) searchComponent: SearchComponent;
    @ViewChild(ResultsListComponent) resultsListComponent: ResultsListComponent;
    @ViewChild(GoogleMapComponent) googleMapComponent: GoogleMapComponent;
    @ViewChild("preSearchDiv") preSearchDiv: ElementRef;

    readonly i18n = this.i18nService.getI18n();
    readonly initialSortOrder = "name";
    sortOrder: SortOrder = this.initialSortOrder;
    allLocations: (GastroLocation | ShoppingLocation)[] = [];
    filteredLocations: (GastroLocation | ShoppingLocation)[] = [];
    query: GastroQuery | ShoppingQuery;
    isGastro: boolean | undefined;
    fullMapView = false;
    coordinates: Coordinates | null = null;

    ngOnInit() {
        this.route
            .url
            .subscribe(url => {
                const path = url[0].path;
                switch (path) {
                    case "gastro":
                        this.initGastro();
                        break;
                    case "shopping":
                        this.initShopping();
                        break;
                    default:
                        throw new Error("Unexpected path: " + path);
                }
            });
    }

    initGastro() {
        this.query = new GastroQuery();
        this.searchComponent.init(this.query);
        this.isGastro = true;
        this.locationService.getGastroLocations()
            .then(locations => {
                this.allLocations = locations;
                this.filteredLocations = locations;
                this.googleMapComponent.init(locations);
            });
    }

    initShopping() {
        this.query = new ShoppingQuery();
        this.searchComponent.init(this.query);
        this.isGastro = false;
        this.locationService.getShoppingLocations()
            .then(locations => {
                this.allLocations = locations;
                this.filteredLocations = locations;
                this.googleMapComponent.init(locations);
            });
    }

    onQueryChange(query: GastroQuery | ShoppingQuery) {
        this.query = query;
        this.updateFilteredLocations();
    }

    onSortOrderChange(sortOrder: SortOrder) {
        this.sortOrder = sortOrder;
        this.updateFilteredLocations();
    }

    updateFilteredLocations() {
        this.filteredLocations =
            this.allLocations
                .filter(it => this.searchService.isResult(it, this.query))
                .sort(this.getSortFunction());
    }
<commit_msg>Bug fix: Initial sort order<commit_after>import { Component, ElementRef, OnInit, ViewChild } from "@angular/core";
import { ActivatedRoute } from "@angular/router";

import { GastroLocation } from "../model/gastro-location";
import { GastroQuery } from "../model/gastro-query";
import { ShoppingLocation } from "../model/shopping-location";
import { ShoppingQuery } from "../model/shopping-query";
import { GoogleMapComponent } from "../google-map/google-map.component";
import { I18nService } from "../i18n.service";
import { Location } from "../model/location";
import { LocationService } from "../location.service";
import { ResultsListComponent } from "../results-list/results-list.component";
import { SearchComponent } from "../search/search.component";
import { SearchService } from "../search.service";
import { SortOrder } from "../sort/sort-order";

@Component({
    selector: "app-main",
    templateUrl: "./main.component.html",
    styleUrls: [ "./main.component.scss" ],
})
export class MainComponent implements OnInit {

    constructor(
        private readonly route: ActivatedRoute,
        private readonly i18nService: I18nService,
        private readonly locationService: LocationService,
        private readonly searchService: SearchService,
    ) {}

    @ViewChild(SearchComponent) searchComponent: SearchComponent;
    @ViewChild(ResultsListComponent) resultsListComponent: ResultsListComponent;
    @ViewChild(GoogleMapComponent) googleMapComponent: GoogleMapComponent;
    @ViewChild("preSearchDiv") preSearchDiv: ElementRef;

    readonly i18n = this.i18nService.getI18n();
    readonly initialSortOrder = "name";
    sortOrder: SortOrder = this.initialSortOrder;
    allLocations: (GastroLocation | ShoppingLocation)[] = [];
    filteredLocations: (GastroLocation | ShoppingLocation)[] = [];
    query: GastroQuery | ShoppingQuery;
    isGastro: boolean | undefined;
    fullMapView = false;
    coordinates: Coordinates | null = null;

    ngOnInit() {
        this.route
            .url
            .subscribe(url => {
                const path = url[0].path;
                switch (path) {
                    case "gastro":
                        this.initGastro();
                        break;
                    case "shopping":
                        this.initShopping();
                        break;
                    default:
                        throw new Error("Unexpected path: " + path);
                }
            });
    }

    initGastro() {
        this.query = new GastroQuery();
        this.searchComponent.init(this.query);
        this.isGastro = true;
        this.locationService.getGastroLocations()
            .then(locations => {
                this.allLocations = locations;
                this.filteredLocations = locations.sort(this.getSortFunction());
                this.googleMapComponent.init(locations);
            });
    }

    initShopping() {
        this.query = new ShoppingQuery();
        this.searchComponent.init(this.query);
        this.isGastro = false;
        this.locationService.getShoppingLocations()
            .then(locations => {
                this.allLocations = locations;
                this.filteredLocations = locations.sort(this.getSortFunction());
                this.googleMapComponent.init(locations);
            });
    }

    onQueryChange(query: GastroQuery | ShoppingQuery) {
        this.query = query;
        this.updateFilteredLocations();
    }

    onSortOrderChange(sortOrder: SortOrder) {
        this.sortOrder = sortOrder;
        this.updateFilteredLocations();
    }

    updateFilteredLocations() {
        this.filteredLocations =
            this.allLocations
                .filter(it => this.searchService.isResult(it, this.query))
                .sort(this.getSortFunction());
    }

{'fraction_non_alphanumeric': 0.11446259220231823, 'fraction_numerical': 0.003951527924130664, 'mean_word_length': 2.358248562582928, 'pattern_counts': {'":': 4, '<': 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': '4108828', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1941, 'n_words': 396}