Browse Source

Fixes.

pull/356/head
Sebastian Stehle 7 years ago
parent
commit
74d9543dfb
  1. 4
      src/Squidex/app/features/administration/state/users.state.ts
  2. 16
      src/Squidex/app/framework/utils/rxjs-extensions.ts
  3. 5
      src/Squidex/app/shared/state/apps.state.ts
  4. 4
      src/Squidex/app/shared/state/backups.state.ts
  5. 9
      src/Squidex/app/shared/state/clients.state.ts
  6. 37
      src/Squidex/app/shared/state/contents.state.ts
  7. 3
      src/Squidex/app/shared/state/contributors.state.ts
  8. 5
      src/Squidex/app/shared/state/languages.state.ts
  9. 7
      src/Squidex/app/shared/state/patterns.state.ts
  10. 5
      src/Squidex/app/shared/state/roles.state.ts
  11. 5
      src/Squidex/app/shared/state/rules.state.ts
  12. 68
      src/Squidex/app/shared/state/schemas.state.ts

4
src/Squidex/app/features/administration/state/users.state.ts

@ -139,9 +139,9 @@ export class UsersState extends State<Snapshot> {
public create(request: CreateUserDto): Observable<UserDto> {
return this.usersService.postUser(request).pipe(
tap(payload => {
tap(created => {
this.next(s => {
const users = s.users.pushFront(this.createUser(payload));
const users = s.users.pushFront(this.createUser(created));
const usersPager = s.usersPager.incrementCount();
return { ...s, users, usersPager };

16
src/Squidex/app/framework/utils/rxjs-extensions.ts

@ -26,9 +26,13 @@ export function mapVersioned<T = any, R = any>(project: (value: T, version: Vers
};
}
type Options<T, R = T> = { silent?: boolean, project?: ((value: T) => R) };
type Options = { silent?: boolean };
export function shareSubscribed<T, R = T>(dialogs: DialogService, options?: Options<T, R>) {
export function shareSubscribed<T>(dialogs: DialogService, options?: Options) {
return shareMapSubscribed<T, T>(dialogs, x => x, options);
}
export function shareMapSubscribed<T, R = T>(dialogs: DialogService, project: (value: T) => R, options?: Options) {
return function mapOperation(source: Observable<T>) {
const shared = source.pipe(publishReplay(), refCount());
@ -42,13 +46,7 @@ export function shareSubscribed<T, R = T>(dialogs: DialogService, options?: Opti
}))
.subscribe();
if (options && !!options.project) {
const project = options.project;
return shared.pipe(map(x => project(x)));
} else {
return <any>shared;
}
return shared.pipe(map(x => project(x)));
};
}

5
src/Squidex/app/shared/state/apps.state.ts

@ -84,9 +84,10 @@ export class AppsState extends State<Snapshot> {
public create(request: CreateAppDto, now?: DateTime): Observable<AppDto> {
return this.appsService.postApp(request).pipe(
tap(payload => {
map(payload => createApp(request, payload, now)),
tap(created => {
this.next(s => {
const apps = s.apps.push(createApp(request, payload, now)).sortByStringAsc(x => x.name);
const apps = s.apps.push(created).sortByStringAsc(x => x.name);
return { ...s, apps };
});

4
src/Squidex/app/shared/state/backups.state.ts

@ -58,13 +58,13 @@ export class BackupsState extends State<Snapshot> {
}
return this.backupsService.getBackups(this.appName).pipe(
tap(payload => {
tap(items => {
if (isReload && !silent) {
this.dialogs.notifyInfo('Backups reloaded.');
}
this.next(s => {
const backups = ImmutableArray.of(payload);
const backups = ImmutableArray.of(items);
return { ...s, backups, isLoaded: true };
});

9
src/Squidex/app/shared/state/clients.state.ts

@ -15,6 +15,7 @@ import {
DialogService,
ImmutableArray,
mapVersioned,
shareMapSubscribed,
shareSubscribed,
State,
Version
@ -66,12 +67,12 @@ export class ClientsState extends State<Snapshot> {
}
return this.clientsService.getClients(this.appName).pipe(
tap(({ version, payload: newClients }) => {
tap(({ version, payload }) => {
if (isReload) {
this.dialogs.notifyInfo('Clients reloaded.');
}
const clients = ImmutableArray.of(newClients);
const clients = ImmutableArray.of(payload);
this.next(s => {
return { ...s, clients, isLoaded: true, version };
@ -89,7 +90,7 @@ export class ClientsState extends State<Snapshot> {
return { ...s, clients, version: version };
});
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public revoke(client: ClientDto): Observable<any> {
@ -114,7 +115,7 @@ export class ClientsState extends State<Snapshot> {
return { ...s, clients, version };
});
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
private get appName() {

37
src/Squidex/app/shared/state/contents.state.ts

@ -14,7 +14,6 @@ import {
DialogService,
ErrorDto,
ImmutableArray,
mapVersioned,
Pager,
shareSubscribed,
State,
@ -202,78 +201,78 @@ export abstract class ContentsStateBase extends State<Snapshot> {
public publishChanges(content: ContentDto, dueTime: string | null, now?: DateTime): Observable<ContentDto> {
return this.contentsService.changeContentStatus(this.appName, this.schemaName, content.id, 'Publish', dueTime, content.version).pipe(
mapVersioned(({ version }) => {
map(({ version }) => {
if (dueTime) {
return changeScheduleStatus(content, 'Published', dueTime, this.user, version, now);
} else {
return confirmChanges(content, this.user, version, now);
}
}),
tap(({ payload }) => {
tap(updated => {
this.dialogs.notifyInfo('Content updated successfully.');
this.replaceContent(payload);
this.replaceContent(updated);
}),
shareSubscribed(this.dialogs));
}
public changeStatus(content: ContentDto, action: string, status: string, dueTime: string | null, now?: DateTime): Observable<ContentDto> {
return this.contentsService.changeContentStatus(this.appName, this.schemaName, content.id, action, dueTime, content.version).pipe(
mapVersioned(({ version }) => {
map(({ version }) => {
if (dueTime) {
return changeScheduleStatus(content, status, dueTime, this.user, version, now);
} else {
return changeStatus(content, status, this.user, version, now);
}
}),
tap(({ payload }) => {
tap(updated => {
this.dialogs.notifyInfo('Content updated successfully.');
this.replaceContent(payload);
this.replaceContent(updated);
}),
shareSubscribed(this.dialogs));
}
public update(content: ContentDto, request: any, now?: DateTime): Observable<ContentDto> {
return this.contentsService.putContent(this.appName, this.schemaName, content.id, request, false, content.version).pipe(
mapVersioned((payload, version) => updateData(content, payload, this.user, version, now)),
tap(({ payload }) => {
map(({ payload, version }) => updateData(content, payload, this.user, version, now)),
tap(updated => {
this.dialogs.notifyInfo('Content updated successfully.');
this.replaceContent(payload, content.version);
this.replaceContent(updated, content.version);
}),
shareSubscribed(this.dialogs));
}
public proposeUpdate(content: ContentDto, request: any, now?: DateTime): Observable<ContentDto> {
return this.contentsService.putContent(this.appName, this.schemaName, content.id, request, true, content.version).pipe(
mapVersioned((payload, version) => updateDataDraft(content, payload, this.user, version, now)),
tap(({ payload }) => {
map(({ payload, version }) => updateDataDraft(content, payload, this.user, version, now)),
tap(updated => {
this.dialogs.notifyInfo('Content updated successfully.');
this.replaceContent(payload, content.version);
this.replaceContent(updated, content.version);
}),
shareSubscribed(this.dialogs));
}
public discardChanges(content: ContentDto, now?: DateTime): Observable<ContentDto> {
return this.contentsService.discardChanges(this.appName, this.schemaName, content.id, content.version).pipe(
mapVersioned((_, version) => discardChanges(content, this.user, version, now)),
tap(({ payload }) => {
map(({ version }) => discardChanges(content, this.user, version, now)),
tap(updated => {
this.dialogs.notifyInfo('Content updated successfully.');
this.replaceContent(payload, content.version);
this.replaceContent(updated, content.version);
}),
shareSubscribed(this.dialogs));
}
public patch(content: ContentDto, request: any, now?: DateTime): Observable<ContentDto> {
return this.contentsService.patchContent(this.appName, this.schemaName, content.id, request, content.version).pipe(
mapVersioned((data, version) => updateData(content, data, this.user, version, now)),
tap(({ payload }) => {
map(({ payload, version }) => updateData(content, payload, this.user, version, now)),
tap(updated => {
this.dialogs.notifyInfo('Content updated successfully.');
this.replaceContent(payload, content.version);
this.replaceContent(updated, content.version);
}),
shareSubscribed(this.dialogs));
}

3
src/Squidex/app/shared/state/contributors.state.ts

@ -13,6 +13,7 @@ import {
DialogService,
ErrorDto,
ImmutableArray,
shareMapSubscribed,
shareSubscribed,
State,
Types,
@ -124,7 +125,7 @@ export class ContributorsState extends State<Snapshot> {
this.replaceContributors(contributors, version);
}),
shareSubscribed(this.dialogs, { project: x => x.payload.isCreated }));
shareMapSubscribed(this.dialogs, x => x.payload.isCreated));
}
private updateContributors(id: string, role: string) {

5
src/Squidex/app/shared/state/languages.state.ts

@ -13,6 +13,7 @@ import {
DialogService,
ImmutableArray,
mapVersioned,
shareMapSubscribed,
shareSubscribed,
State,
Version
@ -121,7 +122,7 @@ export class LanguagesState extends State<Snapshot> {
this.replaceLanguages(languages, version);
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public remove(language: AppLanguageDto): Observable<any> {
@ -150,7 +151,7 @@ export class LanguagesState extends State<Snapshot> {
this.replaceLanguages(languages, version);
}),
shareSubscribed(this.dialogs));
shareMapSubscribed(this.dialogs, x => x.payload));
}
private replaceLanguages(languages: AppLanguagesList, version: Version, allLanguages?: LanguageList) {

7
src/Squidex/app/shared/state/patterns.state.ts

@ -13,6 +13,7 @@ import {
DialogService,
ImmutableArray,
mapVersioned,
shareMapSubscribed,
shareSubscribed,
State,
Version
@ -74,7 +75,7 @@ export class PatternsState extends State<Snapshot> {
return { ...s, patterns, isLoaded: true, version: version };
});
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public create(request: EditPatternDto): Observable<PatternDto> {
@ -86,7 +87,7 @@ export class PatternsState extends State<Snapshot> {
return { ...s, patterns, version: version };
});
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public update(pattern: PatternDto, request: EditPatternDto): Observable<PatternDto> {
@ -99,7 +100,7 @@ export class PatternsState extends State<Snapshot> {
return { ...s, patterns, version: version };
});
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public delete(pattern: PatternDto): Observable<any> {

5
src/Squidex/app/shared/state/roles.state.ts

@ -13,6 +13,7 @@ import {
DialogService,
ImmutableArray,
mapVersioned,
shareMapSubscribed,
shareSubscribed,
State,
Version
@ -87,7 +88,7 @@ export class RolesState extends State<Snapshot> {
return { ...s, roles, version };
});
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public delete(role: RoleDto): Observable<any> {
@ -112,7 +113,7 @@ export class RolesState extends State<Snapshot> {
return { ...s, roles, version };
});
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
private get appName() {

5
src/Squidex/app/shared/state/rules.state.ts

@ -80,9 +80,10 @@ export class RulesState extends State<Snapshot> {
public create(request: UpsertRuleDto, now?: DateTime): Observable<RuleDto> {
return this.rulesService.postRule(this.appName, request).pipe(
tap(response => {
map(payload => createRule(request, payload, this.user, now)),
tap(created => {
this.next(s => {
const rules = s.rules.push(createRule(request, response, this.user, now));
const rules = s.rules.push(created);
return { ...s, rules };
});

68
src/Squidex/app/shared/state/schemas.state.ts

@ -14,6 +14,7 @@ import {
DialogService,
ImmutableArray,
mapVersioned,
shareMapSubscribed,
shareSubscribed,
State,
Types,
@ -139,9 +140,10 @@ export class SchemasState extends State<Snapshot> {
public create(request: CreateSchemaDto, now?: DateTime): Observable<SchemaDetailsDto> {
return this.schemasService.postSchema(this.appName, request).pipe(
tap(response => {
map(payload => createSchema(request, payload, this.user, now)),
tap(created => {
this.next(s => {
const schemas = s.schemas.push(createSchema(request, response, this.user, now)).sortByStringAsc(x => x.displayName);
const schemas = s.schemas.push(created).sortByStringAsc(x => x.displayName);
return { ...s, schemas };
});
@ -181,8 +183,8 @@ export class SchemasState extends State<Snapshot> {
public publish(schema: SchemaDto, now?: DateTime): Observable<SchemaDto> {
return this.schemasService.publishSchema(this.appName, schema.name, schema.version).pipe(
map(({ version }) => setPublished(schema, true, this.user, version, now)),
tap(newSchema => {
this.replaceSchema(newSchema);
tap(updated => {
this.replaceSchema(updated);
}),
shareSubscribed(this.dialogs));
}
@ -190,8 +192,8 @@ export class SchemasState extends State<Snapshot> {
public unpublish(schema: SchemaDto, now?: DateTime): Observable<SchemaDto> {
return this.schemasService.unpublishSchema(this.appName, schema.name, schema.version).pipe(
map(({ version }) => setPublished(schema, false, this.user, version, now)),
tap(newSchema => {
this.replaceSchema(newSchema);
tap(updated => {
this.replaceSchema(updated);
}),
shareSubscribed(this.dialogs));
}
@ -199,8 +201,8 @@ export class SchemasState extends State<Snapshot> {
public changeCategory(schema: SchemaDto, name: string, now?: DateTime): Observable<SchemaDto> {
return this.schemasService.putCategory(this.appName, schema.name, { name }, schema.version).pipe(
map(({ version }) => changeCategory(schema, name, this.user, version, now)),
tap(newSchema => {
this.replaceSchema(newSchema);
tap(updated => {
this.replaceSchema(updated);
}),
shareSubscribed(this.dialogs));
}
@ -208,8 +210,8 @@ export class SchemasState extends State<Snapshot> {
public configurePreviewUrls(schema: SchemaDetailsDto, request: {}, now?: DateTime): Observable<SchemaDetailsDto> {
return this.schemasService.putPreviewUrls(this.appName, schema.name, request, schema.version).pipe(
map(({ version }) => configurePreviewUrls(schema, request, this.user, version, now)),
tap(newSchema => {
this.replaceSchema(newSchema);
tap(updated => {
this.replaceSchema(updated);
}),
shareSubscribed(this.dialogs));
}
@ -217,8 +219,8 @@ export class SchemasState extends State<Snapshot> {
public configureScripts(schema: SchemaDetailsDto, request: {}, now?: DateTime): Observable<SchemaDetailsDto> {
return this.schemasService.putScripts(this.appName, schema.name, request, schema.version).pipe(
map(({ version }) => configureScripts(schema, request, this.user, version, now)),
tap(newSchema => {
this.replaceSchema(newSchema);
tap(updated => {
this.replaceSchema(updated);
}),
shareSubscribed(this.dialogs));
}
@ -226,8 +228,8 @@ export class SchemasState extends State<Snapshot> {
public update(schema: SchemaDetailsDto, request: UpdateSchemaDto, now?: DateTime): Observable<SchemaDetailsDto> {
return this.schemasService.putSchema(this.appName, schema.name, request, schema.version).pipe(
map(({ version }) => updateProperties(schema, request, this.user, version, now)),
tap(newSchema => {
this.replaceSchema(newSchema);
tap(updated => {
this.replaceSchema(updated);
}),
shareSubscribed(this.dialogs));
}
@ -235,37 +237,37 @@ export class SchemasState extends State<Snapshot> {
public addField(schema: SchemaDetailsDto, request: AddFieldDto, parent?: RootFieldDto, now?: DateTime): Observable<FieldDto> {
return this.schemasService.postField(this.appName, schema.name, request, pid(parent), schema.version).pipe(
map(({ version, payload }) => {
let newSchema: SchemaDto;
let updated: SchemaDto;
if (Types.is(payload, NestedFieldDto)) {
newSchema = updateField(schema, addNested(parent!, payload), this.user, version, now);
updated = updateField(schema, addNested(parent!, payload), this.user, version, now);
} else {
newSchema = addField(schema, payload, this.user, version, now);
updated = addField(schema, payload, this.user, version, now);
}
return { newSchema, field: payload };
return { updated, field: payload };
}),
tap(({ newSchema }) => {
this.replaceSchema(newSchema);
tap(({ updated }) => {
this.replaceSchema(updated);
}),
shareSubscribed(this.dialogs, { silent: true, project: x => x.field }));
shareMapSubscribed(this.dialogs, x => x.field, { silent: true }));
}
public sortFields(schema: SchemaDetailsDto, fields: any[], parent?: RootFieldDto, now?: DateTime): Observable<SchemaDetailsDto> {
return this.schemasService.putFieldOrdering(this.appName, schema.name, fields.map(t => t.fieldId), pid(parent), schema.version).pipe(
map(({ version }) => {
let newSchema: SchemaDto;
let updated: SchemaDetailsDto;
if (!parent) {
newSchema = replaceFields(schema, fields, this.user, version, now);
updated = replaceFields(schema, fields, this.user, version, now);
} else {
newSchema = updateField(schema, replaceNested(parent, fields), this.user, version, now);
updated = updateField(schema, replaceNested(parent, fields), this.user, version, now);
}
return newSchema;
return updated;
}),
tap(newSchema => {
this.replaceSchema(newSchema);
tap(updated => {
this.replaceSchema(updated);
}),
shareSubscribed(this.dialogs));
}
@ -276,7 +278,7 @@ export class SchemasState extends State<Snapshot> {
tap(({ version, payload }) => {
this.replaceField(schema, payload, version, now);
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public enableField<T extends FieldDto>(schema: SchemaDetailsDto, field: T, now?: DateTime): Observable<T> {
@ -285,7 +287,7 @@ export class SchemasState extends State<Snapshot> {
tap(({ version, payload }) => {
this.replaceField(schema, payload, version, now);
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public disableField<T extends FieldDto>(schema: SchemaDetailsDto, field: T, now?: DateTime): Observable<T> {
@ -294,7 +296,7 @@ export class SchemasState extends State<Snapshot> {
tap(({ version, payload }) => {
this.replaceField(schema, payload, version, now);
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public showField<T extends FieldDto>(schema: SchemaDetailsDto, field: T, now?: DateTime): Observable<T> {
@ -303,7 +305,7 @@ export class SchemasState extends State<Snapshot> {
tap(({ version, payload }) => {
this.replaceField(schema, payload, version, now);
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public hideField<T extends FieldDto>(schema: SchemaDetailsDto, field: T, now?: DateTime): Observable<T> {
@ -312,7 +314,7 @@ export class SchemasState extends State<Snapshot> {
tap(({ version, payload }) => {
this.replaceField(schema, payload, version, now);
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public updateField<T extends FieldDto>(schema: SchemaDetailsDto, field: T, request: UpdateFieldDto, now?: DateTime): Observable<T> {
@ -321,7 +323,7 @@ export class SchemasState extends State<Snapshot> {
tap(({ version, payload }) => {
this.replaceField(schema, payload, version, now);
}),
shareSubscribed(this.dialogs, { project: x => x.payload }));
shareMapSubscribed(this.dialogs, x => x.payload));
}
public deleteField(schema: SchemaDetailsDto, field: AnyFieldDto, now?: DateTime): Observable<any> {

Loading…
Cancel
Save