mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Adds per-library progress settings to library management
This commit is contained in:
1 parent
8011c532a1
commit
0b5b65391c
13 files changed
+314
-2
No files matched your search
@@ -68,6 +68,17 @@ public class LibraryDto
|
||||
/// </summary>
|
||||
public bool ShouldSkipUnchangedDirectoriesDuringScan { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the consumption progress of the media library items is tracked, or not. When absent, the default of the library type is used on create, and the stored value is kept on update.
|
||||
/// </summary>
|
||||
public bool? ShouldTrackConsumptionProgress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the percentage of a media library item that must be consumed for its session to be considered completed. When absent, the default of the library type is used on create,
|
||||
/// and the stored value is kept on update.
|
||||
/// </summary>
|
||||
public int? CompletionThresholdPercentage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ordered parts of the template describing the structure of the media library on disk.
|
||||
/// </summary>
|
||||
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>معرف الكتاب</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>تتبع تقدم الاستهلاك</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>ما إذا كان يتم تذكر موضع التشغيل أو القراءة لعناصر هذه المكتبة، حتى يتمكن المستخدم من المتابعة من حيث توقف.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>حد الإكمال (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>النسبة المئوية من العنصر التي يجب استهلاكها لاعتبار جلسته مكتملة. عند تركه فارغًا، تُستخدم القيمة الافتراضية لنوع المكتبة عند إنشاء مكتبة أو عند تفعيل تتبع التقدم، وتُحتفظ القيمة المخزنة عند تحرير مكتبة تتبع التقدم بالفعل. الأنواع التي ليس لها حد افتراضي تسجل الإكمال فقط عند الإبلاغ عنه صراحةً.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>يجب أن يكون حد الإكمال عددًا صحيحًا بين 0 و100.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>Buch-ID</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Konsumfortschritt Verfolgen</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Ob die Wiedergabe- oder Leseposition der Elemente dieser Bibliothek gespeichert wird, damit der Benutzer dort fortsetzen kann, wo er aufgehört hat.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Abschlussschwelle (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Der Prozentsatz eines Elements, der konsumiert werden muss, damit seine Sitzung als abgeschlossen gilt. Wenn das Feld leer bleibt, wird der Standardwert des Bibliothekstyps beim Erstellen einer Bibliothek oder beim Aktivieren der Fortschrittsverfolgung verwendet; beim Bearbeiten einer Bibliothek, die den Fortschritt bereits verfolgt, bleibt die gespeicherte Schwelle erhalten. Typen ohne Standardschwelle erfassen den Abschluss nur bei ausdrücklicher Meldung.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>Die Abschlussschwelle muss eine ganze Zahl zwischen 0 und 100 sein.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>Book id</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Track Consumption Progress</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Whether the playback or reading position of this library's items is remembered, so the user can resume where they left off.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Completion Threshold (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>The percentage of an item that must be consumed for its session to be considered completed. When empty, the default of the library type is used when creating a library or enabling progress tracking, and the stored threshold is kept when editing a library that already tracks progress. Types without a default threshold record completion only when it is reported explicitly.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>The completion threshold must be a whole number between 0 and 100.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>Id del libro</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Rastrear El Progreso Del Consumo</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Si se recuerda la posición de reproducción o lectura de los elementos de esta biblioteca, para que el usuario pueda continuar donde lo dejó.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Umbral De Finalización (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>El porcentaje de un elemento que debe consumirse para que su sesión se considere completada. Si se deja vacío, se usa el valor predeterminado del tipo de biblioteca al crear una biblioteca o al activar el seguimiento del progreso, y se conserva el valor almacenado al editar una biblioteca que ya lo sigue. Los tipos sin umbral predeterminado registran la finalización solo cuando se informa explícitamente.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>El umbral de finalización debe ser un número entero entre 0 y 100.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>Id du livre</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Suivre La Progression De Consommation</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Si la position de lecture ou de visionnage des éléments de cette bibliothèque est mémorisée, afin que l'utilisateur puisse reprendre là où il s'est arrêté.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Seuil d'achèvement (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Le pourcentage d'un élément qui doit être consommé pour que sa session soit considérée comme terminée. S'il est vide, la valeur par défaut du type de bibliothèque est utilisée lors de la création d'une bibliothèque ou de l'activation du suivi de la progression, et la valeur enregistrée est conservée lors de la modification d'une bibliothèque qui suit déjà la progression. Les types sans seuil par défaut enregistrent l'achèvement uniquement lorsqu'il est signalé explicitement.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>Le seuil d'achèvement doit être un nombre entier compris entre 0 et 100.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>Id del libro</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Monitora Il Progresso Di Consumo</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Se la posizione di riproduzione o di lettura degli elementi di questa libreria viene ricordata, così che l'utente possa riprendere da dove si era interrotto.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Soglia Di Completamento (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>La percentuale di un elemento che deve essere consumata perché la sua sessione sia considerata completata. Se lasciato vuoto, viene usato il valore predefinito del tipo di libreria quando si crea una libreria o si attiva il monitoraggio del progresso, mentre il valore salvato viene mantenuto quando si modifica una libreria che monitora già il progresso. I tipi senza soglia predefinita registrano il completamento solo quando viene segnalato esplicitamente.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>La soglia di completamento deve essere un numero intero compreso tra 0 e 100.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>書籍ID</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>進行状況を記録</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>このライブラリの項目の再生位置または閲覧位置を記憶し、ユーザーが中断した場所から再開できるようにするかどうか。</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>完了しきい値 (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>項目のセッションを完了とみなすために消費する必要がある割合。空欄の場合、ライブラリの作成時または進行状況の追跡を有効にするときはライブラリの種類の既定値が使用され、すでに進行状況を追跡しているライブラリの編集時は保存されているしきい値が維持されます。既定のしきい値がない種類では、明示的に報告された場合にのみ完了を記録します。</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>完了しきい値は 0 から 100 の間の整数である必要があります。</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>Book id</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Track Consumption Progress</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Whether the playback or reading position of this library's items is remembered, so the user can resume where they left off.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Completion Threshold (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>The percentage of an item that must be consumed for its session to be considered completed. When empty, the default of the library type is used when creating a library or enabling progress tracking, and the stored threshold is kept when editing a library that already tracks progress. Types without a default threshold record completion only when it is reported explicitly.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>The completion threshold must be a whole number between 0 and 100.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>Id-ul cărții</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Urmărește Progresul Consumului</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Dacă poziția de redare sau de citire a elementelor acestei biblioteci este reținută, astfel încât utilizatorul să poată relua de unde a rămas.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Prag De Finalizare (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Procentul unui element care trebuie consumat pentru ca sesiunea sa să fie considerată finalizată. Dacă este lăsat gol, se folosește valoarea implicită a tipului de bibliotecă la crearea unei biblioteci sau la activarea urmăririi progresului, iar valoarea salvată este păstrată la editarea unei biblioteci care urmărește deja progresul. Tipurile fără un prag implicit înregistrează finalizarea doar când este raportată explicit.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>Pragul de finalizare trebuie să fie un număr întreg între 0 și 100.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>Ідентифікатор книги</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Відстежувати прогрес споживання</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>Чи запам'ятовується позиція відтворення або читання елементів цієї бібліотеки, щоб користувач міг продовжити з того місця, де зупинився.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Поріг завершення (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>Відсоток елемента, який потрібно спожити, щоб його сеанс вважався завершеним. Якщо залишити порожнім, типове значення типу бібліотеки використовується під час створення бібліотеки або ввімкнення відстеження прогресу, а збережене значення зберігається під час редагування бібліотеки, яка вже відстежує прогрес. Типи без типового порогу фіксують завершення лише тоді, коли його явно повідомлено.</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>Поріг завершення має бути цілим числом від 0 до 100.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="PathPartBookId" xml:space="preserve">
|
||||
<value>书籍编号</value>
|
||||
</data>
|
||||
<data name="ShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>跟踪消费进度</value>
|
||||
</data>
|
||||
<data name="DescriptionShouldTrackConsumptionProgress" xml:space="preserve">
|
||||
<value>是否记住此媒体库项目的播放或阅读位置,以便用户可以从上次停止的地方继续。</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>完成阈值 (%)</value>
|
||||
</data>
|
||||
<data name="DescriptionCompletionThresholdPercentage" xml:space="preserve">
|
||||
<value>为了使某个项目的会话被视为已完成,必须消费的百分比。留空时,创建媒体库或启用进度跟踪会使用该类型的默认值,而编辑已在跟踪进度的媒体库时会保留已存储的阈值。没有默认阈值的类型仅在明确报告时记录完成。</value>
|
||||
</data>
|
||||
<data name="CompletionThresholdPercentageValidation" xml:space="preserve">
|
||||
<value>完成阈值必须是介于 0 和 100 之间的整数。</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
@{
|
||||
var id = Context.Request.RouteValues["id"] as string;
|
||||
var shouldTrackConsumptionProgress = Model.ShouldTrackConsumptionProgress ?? false;
|
||||
// Generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler.
|
||||
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
||||
}
|
||||
@@ -23,7 +24,7 @@
|
||||
<div style="min-height: 1rem;"></div><!-- The first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position. -->
|
||||
<div class="enlightenment-panel shadow-effect mx-auto panel w-50 mb-10" style="min-width: 320px;">
|
||||
<div class="shine-effect"></div>
|
||||
<form method="post" id="add-media-library-form" class="inline">
|
||||
<form method="post" id="add-media-library-form" class="inline" novalidate>
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" asp-for="Id" value="@id" />
|
||||
<input type="hidden" asp-for="UserId" value="@Model.UserId"/>
|
||||
@@ -204,6 +205,28 @@
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionShouldSkipUnchangedDirectoriesDuringScan"]</small>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label for="should-track-consumption-progress">@_localizer["ShouldTrackConsumptionProgress"]</label>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label class="enlightenment-checkbox-label">
|
||||
<input type="checkbox" id="should-track-consumption-progress" name="ShouldTrackConsumptionProgress" class="enlightenment-checkbox-hidden" checked="@(shouldTrackConsumptionProgress ? "checked" : null)" />
|
||||
<span class="enlightenment-checkbox"></span>
|
||||
</label>
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionShouldTrackConsumptionProgress"]</small>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="CompletionThresholdPercentage">@_localizer["CompletionThresholdPercentage"]</label>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input asp-for="CompletionThresholdPercentage" type="number" min="0" max="100" step="1" class="enlightenment-input" disabled="@(!shouldTrackConsumptionProgress ? "disabled" : null)" aria-describedby="completion-threshold-validation" />
|
||||
<span id="completion-threshold-validation" class="invalid-feedback hidden">@_localizer["CompletionThresholdPercentageValidation"]</span>
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionCompletionThresholdPercentage"]</small>
|
||||
</div>
|
||||
<!-- Path template. -->
|
||||
<style>
|
||||
.path-template-palette { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
|
||||
@@ -320,9 +343,22 @@
|
||||
const chkCanDownloadMetadataFromWeb = form.querySelector('[name="CanDownloadMetadataFromWeb"]');
|
||||
const chkShouldSaveMetadataInMediaDirectories = form.querySelector('[name="ShouldSaveMetadataInMediaDirectories"]');
|
||||
const chkShouldSkipUnchangedDirectoriesDuringScan = form.querySelector('[name="ShouldSkipUnchangedDirectoriesDuringScan"]');
|
||||
const chkShouldTrackConsumptionProgress = form.querySelector('[name="ShouldTrackConsumptionProgress"]');
|
||||
const inputCompletionThresholdPercentage = form.querySelector('[name="CompletionThresholdPercentage"]');
|
||||
const completionThresholdValidation = document.getElementById('completion-threshold-validation');
|
||||
// The threshold loaded with an existing library, so turning tracking off does not replace a custom stored value with the type default.
|
||||
const initialCompletionThresholdPercentage = inputCompletionThresholdPercentage.value.trim();
|
||||
|
||||
// Create new or update existing media library.
|
||||
async function handleAddMediaLibraryAsync() {
|
||||
// A threshold outside the allowed range is a client side validation failure, so no request is sent.
|
||||
if (!isCompletionThresholdValid()) {
|
||||
setCompletionThresholdValidationMessage(true);
|
||||
inputCompletionThresholdPercentage.focus();
|
||||
return;
|
||||
}
|
||||
const shouldTrackConsumptionProgress = chkShouldTrackConsumptionProgress.checked;
|
||||
const completionThresholdPercentage = inputCompletionThresholdPercentage.value.trim();
|
||||
const formData = {
|
||||
Id: form.querySelector('[name="Id"]').value || null,
|
||||
UserId: form.querySelector('[name="UserId"]').value || null,
|
||||
@@ -340,6 +376,13 @@
|
||||
CanDownloadMetadataFromWeb: chkCanDownloadMetadataFromWeb.checked,
|
||||
ShouldSaveMetadataInMediaDirectories: chkShouldSaveMetadataInMediaDirectories.checked,
|
||||
ShouldSkipUnchangedDirectoriesDuringScan: chkShouldSkipUnchangedDirectoriesDuringScan.checked,
|
||||
ShouldTrackConsumptionProgress: shouldTrackConsumptionProgress,
|
||||
// An empty threshold is sent as null: creating a library or enabling progress tracking uses the type default,
|
||||
// editing a library that already tracks progress keeps the stored threshold, and types without a default
|
||||
// threshold record completion only when it is reported explicitly. It is always null while tracking is off.
|
||||
CompletionThresholdPercentage: shouldTrackConsumptionProgress && completionThresholdPercentage !== ''
|
||||
? Number(completionThresholdPercentage)
|
||||
: null,
|
||||
PathTemplateParts: Array.from(pathTemplateDropzone.querySelectorAll('.path-template-pill')).map(pill => {
|
||||
const optional = pill.querySelector('.path-template-optional');
|
||||
return {
|
||||
@@ -622,6 +665,81 @@
|
||||
}
|
||||
};
|
||||
|
||||
// The default completion threshold of each library type that tracks consumption progress by default. It mirrors
|
||||
// LibraryConsumptionSettings.CreateDefault(LibraryType) in the domain, so the two must be kept in sync.
|
||||
const defaultCompletionThresholds = {
|
||||
Book: 100, EBook: 100, ComicBook: 100, Magazine: 100, Newspaper: 100, Manga: 100, GraphicNovel: 100, AcademicPaper: 100, SheetMusic: 100,
|
||||
TvShow: 90, Movie: 90, Documentary: 90, Anime: 90, ConcertVideo: 90, TutorialVideo: 90, HomeVideo: 90, YouTubeVideo: 90, MusicVideo: 90,
|
||||
LiveRecordingVideo: 90, InterviewVideo: 90, CoverSongVideo: 90,
|
||||
Audiobook: 95, PodcastAudio: 95, PodcastVideo: 95
|
||||
};
|
||||
|
||||
// Gets the default consumption settings of a library type. Types that are not listed track nothing and have no threshold.
|
||||
function getDefaultConsumptionSettings(libraryType) {
|
||||
if (Object.prototype.hasOwnProperty.call(defaultCompletionThresholds, libraryType))
|
||||
return { shouldTrackConsumptionProgress: true, completionThresholdPercentage: defaultCompletionThresholds[libraryType] };
|
||||
return { shouldTrackConsumptionProgress: false, completionThresholdPercentage: null };
|
||||
}
|
||||
|
||||
// Gets the library type currently selected in the combobox.
|
||||
function getSelectedLibraryType() {
|
||||
return libraryTypeSelectedItem ? libraryTypeSelectedItem.getAttribute('data-value') : null;
|
||||
}
|
||||
|
||||
// A threshold is valid when it is empty, or a whole number between 0 and 100.
|
||||
function isCompletionThresholdValid() {
|
||||
if (!chkShouldTrackConsumptionProgress.checked)
|
||||
return true;
|
||||
const value = inputCompletionThresholdPercentage.value.trim();
|
||||
if (value === '')
|
||||
return true;
|
||||
const threshold = Number(value);
|
||||
return Number.isInteger(threshold) && threshold >= 0 && threshold <= 100;
|
||||
}
|
||||
|
||||
// Shows or hides the localized validation message of the completion threshold.
|
||||
function setCompletionThresholdValidationMessage(isVisible) {
|
||||
completionThresholdValidation.classList.toggle('hidden', !isVisible);
|
||||
inputCompletionThresholdPercentage.setAttribute('aria-invalid', isVisible ? 'true' : 'false');
|
||||
}
|
||||
|
||||
// Keeps the threshold input state in sync with the progress tracking checkbox, so the threshold can only be edited
|
||||
// while tracking is on, and it is never sent while tracking is off.
|
||||
function syncCompletionThresholdInputState() {
|
||||
inputCompletionThresholdPercentage.disabled = !chkShouldTrackConsumptionProgress.checked;
|
||||
if (!chkShouldTrackConsumptionProgress.checked)
|
||||
inputCompletionThresholdPercentage.value = '';
|
||||
setCompletionThresholdValidationMessage(false);
|
||||
}
|
||||
|
||||
// Applies the default consumption settings of the selected library type, for a new library.
|
||||
function applyDefaultConsumptionSettings() {
|
||||
const settings = getDefaultConsumptionSettings(getSelectedLibraryType());
|
||||
chkShouldTrackConsumptionProgress.checked = settings.shouldTrackConsumptionProgress;
|
||||
inputCompletionThresholdPercentage.value = settings.completionThresholdPercentage ?? '';
|
||||
syncCompletionThresholdInputState();
|
||||
}
|
||||
|
||||
// On progress tracking checkbox change, enables the threshold input and restores the threshold that was loaded with the library
|
||||
// when it had a stored value, or prefills the default of the library type when it did not. Turning tracking off clears the threshold.
|
||||
const handleShouldTrackConsumptionProgressChange = function() {
|
||||
if (chkShouldTrackConsumptionProgress.checked && inputCompletionThresholdPercentage.value.trim() === '') {
|
||||
if (id && initialCompletionThresholdPercentage !== '')
|
||||
inputCompletionThresholdPercentage.value = initialCompletionThresholdPercentage;
|
||||
else {
|
||||
const settings = getDefaultConsumptionSettings(getSelectedLibraryType());
|
||||
if (settings.shouldTrackConsumptionProgress && settings.completionThresholdPercentage !== null)
|
||||
inputCompletionThresholdPercentage.value = settings.completionThresholdPercentage;
|
||||
}
|
||||
}
|
||||
syncCompletionThresholdInputState();
|
||||
};
|
||||
|
||||
// On completion threshold input, updates the validation message.
|
||||
const handleCompletionThresholdInput = function() {
|
||||
setCompletionThresholdValidationMessage(!isCompletionThresholdValid());
|
||||
};
|
||||
|
||||
// Path template editor.
|
||||
const pathTemplateSection = document.getElementById('path-template-section');
|
||||
const pathTemplatePalette = document.getElementById('path-template-palette');
|
||||
@@ -953,7 +1071,12 @@
|
||||
const handleLibraryTypeChange = function(e) {
|
||||
const option = e.target.closest('.enlightenment-option');
|
||||
if (!option || option.classList.contains('disabled') || !option.getAttribute('data-value')) return;
|
||||
setTimeout(() => { loadPathTemplateAsync(); }, 0);
|
||||
setTimeout(() => {
|
||||
loadPathTemplateAsync();
|
||||
// A new library starts from the default consumption settings of its type. An existing library keeps the settings it was loaded with.
|
||||
if (!id)
|
||||
applyDefaultConsumptionSettings();
|
||||
}, 0);
|
||||
};
|
||||
|
||||
// Add listeners.
|
||||
@@ -965,6 +1088,9 @@
|
||||
imgAddCover.addEventListener('click', handleImgAddCoverClick);
|
||||
mediaCoverFormTable.addEventListener('click', handleRowRemoval);
|
||||
mediaDirectoriesFormTable.addEventListener('click', handleRowRemoval);
|
||||
chkShouldTrackConsumptionProgress.addEventListener('change', handleShouldTrackConsumptionProgressChange);
|
||||
inputCompletionThresholdPercentage.addEventListener('input', handleCompletionThresholdInput);
|
||||
inputCompletionThresholdPercentage.addEventListener('change', handleCompletionThresholdInput);
|
||||
pathTemplateDropzone.addEventListener('dragover', handlePathTemplateDragOver);
|
||||
pathTemplateDropzone.addEventListener('drop', handlePathTemplateDrop);
|
||||
pathTemplateDropzone.addEventListener('dragleave', handlePathTemplateDragLeave);
|
||||
@@ -991,6 +1117,9 @@
|
||||
imgAddCover.removeEventListener('click', handleImgAddCoverClick);
|
||||
mediaCoverFormTable.removeEventListener('click', handleRowRemoval);
|
||||
mediaDirectoriesFormTable.removeEventListener('click', handleRowRemoval);
|
||||
chkShouldTrackConsumptionProgress.removeEventListener('change', handleShouldTrackConsumptionProgressChange);
|
||||
inputCompletionThresholdPercentage.removeEventListener('input', handleCompletionThresholdInput);
|
||||
inputCompletionThresholdPercentage.removeEventListener('change', handleCompletionThresholdInput);
|
||||
pathTemplateDropzone.removeEventListener('dragover', handlePathTemplateDragOver);
|
||||
pathTemplateDropzone.removeEventListener('drop', handlePathTemplateDrop);
|
||||
pathTemplateDropzone.removeEventListener('dragleave', handlePathTemplateDragLeave);
|
||||
@@ -1018,6 +1147,13 @@
|
||||
// Load the path template of the selected library type, and its default, for both new and existing libraries.
|
||||
loadPathTemplateAsync();
|
||||
|
||||
// A new library starts from the default consumption settings of the selected library type. An existing library
|
||||
// renders the stored values, but its threshold input state is still reconciled with the tracking checkbox.
|
||||
if (!id)
|
||||
applyDefaultConsumptionSettings();
|
||||
else
|
||||
syncCompletionThresholdInputState();
|
||||
|
||||
// Store all cleanups for this view on window object using the scriptId.
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
|
||||
Reference in new issue
Block a user