rajah 11 mesiacov pred
rodič
commit
a92bc09b95

+ 2 - 0
src/app/app.routes.ts

@@ -8,6 +8,7 @@ import { HomeComponent } from './composants/home/home.component';
 import { LoginComponent } from './composants/login/login.component';
 import { EventListComponent } from './composants/event-list/event-list.component';
 import { WebcamListComponent } from './composants/webcam-list/webcam-list.component';
+import { ChatComponent } from './composants/chat/chat.component';
 import { AccountDetailsComponent } from './composants/account-details/account-details.component';
 import { AccountUpdateComponent } from './composants/account-update/account-update.component';
 import { AccountPasswordComponent } from './composants/account-password/account-password.component';
@@ -38,6 +39,7 @@ export const routes: Routes = [
   {path: 'login', component: LoginComponent, runGuardsAndResolvers: 'always' },
   {path: 'event-list', component: EventListComponent, runGuardsAndResolvers: 'always' },
   {path: 'webcam-list', component: WebcamListComponent, runGuardsAndResolvers: 'always' },
+  {path: 'chat', component: ChatComponent, canActivate: [UserGuard], runGuardsAndResolvers: 'always' },
   {path: 'account-details', component: AccountDetailsComponent, canActivate: [UserGuard], runGuardsAndResolvers: 'always' },
   {path: 'account-update', component: AccountUpdateComponent, canActivate: [UserGuard], runGuardsAndResolvers: 'always' },
   {path: 'account-password', component: AccountPasswordComponent, canActivate: [UserGuard], runGuardsAndResolvers: 'always' },

+ 0 - 0
src/app/composants/chat/chat.component.css


+ 6 - 0
src/app/composants/chat/chat.component.html

@@ -0,0 +1,6 @@
+<app-menu></app-menu>
+<div id="main">
+
+Chat !
+
+</div>

+ 50 - 0
src/app/composants/chat/chat.component.ts

@@ -0,0 +1,50 @@
+import { Component, OnInit } from '@angular/core';
+import { timer } from 'rxjs';
+
+import { MenuComponent } from '../menu/menu.component';
+import { MessageShort } from '../../interfaces/chat';
+import { ChatService } from '../../services/chat.service';
+
+@Component({ selector: 'app-chat', imports: [MenuComponent], templateUrl: './chat.component.html', styleUrl: './chat.component.css' })
+
+export class ChatComponent implements OnInit
+{
+
+  dernierNumero: number = 0;
+
+  lignes: MessageShort[] = [];
+
+  ajoute: MessageShort = new MessageShort();
+
+  constructor(private chatService: ChatService) { }
+
+  ngOnInit()
+  {
+    this.recupererToutesLignes();
+
+    timer(0, 7000).subscribe(() => { this.recupererDernieresLignes(); });
+  }
+
+  recupererToutesLignes() { this.chatService.getList().subscribe(data => { this.lignes = data; }); this.setDernierNumero(); }
+
+  recupererDernieresLignes() { this.chatService.getNew(this.dernierNumero).subscribe(data => { this.lignes = [...this.lignes, ...data]; }); this.setDernierNumero(); }
+
+  private setDernierNumero()
+  {
+    this.dernierNumero = 0;
+
+    if (this.lignes != null)
+    {
+      if (this.lignes.length > 0)
+      {
+        for (let i = 0; i < this.lignes.length; i++) { this.dernierNumero = Math.max(this.dernierNumero, this.lignes[i].numeroMessage); }
+      }
+    }
+  }
+
+  envoiNouvelleLigne()
+  {
+    this.chatService.addNew(this.dernierNumero, this.ajoute).subscribe(data => { this.lignes = [...this.lignes, ...data]; }); this.setDernierNumero();
+  }
+
+}

+ 4 - 5
src/app/composants/event-list/event-list.component.html

@@ -2,11 +2,12 @@
 <div id="main">
 <div class="card shadow rounded-bottom-0">
 
-  <p class="fs-4 text-center" style="margin-top:12px;"><span i18n>Planning des conférences et événements</span></p>
+  <p class="fs-3 text-center" style="margin-top:12px;"><span i18n>Planning des conférences et événements</span></p>
 
-  <div class="alert alert-warning text-center" role="alert" style="margin:7px;"><span i18n>Soumis à modifications, merci de consulter cette page régulièrement.</span></div>
+  <div style="margin:auto;"><small><span i18n>Soumis à modifications, merci de consulter cette page régulièrement.</span></small></div>
+</div>
 
-  <div class="d-flex flex-wrap justify-content-around">
+<div class="d-flex flex-wrap justify-content-around">
 
 @if (this.journees.jour1Court) {
 
@@ -194,7 +195,5 @@
 
 }
 
-  </div>
-
 </div>
 </div>

+ 8 - 0
src/app/interfaces/chat.ts

@@ -0,0 +1,8 @@
+export class MessageShort
+{
+  dateCreation?: string;
+  numeroMessage: number = 0;
+  pseudonyme: string = "";
+  ligne: string = "";
+  numeroDestinataire: number = 0;
+}

+ 22 - 0
src/app/services/chat.service.ts

@@ -0,0 +1,22 @@
+import { Injectable } from '@angular/core';
+import { HttpClient } from '@angular/common/http'
+import { Observable } from 'rxjs';
+import { Environnement } from '../env';
+import { MessageShort } from '../interfaces/chat';
+
+@Injectable({ providedIn: 'root' })
+
+export class ChatService
+{
+
+  private baseURL = Environnement.apiUrl + "chat";
+
+  constructor(private httpClient: HttpClient) { }
+
+  getList(): Observable<MessageShort[]> { return this.httpClient.get<MessageShort[]>(`${this.baseURL}/list`); }
+
+  getNew(last: number): Observable<MessageShort[]> { return this.httpClient.get<MessageShort[]>(`${this.baseURL}/new/${last}`); }
+
+  addNew(last: number, msg: MessageShort): Observable<MessageShort[]>{ return this.httpClient.post<MessageShort[]>(`${this.baseURL}/add/${last}`, msg); }
+
+}