Skip to content

Commit

Permalink
Small Bugfixes (#2414)
Browse files Browse the repository at this point in the history
  • Loading branch information
majora2007 authored Nov 8, 2023
1 parent 26b0cb7 commit b7e7eaf
Show file tree
Hide file tree
Showing 22 changed files with 91 additions and 87 deletions.
12 changes: 6 additions & 6 deletions API.Tests/Services/SeriesServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public class SeriesServiceTests : AbstractDbTest

public SeriesServiceTests() : base()
{
var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), new FileSystem()
{

});
var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), new FileSystem());


var locService = new LocalizationService(ds, new MockHostingEnvironment(),
Expand Down Expand Up @@ -461,7 +458,7 @@ public async Task UpdateRating_ShouldClampRatingAt5()

JobStorage.Current = new InMemoryStorage();
var ratings = (await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007",
AppUserIncludes.Ratings))
AppUserIncludes.Ratings)!)
.Ratings;
Assert.NotEmpty(ratings);
Assert.Equal(5, ratings.First().Rating);
Expand Down Expand Up @@ -526,6 +523,7 @@ public async Task UpdateSeriesMetadata_ShouldCreateEmptyMetadata_IfDoesntExist()
Assert.True(success);

var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(1);
Assert.NotNull(series);
Assert.NotNull(series.Metadata);
Assert.Contains("New Genre".SentenceCase(), series.Metadata.Genres.Select(g => g.Title));

Expand Down Expand Up @@ -805,7 +803,7 @@ private static Series CreateSeriesMock()
[Fact]
public void GetFirstChapterForMetadata_BookWithOnlyVolumeNumbers_Test()
{
var file = new MangaFileBuilder("Test.cbz", MangaFormat.Archive, 1).Build();
var file = new MangaFileBuilder("Test.cbz", MangaFormat.Epub, 1).Build();

var series = new SeriesBuilder("Test")
.WithVolume(new VolumeBuilder("1")
Expand All @@ -819,6 +817,7 @@ public void GetFirstChapterForMetadata_BookWithOnlyVolumeNumbers_Test()
series.Library = new LibraryBuilder("Test LIb", LibraryType.Book).Build();

var firstChapter = SeriesService.GetFirstChapterForMetadata(series);
Assert.NotNull(firstChapter);
Assert.Equal(1, firstChapter.Pages);
}

Expand All @@ -828,6 +827,7 @@ public void GetFirstChapterForMetadata_Book_Test()
var series = CreateSeriesMock();

var firstChapter = SeriesService.GetFirstChapterForMetadata(series);
Assert.NotNull(firstChapter);
Assert.Same("1", firstChapter.Range);
}

Expand Down
2 changes: 1 addition & 1 deletion API/Services/Tasks/Scanner/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class Parser
public const string DefaultVolume = "0";
public static readonly TimeSpan RegexTimeout = TimeSpan.FromMilliseconds(500);

public const string ImageFileExtensions = @"^(\.png|\.jpeg|\.jpg|\.webp|\.gif|\.avif)";
public const string ImageFileExtensions = @"^(\.png|\.jpeg|\.jpg|\.webp|\.gif|\.avif)"; // Don't forget to update CoverChooser
public const string ArchiveFileExtensions = @"\.cbz|\.zip|\.rar|\.cbr|\.tar.gz|\.7zip|\.7z|\.cb7|\.cbt";
private const string BookFileExtensions = @"\.epub|\.pdf";
private const string XmlRegexExtensions = @"\.xml";
Expand Down
2 changes: 1 addition & 1 deletion API/Services/Tasks/Scanner/ProcessSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void UpdateSeriesMetadata(Series series, Library library)
if (series.Metadata.MaxCount == series.Metadata.TotalCount && series.Metadata.TotalCount > 0)
{
series.Metadata.PublicationStatus = PublicationStatus.Completed;
} else if (series.Metadata.TotalCount > 0)
} else if (series.Metadata.TotalCount > 0 && series.Metadata.MaxCount > 0)
{
series.Metadata.PublicationStatus = PublicationStatus.Ended;
}
Expand Down
4 changes: 4 additions & 0 deletions UI/Web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ Run `npx playwright test --reporter=line` or `npx playwright test` to run e2e te

ng serve --host 0.0.0.0
and update environment.ts to your local ip.

