proccesses are working now!
This commit is contained in:
parent
fb0bb4f049
commit
a7ba7605d3
@ -13,4 +13,7 @@ dofile (localdir .. "/orgs/requests.lua")
|
|||||||
dofile (localdir .. "/interactions/interactions.lua")
|
dofile (localdir .. "/interactions/interactions.lua")
|
||||||
|
|
||||||
-- messaging functions
|
-- messaging functions
|
||||||
dofile (localdir .. "/processes/processes.lua")
|
dofile (localdir .. "/processes/processes.lua")
|
||||||
|
|
||||||
|
--modules
|
||||||
|
dofile (localdir .. "/modules/consent.lua")
|
@ -77,10 +77,10 @@ if (modpol.orgs.array) then
|
|||||||
for id, org in ipairs(modpol.orgs.array) do
|
for id, org in ipairs(modpol.orgs.array) do
|
||||||
if type(org) == 'table' then
|
if type(org) == 'table' then
|
||||||
setmetatable(org, modpol.orgs)
|
setmetatable(org, modpol.orgs)
|
||||||
end
|
-- sets process metatable on load
|
||||||
-- sets process metatable on load
|
for id, process in ipairs(org.processes) do
|
||||||
for id, process in ipairs(org.processes) do
|
setmetatable(process, org.modules[process.type])
|
||||||
setmetatable(process, org.modules[process.type])
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
modpol.modules = modpol.modules or {}
|
||||||
|
|
||||||
modpol.modules.consent = {
|
modpol.modules.consent = {
|
||||||
type = "consent",
|
type = "consent",
|
||||||
}
|
}
|
||||||
@ -9,7 +11,7 @@ function temp_consent_process()
|
|||||||
return {
|
return {
|
||||||
org_id = nil,
|
org_id = nil,
|
||||||
request_id = nil,
|
request_id = nil,
|
||||||
total_votes = nil,
|
total_votes = 0,
|
||||||
votes_yes = {},
|
votes_yes = {},
|
||||||
votes_no = {}
|
votes_no = {}
|
||||||
}
|
}
|
||||||
@ -17,16 +19,15 @@ end
|
|||||||
|
|
||||||
-- ===============================================
|
-- ===============================================
|
||||||
-- function to create a new consent process to resolve a pending process
|
-- function to create a new consent process to resolve a pending process
|
||||||
function modpol.modules.consent.new_process(request_id, org_id)
|
function modpol.modules.consent:new_process(request_id, org_id)
|
||||||
local process = temp_consent_process()
|
local process = temp_consent_process()
|
||||||
process.request_id = request_id
|
process.request_id = request_id
|
||||||
process.org_id = org_id
|
process.org_id = org_id
|
||||||
|
|
||||||
setmetatable(process, modpol.modules.consent)
|
setmetatable(process, modpol.modules.consent)
|
||||||
|
modpol.ocutil.log('Created new process for request id #' .. request_id)
|
||||||
|
|
||||||
modpol.ocutil.log('Created new process for request id')
|
return process
|
||||||
|
|
||||||
return temp_consent_process
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ======================================================
|
-- ======================================================
|
||||||
@ -38,6 +39,7 @@ function modpol.modules.consent:approve(user, decision)
|
|||||||
else
|
else
|
||||||
table.insert(self.votes_no, user)
|
table.insert(self.votes_no, user)
|
||||||
modpol.ocutil.log('User ' .. user .. ' voted no on request #' .. self.request_id)
|
modpol.ocutil.log('User ' .. user .. ' voted no on request #' .. self.request_id)
|
||||||
|
end
|
||||||
|
|
||||||
self.total_votes = self.total_votes + 1
|
self.total_votes = self.total_votes + 1
|
||||||
|
|
||||||
@ -45,11 +47,11 @@ end
|
|||||||
|
|
||||||
-- ===================================================
|
-- ===================================================
|
||||||
-- determines whether process has finished and resolves request if it has (unfinished)
|
-- determines whether process has finished and resolves request if it has (unfinished)
|
||||||
function modules.consent.call_vote_check(process)
|
-- function modpol.modules.consent.call_vote_check(process)
|
||||||
if votes_yes > to_pass then
|
-- if votes_yes > to_pass then
|
||||||
call_success()
|
-- call_success()
|
||||||
elseif votes_no > to_pass then
|
-- elseif votes_no > to_pass then
|
||||||
call_failure()
|
-- call_failure()
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
|
|
||||||
|
@ -7,11 +7,15 @@ modpol.orgs.request_params = {
|
|||||||
|
|
||||||
-- ================================
|
-- ================================
|
||||||
-- creates a new process linked to a request id
|
-- creates a new process linked to a request id
|
||||||
function modpol.orgs:create_process(request_id)
|
function modpol.orgs:create_process(process_type, request_id)
|
||||||
local new_process = {
|
if not modpol.modules[process_type] then
|
||||||
object = "I am a process",
|
modpol.ocutil.log('Process type "' .. process_type .. '" does not exist')
|
||||||
request_id = request_id
|
return
|
||||||
}
|
end
|
||||||
|
|
||||||
|
-- retrieving requested module
|
||||||
|
local module = modpol.modules[process_type]
|
||||||
|
local new_process = module:new_process(request_id, self.id)
|
||||||
|
|
||||||
-- linear search for empty process slots (lazy deletion)
|
-- linear search for empty process slots (lazy deletion)
|
||||||
for k, v in ipairs(self.processes) do
|
for k, v in ipairs(self.processes) do
|
||||||
@ -24,8 +28,10 @@ function modpol.orgs:create_process(request_id)
|
|||||||
-- attempts to fill empty spots in list, otherwise appends to end
|
-- attempts to fill empty spots in list, otherwise appends to end
|
||||||
if empty_index then
|
if empty_index then
|
||||||
self.processes[empty_index] = new_process
|
self.processes[empty_index] = new_process
|
||||||
|
return empty_index
|
||||||
else
|
else
|
||||||
table.insert(self.processes, new_process)
|
table.insert(self.processes, new_process)
|
||||||
|
return #self.processes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ new_request = {
|
|||||||
params = {"lukvmil"}
|
params = {"lukvmil"}
|
||||||
}
|
}
|
||||||
|
|
||||||
request_id = test_org:make_request(new_request)
|
|
||||||
request_id = test_org:make_request(new_request)
|
request_id = test_org:make_request(new_request)
|
||||||
|
|
||||||
print(test_org:list_request())
|
process_id = test_org:create_process("consent", request_id)
|
||||||
test_org:create_process(request_id)
|
process = test_org.processes[process_id]
|
||||||
|
process:approve("luke", true)
|
Loading…
x
Reference in New Issue
Block a user