diff --git a/caller.qplug b/caller.qplug index 90e1c02..cd00267 100644 --- a/caller.qplug +++ b/caller.qplug @@ -1,66 +1,84 @@ -PluginInfo = { - Name = "Caller", - Version = "0.1.0-master", - Id = "Caller.plugin.0.1.0-master", - Description = "Plugin for taking a name and input and producing a call output", - Author = "Joel Wetzell" -} -require("json") - -function GetPrettyName() - return "Caller" -end - -function GetProperties() - local props = {} - return props -end - -function RectifyProperties(props) - return props -end - -function GetControls(props) - local controls = { - { - Name = "QueueUp", - ControlType = "Button", - ButtonType = "Toggle", - PinStyle = "Both", - UserPin = true - }, - { - Name = "CallOut", - ControlType = "Text", - PinStyle = "Output", - UserPin = true - }, - { - Name = "CallerName", - ControlType = "Text", - PinStyle = "Input", - UserPin = true - } - } - return controls -end - -function Initialize() -end - -function SetupControlHandlers() - Controls["QueueUp"].EventHandler = function (ctrl) - local call = { - Queue = ctrl.Boolean, - Name = Controls["CallerName"].String, - Time = os.time() - } - local callString = json.encode(call) - Controls["CallOut"].String = json.encode(call) - end -end - -if(Controls) then - Initialize() - SetupControlHandlers() +PluginInfo = { + Name = "Caller", + Version = "0.1.0-master", + Id = "Caller.plugin.0.1.0-master", + Description = "Plugin for taking a name and input and producing a call output", + Author = "Joel Wetzell" +} +require("json") + +function GetPrettyName() + return "Caller" +end + +function GetProperties() + local props = {} + return props +end + +function RectifyProperties(props) + return props +end + +function GetControls(props) + local controls = { + { + Name = "Clear", + ControlType = "Button", + ButtonType = "Trigger", + PinStyle = "Input", + UserPin = true + }, + { + Name = "QueueUp", + ControlType = "Button", + ButtonType = "Toggle", + PinStyle = "Both", + UserPin = true + }, + { + Name = "CallOut", + ControlType = "Text", + PinStyle = "Output", + UserPin = true + }, + { + Name = "CallerName", + ControlType = "Text", + PinStyle = "Input", + UserPin = true + } + } + return controls +end + +function Initialize() +end + +function CreateCall(name, queue) + local call = { + Queue = queue, + Name = name, + Time = os.time() + } + return call +end + + +function SetupControlHandlers() + Controls["QueueUp"].EventHandler = function (ctrl) + local call = CreateCall(Controls["CallerName"].String, Controls["QueueUp"].Boolean) + Controls["CallOut"].String = json.encode(call) + end + + Controls["Clear"].EventHandler = function (ctrl) + Controls["QueueUp"].Boolean = false + local call = CreateCall(Controls["CallerName"].String, false) + Controls["CallOut"].String = json.encode(call) + end +end + +if(Controls) then + Initialize() + SetupControlHandlers() end \ No newline at end of file diff --git a/callqueue.qplug b/callqueue.qplug index 0dde87d..9383d0f 100644 --- a/callqueue.qplug +++ b/callqueue.qplug @@ -1,129 +1,152 @@ -PluginInfo = { - Name = "CallQueue", - Version = "0.1.0-master", - Id = "callqueue.plugin.0.1.0-master", - Description = "Plugin for taking incoming call objects and maintaining a queue", - Author = "Joel Wetzell" -} -require("json") -function GetPrettyName() - return "Call Queue" -end - -function GetProperties() - local props = { - { - Name = "Call Count", - Type = "integer", - Min = 0, - Max = 20, - Value = 1 - }, - } - return props -end - -function RectifyProperties(props) - return props -end - -function GetControls(props) - local controls = { - { - Name = "PopCall", - ControlType = "Button", - ButtonType = "Trigger", - PinStyle = "Input", - UserPin = true - }, - { - Name = "TopCallName", - ControlType = "Text", - PinStyle = "Output", - UserPin = true - }, - } - for i=1,props["Call Count"].Value do - print(i) - local name = "Call" .. i - table.insert(controls, { - Name = name, - ControlType = "Text", - PinStyle = "Input", - UserPin = true - }) - end - return controls -end - -function ClearCalls() - CallList = {} -end - -function UpdateOutputs() - local topCall = CallList[1] - if topCall == nil then - Controls["TopCallName"].String = "" - else - Controls["TopCallName"].String = topCall.Name - end -end - -function PushCall(call) - for i, value in pairs(CallList) do - if value.Position == call.Position then - print("call already in queue for position " .. call.Position) - return - end - end - table.insert(CallList, call) - print("call for " .. call.Name .. " at position " .. call.Position .. " pushed") - UpdateOutputs() -end - -function PopCall() - call = table.remove(CallList,1) - if call then - print("call for " .. call.Name .. " at position " .. call.Position .. " popped") - end - UpdateOutputs() -end - -function RemoveCall(call) - for i, value in pairs(CallList) do - if value.Position == call.Position then - print("removing call for position " .. call.Position) - table.remove(CallList, i) - return - end - end -end - -function Initialize() - ClearCalls() -end - -function SetupControlHandlers() - Controls["PopCall"].EventHandler = function (ctrl) - PopCall() - end - - for i=1, Properties["Call Count"].Value do - Controls["Call"..i].EventHandler = function (ctrl) - if ctrl.String ~= "" then - local call = json.decode(ctrl.String) - call.Position = i - if call.Queue then - PushCall(call) - else - RemoveCall(call) - end - end - end - end -end - -if(Controls) then - Initialize() - SetupControlHandlers() +PluginInfo = { + Name = "CallQueue", + Version = "0.1.0-master", + Id = "callqueue.plugin.0.1.0-master", + Description = "Plugin for taking incoming call objects and maintaining a queue", + Author = "Joel Wetzell" +} +require("json") +function GetPrettyName() + return "Call Queue" +end + +function GetProperties() + local props = { + { + Name = "Call Count", + Type = "integer", + Min = 0, + Max = 20, + Value = 1 + }, + } + return props +end + +function RectifyProperties(props) + return props +end + +function GetControls(props) + local controls = { + { + Name = "PopCall", + ControlType = "Button", + ButtonType = "Trigger", + PinStyle = "Input", + UserPin = true + }, + { + Name = "CallList", + ControlType = "Text", + PinStyle = "Output", + UserPin = true + }, + { + Name = "ClearAll", + ControlType = "Button", + ButtonType = "Trigger", + Pinstyle = "Input", + UserPin = true + } + } + for i=1,props["Call Count"].Value do + local name = "Call" .. i + table.insert(controls, { + Name = name .. "In", + ControlType = "Text", + PinStyle = "Input", + UserPin = true + }) + table.insert(controls, { + Name = name .. "Clear", + ControlType = "Button", + ButttonType = "Trigger", + PinStyle = "Output", + UserPin = true + }) + end + return controls +end + +function ClearCalls() + CallList = {} + for i=1, Properties["Call Count"].Value do + Controls["Call"..i.."Clear"]:Trigger() + end + UpdateOutputs() +end + +function UpdateOutputs() + local listString = "" + if (#CallList > 0) then + for i, v in pairs(CallList) do + listString = listString .. v.Name .. "\n" + end + end + Controls["CallList"].String = listString +end + +function PushCall(call) + for i, value in pairs(CallList) do + if value.Position == call.Position then + print("call already in queue for position " .. call.Position) + return + end + end + table.insert(CallList, call) + print("call for " .. call.Name .. " at position " .. call.Position .. " pushed") + UpdateOutputs() +end + +function PopCall() + call = table.remove(CallList,1) + if call then + print("call for " .. call.Name .. " at position " .. call.Position .. " popped") + Controls["Call"..call.Position.."Clear"]:Trigger() + end + UpdateOutputs() +end + +function RemoveCall(call) + for i, value in pairs(CallList) do + if value.Position == call.Position then + print("removing call for position " .. call.Position) + table.remove(CallList, i) + end + end + UpdateOutputs() +end + +function Initialize() + ClearCalls() +end + +function SetupControlHandlers() + Controls["PopCall"].EventHandler = function (ctrl) + PopCall() + end + + Controls["ClearAll"].EventHandler = function (ctrl) + ClearCalls() + end + + for i=1, Properties["Call Count"].Value do + Controls["Call"..i.."In"].EventHandler = function (ctrl) + if ctrl.String ~= "" then + local call = json.decode(ctrl.String) + call.Position = i + if call.Queue then + PushCall(call) + else + RemoveCall(call) + end + end + end + end +end + +if(Controls) then + Initialize() + SetupControlHandlers() end \ No newline at end of file