diff --git a/src/lib/server/pcd/queries/customFormats/conditions.ts b/src/lib/server/pcd/queries/customFormats/conditions.ts index 0a1e3fe..ebd334b 100644 --- a/src/lib/server/pcd/queries/customFormats/conditions.ts +++ b/src/lib/server/pcd/queries/customFormats/conditions.ts @@ -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), diff --git a/src/lib/server/pcd/queries/customFormats/updateConditions.ts b/src/lib/server/pcd/queries/customFormats/updateConditions.ts index fe0e60a..5e4740c 100644 --- a/src/lib/server/pcd/queries/customFormats/updateConditions.ts +++ b/src/lib/server/pcd/queries/customFormats/updateConditions.ts @@ -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 }); diff --git a/src/routes/custom-formats/[databaseId]/[id]/conditions/+page.svelte b/src/routes/custom-formats/[databaseId]/[id]/conditions/+page.svelte index ca65d02..5b813e9 100644 --- a/src/routes/custom-formats/[databaseId]/[id]/conditions/+page.svelte +++ b/src/routes/custom-formats/[databaseId]/[id]/conditions/+page.svelte @@ -112,6 +112,7 @@ id: nextDraftId--, name: 'New Condition', type: 'release_title', + arrType: 'all', negate: false, required: false }; diff --git a/src/routes/custom-formats/[databaseId]/[id]/conditions/components/ConditionCard.svelte b/src/routes/custom-formats/[databaseId]/[id]/conditions/components/ConditionCard.svelte index b34ab0d..9929e45 100644 --- a/src/routes/custom-formats/[databaseId]/[id]/conditions/components/ConditionCard.svelte +++ b/src/routes/custom-formats/[databaseId]/[id]/conditions/components/ConditionCard.svelte @@ -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 @@ Required + +