Skip to content

Commit

Permalink
Merge pull request #186 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Add last update date time on DTOs
  • Loading branch information
Ziedelth authored Feb 14, 2024
2 parents edaec5a + 7df00dd commit 1c6c259
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ package fr.shikkanime.converters.episode
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.EpisodeDto
import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.entities.Episode
import fr.shikkanime.utils.withUTC
import org.apache.tika.language.detect.LanguageDetector
import java.time.format.DateTimeFormatter

class EpisodeToEpisodeDtoConverter : AbstractConverter<Episode, EpisodeDto>() {
private val languageDetector: LanguageDetector = LanguageDetector.getDefaultLanguageDetector().loadModels()

override fun convert(from: Episode): EpisodeDto {
val status = if (
from.image.isNullOrBlank() ||
from.description.isNullOrBlank() ||
from.description?.startsWith("(") == true ||
languageDetector.detect(from.description).language.lowercase() != from.anime!!.countryCode!!.name.lowercase()
) Status.INVALID else Status.VALID

return EpisodeDto(
uuid = from.uuid,
platform = from.platform!!,
Expand All @@ -25,7 +36,8 @@ class EpisodeToEpisodeDtoConverter : AbstractConverter<Episode, EpisodeDto>() {
duration = from.duration,
description = from.description,
uncensored = from.image!!.contains("nc/", true),
lastUpdateDateTime = from.lastUpdateDateTime?.withUTC()?.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
lastUpdateDateTime = from.lastUpdateDateTime?.withUTC()?.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME),
status = status,
)
}
}
2 changes: 2 additions & 0 deletions src/main/kotlin/fr/shikkanime/dtos/EpisodeDto.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.shikkanime.dtos

import fr.shikkanime.dtos.animes.AnimeDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.entities.enums.EpisodeType
import fr.shikkanime.entities.enums.LangType
import fr.shikkanime.entities.enums.Platform
Expand All @@ -24,4 +25,5 @@ data class EpisodeDto(
val description: String?,
val uncensored: Boolean,
val lastUpdateDateTime: String?,
val status: Status? = null,
) : Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class EpisodeRepository : AbstractRepository<Episode>() {
}

private fun buildSortQuery(sort: List<SortParameter>, query: StringBuilder) {
val fields = listOf("episodeType", "langType", "releaseDateTime", "season", "number")
val fields = listOf("episodeType", "langType", "releaseDateTime", "season", "number", "lastUpdateDateTime")
val subQuery = mutableListOf<String>()

sort.filter { fields.contains(it.field) }.forEach { param ->
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/fr/shikkanime/services/EpisodeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class EpisodeService : AbstractService<Episode, EpisodeRepository>() {

parameters["duration"]?.takeIf { it.isNotBlank() }?.let { episode.duration = it.toLong() }
parameters["description"]?.takeIf { it.isNotBlank() }?.let { episode.description = it }
episode.lastUpdateDateTime = ZonedDateTime.now()

val update = super.update(episode)
MapCache.invalidate(Episode::class.java)
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/templates/admin/episodes/edit.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@
<input type="datetime-local" class="form-control" id="releaseDateTime" name="releaseDateTime"
value="${episode.releaseDateTime?keep_before_last(":")}">
</div>
<div class="col-md-6">
<label for="lastUpdateDateTime" class="form-label">Last update date time</label>
<input type="datetime-local" class="form-control disabled" id="lastUpdateDateTime"
name="lastUpdateDateTime"
value="<#if episode.lastUpdateDateTime??>${episode.lastUpdateDateTime?keep_before_last(":")}</#if>"
disabled>
</div>
<div class="col-md-6">
<label for="season" class="form-label">Season</label>
<input type="number" class="form-control" id="season" name="season" value="${episode.season?c}">
Expand Down
59 changes: 46 additions & 13 deletions src/main/resources/templates/admin/episodes/list.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
<tr>
<th scope="col">Anime</th>
<th scope="col">Platform</th>
<th scope="col">Episode type</th>
<th scope="col">Lang type</th>
<th scope="col">Season</th>
<th scope="col">Number</th>
<th scope="col">Details</th>
<th scope="col">Description</th>
<th scope="col">Actions</th>
</tr>
</thead>
Expand All @@ -34,14 +32,40 @@
</div>

<script>
function buildTableElement(uuid, anime, platform, episodeType, langType, season, number) {
function buildTableElement(uuid, anime, platform, episodeType, langType, season, number, description, status) {
let episodeTypePrefix = '';
switch (episodeType) {
case 'EPISODE':
episodeTypePrefix = 'EP';
break;
case 'SPECIAL':
episodeTypePrefix = 'SP';
break;
case 'FILM':
episodeTypePrefix = 'MOV';
break;
}
let langTypePrefix = '';
switch (langType) {
case 'SUBTITLES':
langTypePrefix = 'SUB';
break;
case 'VOICE':
langTypePrefix = 'DUB';
break;
}
const details = 'S' + season + ' ' + episodeTypePrefix + number + ' ' + langTypePrefix;
const isInvalid = status === 'INVALID';
return `<tr>
<th scope="row">` + anime + `</th>
<th scope="row"><span class="me-2 badge bg-` + (isInvalid ? 'danger' : 'success') + `">` + (isInvalid ? 'Invalid' : 'Valid') + `</span>` + anime + `</th>
<td>` + platform + `</td>
<td>` + episodeType + `</td>
<td>` + langType + `</td>
<td>` + season + `</td>
<td>` + number + `</td>
<td>` + details + `</td>
<td>` + description + `</td>
<td>
<a href="/admin/episodes/` + uuid + `" class="btn btn-warning">
<i class="bi bi-pencil-square"></i>
Expand All @@ -52,7 +76,7 @@
}
async function getEpisodes(anime, page) {
let params = '?sort=releaseDateTime&desc=releaseDateTime';
let params = '?sort=lastUpdateDateTime&desc=lastUpdateDateTime';
if (anime) {
params = '?anime=' + anime;
Expand All @@ -63,11 +87,20 @@
function buildTable(episodes) {
const table = document.getElementById('episodes-table');
table.innerHTML = '';
episodes.forEach(episode => {
table.innerHTML += buildTableElement(episode.uuid, episode.anime.name, episode.platform, episode.episodeType, episode.langType, episode.season, episode.number);
table.innerHTML += buildTableElement(
episode.uuid,
episode.anime.shortName,
episode.platform,
episode.episodeType,
episode.langType,
episode.season,
episode.number,
episode.description || '',
episode.status,
);
});
}
Expand Down

0 comments on commit 1c6c259

Please sign in to comment.