This commit significantly expands the application's routing, navigation, and administrative capabilities. It introduces several new functional modules and refines the core layout for a more professional, dashboard-oriented experience. - **Routing & Navigation**: - Added routes for `wallboard`, `call-center`, `call-center/calls`, and `chat-questions`. - Updated `SidebarComponent` to include all new navigation items. - Enhanced `LayoutComponent` with dynamic navigation based on user roles (admin vs. user). - **New Administrative Pages**: - `WallboardPage`: Implements a real-time KPI dashboard with call activity trends and outcome distributions. - `CallCenterPage`: Provides a symbolic interface for managing call center connectivity and synchronization. - `CallCenterCallsPage`: Implements a call history retrieval interface with filtering capabilities. - `ChatQuestionsPage`: Adds a module for reviewing user questions from web and mobile channels. - **Core Infrastructure & Refinement**: - Updated `AppConfig` to include an `APP_INITIALIZER` for validating user identity via `AuthService` on startup. - Refined `HomeComponent` layout to a "Claude-style" continuous chat column. - Implemented global themed scrollbars and integrated the 'Lahze' font family. - Added `proxy.conf.json` and updated `angular.json` to support local backend development. - **Documentation**: - Added comprehensive API handoff guides for frontend-backend connection and MVP API catalog.
147 lines
4.6 KiB
TypeScript
147 lines
4.6 KiB
TypeScript
import { ChangeDetectionStrategy, Component, computed, inject, signal, OnInit } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { forkJoin } from 'rxjs';
|
|
import { ReportsService } from '../../services/reports/reports.service';
|
|
import { ReportsView } from '../../services/reports/reports.types';
|
|
import { BarChartComponent, BarChartItem } from '../../shared/ui/charts/bar-chart.component';
|
|
import { DoughnutChartComponent, DoughnutSegment } from '../../shared/ui/charts/doughnut-chart.component';
|
|
import { LineChartComponent, LinePoint } from '../../shared/ui/charts/line-chart.component';
|
|
import { CHART_PALETTE } from '../../shared/utils/chart-palette';
|
|
import { formatCount, formatDecimal, formatPercent } from '../../shared/utils/format.util';
|
|
|
|
type ReportTabId = 'questions' | 'performance';
|
|
|
|
@Component({
|
|
selector: 'app-reports',
|
|
standalone: true,
|
|
imports: [CommonModule, BarChartComponent, DoughnutChartComponent, LineChartComponent],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
templateUrl: './reports.page.html',
|
|
styleUrl: './reports.page.css',
|
|
})
|
|
export class ReportsPage implements OnInit {
|
|
private readonly reports = inject(ReportsService);
|
|
|
|
readonly tabs: { id: ReportTabId; label: string; icon: string }[] = [
|
|
{
|
|
id: 'questions',
|
|
label: 'پرسشهای کاربران',
|
|
icon: 'M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z',
|
|
},
|
|
{
|
|
id: 'performance',
|
|
label: 'عملکرد و روند',
|
|
icon: 'M22 12h-4l-3 9L9 3l-3 9H2',
|
|
},
|
|
];
|
|
|
|
readonly activeTab = signal<ReportTabId>('questions');
|
|
|
|
readonly loading = signal(true);
|
|
readonly loadError = signal(false);
|
|
readonly data = signal<ReportsView | null>(null);
|
|
|
|
readonly summary = computed(() => this.data()?.summary ?? null);
|
|
readonly ai = computed(() => this.data()?.aiPerformance ?? null);
|
|
|
|
readonly topQuestions = computed<BarChartItem[]>(() => {
|
|
const questions = this.data()?.topQuestions ?? [];
|
|
return questions.map((question, index) => ({
|
|
label: question.text,
|
|
value: question.count,
|
|
color: CHART_PALETTE[index % CHART_PALETTE.length],
|
|
hint: `دسته: ${question.category}`,
|
|
}));
|
|
});
|
|
|
|
readonly categories = computed<DoughnutSegment[]>(() => {
|
|
const shares = this.data()?.categories ?? [];
|
|
return shares.map((share, index) => ({
|
|
label: share.category,
|
|
value: share.count,
|
|
color: CHART_PALETTE[index % CHART_PALETTE.length],
|
|
}));
|
|
});
|
|
|
|
readonly trend = computed<LinePoint[]>(() => {
|
|
const points = this.data()?.trend ?? [];
|
|
return points.map((point) => ({ label: point.label, value: point.count }));
|
|
});
|
|
|
|
readonly channels = computed<BarChartItem[]>(() => {
|
|
const channels = this.data()?.aiPerformance.channels ?? [];
|
|
return channels.map((channel, index) => ({
|
|
label: channel.label,
|
|
value: channel.count,
|
|
color: CHART_PALETTE[index % CHART_PALETTE.length],
|
|
}));
|
|
});
|
|
|
|
readonly aiAnswerRate = computed(() => {
|
|
const summary = this.summary();
|
|
if (!summary || summary.totalQuestions === 0) return 0;
|
|
return (summary.aiAnswered / summary.totalQuestions) * 100;
|
|
});
|
|
|
|
readonly faqBasedRate = computed(() => {
|
|
const ai = this.ai();
|
|
if (!ai || ai.totalResponses === 0) return 0;
|
|
return (ai.faqBasedResponses / ai.totalResponses) * 100;
|
|
});
|
|
|
|
readonly trendTotal = computed(() => this.trend().reduce((sum, point) => sum + point.value, 0));
|
|
|
|
readonly trendPeak = computed(() => {
|
|
const points = this.trend();
|
|
if (points.length === 0) return null;
|
|
return points.reduce((peak, point) => (point.value > peak.value ? point : peak), points[0]);
|
|
});
|
|
|
|
ngOnInit(): void {
|
|
this.load();
|
|
}
|
|
|
|
selectTab(id: ReportTabId): void {
|
|
this.activeTab.set(id);
|
|
}
|
|
|
|
load(): void {
|
|
this.loading.set(true);
|
|
this.loadError.set(false);
|
|
|
|
forkJoin({
|
|
topQuestions: this.reports.getTopQuestions(),
|
|
summary: this.reports.getQuestionSummary(),
|
|
categories: this.reports.getCategoryDistribution(),
|
|
trend: this.reports.getUsageTrend(),
|
|
aiPerformance: this.reports.getAiPerformance(),
|
|
}).subscribe({
|
|
next: (data) => {
|
|
this.data.set(data);
|
|
this.loading.set(false);
|
|
},
|
|
error: () => {
|
|
this.data.set(null);
|
|
this.loading.set(false);
|
|
this.loadError.set(true);
|
|
},
|
|
});
|
|
}
|
|
|
|
retry(): void {
|
|
this.load();
|
|
}
|
|
|
|
formatCount(value: number): string {
|
|
return formatCount(value);
|
|
}
|
|
|
|
formatDecimal(value: number): string {
|
|
return formatDecimal(value);
|
|
}
|
|
|
|
formatPercent(value: number): string {
|
|
return formatPercent(value);
|
|
}
|
|
}
|