Skip to content

Commit

Permalink
Best known for is in (and uses Kavita+ data when available, otherwise…
Browse files Browse the repository at this point in the history
… it's just a random order).
  • Loading branch information
majora2007 committed Oct 11, 2024
1 parent 39cc622 commit 0d1aa75
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 12 deletions.
6 changes: 6 additions & 0 deletions API/Controllers/PersonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,11 @@ public async Task<ActionResult<PersonDto>> UpdatePerson(UpdatePersonDto dto)
return Ok(_mapper.Map<PersonDto>(person));
}

[HttpGet("series-known-for")]
public async Task<ActionResult<IEnumerable<SeriesDto>>> GetKnownSeries(int personId)
{
return Ok(await _unitOfWork.PersonRepository.GetSeriesKnownFor(personId));
}


}
16 changes: 16 additions & 0 deletions API/Data/Repositories/PersonRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface IPersonRepository
Task<Person?> GetPersonById(int personId);
Task<PersonDto?> GetPersonDtoByName(string name, int userId);
Task<Person> GetPersonByName(string name);

Task<IEnumerable<SeriesDto>> GetSeriesKnownFor(int personId);
}

public class PersonRepository : IPersonRepository
Expand Down Expand Up @@ -226,6 +228,20 @@ public async Task<Person> GetPersonByName(string name)
return await _context.Person.FirstOrDefaultAsync(p => p.NormalizedName == name.ToNormalized());
}

public async Task<IEnumerable<SeriesDto>> GetSeriesKnownFor(int personId)
{
return await _context.Person
.Where(p => p.Id == personId)
.SelectMany(p => p.SeriesMetadataPeople)
.Select(smp => smp.SeriesMetadata)
.Select(sm => sm.Series)
.Distinct()
.OrderByDescending(s => s.ExternalSeriesMetadata.AverageExternalRating)
.Take(20)
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
.ToListAsync();
}


public async Task<IList<Person>> GetAllPeople()
{
Expand Down
3 changes: 3 additions & 0 deletions UI/Web/src/app/_services/person.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class PersonService {
return this.httpClient.get<Array<PersonRole>>(this.baseUrl + `person/roles?name=${name}`);
}

getSeriesMostKnownFor(personId: number) {
return this.httpClient.get<Array<Series>>(this.baseUrl + `person/series-known-for?personId=${personId}`);
}

getAuthorsToBrowse(pageNum?: number, itemsPerPage?: number) {
let params = new HttpParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ export class EditSeriesModalComponent implements OnInit {
};

personSettings.addTransformFn = ((title: string) => {
return {id: 0, name: title, role: role, description: '', coverImage: '', coverImageLocked: false };
return {id: 0, name: title, description: '', coverImageLocked: false };
});

return personSettings;
Expand Down
32 changes: 27 additions & 5 deletions UI/Web/src/app/person-detail/person-detail.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="main-container container-fluid">
@if (person$ | async; as person) {
<ng-container *transloco="let t; read: 'person-detail'">
@if (person$ | async; as person) {
<div #companionBar>
<app-side-nav-companion-bar>
<ng-container title>
Expand Down Expand Up @@ -37,11 +38,9 @@ <h5>Roles in Libraries</h5>
</div>
</div>

<!-- Works Carousel -->
<!-- TODO: Works needs to be different. I think we need to show individual chapters -->
@if (works$ | async; as works) {
<div class="row mt-2">
<app-carousel-reel [items]="works" [title]="'Works'" (sectionClick)="loadFilterByPerson()">
<app-carousel-reel [items]="works" [title]="t('known-for-title')" (sectionClick)="loadFilterByPerson()">
<ng-template #carouselItem let-item>
<app-card-item [entity]="item"
[imageUrl]="imageService.getSeriesCoverImage(item.id)"
Expand All @@ -57,8 +56,30 @@ <h5>Roles in Libraries</h5>
</div>
}


@if (roles$ | async; as roles) {
@for(role of roles; track role) {
<div class="row mt-2">
<app-carousel-reel [items]="[]" [title]="'As a ' + (role | personRole)" (sectionClick)="loadFilterByPerson()">
<ng-template #carouselItem let-item>
<app-card-item [entity]="item"
[imageUrl]="imageService.getChapterCoverImage(item.id)"
[title]="item.name"
[suppressArchiveWarning]="true"
(clicked)="navigateToSeries(item)">
<ng-template #subtitle>
Role here
</ng-template>
</app-card-item>
</ng-template>
</app-carousel-reel>
</div>
}
}


<!-- Individual Works Carousel -->
<div class="row mt-2">
<div class="row mt-2">
<app-carousel-reel [items]="[]" [title]="'Individual Works'" (sectionClick)="loadFilterByPerson()">
<ng-template #carouselItem let-item>
<app-card-item [entity]="item"
Expand Down Expand Up @@ -92,4 +113,5 @@ <h5>Roles in Libraries</h5>
}

}
</ng-container>
</div>
13 changes: 7 additions & 6 deletions UI/Web/src/app/person-detail/person-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {Action, ActionFactoryService, ActionItem} from "../_services/action-fact
import {Chapter} from "../_models/chapter";
import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
import {EditPersonModalComponent} from "./_modal/edit-person-modal/edit-person-modal.component";
import {TranslocoDirective} from "@jsverse/transloco";

@Component({
selector: 'app-person-detail',
Expand All @@ -53,7 +54,8 @@ import {EditPersonModalComponent} from "./_modal/edit-person-modal/edit-person-m
CarouselReelComponent,
SeriesCardComponent,
CardItemComponent,
CardActionablesComponent
CardActionablesComponent,
TranslocoDirective
],
templateUrl: './person-detail.component.html',
styleUrl: './person-detail.component.scss',
Expand Down Expand Up @@ -97,18 +99,17 @@ export class PersonDetailComponent {
this.person$ = this.personService.get(this.personName).pipe(tap(p => {
this.person = p;

this.works$ = this.personService.getSeriesMostKnownFor(this.person.id).pipe(
takeUntilDestroyed(this.destroyRef)
);

this.cdRef.markForCheck();
}), takeUntilDestroyed(this.destroyRef));

this.roles$ = this.personService.getRolesForPerson(this.personName).pipe(tap(roles => {
this.roles = roles;
this.filter = this.createFilter(roles);

this.works$ = this.seriesService.getSeriesForLibraryV2(undefined, undefined, this.filter!).pipe(
map((d: PaginatedResult<Series[]>) => d.result),
takeUntilDestroyed(this.destroyRef)
);

this.cdRef.markForCheck();
}), takeUntilDestroyed(this.destroyRef));
});
Expand Down
4 changes: 4 additions & 0 deletions UI/Web/src/assets/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,10 @@
"cover-image-description": "{{edit-series-modal.cover-image-description}}"
},

"person-detail": {
"known-for-title": "Known For"
},

"library-settings-modal": {
"close": "{{common.close}}",
"edit-title": "Edit {{name}}",
Expand Down

0 comments on commit 0d1aa75

Please sign in to comment.