Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

70 lines
1.9 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Observable } from 'rxjs';
import {
AppComponentBase,
AppsStoreService,
NotificationService,
SchemaDto,
SchemasService
} from 'shared';
@Component({
selector: 'sqx-schemas-page',
styleUrls: ['./schemas-page.component.scss'],
templateUrl: './schemas-page.component.html'
})
export class SchemasPageComponent extends AppComponentBase {
public schemasFilter = new FormControl();
public schemasFiltered =
this.schemasFilter.valueChanges
.startWith(null)
.distinctUntilChanged()
.debounceTime(300)
.combineLatest(this.loadSchemas(),
(query, schemas) => {
this.schemasFilter.setValue(query);
schemas = schemas.filter(t => t.isPublished);
if (query && query.length > 0) {
schemas = schemas.filter(t => t.name.indexOf(query) >= 0);
}
return schemas;
}).map(schemas => {
return schemas.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
});
constructor(apps: AppsStoreService, notifications: NotificationService,
private readonly schemasService: SchemasService
) {
super(notifications, apps);
}
private loadSchemas(): Observable<SchemaDto[]> {
return this.appName()
.switchMap(app => this.schemasService.getSchemas(app).retry(2))
.catch(error => {
this.notifyError(error);
return [];
});
}
}