mirror of https://github.com/Squidex/squidex.git
27 changed files with 2211 additions and 1709 deletions
@ -0,0 +1,19 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using Newtonsoft.Json.Linq; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.UI.Models |
||||
|
{ |
||||
|
public sealed class UpdateSettingDto |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The value for the setting.
|
||||
|
/// </summary>
|
||||
|
public JToken Value { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,79 @@ |
|||||
|
/* |
||||
|
* Squidex Headless CMS |
||||
|
* |
||||
|
* @license |
||||
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
||||
|
*/ |
||||
|
|
||||
|
import { BehaviorSubject } from 'rxjs'; |
||||
|
import { IMock, Mock, Times } from 'typemoq'; |
||||
|
|
||||
|
import { Query, SchemaQueries } from './schema-queries'; |
||||
|
import { UIState } from './ui.state'; |
||||
|
|
||||
|
describe('SchemaQueries', () => { |
||||
|
const schema = 'my-schema'; |
||||
|
|
||||
|
let uiState: IMock<UIState>; |
||||
|
let filter = new BehaviorSubject(''); |
||||
|
let queries = new BehaviorSubject({}); |
||||
|
let schemaQueries: SchemaQueries; |
||||
|
|
||||
|
beforeEach(() => { |
||||
|
uiState = Mock.ofType<UIState>(); |
||||
|
|
||||
|
uiState.setup(x => x.get('schemas.my-schema.queries', {})) |
||||
|
.returns(() => queries); |
||||
|
|
||||
|
queries.next({ |
||||
|
key1: 'query1', |
||||
|
key2: 'query2' |
||||
|
}); |
||||
|
|
||||
|
schemaQueries = new SchemaQueries(uiState.object, schema); |
||||
|
}); |
||||
|
|
||||
|
it('should load queries', () => { |
||||
|
let converted: Query[]; |
||||
|
|
||||
|
schemaQueries.queries.subscribe(x => { |
||||
|
converted = x; |
||||
|
}); |
||||
|
|
||||
|
expect(converted!).toEqual([ |
||||
|
{ |
||||
|
name: 'key1', |
||||
|
nameSortable: 'KEY1', |
||||
|
filter: 'query1' |
||||
|
}, { |
||||
|
name: 'key2', |
||||
|
nameSortable: 'KEY2', |
||||
|
filter: 'query2' |
||||
|
} |
||||
|
]); |
||||
|
}); |
||||
|
|
||||
|
it('should provide key', () => { |
||||
|
let key: string; |
||||
|
|
||||
|
schemaQueries.getSaveKey(filter).subscribe(x => { |
||||
|
key = x!; |
||||
|
}); |
||||
|
|
||||
|
filter.next('query2'); |
||||
|
|
||||
|
expect(key!).toEqual('key2'); |
||||
|
}); |
||||
|
|
||||
|
it('should forward add call to state', () => { |
||||
|
schemaQueries.add('key3', 'filter3'); |
||||
|
|
||||
|
uiState.verify(x => x.set('schemas.my-schema.queries.key3', 'filter3'), Times.once()); |
||||
|
}); |
||||
|
|
||||
|
it('should forward remove call to state', () => { |
||||
|
schemaQueries.remove('key3'); |
||||
|
|
||||
|
uiState.verify(x => x.remove('schemas.my-schema.queries.key3'), Times.once()); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,78 @@ |
|||||
|
/* |
||||
|
* 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; |
||||
|
}) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
public add(key: string, filter: string) { |
||||
|
this.uiState.set(`schemas.${this.schemaName}.queries.${key}`, filter); |
||||
|
} |
||||
|
|
||||
|
public remove(key: string) { |
||||
|
this.uiState.remove(`schemas.${this.schemaName}.queries.${key}`); |
||||
|
} |
||||
|
|
||||
|
public getSaveKey(filter$: Observable<string>): Observable<string | null> { |
||||
|
return combineLatest(this.queries, filter$).pipe( |
||||
|
map(project => { |
||||
|
const filter = project[1]; |
||||
|
|
||||
|
if (filter) { |
||||
|
for (let query of project[0]) { |
||||
|
if (query.filter === filter) { |
||||
|
return query.name; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return null; |
||||
|
})); |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
Binary file not shown.
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 80 KiB |
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Loading…
Reference in new issue