<commit_before>/*
 * Squidex Headless CMS
 *
 * @license
 * Copyright (c) <NAME>. All rights reserved
 */

import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Subscription } from 'rxjs';

import {
    AppContext,
    fadeAnimation,
    ImmutableArray,
    ModalView,
    SchemaDto,
    SchemasService
} from 'shared';

import {
    SchemaCloning,
    SchemaCreated,
    SchemaDeleted,
    SchemaUpdated
} from './../messages';

@Component({
    selector: 'sqx-schemas-page',
    styleUrls: ['./schemas-page.component.scss'],
    templateUrl: './schemas-page.component.html',
    providers: [
        AppContext
    ],
    animations: [
        fadeAnimation
    ]
})
export class SchemasPageComponent implements OnDestroy, OnInit {
    private schemaUpdatedSubscription: Subscription;
    private schemaDeletedSubscription: Subscription;
    private schemaCloningSubscription: Subscription;

    public addSchemaDialog = new ModalView();

    public schemas = ImmutableArray.empty<SchemaDto>();
    public schemaQuery: string;
    public schemasFilter = new FormControl();
    public schemasFiltered = ImmutableArray.empty<SchemaDto>();

    public import: any;

    constructor(public readonly ctx: AppContext,
        private readonly schemasService: SchemasService
    ) {
    }

    public ngOnDestroy() {
        this.schemaUpdatedSubscription.unsubscribe();
        this.schemaDeletedSubscription.unsubscribe();
        this.schemaCloningSubscription.unsubscribe();
    }

    public ngOnInit() {
        this.schemasFilter.valueChanges
            .distinctUntilChanged()
            .debounceTime(100)
            .subscribe(q => {
                this.updateSchemas(this.schemas, this.schemaQuery = q);
            });

        this.ctx.route.params.map(q => q['showDialog'])
            .subscribe(showDialog => {
                if (showDialog) {
                    this.addSchemaDialog.show();
                }
            });

        this.schemaCloningSubscription =
            this.ctx.bus.of(SchemaCloning)
                .subscribe(m => {
                    this.createSchema(m.importing);
                });

        this.schemaUpdatedSubscription =
            this.ctx.bus.of(SchemaUpdated)
                .subscribe(m => {
                    this.updateSchemas(this.schemas.replaceBy('id', m.schema));
                });

        this.schemaDeletedSubscription =
            this.ctx.bus.of(SchemaDeleted)
                .subscribe(m => {
                    this.updateSchemas(this.schemas.filter(s => s.id !== m.schema.id));
                });

        this.load();
    }

    public createSchema(importing: any) {
        this.import = importing;

        this.addSchemaDialog.show();
    }

    private load() {
        this.schemasService.getSchemas(this.ctx.appName)
            .subscribe(dtos => {
                this.updateSchemas(ImmutableArray.of(dtos));
            }, error => {
                this.ctx.notifyError(error);
            });
    }

    public onSchemaCreated(schema: SchemaDto) {
        this.updateSchemas(this.schemas.push(schema), this.schemaQuery);
        this.emitSchemaCreated(schema);

        this.addSchemaDialog.hide();
    }

    private emitSchemaCreated(schema: SchemaDto) {
        this.ctx.bus.emit(new SchemaCreated(schema));
    }

    private updateSchemas(schemas: ImmutableArray<SchemaDto>, query?: string) {
        this.schemas = schemas;

        query = query || this.schemaQuery;

        if (query && query.length > 0) {
            schemas = schemas.filter(t => t.name.indexOf(query!) >= 0);
        }

        this.schemasFiltered = schemas.sortByStringAsc(x => x.name);
    }
}
<commit_msg>Redirect directly to new schema..<commit_after>/*
 * Squidex Headless CMS
 *
 * @license
 * Copyright (c) <NAME>. All rights reserved
 */

