Allow deleting Scrobble events
This commit is contained in:
parent
1a4aa215d6
commit
169d819de5
10 changed files with 160 additions and 11 deletions
|
|
@ -254,7 +254,7 @@ public class ScrobblingController : BaseApiController
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a hold against the Series for user's scrobbling
|
/// Remove a hold against the Series for user's scrobbling
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="seriesId"></param>
|
/// <param name="seriesId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
|
@ -281,4 +281,18 @@ public class ScrobblingController : BaseApiController
|
||||||
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(User.GetUserId());
|
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(User.GetUserId());
|
||||||
return Ok(user is {HasRunScrobbleEventGeneration: true});
|
return Ok(user is {HasRunScrobbleEventGeneration: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete the given scrobble events if they belong to that user
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="eventIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("bulk-remove-events")]
|
||||||
|
public async Task<ActionResult> BulkRemoveScrobbleEvents(IList<long> eventIds)
|
||||||
|
{
|
||||||
|
var events = await _unitOfWork.ScrobbleRepository.GetUserEvents(User.GetUserId(), eventIds);
|
||||||
|
_unitOfWork.ScrobbleRepository.Remove(events);
|
||||||
|
await _unitOfWork.CommitAsync();
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace API.DTOs.Scrobbling;
|
||||||
|
|
||||||
public sealed record ScrobbleEventDto
|
public sealed record ScrobbleEventDto
|
||||||
{
|
{
|
||||||
|
public long Id { get; init; }
|
||||||
public string SeriesName { get; set; }
|
public string SeriesName { get; set; }
|
||||||
public int SeriesId { get; set; }
|
public int SeriesId { get; set; }
|
||||||
public int LibraryId { get; set; }
|
public int LibraryId { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,13 @@ public interface IScrobbleRepository
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<ScrobbleEvent?> GetEvent(int userId, int seriesId, ScrobbleEventType eventType, bool isNotProcessed = false);
|
Task<ScrobbleEvent?> GetEvent(int userId, int seriesId, ScrobbleEventType eventType, bool isNotProcessed = false);
|
||||||
Task<IEnumerable<ScrobbleEvent>> GetUserEventsForSeries(int userId, int seriesId);
|
Task<IEnumerable<ScrobbleEvent>> GetUserEventsForSeries(int userId, int seriesId);
|
||||||
|
/// <summary>
|
||||||
|
/// Return the events with given ids, when belonging to the passed user
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId"></param>
|
||||||
|
/// <param name="scrobbleEventIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IList<ScrobbleEvent>> GetUserEvents(int userId, IList<long> scrobbleEventIds);
|
||||||
Task<PagedList<ScrobbleEventDto>> GetUserEvents(int userId, ScrobbleEventFilter filter, UserParams pagination);
|
Task<PagedList<ScrobbleEventDto>> GetUserEvents(int userId, ScrobbleEventFilter filter, UserParams pagination);
|
||||||
Task<IList<ScrobbleEvent>> GetAllEventsForSeries(int seriesId);
|
Task<IList<ScrobbleEvent>> GetAllEventsForSeries(int seriesId);
|
||||||
Task<IList<ScrobbleEvent>> GetAllEventsWithSeriesIds(IEnumerable<int> seriesIds);
|
Task<IList<ScrobbleEvent>> GetAllEventsWithSeriesIds(IEnumerable<int> seriesIds);
|
||||||
|
|
@ -166,13 +173,20 @@ public class ScrobbleRepository : IScrobbleRepository
|
||||||
public async Task<IEnumerable<ScrobbleEvent>> GetUserEventsForSeries(int userId, int seriesId)
|
public async Task<IEnumerable<ScrobbleEvent>> GetUserEventsForSeries(int userId, int seriesId)
|
||||||
{
|
{
|
||||||
return await _context.ScrobbleEvent
|
return await _context.ScrobbleEvent
|
||||||
.Where(e => e.AppUserId == userId && !e.IsProcessed)
|
.Where(e => e.AppUserId == userId && !e.IsProcessed && e.SeriesId == seriesId)
|
||||||
.Include(e => e.Series)
|
.Include(e => e.Series)
|
||||||
.OrderBy(e => e.LastModifiedUtc)
|
.OrderBy(e => e.LastModifiedUtc)
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IList<ScrobbleEvent>> GetUserEvents(int userId, IList<long> scrobbleEventIds)
|
||||||
|
{
|
||||||
|
return await _context.ScrobbleEvent
|
||||||
|
.Where(e => e.AppUserId == userId && scrobbleEventIds.Contains(e.Id))
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<PagedList<ScrobbleEventDto>> GetUserEvents(int userId, ScrobbleEventFilter filter, UserParams pagination)
|
public async Task<PagedList<ScrobbleEventDto>> GetUserEvents(int userId, ScrobbleEventFilter filter, UserParams pagination)
|
||||||
{
|
{
|
||||||
var query = _context.ScrobbleEvent
|
var query = _context.ScrobbleEvent
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export enum ScrobbleEventType {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScrobbleEvent {
|
export interface ScrobbleEvent {
|
||||||
|
id: number;
|
||||||
seriesName: string;
|
seriesName: string;
|
||||||
seriesId: number;
|
seriesId: number;
|
||||||
libraryId: number;
|
libraryId: number;
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,10 @@ export class ScrobblingService {
|
||||||
|
|
||||||
triggerScrobbleEventGeneration() {
|
triggerScrobbleEventGeneration() {
|
||||||
return this.httpClient.post(this.baseUrl + 'scrobbling/generate-scrobble-events', TextResonse);
|
return this.httpClient.post(this.baseUrl + 'scrobbling/generate-scrobble-events', TextResonse);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bulkRemoveEvents(eventIds: number[]) {
|
||||||
|
return this.httpClient.post(this.baseUrl + "scrobbling/bulk-remove-events", eventIds)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@
|
||||||
<form [formGroup]="formGroup">
|
<form [formGroup]="formGroup">
|
||||||
<div class="form-group pe-1">
|
<div class="form-group pe-1">
|
||||||
<label for="filter">{{t('filter-label')}}</label>
|
<label for="filter">{{t('filter-label')}}</label>
|
||||||
<input id="filter" type="text" class="form-control" formControlName="filter" autocomplete="off"/>
|
<div class="input-group">
|
||||||
|
<input id="filter" type="text" class="form-control" formControlName="filter" autocomplete="off" [placeholder]="t('filter-label')"/>
|
||||||
|
<button class="btn btn-primary" type="button" [disabled]="!selections.hasAnySelected()" (click)="bulkDelete()">{{t('delete-selected')}}</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -40,6 +43,20 @@
|
||||||
[sorts]="[{prop: 'createdUtc', dir: 'desc'}]"
|
[sorts]="[{prop: 'createdUtc', dir: 'desc'}]"
|
||||||
>
|
>
|
||||||
|
|
||||||
|
<ngx-datatable-column prop="select" [sortable]="false" [draggable]="false" [resizeable]="false" [width]="50">
|
||||||
|
<ng-template let-column="column" ngx-datatable-header-template>
|
||||||
|
<div class="form-check">
|
||||||
|
<input id="select-all" type="checkbox" class="form-check-input"
|
||||||
|
[ngModel]="selectAll" (change)="toggleAll()" [indeterminate]="selections?.hasSomeSelected()">
|
||||||
|
<label for="select-all" class="form-check-label d-md-block d-none">{{t('select-header')}}</label>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
<ng-template let-event="row" let-idx="index" ngx-datatable-cell-template>
|
||||||
|
<input id="select-event-{{idx}}" type="checkbox" class="form-check-input"
|
||||||
|
[ngModel]="selections.isSelected(event)" (change)="handleSelection(event, idx)">
|
||||||
|
</ng-template>
|
||||||
|
</ngx-datatable-column>
|
||||||
|
|
||||||
<ngx-datatable-column prop="createdUtc" [sortable]="true" [draggable]="false" [resizeable]="false">
|
<ngx-datatable-column prop="createdUtc" [sortable]="true" [draggable]="false" [resizeable]="false">
|
||||||
<ng-template let-column="column" ngx-datatable-header-template>
|
<ng-template let-column="column" ngx-datatable-header-template>
|
||||||
{{t('created-header')}}
|
{{t('created-header')}}
|
||||||
|
|
@ -101,7 +118,7 @@
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</ngx-datatable-column>
|
</ngx-datatable-column>
|
||||||
|
|
||||||
<ngx-datatable-column prop="isPorcessed" [sortable]="true" [draggable]="false" [resizeable]="false">
|
<ngx-datatable-column prop="isProcessed" [sortable]="true" [draggable]="false" [resizeable]="false">
|
||||||
<ng-template let-column="column" ngx-datatable-header-template>
|
<ng-template let-column="column" ngx-datatable-header-template>
|
||||||
{{t('is-processed-header')}}
|
{{t('is-processed-header')}}
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,12 @@
|
||||||
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, inject, OnInit} from '@angular/core';
|
import {
|
||||||
|
ChangeDetectionStrategy,
|
||||||
|
ChangeDetectorRef,
|
||||||
|
Component,
|
||||||
|
DestroyRef,
|
||||||
|
HostListener,
|
||||||
|
inject,
|
||||||
|
OnInit
|
||||||
|
} from '@angular/core';
|
||||||
|
|
||||||
import {ScrobbleProvider, ScrobblingService} from "../../_services/scrobbling.service";
|
import {ScrobbleProvider, ScrobblingService} from "../../_services/scrobbling.service";
|
||||||
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
|
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
|
||||||
|
|
@ -9,7 +17,7 @@ import {ScrobbleEventSortField} from "../../_models/scrobbling/scrobble-event-fi
|
||||||
import {debounceTime, take} from "rxjs/operators";
|
import {debounceTime, take} from "rxjs/operators";
|
||||||
import {PaginatedResult} from "../../_models/pagination";
|
import {PaginatedResult} from "../../_models/pagination";
|
||||||
import {SortEvent} from "../table/_directives/sortable-header.directive";
|
import {SortEvent} from "../table/_directives/sortable-header.directive";
|
||||||
import {FormControl, FormGroup, ReactiveFormsModule} from "@angular/forms";
|
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from "@angular/forms";
|
||||||
import {translate, TranslocoModule} from "@jsverse/transloco";
|
import {translate, TranslocoModule} from "@jsverse/transloco";
|
||||||
import {DefaultValuePipe} from "../../_pipes/default-value.pipe";
|
import {DefaultValuePipe} from "../../_pipes/default-value.pipe";
|
||||||
import {TranslocoLocaleModule} from "@jsverse/transloco-locale";
|
import {TranslocoLocaleModule} from "@jsverse/transloco-locale";
|
||||||
|
|
@ -19,6 +27,7 @@ import {ColumnMode, NgxDatatableModule} from "@siemens/ngx-datatable";
|
||||||
import {AsyncPipe} from "@angular/common";
|
import {AsyncPipe} from "@angular/common";
|
||||||
import {AccountService} from "../../_services/account.service";
|
import {AccountService} from "../../_services/account.service";
|
||||||
import {ToastrService} from "ngx-toastr";
|
import {ToastrService} from "ngx-toastr";
|
||||||
|
import {SelectionModel} from "../../typeahead/_models/selection-model";
|
||||||
|
|
||||||
export interface DataTablePage {
|
export interface DataTablePage {
|
||||||
pageNumber: number,
|
pageNumber: number,
|
||||||
|
|
@ -30,7 +39,7 @@ export interface DataTablePage {
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-user-scrobble-history',
|
selector: 'app-user-scrobble-history',
|
||||||
imports: [ScrobbleEventTypePipe, ReactiveFormsModule, TranslocoModule,
|
imports: [ScrobbleEventTypePipe, ReactiveFormsModule, TranslocoModule,
|
||||||
DefaultValuePipe, TranslocoLocaleModule, UtcToLocalTimePipe, NgbTooltip, NgxDatatableModule, AsyncPipe],
|
DefaultValuePipe, TranslocoLocaleModule, UtcToLocalTimePipe, NgbTooltip, NgxDatatableModule, AsyncPipe, FormsModule],
|
||||||
templateUrl: './user-scrobble-history.component.html',
|
templateUrl: './user-scrobble-history.component.html',
|
||||||
styleUrls: ['./user-scrobble-history.component.scss'],
|
styleUrls: ['./user-scrobble-history.component.scss'],
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
|
|
@ -48,8 +57,6 @@ export class UserScrobbleHistoryComponent implements OnInit {
|
||||||
private readonly toastr = inject(ToastrService);
|
private readonly toastr = inject(ToastrService);
|
||||||
protected readonly accountService = inject(AccountService);
|
protected readonly accountService = inject(AccountService);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tokenExpired = false;
|
tokenExpired = false;
|
||||||
formGroup: FormGroup = new FormGroup({
|
formGroup: FormGroup = new FormGroup({
|
||||||
'filter': new FormControl('', [])
|
'filter': new FormControl('', [])
|
||||||
|
|
@ -68,6 +75,21 @@ export class UserScrobbleHistoryComponent implements OnInit {
|
||||||
};
|
};
|
||||||
hasRunScrobbleGen: boolean = false;
|
hasRunScrobbleGen: boolean = false;
|
||||||
|
|
||||||
|
selections: SelectionModel<ScrobbleEvent> = new SelectionModel();
|
||||||
|
selectAll: boolean = false;
|
||||||
|
isShiftDown: boolean = false;
|
||||||
|
lastSelectedIndex: number | null = null;
|
||||||
|
|
||||||
|
@HostListener('document:keydown.shift', ['$event'])
|
||||||
|
handleKeypress(_: KeyboardEvent) {
|
||||||
|
this.isShiftDown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostListener('document:keyup.shift', ['$event'])
|
||||||
|
handleKeyUp(_: KeyboardEvent) {
|
||||||
|
this.isShiftDown = false;
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
||||||
this.pageInfo.pageNumber = 0;
|
this.pageInfo.pageNumber = 0;
|
||||||
|
|
@ -118,6 +140,7 @@ export class UserScrobbleHistoryComponent implements OnInit {
|
||||||
.pipe(take(1))
|
.pipe(take(1))
|
||||||
.subscribe((result: PaginatedResult<ScrobbleEvent[]>) => {
|
.subscribe((result: PaginatedResult<ScrobbleEvent[]>) => {
|
||||||
this.events = result.result;
|
this.events = result.result;
|
||||||
|
this.selections = new SelectionModel(false, this.events);
|
||||||
|
|
||||||
this.pageInfo.totalPages = result.pagination.totalPages - 1; // ngx-datatable is 0 based, Kavita is 1 based
|
this.pageInfo.totalPages = result.pagination.totalPages - 1; // ngx-datatable is 0 based, Kavita is 1 based
|
||||||
this.pageInfo.size = result.pagination.itemsPerPage;
|
this.pageInfo.size = result.pagination.itemsPerPage;
|
||||||
|
|
@ -143,4 +166,55 @@ export class UserScrobbleHistoryComponent implements OnInit {
|
||||||
this.toastr.info(translate('toasts.scrobble-gen-init'))
|
this.toastr.info(translate('toasts.scrobble-gen-init'))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bulkDelete() {
|
||||||
|
if (!this.selections.hasAnySelected()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventIds = this.selections.selected().map(e => e.id);
|
||||||
|
|
||||||
|
this.scrobblingService.bulkRemoveEvents(eventIds).subscribe({
|
||||||
|
next: () => {
|
||||||
|
this.events = this.events.filter(e => !eventIds.includes(e.id));
|
||||||
|
this.selectAll = false;
|
||||||
|
this.selections.clearSelected();
|
||||||
|
this.pageInfo.totalElements -= eventIds.length;
|
||||||
|
this.cdRef.markForCheck();
|
||||||
|
},
|
||||||
|
error: err => {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleAll() {
|
||||||
|
this.selectAll = !this.selectAll;
|
||||||
|
this.events.forEach(e => this.selections.toggle(e, this.selectAll));
|
||||||
|
this.cdRef.markForCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSelection(item: ScrobbleEvent, index: number) {
|
||||||
|
if (this.isShiftDown && this.lastSelectedIndex !== null) {
|
||||||
|
// Bulk select items between the last selected item and the current one
|
||||||
|
const start = Math.min(this.lastSelectedIndex, index);
|
||||||
|
const end = Math.max(this.lastSelectedIndex, index);
|
||||||
|
|
||||||
|
for (let i = start; i <= end; i++) {
|
||||||
|
const event = this.events[i];
|
||||||
|
if (!this.selections.isSelected(event, (e1, e2) => e1.id == e2.id)) {
|
||||||
|
this.selections.toggle(event, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.selections.toggle(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lastSelectedIndex = index;
|
||||||
|
|
||||||
|
|
||||||
|
const numberOfSelected = this.selections.selected().length;
|
||||||
|
this.selectAll = numberOfSelected === this.events.length;
|
||||||
|
this.cdRef.markForCheck();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
<label for="filter" class="visually-hidden">{{t('filter-label')}}</label>
|
<label for="filter" class="visually-hidden">{{t('filter-label')}}</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input id="filter" type="text" class="form-control" [placeholder]="t('filter-label')" formControlName="filter" />
|
<input id="filter" type="text" class="form-control" [placeholder]="t('filter-label')" formControlName="filter" />
|
||||||
<button class="btn btn-primary" type="button" (click)="clear()">{{t('clear-errors')}}</button>
|
<button class="btn btn-primary" type="button" [disabled]="data.length === 0" (click)="clear()">{{t('clear-errors')}}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,28 @@ export class SelectionModel<T> {
|
||||||
return (selectedCount !== this._data.length && selectedCount !== 0)
|
return (selectedCount !== this._data.length && selectedCount !== 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return If at least one item is selected
|
||||||
|
*/
|
||||||
|
hasAnySelected(): boolean {
|
||||||
|
for (const d of this._data) {
|
||||||
|
if (d.selected) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks every data entry has not selected
|
||||||
|
*/
|
||||||
|
clearSelected() {
|
||||||
|
this._data = this._data.map(d => {
|
||||||
|
d.selected = false;
|
||||||
|
return d;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @returns All Selected items
|
* @returns All Selected items
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@
|
||||||
"series-header": "Series",
|
"series-header": "Series",
|
||||||
"data-header": "Data",
|
"data-header": "Data",
|
||||||
"is-processed-header": "Is Processed",
|
"is-processed-header": "Is Processed",
|
||||||
|
"select-header": "Select all",
|
||||||
|
"delete-selected": "Delete selected",
|
||||||
"no-data": "{{common.no-data}}",
|
"no-data": "{{common.no-data}}",
|
||||||
"volume-and-chapter-num": "Volume {{v}} Chapter {{n}}",
|
"volume-and-chapter-num": "Volume {{v}} Chapter {{n}}",
|
||||||
"volume-num": "Volume {{num}}",
|
"volume-num": "Volume {{num}}",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue