Add more user-specific charts (#1991)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
+23
-3
@@ -3,18 +3,18 @@
|
||||
<div class="header-title">
|
||||
<h3>
|
||||
<i class="pi pi-clock timeline-title-icon"></i>
|
||||
{{ getTitle() }}
|
||||
Reading Session Timeline
|
||||
</h3>
|
||||
<p class="timeline-subtitle">Weekly overview of your reading sessions and patterns</p>
|
||||
</div>
|
||||
<div class="week-selector">
|
||||
<div class="week-info">
|
||||
<button type="button"
|
||||
class="week-nav-btn"
|
||||
(click)="changeWeek(-1)"
|
||||
title="Previous week">
|
||||
<i class="pi pi-chevron-left"></i>
|
||||
</button>
|
||||
<div class="week-info">
|
||||
<div class="week-display">
|
||||
<span class="week-label">Week {{ currentWeek }}</span>
|
||||
<span class="week-dates">{{ getWeekDateRange() }}</span>
|
||||
</div>
|
||||
@@ -25,6 +25,26 @@
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="filter-controls">
|
||||
<p-select
|
||||
[options]="yearOptions"
|
||||
[(ngModel)]="currentYear"
|
||||
(onChange)="onYearChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Year"
|
||||
[style]="{'min-width': '120px'}">
|
||||
</p-select>
|
||||
<p-select
|
||||
[options]="weekOptions"
|
||||
[(ngModel)]="currentWeek"
|
||||
(onChange)="onWeekChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Week"
|
||||
[style]="{'min-width': '120px'}">
|
||||
</p-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="timeline-content">
|
||||
|
||||
+173
-42
@@ -3,15 +3,13 @@
|
||||
}
|
||||
|
||||
.timeline-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
gap: 1rem;
|
||||
|
||||
.header-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
@@ -27,17 +25,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
.week-selector {
|
||||
.week-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
flex-shrink: 0;
|
||||
justify-self: center;
|
||||
|
||||
.week-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 6px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
padding: 0.6rem 0.6rem;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
@@ -60,26 +57,96 @@
|
||||
}
|
||||
}
|
||||
|
||||
.week-info {
|
||||
.week-display {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
min-width: 100px;
|
||||
min-width: 120px;
|
||||
|
||||
.week-label {
|
||||
font-size: 1.125rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
white-space: nowrap;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.week-dates {
|
||||
font-size: 0.8rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
white-space: nowrap;
|
||||
margin-top: 0.1rem;
|
||||
line-height: 1.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.filter-controls {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
justify-self: end;
|
||||
}
|
||||
}
|
||||
|
||||
.week-info-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
padding: 0.75rem;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
|
||||
.week-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 6px;
|
||||
padding: 0.6rem 6rem;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-color: rgba(255, 255, 255, 0.3);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.week-display {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
min-width: 150px;
|
||||
|
||||
.week-label {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.week-dates {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-secondary-color);
|
||||
white-space: nowrap;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.timeline-content {
|
||||
@@ -153,7 +220,7 @@
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
border-radius: 4px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
min-height: 40px;
|
||||
min-height: 35px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,29 +255,32 @@
|
||||
box-sizing: border-box;
|
||||
|
||||
&.book-type-epub, &.book-type-default {
|
||||
background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
|
||||
box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
|
||||
background: rgba(59, 130, 246, 0.8);
|
||||
border: 1px solid rgba(59, 130, 246, 1);
|
||||
box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 16px rgba(74, 144, 226, 0.5);
|
||||
box-shadow: 0 4px 8px rgba(59, 130, 246, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
&.book-type-pdf {
|
||||
background: linear-gradient(135deg, #e24a4a 0%, #bd3535 100%);
|
||||
box-shadow: 0 2px 8px rgba(226, 74, 74, 0.3);
|
||||
background: rgba(239, 68, 68, 0.8);
|
||||
border: 1px solid rgba(239, 68, 68, 1);
|
||||
box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 16px rgba(226, 74, 74, 0.5);
|
||||
box-shadow: 0 4px 8px rgba(239, 68, 68, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
&.book-type-cbx {
|
||||
background: linear-gradient(135deg, #e2b74a 0%, #bd9635 100%);
|
||||
box-shadow: 0 2px 8px rgba(226, 183, 74, 0.3);
|
||||
background: rgba(255, 193, 7, 0.8);
|
||||
border: 1px solid rgba(255, 193, 7, 1);
|
||||
box-shadow: 0 2px 4px rgba(255, 193, 7, 0.3);
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 16px rgba(226, 183, 74, 0.5);
|
||||
box-shadow: 0 4px 8px rgba(255, 193, 7, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +381,7 @@
|
||||
|
||||
i {
|
||||
font-size: 1.1rem;
|
||||
color: #4a90e2;
|
||||
color: rgba(239, 68, 68, 1);
|
||||
}
|
||||
|
||||
.tooltip-title {
|
||||
@@ -384,22 +454,77 @@
|
||||
|
||||
.timeline-title-icon {
|
||||
font-size: 1.5rem;
|
||||
color: var(--primary-color);
|
||||
color: rgba(239, 68, 68, 1);
|
||||
vertical-align: middle;
|
||||
margin-right: 0.25em;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.timeline-header {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.75rem;
|
||||
|
||||
.header-title {
|
||||
grid-column: 1;
|
||||
}
|
||||
|
||||
.week-info {
|
||||
grid-column: 1;
|
||||
justify-self: stretch;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.filter-controls {
|
||||
grid-column: 1;
|
||||
justify-self: stretch;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.5rem;
|
||||
|
||||
::ng-deep p-select {
|
||||
width: 100%;
|
||||
|
||||
.p-select {
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.timeline-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
.header-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.week-selector {
|
||||
justify-content: center;
|
||||
margin-top: 0.5rem;
|
||||
.timeline-subtitle {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
|
||||
.week-info {
|
||||
min-width: 120px;
|
||||
.week-info {
|
||||
padding: 0.6rem 0.6rem;
|
||||
|
||||
.week-display {
|
||||
min-width: 100px;
|
||||
|
||||
.week-label {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.week-dates {
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
}
|
||||
|
||||
.week-nav-btn {
|
||||
padding: 0.35rem 0.5rem;
|
||||
|
||||
i {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -467,24 +592,30 @@
|
||||
.timeline-header {
|
||||
.header-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.timeline-subtitle {
|
||||
font-size: 0.85rem;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.week-selector {
|
||||
.filter-controls {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.week-info {
|
||||
.week-label {
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
.week-display {
|
||||
min-width: 90px;
|
||||
|
||||
.week-nav-btn {
|
||||
padding: 0.4rem 0.6rem;
|
||||
.week-label {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.week-dates {
|
||||
font-size: 0.65rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+64
-13
@@ -3,6 +3,10 @@ import {CommonModule} from '@angular/common';
|
||||
import {ReadingSessionTimelineResponse, UserStatsService} from '../../../settings/user-management/user-stats.service';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {BookType} from '../../../book/model/book.model';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {of} from 'rxjs';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
|
||||
interface ReadingSession {
|
||||
startTime: Date;
|
||||
@@ -37,14 +41,13 @@ interface DayTimeline {
|
||||
@Component({
|
||||
selector: 'app-reading-session-timeline',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, Select, FormsModule],
|
||||
templateUrl: './reading-session-timeline.component.html',
|
||||
styleUrls: ['./reading-session-timeline.component.scss']
|
||||
})
|
||||
export class ReadingSessionTimelineComponent implements OnInit {
|
||||
@Input() initialYear: number = new Date().getFullYear();
|
||||
@Input() weekNumber: number = this.getCurrentWeekNumber();
|
||||
@Input() userName: string = '';
|
||||
|
||||
private userStatsService = inject(UserStatsService);
|
||||
private urlHelperService = inject(UrlHelperService);
|
||||
@@ -54,14 +57,52 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
public timelineData: DayTimeline[] = [];
|
||||
public currentYear: number = new Date().getFullYear();
|
||||
public currentWeek: number = this.getCurrentWeekNumber();
|
||||
public currentMonth: number = new Date().getMonth() + 1;
|
||||
|
||||
public yearOptions: { label: string; value: number }[] = [];
|
||||
public weekOptions: { label: string; value: number }[] = [];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.currentYear = this.initialYear;
|
||||
this.currentWeek = this.weekNumber;
|
||||
this.updateCurrentMonth();
|
||||
this.initializeYearOptions();
|
||||
this.updateWeekOptions();
|
||||
this.initializeHourLabels();
|
||||
this.loadReadingSessions();
|
||||
}
|
||||
|
||||
private initializeYearOptions(): void {
|
||||
const currentYear = new Date().getFullYear();
|
||||
this.yearOptions = [];
|
||||
for (let year = currentYear; year >= currentYear - 10; year--) {
|
||||
this.yearOptions.push({ label: year.toString(), value: year });
|
||||
}
|
||||
}
|
||||
|
||||
private updateWeekOptions(): void {
|
||||
const weeksInYear = this.getWeeksInYear(this.currentYear);
|
||||
this.weekOptions = [];
|
||||
for (let week = 1; week <= weeksInYear; week++) {
|
||||
this.weekOptions.push({ label: `Week ${week}`, value: week });
|
||||
}
|
||||
}
|
||||
|
||||
public onYearChange(): void {
|
||||
this.updateWeekOptions();
|
||||
const maxWeeks = this.getWeeksInYear(this.currentYear);
|
||||
if (this.currentWeek > maxWeeks) {
|
||||
this.currentWeek = maxWeeks;
|
||||
}
|
||||
this.updateCurrentMonth();
|
||||
this.loadReadingSessions();
|
||||
}
|
||||
|
||||
public onWeekChange(): void {
|
||||
this.updateCurrentMonth();
|
||||
this.loadReadingSessions();
|
||||
}
|
||||
|
||||
private initializeHourLabels(): void {
|
||||
for (let i = 0; i < 24; i++) {
|
||||
const hour = i === 0 ? 12 : i > 12 ? i - 12 : i;
|
||||
@@ -71,15 +112,17 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
}
|
||||
|
||||
private loadReadingSessions(): void {
|
||||
this.userStatsService.getTimelineForWeek(this.currentYear, this.currentWeek)
|
||||
this.userStatsService.getTimelineForWeek(this.currentYear, this.currentMonth, this.currentWeek)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
console.error('Error loading reading sessions:', error);
|
||||
return of([]);
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
const sessions = this.convertResponseToSessions(response);
|
||||
this.processSessionData(sessions);
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error loading reading sessions:', error);
|
||||
this.processSessionData([]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -119,14 +162,28 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
if (this.currentWeek > weeksInYear) {
|
||||
this.currentWeek = 1;
|
||||
this.currentYear++;
|
||||
this.updateWeekOptions();
|
||||
} else if (this.currentWeek < 1) {
|
||||
this.currentYear--;
|
||||
this.currentWeek = this.getWeeksInYear(this.currentYear);
|
||||
this.updateWeekOptions();
|
||||
}
|
||||
|
||||
this.updateCurrentMonth();
|
||||
this.loadReadingSessions();
|
||||
}
|
||||
|
||||
private updateCurrentMonth(): void {
|
||||
const startOfYear = new Date(this.currentYear, 0, 1);
|
||||
const daysToAdd = (this.currentWeek - 1) * 7;
|
||||
const weekStart = new Date(startOfYear.getTime() + daysToAdd * 24 * 60 * 60 * 1000);
|
||||
|
||||
const dayOfWeek = weekStart.getDay();
|
||||
weekStart.setDate(weekStart.getDate() - dayOfWeek);
|
||||
|
||||
this.currentMonth = weekStart.getMonth() + 1;
|
||||
}
|
||||
|
||||
private getWeeksInYear(year: number): number {
|
||||
const lastDay = new Date(year, 11, 31);
|
||||
const startOfYear = new Date(year, 0, 1);
|
||||
@@ -325,10 +382,4 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
public getCoverUrl(bookId: number): string {
|
||||
return this.urlHelperService.getThumbnailUrl1(bookId);
|
||||
}
|
||||
|
||||
public getTitle(): string {
|
||||
return this.userName
|
||||
? `${this.userName}'s Reading Session Timeline`
|
||||
: 'Reading Session Timeline';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user