Kavita/UI/Web/src/app/_services/library.service.ts
Joseph Milazzo f5229fd0e6
Bulk Operations (#596)
* Implemented the ability to perform multi-selections on cards. Basic selection code is done, CSS needed and exposing actions.

* Implemented a bulk selection bar. Added logic to the card on when to force show checkboxes.

* Fixed some bad parsing groups and cases for Comic Chapters.

* Hooked up some bulk actions on series detail page. Not hooked up to backend yet.

* Fixes #593. URI Enocde library names as sometimes they can have & in them.

* Implemented the ability to mark volume/chapters as read/unread.

* Hooked up mark as unread with specials as well.

* Add to reading list hooked up for Series Detail

* Implemented ability to add multiple series to a reading list.

* Implemented bulk selection for series cards

* Added comments to the new code in ReaderService.cs

* Implemented proper styling on bulk operation bar and integrated for collections.

* Fixed an issue with shift clicking

* Cleaned up css of bulk operations bar

* Code cleanup
2021-09-24 17:27:47 -07:00

99 lines
3 KiB
TypeScript

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { of } from 'rxjs';
import { map, take } from 'rxjs/operators';
import { environment } from 'src/environments/environment';
import { Library, LibraryType } from '../_models/library';
import { SearchResult } from '../_models/search-result';
@Injectable({
providedIn: 'root'
})
export class LibraryService {
baseUrl = environment.apiUrl;
private libraryNames: {[key:number]: string} | undefined = undefined;
private libraryTypes: {[key: number]: LibraryType} | undefined = undefined;
constructor(private httpClient: HttpClient) {}
getLibraryNames() {
if (this.libraryNames != undefined) {
return of(this.libraryNames);
}
return this.httpClient.get<Library[]>(this.baseUrl + 'library').pipe(map(l => {
this.libraryNames = {};
l.forEach(lib => {
if (this.libraryNames !== undefined) {
this.libraryNames[lib.id] = lib.name;
}
});
return this.libraryNames;
}));
}
listDirectories(rootPath: string) {
let query = '';
if (rootPath !== undefined && rootPath.length > 0) {
query = '?path=' + encodeURIComponent(rootPath);
}
return this.httpClient.get<string[]>(this.baseUrl + 'library/list' + query);
}
getLibraries() {
return this.httpClient.get<Library[]>(this.baseUrl + 'library');
}
getLibrariesForMember() {
return this.httpClient.get<Library[]>(this.baseUrl + 'library/libraries');
}
updateLibrariesForMember(username: string, selectedLibraries: Library[]) {
return this.httpClient.post(this.baseUrl + 'library/grant-access', {username, selectedLibraries});
}
scan(libraryId: number) {
return this.httpClient.post(this.baseUrl + 'library/scan?libraryId=' + libraryId, {});
}
refreshMetadata(libraryId: number) {
return this.httpClient.post(this.baseUrl + 'library/refresh-metadata?libraryId=' + libraryId, {});
}
create(model: {name: string, type: number, folders: string[]}) {
return this.httpClient.post(this.baseUrl + 'library/create', model);
}
delete(libraryId: number) {
return this.httpClient.delete(this.baseUrl + 'library/delete?libraryId=' + libraryId, {});
}
update(model: {name: string, folders: string[], id: number}) {
return this.httpClient.post(this.baseUrl + 'library/update', model);
}
getLibraryType(libraryId: number) {
if (this.libraryTypes != undefined && this.libraryTypes.hasOwnProperty(libraryId)) {
return of(this.libraryTypes[libraryId]);
}
return this.httpClient.get<LibraryType>(this.baseUrl + 'library/type?libraryId=' + libraryId).pipe(map(l => {
if (this.libraryTypes === undefined) {
this.libraryTypes = {};
}
this.libraryTypes[libraryId] = l;
return this.libraryTypes[libraryId];
}));
}
search(term: string) {
if (term === '') {
return of([]);
}
return this.httpClient.get<SearchResult[]>(this.baseUrl + 'library/search?queryString=' + encodeURIComponent(term));
}
}