Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 6805852
Author: Darryl L. Pierce <mcpierce@gmail.com>
Date:   Wed Mar 4 09:02:10 2020 -0500

    [Issue #168] Fix backend bugs.

commit b17acf5
Author: Darryl L. Pierce <mcpierce@gmail.com>
Date:   Wed Mar 4 08:55:38 2020 -0500

    [Issue #168] Fix sorting to not affect the underlying array.

commit fbb34dd
Author: Darryl L. Pierce <mcpierce@gmail.com>
Date:   Wed Mar 4 08:45:39 2020 -0500

    [Issue #168] Add id attribute to header tags.

commit 6c28e98
Author: Darryl L. Pierce <mcpierce@gmail.com>
Date:   Wed Mar 4 08:41:44 2020 -0500

    [Issue #168] Add alt tag to scraping page cover view.

commit d3e89d6
Author: Darryl L. Pierce <mcpierce@gmail.com>
Date:   Wed Mar 4 08:40:36 2020 -0500

    [Issue #168] Close open resources.
  • Loading branch information
mcpierce committed Jun 21, 2020
1 parent b818a3c commit 94e5703
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 88 deletions.
Expand Up @@ -2,7 +2,8 @@ <h2>{{'multi-comic-scraping-page.title'|translate:{count: comics.length} }}</h2>
<div class='ui-g'>
<div class='ui-g-3'>
<p-card *ngIf='currentComic'>
<img [src]='currentComic|comicCoverUrl'
<img alt='comic cover'
[src]='currentComic|comicCoverUrl'
width='100%'
height='auto'/>
</p-card>
Expand Down
Expand Up @@ -2,26 +2,24 @@
<div class="ui-g-12">
<h2>{{ 'reading-lists-page.title' | translate }}</h2>
<div class="cx-right-align-container">
<button
pButton
type="button"
[label]="'reading-lists-page.button.new-reading-list' | translate"
(click)="create_new_reading_list()"
<button pButton
type="button"
[label]="'reading-lists-page.button.new-reading-list' | translate"
(click)="create_new_reading_list()"
></button>
</div>
</div>
<div class="ui-g-12">
<p-table [value]="readingLists">
<ng-template pTemplate="header">
<tr>
<th>{{ 'reading-lists-page.table.headers.name' | translate }}</th>
<th>{{ 'reading-lists-page.table.headers.summary' | translate }}</th>
<th>
{{ 'reading-lists-page.table.headers.comic-count' | translate }}
</th>
<th id='reading-list-name'>{{ 'reading-lists-page.table.headers.name' | translate }}</th>
<th id='reading-list-summary'>{{ 'reading-lists-page.table.headers.summary' | translate }}</th>
<th id='reading-list-comic-count'>{{ 'reading-lists-page.table.headers.comic-count' | translate }}</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-list>
<ng-template pTemplate="body"
let-list>
<tr>
<td>
<a [routerLink]="['/lists', list.id]">{{ list.name }}</a>
Expand Down
Expand Up @@ -79,7 +79,7 @@ describe('Selection Reducer', () => {
comics: [COMIC_1, COMIC_2, COMIC_3]
})
);
expect(state.comics.sort((c1, c2) => c1.id - c2.id)).toEqual(
expect([...state.comics].sort((c1, c2) => c1.id - c2.id)).toEqual(
[COMIC_1, COMIC_3, COMIC_5, COMIC_2].sort((c1, c2) => c1.id - c2.id)
);
});
Expand Down
8 changes: 4 additions & 4 deletions comixed-frontend/src/app/library/utility.functions.spec.ts
Expand Up @@ -38,20 +38,20 @@ describe('Utility Functions', () => {

it('merges non-overlapping sets', () => {
expect(
mergeComics(NO_OVERLAP, UPDATE).sort(
[...mergeComics(NO_OVERLAP, UPDATE)].sort(
(left, right) => left.id - right.id
)
).toEqual(
NO_OVERLAP.concat(UPDATE).sort((left, right) => left.id - right.id)
[...NO_OVERLAP.concat(UPDATE)].sort((left, right) => left.id - right.id)
);
});

it('merges overlapping sets', () => {
expect(
mergeComics(SOME_OVERLAP, UPDATE).sort(
[...mergeComics(SOME_OVERLAP, UPDATE)].sort(
(left, right) => left.id - right.id
)
).toEqual(OVERLAP_UPDATED.sort((left, right) => left.id - right.id));
).toEqual([...OVERLAP_UPDATED].sort((left, right) => left.id - right.id));
});
});

Expand Down
@@ -1,11 +1,13 @@
<p-table [value]="user.preferences" [sortField]="'name'">
<p-table [value]="user.preferences"
[sortField]="'name'">
<ng-template pTemplate="header">
<tr>
<th>{{ 'account-preferences.label.preference-name' | translate }}</th>
<th>{{ 'account-preferences.label.preference-value' | translate }}</th>
<th id='user-preference-name'>{{ 'account-preferences.label.preference-name' | translate }}</th>
<th id='user-preference'>{{ 'account-preferences.label.preference-value' | translate }}</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-preference>
<ng-template pTemplate="body"
let-preference>
<tr>
<td>{{ preference.name }}</td>
<td>{{ preference.value }}</td>
Expand Down
@@ -1,16 +1,16 @@
<p-toolbar>
<div class='ui-toolbar-group-left'>
<button *ngIf='isAdmin'
pButton
type='button'
[style]='{ float: "right" }'
label='{{"admin.users.button.new-user"|translate}}'
icon='fa fa-fw fa-user-plus'
(click)='setNewUser()'></button>
</div>
<div class='ui-toolbar-group-right'>
<div class='ui-toolbar-group-left'>
<button *ngIf='isAdmin'
pButton
type='button'
[style]='{ float: "right" }'
label='{{"admin.users.button.new-user"|translate}}'
icon='fa fa-fw fa-user-plus'
(click)='setNewUser()'></button>
</div>
<div class='ui-toolbar-group-right'>

</div>
</div>
</p-toolbar>

<div *ngIf='current'
Expand All @@ -31,33 +31,31 @@ <h2>{{current?.email || "admin.user-editor.label.new-user"|translate}}</h2>
selectionMode='single'
(onRowSelect)='setCurrentUser($event.data)'
(onRowUnselect)='setCurrentUser(null)'>
<ng-template pTemplate='header'>
<tr>
<th></th>
<th>{{'admin.users.label.email'|translate}}</th>
<th>{{'admin.users.label.roles'|translate}}</th>
<th>{{'admin.users.label.member-since'|translate}}</th>
<th>{{'admin.users.label.last-logged-on'|translate}}</th>
<th></th>
</tr>
</ng-template>
<ng-template pTemplate='body'
let-user>
<tr [pSelectableRow]='user'>
<td>
<button pButton
type='button'
icon='fa fa-fw fa-user-times'
pTooltip='{{(user.id === loggedInUser.id ? "users-page.text.cant-delete-yourself" : "users-page.text.delete-user")|translate}}'
(click)='deleteUser(user)'></button>
</td>
<td>{{user.email}}</td>
<td>
<span *ngFor='let role of user.roles'>[{{role.name}}]</span>
</td>
<td>{{user.first_login_date|date: 'medium'}}</td>
<td>{{user.last_login_date|date: 'medium'}}</td>
<td></td>
</tr>
</ng-template>
<ng-template pTemplate='header'>
<tr>
<th id='user-list-action'></th>
<th id='user-list-email'>{{'admin.users.label.email'|translate}}</th>
<th id='user-list-roles'>{{'admin.users.label.roles'|translate}}</th>
<th id='user-list-member-since'>{{'admin.users.label.member-since'|translate}}</th>
<th id='user-list-last-logged-in'>{{'admin.users.label.last-logged-on'|translate}}</th>
</tr>
</ng-template>
<ng-template pTemplate='body'
let-user>
<tr [pSelectableRow]='user'>
<td>
<button pButton
type='button'
icon='fa fa-fw fa-user-times'
pTooltip='{{(user.id === loggedInUser.id ? "users-page.text.cant-delete-yourself" : "users-page.text.delete-user")|translate}}'
(click)='deleteUser(user)'></button>
</td>
<td>{{user.email}}</td>
<td>
<span *ngFor='let role of user.roles'>[{{role.name}}]</span>
</td>
<td>{{user.first_login_date|date: 'medium'}}</td>
<td>{{user.last_login_date|date: 'medium'}}</td>
</tr>
</ng-template>
</p-table>
Expand Up @@ -135,7 +135,7 @@ protected ZipFile openArchive(File comicFile) throws ArchiveAdaptorException {

@Override
void saveComicInternal(Comic source, String filename, boolean renamePages)
throws ArchiveAdaptorException {
throws ArchiveAdaptorException, IOException {
logger.debug("Creating temporary file: " + filename);

ZipArchiveOutputStream zoutput = null;
Expand Down Expand Up @@ -171,11 +171,13 @@ void saveComicInternal(Comic source, String filename, boolean renamePages)
zoutput.write(page.getContent());
zoutput.closeArchiveEntry();
}

zoutput.finish();
zoutput.close();
} catch (IOException | ArchiveException error) {
throw new ArchiveAdaptorException("error creating comic archive", error);
} finally {
if (zoutput != null) {
zoutput.finish();
zoutput.close();
}
}
}

Expand Down
Expand Up @@ -164,7 +164,11 @@ public void clearRoles() {
}

public void deleteProperty(final String name) {
this.preferences.remove(name);
for (int index = 0; index < this.preferences.size(); index++) {
if (this.preferences.get(index).getName().equals(name)) {
this.preferences.remove(index);
}
}
}

public List<Bookmark> getBookmarks() {
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import org.comixed.adaptors.ComicDataAdaptor;
import org.comixed.adaptors.archive.ArchiveAdaptorException;
import org.comixed.handlers.ComicFileHandlerException;
Expand All @@ -37,7 +38,6 @@
import org.comixed.net.GetLibraryUpdatesResponse;
import org.comixed.repositories.ComiXedUserRepository;
import org.comixed.repositories.library.ComicFormatRepository;
import org.comixed.repositories.library.ComicRepository;
import org.comixed.repositories.library.LastReadDatesRepository;
import org.comixed.repositories.library.ScanTypeRepository;
import org.comixed.service.file.FileService;
Expand Down Expand Up @@ -70,7 +70,6 @@ public class ComicController {
@Autowired private PageCacheService pageCacheService;
@Autowired private FileService fileService;
@Autowired private FileTypeIdentifier fileTypeIdentifier;
@Autowired private ComicRepository comicRepository;
@Autowired private ComiXedUserRepository userRepository;
@Autowired private LastReadDatesRepository lastReadRepository;
@Autowired private ScanTypeRepository scanTypeRepository;
Expand All @@ -89,16 +88,16 @@ public Comic deleteComic(@PathVariable("id") long id) throws ComicException {

@RequestMapping(value = "/{id}/metadata", method = RequestMethod.DELETE)
@JsonView(ComicDetails.class)
public Comic deleteMetadata(@PathVariable("id") long id) {
public Comic deleteMetadata(@PathVariable("id") long id) throws ComicException {
this.logger.debug("Updating comic: id={}", id);

Comic comic = this.comicRepository.findById(id).get();
Comic comic = this.comicService.getComic(id);

if (comic != null) {
this.logger.debug("Clearing metadata for comic");
this.comicDataAdaptor.clear(comic);
this.logger.debug("Saving updates to comic");
this.comicRepository.save(comic);
this.comicService.save(comic);
ComicController.stopWaitingForStatus();
} else {
this.logger.debug("No such comic found");
Expand Down Expand Up @@ -263,50 +262,52 @@ public int rescanComics() {
}

@RequestMapping(value = "/{id}/format", method = RequestMethod.PUT)
public void setFormat(
@PathVariable("id") long comicId, @RequestParam("format_id") long formatId) {
public void setFormat(@PathVariable("id") long comicId, @RequestParam("format_id") long formatId)
throws ComicException {
this.logger.debug("Setting format: comicId={} formatId={}", comicId, formatId);

Comic comic = this.comicRepository.findById(comicId).get();
ComicFormat format = this.comicFormatRepository.findById(formatId).get();
Comic comic = this.comicService.getComic(comicId);
Optional<ComicFormat> formatRecord = this.comicFormatRepository.findById(formatId);

if (comic != null) {
comic.setFormat(format);
if (comic != null && formatRecord.isPresent()) {
comic.setFormat(formatRecord.get());
this.logger.debug("Saving update to comic");
this.comicRepository.save(comic);
this.comicService.save(comic);
} else {
this.logger.debug("No such comic found");
}
}

@RequestMapping(value = "/{id}/scan_type", method = RequestMethod.PUT)
public void setScanType(
@PathVariable("id") long comicId, @RequestParam("scan_type_id") long scanTypeId) {
@PathVariable("id") long comicId, @RequestParam("scan_type_id") long scanTypeId)
throws ComicException {
this.logger.debug("Setting scan type: comicId={} scanTypeId={}", comicId, scanTypeId);

Comic comic = this.comicRepository.findById(comicId).get();
ScanType scanType = this.scanTypeRepository.findById(scanTypeId).get();
Comic comic = this.comicService.getComic(comicId);
Optional<ScanType> scanTypeRecord = this.scanTypeRepository.findById(scanTypeId);

if (comic != null) {
comic.setScanType(scanType);
if (comic != null && scanTypeRecord.isPresent()) {
comic.setScanType(scanTypeRecord.get());
this.logger.debug("Saving update to comic");
this.comicRepository.save(comic);
this.comicService.save(comic);
} else {
this.logger.debug("No such comic found");
}
}

@RequestMapping(value = "/{id}/sort_name", method = RequestMethod.PUT)
public void setSortName(
@PathVariable("id") long comicId, @RequestParam("sort_name") String sortName) {
@PathVariable("id") long comicId, @RequestParam("sort_name") String sortName)
throws ComicException {
this.logger.debug("Setting sort name: comicId={} sortName={}", comicId, sortName);

Comic comic = this.comicRepository.findById(comicId).get();
Comic comic = this.comicService.getComic(comicId);

if (comic != null) {
comic.setSortName(sortName);
this.logger.debug("Saving update to comic");
this.comicRepository.save(comic);
this.comicService.save(comic);
} else {
this.logger.debug("No such comic found");
}
Expand Down
Expand Up @@ -104,6 +104,7 @@ public GetUpdatedComicsResponse getUpdatedComics(
Thread.sleep(1000L);
} catch (InterruptedException error) {
this.log.error("error while waiting for updates", error);
Thread.currentThread().interrupt();
}
}
}
Expand Down
Expand Up @@ -125,7 +125,7 @@ public ReadingList getReadingListForUser(final String email, final long id)
if (readingList.isPresent()) {
final ComiXedUser owner = readingList.get().getOwner();

if (owner.getId() == user.getId()) {
if (owner.getId().equals(user.getId())) {
return readingList.get();
}

Expand Down
Expand Up @@ -84,6 +84,7 @@ public void addTasksToQueue(WorkerTask task) {

} catch (InterruptedException error) {
this.logger.error("Unable to queue task", error);
Thread.currentThread().interrupt();
}
this.logger.debug("Queue size is now {}", this.queue.size());
this.wakeUpWorker();
Expand Down Expand Up @@ -151,6 +152,7 @@ public void run() {
}
} catch (InterruptedException cause) {
this.logger.error("Worker interrupted", cause);
Thread.currentThread().interrupt();
}
}
if (!this.queue.isEmpty() && (this.state != State.STOP)) {
Expand Down

0 comments on commit 94e5703

Please sign in to comment.