build(ui): expand application shell and implement administrative dashboard pages

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.
This commit is contained in:
Peyman Honarjoo
2026-10-10 00:20:00 +03:30
parent 0b5a882ecb
commit ff7fcbc4bb
71 changed files with 9148 additions and 780 deletions
@@ -0,0 +1,87 @@
import {
CallActivityPoint,
CallOutcomeShare,
HourlyCallPoint,
WallboardKpis,
} from './wallboard.types';
const ACTIVITY_DAYS = 14;
const HOUR_BUCKETS: { hour: number; span: number }[] = [
{ hour: 8, span: 2 },
{ hour: 10, span: 2 },
{ hour: 12, span: 2 },
{ hour: 14, span: 2 },
{ hour: 16, span: 2 },
{ hour: 18, span: 2 },
{ hour: 20, span: 2 },
];
/** Deterministic pseudo-random source so mock data stays stable across reloads and tests. */
function seededNoise(seed: number): number {
const value = Math.sin(seed * 12.9898) * 43758.5453;
return Math.abs(value - Math.floor(value));
}
function buildActivity(): CallActivityPoint[] {
const points: CallActivityPoint[] = [];
const today = new Date();
for (let offset = ACTIVITY_DAYS - 1; offset >= 0; offset--) {
const date = new Date(today);
date.setDate(today.getDate() - offset);
const weekday = date.getDay();
const isWeekend = weekday === 4 || weekday === 5;
const noise = seededNoise(offset + 3);
// Lower weekend volume with a mild upward drift toward today.
const base = isWeekend ? 620 : 980;
const drift = (ACTIVITY_DAYS - offset) * 6;
points.push({
label: date.toLocaleDateString('fa-IR', { day: 'numeric', month: 'long' }),
count: Math.round(base + noise * 180 + drift),
});
}
return points;
}
function buildHourly(): HourlyCallPoint[] {
return HOUR_BUCKETS.map((bucket, index) => {
const noise = seededNoise(index + 11);
// Mid-day and late-afternoon peaks, quiet early morning.
const peak = bucket.hour <= 12 ? 1.35 : bucket.hour >= 18 ? 1.5 : 1.15;
return {
label: `${toPersianHour(bucket.hour)}–${toPersianHour(bucket.hour + bucket.span)}`,
count: Math.round((520 + noise * 260) * peak),
};
});
}
function toPersianHour(hour: number): string {
const persianDigits = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
return String(hour)
.padStart(2, '0')
.replace(/\d/g, (digit) => persianDigits[Number(digit)]);
}
export const MOCK_WALLBOARD_KPIS: WallboardKpis = {
totalCalls: 12846,
aiCalls: 8412,
avgAiTalkSeconds: 142,
successfulAiCalls: 7156,
transferredToAgentCalls: 1256,
periodLabel: 'امروز',
};
export const MOCK_CALL_OUTCOMES: CallOutcomeShare[] = [
{ id: 'ai', label: 'پاسخ‌گویی هوش مصنوعی', value: 7156 },
{ id: 'transfer', label: 'انتقال به کارشناس پس از هوش مصنوعی', value: 1256 },
{ id: 'direct-agent', label: 'تماس مستقیم با کارشناس', value: 4434 },
];
export const MOCK_CALL_ACTIVITY: CallActivityPoint[] = buildActivity();
export const MOCK_HOURLY_CALLS: HourlyCallPoint[] = buildHourly();
@@ -0,0 +1,77 @@
import { TestBed } from '@angular/core/testing';
import { provideZonelessChangeDetection } from '@angular/core';
import { provideAnimations } from '@angular/platform-browser/animations';
import { provideHttpClient } from '@angular/common/http';
import { provideRouter } from '@angular/router';
import { TOAST_CONFIG, DefaultGlobalConfig } from 'ngx-toastr';
import { firstValueFrom } from 'rxjs';
import { WallboardService } from './wallboard.service';
describe('WallboardService', () => {
let service: WallboardService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideHttpClient(),
provideRouter([]),
provideAnimations(),
{ provide: TOAST_CONFIG, useValue: { default: DefaultGlobalConfig, config: {} } },
],
});
service = TestBed.inject(WallboardService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
it('returns KPIs with a consistent AI breakdown', async () => {
const kpis = await firstValueFrom(service.getKpis());
expect(kpis.totalCalls).toBeGreaterThan(0);
expect(kpis.aiCalls).toBeGreaterThan(0);
expect(kpis.aiCalls).toBeLessThanOrEqual(kpis.totalCalls);
expect(kpis.successfulAiCalls + kpis.transferredToAgentCalls).toBe(kpis.aiCalls);
expect(kpis.avgAiTalkSeconds).toBeGreaterThan(0);
});
it('returns outcome shares summing up to the total call count', async () => {
const outcomes = await firstValueFrom(service.getOutcomes());
const kpis = await firstValueFrom(service.getKpis());
const total = outcomes.reduce((sum, outcome) => sum + outcome.value, 0);
expect(outcomes.length).toBeGreaterThan(0);
expect(total).toBe(kpis.totalCalls);
});
it('returns a 14 point activity trend with valid labels', async () => {
const activity = await firstValueFrom(service.getActivity());
expect(activity).toHaveLength(14);
activity.forEach((point) => {
expect(point.label).toBeTruthy();
expect(point.count).toBeGreaterThan(0);
});
});
it('returns hourly buckets covering the whole working day', async () => {
const hourly = await firstValueFrom(service.getHourlyDistribution());
expect(hourly.length).toBeGreaterThan(0);
hourly.forEach((bucket) => {
expect(bucket.label).toMatch(/–/);
expect(bucket.count).toBeGreaterThan(0);
});
});
it('returns a complete overview combining every wallboard dataset', async () => {
const overview = await firstValueFrom(service.getOverview());
expect(overview.kpis.totalCalls).toBeGreaterThan(0);
expect(overview.outcomes.length).toBeGreaterThan(0);
expect(overview.activity).toHaveLength(14);
expect(overview.hourly.length).toBeGreaterThan(0);
});
});
@@ -0,0 +1,77 @@
import { Injectable, inject } from '@angular/core';
import { map, Observable, of } from 'rxjs';
import { HttpService } from '../http-request/http.service';
import {
CallActivityPoint,
CallOutcomeShare,
HourlyCallPoint,
WallboardKpis,
WallboardView,
} from './wallboard.types';
import {
MOCK_CALL_ACTIVITY,
MOCK_CALL_OUTCOMES,
MOCK_HOURLY_CALLS,
MOCK_WALLBOARD_KPIS,
} from './wallboard.mock';
/**
* Call center wallboard data source. The dashboard is read-only, so every
* endpoint is a plain GET that returns a ready-to-render view. While no
* wallboard endpoints exist on the backend, deterministic mock data keeps the
* dashboard fully explorable; flip `useMockData` to false (and align the
* endpoint paths) to consume the real API without touching the page.
*/
@Injectable({
providedIn: 'root',
})
export class WallboardService {
private readonly http = inject(HttpService);
/** Flip to false once the backend wallboard endpoints are deployed. */
private readonly useMockData = true;
getKpis(): Observable<WallboardKpis> {
return this.request<WallboardKpis>('wallboard/kpis', {}, MOCK_WALLBOARD_KPIS);
}
/** سهم روش‌های پاسخ‌گویی: هوش مصنوعی در مقابل کارشناس. */
getOutcomes(): Observable<CallOutcomeShare[]> {
return this.request<CallOutcomeShare[]>('wallboard/call-outcomes', {}, MOCK_CALL_OUTCOMES);
}
getActivity(days = 14): Observable<CallActivityPoint[]> {
return this.request<CallActivityPoint[]>(
'wallboard/call-activity',
{ days },
MOCK_CALL_ACTIVITY,
);
}
getHourlyDistribution(): Observable<HourlyCallPoint[]> {
return this.request<HourlyCallPoint[]>(
'wallboard/hourly-distribution',
{},
MOCK_HOURLY_CALLS,
);
}
getOverview(): Observable<WallboardView> {
return this.request<WallboardView>('wallboard/overview', {}, {
kpis: MOCK_WALLBOARD_KPIS,
outcomes: MOCK_CALL_OUTCOMES,
activity: MOCK_CALL_ACTIVITY,
hourly: MOCK_HOURLY_CALLS,
});
}
private request<T>(endpoint: string, params: Record<string, unknown>, fallback: T): Observable<T> {
if (this.useMockData) {
return of(fallback);
}
return this.http
.get<T>(endpoint, { params, skipToast: true, skipHasErrorCheck: true })
.pipe(map((response) => response.result));
}
}
@@ -0,0 +1,41 @@
/** KPI snapshot for the wallboard («والبورد») dashboard. */
export interface WallboardKpis {
/** کل تماس‌های دریافتی */
totalCalls: number;
/** تماس‌هایی که با هوش مصنوعی گفتگو شده‌اند */
aiCalls: number;
/** میانگین زمان صحبت کاربر با هوش مصنوعی (ثانیه) */
avgAiTalkSeconds: number;
/** تماس‌هایی که هوش مصنوعی با موفقیت به پایان رسانده است */
successfulAiCalls: number;
/** تماس‌هایی که پس از هوش مصنوعی به کارشناس transfer شده‌اند */
transferredToAgentCalls: number;
/** برچسب بازه زمانی گزارش */
periodLabel: string;
}
/** سهم هر روش پاسخ‌گویی از کل تماس‌ها (نمودار دایره‌ای هوش مصنوعی/کارشناس) */
export interface CallOutcomeShare {
id: string;
label: string;
value: number;
}
/** نقطه از روند فعالیت تماس‌ها در گذر زمان (نمودار خطی) */
export interface CallActivityPoint {
label: string;
count: number;
}
/** حجم تماس‌ها در هر بازه ساعتی (نمودار میله‌ای) */
export interface HourlyCallPoint {
label: string;
count: number;
}
export interface WallboardView {
kpis: WallboardKpis;
outcomes: CallOutcomeShare[];
activity: CallActivityPoint[];
hourly: HourlyCallPoint[];
}