<commit_before>/*
 * Squidex Headless CMS
 *
 * @license
 * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
 */

import { combineLatest, Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { UIState } from './ui.state';

export interface Query {
    name: string;
    nameSortable?: string;
    filter: string;
}

export class SchemaQueries {
    public queries: Observable<Query[]>;

    public defaultQueries: Query[] = [{
        name: 'All (newest first)', filter: ''
    }, {
        name: 'All (oldest first)', filter: '$orderby=lastModified desc'
    }];

    constructor(
        private readonly uiState: UIState,
        private readonly schemaName: string
    ) {
        this.queries = this.uiState.get(`schemas.${this.schemaName}.queries`, {}).pipe(
            map(x => {
                let queries: Query[] = Object.keys(x).map(y => ({ name: y, filter: x[y] }));

                for (let query of queries) {
                    query.nameSortable = query.name.toUpperCase();
                }

                queries = queries.sort((a, b) => {
                    if (a.nameSortable! < b.nameSortable!) {
                        return -1;
                    }
                    if (a.nameSortable! > b.nameSortable!) {
                        return 1;
                    }
                    return 0;
                });

                return queries;
            })
        );
    }<commit_msg>Queries fixed<commit_after>/*
 * Squidex Headless CMS
 *
 * @license
 * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
 */

import { combineLatest, Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { UIState } from './ui.state';

export interface Query {
    name: string;
    nameSortable?: string;
    filter: string;
}

export class SchemaQueries {
    public queries: Observable<Query[]>;

    public defaultQueries: Query[] = [{
        name: 'All (newest first)', filter: ''
    }, {
        name: 'All (oldest first)', filter: '$orderby=lastModified asc'
    }];

    constructor(
        private readonly uiState: UIState,
        private readonly schemaName: string
    ) {
        this.queries = this.uiState.get(`schemas.${this.schemaName}.queries`, {}).pipe(
            map(x => {
                let queries: Query[] = Object.keys(x).map(y => ({ name: y, filter: x[y] }));

                for (let query of queries) {
                    query.nameSortable = query.name.toUpperCase();
                }

                queries = queries.sort((a, b) => {
                    if (a.nameSortable! < b.nameSortable!) {
                        return -1;
                    }
                    if (a.nameSortable! > b.nameSortable!) {
                        return 1;
                    }
                    return 0;
                });

                return queries;
            })
        );
    }
{'fraction_non_alphanumeric': 0.12854700854700854, 'fraction_numerical': 0.0020512820512820513, 'mean_word_length': 1.603202846975089, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '5281264', 'n_tokens_mistral': 855, 'n_tokens_neox': 805, 'n_words': 203}