## Notes:
- injected services should be at the top of the file
- all components must be standalone
25 changes: 0 additions & 25 deletions UI/Web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions UI/Web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@
"@popperjs/core": "^2.11.7",
"@swimlane/ngx-charts": "^20.1.2",
"@tweenjs/tween.js": "^21.0.0",
"@types/file-saver": "^2.0.6",
"angular-animations": "^0.11.0",
"bootstrap": "^5.3.1",
"charts.css": "^1.1.0",
"eventsource": "^2.0.2",
"file-saver": "^2.0.5",
"luxon": "^3.4.3",
"ng-circle-progress": "^1.7.1",
"ng-lazyload-image": "^9.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,9 @@ <h6>{{t('tags-title')}}</h6>
<li [ngbNavItem]="tabs[TabID.Cover]" [disabled]="(isAdmin$ | async) === false">
<a ngbNavLink>{{t(tabs[TabID.Cover].title)}}</a>
<ng-template ngbNavContent>
<app-cover-image-chooser [(imageUrls)]="imageUrls"
[showReset]="chapter.coverImageLocked"
[showApplyButton]="true"
(applyCover)="applyCoverImage($event)"
(resetCover)="resetCoverImage()"
>
</app-cover-image-chooser>
<app-cover-image-chooser [(imageUrls)]="imageUrls" (imageSelected)="updateCoverImageIndex($event)"
(selectedBase64Url)="applyCoverImage($event)" [showReset]="chapter.coverImageLocked"
(resetClicked)="resetCoverImage()"></app-cover-image-chooser>
</ng-template>
</li>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ export class CardDetailDrawerComponent implements OnInit {
this.uploadService.updateChapterCoverImage(this.chapter.id, coverUrl).subscribe(() => {});
}

updateCoverImageIndex(selectedIndex: number) {
if (selectedIndex <= 0) return;
this.applyCoverImage(this.imageUrls[selectedIndex]);
}

