Add more user-specific charts (#1991)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -1,11 +1,99 @@
|
||||
<div class="user-stats-container">
|
||||
<div class="charts-container">
|
||||
<div class="chart-card">
|
||||
<app-reading-session-heatmap [initialYear]="currentYear" [userName]="userName"></app-reading-session-heatmap>
|
||||
</div>
|
||||
|
||||
<div class="chart-card">
|
||||
<app-reading-session-timeline [initialYear]="currentYear" [userName]="userName"></app-reading-session-timeline>
|
||||
<div class="header-section">
|
||||
<div class="header-content">
|
||||
<div class="greeting">
|
||||
<i class="pi pi-chart-line"></i>
|
||||
<h2>{{ userName }}'s Reading Statistics</h2>
|
||||
</div>
|
||||
<button class="config-toggle-btn" (click)="toggleConfigPanel()">
|
||||
<i class="pi pi-cog"></i>
|
||||
<span>Customize Layout</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-dialog
|
||||
[(visible)]="showConfigPanel"
|
||||
[modal]="true"
|
||||
[draggable]="false"
|
||||
[resizable]="false"
|
||||
[style]="{width: '600px', maxWidth: '90vw'}"
|
||||
styleClass="config-dialog"
|
||||
header="Chart Configuration">
|
||||
|
||||
<div class="config-dialog-content">
|
||||
<div class="config-list" cdkDropList (cdkDropListDropped)="drop($event)">
|
||||
@for (chart of charts; track chart.id) {
|
||||
<div class="config-item" cdkDrag>
|
||||
<div class="drag-handle" cdkDragHandle>
|
||||
<i class="pi pi-bars"></i>
|
||||
</div>
|
||||
<span class="chart-title">{{ chart.title }}</span>
|
||||
<button
|
||||
class="visibility-toggle"
|
||||
(click)="toggleChart(chart.id)"
|
||||
[class.disabled]="!chart.enabled">
|
||||
<i [class]="chart.enabled ? 'pi pi-eye' : 'pi pi-eye-slash'"></i>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template pTemplate="footer">
|
||||
<p-button class="reset-btn" (click)="resetLayout()" severity="danger">
|
||||
<i class="pi pi-refresh"></i>
|
||||
<span>Reset Layout</span>
|
||||
</p-button>
|
||||
<p-button class="hide-all-btn" (click)="hideAllCharts()" severity="secondary">
|
||||
<i class="pi pi-eye-slash"></i>
|
||||
<span>Hide All</span>
|
||||
</p-button>
|
||||
<p-button class="show-all-btn" (click)="showAllCharts()" severity="secondary">
|
||||
<i class="pi pi-eye"></i>
|
||||
<span>Show All</span>
|
||||
</p-button>
|
||||
<p-button class="close-btn" (click)="toggleConfigPanel()" severity="secondary">
|
||||
<span>Close</span>
|
||||
</p-button>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
|
||||
<!-- Charts Container -->
|
||||
<div class="charts-container" cdkDropList (cdkDropListDropped)="drop($event)">
|
||||
@for (chart of visibleCharts; track chart.id) {
|
||||
<div class="chart-card" [class]="chart.sizeClass" cdkDrag>
|
||||
<div class="chart-drag-handle" cdkDragHandle>
|
||||
<i class="pi pi-arrows-alt"></i>
|
||||
</div>
|
||||
|
||||
@switch (chart.id) {
|
||||
@case ('heatmap') {
|
||||
<app-reading-session-heatmap [initialYear]="currentYear"></app-reading-session-heatmap>
|
||||
}
|
||||
@case ('timeline') {
|
||||
<app-reading-session-timeline [initialYear]="currentYear"></app-reading-session-timeline>
|
||||
}
|
||||
@case ('genre-stats') {
|
||||
<app-genre-stats-chart></app-genre-stats-chart>
|
||||
}
|
||||
@case ('completion-timeline') {
|
||||
<app-completion-timeline-chart [initialYear]="currentYear"></app-completion-timeline-chart>
|
||||
}
|
||||
@case ('favorite-days') {
|
||||
<app-favorite-days-chart></app-favorite-days-chart>
|
||||
}
|
||||
@case ('peak-hours') {
|
||||
<app-peak-hours-chart></app-peak-hours-chart>
|
||||
}
|
||||
@case ('reading-dna') {
|
||||
<app-reading-dna-chart></app-reading-dna-chart>
|
||||
}
|
||||
@case ('reading-habits') {
|
||||
<app-reading-habits-chart></app-reading-habits-chart>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+317
-11
@@ -9,16 +9,12 @@
|
||||
.header-section {
|
||||
background: var(--card-background);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
padding: 1rem;
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 2rem;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
transition: all 0.3s ease;
|
||||
width: fit-content;
|
||||
max-width: 100%;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(255, 255, 255, 0.2);
|
||||
@@ -27,16 +23,19 @@
|
||||
|
||||
.header-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
gap: 2rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.greeting {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
|
||||
i {
|
||||
font-size: 1.5rem;
|
||||
@@ -51,12 +50,147 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.config-toggle-btn {
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.config-header {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.config-toggle-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 1.25rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
color: var(--text-color);
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
font-size: 0.9rem;
|
||||
white-space: nowrap;
|
||||
|
||||
&:hover {
|
||||
background: var(--p-primary-color);
|
||||
color: white;
|
||||
border-color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
// Dialog styles
|
||||
::ng-deep .config-dialog {
|
||||
.p-dialog-header {
|
||||
border-bottom: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.p-dialog-content {
|
||||
background: var(--card-background);
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.p-dialog-footer {
|
||||
border-top: 1px solid var(--p-content-border-color);
|
||||
padding: 1rem 1.5rem;
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
justify-content: flex-end;
|
||||
|
||||
.reset-btn {
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.hide-all-btn,
|
||||
.show-all-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.config-dialog-content {
|
||||
.config-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.config-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 0.5rem 1.25rem;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
cursor: move;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
.drag-handle {
|
||||
cursor: grab;
|
||||
color: var(--text-color-secondary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
&:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
}
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
color: var(--text-color);
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.visibility-toggle {
|
||||
padding: 0.5rem;
|
||||
background: transparent;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
color: var(--p-primary-color);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--p-primary-color);
|
||||
color: white;
|
||||
border-color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
color: var(--text-color-secondary);
|
||||
opacity: 0.5;
|
||||
|
||||
&:hover {
|
||||
background: transparent;
|
||||
color: var(--text-color-secondary);
|
||||
border-color: var(--p-content-border-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.charts-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(12, 1fr);
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
@@ -67,11 +201,77 @@
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(255, 255, 255, 0.2);
|
||||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
||||
|
||||
.chart-drag-handle {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.chart-drag-handle {
|
||||
position: absolute;
|
||||
top: 0.5rem;
|
||||
right: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
border-radius: 6px;
|
||||
cursor: grab;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease;
|
||||
z-index: 10;
|
||||
color: var(--text-color);
|
||||
|
||||
&:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
&.chart-small-square {
|
||||
grid-column: span 3;
|
||||
}
|
||||
|
||||
&.chart-small {
|
||||
grid-column: span 4;
|
||||
}
|
||||
|
||||
&.chart-medium {
|
||||
grid-column: span 6;
|
||||
}
|
||||
|
||||
&.chart-large {
|
||||
grid-column: span 8;
|
||||
}
|
||||
|
||||
&.chart-wide {
|
||||
grid-column: span 9;
|
||||
}
|
||||
|
||||
&.chart-full {
|
||||
grid-column: span 12;
|
||||
}
|
||||
}
|
||||
|
||||
.cdk-drag-preview {
|
||||
opacity: 0.8;
|
||||
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.cdk-drag-placeholder {
|
||||
opacity: 0.3;
|
||||
border: 2px dashed var(--p-primary-color);
|
||||
}
|
||||
|
||||
.cdk-drag-animating {
|
||||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
@@ -79,10 +279,60 @@
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.config-toggle-btn {
|
||||
span {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .config-dialog {
|
||||
.p-dialog-content {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.p_dialog_footer {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
.reset-btn {
|
||||
margin-right: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.config-panel {
|
||||
padding: 1rem;
|
||||
|
||||
.config-panel-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 1rem;
|
||||
|
||||
.reset-btn {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.header-section {
|
||||
padding: 1rem;
|
||||
|
||||
.header-content {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
position: static;
|
||||
}
|
||||
|
||||
.greeting {
|
||||
position: static;
|
||||
transform: none;
|
||||
|
||||
i {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
@@ -94,8 +344,36 @@
|
||||
}
|
||||
}
|
||||
|
||||
.config-toggle-btn {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
margin-left: 0;
|
||||
|
||||
span {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
|
||||
.charts-container {
|
||||
grid-template-columns: repeat(6, 1fr);
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
padding: 1rem;
|
||||
|
||||
.chart-drag-handle {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
&.chart-small-square,
|
||||
&.chart-small,
|
||||
&.chart-medium,
|
||||
&.chart-large,
|
||||
&.chart-wide,
|
||||
&.chart-full {
|
||||
grid-column: span 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +382,20 @@
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.config-toggle-btn {
|
||||
padding: 0.5rem 0.75rem;
|
||||
}
|
||||
|
||||
::ng-deep .config-dialog {
|
||||
.p-dialog-content {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.config-panel {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.header-section {
|
||||
padding: 0.75rem;
|
||||
|
||||
@@ -121,7 +413,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
.charts-container {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
padding: 0.75rem;
|
||||
|
||||
&.chart-small-square,
|
||||
&.chart-small,
|
||||
&.chart-medium,
|
||||
&.chart-large,
|
||||
&.chart-wide,
|
||||
&.chart-full {
|
||||
grid-column: span 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,38 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {Subject} from 'rxjs';
|
||||
import {CdkDragDrop, DragDropModule} from '@angular/cdk/drag-drop';
|
||||
import {DialogModule} from 'primeng/dialog';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {ReadingSessionHeatmapComponent} from '../reading-session-heatmap/reading-session-heatmap.component';
|
||||
import {ReadingSessionTimelineComponent} from '../reading-session-timeline/reading-session-timeline.component';
|
||||
import {GenreStatsChartComponent} from '../genre-stats-chart/genre-stats-chart.component';
|
||||
import {CompletionTimelineChartComponent} from '../completion-timeline-chart/completion-timeline-chart.component';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
|
||||
interface UserChartConfig {
|
||||
id: string;
|
||||
component: any;
|
||||
enabled: boolean;
|
||||
order: number;
|
||||
}
|
||||
import {FavoriteDaysChartComponent} from '../favorite-days-chart/favorite-days-chart.component';
|
||||
import {PeakHoursChartComponent} from '../peak-hours-chart/peak-hours-chart.component';
|
||||
import {ReadingDNAChartComponent} from '../reading-dna-chart/reading-dna-chart.component';
|
||||
import {ReadingHabitsChartComponent} from '../reading-habits-chart/reading-habits-chart.component';
|
||||
import {UserChartConfig, UserChartConfigService} from '../../service/user-chart-config.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-stats',
|
||||
standalone: true,
|
||||
imports: [CommonModule, ReadingSessionHeatmapComponent, ReadingSessionTimelineComponent],
|
||||
imports: [
|
||||
CommonModule,
|
||||
DragDropModule,
|
||||
DialogModule,
|
||||
ButtonModule,
|
||||
ReadingSessionHeatmapComponent,
|
||||
ReadingSessionTimelineComponent,
|
||||
GenreStatsChartComponent,
|
||||
CompletionTimelineChartComponent,
|
||||
FavoriteDaysChartComponent,
|
||||
PeakHoursChartComponent,
|
||||
ReadingDNAChartComponent,
|
||||
ReadingHabitsChartComponent
|
||||
],
|
||||
templateUrl: './user-stats.component.html',
|
||||
styleUrls: ['./user-stats.component.scss']
|
||||
})
|
||||
@@ -24,10 +40,22 @@ export class UserStatsComponent implements OnInit, OnDestroy {
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
private userService = inject(UserService);
|
||||
private chartConfigService = inject(UserChartConfigService);
|
||||
|
||||
public currentYear = new Date().getFullYear();
|
||||
public userName: string = '';
|
||||
public showConfigPanel = false;
|
||||
public charts: UserChartConfig[] = [];
|
||||
public visibleCharts: UserChartConfig[] = [];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.chartConfigService.charts$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(charts => {
|
||||
this.charts = charts;
|
||||
this.visibleCharts = this.chartConfigService.getVisibleCharts();
|
||||
});
|
||||
|
||||
this.userService.userState$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(state => {
|
||||
@@ -41,4 +69,36 @@ export class UserStatsComponent implements OnInit, OnDestroy {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
toggleChart(chartId: string): void {
|
||||
this.chartConfigService.toggleChart(chartId);
|
||||
}
|
||||
|
||||
drop(event: CdkDragDrop<UserChartConfig[]>): void {
|
||||
this.chartConfigService.reorderCharts(event.previousIndex, event.currentIndex);
|
||||
}
|
||||
|
||||
toggleConfigPanel(): void {
|
||||
this.showConfigPanel = !this.showConfigPanel;
|
||||
}
|
||||
|
||||
resetLayout(): void {
|
||||
this.chartConfigService.resetLayout();
|
||||
}
|
||||
|
||||
hideAllCharts(): void {
|
||||
this.charts.forEach(chart => {
|
||||
if (chart.enabled) {
|
||||
this.chartConfigService.toggleChart(chart.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
showAllCharts(): void {
|
||||
this.charts.forEach(chart => {
|
||||
if (!chart.enabled) {
|
||||
this.chartConfigService.toggleChart(chart.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user