import { Component, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { FormControl } from '@angular/forms';
import { Subscription } from 'rxjs';

import {
    AppContext,
    fadeAnimation,
    ImmutableArray,
    ModalView,
    SchemaDto,
    SchemasService
} from 'shared';

import {
    SchemaCloning,
    SchemaCreated,
    SchemaDeleted,
    SchemaUpdated
} from './../messages';

@Component({
    selector: 'sqx-schemas-page',
    styleUrls: ['./schemas-page.component.scss'],
    templateUrl: './schemas-page.component.html',
    providers: [
        AppContext
    ],
    animations: [
        fadeAnimation
    ]
})
export class SchemasPageComponent implements OnDestroy, OnInit {
    private schemaUpdatedSubscription: Subscription;
    private schemaDeletedSubscription: Subscription;
    private schemaCloningSubscription: Subscription;

    public addSchemaDialog = new ModalView();

    public schemas = ImmutableArray.empty<SchemaDto>();
    public schemaQuery: string;
    public schemasFilter = new FormControl();
    public schemasFiltered = ImmutableArray.empty<SchemaDto>();

    public import: any;

    constructor(public readonly ctx: AppContext,
        private readonly router: Router,
        private readonly schemasService: SchemasService
    ) {
    }

    public ngOnDestroy() {
        this.schemaUpdatedSubscription.unsubscribe();
        this.schemaDeletedSubscription.unsubscribe();
        this.schemaCloningSubscription.unsubscribe();
    }

    public ngOnInit() {
        this.schemasFilter.valueChanges
            .distinctUntilChanged()
            .debounceTime(100)
            .subscribe(q => {
                this.updateSchemas(this.schemas, this.schemaQuery = q);
            });

        this.ctx.route.params.map(q => q['showDialog'])
            .subscribe(showDialog => {
                if (showDialog) {
                    this.addSchemaDialog.show();
                }
            });

        this.schemaCloningSubscription =
            this.ctx.bus.of(SchemaCloning)
                .subscribe(m => {
                    this.createSchema(m.importing);
                });

        this.schemaUpdatedSubscription =
            this.ctx.bus.of(SchemaUpdated)
                .subscribe(m => {
                    this.updateSchemas(this.schemas.replaceBy('id', m.schema));
                });

        this.schemaDeletedSubscription =
            this.ctx.bus.of(SchemaDeleted)
                .subscribe(m => {
                    this.updateSchemas(this.schemas.filter(s => s.id !== m.schema.id));
                });

        this.load();
    }

    public createSchema(importing: any) {
        this.import = importing;

        this.addSchemaDialog.show();
    }

    private load() {
        this.schemasService.getSchemas(this.ctx.appName)
            .subscribe(dtos => {
                this.updateSchemas(ImmutableArray.of(dtos));
            }, error => {
                this.ctx.notifyError(error);
            });
    }

    public onSchemaCreated(schema: SchemaDto) {
        this.updateSchemas(this.schemas.push(schema), this.schemaQuery);
        this.emitSchemaCreated(schema);

        this.addSchemaDialog.hide();

        this.router.navigate([ schema.name ], { relativeTo: this.ctx.route });
    }

    private emitSchemaCreated(schema: SchemaDto) {
        this.ctx.bus.emit(new SchemaCreated(schema));
    }

    private updateSchemas(schemas: ImmutableArray<SchemaDto>, query?: string) {
        this.schemas = schemas;

        query = query || this.schemaQuery;

        if (query && query.length > 0) {
            schemas = schemas.filter(t => t.name.indexOf(query!) >= 0);
        }

        this.schemasFiltered = schemas.sortByStringAsc(x => x.name);
    }
}

{'fraction_non_alphanumeric': 0.11609120521172639, 'fraction_numerical': 0.0013029315960912053, 'mean_word_length': 2.2076890931884665, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, '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': '5397762', 'n_tokens_mistral': 2165, 'n_tokens_neox': 2093, 'n_words': 370}