resetCoverImage() {
this.uploadService.resetChapterCoverLock(this.chapter.id).subscribe(() => {
this.toastr.info(translate('toasts.regen-cover'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="input-group col-auto me-md-2" style="width: 83%">
<label class="input-group-text" for="load-image">{{t('url-label')}}</label>
<input type="text" autofocus autocomplete="off" class="form-control" formControlName="coverImageUrl" placeholder="https://" id="load-image" class="form-control">
<button class="btn btn-outline-secondary" type="button" id="load-image-addon" (click)="loadImage(); mode='all';" [disabled]="(form.get('coverImageUrl')?.value).length === 0">
<button class="btn btn-outline-secondary" type="button" id="load-image-addon" (click)="loadImageFromUrl(); mode='all';" [disabled]="(form.get('coverImageUrl')?.value).length === 0">
{{t('load')}}
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component, DestroyRef,
Component,
EventEmitter,
inject,
Inject,
Expand All @@ -11,7 +11,7 @@ import {
} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
import {NgxFileDropEntry, FileSystemFileEntry, NgxFileDropModule} from 'ngx-file-drop';
import { fromEvent, Subject } from 'rxjs';
import { fromEvent } from 'rxjs';
import { takeWhile } from 'rxjs/operators';
import { ToastrService } from 'ngx-toastr';
import { ImageService } from 'src/app/_services/image.service';
Expand All @@ -37,7 +37,6 @@ import {translate, TranslocoModule} from "@ngneat/transloco";
})
export class CoverImageChooserComponent implements OnInit {

private readonly destroyRef = inject(DestroyRef);
private readonly cdRef = inject(ChangeDetectorRef);
public readonly imageService = inject(ImageService);
public readonly fb = inject(FormBuilder);
Expand Down Expand Up @@ -84,8 +83,7 @@ export class CoverImageChooserComponent implements OnInit {
appliedIndex: number = 0;
form!: FormGroup;
files: NgxFileDropEntry[] = [];
acceptableExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.webp'].join(',');

acceptableExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.avif'].join(',');
mode: 'file' | 'url' | 'all' = 'all';

constructor(@Inject(DOCUMENT) private document: Document) { }
Expand Down Expand Up @@ -182,6 +180,25 @@ export class CoverImageChooserComponent implements OnInit {
});
}

loadImageFromUrl(url?: string) {
url = url || this.form.get('coverImageUrl')?.value.trim();
if (!url || url === '') return;

this.uploadService.uploadByUrl(url).subscribe(filename => {
const img = new Image();
img.crossOrigin = 'Anonymous';
img.src = this.imageService.getCoverUploadImage(filename);
img.onload = (e) => this.handleUrlImageAdd(img);
img.onerror = (e) => {
this.toastr.error(translate('errors.rejected-cover-upload'));
this.form.get('coverImageUrl')?.setValue('');
this.cdRef.markForCheck();
};
this.form.get('coverImageUrl')?.setValue('');
this.cdRef.markForCheck();
});
}



changeMode(mode: 'url') {
Expand Down Expand Up @@ -239,12 +256,6 @@ export class CoverImageChooserComponent implements OnInit {
});
}

public fileOver(event: any){
}

public fileLeave(event: any){
}

reset() {
this.resetClicked.emit();
this.selectedIndex = -1;
Expand Down Expand Up @@ -275,4 +286,6 @@ export class CoverImageChooserComponent implements OnInit {
});
}

protected fileOver(event: any){}
protected fileLeave(event: any){}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class InfiniteScrollerComponent implements OnInit, OnChanges, OnDestroy {
/**
* Debug mode. Will show extra information. Use bitwise (|) operators between different modes to enable different output
*/
debugMode: DEBUG_MODES = DEBUG_MODES.Outline;
debugMode: DEBUG_MODES = DEBUG_MODES.None;
/**
* Debug mode. Will filter out any messages in here so they don't hit the log
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h5>{{heading}}</h5>
</div>
<div class="col-lg-9 col-md-8 col-sm-12">
<app-badge-expander [items]="tags">
<app-badge-expander [items]="tags" [itemsTillExpander]="utilityService.getActiveBreakpoint() >= Breakpoint.Desktop ? 30 : 4">
<ng-template #badgeExpanderItem let-item let-position="idx">
<ng-container *ngIf="itemTemplate; else useTitle">
<span (click)="goTo(queryParam, item.id)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {TagBadgeComponent, TagBadgeCursor} from "../../../shared/tag-badge/tag-b
import {FilterUtilitiesService} from "../../../shared/_services/filter-utilities.service";
import {FilterComparison} from "../../../_models/metadata/v2/filter-comparison";
import {FilterField} from "../../../_models/metadata/v2/filter-field";
import {Breakpoint, UtilityService} from "../../../shared/_services/utility.service";

@Component({
selector: 'app-metadata-detail',
Expand All @@ -17,19 +18,23 @@ import {FilterField} from "../../../_models/metadata/v2/filter-field";
})
export class MetadataDetailComponent {

private readonly filterUtilityService = inject(FilterUtilitiesService);
public readonly utilityService = inject(UtilityService);
protected readonly TagBadgeCursor = TagBadgeCursor;
protected readonly Breakpoint = Breakpoint;

@Input({required: true}) tags: Array<any> = [];
@Input({required: true}) libraryId!: number;
@Input({required: true}) heading!: string;
@Input() queryParam: FilterField = FilterField.None;
@ContentChild('titleTemplate') titleTemplate!: TemplateRef<any>;
@ContentChild('itemTemplate') itemTemplate?: TemplateRef<any>;

private readonly filterUtilityService = inject(FilterUtilitiesService);
protected readonly TagBadgeCursor = TagBadgeCursor;


goTo(queryParamName: FilterField, filter: any) {
if (queryParamName === FilterField.None) return;
this.filterUtilityService.applyFilter(['library', this.libraryId], queryParamName, FilterComparison.Equal, filter).subscribe();
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ng-container *transloco="let t; read: 'series-metadata-detail'">
<div class="row g-0 mt-2 mb-2">
<app-read-more [text]="seriesSummary" [maxLength]="250"></app-read-more>
<app-read-more [text]="seriesSummary" [maxLength]="utilityService.getActiveBreakpoint() >= Breakpoint.Desktop ? 1000 : 250"></app-read-more>
</div>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,6 @@ export class SeriesMetadataDetailComponent implements OnChanges {
navigate(basePage: string, id: number) {
this.router.navigate([basePage, id]);
}

protected readonly Breakpoint = Breakpoint;
}
10 changes: 0 additions & 10 deletions UI/Web/src/app/shared/_providers/saver.provider.ts

This file was deleted.

14 changes: 12 additions & 2 deletions UI/Web/src/app/shared/_services/download.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
of,
filter,
} from 'rxjs';
import { SAVER, Saver } from '../_providers/saver.provider';
import { download, Download } from '../_models/download';
import { PageBookmark } from 'src/app/_models/readers/page-bookmark';
import {switchMap, take, takeWhile, throttleTime} from 'rxjs/operators';
Expand Down Expand Up @@ -69,7 +68,7 @@ export class DownloadService {
private readonly destroyRef = inject(DestroyRef);

constructor(private httpClient: HttpClient, private confirmService: ConfirmService,
@Inject(SAVER) private save: Saver, private accountService: AccountService) { }
private accountService: AccountService) { }


/**
Expand Down Expand Up @@ -270,4 +269,15 @@ export class DownloadService {
finalize(() => this.finalizeDownloadState(downloadType, subtitle))
);
}

private save(blob: Blob, filename: string) {
const saveLink = document.createElement( 'a' );
if (saveLink.href) {
URL.revokeObjectURL(saveLink.href);
}
saveLink.href = URL.createObjectURL(blob);
saveLink.download = filename;
saveLink.dispatchEvent( new MouseEvent( 'click' ) );
}

}
Loading

0 comments on commit b7e7eaf

Please sign in to comment.