2018-11-27 22:44:37 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { OpenSlidesComponent } from '../../openslides.component';
|
|
|
|
import { MatDialog } from '@angular/material';
|
2018-11-29 17:36:22 +01:00
|
|
|
import {
|
|
|
|
ChoiceDialogComponent,
|
|
|
|
ChoiceDialogOptions,
|
|
|
|
ChoiceAnswer
|
|
|
|
} from '../../shared/components/choice-dialog/choice-dialog.component';
|
2018-11-27 22:44:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A service for prompting the user to select a choice.
|
|
|
|
*/
|
|
|
|
@Injectable({
|
2018-11-29 17:36:22 +01:00
|
|
|
providedIn: 'root'
|
2018-11-27 22:44:37 +01:00
|
|
|
})
|
|
|
|
export class ChoiceService extends OpenSlidesComponent {
|
|
|
|
/**
|
|
|
|
* Ctor.
|
|
|
|
*
|
|
|
|
* @param dialog For opening the ChoiceDialog
|
|
|
|
*/
|
|
|
|
public constructor(private dialog: MatDialog) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the dialog. Returns the chosen value after the user accepts.
|
|
|
|
* @param title The title to display in the dialog
|
|
|
|
* @param choices The available choices
|
|
|
|
* @returns an answer {@link ChoiceAnswer}
|
|
|
|
*/
|
2018-11-29 17:36:22 +01:00
|
|
|
public async open(
|
|
|
|
title: string,
|
|
|
|
choices: ChoiceDialogOptions,
|
|
|
|
multiSelect: boolean = false
|
|
|
|
): Promise<ChoiceAnswer> {
|
2018-11-27 22:44:37 +01:00
|
|
|
const dialogRef = this.dialog.open(ChoiceDialogComponent, {
|
|
|
|
minWidth: '250px',
|
2018-11-29 18:20:21 +01:00
|
|
|
maxHeight:'90vh',
|
2018-11-27 22:44:37 +01:00
|
|
|
data: { title: title, choices: choices, multiSelect: multiSelect }
|
|
|
|
});
|
|
|
|
return dialogRef.afterClosed().toPromise();
|
|
|
|
}
|
|
|
|
}
|