fix calendar: table params for Lua functions + remove duplicate header

- CalendarPluginPage.svelte: removed <h2>pluginName — pageLabel</h2> (AppHeader already shows title)
- main.lua: all API functions now accept a single table parameter:
  - get_events(params) — reads params.start_date or params.start
  - get_event(params) — reads params.id
  - update_event(params) — reads params.id + mutable fields
  - delete_event(params) — reads params.id
  - get_expanded_events(params), get_calendar_events(params) — same
  - get_events_day(params) — reads params.date
  - create_event(opts) — already worked, no change
- Backward compatible: get_events accepts both start/start_date and end/end_date keys
This commit is contained in:
mirivlad 2026-06-08 11:18:28 +08:00
parent b1d1defebe
commit fddbd3a98a
7 changed files with 38 additions and 32 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -19,8 +19,8 @@
background: #13131f; background: #13131f;
} }
</style> </style>
<script type="module" crossorigin src="/assets/main-CMk8guXZ.js"></script> <script type="module" crossorigin src="/assets/main-Ch0NvF0Q.js"></script>
<link rel="stylesheet" crossorigin href="/assets/main-BecQca8b.css"> <link rel="stylesheet" crossorigin href="/assets/main-BdKe9T_7.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -143,7 +143,9 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Get events within a date range (inclusive) -- Get events within a date range (inclusive)
function M.get_events(start_date, end_date) function M.get_events(params)
local start_date = params.start_date or params.start
local end_date = params.end_date or params["end"] or params.end_date
if not start_date then error("start_date required") end if not start_date then error("start_date required") end
if not end_date then end_date = start_date end if not end_date then end_date = start_date end
return verstak.db.query( return verstak.db.query(
@ -167,18 +169,23 @@ function M.get_events(start_date, end_date)
end end
-- Get events for a specific day -- Get events for a specific day
function M.get_events_day(date_str) function M.get_events_day(params)
return M.get_events(date_str .. "T00:00:00", date_str .. "T23:59:59") local date_str = params.date or params
if type(date_str) ~= "string" then date_str = tostring(date_str) end
return M.get_events({ start_date = date_str .. "T00:00:00", end_date = date_str .. "T23:59:59" })
end end
-- Get event by ID -- Get event by ID
function M.get_event(id) function M.get_event(params)
local id = params.id or params
if not id then error("event id required") end
return verstak.db.query_row( return verstak.db.query_row(
"SELECT * FROM events WHERE id = ?", id "SELECT * FROM events WHERE id = ?", id
) )
end end
-- Create a single event (base event for recurrences) -- Create a single event (base event for recurrences)
-- Already accepts a single table — no change needed
function M.create_event(opts) function M.create_event(opts)
opts = opts or {} opts = opts or {}
if not opts.title or opts.title == "" then error("event title required") end if not opts.title or opts.title == "" then error("event title required") end
@ -237,14 +244,14 @@ function M.create_event(opts)
end end
-- Update an event (partial fields) -- Update an event (partial fields)
function M.update_event(id, fields) function M.update_event(params)
local id = params.id
if not id then error("event id required") end if not id then error("event id required") end
local old = verstak.db.query_row("SELECT * FROM events WHERE id = ?", id) local old = verstak.db.query_row("SELECT * FROM events WHERE id = ?", id)
if not old then error("event not found: " .. id) end if not old then error("event not found: " .. id) end
local updates = {}
local params = {}
local set_clauses = {} local set_clauses = {}
local sql_params = {}
-- Build dynamic update -- Build dynamic update
local mutable = { local mutable = {
@ -254,35 +261,36 @@ function M.update_event(id, fields)
completed = true completed = true
} }
for k, v in pairs(fields) do for k, v in pairs(params) do
if mutable[k] then if k ~= "id" and mutable[k] then
if k == "all_day" or k == "completed" then if k == "all_day" or k == "completed" then
v = v and 1 or 0 v = v and 1 or 0
end end
table.insert(set_clauses, k .. " = ?") table.insert(set_clauses, k .. " = ?")
table.insert(params, v) table.insert(sql_params, v)
end end
end end
table.insert(params, now()) table.insert(sql_params, now())
table.insert(params, id) table.insert(sql_params, id)
if #set_clauses > 0 then if #set_clauses > 0 then
verstak.db.exec( verstak.db.exec(
"UPDATE events SET " .. table.concat(set_clauses, ", ") .. ", updated_at = ? WHERE id = ?", "UPDATE events SET " .. table.concat(set_clauses, ", ") .. ", updated_at = ? WHERE id = ?",
unpack(params) unpack(sql_params)
) )
end end
safe_log(verstak.activity.log,"event_updated", safe_log(verstak.activity.log,"event_updated",
"Событие обновлено: " .. (fields.title or old.title or id), id, old.node_id or "") "Событие обновлено: " .. (params.title or old.title or id), id, old.node_id or "")
return true return true
end end
-- Delete an event -- Delete an event
function M.delete_event(id) function M.delete_event(params)
if not id then error("event id required") end local id = params.id or params
if not id or type(id) ~= "string" then error("event id required") end
local old = verstak.db.query_row("SELECT title, node_id FROM events WHERE id = ?", id) local old = verstak.db.query_row("SELECT title, node_id FROM events WHERE id = ?", id)
if not old then return true end if not old then return true end
@ -423,7 +431,9 @@ end
M.expand_recurring = expand_recurring M.expand_recurring = expand_recurring
-- Get all events (flat + expanded) for a range — used by the panel -- Get all events (flat + expanded) for a range — used by the panel
function M.get_expanded_events(start_date, end_date) function M.get_expanded_events(params)
local start_date = params.start_date or params.start
local end_date = params.end_date or params["end"]
local base_events = verstak.db.query( local base_events = verstak.db.query(
[[SELECT * FROM events WHERE recurring_rule IS NOT NULL AND recurring_rule != '' [[SELECT * FROM events WHERE recurring_rule IS NOT NULL AND recurring_rule != ''
AND completed = 0]] AND completed = 0]]
@ -454,11 +464,11 @@ function M.get_expanded_events(start_date, end_date)
end end
-- Get all events (flat + expanded) for a range — used by the panel -- Get all events (flat + expanded) for a range — used by the panel
function M.get_calendar_events(start_date, end_date) function M.get_calendar_events(params)
-- 1. Normal events -- 1. Normal events
local normal = M.get_events(start_date, end_date) local normal = M.get_events(params)
-- 2. Expanded recurring -- 2. Expanded recurring
local recur = M.get_expanded_events(start_date, end_date) local recur = M.get_expanded_events(params)
-- Merge -- Merge
local all = {} local all = {}
for _, e in ipairs(normal) do table.insert(all, e) end for _, e in ipairs(normal) do table.insert(all, e) end

View File

@ -204,10 +204,6 @@
</script> </script>
<div class="plugin-page"> <div class="plugin-page">
<div class="plugin-page-header">
<h2>{pluginName}{pageLabel}</h2>
</div>
{#if loading} {#if loading}
<p class="loading">Загрузка…</p> <p class="loading">Загрузка…</p>
{:else if error} {:else if error}