Browse Source

State updated

pull/271/head
Sebastian Stehle 9 years ago
parent
commit
af97cb3831
  1. 13
      src/Squidex/app/features/administration/pages/users/user-page.component.ts
  2. 70
      src/Squidex/app/features/administration/state/users.state.ts
  3. 2
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts
  4. 8
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts
  5. 344
      src/Squidex/app/features/schemas/state/schemas.state.ts

13
src/Squidex/app/features/administration/pages/users/user-page.component.ts

@ -11,7 +11,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { UserDto } from './../../services/users.service'; import { UserDto } from './../../services/users.service';
import { UserForm, UsersState, getSelectedUser } from './../../state/users.state'; import { UserForm, UsersState } from './../../state/users.state';
@Component({ @Component({
selector: 'sqx-user-page', selector: 'sqx-user-page',
@ -25,7 +25,7 @@ export class UserPageComponent implements OnDestroy, OnInit {
public userForm: UserForm; public userForm: UserForm;
public selectedUser = public selectedUser =
this.usersState.changes.map(getSelectedUser) this.usersState.changes.map(x => x.selectedUser)
.distinctUntilChanged(); .distinctUntilChanged();
public isCurrentUser = public isCurrentUser =
@ -46,10 +46,11 @@ export class UserPageComponent implements OnDestroy, OnInit {
public ngOnInit() { public ngOnInit() {
this.selectedUserSubscription = this.selectedUserSubscription =
this.usersState.changes.map(getSelectedUser).subscribe(user => { this.usersState.changes.map(x => x.selectedUser)
this.user = user; .subscribe(user => {
this.userForm.load(user); this.user = user;
}); this.userForm.load(user);
});
} }
public save() { public save() {

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

@ -14,6 +14,7 @@ import '@app/framework/utils/rxjs-extensions';
import { import {
AuthService, AuthService,
DialogService, DialogService,
ImmutableArray,
Pager, Pager,
Form, Form,
State, State,
@ -23,7 +24,8 @@ import {
import { import {
CreateUserDto, CreateUserDto,
UserDto, UserDto,
UsersService UsersService,
UpdateUserDto
} from './../services/users.service'; } from './../services/users.service';
export class UserForm extends Form<FormGroup> { export class UserForm extends Form<FormGroup> {
@ -69,10 +71,10 @@ export class UserForm extends Form<FormGroup> {
} }
interface Snapshot { interface Snapshot {
users: UserDto[]; users: ImmutableArray<UserDto>;
usersPager: Pager; usersPager: Pager;
usersQuery?: string; usersQuery?: string;
selectedUserId?: string | null; selectedUser?: UserDto;
isCurrentUser?: boolean; isCurrentUser?: boolean;
} }
@ -83,15 +85,15 @@ export class UsersState extends State<Snapshot> {
private readonly dialogs: DialogService, private readonly dialogs: DialogService,
private readonly usersService: UsersService private readonly usersService: UsersService
) { ) {
super({ users: [], usersPager: new Pager(10) }); super({ users: ImmutableArray.empty(), usersPager: new Pager(10) });
} }
public selectUser(selectedUserId: string | null): Observable<UserDto | null> { public selectUser(id: string | null): Observable<UserDto | null> {
return this.loadUser(selectedUserId) return this.loadUser(id)
.do(user => { .do(selectedUser => {
const isCurrentUser = selectedUserId === this.authState.user!.id; const isCurrentUser = id === this.authState.user!.id;
this.next(s => ({...s, selectedUserId, isCurrentUser })); this.next(s => ({...s, selectedUser, isCurrentUser }));
}); });
} }
@ -111,26 +113,26 @@ export class UsersState extends State<Snapshot> {
public loadUsers(notify = false): Observable<any> { public loadUsers(notify = false): Observable<any> {
return this.usersService.getUsers(this.snapshot.usersPager.pageSize, this.snapshot.usersPager.skip, this.snapshot.usersQuery) return this.usersService.getUsers(this.snapshot.usersPager.pageSize, this.snapshot.usersPager.skip, this.snapshot.usersQuery)
.catch(error => this.dialogs.notifyError(error))
.do(dtos => { .do(dtos => {
if (notify) { if (notify) {
this.dialogs.notifyInfo('Users reloaded.'); this.dialogs.notifyInfo('Users reloaded.');
} }
this.next(s => { this.next(s => {
const users = dtos.items; const users = ImmutableArray.of(dtos.items);
const usersPager = s.usersPager.setCount(dtos.total); const usersPager = s.usersPager.setCount(dtos.total);
return { ...s, users, usersPager, usersLoading: false }; return { ...s, users, usersPager, usersLoading: false };
}); });
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public createUser(request: CreateUserDto): Observable<UserDto> { public createUser(request: CreateUserDto): Observable<UserDto> {
return this.usersService.postUser(request) return this.usersService.postUser(request)
.do(dto => { .do(dto => {
this.next(s => { this.next(s => {
const users = [dto, ...s.users]; const users = s.users.pushFront(dto);
const usersPager = s.usersPager.incrementCount(); const usersPager = s.usersPager.incrementCount();
return { ...s, users, usersPager }; return { ...s, users, usersPager };
@ -143,36 +145,24 @@ export class UsersState extends State<Snapshot> {
.do(() => { .do(() => {
this.dialogs.notifyInfo('User saved successsfull'); this.dialogs.notifyInfo('User saved successsfull');
this.next(s => { this.replaceUser(update(user, request));
const users = s.users.map(u => u.id === user.id ? u.update(request.email, request.displayName) : u);
return { ...s, users };
});
}); });
} }
public lockUser(user: UserDto): Observable<any> { public lockUser(user: UserDto): Observable<any> {
return this.usersService.lockUser(user.id) return this.usersService.lockUser(user.id)
.catch(error => this.dialogs.notifyError(error))
.do(() => { .do(() => {
this.next(s => { this.replaceUser(setLocked(user, true));
const users = s.users.map(u => u.id === user.id ? u.lock() : u); })
.catch(error => this.dialogs.notifyError(error));
return { ...s, users };
});
});
} }
public unlockUser(user: UserDto): Observable<any> { public unlockUser(user: UserDto): Observable<any> {
return this.usersService.unlockUser(user.id) return this.usersService.unlockUser(user.id)
.catch(error => this.dialogs.notifyError(error))
.do(() => { .do(() => {
this.next(s => { this.replaceUser(setLocked(user, false));
const users = s.users.map(u => u.id === user.id ? u.unlock() : u); })
.catch(error => this.dialogs.notifyError(error));
return { ...s, users };
});
});
} }
public search(query: string): Observable<any> { public search(query: string): Observable<any> {
@ -192,6 +182,20 @@ export class UsersState extends State<Snapshot> {
return this.loadUsers(); return this.loadUsers();
} }
private replaceUser(user: UserDto) {
return this.next(s => {
const users = s.users.replaceBy('id', user);
const selectedUser = s.selectedUser && s.selectedUser.id === user.id ? user : s.selectedUser;
return { ...s, users, selectedUser };
});
}
} }
export const getSelectedUser = (c: Snapshot) => c.users.find(x => x.id === c.selectedUserId);
const update = (user: UserDto, request: UpdateUserDto) =>
new UserDto(user.id, request.email, request.displayName, user.pictureUrl, user.isLocked);
const setLocked = (user: UserDto, locked: boolean) =>
new UserDto(user.id, user.email, user.displayName, user.pictureUrl, locked);

2
src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts

@ -65,7 +65,7 @@ export class SchemaPageComponent implements OnDestroy, OnInit {
public ngOnInit() { public ngOnInit() {
this.selectedSchemaSubscription = this.selectedSchemaSubscription =
this.schemasState.selectedSchema this.schemasState.changes.map(x => x.selectedSchema)
.subscribe(schema => { .subscribe(schema => {
this.schema = schema!; this.schema = schema!;

8
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts

@ -32,14 +32,14 @@ export class SchemasPageComponent implements OnDestroy, OnInit {
public schemasFilter = new FormControl(); public schemasFilter = new FormControl();
public schemasFiltered = public schemasFiltered =
this.schemasState.schemasItems this.schemasState.changes.map(x => x.schemas)
.combineLatest(this.schemasFilter.valueChanges.startWith(''), .combineLatest(this.schemasFilter.valueChanges.startWith(''),
(schemas, query) => { (schemas, query) => {
if (query && query.length > 0) { if (query && query.length > 0) {
schemas = schemas.filter(t => t.name.indexOf(query) >= 0); return schemas.filter(t => t.name.indexOf(query) >= 0);
} else {
return schemas;
} }
return schemas.sortByStringAsc(x => x.name);
}); });
public import: any; public import: any;

344
src/Squidex/app/features/schemas/state/schemas.state.ts

@ -7,7 +7,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { BehaviorSubject, Observable } from 'rxjs'; import { Observable } from 'rxjs';
import '@app/framework/utils/rxjs-extensions'; import '@app/framework/utils/rxjs-extensions';
@ -25,10 +25,14 @@ import {
SchemaDto, SchemaDto,
SchemaDetailsDto, SchemaDetailsDto,
SchemasService, SchemasService,
State,
UpdateFieldDto, UpdateFieldDto,
UpdateSchemaScriptsDto, UpdateSchemaScriptsDto,
UpdateSchemaDto, UpdateSchemaDto,
ValidatorsEx ValidatorsEx,
Version,
SchemaPropertiesDto,
FieldPropertiesDto
} from '@app/shared'; } from '@app/shared';
const FALLBACK_NAME = 'my-schema'; const FALLBACK_NAME = 'my-schema';
@ -133,21 +137,13 @@ export class AddFieldForm extends Form<FormGroup> {
} }
} }
@Injectable() interface Snapshot {
export class SchemasState { schemas: ImmutableArray<SchemaDto>;
public schemasItems = new BehaviorSubject<ImmutableArray<SchemaDto>>(ImmutableArray.empty()); selectedSchema?: SchemaDetailsDto | null;
}
public selectedSchema = new BehaviorSubject<SchemaDetailsDto | null>(null);
public selectedReferencedSchema = new BehaviorSubject<SchemaDetailsDto | null>(null);
public get schemaName() {
return this.selectedSchema.value!.name;
}
public get referencedSchemaName() {
return this.selectedReferencedSchema.value!.name;
}
@Injectable()
export class SchemasState extends State<Snapshot> {
private get appName() { private get appName() {
return this.appsState.appName; return this.appsState.appName;
} }
@ -157,31 +153,29 @@ export class SchemasState {
} }
constructor( constructor(
private readonly schemasService: SchemasService, private readonly appsState: AppsState,
private readonly dialogs: DialogService,
private readonly authState: AuthService, private readonly authState: AuthService,
private readonly appsState: AppsState private readonly dialogs: DialogService,
private readonly schemasService: SchemasService
) { ) {
super({ schemas: ImmutableArray.of() });
} }
public selectSchema(id: string | null): Observable<SchemaDetailsDto | null> { public selectSchema(selectedSchemaId: string | null): Observable<SchemaDetailsDto | null> {
return this.loadSchema(id) return this.loadSchema(selectedSchemaId)
.do(schema => { .do(schema => {
this.selectedSchema.next(schema); this.next(s => {
}); const schemas = schema ? s.schemas.replaceBy('id', schema) : s.schemas;
}
public selectReferencedSchema(id: string | null): Observable<SchemaDetailsDto | null> { return { ...s, selectedSchemaId, schemas };
return this.loadSchema(id) });
.do(schema => {
this.selectedReferencedSchema.next(schema);
}); });
} }
private loadSchema(id: string | null) { private loadSchema(id: string | null) {
return !id ? return !id ?
Observable.of(null) : Observable.of(null) :
Observable.of(<SchemaDetailsDto>this.schemasItems.value.find(x => x.id === id && x instanceof SchemaDetailsDto)) Observable.of(<SchemaDetailsDto>this.snapshot.schemas.find(x => x.id === id && x instanceof SchemaDetailsDto))
.switchMap(schema => { .switchMap(schema => {
if (!schema) { if (!schema) {
return this.schemasService.getSchema(this.appName, id).catch(() => Observable.of(null)); return this.schemasService.getSchema(this.appName, id).catch(() => Observable.of(null));
@ -193,144 +187,312 @@ export class SchemasState {
public load(): Observable<any> { public load(): Observable<any> {
return this.schemasService.getSchemas(this.appName) return this.schemasService.getSchemas(this.appName)
.catch(error => this.dialogs.notifyError(error))
.do(dtos => { .do(dtos => {
this.schemasItems.nextBy(v => ImmutableArray.of(dtos)); return this.next(s => {
}); const schemas = ImmutableArray.of(dtos).sortByStringAsc(x => x.displayName);
return { ...s, schemas };
});
})
.catch(error => this.dialogs.notifyError(error));
}
public delete(schema: SchemaDto): Observable<any> {
return this.schemasService.deleteSchema(this.appName, schema.name, schema.version)
.do(dto => {
return this.next(s => {
const schemas = s.schemas.filter(x => x.id !== schema.id);
return { ...s, schemas };
});
})
.catch(error => this.dialogs.notifyError(error));
} }
public create(request: CreateSchemaDto) { public create(request: CreateSchemaDto) {
return this.schemasService.postSchema(this.appName, request, this.user, DateTime.now()) return this.schemasService.postSchema(this.appName, request, this.user, DateTime.now())
.do(dto => { .do(dto => {
this.schemasItems.nextBy(v => v.push(dto)); return this.next(s => {
const schemas = s.schemas.push(dto).sortByStringAsc(x => x.displayName);
return { ...s, schemas };
});
}); });
} }
public addField(schema: SchemaDetailsDto, request: AddFieldDto): Observable<FieldDto> { public addField(schema: SchemaDetailsDto, request: AddFieldDto): Observable<FieldDto> {
return this.schemasService.postField(this.appName, schema.name, request, schema.version) return this.schemasService.postField(this.appName, schema.name, request, schema.version)
.do(dto => { .do(dto => {
this.replaceSchema(schema.addField(dto.payload, this.user, dto.version)); this.replaceSchema(addField(schema, dto.payload, this.user, dto.version));
}).map(d => d.payload); }).map(d => d.payload);
} }
public publish(schema: SchemaDto): Observable<any> { public publish(schema: SchemaDto): Observable<any> {
return this.schemasService.publishSchema(this.appName, schema.name, schema.version) return this.schemasService.publishSchema(this.appName, schema.name, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.publish(this.user, dto.version)); this.replaceSchema(setPublished(schema, true, this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public unpublish(schema: SchemaDto): Observable<any> { public unpublish(schema: SchemaDto): Observable<any> {
return this.schemasService.unpublishSchema(this.appName, schema.name, schema.version) return this.schemasService.unpublishSchema(this.appName, schema.name, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.unpublish(this.user, dto.version)); this.replaceSchema(setPublished(schema, true, this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public enableField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> { public enableField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> {
return this.schemasService.enableField(this.appName, schema.name, field.fieldId, schema.version) return this.schemasService.enableField(this.appName, schema.name, field.fieldId, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.updateField(field.enable(), this.user, dto.version)); this.replaceSchema(updateField(schema, setDisabled(field, false), this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public disableField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> { public disableField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> {
return this.schemasService.disableField(this.appName, schema.name, field.fieldId, schema.version) return this.schemasService.disableField(this.appName, schema.name, field.fieldId, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.updateField(field.disable(), this.user, dto.version)); this.replaceSchema(updateField(schema, setDisabled(field, true), this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public lockField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> { public lockField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> {
return this.schemasService.lockField(this.appName, schema.name, field.fieldId, schema.version) return this.schemasService.lockField(this.appName, schema.name, field.fieldId, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.updateField(field.lock(), this.user, dto.version)); this.replaceSchema(updateField(schema, setLocked(field, true), this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public showField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> { public showField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> {
return this.schemasService.showField(this.appName, schema.name, field.fieldId, schema.version) return this.schemasService.showField(this.appName, schema.name, field.fieldId, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.updateField(field.show(), this.user, dto.version)); this.replaceSchema(updateField(schema, setHidden(field, false), this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public hideField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> { public hideField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> {
return this.schemasService.hideField(this.appName, schema.name, field.fieldId, schema.version) return this.schemasService.hideField(this.appName, schema.name, field.fieldId, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.updateField(field.hide(), this.user, dto.version)); this.replaceSchema(updateField(schema, setHidden(field, true), this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public deleteField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> { public deleteField(schema: SchemaDetailsDto, field: FieldDto): Observable<any> {
return this.schemasService.deleteField(this.appName, schema.name, field.fieldId, schema.version) return this.schemasService.deleteField(this.appName, schema.name, field.fieldId, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.removeField(field, this.user, dto.version)); this.replaceSchema(removeField(schema, field, this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public sortFields(schema: SchemaDetailsDto, fields: FieldDto[]): Observable<any> { public sortFields(schema: SchemaDetailsDto, fields: FieldDto[]): Observable<any> {
return this.schemasService.putFieldOrdering(this.appName, schema.name, fields.map(t => t.fieldId), schema.version) return this.schemasService.putFieldOrdering(this.appName, schema.name, fields.map(t => t.fieldId), schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.replaceFields(fields, this.user, dto.version)); this.replaceSchema(replaceFields(schema, fields, this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public updateField(schema: SchemaDetailsDto, field: FieldDto, request: UpdateFieldDto): Observable<any> { public updateField(schema: SchemaDetailsDto, field: FieldDto, request: UpdateFieldDto): Observable<any> {
return this.schemasService.putField(this.appName, schema.name, field.fieldId, request, schema.version) return this.schemasService.putField(this.appName, schema.name, field.fieldId, request, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.updateField(field.update(request.properties), this.user, dto.version)); this.replaceSchema(updateField(schema, update(field, request.properties), this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public configureScripts(schema: SchemaDetailsDto, request: UpdateSchemaScriptsDto): Observable<any> { public configureScripts(schema: SchemaDetailsDto, request: UpdateSchemaScriptsDto): Observable<any> {
return this.schemasService.putSchemaScripts(this.appName, schema.name, request, schema.version) return this.schemasService.putSchemaScripts(this.appName, schema.name, request, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.configureScripts(request, this.user, dto.version)); this.replaceSchema(configureScripts(schema, request, this.user, dto.version));
}); })
.catch(error => this.dialogs.notifyError(error));
} }
public update(schema: SchemaDetailsDto, request: UpdateSchemaDto): Observable<any> { public update(schema: SchemaDetailsDto, request: UpdateSchemaDto): Observable<any> {
return this.schemasService.putSchema(this.appName, schema.name, request, schema.version) return this.schemasService.putSchema(this.appName, schema.name, request, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => { .do(dto => {
this.replaceSchema(schema.update(request, this.user, dto.version)); this.replaceSchema(updateProperties(schema, request, this.user, dto.version));
}); })
} .catch(error => this.dialogs.notifyError(error));
public delete(schema: SchemaDto): Observable<any> {
return this.schemasService.deleteSchema(this.appName, schema.name, schema.version)
.catch(error => this.dialogs.notifyError(error))
.do(dto => {
this.schemasItems.nextBy(v => v.filter(s => s.id !== schema.id));
});
} }
private replaceSchema(schema: SchemaDto) { private replaceSchema(schema: SchemaDto) {
this.schemasItems.nextBy(v => v.replaceBy('id', schema)); return this.next(s => {
const schemas = s.schemas.replaceBy('id', schema).sortByStringAsc(x => x.displayName);
if (schema instanceof SchemaDetailsDto) { const selectedSchema = s.selectedSchema && s.selectedSchema.id === schema.id ? schema : s.selectedSchema;
this.selectedSchema.nextBy(v => v !== null && v.id === schema.id ? schema : v);
this.selectedReferencedSchema.nextBy(v => v !== null && v.id === schema.id ? schema : v);
}
}
public trackBySchema(index: number, schema: SchemaDto): any { return { ...s, schemas, selectedSchema };
return schema.id; });
} }
}
public trackByField(index: number, field: FieldDto): any { const setPublished = (schema: SchemaDto | SchemaDetailsDto, publish: boolean, user: string, version: Version, now?: DateTime) => {
return field.fieldId; if (schema instanceof SchemaDetailsDto) {
} return new SchemaDetailsDto(
} schema.id,
schema.name,
schema.properties,
true,
schema.createdBy, user,
schema.created, now || DateTime.now(),
version,
schema.fields,
schema.scriptQuery,
schema.scriptCreate,
schema.scriptUpdate,
schema.scriptDelete,
schema.scriptChange);
} else {
return new SchemaDto(
schema.id,
schema.name,
schema.properties,
true,
schema.createdBy, user,
schema.created, now || DateTime.now(),
version);
}
};
const configureScripts = (schema: SchemaDetailsDto, scripts: UpdateSchemaScriptsDto, user: string, version: Version, now?: DateTime) =>
new SchemaDetailsDto(
schema.id,
schema.name,
schema.properties,
schema.isPublished,
schema.createdBy, user,
schema.created, now || DateTime.now(),
version,
schema.fields,
scripts.scriptQuery,
scripts.scriptCreate,
scripts.scriptUpdate,
scripts.scriptDelete,
scripts.scriptChange);
const updateProperties = (schema: SchemaDetailsDto, properties: SchemaPropertiesDto, user: string, version: Version, now?: DateTime) =>
new SchemaDetailsDto(
schema.id,
schema.name,
properties,
schema.isPublished,
schema.createdBy, user,
schema.created, now || DateTime.now(),
version,
schema.fields,
schema.scriptQuery,
schema.scriptCreate,
schema.scriptUpdate,
schema.scriptDelete,
schema.scriptChange);
const addField = (schema: SchemaDetailsDto, field: FieldDto, user: string, version: Version, now?: DateTime) =>
new SchemaDetailsDto(
schema.id,
schema.name,
schema.properties,
schema.isPublished,
schema.createdBy, user,
schema.created, now || DateTime.now(),
version,
[...schema.fields, field],
schema.scriptQuery,
schema.scriptCreate,
schema.scriptUpdate,
schema.scriptDelete,
schema.scriptChange);
const updateField = (schema: SchemaDetailsDto, field: FieldDto, user: string, version: Version, now?: DateTime) =>
new SchemaDetailsDto(
schema.id,
schema.name,
schema.properties,
schema.isPublished,
schema.createdBy, user,
schema.created, now || DateTime.now(),
version,
schema.fields.map(f => f.fieldId === field.fieldId ? field : f),
schema.scriptQuery,
schema.scriptCreate,
schema.scriptUpdate,
schema.scriptDelete,
schema.scriptChange);
const replaceFields = (schema: SchemaDetailsDto, fields: FieldDto[], user: string, version: Version, now?: DateTime) =>
new SchemaDetailsDto(
schema.id,
schema.name,
schema.properties,
schema.isPublished,
schema.createdBy, user,
schema.created, now || DateTime.now(),
version,
fields,
schema.scriptQuery,
schema.scriptCreate,
schema.scriptUpdate,
schema.scriptDelete,
schema.scriptChange);
const removeField = (schema: SchemaDetailsDto, field: FieldDto, user: string, version: Version, now?: DateTime) =>
new SchemaDetailsDto(
schema.id,
schema.name,
schema.properties,
schema.isPublished,
schema.createdBy, user,
schema.created, now || DateTime.now(),
version,
schema.fields.filter(f => f.fieldId !== field.fieldId),
schema.scriptQuery,
schema.scriptCreate,
schema.scriptUpdate,
schema.scriptDelete,
schema.scriptChange);
const setLocked = (field: FieldDto, isLocked: boolean) =>
new FieldDto(
field.fieldId,
field.name,
isLocked,
field.isHidden,
field.isDisabled,
field.partitioning,
field.properties);
const setHidden = (field: FieldDto, isHidden: boolean) =>
new FieldDto(
field.fieldId,
field.name,
field.isLocked,
isHidden,
field.isDisabled,
field.partitioning,
field.properties);
const setDisabled = (field: FieldDto, isDisabled: boolean) =>
new FieldDto(
field.fieldId,
field.name,
field.isLocked,
field.isDisabled,
isDisabled,
field.partitioning,
field.properties);
const update = (field: FieldDto, properties: FieldPropertiesDto) =>
new FieldDto(
field.fieldId,
field.name,
field.isLocked,
field.isHidden,
field.isDisabled,
field.partitioning,
properties);
Loading…
Cancel
Save