<commit_before>/**
 * @license
 * Copyright 2017 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {Component, OnDestroy} from "@angular/core";
import {ActivatedRoute} from "@angular/router";

import {ApisService} from "../../services/apis.service";
import {Api} from "../../models/api.model";
import {ArrayUtils} from "../../util/common";
import {AbstractPageComponent} from "../../components/page-base.component";
import {Title} from "@angular/platform-browser";


const API_FILTERS_KEY = "apicurio.studio.pages.apis.filters";


class Filters {
    nameFilter: string;
    sortDirection: string;
    layout: string;

    constructor(params?: any) {
        this.reset();
        if (params) {
            for (let key in params) {
                let value: string = params[key];
                this[key] = value;
            }
        }
    }

    public accepts(api: Api): boolean {
        let name: string = api.name.toLocaleLowerCase();
        let namef: string = this.nameFilter.toLocaleLowerCase();
        if (name.indexOf(namef) >= 0) {
            return true;
        }
        if (api.tags && api.tags.length > 0) {
            return api.tags.map(tag => {
                return tag.toLocaleLowerCase() == namef;
            }).reduce( (v1, v2) => {
                return v1 || v2;
            });
        }
        return false;
    }

    public reset(): void {
        this.nameFilter = "";
        this.sortDirection = "ASC";
        this.layout = "card";
    }
}


@Component({
    moduleId: module.id,
    selector: "apis-page",
    templateUrl: "apis.page.html",
    styleUrls: ["apis.page.css"]
})
export class ApisPageComponent extends AbstractPageComponent implements OnDestroy {

    public allApis: Api[] = [];
    public filteredApis: Api[];
    public selectedApis: Api[];
    public filters: Filters = new Filters();

    public numApisToDelete: number = 0;

    /**
     * C'tor.
     * @param {ApisService} apis
     * @param {ActivatedRoute} route
     * @param {Title} titleService<commit_msg>Reduce scope of filters property<commit_after>/**
 * @license
 * Copyright 2017 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {Component, OnDestroy} from "@angular/core";
import {ActivatedRoute} from "@angular/router";

import {ApisService} from "../../services/apis.service";
import {Api} from "../../models/api.model";
import {ArrayUtils} from "../../util/common";
import {AbstractPageComponent} from "../../components/page-base.component";
import {Title} from "@angular/platform-browser";


const API_FILTERS_KEY = "apicurio.studio.pages.apis.filters";


class Filters {
    nameFilter: string;
    sortDirection: string;
    layout: string;

    constructor(params?: any) {
        this.reset();
        if (params) {
            for (let key in params) {
                let value: string = params[key];
                this[key] = value;
            }
        }
    }

    public accepts(api: Api): boolean {
        let name: string = api.name.toLocaleLowerCase();
        let namef: string = this.nameFilter.toLocaleLowerCase();
        if (name.indexOf(namef) >= 0) {
            return true;
        }
        if (api.tags && api.tags.length > 0) {
            return api.tags.map(tag => {
                return tag.toLocaleLowerCase() == namef;
            }).reduce( (v1, v2) => {
                return v1 || v2;
            });
        }
        return false;
    }

    public reset(): void {
        this.nameFilter = "";
        this.sortDirection = "ASC";
        this.layout = "card";
    }
}


@Component({
    moduleId: module.id,
    selector: "apis-page",
    templateUrl: "apis.page.html",
    styleUrls: ["apis.page.css"]
})
export class ApisPageComponent extends AbstractPageComponent implements OnDestroy {

    public allApis: Api[] = [];
    public filteredApis: Api[];
    public selectedApis: Api[];
    private filters: Filters = new Filters();

    public numApisToDelete: number = 0;

    /**
     * C'tor.
     * @param {ApisService} apis
     * @param {ActivatedRoute} route
     * @param {Title} titleService
{'fraction_non_alphanumeric': 0.12524309607156747, 'fraction_numerical': 0.005834305717619603, 'mean_word_length': 2.4915139171758316, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2395138', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1453, 'n_words': 455}