From c66f2152ee800fd8aa9cacc5f19a1daa023f1ff3 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 12 Nov 2019 11:06:48 +0000 Subject: [PATCH] people: Show SIP agent status Signed-off-by: Michael Tremer --- Makefile.am | 1 + src/backend/accounts.py | 4 ++++ src/backend/talk.py | 6 +++++ src/templates/people/modules/agent.html | 30 +++++++++++++++++++++++++ src/templates/people/sip.html | 2 ++ src/web/__init__.py | 1 + src/web/people.py | 5 +++++ 7 files changed, 49 insertions(+) create mode 100644 src/templates/people/modules/agent.html diff --git a/Makefile.am b/Makefile.am index fcbfd0d7..a098280d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -254,6 +254,7 @@ templates_people_messagesdir = $(templates_peopledir)/messages templates_people_modules_DATA = \ src/templates/people/modules/accounts-list.html \ src/templates/people/modules/accounts-new.html \ + src/templates/people/modules/agent.html \ src/templates/people/modules/cdr.html \ src/templates/people/modules/channels.html \ src/templates/people/modules/mos.html \ diff --git a/src/backend/accounts.py b/src/backend/accounts.py index 18ae2d31..ec29bcf5 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -826,6 +826,10 @@ class Account(Object): def sip_url(self): return "%s@ipfire.org" % self.sip_id + @lazy_property + def agent_status(self): + return self.backend.talk.freeswitch.get_agent_status(self) + def uses_sip_forwarding(self): if self.sip_routing_address: return True diff --git a/src/backend/talk.py b/src/backend/talk.py index 34a21315..4215e7d5 100644 --- a/src/backend/talk.py +++ b/src/backend/talk.py @@ -82,6 +82,12 @@ class Freeswitch(Object): return conferences + def get_agent_status(self, account): + res = self.db.get("SELECT status FROM agents \ + WHERE name = %s", account.sip_url) + + if res: + return res.status class SIPRegistration(object): def __init__(self, freeswitch, data): diff --git a/src/templates/people/modules/agent.html b/src/templates/people/modules/agent.html new file mode 100644 index 00000000..db3e2d21 --- /dev/null +++ b/src/templates/people/modules/agent.html @@ -0,0 +1,30 @@ +{% set status = account.agent_status %} + +{% if status %} +
+
+
{{ _("Agent Status") }}
+ +

+ {% if status == "Available" or status == "Available (On Demand)" %} + + + {{ _("This agent is currently available") }} + + {% elif status == "Logged Out" %} + + + {{ _("This agent is currently logged out") }} + + {% elif status == "On Break" %} + + + {{ _("This agent is currently on a break") }} + + {% else %} + {{ _("Unknown status: %s") % status }} + {% end %} +

+
+
+{% end %} diff --git a/src/templates/people/sip.html b/src/templates/people/sip.html index a5b47cd4..9379f328 100644 --- a/src/templates/people/sip.html +++ b/src/templates/people/sip.html @@ -7,6 +7,8 @@ {% module Channels(account) %} + {% module Agent(account) %} + {% module Registrations(account) %} {% if account.uses_sip_forwarding() %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 1ef64452..be51b6a9 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -74,6 +74,7 @@ class Application(tornado.web.Application): # People "AccountsList" : people.AccountsListModule, + "Agent" : people.AgentModule, "CDR" : people.CDRModule, "Channels" : people.ChannelsModule, "MOS" : people.MOSModule, diff --git a/src/web/people.py b/src/web/people.py index ea6ea8a5..dfc02b55 100644 --- a/src/web/people.py +++ b/src/web/people.py @@ -373,6 +373,11 @@ class AccountsListModule(ui_modules.UIModule): return self.render_string("people/modules/accounts-list.html", accounts=accounts) +class AgentModule(ui_modules.UIModule): + def render(self, account): + return self.render_string("people/modules/agent.html", account=account) + + class CDRModule(ui_modules.UIModule): def render(self, account, date=None, limit=None): cdr = account.get_cdr(date=date, limit=limit) -- 2.47.3