mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 10:51:02 +01:00
feat(conditions): add per-condition arr_type support
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
id: nextDraftId--,
|
||||
name: 'New Condition',
|
||||
type: 'release_title',
|
||||
arrType: 'all',
|
||||
negate: false,
|
||||
required: false
|
||||
};
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user