formacao
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core';
|
||||
import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core';
|
||||
import { provideHttpClient } from '@angular/common/http';
|
||||
import { provideRouter } from '@angular/router';
|
||||
|
||||
import { routes } from './app.routes';
|
||||
@@ -6,6 +7,7 @@ import { routes } from './app.routes';
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideBrowserGlobalErrorListeners(),
|
||||
provideHttpClient(),
|
||||
provideRouter(routes)
|
||||
]
|
||||
};
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * * The content below * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * is only a placeholder * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * and can be replaced. * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
|
||||
<!-- * * * * * * * * * Delete the template below * * * * * * * * * -->
|
||||
<!-- * * * * * * * to get started with your project! * * * * * * * -->
|
||||
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
|
||||
|
||||
<style>
|
||||
:host {
|
||||
--bright-blue: oklch(51.01% 0.274 263.83);
|
||||
|
||||
+28
-1
@@ -1,19 +1,46 @@
|
||||
import { Routes } from '@angular/router';
|
||||
import { Routes } from '@angular/router';
|
||||
import { Formacaometacase } from './formacaometacase/formacaometacase';
|
||||
import { CourseDetailPageComponent } from './course-detail-page/course-detail-page';
|
||||
import { CourseLearningPageComponent } from './course-learning-page/course-learning-page';
|
||||
import { authGuard } from './auth/auth.guard';
|
||||
import { LoginPageComponent } from './login-page/login-page';
|
||||
import { PaginaPrincipalComponent } from './pagina-principal/pagina-principal';
|
||||
import { VitoriaAiPageComponent } from './vitoria-ai-page/vitoria-ai-page';
|
||||
import { ConversorExtratosPageComponent } from './conversor-extratos-page/conversor-extratos-page';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: LoginPageComponent
|
||||
},
|
||||
{
|
||||
path: 'formacoes',
|
||||
canActivate: [authGuard],
|
||||
component: Formacaometacase
|
||||
},
|
||||
{
|
||||
path: 'pagina-principal',
|
||||
canActivate: [authGuard],
|
||||
component: PaginaPrincipalComponent
|
||||
},
|
||||
{
|
||||
path: 'vitoria-ai',
|
||||
canActivate: [authGuard],
|
||||
component: VitoriaAiPageComponent
|
||||
},
|
||||
{
|
||||
path: 'conversor-extratos',
|
||||
canActivate: [authGuard],
|
||||
component: ConversorExtratosPageComponent
|
||||
},
|
||||
{
|
||||
path: 'cursos/:slug',
|
||||
canActivate: [authGuard],
|
||||
component: CourseDetailPageComponent
|
||||
},
|
||||
{
|
||||
path: 'cursos/:slug/percurso',
|
||||
canActivate: [authGuard],
|
||||
component: CourseLearningPageComponent
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { CanActivateFn, Router } from '@angular/router';
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
export const authGuard: CanActivateFn = () => {
|
||||
const authService = inject(AuthService);
|
||||
const router = inject(Router);
|
||||
|
||||
return authService.isLoggedIn().then((isLoggedIn) => {
|
||||
if (isLoggedIn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return router.createUrlTree(['/']);
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,113 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
|
||||
export interface AuthSession {
|
||||
email: string;
|
||||
name: string;
|
||||
token: string;
|
||||
expiresAt: number;
|
||||
loggedAt: string;
|
||||
}
|
||||
|
||||
interface LoginResponse {
|
||||
token: string;
|
||||
expiresAt: number;
|
||||
user: {
|
||||
email: string;
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthService {
|
||||
private static readonly STORAGE_KEY = 'metacaseUser';
|
||||
|
||||
readonly currentUser = signal<AuthSession | null>(this.readSession());
|
||||
|
||||
hasStoredSession(): boolean {
|
||||
return this.currentUser() !== null;
|
||||
}
|
||||
|
||||
async isLoggedIn(): Promise<boolean> {
|
||||
const session = this.currentUser();
|
||||
|
||||
if (!session || Date.now() >= session.expiresAt) {
|
||||
this.logout();
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/session', {
|
||||
headers: {
|
||||
Authorization: `Bearer ${session.token}`
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
return true;
|
||||
}
|
||||
} catch {
|
||||
this.logout();
|
||||
return false;
|
||||
}
|
||||
|
||||
this.logout();
|
||||
return false;
|
||||
}
|
||||
|
||||
async login(email: string, password: string, rememberSession: boolean): Promise<void> {
|
||||
const response = await fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ email, password })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Credenciais invalidas.');
|
||||
}
|
||||
|
||||
const loginResponse = (await response.json()) as LoginResponse;
|
||||
const session: AuthSession = {
|
||||
email: loginResponse.user.email,
|
||||
name: loginResponse.user.name,
|
||||
token: loginResponse.token,
|
||||
expiresAt: loginResponse.expiresAt,
|
||||
loggedAt: new Date().toISOString()
|
||||
};
|
||||
|
||||
this.clearStoredSession();
|
||||
const storage = rememberSession ? localStorage : sessionStorage;
|
||||
storage.setItem(AuthService.STORAGE_KEY, JSON.stringify(session));
|
||||
this.currentUser.set(session);
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
this.clearStoredSession();
|
||||
this.currentUser.set(null);
|
||||
}
|
||||
|
||||
private readSession(): AuthSession | null {
|
||||
const storedSession =
|
||||
localStorage.getItem(AuthService.STORAGE_KEY) ??
|
||||
sessionStorage.getItem(AuthService.STORAGE_KEY);
|
||||
|
||||
if (!storedSession) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(storedSession) as AuthSession;
|
||||
} catch {
|
||||
this.clearStoredSession();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private clearStoredSession(): void {
|
||||
localStorage.removeItem(AuthService.STORAGE_KEY);
|
||||
sessionStorage.removeItem(AuthService.STORAGE_KEY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
.hidden-file-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.hero-logo-badge {
|
||||
position: absolute;
|
||||
top: 24px;
|
||||
right: 24px;
|
||||
z-index: 1;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 14px;
|
||||
padding: 10px 16px;
|
||||
border: 1px solid rgba(191, 219, 254, 0.55);
|
||||
border-radius: 999px;
|
||||
background: rgba(239, 246, 255, 0.88);
|
||||
backdrop-filter: blur(8px);
|
||||
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
|
||||
}
|
||||
|
||||
.hero-logo {
|
||||
width: clamp(120px, 16vw, 190px);
|
||||
height: auto;
|
||||
display: block;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.back-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
color: #f8f8f8;
|
||||
text-decoration: none;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.logout-button {
|
||||
min-height: 34px;
|
||||
cursor: pointer;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
background: #1d4ed8;
|
||||
padding: 0 14px;
|
||||
color: #ffffff;
|
||||
font-size: 0.88rem;
|
||||
font-weight: 800;
|
||||
transition: background-color 0.2s ease, transform 0.2s ease;
|
||||
}
|
||||
|
||||
.logout-button:hover {
|
||||
background: #1e40af;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.converter-status {
|
||||
margin-top: 1.5rem;
|
||||
border-radius: 1.5rem;
|
||||
border: 1px solid rgb(226 232 240);
|
||||
background: rgb(255 255 255);
|
||||
padding: 1rem 1.25rem;
|
||||
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
|
||||
}
|
||||
|
||||
.converter-status__eyebrow {
|
||||
margin: 0;
|
||||
color: rgb(15 23 42);
|
||||
font-size: 0.78rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.converter-status__message {
|
||||
margin: 0.45rem 0 0;
|
||||
color: rgb(71 85 105);
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.bank-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.bank-card__button {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.bank-card__button--active {
|
||||
outline: 2px solid rgba(37, 99, 235, 0.35);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.bank-card__button--disabled {
|
||||
opacity: 0.82;
|
||||
}
|
||||
|
||||
.bank-card__badge {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
left: 16px;
|
||||
z-index: 1;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 32px;
|
||||
padding: 0 14px;
|
||||
border-radius: 999px;
|
||||
background: rgba(22, 163, 74, 0.92);
|
||||
color: #ffffff;
|
||||
font-size: 0.74rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.bank-card__badge--muted {
|
||||
background: rgba(100, 116, 139, 0.92);
|
||||
}
|
||||
|
||||
.bank-card__action {
|
||||
display: block;
|
||||
width: 100%;
|
||||
margin-top: 1.5rem;
|
||||
border-radius: 1rem;
|
||||
background: linear-gradient(to right, #4f46e5, #7c3aed);
|
||||
padding: 0.85rem 1rem;
|
||||
color: #ffffff;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.bank-card__action--muted {
|
||||
background: linear-gradient(to right, #94a3b8, #64748b);
|
||||
}
|
||||
|
||||
@media (max-width: 1400px) {
|
||||
.bank-grid {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.bank-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.bank-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.hero-logo-badge {
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
padding: 8px 14px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.hero-logo {
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.bank-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<div class="min-h-screen bg-slate-50 text-slate-900">
|
||||
<input
|
||||
#pdfInput
|
||||
type="file"
|
||||
accept=".pdf,application/pdf"
|
||||
class="hidden-file-input"
|
||||
(change)="onFileSelected($event)"
|
||||
/>
|
||||
|
||||
<section class="relative overflow-hidden bg-slate-950">
|
||||
<div class="absolute inset-0 bg-gradient-to-r from-indigo-700/20 via-cyan-500/10 to-purple-700/20"></div>
|
||||
<div class="hero-logo-badge">
|
||||
<button type="button" class="logout-button" (click)="logout()">Sair</button>
|
||||
<a href="https://www.metacase.pt" target="_blank" rel="noopener">
|
||||
<img
|
||||
src="/logo-metacase-cor.svg"
|
||||
alt="Metacase"
|
||||
class="hero-logo"
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="relative mx-auto max-w-7xl px-6 py-20 lg:px-8">
|
||||
<div class="max-w-3xl">
|
||||
<span class="inline-flex rounded-full border border-white/20 bg-white/10 px-4 py-1 text-sm font-medium text-white">
|
||||
Operacional Framework
|
||||
</span>
|
||||
|
||||
<h1 class="mt-6 text-4xl font-bold tracking-tight text-white sm:text-5xl lg:text-6xl">
|
||||
Conversor de Extratos
|
||||
</h1>
|
||||
|
||||
<p class="mt-6 text-lg leading-8 text-slate-300">
|
||||
Area dedicada a conversao de extratos bancarios a partir de PDF com exportacao final para Excel.
|
||||
</p>
|
||||
|
||||
<a routerLink="/pagina-principal" class="back-link"><br><br>Voltar ao menu do Multipurpose Hub</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="mx-auto max-w-7xl px-6 py-10 lg:px-8">
|
||||
<div class="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
|
||||
<div>
|
||||
<h2 class="text-3xl font-bold tracking-tight text-slate-900">Entidades Bancarias</h2>
|
||||
<p class="mt-2 text-slate-600">
|
||||
Atualmente encontram-se disponiveis {{ converterCards.length }} {{ converterCards.length === 1 ? 'entidade bancaria' : 'entidades bancarias' }}.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="inline-flex w-fit items-center rounded-2xl border border-slate-200 bg-white px-4 py-3 shadow-sm">
|
||||
<span class="text-sm font-semibold text-slate-700">
|
||||
{{ converterCards.length }} {{ converterCards.length === 1 ? 'banco' : 'bancos' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="converter-status">
|
||||
<p class="converter-status__eyebrow">{{ isLoading ? 'A processar' : statusTitle }}</p>
|
||||
<p class="converter-status__message">{{ statusMessage }}</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="mx-auto max-w-7xl px-6 pb-16 lg:px-8">
|
||||
<div class="bank-grid">
|
||||
<article
|
||||
*ngFor="let card of converterCards; trackBy: trackByBankKey"
|
||||
class="group overflow-hidden rounded-3xl border border-slate-200 bg-white shadow-sm transition duration-300 hover:-translate-y-1 hover:shadow-xl"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="bank-card__button"
|
||||
[class.bank-card__button--active]="selectedBankKey === card.bankKey"
|
||||
[class.bank-card__button--disabled]="!card.available"
|
||||
[disabled]="isLoading"
|
||||
(click)="handleCardClick(card)"
|
||||
>
|
||||
<div class="relative h-56 overflow-hidden">
|
||||
<img
|
||||
[src]="card.image"
|
||||
[alt]="card.title"
|
||||
class="h-full w-full bg-slate-50 object-contain transition duration-500 group-hover:scale-105"
|
||||
/>
|
||||
|
||||
<div class="absolute inset-0 bg-gradient-to-t from-black/10 via-transparent to-transparent"></div>
|
||||
|
||||
<div class="bank-card__badge" [class.bank-card__badge--muted]="!card.available">
|
||||
{{ card.available ? 'Disponivel' : 'Em breve' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="p-6">
|
||||
<h3 class="mt-2 text-xl font-bold text-slate-900">
|
||||
{{ card.title }}
|
||||
</h3>
|
||||
|
||||
<p class="mt-3 text-sm leading-6 text-slate-600">
|
||||
{{ card.description }}
|
||||
</p>
|
||||
|
||||
<div class="mt-5 flex flex-wrap gap-2">
|
||||
<span class="rounded-full bg-slate-100 px-3 py-1 text-xs font-semibold text-slate-700">
|
||||
{{ card.available ? 'PDF para Excel' : 'Configuracao pendente' }}
|
||||
</span>
|
||||
|
||||
<span
|
||||
*ngIf="selectedBankKey === card.bankKey"
|
||||
class="rounded-full bg-blue-50 px-3 py-1 text-xs font-semibold text-blue-700"
|
||||
>
|
||||
Selecionado
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<span class="bank-card__action" [class.bank-card__action--muted]="!card.available">
|
||||
{{ isLoading && selectedBankKey === card.bankKey ? 'A processar...' : (card.available ? 'Selecionar PDF' : 'Em breve') }}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
@@ -0,0 +1,225 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
||||
import { Component, ElementRef, ViewChild, inject } from '@angular/core';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { finalize } from 'rxjs';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { ConversorExtratosService } from './conversor-extratos.service';
|
||||
|
||||
interface ConverterCard {
|
||||
bankKey: string;
|
||||
title: string;
|
||||
description: string;
|
||||
image: string;
|
||||
available: boolean;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-conversor-extratos-page',
|
||||
standalone: true,
|
||||
imports: [CommonModule, RouterLink],
|
||||
templateUrl: './conversor-extratos-page.html',
|
||||
styleUrl: './conversor-extratos-page.css'
|
||||
})
|
||||
export class ConversorExtratosPageComponent {
|
||||
@ViewChild('pdfInput') private pdfInput?: ElementRef<HTMLInputElement>;
|
||||
|
||||
private readonly authService = inject(AuthService);
|
||||
private readonly router = inject(Router);
|
||||
private readonly conversorService = inject(ConversorExtratosService);
|
||||
|
||||
readonly converterCards: ConverterCard[] = [
|
||||
{
|
||||
bankKey: 'millennium-bcp',
|
||||
title: 'Millennium BCP',
|
||||
description: 'Em breve.',
|
||||
image: '/imagenscursos/Millenniumbcp.png',
|
||||
available: false
|
||||
},
|
||||
{
|
||||
bankKey: 'caixa-geral-depositos',
|
||||
title: 'Caixa Geral',
|
||||
description: 'Em breve.',
|
||||
image: '/imagenscursos/cgd.png',
|
||||
available: false
|
||||
},
|
||||
{
|
||||
bankKey: 'bankinter',
|
||||
title: 'Bankinter',
|
||||
description: 'Em breve.',
|
||||
image: '/imagenscursos/bankinter.png',
|
||||
available: false
|
||||
},
|
||||
{
|
||||
bankKey: 'novo-banco',
|
||||
title: 'Novo Banco',
|
||||
description: 'Em breve.',
|
||||
image: '/imagenscursos/novobanco.png',
|
||||
available: false
|
||||
},
|
||||
{
|
||||
bankKey: 'bpi',
|
||||
title: 'BPI',
|
||||
description: 'Em breve.',
|
||||
image: '/imagenscursos/BPI.png',
|
||||
available: false
|
||||
},
|
||||
{
|
||||
bankKey: 'bic',
|
||||
title: 'BIC',
|
||||
description: 'Clique, selecione o PDF e descarregue o Excel final.',
|
||||
image: '/imagenscursos/bic.png',
|
||||
available: true
|
||||
},
|
||||
{
|
||||
bankKey: 'abanca',
|
||||
title: 'ABanca',
|
||||
description: 'Clique, selecione o PDF e descarregue o Excel final.',
|
||||
image: '/imagenscursos/ABanca.png',
|
||||
available: true
|
||||
}
|
||||
];
|
||||
|
||||
selectedBankKey = '';
|
||||
isLoading = false;
|
||||
statusTitle = '2 Bancos disponiveis';
|
||||
statusMessage = 'Clique no cartao para selecionar o PDF a converter.';
|
||||
|
||||
logout(): void {
|
||||
this.authService.logout();
|
||||
void this.router.navigateByUrl('/');
|
||||
}
|
||||
|
||||
trackByBankKey(_: number, card: ConverterCard): string {
|
||||
return card.bankKey;
|
||||
}
|
||||
|
||||
handleCardClick(card: ConverterCard): void {
|
||||
if (this.isLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.selectedBankKey = card.bankKey;
|
||||
|
||||
if (!card.available) {
|
||||
this.setStatus(`${card.title} ainda nao disponivel`, 'Replica o mesmo padrao do ABanca quando tiveres o script pronto.');
|
||||
return;
|
||||
}
|
||||
|
||||
this.setStatus(`${card.title} selecionado`, 'Escolhe o PDF do extrato para iniciar a conversao.');
|
||||
this.resetInput();
|
||||
this.pdfInput?.nativeElement.click();
|
||||
}
|
||||
|
||||
onFileSelected(event: Event): void {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
const selectedCard = this.converterCards.find((card) => card.bankKey === this.selectedBankKey);
|
||||
|
||||
if (!file || !selectedCard || !selectedCard.available) {
|
||||
this.resetInput();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!file.name.toLowerCase().endsWith('.pdf')) {
|
||||
this.setStatus('Ficheiro invalido', 'Seleciona um ficheiro PDF para continuar.');
|
||||
this.resetInput();
|
||||
return;
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
this.setStatus(`A processar ${selectedCard.title}`, `A converter o ficheiro ${file.name}. Aguarda pelo download.`);
|
||||
|
||||
this.conversorService
|
||||
.executeConverter(selectedCard.bankKey, file)
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
this.isLoading = false;
|
||||
this.resetInput();
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
const filename = this.getDownloadFileName(response, selectedCard);
|
||||
this.downloadBlob(response.body, filename);
|
||||
this.setStatus('Conversao concluida', `O ficheiro ${filename} foi gerado com sucesso.`);
|
||||
},
|
||||
error: (error: unknown) => {
|
||||
this.setStatus('Conversao falhou', this.getErrorMessage(error));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private resetInput(): void {
|
||||
const nativeInput = this.pdfInput?.nativeElement;
|
||||
if (nativeInput) {
|
||||
nativeInput.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
private setStatus(title: string, message: string): void {
|
||||
this.statusTitle = title;
|
||||
this.statusMessage = message;
|
||||
}
|
||||
|
||||
private getDownloadFileName(response: HttpResponse<Blob>, card: ConverterCard): string {
|
||||
const disposition = response.headers.get('content-disposition') || '';
|
||||
const encodedMatch = disposition.match(/filename\*=UTF-8''([^;]+)/i);
|
||||
|
||||
if (encodedMatch?.[1]) {
|
||||
return decodeURIComponent(encodedMatch[1]);
|
||||
}
|
||||
|
||||
const plainMatch = disposition.match(/filename="?([^"]+)"?/i);
|
||||
if (plainMatch?.[1]) {
|
||||
return plainMatch[1];
|
||||
}
|
||||
|
||||
return `${this.slugify(card.title)}-resultado.xlsx`;
|
||||
}
|
||||
|
||||
private downloadBlob(blob: Blob | null, filename: string): void {
|
||||
if (!blob) {
|
||||
throw new Error('O backend nao devolveu nenhum ficheiro.');
|
||||
}
|
||||
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = objectUrl;
|
||||
link.download = filename;
|
||||
link.click();
|
||||
setTimeout(() => URL.revokeObjectURL(objectUrl), 0);
|
||||
}
|
||||
|
||||
private slugify(value: string): string {
|
||||
return value
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '');
|
||||
}
|
||||
|
||||
private getErrorMessage(error: unknown): string {
|
||||
if (error && typeof error === 'object' && 'name' in error && error.name === 'TimeoutError') {
|
||||
return 'O script demorou demasiado tempo a responder. Confirma o ambiente Python e o tamanho do PDF.';
|
||||
}
|
||||
|
||||
if (error instanceof HttpErrorResponse) {
|
||||
const detail =
|
||||
typeof error.error === 'string'
|
||||
? error.error
|
||||
: typeof error.error?.detail === 'string'
|
||||
? error.error.detail
|
||||
: typeof error.error?.message === 'string'
|
||||
? error.error.message
|
||||
: '';
|
||||
|
||||
if (error.status === 0) {
|
||||
return 'Nao foi possivel comunicar com o backend do conversor.';
|
||||
}
|
||||
|
||||
return detail ? `Erro do backend (${error.status}): ${detail}` : `Erro do backend (${error.status}).`;
|
||||
}
|
||||
|
||||
return 'O pedido falhou por um erro inesperado.';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable, timeout } from 'rxjs';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ConversorExtratosService {
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly endpoint = '/api/conversor-extratos/executar';
|
||||
private readonly requestTimeoutMs = 600000;
|
||||
|
||||
executeConverter(bankKey: string, file: File): Observable<HttpResponse<Blob>> {
|
||||
const headers = new HttpHeaders({
|
||||
'Content-Type': file.type || 'application/pdf',
|
||||
'X-Bank-Key': bankKey,
|
||||
'X-File-Name': encodeURIComponent(file.name)
|
||||
});
|
||||
|
||||
return this.http
|
||||
.post(this.endpoint, file, {
|
||||
headers,
|
||||
observe: 'response',
|
||||
responseType: 'blob'
|
||||
})
|
||||
.pipe(timeout(this.requestTimeoutMs));
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<section class="course-intro">
|
||||
<div class="course-intro__inner">
|
||||
<div class="course-intro__main">
|
||||
<a routerLink="/" class="back-link">Voltar ao menu das formações</a>
|
||||
<a routerLink="/formacoes" class="back-link">Voltar ao menu das formações</a>
|
||||
|
||||
<h1>{{ course.title }}</h1>
|
||||
<p class="intro-summary">{{ course.summary }}</p>
|
||||
@@ -59,7 +59,7 @@
|
||||
<h2>Começar esta formação</h2>
|
||||
<p>{{ course.description }}</p>
|
||||
<a [routerLink]="['/cursos', course.slug, 'percurso']" class="button">Iniciar formação</a>
|
||||
<a routerLink="/" class="button button--secondary">Voltar ao menu das formações</a>
|
||||
<a routerLink="/formacoes" class="button button--secondary">Voltar ao menu das formações</a>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
@@ -115,7 +115,7 @@
|
||||
<div class="course-not-found__card">
|
||||
<h1>Formação não encontrada</h1>
|
||||
<p>A formação selecionada não está disponível neste momento.</p>
|
||||
<a routerLink="/" class="button">Voltar aos cursos</a>
|
||||
<a routerLink="/formacoes" class="button">Voltar aos cursos</a>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
@@ -314,7 +314,7 @@
|
||||
<div class="course-not-found__card">
|
||||
<h1>Percurso nao encontrado</h1>
|
||||
<p>O percurso pedido nao esta disponivel neste momento.</p>
|
||||
<a routerlink="/" class="button">Voltar aos cursos</a>
|
||||
<a routerLink="/formacoes" class="button">Voltar aos cursos</a>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 14px;
|
||||
padding: 10px 16px;
|
||||
border: 1px solid rgba(191, 219, 254, 0.55);
|
||||
border-radius: 999px;
|
||||
@@ -21,6 +22,33 @@
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.back-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
color: #f8f8f8;
|
||||
text-decoration: none;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.logout-button {
|
||||
min-height: 34px;
|
||||
cursor: pointer;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
background: #1d4ed8;
|
||||
padding: 0 14px;
|
||||
color: #ffffff;
|
||||
font-size: 0.88rem;
|
||||
font-weight: 800;
|
||||
transition: background-color 0.2s ease, transform 0.2s ease;
|
||||
}
|
||||
|
||||
.logout-button:hover {
|
||||
background: #1e40af;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.course-card__badge {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
@@ -48,6 +76,7 @@
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
padding: 8px 14px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.hero-logo {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<div class="min-h-screen bg-slate-50 text-slate-900">
|
||||
<div class="min-h-screen bg-slate-50 text-slate-900">
|
||||
<section class="relative overflow-hidden bg-slate-950">
|
||||
<div class="absolute inset-0 bg-gradient-to-r from-indigo-700/20 via-cyan-500/10 to-purple-700/20"></div>
|
||||
<div class="hero-logo-badge">
|
||||
<button type="button" class="logout-button" (click)="logout()">Sair</button>
|
||||
<a href="https://www.metacase.pt" target="_blank" rel="noopener">
|
||||
<img
|
||||
src="/logo-metacase-cor.svg"
|
||||
@@ -24,6 +25,7 @@
|
||||
<p class="mt-6 text-lg leading-8 text-slate-300">
|
||||
Formações práticas e atualizadas para a utilização da plataforma TargetOne <br>Aprendizagem orientada para a ferramenta com formações teóricas e práticas
|
||||
</p>
|
||||
<a routerLink="/pagina-principal" class="back-link"><br><br>Voltar ao menu do Multipurpose Hub</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -79,7 +81,6 @@
|
||||
</p>
|
||||
|
||||
<div class="mt-5 flex flex-wrap gap-2">
|
||||
|
||||
<span class="rounded-full bg-slate-100 px-3 py-1 text-xs font-semibold text-slate-700">
|
||||
{{ course.duration }}
|
||||
</span>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { COURSES, type Course } from '../data/courses';
|
||||
|
||||
@Component({
|
||||
@@ -12,4 +13,14 @@ import { COURSES, type Course } from '../data/courses';
|
||||
})
|
||||
export class Formacaometacase {
|
||||
readonly courses: Course[] = COURSES;
|
||||
|
||||
constructor(
|
||||
private readonly authService: AuthService,
|
||||
private readonly router: Router
|
||||
) {}
|
||||
|
||||
logout(): void {
|
||||
this.authService.logout();
|
||||
void this.router.navigateByUrl('/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
:host {
|
||||
display: block;
|
||||
min-height: 100vh;
|
||||
background:
|
||||
linear-gradient(135deg, rgba(15, 23, 42, 0.86), rgba(30, 64, 175, 0.68)),
|
||||
url('/screenshots/Pagina Principal.jpg') center / cover no-repeat;
|
||||
color: #0f172a;
|
||||
}
|
||||
|
||||
.login-page {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
width: min(100%, 420px);
|
||||
border: 1px solid rgba(226, 232, 240, 0.86);
|
||||
border-radius: 8px;
|
||||
background: rgba(255, 255, 255, 0.96);
|
||||
padding: 32px;
|
||||
box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
|
||||
}
|
||||
|
||||
.login-logo {
|
||||
display: block;
|
||||
width: 170px;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.login-header span {
|
||||
display: inline-flex;
|
||||
border-radius: 999px;
|
||||
background: #dbeafe;
|
||||
padding: 7px 11px;
|
||||
color: #1d4ed8;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
margin: 18px 0 0;
|
||||
font-size: 2rem;
|
||||
line-height: 1.1;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
margin: 10px 0 0;
|
||||
color: #64748b;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.login-form {
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
margin-top: 28px;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
color: #334155;
|
||||
font-size: 0.92rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.field input {
|
||||
min-height: 52px;
|
||||
width: 100%;
|
||||
border: 1px solid #cbd5e1;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
padding: 0 14px;
|
||||
color: #0f172a;
|
||||
font: inherit;
|
||||
font-weight: 500;
|
||||
outline: none;
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.field input:focus {
|
||||
border-color: #2563eb;
|
||||
box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.16);
|
||||
}
|
||||
|
||||
.field input.field--invalid {
|
||||
border-color: #dc2626;
|
||||
}
|
||||
|
||||
.remember-row {
|
||||
display: inline-flex;
|
||||
width: fit-content;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
color: #475569;
|
||||
font-size: 0.92rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.remember-row input {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
accent-color: #2563eb;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
margin: 0;
|
||||
border-radius: 8px;
|
||||
background: #fee2e2;
|
||||
padding: 12px 14px;
|
||||
color: #991b1b;
|
||||
font-size: 0.92rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.login-form button {
|
||||
min-height: 54px;
|
||||
cursor: pointer;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
background: linear-gradient(135deg, #2563eb, #7c3aed);
|
||||
color: #ffffff;
|
||||
font-size: 1rem;
|
||||
font-weight: 800;
|
||||
transition: opacity 0.2s ease, transform 0.2s ease;
|
||||
}
|
||||
|
||||
.login-form button:hover {
|
||||
opacity: 0.94;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.login-card {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 1.75rem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<main class="login-page">
|
||||
<section class="login-card" aria-labelledby="login-title">
|
||||
<img src="/logo-metacase-cor.svg" alt="Metacase" class="login-logo" />
|
||||
|
||||
<div class="login-header">
|
||||
<span>Multipurpose hub</span>
|
||||
<h1 id="login-title">Iniciar sessao</h1>
|
||||
<p>Entre para aceder as formacoes TargetOne.</p>
|
||||
</div>
|
||||
|
||||
<form class="login-form" (ngSubmit)="login()" novalidate>
|
||||
<label class="field">
|
||||
<span>Email</span>
|
||||
<input
|
||||
type="email"
|
||||
name="email"
|
||||
autocomplete="email"
|
||||
placeholder="nome@empresa.pt"
|
||||
[(ngModel)]="email"
|
||||
[class.field--invalid]="submitted() && !email.trim()"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label class="field">
|
||||
<span>Palavra-passe</span>
|
||||
<input
|
||||
type="password"
|
||||
name="password"
|
||||
autocomplete="current-password"
|
||||
placeholder="Palavra-passe"
|
||||
[(ngModel)]="password"
|
||||
[class.field--invalid]="submitted() && !password"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label class="remember-row">
|
||||
<input type="checkbox" name="rememberSession" [(ngModel)]="rememberSession" />
|
||||
<span>Manter sessao iniciada</span>
|
||||
</label>
|
||||
|
||||
<p class="error-message" *ngIf="errorMessage()">{{ errorMessage() }}</p>
|
||||
|
||||
<button type="submit">Entrar</button>
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
@@ -0,0 +1,51 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, OnInit, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login-page',
|
||||
standalone: true,
|
||||
imports: [CommonModule, FormsModule],
|
||||
templateUrl: './login-page.html',
|
||||
styleUrl: './login-page.css'
|
||||
})
|
||||
export class LoginPageComponent implements OnInit {
|
||||
email = '';
|
||||
password = '';
|
||||
rememberSession = true;
|
||||
|
||||
readonly submitted = signal(false);
|
||||
readonly errorMessage = signal('');
|
||||
|
||||
constructor(
|
||||
private readonly authService: AuthService,
|
||||
private readonly router: Router
|
||||
) {}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
if (await this.authService.isLoggedIn()) {
|
||||
void this.router.navigateByUrl('/formacoes');
|
||||
}
|
||||
}
|
||||
|
||||
async login(): Promise<void> {
|
||||
this.submitted.set(true);
|
||||
this.errorMessage.set('');
|
||||
|
||||
const email = this.email.trim();
|
||||
|
||||
if (!email || !this.password) {
|
||||
this.errorMessage.set('Preencha o email e a palavra-passe.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.authService.login(email, this.password, this.rememberSession);
|
||||
void this.router.navigateByUrl('/pagina-principal');
|
||||
} catch {
|
||||
this.errorMessage.set('Email ou palavra-passe incorretos.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.hub-page {
|
||||
position: relative;
|
||||
min-height: 100vh;
|
||||
padding: 32px;
|
||||
color: #0f172a;
|
||||
background:
|
||||
radial-gradient(circle at top left, rgba(59, 130, 246, 0.16), transparent 28%),
|
||||
radial-gradient(circle at top right, rgba(56, 189, 248, 0.18), transparent 26%),
|
||||
linear-gradient(180deg, #f8fbff 0%, #eef4ff 44%, #f8fafc 100%);
|
||||
}
|
||||
|
||||
.hub-page__backdrop {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
pointer-events: none;
|
||||
background:
|
||||
linear-gradient(135deg, rgba(255, 255, 255, 0.64), rgba(255, 255, 255, 0)),
|
||||
radial-gradient(circle at center, rgba(15, 23, 42, 0.03), transparent 54%);
|
||||
}
|
||||
|
||||
.hub-topbar,
|
||||
.hub-hero,
|
||||
.hub-grid {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.hub-topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.hub-topbar__brand {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 14px 18px;
|
||||
border: 1px solid rgba(191, 219, 254, 0.7);
|
||||
border-radius: 999px;
|
||||
background: rgba(255, 255, 255, 0.84);
|
||||
box-shadow: 0 20px 48px rgba(15, 23, 42, 0.08);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.hub-topbar__logo {
|
||||
width: clamp(170px, 18vw, 260px);
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.hub-topbar__logout {
|
||||
min-height: 44px;
|
||||
padding: 0 18px;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
background: linear-gradient(135deg, #1d4ed8, #2563eb);
|
||||
color: #fff;
|
||||
font-weight: 800;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 16px 34px rgba(37, 99, 235, 0.24);
|
||||
}
|
||||
|
||||
.hub-hero {
|
||||
max-width: 760px;
|
||||
margin: 44px auto 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.hub-hero__eyebrow {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 34px;
|
||||
padding: 0 14px;
|
||||
border-radius: 999px;
|
||||
background: rgba(37, 99, 235, 0.1);
|
||||
color: #1d4ed8;
|
||||
font-size: 0.82rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.hub-hero h1 {
|
||||
margin: 18px 0 0;
|
||||
font-size: clamp(2.4rem, 4vw, 4rem);
|
||||
line-height: 1.05;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.hub-hero p {
|
||||
margin: 18px auto 0;
|
||||
max-width: 640px;
|
||||
color: #ffffff;
|
||||
font-size: 1.05rem;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.hub-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 28px;
|
||||
align-items: start;
|
||||
margin-top: 54px;
|
||||
}
|
||||
|
||||
.orbit-card {
|
||||
position: relative;
|
||||
min-height: 620px;
|
||||
padding: 28px;
|
||||
border: 1px solid rgba(148, 163, 184, 0.2);
|
||||
border-radius: 36px;
|
||||
background: rgb(255, 255, 255);
|
||||
box-shadow: 0 28px 70px rgba(15, 23, 42, 0.08);
|
||||
backdrop-filter: blur(14px);
|
||||
}
|
||||
|
||||
.orbit-card__header span {
|
||||
text-align: center;
|
||||
display: block;
|
||||
color: #0f172a;
|
||||
font-size: 1.4rem;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.orbit-card__header p {
|
||||
text-align: center;
|
||||
margin: 8px 0 0;
|
||||
color: #e2e8f0;
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.orbit-shell {
|
||||
--orbit-radius: 190px;
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 500px;
|
||||
}
|
||||
|
||||
.orbit-core {
|
||||
width: 250px;
|
||||
height: 250px;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background-color: #ffffff;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: contain;
|
||||
box-shadow: 0 30px 60px rgba(15, 23, 42, 0.18);
|
||||
cursor: pointer;
|
||||
transition: transform 0.24s ease, box-shadow 0.24s ease;
|
||||
}
|
||||
|
||||
.orbit-core:hover,
|
||||
.orbit-core--open {
|
||||
transform: scale(1.03);
|
||||
box-shadow: 0 34px 78px rgba(37, 99, 235, 0.24);
|
||||
}
|
||||
|
||||
.orbit-menu__item {
|
||||
--orbit-angle: 0deg;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 170px;
|
||||
min-height: 120px;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid rgba(255,255,255);
|
||||
border-radius: 24px;
|
||||
background: rgba(255, 255, 255, 0.98);
|
||||
box-shadow: 0 22px 42px rgba(15, 23, 42, 0.12);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transform: translate(-50%, -50%) rotate(var(--orbit-angle)) translateX(30px) rotate(calc(var(--orbit-angle) * -1)) scale(0.72);
|
||||
transition: transform 0.28s ease, opacity 0.28s ease;
|
||||
}
|
||||
|
||||
.orbit-menu__item--open {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
transform: translate(-50%, -50%) rotate(var(--orbit-angle)) translateX(var(--orbit-radius)) rotate(calc(var(--orbit-angle) * -1)) scale(1);
|
||||
}
|
||||
|
||||
.orbit-menu__image {
|
||||
width: 100%;
|
||||
height: 52px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.orbit-menu__label {
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
color: #0f172a;
|
||||
font-weight: 900;
|
||||
font-size: 0.96rem;
|
||||
}
|
||||
|
||||
.orbit-menu__caption {
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
color: #64748b;
|
||||
font-size: 0.78rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.hub-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {.hub-page {padding: 18px;}
|
||||
.hub-topbar {flex-direction: column;align-items: stretch;}
|
||||
.hub-topbar__brand {justify-content: center; }
|
||||
.orbit-shell {--orbit-radius: 150px;min-height: 430px;}
|
||||
.orbit-core {width: 200px;height: 200px;}
|
||||
.orbit-menu__item {width: 150px;min-height: 112px;}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<div class="hub-page">
|
||||
<div class="hub-page__backdrop"></div>
|
||||
|
||||
<header class="hub-topbar">
|
||||
<div class="hub-topbar__brand">
|
||||
<img src="/logo-metacase-cor.svg" alt="Metacase" class="hub-topbar__logo" />
|
||||
</div>
|
||||
|
||||
<button type="button" class="hub-topbar__logout" (click)="logout()">Sair</button>
|
||||
</header>
|
||||
|
||||
<section class="hub-hero">
|
||||
<div class="hub-hero__copy">
|
||||
<span class="hub-hero__eyebrow">Multipurpose Hub</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="hub-grid">
|
||||
<article class="orbit-card orbit-card--left">
|
||||
<div class="orbit-card__header">
|
||||
<span>Learning Hub</span>
|
||||
</div>
|
||||
|
||||
<div class="orbit-shell">
|
||||
<button
|
||||
type="button"
|
||||
class="orbit-core"
|
||||
[class.orbit-core--open]="leftOrbitOpen()"
|
||||
[style.background-image]="'url(' + leftCoreImage + ')'"
|
||||
(click)="toggleLeftOrbit()"
|
||||
>
|
||||
<span class="sr-only">Abrir atalhos Learning Hub</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
*ngFor="let shortcut of leftShortcuts"
|
||||
type="button"
|
||||
class="orbit-menu__item"
|
||||
[class.orbit-menu__item--open]="leftOrbitOpen()"
|
||||
[style.--orbit-angle]="shortcut.angle"
|
||||
(click)="activateShortcut(shortcut)"
|
||||
>
|
||||
<img [src]="shortcut.image" [alt]="shortcut.label" class="orbit-menu__image" />
|
||||
<span class="orbit-menu__label">{{ shortcut.label }}</span>
|
||||
<span class="orbit-menu__caption">{{ shortcut.caption }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="orbit-card orbit-card--right">
|
||||
<div class="orbit-card__header">
|
||||
<span>Operational Framework</span>
|
||||
</div>
|
||||
|
||||
<div class="orbit-shell orbit-shell--right">
|
||||
<button
|
||||
type="button"
|
||||
class="orbit-core"
|
||||
[class.orbit-core--open]="rightOrbitOpen()"
|
||||
[style.background-image]="'url(' + rightCoreImage + ')'"
|
||||
(click)="toggleRightOrbit()"
|
||||
>
|
||||
<span class="sr-only">Abrir atalhos Operational Framework</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
*ngFor="let shortcut of rightShortcuts"
|
||||
type="button"
|
||||
class="orbit-menu__item orbit-menu__item--right"
|
||||
[class.orbit-menu__item--open]="rightOrbitOpen()"
|
||||
[style.--orbit-angle]="shortcut.angle"
|
||||
(click)="activateShortcut(shortcut)"
|
||||
>
|
||||
<img [src]="shortcut.image" [alt]="shortcut.label" class="orbit-menu__image" />
|
||||
<span class="orbit-menu__label">{{ shortcut.label }}</span>
|
||||
<span class="orbit-menu__caption">{{ shortcut.caption }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
</div>
|
||||
@@ -0,0 +1,98 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, signal } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
|
||||
interface HubShortcut {
|
||||
label: string;
|
||||
caption: string;
|
||||
image: string;
|
||||
angle: string;
|
||||
route?: string;
|
||||
href?: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-pagina-principal',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
templateUrl: './pagina-principal.html',
|
||||
styleUrl: './pagina-principal.css'
|
||||
})
|
||||
export class PaginaPrincipalComponent {
|
||||
readonly leftOrbitOpen = signal(false);
|
||||
readonly rightOrbitOpen = signal(false);
|
||||
|
||||
readonly leftCoreImage = '/imagenscursos/learninghub.png';
|
||||
readonly rightCoreImage = '/imagenscursos/operationframework.png';
|
||||
|
||||
readonly leftShortcuts: HubShortcut[] = [
|
||||
{
|
||||
label: 'Formacoes',
|
||||
caption: 'Learning Hub',
|
||||
image: '/imagenscursos/LearningHub (2).png',
|
||||
route: '/formacoes',
|
||||
angle: '0deg'
|
||||
},
|
||||
{
|
||||
label: 'Vitoria AI',
|
||||
caption: 'LLM',
|
||||
image: '/imagenscursos/VitoriaAI.png',
|
||||
route: '/vitoria-ai',
|
||||
angle: '90deg'
|
||||
}
|
||||
];
|
||||
|
||||
readonly rightShortcuts: HubShortcut[] = [
|
||||
{
|
||||
label: 'Conversor de Extratos',
|
||||
caption: 'Por entidade bancaria',
|
||||
image: '/imagenscursos/outconversor.png',
|
||||
route: '/conversor-extratos',
|
||||
angle: '0deg'
|
||||
},
|
||||
{
|
||||
label: 'Tradutor',
|
||||
caption: 'Tradutor de textos',
|
||||
image: '/imagenscursos/Reportcreator.png',
|
||||
route: '/cursos/formacao-plataforma',
|
||||
angle: '90deg'
|
||||
},
|
||||
{
|
||||
label: 'Report Creator',
|
||||
caption: 'Report digitalization',
|
||||
image: '/imagenscursos/Digitalizationreport.png',
|
||||
route: '/cursos/formacao-plataforma',
|
||||
angle: '180deg'
|
||||
}
|
||||
];
|
||||
|
||||
constructor(
|
||||
private readonly authService: AuthService,
|
||||
private readonly router: Router
|
||||
) {}
|
||||
|
||||
toggleLeftOrbit(): void {
|
||||
this.leftOrbitOpen.update((current) => !current);
|
||||
}
|
||||
|
||||
toggleRightOrbit(): void {
|
||||
this.rightOrbitOpen.update((current) => !current);
|
||||
}
|
||||
|
||||
activateShortcut(shortcut: HubShortcut): void {
|
||||
if (shortcut.route) {
|
||||
void this.router.navigateByUrl(shortcut.route);
|
||||
return;
|
||||
}
|
||||
|
||||
if (shortcut.href) {
|
||||
window.open(shortcut.href, '_blank', 'noopener');
|
||||
}
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
this.authService.logout();
|
||||
void this.router.navigateByUrl('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.ai-page {
|
||||
min-height: 100vh;
|
||||
padding: 28px;
|
||||
background:
|
||||
radial-gradient(circle at top right, rgba(37, 99, 235, 0.12), transparent 22%),
|
||||
linear-gradient(180deg, #0f172a 0%, #111827 28%, #e2e8f0 28%, #f8fafc 100%);
|
||||
}
|
||||
|
||||
.ai-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 24px;
|
||||
max-width: 1240px;
|
||||
margin: 0 auto 28px;
|
||||
padding: 30px;
|
||||
border-radius: 32px;
|
||||
background: rgba(15, 23, 42, 0.78);
|
||||
color: #fff;
|
||||
box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
|
||||
}
|
||||
|
||||
.ai-header__badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 30px;
|
||||
padding: 0 12px;
|
||||
border-radius: 999px;
|
||||
background: rgba(59, 130, 246, 0.18);
|
||||
color: #bfdbfe;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.ai-header h1 {
|
||||
margin: 16px 0 0;
|
||||
font-size: clamp(2rem, 3.2vw, 3.4rem);
|
||||
line-height: 1.05;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.ai-header p {
|
||||
margin: 12px 0 0;
|
||||
max-width: 620px;
|
||||
color: #cbd5e1;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.ai-header__actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav-link,
|
||||
.new-chat-button,
|
||||
.send-button,
|
||||
.conversation-chip {
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.nav-link,
|
||||
.new-chat-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 44px;
|
||||
padding: 0 18px;
|
||||
border-radius: 999px;
|
||||
text-decoration: none;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.new-chat-button,
|
||||
.send-button {
|
||||
background: linear-gradient(135deg, #2563eb, #4f46e5);
|
||||
color: #fff;
|
||||
box-shadow: 0 16px 36px rgba(37, 99, 235, 0.22);
|
||||
}
|
||||
|
||||
.ai-layout {
|
||||
display: grid;
|
||||
grid-template-columns: 280px minmax(0, 1fr);
|
||||
gap: 24px;
|
||||
max-width: 1240px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.conversation-panel,
|
||||
.chat-panel {
|
||||
border: 1px solid rgba(148, 163, 184, 0.18);
|
||||
border-radius: 28px;
|
||||
background: rgba(255, 255, 255, 0.94);
|
||||
box-shadow: 0 24px 60px rgba(15, 23, 42, 0.08);
|
||||
}
|
||||
|
||||
.conversation-panel {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.conversation-panel h2 {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.conversation-panel p {
|
||||
margin: 10px 0 0;
|
||||
color: #64748b;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.conversation-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.conversation-chip,
|
||||
.conversation-empty {
|
||||
width: 100%;
|
||||
padding: 14px 16px;
|
||||
border-radius: 18px;
|
||||
background: #eff6ff;
|
||||
color: #1e3a8a;
|
||||
text-align: left;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.conversation-empty {
|
||||
margin-top: 20px;
|
||||
color: #64748b;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.chat-panel {
|
||||
display: grid;
|
||||
grid-template-rows: minmax(0, 1fr) auto;
|
||||
min-height: 680px;
|
||||
}
|
||||
|
||||
.message-stream {
|
||||
overflow-y: auto;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.message-card {
|
||||
max-width: 80%;
|
||||
margin-bottom: 16px;
|
||||
padding: 18px;
|
||||
border-radius: 24px;
|
||||
background: #f8fafc;
|
||||
box-shadow: 0 16px 34px rgba(15, 23, 42, 0.06);
|
||||
}
|
||||
|
||||
.message-card--user {
|
||||
margin-left: auto;
|
||||
background: linear-gradient(135deg, #dbeafe, #eff6ff);
|
||||
}
|
||||
|
||||
.message-card--error {
|
||||
background: linear-gradient(135deg, #fee2e2, #fef2f2);
|
||||
}
|
||||
|
||||
.message-card__meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
color: #64748b;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 800;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.message-card__content {
|
||||
margin: 12px 0 0;
|
||||
color: #0f172a;
|
||||
white-space: pre-wrap;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.message-card__sources {
|
||||
margin: 14px 0 0;
|
||||
padding-left: 16px;
|
||||
color: #475569;
|
||||
}
|
||||
|
||||
.message-card__sources li + li {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.message-loading {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 42px;
|
||||
padding: 0 16px;
|
||||
border-radius: 999px;
|
||||
background: #eff6ff;
|
||||
color: #1d4ed8;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.chat-composer {
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
padding: 22px 24px 24px;
|
||||
border-top: 1px solid rgba(226, 232, 240, 0.8);
|
||||
}
|
||||
|
||||
.chat-composer textarea {
|
||||
width: 100%;
|
||||
min-height: 120px;
|
||||
padding: 16px 18px;
|
||||
border: 1px solid rgba(148, 163, 184, 0.32);
|
||||
border-radius: 22px;
|
||||
resize: vertical;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.send-button {
|
||||
justify-self: end;
|
||||
min-height: 46px;
|
||||
padding: 0 22px;
|
||||
border-radius: 999px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.send-button:disabled {
|
||||
opacity: 0.7;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
@media (max-width: 980px) {
|
||||
.ai-layout {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.ai-page {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.ai-header {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ai-header__actions {
|
||||
width: 100%;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.message-card {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<div class="ai-page">
|
||||
<header class="ai-header">
|
||||
<div>
|
||||
<span class="ai-header__badge">{{ badge }}</span>
|
||||
<h1>{{ appName }}</h1>
|
||||
<p>Assistente conversacional para apoio à navegação e aos conteúdos da área de formação.</p>
|
||||
</div>
|
||||
|
||||
<div class="ai-header__actions">
|
||||
<a routerLink="/pagina-principal" class="nav-link">Pagina principal</a>
|
||||
<button type="button" class="new-chat-button" (click)="newChat()">Nova conversa</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="ai-layout">
|
||||
<aside class="conversation-panel">
|
||||
<h2>Conversas recentes</h2>
|
||||
<p>Os últimos prompts enviados ficam resumidos aqui.</p>
|
||||
|
||||
<div class="conversation-list" *ngIf="conversations.length; else noConversations">
|
||||
<button type="button" class="conversation-chip" *ngFor="let conversation of conversations">
|
||||
{{ conversation }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<ng-template #noConversations>
|
||||
<div class="conversation-empty">Sem histórico recente.</div>
|
||||
</ng-template>
|
||||
</aside>
|
||||
|
||||
<div class="chat-panel">
|
||||
<div #scrollContainer class="message-stream">
|
||||
<article
|
||||
*ngFor="let message of messages; trackBy: trackByMessage"
|
||||
class="message-card"
|
||||
[class.message-card--user]="message.role === 'user'"
|
||||
[class.message-card--error]="message.isError"
|
||||
>
|
||||
<div class="message-card__meta">
|
||||
<span>{{ message.role === 'user' ? 'Utilizador' : 'Vitoria AI' }}</span>
|
||||
<span>{{ message.createdAt | date:'HH:mm' }}</span>
|
||||
</div>
|
||||
|
||||
<p class="message-card__content">{{ message.content }}</p>
|
||||
|
||||
<ul class="message-card__sources" *ngIf="message.sources?.length">
|
||||
<li *ngFor="let source of message.sources">
|
||||
{{ source.nome_pdf }} · {{ source.categoria }} · Chunk {{ source.chunk_id }}
|
||||
</li>
|
||||
</ul>
|
||||
</article>
|
||||
|
||||
<div class="message-loading" *ngIf="isLoading">A gerar resposta...</div>
|
||||
</div>
|
||||
|
||||
<div class="chat-composer">
|
||||
<textarea
|
||||
[(ngModel)]="prompt"
|
||||
(keydown)="handleKeyDown($event)"
|
||||
placeholder="Escreve a tua pergunta..."
|
||||
rows="4"
|
||||
></textarea>
|
||||
|
||||
<button type="button" class="send-button" (click)="send()" [disabled]="isLoading || !prompt.trim()">
|
||||
{{ isLoading ? 'A aguardar...' : 'Enviar' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
@@ -0,0 +1,157 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { Component, ElementRef, ViewChild, inject } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { finalize } from 'rxjs';
|
||||
import { ChatMessage, VitoriaAiService } from './vitoria-ai.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-vitoria-ai-page',
|
||||
standalone: true,
|
||||
imports: [CommonModule, FormsModule, RouterLink],
|
||||
templateUrl: './vitoria-ai-page.html',
|
||||
styleUrl: './vitoria-ai-page.css'
|
||||
})
|
||||
export class VitoriaAiPageComponent {
|
||||
@ViewChild('scrollContainer') private scrollContainer?: ElementRef<HTMLDivElement>;
|
||||
|
||||
private readonly chatService = inject(VitoriaAiService);
|
||||
|
||||
readonly appName = 'Vitoria AI';
|
||||
readonly badge = 'Beta Release';
|
||||
|
||||
prompt = '';
|
||||
isLoading = false;
|
||||
conversations: string[] = [];
|
||||
|
||||
messages: ChatMessage[] = [
|
||||
{
|
||||
id: crypto.randomUUID(),
|
||||
role: 'assistant',
|
||||
content: 'Ola. Sou a Vitoria AI, uma assistente virtual para a area da formacao. Em que posso ajudar?',
|
||||
createdAt: new Date()
|
||||
}
|
||||
];
|
||||
|
||||
newChat(): void {
|
||||
this.prompt = '';
|
||||
this.isLoading = false;
|
||||
this.messages = [
|
||||
{
|
||||
id: crypto.randomUUID(),
|
||||
role: 'assistant',
|
||||
content: 'Nova conversa iniciada. Em que posso ajudar?',
|
||||
createdAt: new Date()
|
||||
}
|
||||
];
|
||||
this.scrollToBottom();
|
||||
}
|
||||
|
||||
send(): void {
|
||||
const content = this.prompt.trim();
|
||||
if (!content || this.isLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
const userMessage: ChatMessage = {
|
||||
id: crypto.randomUUID(),
|
||||
role: 'user',
|
||||
content,
|
||||
createdAt: new Date()
|
||||
};
|
||||
|
||||
this.messages = [...this.messages, userMessage];
|
||||
this.prompt = '';
|
||||
this.isLoading = true;
|
||||
this.trackConversation(content);
|
||||
this.scrollToBottom();
|
||||
|
||||
this.chatService
|
||||
.sendMessage(
|
||||
content,
|
||||
this.messages.map(({ role, content: messageContent, createdAt }) => ({
|
||||
role,
|
||||
content: messageContent,
|
||||
createdAt
|
||||
}))
|
||||
)
|
||||
.pipe(finalize(() => (this.isLoading = false)))
|
||||
.subscribe({
|
||||
next: (reply) => {
|
||||
const assistantMessage: ChatMessage = {
|
||||
id: crypto.randomUUID(),
|
||||
role: 'assistant',
|
||||
content: reply.resposta || 'Sem resposta do servico.',
|
||||
createdAt: new Date(),
|
||||
sources: reply.fontes ?? []
|
||||
};
|
||||
|
||||
this.messages = [...this.messages, assistantMessage];
|
||||
this.scrollToBottom();
|
||||
},
|
||||
error: (error: unknown) => {
|
||||
const errorMessage: ChatMessage = {
|
||||
id: crypto.randomUUID(),
|
||||
role: 'assistant',
|
||||
content: this.getErrorMessage(error),
|
||||
createdAt: new Date(),
|
||||
isError: true
|
||||
};
|
||||
|
||||
this.messages = [...this.messages, errorMessage];
|
||||
this.scrollToBottom();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handleKeyDown(event: KeyboardEvent): void {
|
||||
if (event.key === 'Enter' && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
this.send();
|
||||
}
|
||||
}
|
||||
|
||||
trackByMessage(_: number, message: ChatMessage): string {
|
||||
return message.id;
|
||||
}
|
||||
|
||||
private trackConversation(content: string): void {
|
||||
const normalized = content.slice(0, 60);
|
||||
this.conversations = [normalized, ...this.conversations.filter((item) => item !== normalized)].slice(0, 6);
|
||||
}
|
||||
|
||||
private scrollToBottom(): void {
|
||||
queueMicrotask(() => {
|
||||
const native = this.scrollContainer?.nativeElement;
|
||||
if (native) {
|
||||
native.scrollTop = native.scrollHeight;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getErrorMessage(error: unknown): string {
|
||||
if (error && typeof error === 'object' && 'name' in error && error.name === 'TimeoutError') {
|
||||
return 'O backend demorou demasiado tempo a responder. Verifica a latencia do modelo e do endpoint Python.';
|
||||
}
|
||||
|
||||
if (error instanceof HttpErrorResponse) {
|
||||
const detail =
|
||||
typeof error.error?.detail === 'string'
|
||||
? error.error.detail
|
||||
: typeof error.error?.message === 'string'
|
||||
? error.error.message
|
||||
: typeof error.error === 'string'
|
||||
? error.error
|
||||
: '';
|
||||
|
||||
if (error.status === 0) {
|
||||
return 'Nao foi possivel ligar ao backend da Vitoria AI. Confirma que o servico Python esta em execucao e acessivel para este servidor.';
|
||||
}
|
||||
|
||||
return detail ? `Erro do backend (${error.status}): ${detail}` : `Erro do backend (${error.status}).`;
|
||||
}
|
||||
|
||||
return 'O pedido falhou por um erro inesperado ao comunicar com o backend.';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { map, Observable, timeout } from 'rxjs';
|
||||
|
||||
export interface ChatSource {
|
||||
nome_pdf: string;
|
||||
categoria: string;
|
||||
chunk_id: number;
|
||||
score_distancia: number;
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
id: string;
|
||||
role: 'user' | 'assistant' | 'system';
|
||||
content: string;
|
||||
createdAt: Date;
|
||||
sources?: ChatSource[];
|
||||
isError?: boolean;
|
||||
}
|
||||
|
||||
interface AskQuestionRequest {
|
||||
pergunta: string;
|
||||
history?: Array<Pick<ChatMessage, 'role' | 'content' | 'createdAt'>>;
|
||||
}
|
||||
|
||||
interface RawAskQuestionResponse {
|
||||
pergunta?: string;
|
||||
resposta?: string;
|
||||
answer?: string;
|
||||
message?: string;
|
||||
fontes?: ChatSource[];
|
||||
sources?: ChatSource[];
|
||||
}
|
||||
|
||||
export interface AskQuestionResponse {
|
||||
pergunta?: string;
|
||||
resposta: string;
|
||||
fontes: ChatSource[];
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class VitoriaAiService {
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly endpoint = '/api/vitoria-ai/perguntar';
|
||||
private readonly requestTimeoutMs = 240000;
|
||||
|
||||
sendMessage(
|
||||
question: string,
|
||||
history: Array<Pick<ChatMessage, 'role' | 'content' | 'createdAt'>> = []
|
||||
): Observable<AskQuestionResponse> {
|
||||
const payload: AskQuestionRequest = { pergunta: question, history };
|
||||
|
||||
return this.http
|
||||
.post<RawAskQuestionResponse>(this.endpoint, payload)
|
||||
.pipe(
|
||||
map((response) => ({
|
||||
pergunta: response.pergunta ?? question,
|
||||
resposta: response.resposta ?? response.answer ?? response.message ?? '',
|
||||
fontes: response.fontes ?? response.sources ?? []
|
||||
}))
|
||||
)
|
||||
.pipe(timeout(this.requestTimeoutMs));
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
|
||||
@import 'tailwindcss';
|
||||
@source "./app/**/*.{html,ts}";
|
||||
|
||||
Reference in New Issue
Block a user