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:
parent
b1d1defebe
commit
fddbd3a98a
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
|
|
@ -19,8 +19,8 @@
|
|||
background: #13131f;
|
||||
}
|
||||
</style>
|
||||
<script type="module" crossorigin src="/assets/main-CMk8guXZ.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/main-BecQca8b.css">
|
||||
<script type="module" crossorigin src="/assets/main-Ch0NvF0Q.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/main-BdKe9T_7.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
|
|
|||
|
|
@ -143,7 +143,9 @@ end
|
|||
--------------------------------------------------------------------------------
|
||||
|
||||
-- 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 end_date then end_date = start_date end
|
||||
return verstak.db.query(
|
||||
|
|
@ -167,18 +169,23 @@ function M.get_events(start_date, end_date)
|
|||
end
|
||||
|
||||
-- Get events for a specific day
|
||||
function M.get_events_day(date_str)
|
||||
return M.get_events(date_str .. "T00:00:00", date_str .. "T23:59:59")
|
||||
function M.get_events_day(params)
|
||||
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
|
||||
|
||||
-- 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(
|
||||
"SELECT * FROM events WHERE id = ?", id
|
||||
)
|
||||
end
|
||||
|
||||
-- Create a single event (base event for recurrences)
|
||||
-- Already accepts a single table — no change needed
|
||||
function M.create_event(opts)
|
||||
opts = opts or {}
|
||||
if not opts.title or opts.title == "" then error("event title required") end
|
||||
|
|
@ -237,14 +244,14 @@ function M.create_event(opts)
|
|||
end
|
||||
|
||||
-- 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
|
||||
local old = verstak.db.query_row("SELECT * FROM events WHERE id = ?", id)
|
||||
if not old then error("event not found: " .. id) end
|
||||
|
||||
local updates = {}
|
||||
local params = {}
|
||||
local set_clauses = {}
|
||||
local sql_params = {}
|
||||
|
||||
-- Build dynamic update
|
||||
local mutable = {
|
||||
|
|
@ -254,35 +261,36 @@ function M.update_event(id, fields)
|
|||
completed = true
|
||||
}
|
||||
|
||||
for k, v in pairs(fields) do
|
||||
if mutable[k] then
|
||||
for k, v in pairs(params) do
|
||||
if k ~= "id" and mutable[k] then
|
||||
if k == "all_day" or k == "completed" then
|
||||
v = v and 1 or 0
|
||||
end
|
||||
table.insert(set_clauses, k .. " = ?")
|
||||
table.insert(params, v)
|
||||
table.insert(sql_params, v)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(params, now())
|
||||
table.insert(params, id)
|
||||
table.insert(sql_params, now())
|
||||
table.insert(sql_params, id)
|
||||
|
||||
if #set_clauses > 0 then
|
||||
verstak.db.exec(
|
||||
"UPDATE events SET " .. table.concat(set_clauses, ", ") .. ", updated_at = ? WHERE id = ?",
|
||||
unpack(params)
|
||||
unpack(sql_params)
|
||||
)
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
-- Delete an event
|
||||
function M.delete_event(id)
|
||||
if not id then error("event id required") end
|
||||
function M.delete_event(params)
|
||||
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)
|
||||
if not old then return true end
|
||||
|
||||
|
|
@ -423,7 +431,9 @@ end
|
|||
M.expand_recurring = expand_recurring
|
||||
|
||||
-- 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(
|
||||
[[SELECT * FROM events WHERE recurring_rule IS NOT NULL AND recurring_rule != ''
|
||||
AND completed = 0]]
|
||||
|
|
@ -454,11 +464,11 @@ function M.get_expanded_events(start_date, end_date)
|
|||
end
|
||||
|
||||
-- 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
|
||||
local normal = M.get_events(start_date, end_date)
|
||||
local normal = M.get_events(params)
|
||||
-- 2. Expanded recurring
|
||||
local recur = M.get_expanded_events(start_date, end_date)
|
||||
local recur = M.get_expanded_events(params)
|
||||
-- Merge
|
||||
local all = {}
|
||||
for _, e in ipairs(normal) do table.insert(all, e) end
|
||||
|
|
|
|||
|
|
@ -204,10 +204,6 @@
|
|||
</script>
|
||||
|
||||
<div class="plugin-page">
|
||||
<div class="plugin-page-header">
|
||||
<h2>{pluginName} — {pageLabel}</h2>
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
<p class="loading">Загрузка…</p>
|
||||
{:else if error}
|
||||
|
|
|
|||
Loading…
Reference in New Issue