Dialog Create Room
This commit is contained in:
parent
916ccddd7d
commit
8fe42de825
4 changed files with 80 additions and 0 deletions
|
|
@ -0,0 +1,13 @@
|
||||||
|
<h1 mat-dialog-title>New room</h1>
|
||||||
|
<mat-divider></mat-divider>
|
||||||
|
<br>
|
||||||
|
<div mat-dialog-content>
|
||||||
|
<p>Saisissez un nouveau nom de room</p>
|
||||||
|
<input matInput [(ngModel)]="newRoomName" class="w-100">
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="alert alert-danger w-100" *ngIf="errorMessage!==''"><span class="font-weight-bold">Erreur : </span>{{errorMessage}}</div>
|
||||||
|
<div mat-dialog-actions class="float-right">
|
||||||
|
<button mat-raised-button color="accent" class="mb-2" (click)="onNoClick()">Fermer</button>
|
||||||
|
<button mat-raised-button color="primary" class="mb-2" (click)="onCreateRoom()" cdkFocusInitial>Créer la room</button>
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { CreateRoomDialogComponent } from './create-room-dialog.component';
|
||||||
|
|
||||||
|
describe('CreateRoomDialogComponent', () => {
|
||||||
|
let component: CreateRoomDialogComponent;
|
||||||
|
let fixture: ComponentFixture<CreateRoomDialogComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ CreateRoomDialogComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(CreateRoomDialogComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
import {Component, Inject, OnInit} from '@angular/core';
|
||||||
|
import {MessageService} from "../services/message/message.service";
|
||||||
|
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||||
|
import {environment} from "../../environments/environment";
|
||||||
|
|
||||||
|
export interface CreateRoomDialogData {
|
||||||
|
owner: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-create-room-dialog',
|
||||||
|
templateUrl: './create-room-dialog.component.html',
|
||||||
|
styleUrls: ['./create-room-dialog.component.scss']
|
||||||
|
})
|
||||||
|
export class CreateRoomDialogComponent{
|
||||||
|
|
||||||
|
newRoomName = '';
|
||||||
|
errorMessage = '';
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
public dialogRef: MatDialogRef<CreateRoomDialogComponent>,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: CreateRoomDialogData,
|
||||||
|
@Inject(MessageService) private messageService: MessageService) { }
|
||||||
|
|
||||||
|
onNoClick(): void {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
onCreateRoom(){
|
||||||
|
this.messageService.sendMessage(environment.urlCPR, "conversations/newRoom", {owner: this.data.owner, roomName: this.newRoomName}).subscribe(data => {
|
||||||
|
if (data.status !== 'ok') {
|
||||||
|
console.log(data.data.reason);
|
||||||
|
this.errorMessage = data.data.reason;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.dialogRef.close({
|
||||||
|
data: data.data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in a new issue