blob: 0abbc6ae197e86d33eaaf0d139a3709a47309a90 [file]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import {Component, ElementRef, EventEmitter, Input, Output, ViewChild} from "@angular/core";
import {IAPICommentModel} from "../../core/api/statements";
import {momentFormatDisplayFullDateAndTime} from "../../util/moment";
@Component({
selector: "app-comments",
templateUrl: "./comments.component.html",
styleUrls: ["./comments.component.scss"]
})
export class CommentsComponent {
@Input()
public appCollapsed: boolean;
@Input()
public appCommentsToShow = 5;
@Input()
public appComments: Array<IAPICommentModel>;
public hasInputSomething = false;
@Output()
public appDelete: EventEmitter<number> = new EventEmitter();
@Output()
public appAdd: EventEmitter<string> = new EventEmitter();
@Input()
public timeDisplayFormat: string = momentFormatDisplayFullDateAndTime;
@ViewChild("textAreaElement")
private textAreaRef: ElementRef<HTMLTextAreaElement>;
public onInput() {
this.hasInputSomething = this.textAreaRef.nativeElement.value !== "";
this.resize();
}
public resize() {
this.textAreaRef.nativeElement.style.height = "1px";
this.textAreaRef.nativeElement.style.height = this.textAreaRef.nativeElement.scrollHeight + "px";
}
public onSave() {
this.appAdd.emit(this.textAreaRef.nativeElement.value);
this.clear();
}
public onDelete(id: number) {
this.appDelete.emit(id);
}
public clear() {
this.textAreaRef.nativeElement.value = "";
this.hasInputSomething = false;
this.resize();
}
public showMore(all = false) {
if (this.appCommentsToShow == null) {
this.appCommentsToShow = 0;
}
this.appCommentsToShow = all ? undefined : Math.min(this.appComments?.length, this.appCommentsToShow + 5);
}
}