feat(conditions): add per-condition arr_type support

This commit is contained in:
Sam Chau
2026-01-19 03:37:26 +10:30
parent 9b2f0d393c
commit 95930edc53
5 changed files with 77 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ export interface ConditionData {
id: number;
name: string;
type: string;
arrType: 'all' | 'radarr' | 'sonarr';
negate: boolean;
required: boolean;
// Type-specific data
@@ -35,7 +36,7 @@ export async function getConditionsForEvaluation(
// Get base conditions
const conditions = await db
.selectFrom('custom_format_conditions')
.select(['id', 'name', 'type', 'negate', 'required'])
.select(['id', 'name', 'type', 'arr_type', 'negate', 'required'])
.where('custom_format_id', '=', formatId)
.execute();
@@ -194,6 +195,7 @@ export async function getConditionsForEvaluation(
id: c.id,
name: c.name,
type: c.type,
arrType: c.arr_type as 'all' | 'radarr' | 'sonarr',
negate: c.negate === 1,
required: c.required === 1,
patterns: patternsMap.get(c.id),

View File

@@ -151,7 +151,7 @@ export async function updateConditions(options: UpdateConditionsOptions) {
for (const condition of newConditions) {
// Insert the base condition
queries.push({
sql: `INSERT INTO custom_format_conditions (custom_format_id, name, type, arr_type, negate, required) VALUES (${formatId}, '${esc(condition.name)}', '${esc(condition.type)}', 'all', ${condition.negate ? 1 : 0}, ${condition.required ? 1 : 0})`,
sql: `INSERT INTO custom_format_conditions (custom_format_id, name, type, arr_type, negate, required) VALUES (${formatId}, '${esc(condition.name)}', '${esc(condition.type)}', '${condition.arrType ?? 'all'}', ${condition.negate ? 1 : 0}, ${condition.required ? 1 : 0})`,
parameters: [],
query: {} as never
});
@@ -177,13 +177,14 @@ export async function updateConditions(options: UpdateConditionsOptions) {
const baseChanged =
original.name !== condition.name ||
original.type !== condition.type ||
original.arrType !== condition.arrType ||
original.negate !== condition.negate ||
original.required !== condition.required;
if (baseChanged) {
// Update base condition
queries.push({
sql: `UPDATE custom_format_conditions SET name = '${esc(condition.name)}', type = '${esc(condition.type)}', negate = ${condition.negate ? 1 : 0}, required = ${condition.required ? 1 : 0} WHERE id = ${condition.id}`,
sql: `UPDATE custom_format_conditions SET name = '${esc(condition.name)}', type = '${esc(condition.type)}', arr_type = '${condition.arrType ?? 'all'}', negate = ${condition.negate ? 1 : 0}, required = ${condition.required ? 1 : 0} WHERE id = ${condition.id}`,
parameters: [],
query: {} as never
});

View File

@@ -112,6 +112,7 @@
id: nextDraftId--,
name: 'New Condition',
type: 'release_title',
arrType: 'all',
negate: false,
required: false
};

View File

@@ -37,6 +37,19 @@
dispatch('change', { ...condition, ...updates });
}
// Arr type toggle colors and state
const ARR_COLORS = { radarr: '#FFC230', sonarr: '#00CCFF' };
$: radarrEnabled = condition.arrType === 'all' || condition.arrType === 'radarr';
$: sonarrEnabled = condition.arrType === 'all' || condition.arrType === 'sonarr';
function getArrType(r: boolean, s: boolean): 'all' | 'radarr' | 'sonarr' {
if (r && s) return 'all';
if (r) return 'radarr';
if (s) return 'sonarr';
return 'all'; // Default to 'all' if neither is checked
}
// Filter condition types based on arrType
$: filteredConditionTypes = CONDITION_TYPES.filter(
(t) => t.arrType === 'all' || t.arrType === arrType
@@ -356,6 +369,28 @@
<span class="text-xs text-neutral-500 dark:text-neutral-400">Required</span>
</div>
<!-- Radarr -->
<div class="flex shrink-0 items-center gap-1.5">
<IconCheckbox
icon={Check}
checked={radarrEnabled}
color={ARR_COLORS.radarr}
on:click={() => emitChange({ arrType: getArrType(!radarrEnabled, sonarrEnabled) })}
/>
<span class="text-xs text-neutral-500 dark:text-neutral-400">Radarr</span>
</div>
<!-- Sonarr -->
<div class="flex shrink-0 items-center gap-1.5">
<IconCheckbox
icon={Check}
checked={sonarrEnabled}
color={ARR_COLORS.sonarr}
on:click={() => emitChange({ arrType: getArrType(radarrEnabled, !sonarrEnabled) })}
/>
<span class="text-xs text-neutral-500 dark:text-neutral-400">Sonarr</span>
</div>
<!-- Remove -->
<button
type="button"

View File

@@ -34,6 +34,19 @@
dispatch('change', { ...condition, ...updates });
}
// Arr type toggle colors and state
const ARR_COLORS = { radarr: '#FFC230', sonarr: '#00CCFF' };
$: radarrEnabled = condition.arrType === 'all' || condition.arrType === 'radarr';
$: sonarrEnabled = condition.arrType === 'all' || condition.arrType === 'sonarr';
function getArrType(r: boolean, s: boolean): 'all' | 'radarr' | 'sonarr' {
if (r && s) return 'all';
if (r) return 'radarr';
if (s) return 'sonarr';
return 'all'; // Default to 'all' if neither is checked
}
// Filter condition types based on arrType
$: filteredConditionTypes = CONDITION_TYPES.filter(
(t) => t.arrType === 'all' || t.arrType === arrType
@@ -354,6 +367,28 @@
<span class="text-xs text-neutral-500 dark:text-neutral-400">Required</span>
</div>
<!-- Radarr -->
<div class="flex shrink-0 items-center gap-1.5">
<IconCheckbox
icon={Check}
checked={radarrEnabled}
color={ARR_COLORS.radarr}
on:click={() => emitChange({ arrType: getArrType(!radarrEnabled, sonarrEnabled) })}
/>
<span class="text-xs text-neutral-500 dark:text-neutral-400">Radarr</span>
</div>
<!-- Sonarr -->
<div class="flex shrink-0 items-center gap-1.5">
<IconCheckbox
icon={Check}
checked={sonarrEnabled}
color={ARR_COLORS.sonarr}
on:click={() => emitChange({ arrType: getArrType(radarrEnabled, !sonarrEnabled) })}
/>
<span class="text-xs text-neutral-500 dark:text-neutral-400">Sonarr</span>
</div>
<!-- Confirm -->
<button
type="button"