Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a last updated field to LastReadDate #357

Merged
merged 6 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
-Dsonar.organization=comixed
-Dsonar.projectKey=comixed_comixed
-Dsonar.sources=./src
-Dsonar.exclusions=**/*test*/**
-Dsonar.test.inclusions=**/*test*/**
-Dsonar.exclusions=**/*test*/**,**/*spec.ts
-Dsonar.test.inclusions=**/*test*/**,**/*spec.ts
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
-Pci
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@
<strong>{{"comic-overview.label.last-read-date"|translate}}</strong>
</div>
<div class='ui-g-12'>
{{ "Never"}}
<span *ngIf='!comic.lastReadDate'>{{'comic-overview.text.never-read'|translate}}</span>
<span *ngIf='comic.lastReadDate'>{{comic.lastReadDate|date:'medium'}}</span>
</div>
<div class='ui-g-12'>
<strong>{{"comic-overview.label.page-count"|translate}}</strong>
Expand Down
1 change: 1 addition & 0 deletions comixed-frontend/src/app/comics/models/comic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ export interface Comic {
pages?: Page[];
duplicateCount?: number;
readingLists: ReadingList[];
lastReadDate?: number;
}
22 changes: 22 additions & 0 deletions comixed-frontend/src/app/library/adaptors/library.adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,20 @@ export class LibraryAdaptor {
) {
this._latestUpdatedDate$.next(state.latestUpdatedDate);
}
let updatedLastReadDates = false;
if (!_.isEqual(this._lastReadDate$.getValue(), state.lastReadDates)) {
this.logger.info('updating last read dates');
this._lastReadDate$.next(state.lastReadDates);
updatedLastReadDates = true;
}
if (this._comicCount$.getValue() !== state.comicCount) {
this._comicCount$.next(state.comicCount);
}
this._fetchingUpdate$.next(state.fetchingUpdates);
let updatedComics = false;
if (!_.isEqual(this._comic$.getValue(), state.comics)) {
updatedComics = true;
this.logger.info('updating comics');
this._comic$.next(state.comics);
this._publishers$.next(
extractField(state.comics, CollectionType.PUBLISHERS)
Expand Down Expand Up @@ -159,6 +165,22 @@ export class LibraryAdaptor {
if (state.consolidating !== this._consolidating$.getValue()) {
this._consolidating$.next(state.consolidating);
}

// if either the last read dates or comics have changed then update all comics' last read date
this.logger.debug(`updatedLastReadDates=${updatedLastReadDates}`);
this.logger.debug(`updatedComics=${updatedComics}`);
if (updatedLastReadDates || updatedComics) {
this.logger.trace('Merging last read dates into library');
state.comics.forEach(comic => {
const lastReadDate = state.lastReadDates.find(
entry => entry.comicId === comic.id
);
comic.lastReadDate = !!lastReadDate
? lastReadDate.lastReadDate
: null;
});
this._comic$.next(state.comics);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
*/

import { COMIC_1 } from '../../comics/models/comic.fixtures';
import { USER_READER } from 'app/user';
import { LastReadDate } from 'app/library/models/last-read-date';

export const COMIC_1_LAST_READ_DATE = {
id: 1,
comic_id: COMIC_1.id,
user_id: USER_READER.id,
last_read_date: 65535
export const COMIC_1_LAST_READ_DATE: LastReadDate = {
comicId: COMIC_1.id,
lastReadDate: 65535,
lastUpdated: 65536
};
7 changes: 3 additions & 4 deletions comixed-frontend/src/app/library/models/last-read-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/

export interface LastReadDate {
id: number;
comic_id: number;
user_id: number;
last_read_date: number;
comicId: number;
lastReadDate: number;
lastUpdated: number;
}
3 changes: 2 additions & 1 deletion comixed-frontend/src/assets/i18n/en/comics.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
"format-placeholder": "Click to set format...",
"scan-type-placeholder": "Click to set scan type...",
"sort-name-placeholder": "Click to set a sort name...",
"comicvine-details-link": "The details can be found <a href='http://comicvine.gamespot.com/issue/4000-{comicVineId}'>here</a>."
"comicvine-details-link": "The details can be found <a href='http://comicvine.gamespot.com/issue/4000-{comicVineId}'>here</a>.",
"never-read": "Never"
},
"scan-type": {
"option": {
Expand Down
3 changes: 2 additions & 1 deletion comixed-frontend/src/assets/i18n/es/comics.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
"format-placeholder": "Click to set format...",
"scan-type-placeholder": "Click to set scan type...",
"sort-name-placeholder": "Click to set a sort name...",
"comicvine-details-link": "The details can be found <a href='http://comicvine.gamespot.com/issue/4000-{comicVineId}'>here</a>."
"comicvine-details-link": "The details can be found <a href='http://comicvine.gamespot.com/issue/4000-{comicVineId}'>here</a>.",
"never-read": "Never"
},
"scan-type": {
"option": {
Expand Down
3 changes: 2 additions & 1 deletion comixed-frontend/src/assets/i18n/fr/comics.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@
"format-placeholder": "Click to set format...",
"scan-type-placeholder": "Click to set scan type...",
"sort-name-placeholder": "Click to set a sort name...",
"comicvine-details-link": "The details can be found <a href='http://comicvine.gamespot.com/issue/4000-{comicVineId}'>here</a>."
"comicvine-details-link": "The details can be found <a href='http://comicvine.gamespot.com/issue/4000-{comicVineId}'>here</a>.",
"never-read": "Never"
},
"scan-type": {
"option": {
Expand Down
63 changes: 31 additions & 32 deletions comixed-library/src/main/java/org/comixed/model/comic/Comic.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
public class Comic {
@Enumerated(EnumType.STRING)
@JsonProperty("archiveType")
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
ArchiveType archiveType;

@Transient @JsonIgnore File backingFile;
Expand All @@ -71,9 +71,7 @@ public class Comic {
@OneToMany(mappedBy = "comic", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderColumn(name = "page_number")
@JsonProperty("pages")
@JsonView({
View.ComicDetails.class,
})
@JsonView({View.ComicDetails.class, View.LibraryUpdate.class})
List<Page> pages = new ArrayList<>();

@OneToMany(mappedBy = "comic", cascade = CascadeType.ALL, orphanRemoval = true)
Expand All @@ -91,30 +89,30 @@ public class Comic {
View.DeletedComicList.class,
View.PageList.class,
View.DuplicatePageList.class,
View.DatabaseBackup.class,
View.LibraryUpdate.class,
View.ReadingList.class
})
private Long id;

@ManyToOne
@JoinColumn(name = "scan_type_id")
@JsonProperty("scanType")
@JsonView({View.ComicList.class, View.PageList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.PageList.class, View.LibraryUpdate.class})
private ScanType scanType;

@ManyToOne
@JoinColumn(name = "format_id")
@JsonProperty("format")
@JsonView({View.ComicList.class, View.PageList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.PageList.class, View.LibraryUpdate.class})
private ComicFormat format;

@Column(name = "filename", nullable = false, unique = true, length = 1024)
@JsonProperty("filename")
@JsonView({View.ComicList.class, View.PageList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.PageList.class, View.LibraryUpdate.class})
private String filename;

@OneToOne(cascade = CascadeType.ALL, mappedBy = "comic", orphanRemoval = true)
@JsonView({View.ComicList.class, View.ComicDetails.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private ComicFileDetails fileDetails;

@Formula(value = "(SELECT COUNT(*) FROM pages p WHERE p.comic_id = id)")
Expand All @@ -129,27 +127,27 @@ public class Comic {
@Column(name = "added_date", updatable = false, nullable = false)
@JsonProperty("addedDate")
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
@Temporal(TemporalType.TIMESTAMP)
private Date dateAdded = new Date();

@Column(name = "deleted_date", updatable = true, nullable = true)
@JsonProperty("deletedDate")
@JsonFormat(shape = Shape.NUMBER)
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
@Temporal(TemporalType.TIMESTAMP)
private Date dateDeleted;

@Column(name = "last_updated_date", updatable = true, nullable = false)
@JsonProperty("lastUpdatedDate")
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
@Temporal(TemporalType.TIMESTAMP)
private Date dateLastUpdated = new Date();

@Column(name = "publisher", length = 128)
@JsonProperty("publisher")
@JsonView({View.ComicList.class, View.DuplicatePageList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.DuplicatePageList.class, View.LibraryUpdate.class})
private String publisher;

@Column(name = "series", length = 128)
Expand All @@ -158,7 +156,7 @@ public class Comic {
View.ComicList.class,
View.PageList.class,
View.DuplicatePageList.class,
View.DatabaseBackup.class
View.LibraryUpdate.class
})
private String series;

Expand All @@ -168,7 +166,7 @@ public class Comic {
View.ComicList.class,
View.PageList.class,
View.DuplicatePageList.class,
View.DatabaseBackup.class
View.LibraryUpdate.class
})
private String volume;

Expand All @@ -178,58 +176,58 @@ public class Comic {
View.ComicList.class,
View.PageList.class,
View.DuplicatePageList.class,
View.DatabaseBackup.class
View.LibraryUpdate.class
})
private String issueNumber;

@Column(name = "imprint")
@JsonProperty("imprint")
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private String imprint;

@Column(name = "comic_vine_id", length = 16)
@JsonProperty("comicVineId")
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private String comicVineId;

@Column(name = "cover_date", nullable = true)
@Temporal(TemporalType.DATE)
@JsonProperty("coverDate")
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private Date coverDate;

@Column(name = "title", length = 128)
@JsonProperty("title")
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private String title;

@Column(name = "sort_name", length = 128)
@JsonProperty("sortName")
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private String sortName;

@ElementCollection
@LazyCollection(LazyCollectionOption.FALSE)
@CollectionTable(name = "comic_characters", joinColumns = @JoinColumn(name = "comic_id"))
@Column(name = "character_name")
@JsonProperty("characters")
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private List<String> characters = new ArrayList<>();

@ElementCollection
@LazyCollection(LazyCollectionOption.FALSE)
@CollectionTable(name = "comic_teams", joinColumns = @JoinColumn(name = "comic_id"))
@Column(name = "team_name")
@JsonProperty("teams")
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private List<String> teams = new ArrayList<>();

@ElementCollection
@LazyCollection(LazyCollectionOption.FALSE)
@CollectionTable(name = "comic_locations", joinColumns = @JoinColumn(name = "comic_id"))
@Column(name = "location_name")
@JsonProperty("locations")
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private List<String> locations = new ArrayList<>();

@OneToMany(
Expand All @@ -238,7 +236,7 @@ public class Comic {
fetch = FetchType.EAGER,
orphanRemoval = true)
@JsonProperty("credits")
@JsonView({View.ComicList.class, View.DatabaseBackup.class})
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private Set<Credit> credits = new HashSet<>();

@Transient
Expand All @@ -255,47 +253,48 @@ public class Comic {
value =
"(SELECT COUNT(*) FROM pages p WHERE p.comic_id = id AND p.hash in (SELECT d.hash FROM blocked_page_hashes d))")
@JsonProperty("blockedPageCount")
@JsonView(View.ComicList.class)
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private int blockedPageCount;

@Transient
@JsonProperty("comicVineURL")
@JsonView({View.ComicDetails.class, View.DatabaseBackup.class})
@JsonView({View.ComicDetails.class, View.LibraryUpdate.class})
private String comicVineURL;

@Column(name = "description")
@Lob
@JsonProperty("description")
@JsonView({View.ComicDetails.class, View.DatabaseBackup.class})
@JsonView({View.ComicDetails.class})
private String description;

@Column(name = "notes")
@Lob
@JsonProperty("notes")
@JsonView({View.ComicDetails.class, View.DatabaseBackup.class})
@JsonView({View.ComicDetails.class})
private String notes;

@Column(name = "summary")
@Lob
@JsonProperty("summary")
@JsonView({View.ComicDetails.class, View.DatabaseBackup.class})
@JsonView({View.ComicDetails.class})
private String summary;

@Formula(
"(SELECT COUNT(*) FROM comics c WHERE c.series = series AND c.volume = volume AND c.issue_number = issue_number AND c.cover_date = cover_date)")
@JsonProperty("duplicateCount")
@JsonView(View.ComicList.class)
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private Integer duplicateCount;

@ManyToMany(mappedBy = "comics", cascade = CascadeType.ALL)
@JsonProperty("readingLists")
@JsonView(View.ComicList.class)
@JsonView({View.ComicList.class, View.LibraryUpdate.class})
private Set<ReadingList> readingLists = new HashSet<>();

@OneToMany(mappedBy = "comic", cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<Task> tasks = new ArrayList<>();

@OneToMany(mappedBy = "comic", cascade = CascadeType.REMOVE, orphanRemoval = true)
@JsonIgnore
private List<LastReadDate> lastReadDates = new ArrayList<>();

public Date getDateLastUpdated() {
Expand Down