From 8f3e66e1702394eddc668c09b1bcd98bcec89726 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Sat, 20 Oct 2018 19:58:21 +0200 Subject: [PATCH] TSLint fixes --- .../pages/users/user-page.component.ts | 4 +- .../content/content-history.component.ts | 2 +- .../pages/content/content-page.component.ts | 6 +- .../pages/rules/rule-wizard.component.ts | 6 +- .../pages/schema/field-wizard.component.ts | 2 +- .../schema/schema-edit-form.component.ts | 2 +- .../schema/schema-scripts-form.component.ts | 2 +- .../contributors-page.component.ts | 2 +- .../app/framework/angular/forms/validators.ts | 2 +- .../framework/angular/http/http-extensions.ts | 12 +- src/Squidex/app/shared/internal.ts | 1 + src/Squidex/app/shared/module.ts | 2 + .../app/shared/services/auth.service.ts | 2 +- .../app/shared/services/comments.service.ts | 4 + .../app/shared/services/contents.service.ts | 2 +- .../app/shared/services/schemas.service.ts | 2 +- .../app/shared/state/apps.state.spec.ts | 4 +- src/Squidex/app/shared/state/apps.state.ts | 5 +- .../app/shared/state/comments.state.ts | 119 ++++++++++++++++++ .../app/shared/state/contents.state.ts | 2 +- src/Squidex/app/shared/state/rules.state.ts | 2 +- src/Squidex/app/shared/state/schemas.state.ts | 2 +- 22 files changed, 156 insertions(+), 31 deletions(-) create mode 100644 src/Squidex/app/shared/state/comments.state.ts diff --git a/src/Squidex/app/features/administration/pages/users/user-page.component.ts b/src/Squidex/app/features/administration/pages/users/user-page.component.ts index bfa55f8fc..7e64d182f 100644 --- a/src/Squidex/app/features/administration/pages/users/user-page.component.ts +++ b/src/Squidex/app/features/administration/pages/users/user-page.component.ts @@ -55,14 +55,14 @@ export class UserPageComponent implements OnDestroy, OnInit { if (value) { if (this.user) { this.usersState.update(this.user.user, value) - .subscribe(user => { + .subscribe(() => { this.userForm.submitCompleted(); }, error => { this.userForm.submitFailed(error); }); } else { this.usersState.create(value) - .subscribe(user => { + .subscribe(() => { this.back(); }, error => { this.userForm.submitFailed(error); diff --git a/src/Squidex/app/features/content/pages/content/content-history.component.ts b/src/Squidex/app/features/content/pages/content/content-history.component.ts index ad7718da9..c323106d9 100644 --- a/src/Squidex/app/features/content/pages/content/content-history.component.ts +++ b/src/Squidex/app/features/content/pages/content/content-history.component.ts @@ -51,7 +51,7 @@ export class ContentHistoryComponent { timer(0, 10000), this.messageBus.of(HistoryChannelUpdated).pipe(delay(1000)) ).pipe( - switchMap(app => this.historyService.getHistory(this.appsState.appName, this.channel))); + switchMap(() => this.historyService.getHistory(this.appsState.appName, this.channel))); constructor( private readonly appsState: AppsState, diff --git a/src/Squidex/app/features/content/pages/content/content-page.component.ts b/src/Squidex/app/features/content/pages/content/content-page.component.ts index 1b1e440df..a880fa5c2 100644 --- a/src/Squidex/app/features/content/pages/content/content-page.component.ts +++ b/src/Squidex/app/features/content/pages/content/content-page.component.ts @@ -141,14 +141,14 @@ export class ContentPageComponent implements CanComponentDeactivate, OnDestroy, if (this.content) { if (asProposal) { this.contentsState.proposeUpdate(this.content, value) - .subscribe(dto => { + .subscribe(() => { this.contentForm.submitCompleted(); }, error => { this.contentForm.submitFailed(error); }); } else { this.contentsState.update(this.content, value) - .subscribe(dto => { + .subscribe(() => { this.contentForm.submitCompleted(); }, error => { this.contentForm.submitFailed(error); @@ -156,7 +156,7 @@ export class ContentPageComponent implements CanComponentDeactivate, OnDestroy, } } else { this.contentsState.create(value, publish) - .subscribe(dto => { + .subscribe(() => { this.back(); }, error => { this.contentForm.submitFailed(error); diff --git a/src/Squidex/app/features/rules/pages/rules/rule-wizard.component.ts b/src/Squidex/app/features/rules/pages/rules/rule-wizard.component.ts index 52ba5ad1f..bfdb88f5e 100644 --- a/src/Squidex/app/features/rules/pages/rules/rule-wizard.component.ts +++ b/src/Squidex/app/features/rules/pages/rules/rule-wizard.component.ts @@ -121,7 +121,7 @@ export class RuleWizardComponent implements OnInit { const requestDto = new CreateRuleDto(this.trigger, this.action); this.rulesState.create(requestDto) - .subscribe(dto => { + .subscribe(() => { this.complete(); this.actionForm.submitCompleted(); @@ -134,7 +134,7 @@ export class RuleWizardComponent implements OnInit { private updateTrigger() { this.rulesState.updateTrigger(this.rule, this.trigger) - .subscribe(dto => { + .subscribe(() => { this.complete(); this.triggerForm.submitCompleted(); @@ -145,7 +145,7 @@ export class RuleWizardComponent implements OnInit { private updateAction() { this.rulesState.updateAction(this.rule, this.action) - .subscribe(dto => { + .subscribe(() => { this.complete(); this.actionForm.submitCompleted(); diff --git a/src/Squidex/app/features/schemas/pages/schema/field-wizard.component.ts b/src/Squidex/app/features/schemas/pages/schema/field-wizard.component.ts index a6081d30d..0021baa7f 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field-wizard.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/field-wizard.component.ts @@ -60,7 +60,7 @@ export class FieldWizardComponent implements OnInit { if (value) { this.schemasState.addField(this.schema, value, this.parent) - .subscribe(dto => { + .subscribe(() => { this.addFieldForm.submitCompleted({ type: fieldTypes[0].type }); if (next) { diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.ts b/src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.ts index 472171023..653216265 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.ts @@ -47,7 +47,7 @@ export class SchemaEditFormComponent implements OnInit { if (value) { this.schemasState.update(this.schema, value) - .subscribe(dto => { + .subscribe(() => { this.complete(); }, error => { this.editForm.submitFailed(error); diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-scripts-form.component.ts b/src/Squidex/app/features/schemas/pages/schema/schema-scripts-form.component.ts index 977f9d3de..a48809b1e 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-scripts-form.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/schema-scripts-form.component.ts @@ -53,7 +53,7 @@ export class SchemaScriptsFormComponent implements OnInit { if (value) { this.schemasState.configureScripts(this.schema, value) - .subscribe(dto => { + .subscribe(() => { this.complete(); }, error => { this.editForm.submitFailed(error); diff --git a/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts b/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts index 1be74e48b..91c978c01 100644 --- a/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts +++ b/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts @@ -94,7 +94,7 @@ export class ContributorsPageComponent implements OnInit { const requestDto = new AppContributorDto(user, 'Editor'); this.contributorsState.assign(requestDto) - .subscribe(dto => { + .subscribe(() => { this.assignContributorForm.submitCompleted(); }, error => { this.assignContributorForm.submitFailed(error); diff --git a/src/Squidex/app/framework/angular/forms/validators.ts b/src/Squidex/app/framework/angular/forms/validators.ts index fabd1bbc9..3bbd8831f 100644 --- a/src/Squidex/app/framework/angular/forms/validators.ts +++ b/src/Squidex/app/framework/angular/forms/validators.ts @@ -126,7 +126,7 @@ export module ValidatorsEx { } export function noop(): ValidatorFn { - return (control: AbstractControl) => { + return () => { return null; }; } diff --git a/src/Squidex/app/framework/angular/http/http-extensions.ts b/src/Squidex/app/framework/angular/http/http-extensions.ts index fd5b7e29a..9bebcbc3e 100644 --- a/src/Squidex/app/framework/angular/http/http-extensions.ts +++ b/src/Squidex/app/framework/angular/http/http-extensions.ts @@ -17,31 +17,31 @@ export module HTTP { export function getVersioned(http: HttpClient, url: string, version?: Version): Observable>> { const headers = createHeaders(version); - return handleVersion(http.get(url, { observe: 'response', headers }), version); + return handleVersion(http.get(url, { observe: 'response', headers })); } export function postVersioned(http: HttpClient, url: string, body: any, version?: Version): Observable>> { const headers = createHeaders(version); - return handleVersion(http.post(url, body, { observe: 'response', headers }), version); + return handleVersion(http.post(url, body, { observe: 'response', headers })); } export function putVersioned(http: HttpClient, url: string, body: any, version?: Version): Observable>> { const headers = createHeaders(version); - return handleVersion(http.put(url, body, { observe: 'response', headers }), version); + return handleVersion(http.put(url, body, { observe: 'response', headers })); } export function patchVersioned(http: HttpClient, url: string, body: any, version?: Version): Observable>> { const headers = createHeaders(version); - return handleVersion(http.request('PATCH', url, { body, observe: 'response', headers }), version); + return handleVersion(http.request('PATCH', url, { body, observe: 'response', headers })); } export function deleteVersioned(http: HttpClient, url: string, version?: Version): Observable>> { const headers = createHeaders(version); - return handleVersion(http.delete(url, { observe: 'response', headers }), version); + return handleVersion(http.delete(url, { observe: 'response', headers })); } function createHeaders(version?: Version): HttpHeaders { @@ -52,7 +52,7 @@ export module HTTP { } } - function handleVersion(httpRequest: Observable>, version?: Version): Observable>> { + function handleVersion(httpRequest: Observable>): Observable>> { return httpRequest.pipe(map((response: HttpResponse) => { const etag = response.headers.get('etag') || ''; diff --git a/src/Squidex/app/shared/internal.ts b/src/Squidex/app/shared/internal.ts index db93f8ce4..b2649d32d 100644 --- a/src/Squidex/app/shared/internal.ts +++ b/src/Squidex/app/shared/internal.ts @@ -50,6 +50,7 @@ export * from './state/backups.forms'; export * from './state/backups.state'; export * from './state/clients.forms'; export * from './state/clients.state'; +export * from './state/comments.state'; export * from './state/contents.forms'; export * from './state/contents.state'; export * from './state/contributors.forms'; diff --git a/src/Squidex/app/shared/module.ts b/src/Squidex/app/shared/module.ts index 40e78c6ff..1e8126908 100644 --- a/src/Squidex/app/shared/module.ts +++ b/src/Squidex/app/shared/module.ts @@ -35,6 +35,7 @@ import { BackupsState, ClientsState, CommentsService, + CommentsState, ContentMustExistGuard, ContentsService, ContentsState, @@ -165,6 +166,7 @@ export class SqxSharedModule { BackupsState, ClientsState, CommentsService, + CommentsState, ContentMustExistGuard, ContentsService, ContentsState, diff --git a/src/Squidex/app/shared/services/auth.service.ts b/src/Squidex/app/shared/services/auth.service.ts index 1b2be5eb8..96597f5f8 100644 --- a/src/Squidex/app/shared/services/auth.service.ts +++ b/src/Squidex/app/shared/services/auth.service.ts @@ -185,7 +185,7 @@ export class AuthService { } return true; - }, err => { + }, error => { this.user$.next(null); return false; diff --git a/src/Squidex/app/shared/services/comments.service.ts b/src/Squidex/app/shared/services/comments.service.ts index 2b625ad98..e9316f740 100644 --- a/src/Squidex/app/shared/services/comments.service.ts +++ b/src/Squidex/app/shared/services/comments.service.ts @@ -38,6 +38,10 @@ export class CommentDto extends Model { ) { super(); } + + public with(value: Partial): CommentDto { + return this.clone(value); + } } export class UpsertCommentDto { diff --git a/src/Squidex/app/shared/services/contents.service.ts b/src/Squidex/app/shared/services/contents.service.ts index 9052d8852..ae3579487 100644 --- a/src/Squidex/app/shared/services/contents.service.ts +++ b/src/Squidex/app/shared/services/contents.service.ts @@ -190,7 +190,7 @@ export class ContentsService { body.data, response.version); }), - tap(content => { + tap(() => { this.analytics.trackEvent('Content', 'Created', appName); }), pretifyError('Failed to create content. Please reload.')); diff --git a/src/Squidex/app/shared/services/schemas.service.ts b/src/Squidex/app/shared/services/schemas.service.ts index 6f22d8282..1085d6e13 100644 --- a/src/Squidex/app/shared/services/schemas.service.ts +++ b/src/Squidex/app/shared/services/schemas.service.ts @@ -344,7 +344,7 @@ export class SchemasService { body.scriptDelete, body.scriptChange); }), - tap(schema => { + tap(() => { this.analytics.trackEvent('Schema', 'Created', appName); }), pretifyError('Failed to create schema. Please reload.')); diff --git a/src/Squidex/app/shared/state/apps.state.spec.ts b/src/Squidex/app/shared/state/apps.state.spec.ts index c3f3ad902..64b0123ce 100644 --- a/src/Squidex/app/shared/state/apps.state.spec.ts +++ b/src/Squidex/app/shared/state/apps.state.spec.ts @@ -87,7 +87,7 @@ describe('AppsState', () => { appsService.setup(x => x.postApp(request)) .returns(() => of(newApp)); - appsState.create(request, now).subscribe(); + appsState.create(request).subscribe(); expect(appsState.snapshot.apps.values).toEqual([newApp, ...oldApps]); }); @@ -101,7 +101,7 @@ describe('AppsState', () => { appsService.setup(x => x.deleteApp(newApp.name)) .returns(() => of({})); - appsState.create(request, now).subscribe(); + appsState.create(request).subscribe(); const appsAfterCreate = appsState.snapshot.apps.values; diff --git a/src/Squidex/app/shared/state/apps.state.ts b/src/Squidex/app/shared/state/apps.state.ts index 861bf3160..517c42a76 100644 --- a/src/Squidex/app/shared/state/apps.state.ts +++ b/src/Squidex/app/shared/state/apps.state.ts @@ -10,7 +10,6 @@ import { Observable, of } from 'rxjs'; import { distinctUntilChanged, map, tap } from 'rxjs/operators'; import { - DateTime, DialogService, ImmutableArray, notify, @@ -73,7 +72,7 @@ export class AppsState extends State { })); } - public create(request: CreateAppDto, now?: DateTime): Observable { + public create(request: CreateAppDto): Observable { return this.appsService.postApp(request).pipe( tap(dto => { this.next(s => { @@ -86,7 +85,7 @@ export class AppsState extends State { public delete(name: string): Observable { return this.appsService.deleteApp(name).pipe( - tap(app => { + tap(() => { this.next(s => { const apps = s.apps.filter(x => x.name !== name); diff --git a/src/Squidex/app/shared/state/comments.state.ts b/src/Squidex/app/shared/state/comments.state.ts new file mode 100644 index 000000000..bb8acc26f --- /dev/null +++ b/src/Squidex/app/shared/state/comments.state.ts @@ -0,0 +1,119 @@ +/* + * Squidex Headless CMS + * + * @license + * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. + */ + +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { distinctUntilChanged, map, tap } from 'rxjs/operators'; + +import { + DateTime, + DialogService, + ImmutableArray, + notify, + State, + Version +} from '@app/framework'; + +import { + CommentDto, + CommentsService, + UpsertCommentDto +} from './../services/comments.service'; + +interface Snapshot { + comments: ImmutableArray; + + version: Version; + + isLoaded?: boolean; +} + +@Injectable() +export class CommentsState extends State { + public comments = + this.changes.pipe(map(x => x.comments), + distinctUntilChanged()); + + public isLoaded = + this.changes.pipe(map(x => !!x.isLoaded), + distinctUntilChanged()); + + constructor( + private readonly commentsId: string, + private readonly commentsService: CommentsService, + private readonly dialogs: DialogService + ) { + super({ comments: ImmutableArray.empty(), version: new Version('') }); + } + + public load(): Observable { + return this.commentsService.getComments(this.commentsId, this.version).pipe( + tap(dtos => { + this.next(s => { + let comments = s.comments; + + for (let created of dtos.createdComments) { + comments = comments.push(created); + } + + for (let updated of dtos.updatedComments) { + comments = comments.replaceBy('id', updated); + } + + for (let deleted of dtos.deletedComments) { + comments = comments.filter(x => x.id !== deleted); + } + + return { ...s, comments, isLoaded: true, version: dtos.version }; + }); + }), + notify(this.dialogs)); + } + + public create(request: UpsertCommentDto): Observable { + return this.commentsService.postComment(this.commentsId, request).pipe( + tap(dto => { + this.next(s => { + const comments = s.comments.push(dto); + + return { ...s, comments }; + }); + }), + notify(this.dialogs)); + } + + public update(commentId: string, request: UpsertCommentDto, now?: DateTime): Observable { + return this.commentsService.putComment(this.commentsId, commentId, request).pipe( + tap(() => { + this.next(s => { + const comments = s.comments.map(c => c.id === commentId ? update(c, request, now || DateTime.now()) : c); + + return { ...s, comments }; + }); + }), + notify(this.dialogs)); + } + + public delete(commentId: string): Observable { + return this.commentsService.deleteComment(this.commentsId, commentId).pipe( + tap(dto => { + this.next(s => { + const comments = s.comments.filter(c => c.id !== commentId); + + return { ...s, comments, version: dto.version }; + }); + }), + notify(this.dialogs)); + } + + private get version() { + return this.snapshot.version; + } +} + +const update = (comment: CommentDto, request: UpsertCommentDto, now: DateTime) => + comment.with({ text: request.text, time: now }); \ No newline at end of file diff --git a/src/Squidex/app/shared/state/contents.state.ts b/src/Squidex/app/shared/state/contents.state.ts index 21961630b..481bb0fa9 100644 --- a/src/Squidex/app/shared/state/contents.state.ts +++ b/src/Squidex/app/shared/state/contents.state.ts @@ -132,7 +132,7 @@ export abstract class ContentsStateBase extends State { notify(this.dialogs)); } - public create(request: any, publish: boolean, now?: DateTime) { + public create(request: any, publish: boolean) { return this.contentsService.postContent(this.appName, this.schemaName, request, publish).pipe( tap(dto => { this.dialogs.notifyInfo('Contents created successfully.'); diff --git a/src/Squidex/app/shared/state/rules.state.ts b/src/Squidex/app/shared/state/rules.state.ts index cc51ff828..9005be892 100644 --- a/src/Squidex/app/shared/state/rules.state.ts +++ b/src/Squidex/app/shared/state/rules.state.ts @@ -87,7 +87,7 @@ export class RulesState extends State { public delete(rule: RuleDto): Observable { return this.rulesService.deleteRule(this.appName, rule.id, rule.version).pipe( - tap(dto => { + tap(() => { this.next(s => { const rules = s.rules.removeAll(x => x.id === rule.id); diff --git a/src/Squidex/app/shared/state/schemas.state.ts b/src/Squidex/app/shared/state/schemas.state.ts index cd2adc36e..b7c64a602 100644 --- a/src/Squidex/app/shared/state/schemas.state.ts +++ b/src/Squidex/app/shared/state/schemas.state.ts @@ -140,7 +140,7 @@ export class SchemasState extends State { public delete(schema: SchemaDto): Observable { return this.schemasService.deleteSchema(this.appName, schema.name, schema.version).pipe( - tap(dto => { + tap(() => { return this.next(s => { const schemas = s.schemas.filter(x => x.id !== schema.id); const selectedSchema = s.selectedSchema && s.selectedSchema.id === schema.id ? null : s.selectedSchema;