]> git.ipfire.org Git - ipfire.org.git/commitdiff
people: Add page with call information
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Oct 2018 12:22:29 +0000 (13:22 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Oct 2018 15:12:45 +0000 (16:12 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/backend/talk.py
src/templates/people/call.html [new file with mode: 0644]
src/templates/people/modules/cdr.html
src/templates/people/modules/mos.html [new file with mode: 0644]
src/web/__init__.py
src/web/people.py

index 1738171dba03524aadc11700b24395f7c81d5604..58a66c3b02abff733ae1b0715a2c43a67f389974 100644 (file)
@@ -153,6 +153,7 @@ templates_newsletterdir = $(templatesdir)/newsletter
 
 templates_people_DATA = \
        src/templates/people/base.html \
+       src/templates/people/call.html \
        src/templates/people/calls.html \
        src/templates/people/index.html \
        src/templates/people/passwd.html \
@@ -168,6 +169,7 @@ templates_people_modules_DATA = \
        src/templates/people/modules/accounts-list.html \
        src/templates/people/modules/cdr.html \
        src/templates/people/modules/channels.html \
+       src/templates/people/modules/mos.html \
        src/templates/people/modules/registrations.html
 
 templates_people_modulesdir = $(templates_peopledir)/modules
index 559b83e2f6f21875e19808c879a7a24456c435c6..a739231241384e29f3969739c3b41d78b99319b3 100644 (file)
@@ -61,6 +61,13 @@ class Freeswitch(Object):
                for row in res:
                        yield CDR(self, data=row)
 
+       def get_call_by_uuid(self, uuid):
+               res = self.db.get("SELECT * FROM cdr \
+                       WHERE uuid = %s", uuid)
+
+               if res:
+                       return CDR(self, data=res)
+
 
 class SIPRegistration(object):
        def __init__(self, freeswitch, data):
@@ -194,6 +201,25 @@ class CDR(object):
        def backend(self):
                return self.freeswitch.backend
 
+       @property
+       def db(self):
+               return self.freeswitch.db
+
+       @property
+       def uuid(self):
+               return self.data.uuid
+
+       @lazy_property
+       def bleg(self):
+               if self.data.bleg_uuid:
+                       return self.freeswitch.get_call_by_uuid(self.data.bleg_uuid)
+
+               # If we are the bleg, we need to search for one where UUID is the bleg
+               res = self.db.get("SELECT * FROM cdr WHERE bleg_uuid = %s", self.uuid)
+
+               if res:
+                       return CDR(self.freeswitch, data=res)
+
        @property
        def direction(self):
                if self.data.bleg_uuid:
@@ -235,7 +261,8 @@ class CDR(object):
 
        @property
        def user_agent(self):
-               return self.data.user_agent.replace("_", " ")
+               if self.data.user_agent:
+                       return self.data.user_agent.replace("_", " ")
 
        @property
        def size(self):
diff --git a/src/templates/people/call.html b/src/templates/people/call.html
new file mode 100644 (file)
index 0000000..cd87e74
--- /dev/null
@@ -0,0 +1,75 @@
+{% extends "base.html" %}
+
+{% block title %}{{ _("Call") }}{% end block %}
+
+{% block main %}
+       <div class="card">
+               <div class="card-body">
+                       <h4 class="card-title mb-1">
+                               {% if call.direction == "inbound" %}
+                                       {{ _("Call to") }}
+
+                                       {% if call.callee %}
+                                               <a href="/users/{{ call.callee.uid }}">{{ call.callee }}</a>
+                                       {% else %}
+                                               {{ format_phone_number(call.callee_number) }}
+                                       {% end %}
+                               {% elif call.direction == "outbound" %}
+                                       {{ _("Call from") }}
+
+                                       {% if call.caller %}
+                                               <a href="/users/{{ call.caller.uid }}">{{ call.caller }}</a>
+                                       {% else %}
+                                               {{ format_phone_number(call.caller_number) }}
+                                       {% end %}
+                               {% end %}
+                       </h4>
+                       <h6 class="card-subtitle text-muted mb-4">{{ locale.format_date(call.time_answered or call.time_start) }}</h6>
+
+                       <h3 class="text-center my-5">
+                               {% if call.duration %}
+                                       {{ format_time(call.duration) }}
+                               {% else %}
+                                       {{ _("Not Answered") }}
+                               {% end %}
+                       </h3>
+
+                       <h6>{{ _("Media Information") }}</h6>
+
+                       <div class="row">
+                               {% for c in (call, call.bleg) %}
+                                       {% if c %}
+                                               <div class="col">
+                                                       <div class="card card-body bg-light">
+                                                               <p>
+                                                                       <strong>
+                                                                               {% if c == call %}
+                                                                                       {{ _("Your Leg") }}
+                                                                               {% else %}
+                                                                                       {{ _("Other Leg") }}
+                                                                               {% end %}
+                                                                       </strong>
+                                                               </p>
+
+                                                               <p class="text-center">
+                                                                       {% module MOS(c) %}
+                                                               </p>
+
+                                                               <dl class="row mb-0">
+                                                                       <dt class="col-sm-6">{{ _("Codec") }}</dt>
+                                                                       <dd class="col-sm-6">{{ c.codec or _("N/A") }}</dd>
+
+                                                                       <dt class="col-sm-6">{{ _("Data Transferred") }}</dt>
+                                                                       <dd class="col-sm-6">{{ format_size(c.size) }}</dd>
+
+                                                                       <dt class="col-sm-6">{{ _("User Agent") }}</dt>
+                                                                       <dd class="col-sm-6">{{ c.user_agent or _("N/A") }}</dd>
+                                                               </dl>
+                                                       </div>
+                                               </div>
+                                       {% end %}
+                               {% end %}
+                       </div>
+               </div>
+       </div>
+{% end %}
index 80d1ceca28120a7a38fc2ff3c6fff81fda1ab16d..a2ad0a2baacbf2928298bafe9f6b6b7976d606bc 100644 (file)
                                        {% if c.direction == "inbound" %}
                                                <span class="fas fa-arrow-right text-danger"></span>
 
-                                               {% if c.callee %}
-                                                       <a href="/users/{{ c.callee.uid }}">{{ c.callee }}</a>
-                                               {% else %}
-                                                       {{ format_phone_number(c.callee_number) }}
-                                               {% end %}
+                                               <a href="/users/{{ account.uid }}/calls/{{ c.uuid }}">
+                                                       {% if c.callee %}
+                                                               {{ c.callee }}
+                                                       {% else %}
+                                                               {{ format_phone_number(c.callee_number) }}
+                                                       {% end %}
+                                               </a>
                                        {% elif c.direction == "outbound" %}
                                                <span class="fas fa-arrow-left text-success"></span>
 
-                                               {% if c.caller %}
-                                                       <a href="/users/{{ c.caller.uid }}">{{ c.caller }}</a>
-                                               {% else %}
-                                                       {{ format_phone_number(c.caller_number) }}
-                                               {% end %}
+                                               <a href="/users/{{ account.uid }}/calls/{{ c.uuid }}">
+                                                       {% if c.caller %}
+                                                               {{ c.caller }}
+                                                       {% else %}
+                                                               {{ format_phone_number(c.caller_number) }}
+                                                       {% end %}
+                                               </a>
                                        {% end %}
 
                                        <br>
 
-                                       {% if c.mos %}
-                                               <span class="small text-muted" title="{{ "%.2f" % c.mos }}/5">
-                                                       {% for i in range(1, 6) %}
-                                                               {% if c.mos > (i + 0.5) %}
-                                                                       <span class="fas fa-star"></span>
-                                                               {% elif c.mos > i %}
-                                                                       <span class="fas fa-star-half-alt"></span>
-                                                               {% else %}
-                                                                       <span class="far fa-star"></span>
-                                                               {% end %}
-                                                       {% end %}
-                                               </span>
-                                       {% end %}
+                                       {% module MOS(c) %}
                                </td>
 
                                <td class="text-right">
diff --git a/src/templates/people/modules/mos.html b/src/templates/people/modules/mos.html
new file mode 100644 (file)
index 0000000..524ad74
--- /dev/null
@@ -0,0 +1,13 @@
+{% if call.mos %}
+       <span class="small text-muted" title="{{ "%.2f" % call.mos }}/5">
+               {% for i in range(1, 6) %}
+                       {% if call.mos > (i + 0.5) %}
+                               <span class="fas fa-star"></span>
+                       {% elif call.mos > i %}
+                               <span class="fas fa-star-half-alt"></span>
+                       {% else %}
+                               <span class="far fa-star"></span>
+                       {% end %}
+               {% end %}
+       </span>
+{% end %}
index 46c7fe572fb833b79fd68b1470b77020371db9d9..b8d465462e7271a2ea72961893d03924b8953ee1 100644 (file)
@@ -62,6 +62,7 @@ class Application(tornado.web.Application):
                                "AccountsList"         : people.AccountsListModule,
                                "CDR"                  : people.CDRModule,
                                "Channels"             : people.ChannelsModule,
+                               "MOS"                  : people.MOSModule,
                                "Registrations"        : people.RegistrationsModule,
 
                                # Old modules
@@ -254,6 +255,7 @@ class Application(tornado.web.Application):
                        (r"/users", people.UsersHandler),
                        (r"/users/(\w+)", people.UserHandler),
                        (r"/users/(\w+)\.jpg", people.AvatarHandler),
+                       (r"/users/(\w+)/calls/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})", people.CallHandler),
                        (r"/users/(\w+)/calls(?:/(\d{4}-\d{2}-\d{2}))?", people.CallsHandler),
                        (r"/users/(\w+)/edit", people.UserEditHandler),
                        (r"/users/(\w+)/passwd", people.UserPasswdHandler),
index d5fae5aa4f98d4fb8b9eb28795d6547c672d8b24..6ab25bc21863c548136298bec3ea20a7f1848e9d 100644 (file)
@@ -71,6 +71,18 @@ class CallsHandler(base.BaseHandler):
                self.render("people/calls.html", account=account, date=date)
 
 
+class CallHandler(base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self, uid, uuid):
+               call = self.backend.talk.freeswitch.get_call_by_uuid(uuid)
+               if not call:
+                       raise tornado.web.HTTPError(404, "Could not find call %s" % uuid)
+
+               # XXX limit
+
+               self.render("people/call.html", call=call)
+
+
 class RegistrationsHandler(base.BaseHandler):
        @tornado.web.authenticated
        def get(self, uid):
@@ -245,6 +257,11 @@ class ChannelsModule(ui_modules.UIModule):
                return self.render_string("people/modules/channels.html", account=account, channels=channels)
 
 
+class MOSModule(ui_modules.UIModule):
+       def render(self, call):
+               return self.render_string("people/modules/mos.html", call=call)
+
+
 class RegistrationsModule(ui_modules.UIModule):
        def render(self, account):
                return self.render_string("people/modules/registrations.html", account=account)