remove/add entry from all tables
This commit is contained in:
parent
c2e481edc6
commit
0d6b6ade71
11
voting.lua
11
voting.lua
@ -1,6 +1,5 @@
|
||||
-- The machine requires _three_ touch screens connected: one set to channel "vote", other set to "admin", and third to "submit"
|
||||
|
||||
-- FIXME: I was sleepy: make sure when entries are added/removed, all mappings are in sync
|
||||
-- FIXME: "results" view not opening when there are no votes?
|
||||
|
||||
local categories = {"Creativity", "Aesthetic Appeal", "Detail & Execution", "Use of space"}
|
||||
@ -484,8 +483,9 @@ elseif event.type == "digiline" then
|
||||
show_error("#FF0000", string.format("%s pressed submit!\nYou can't submit for another user! Press 'back' and enter again!", user))
|
||||
return
|
||||
end
|
||||
local sub = mem.entries_by_user[user]
|
||||
local sub = mem.entries_by_user[user] -- exisiting submission from this user
|
||||
if not sub then
|
||||
-- create new one
|
||||
local new_id = mem.id_count
|
||||
mem.id_count = mem.id_count + 1 -- update unique ID generator
|
||||
sub = {
|
||||
@ -570,9 +570,11 @@ elseif event.type == "digiline" then
|
||||
local new_id = mem.id_count
|
||||
mem.id_count = mem.id_count + 1 -- update unique ID generator
|
||||
if new ~= "" then -- add when not empty
|
||||
local entry = {id = new_id, title = new_title, user = event.msg.new_entry_submitter}
|
||||
local user = event.msg.new_entry_submitter
|
||||
local entry = { id = new_id, title = new_title, user = user }
|
||||
table.insert(mem.entries, entry) -- store in ordered list
|
||||
mem.entries_by_id[new_id] = entry -- store in ID -> entry map
|
||||
mem.entries_by_user[user] = entry
|
||||
end
|
||||
show_admin_edit()
|
||||
end
|
||||
@ -583,6 +585,9 @@ elseif event.type == "digiline" then
|
||||
if entry then
|
||||
table.remove(mem.entries, mem.admin_entries_idx)
|
||||
mem.entries_by_id[entry.id] = nil
|
||||
if entry.user then
|
||||
mem.entries_by_user[entry.user] = nil
|
||||
end
|
||||
for pname, votes in pairs(mem.votes) do
|
||||
votes[entry.id] = nil
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user