|
|
@ -5,7 +5,7 @@ |
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
import { Component, Input, OnInit } from '@angular/core'; |
|
|
import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core'; |
|
|
import { FormBuilder } from '@angular/forms'; |
|
|
import { FormBuilder } from '@angular/forms'; |
|
|
import { timer } from 'rxjs'; |
|
|
import { timer } from 'rxjs'; |
|
|
import { switchMap } from 'rxjs/operators'; |
|
|
import { switchMap } from 'rxjs/operators'; |
|
|
@ -27,18 +27,18 @@ import { |
|
|
templateUrl: './comments.component.html' |
|
|
templateUrl: './comments.component.html' |
|
|
}) |
|
|
}) |
|
|
export class CommentsComponent extends ResourceOwner implements OnInit { |
|
|
export class CommentsComponent extends ResourceOwner implements OnInit { |
|
|
public state: CommentsState; |
|
|
@Input() |
|
|
|
|
|
public commentsId: string; |
|
|
public userId: string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public commentsState: CommentsState; |
|
|
public commentForm = new UpsertCommentForm(this.formBuilder); |
|
|
public commentForm = new UpsertCommentForm(this.formBuilder); |
|
|
|
|
|
|
|
|
@Input() |
|
|
public userId: string; |
|
|
public commentsId: string; |
|
|
|
|
|
|
|
|
|
|
|
constructor(authService: AuthService, |
|
|
constructor(authService: AuthService, |
|
|
private readonly appsState: AppsState, |
|
|
private readonly appsState: AppsState, |
|
|
private readonly commentsService: CommentsService, |
|
|
private readonly commentsService: CommentsService, |
|
|
|
|
|
private readonly changeDetector: ChangeDetectorRef, |
|
|
private readonly dialogs: DialogService, |
|
|
private readonly dialogs: DialogService, |
|
|
private readonly formBuilder: FormBuilder |
|
|
private readonly formBuilder: FormBuilder |
|
|
) { |
|
|
) { |
|
|
@ -48,26 +48,27 @@ export class CommentsComponent extends ResourceOwner implements OnInit { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
public ngOnInit() { |
|
|
this.state = new CommentsState(this.appsState, this.commentsId, this.commentsService, this.dialogs); |
|
|
this.commentsState = new CommentsState(this.appsState, this.commentsId, this.commentsService, this.dialogs); |
|
|
|
|
|
|
|
|
this.own(timer(0, 4000).pipe(switchMap(() => this.state.load()))); |
|
|
this.own(timer(0, 4000).pipe(switchMap(() => this.commentsState.load()))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public delete(comment: CommentDto) { |
|
|
public delete(comment: CommentDto) { |
|
|
this.state.delete(comment); |
|
|
this.commentsState.delete(comment); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public update(comment: CommentDto, text: string) { |
|
|
public update(comment: CommentDto, text: string) { |
|
|
this.state.update(comment, text); |
|
|
this.commentsState.update(comment, text); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public comment() { |
|
|
public comment() { |
|
|
const value = this.commentForm.submit(); |
|
|
const value = this.commentForm.submit(); |
|
|
|
|
|
|
|
|
if (value) { |
|
|
if (value && value.text && value.text.length > 0) { |
|
|
this.state.create(value.text); |
|
|
this.commentsState.create(value.text); |
|
|
|
|
|
|
|
|
this.commentForm.submitCompleted(); |
|
|
this.commentForm.submitCompleted(); |
|
|
|
|
|
|
|
|
|
|
|
this.changeDetector.detectChanges(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|