Newer
Older
// eslint-disable-next-line max-classes-per-file
import { Component, Inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog';
import { FileService } from '../../../common/file.service';
import { LikertElementRow } from '../../../common/models/compound-elements/likert-element-row';
import { AnswerOption } from '../../../common/interfaces/UIElementInterfaces';
@Injectable({
providedIn: 'root'
})
export class DialogService {
constructor(private dialog: MatDialog) { }
showConfirmDialog(text: string): Observable<boolean> {
const dialogRef = this.dialog.open(ConfirmationDialog, {
data: {
text: text
}
});
return dialogRef.afterClosed();
}
showTextEditDialog(text: string): Observable<string> {
const dialogRef = this.dialog.open(TextEditDialog, {
data: {
text: text
}
});
return dialogRef.afterClosed();
}
showMultilineTextEditDialog(text: string): Observable<string> {
const dialogRef = this.dialog.open(MultilineTextEditDialog, {
width: '600px',
data: {
text: text
}
});
return dialogRef.afterClosed();
}
showRichTextEditDialog(text: string): Observable<string> {
const dialogRef = this.dialog.open(RichTextEditDialog, {
});
return dialogRef.afterClosed();
}
showLikertAnswerEditDialog(answer: AnswerOption): Observable<AnswerOption> {
const dialogRef = this.dialog.open(LikertAnswerEditDialog, {
width: '300px',
height: '550px',
data: {
answer: answer
},
autoFocus: false
});
return dialogRef.afterClosed();
}
showLikertQuestionEditDialog(question: LikertElementRow): Observable<LikertElementRow> {
const dialogRef = this.dialog.open(LikertQuestionEditDialog, {
width: '300px',
height: '550px',
data: {
question: question
},
autoFocus: false
});
return dialogRef.afterClosed();
}
}
@Component({
selector: 'app-confirmation-dialog',
template: `
<mat-dialog-content>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button [mat-dialog-close]="true">Speichern</button>
<button mat-button mat-dialog-close>Abbrechen</button>
</mat-dialog-actions>
`
})
export class ConfirmationDialog {
constructor(@Inject(MAT_DIALOG_DATA) public data: { text: string }) { }
}
@Component({
selector: 'app-text-edit-dialog',
template: `
<mat-dialog-content>
<mat-form-field>
<mat-label>Text</mat-label>
<input #inputElement matInput type="text" [value]="data.text">
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button [mat-dialog-close]="inputElement.value">Speichern</button>
<button mat-button mat-dialog-close>Abbrechen</button>
</mat-dialog-actions>
`
})
export class TextEditDialog {
constructor(@Inject(MAT_DIALOG_DATA) public data: { text: string }) { }
}
@Component({
selector: 'app-multiline-text-edit-dialog',
template: `
<mat-dialog-content>
<mat-form-field [style.width.%]="100">
<mat-label>Text</mat-label>
<textarea #inputElement matInput type="text" [value]="data.text">
</textarea>
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button [mat-dialog-close]="inputElement.value">Speichern</button>
<button mat-button mat-dialog-close>Abbrechen</button>
</mat-dialog-actions>
`
})
export class MultilineTextEditDialog {
constructor(@Inject(MAT_DIALOG_DATA) public data: { text: string }) { }
selector: 'app-rich-text-edit-dialog-tinymce',
template: `
<mat-dialog-content>
<app-rich-text-editor [(text)]="data.text"></app-rich-text-editor>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button [mat-dialog-close]="data.text">Speichern</button>
<button mat-button mat-dialog-close>Abbrechen</button>
</mat-dialog-actions>
`
})
constructor(@Inject(MAT_DIALOG_DATA) public data: { text: string }) { }
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
@Component({
selector: 'app-likert-answer-edit-dialog',
template: `
<mat-dialog-content fxLayout="column">
<mat-form-field>
<mat-label>Text</mat-label>
<input #textInput matInput type="text" [value]="data.answer.text">
</mat-form-field>
<input #imageUpload type="file" hidden (click)="loadImage()">
<button mat-raised-button (click)="imageUpload.click()">Bild laden</button>
<button mat-raised-button (click)="data.answer.imgSrc = null">Bild entfernen</button>
<img [src]="data.answer.imgSrc"
[style.object-fit]="'scale-down'"
[width]="200">
<mat-form-field appearance="fill">
<mat-label>Position</mat-label>
<mat-select [value]="data.answer.position"
(selectionChange)="this.data.answer.position = $event.value">
<mat-option *ngFor="let option of [{displayValue: 'oben', value: 'above'},
{displayValue: 'unten', value: 'below'}]"
[value]="option.value">
{{option.displayValue}}
</mat-option>
</mat-select>
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button [mat-dialog-close]="{
text: textInput.value,
imgSrc: data.answer.imgSrc,
position: data.answer.position }">
Speichern
</button>
<button mat-button mat-dialog-close>Abbrechen</button>
</mat-dialog-actions>
`
})
export class LikertAnswerEditDialog {
constructor(@Inject(MAT_DIALOG_DATA) public data: { answer: AnswerOption }) { }
async loadImage(): Promise<void> {
this.data.answer.imgSrc = await FileService.loadImage();
}
}
@Component({
selector: 'app-likert-question-edit-dialog',
template: `
<mat-dialog-content fxLayout="column">
<mat-form-field>
<mat-label>Text</mat-label>
<input #textField matInput type="text" [value]="data.question.text">
</mat-form-field>
<mat-form-field>
<mat-label>ID</mat-label>
<input #idField matInput type="text" [value]="data.question.id">
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button [mat-dialog-close]="{ text: textField.value, id: idField.value }">Speichern</button>
<button mat-button mat-dialog-close>Abbrechen</button>
</mat-dialog-actions>
`
})
export class LikertQuestionEditDialog {
constructor(@Inject(MAT_DIALOG_DATA) public data: { question: LikertElementRow }) { }
}