Browse Source

Added staff user who can see all locaions analytics

Mohidul Islam 4 năm trước cách đây
mục cha
commit
915d17d13b

+ 21 - 0
manager/templates/_facebook_review.html

@@ -0,0 +1,21 @@
+<div class="review-content">
+  <div style="flex-grow: 10">
+    <div class="review-header-divider">
+      {% if review.recommendation_type == True %}
+        <span style="color: green">Recommended</span>
+      {% else %}
+        <span style="color: red">Not Recommended</span>
+      {% endif %}
+      <span class="text-muted mb-2">at {{ review.create_time|date:"F d, Y" }}</span>
+      <span style="float: right"> <a href="https://facebook.com/{{ review.id }}">Link</a></span>
+    </div>
+    {% if review.review_text %}
+        <p >{{ review.review_text }}</p>
+    {% endif %}
+    {% if review.facebookreviewreply.replied_text %}
+        <p class="alert alert-success">Reply: {{ review.facebookreviewreply.replied_text }}</p>
+    {% else %}
+     <p class="alert alert-warning">Not Replied Yet!</p>
+    {% endif %}
+  </div>
+</div>

+ 20 - 0
manager/templates/_google_review.html

@@ -0,0 +1,20 @@
+<div class="review-content">
+  <div>
+  <img class="rounded-circle article-img" src="{{ review.reviewer_photo }}">
+  </div>
+    <div style="flex-grow: 10">
+    <div class="review-header-divider">
+      <span class="mr-2"><b>{{ review.reviewer_name }}</b></span>
+      <small class="text-muted">{{ review.update_time|date:"F d, Y" }}</small>
+      <span style="color: #a41515; float: right">{{ review.star_rating }} X &#9733</span>
+    </div>
+    {% if review.comment %}
+        <p >{{ review.comment }}</p>
+    {% endif %}
+    {% if review.reply.replied_text %}
+        <p class="alert alert-success">Reply: {{ review.reply.replied_text }}</p>
+    {% else %}
+     <p class="alert alert-warning">Not Replied Yet!</p>
+    {% endif %}
+  </div>
+</div>

+ 72 - 0
manager/templates/_navbar_man.html

@@ -0,0 +1,72 @@
+<nav class="col-md-2 d-none d-md-block bg-light sidebar">
+  <div class="sidebar-sticky">
+
+    <div class="location-detail">
+      <img class="img-thumbnail" align="center" width="100%" src="https://ercare24.com/wp-content/uploads/2016/07/signature-care-resized-e1462918690585.png">
+
+      <p><b>SignatureCare Emergency Center</b></p>
+
+      <p><i class="fa fa-map-marker" aria-hidden="true"></i>{{ location.care_name }}</p>
+      {% for lm in location.managers %}
+        <p><i class="fa fa-envelope" aria-hidden="true"></i>{{ lm.email }}</p>
+      {% endfor %}
+    </div>
+   <textarea hidden id="location_id"> {{ location.location_id }}</textarea>
+
+    <hr>
+
+    <ul class="nav flex-column">
+      <li class="nav-item">
+        <a class="nav-link" href="{% url 'location-analytics-man' location.location_id %}">
+          <span data-feather="home"></span>
+          Dashboard</span>
+        </a>
+      </li>
+      <li class="nav-item">
+        <a class="nav-link" href="{% url 'location-analytics-graph-man' location.location_id %}">
+          <span data-feather="bar-chart-2"></span>
+          Analytics
+        </a>
+      </li>
+      <li class="nav-item">
+        <a class="nav-link" href="{% url 'staff-leaderboard-man' location.location_id %}">
+          <span data-feather="award"></span>
+          Staff Leaderboard
+        </a>
+      </li>
+      <li class="nav-item">
+        <a class="nav-link" href="#">
+          <span data-feather="layers"></span>
+          Integrations
+        </a>
+      </li>
+    </ul>
+
+    <h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
+      <span>Review List</span>
+      <a class="d-flex align-items-center text-muted" href="#">
+        <span data-feather="plus-circle"></span>
+      </a>
+    </h6>
+    <ul class="nav flex-column mb-2">
+      <li class="nav-item">
+        <a class="nav-link" href="{% url 'location-wise-review-list-man' platform='google' location_id=location.pk %}">
+          <span data-feather="file-text"></span>
+          Google
+        </a>
+      </li>
+      <li class="nav-item">
+        <a class="nav-link" href="{% url 'location-wise-review-list-man' platform='facebook' location_id=location.pk %}">
+          <span data-feather="file-text"></span>
+          Facebook
+        </a>
+      </li>
+<!--      <li class="nav-item">-->
+<!--        <a class="nav-link" href="{% url 'location-wise-review-list' 'yelp' %}">-->
+<!--          <span data-feather="file-text"></span>-->
+<!--          Yelp-->
+<!--        </a>-->
+<!--      </li>-->
+    </ul>
+  </div>
+</nav>

+ 12 - 0
manager/templates/_yelp_review.html

@@ -0,0 +1,12 @@
+<div class="review-content">
+  <div style="flex-grow: 10">
+    <div class="review-header-divider">
+      <span class="mr-2"><b>{{ review.reviewer_name }}</b></span>
+      <small class="text-muted">{{ review.date_posted|date:"F d, Y" }}</small>
+      <span style="color: #a41515; float: right">{{ review.rating }} X &#9733</span>
+    </div>
+    {% if review.comment %}
+        <p >{{ review.comment }}</p>
+    {% endif %}
+  </div>
+</div>

+ 286 - 0
manager/templates/location-wise-reviews-man.html

@@ -0,0 +1,286 @@
+{% extends 'manager-base.html' %}
+
+{% block content %}
+
+  <div class="graph-card graph-card-shadow graph-container">
+    <div style="width: 100%;">
+      <canvas id="myChart" width="1200" height="300"></canvas>
+    </div>
+  </div>
+
+  <div class="graph-card graph-card-shadow graph-container">
+      <div id="bar-chart-container" style="position: relative; width: 70%;">
+        <canvas id="googleLineChart" width="900" height="300"></canvas>
+      </div>
+      <div id="pie-chart-container" style="position: relative; width: 30%;">
+        <canvas id="googlePieChart" width="200" height="150"></canvas>
+      </div>
+  </div>
+
+  <div class="graph-card graph-card-shadow graph-container">
+      <div style="position: relative; width: 70%;">
+        <canvas id="facebookLineChart" width="900" height="300"></canvas>
+      </div>
+      <div style="position: relative; width: 30%;">
+        <canvas id="facebookPieChart" width="200" height="150"></canvas>
+      </div>
+  </div>
+<!--  <div class="graph-card graph-card-shadow graph-container">-->
+<!--      <div style="position: relative; width: 70%;">-->
+<!--        <canvas id="yelpLineChart" width="900" height="300"></canvas>-->
+<!--      </div>-->
+<!--      <div style="position: relative; width: 30%;">-->
+<!--        <canvas id="yelpPieChart" width="200" height="150"></canvas>-->
+<!--      </div>-->
+<!--  </div>-->
+
+<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js" integrity="sha256-TQq84xX6vkwR0Qs1qH5ADkP+MvH0W+9E7TdHJsoIQiM=" crossorigin="anonymous"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script>
+
+<script>
+  var ctx = document.getElementById("myChart");
+  var google_line_ctx = document.getElementById("googleLineChart");
+  var google_pie_ctx = document.getElementById("googlePieChart");
+  var facebook_line_ctx = document.getElementById("facebookLineChart");
+  var facebook_pie_ctx = document.getElementById("facebookPieChart");
+  var location_id = document.getElementById("location_id").value;
+  console.log(location_id)
+  var endpoint = '/user/api/analytics/all-platform';
+  params = {
+      "location_id": location_id.trim()
+  }
+  console.log(params)
+  $.ajax({
+        type: "get",
+        url: endpoint,
+        data: params,
+        dataType: 'json',
+        success: function(data) {
+        console.log(data)
+
+        // All data together in a bar chart..
+          var myBarChart = new Chart(ctx, {
+          type: 'bar',
+          data: {
+              labels: data.google.labels,
+              datasets: [
+                  {
+                    label: 'Google',
+                    data: data.google.total_review,
+                    borderColor: 'rgb(255, 204, 0)',
+                    backgroundColor: 'rgb(255, 204, 0)',
+                    borderWidth: 1,
+                    fill: false
+                },
+                {
+                    label: 'Facebook',
+                    data: data.facebook.total_review,
+                    borderColor: 'rgb(0, 51, 204)',
+                    backgroundColor: 'rgb(0, 51, 204)',
+                    borderWidth: 1,
+                    fill: false
+                }]
+            },
+            options: {
+                scales: {
+                    yAxes: [{
+                        ticks: {
+                            beginAtZero: true
+                        }
+                    }],
+                    xAxes: [{
+                        gridLines: {
+                            drawOnChartArea:false
+                        }
+                    }]
+                },
+                title: {
+                    display: true,
+                    fontSize: 16,
+                    text: "Review of this month in all platforms."
+                }
+            }
+        });
+
+        // Google review charts
+        // Google line chart
+        var myGoogleLineChart = new Chart(google_line_ctx, {
+          type: 'line',
+          data: {
+              labels: data.google.labels,
+              datasets: [
+                  {
+                    label: '1*',
+                    data: data.google.star_rating[0],
+                    borderColor: 'rgb(204, 0, 17)',
+                    backgroundColor: 'rgb(204, 0, 17)',
+                    borderWidth: 1,
+                    lineTension: 0,
+                    fill: false
+                },
+                {
+                    label: '2*',
+                    data: data.google.star_rating[1],
+                    borderColor: 'rgb(255, 119, 0)',
+                    backgroundColor: 'rgb(255, 119, 0)',
+                    borderWidth: 1,
+                    lineTension: 0,
+                    fill: false
+                },
+                {
+                    label: '3*',
+                    data: data.google.star_rating[2],
+                    borderColor: 'rgb(219, 208, 0)',
+                    backgroundColor: 'rgb(219, 208, 0)',
+                    borderWidth: 1,
+                    lineTension: 0,
+                    fill: false
+                },
+                {
+                    label: '4*',
+                    data: data.google.star_rating[3],
+                    borderColor: 'rgb(0, 157, 166)',
+                    backgroundColor: 'rgb(0, 157, 166)',
+                    borderWidth: 1,
+                    lineTension: 0,
+                    fill: false
+                },
+                {
+                    label: '5*',
+                    data: data.google.star_rating[4],
+                    borderColor: 'rgb(0, 97, 0)',
+                    backgroundColor: 'rgb(0, 97, 0)',
+                    borderWidth: 1,
+                    lineTension: 0,
+                    fill: false,
+
+                }]
+            },
+            options: {
+                borderJoinStyle: "bevel",
+                scales: {
+                    yAxes: [{
+                        ticks: {
+                            beginAtZero: true
+                        }
+                    }],
+                    xAxes: [{
+                        gridLines: {
+                            drawOnChartArea:false
+                        }
+                    }]
+                },
+                title: {
+                    display: true,
+                    fontSize: 16,
+                    text: "Monthly review in Google."
+                }
+            }
+        });
+
+        // Google pie chart
+        var myGooglePieChart = new Chart(google_pie_ctx, {
+          type: 'pie',
+          data: {
+              labels: data.google.curr_month.label,
+              datasets: [
+                  {
+                    data: data.google.curr_month.total,
+                    backgroundColor: [
+                      'rgb(0, 97, 0)',
+                      'rgb(0, 157, 166)',
+                      'rgb(219, 208, 0)',
+                      'rgb(255, 119, 0)',
+                       'rgb(204, 0, 17)'
+                    ]
+                }]
+            },
+            options: {
+              title: {
+                display: true,
+                fontSize: 12,
+               // position: 'bottom',
+                text: 'All reviews of this month'
+              }
+            }
+        });
+        // Facebook review charts
+        // Facebook line chart
+        var myFacebookLineChart = new Chart(facebook_line_ctx, {
+          type: 'line',
+          data: {
+              labels: data.facebook.labels,
+              datasets: [
+                  {
+                    label: 'Not Recommended',
+                    data: data.facebook.star_rating[0],
+                    borderColor: 'rgb(204, 0, 17)',
+                    backgroundColor: 'rgb(204, 0, 17)',
+                    borderWidth: 1,
+                    lineTension: 0,
+                    fill: false
+                },
+                {
+                    label: 'Recommended',
+                    data: data.facebook.star_rating[1],
+                    borderColor: 'rgb(0, 51, 204)',
+                    backgroundColor: 'rgb(0, 51, 204)',
+                    borderWidth: 1,
+                    lineTension: 0,
+                    fill: false
+                }]
+            },
+            options: {
+                borderJoinStyle: "bevel",
+                scales: {
+                    yAxes: [{
+                        ticks: {
+                            beginAtZero: true
+                        }
+                    }],
+                    xAxes: [{
+                        gridLines: {
+                            drawOnChartArea:false
+                        }
+                    }]
+                },
+                title: {
+                    display: true,
+                    fontSize: 16,
+                    text: "Monthly review in Facebook."
+                }
+            }
+        });
+
+        // Google pie chart
+        var myFacebookPieChart = new Chart(facebook_pie_ctx, {
+          type: 'pie',
+          data: {
+              labels: data.facebook.curr_month.label,
+              datasets: [
+                  {
+                    data: data.facebook.curr_month.total,
+                    backgroundColor: [
+                        'rgb(0, 51, 204)',
+                        'rgb(204, 0, 17)'
+                    ]
+                }]
+            },
+            options: {
+              title: {
+                display: true,
+                fontSize: 12,
+                text: 'All reviews of this month'
+              }
+            }
+        });
+    },
+
+    error: function(error_data) {
+       console.log(error_data);
+    }
+  });
+</script>
+
+{% endblock content %}

+ 45 - 20
manager/templates/locations.html

@@ -12,6 +12,29 @@
     <!-- Custom styles for this template -->
     <link rel="stylesheet" type="text/css" href="{% static 'user-dashboard.css' %}">
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
+    <style>
+      a:link {
+        text-decoration: none;
+        color: #050608;
+      }
+
+      a:visited {
+        text-decoration: none;
+        color: #013568;
+      }
+
+      a:hover {
+        text-decoration: none;
+        color: #51585e;
+
+      }
+
+      a:active {
+        text-decoration: none;
+        color: #272727;
+
+      }
+    </style>
   </head>
 
   <body>
@@ -33,27 +56,29 @@
     <div class="container">
       <div class="row">
       {% for loc in all_locations %}
-      <div class="col-sm-6">
-        <div class="card mt-2 mb-2 graph-card-shadow">
-          <div class="card-header">
-            <span style="font-size: larger; font-family: sans-serif; font-weight: bold;">{{ loc.care_name }}</span>
-            <span style="float: right;">
-                <i class="fa fa-hospital-o mr-2" aria-hidden="true"></i>
-                <spen>{{ loc.location_name }}</spen>
-            </span>
-          </div>
-          <div class="card-body">
-<!--            <span>Google Review URL: <a href="{{ loc.website_url }}">{{ loc.website_url }}</a></span><br>-->
-<!--            <span>Facebook Page URL: <a href="https://web.facebook.com/{{ loc.facebookpage.id }}">"https://web.facebook.com/{{ loc.facebookpage.id }}</a></span>-->
-            <span>
-              Total Review:
-              <span > <i class="fa fa-google" aria-hidden="true" style="color: #ff7700; margin-left: 1rem;"></i> {{ loc.all_google_review.count }}</span>
-              <span > <i class="fa fa-facebook" aria-hidden="true" style="color: blue; margin-left: 2rem;"></i> {{ loc.all_facebook_review.count }} </span>
-            </span>
+          <div class="col-sm-6">
+            <a href="{% url 'location-analytics-man' loc.location_id %}">
+            <div class="card mt-2 mb-2 graph-card-shadow">
+              <div class="card-header">
+                <span style="font-size: larger; font-family: sans-serif; font-weight: bold;">{{ loc.care_name }}</span>
+                <span style="float: right;">
+                    <i class="fa fa-hospital-o mr-2" aria-hidden="true"></i>
+                    <spen>{{ loc.location_name }}</spen>
+                </span>
+              </div>
+              <div class="card-body">
+    <!--            <span>Google Review URL: <a href="{{ loc.website_url }}">{{ loc.website_url }}</a></span><br>-->
+    <!--            <span>Facebook Page URL: <a href="https://web.facebook.com/{{ loc.facebookpage.id }}">"https://web.facebook.com/{{ loc.facebookpage.id }}</a></span>-->
+                <span>
+                  Total Review:
+                  <span > <i class="fa fa-google" aria-hidden="true" style="color: #ff7700; margin-left: 1rem;"></i> {{ loc.all_google_review.count }}</span>
+                  <span > <i class="fa fa-facebook" aria-hidden="true" style="color: blue; margin-left: 2rem;"></i> {{ loc.all_facebook_review.count }} </span>
+                </span>
+              </div>
+            </div>
+            </a>
           </div>
-        </div>
-      </div>
-    {% endfor %}
+        {% endfor %}
       </div>
     </div>
     <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>

+ 80 - 0
manager/templates/manager-base.html

@@ -0,0 +1,80 @@
+{% load static %}
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+    <meta name="description" content="">
+    <meta name="author" content="">
+    <title>SignatureCare Review Portal</title>
+    <link rel="canonical" href="https://getbootstrap.com/docs/4.0/examples/dashboard/">
+    <!-- Bootstrap core CSS -->
+    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
+    <!-- Custom styles for this template -->
+    <link rel="stylesheet" type="text/css" href="{% static 'user-dashboard.css' %}">
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
+
+
+    {# Include FontAwesome; required for icon display #}
+    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
+
+    {# Include Bootstrap 4 and jQuery #}
+    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
+    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
+
+
+  </head>
+
+  <body>
+    <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
+      <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="{% url 'home-view' %}">SignatureCare Review Portal</a>
+      <ul class="navbar-nav px-3">
+        <li class="nav-item text-nowrap">
+          <a class="nav-link" href="{% url 'logout' %}">Sign out</a>
+        </li>
+      </ul>
+    </nav>
+
+    <div class="container-fluid">
+      <div class="row">
+        {% include '_navbar_man.html' %}
+
+        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
+          <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
+            <h1 class="h2">Dashboard for {{ location.care_name }}</h1>
+            <div class="btn-toolbar mb-2 mb-md-0">
+              <div class="btn-group mr-2">
+                <button class="btn btn-sm btn-outline-secondary">Export</button>
+              </div>
+              <button class="btn btn-sm btn-outline-secondary dropdown-toggle">
+                <span data-feather="calendar"></span>
+                This week
+              </button>
+            </div>
+          </div>
+          {% block content %}
+          {% endblock %}
+        </main>
+      </div>
+    </div>
+        <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap mt-4">
+            <span style="color: white;">&copy;2020 Byte Trek Online Reputation Manager. - Developed by Byte Trek Ltd. </span>
+        </nav>
+    <!-- Bootstrap core JavaScript
+    ================================================== -->
+    <!-- Placed at the end of the document so the pages load faster -->
+    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
+    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
+    <script>window.jQuery || document.write('<script src="/static/jquery-slim.min.js"><\/script>')</script>
+
+
+    <!-- Icons -->
+    <script src="https://unpkg.com/feather-icons/dist/feather.min.js"></script>
+
+    <script>
+      feather.replace()
+    </script>
+
+    <!-- Graphs -->
+  </body>
+</html>

+ 155 - 0
manager/templates/manager-dashboard.html

@@ -0,0 +1,155 @@
+{% extends 'manager-base.html' %}
+{% block content %}
+
+
+<!--cart-->
+<div class="row">
+
+  <div class="col-sm-6 col-md-6">
+      <div class="card text-white bg-secondary mb-3">
+      <div class="card-header"><h5 class="card-title">Google <span><i class="fa fa-google" aria-hidden="true"></i></span></h5></div>
+        <div class="card-body">
+          <table class="table">
+            <tr><td><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Reviews</td> <td>Count</td></tr>
+            <tr>
+              <td>This month (so far)</td>
+              <td>{{ google_this_month }}</td>
+            </tr>
+            <tr>
+              <td>Last month</td>
+              <td>{{ google_last_month }}</td>
+            </tr>
+          </table>
+        </div>
+      </div>
+  </div>
+
+<!--  <div class="col-sm-6 col-md-4">-->
+<!--      <div class="card text-white bg-danger mb-3">-->
+<!--      <div class="card-header"><h5 class="card-title">Yelp <span><i class="fa fa-yelp" aria-hidden="true"></i></span></h5></div>-->
+<!--        <div class="card-body">-->
+<!--          <table class="table">-->
+<!--            <tr>-->
+<!--              <td><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  Total Review</td>-->
+<!--              <td>{{ yelp_total }}</td>-->
+<!--            </tr>-->
+<!--            <tr>-->
+<!--              <td><i class="fa fa-line-chart" aria-hidden="true"></i>  Growth</td>-->
+<!--              <td>{{ yelp_total_growth }}%</td>-->
+<!--            </tr>-->
+<!--          </table>-->
+<!--        </div>-->
+<!--      </div>-->
+<!--  </div>-->
+
+  <div class="col-sm-6 col-md-6">
+      <div class="card text-white bg-primary mb-3">
+      <div class="card-header"><h5 class="card-title">Facebook <span><i class="fa fa-facebook" aria-hidden="true"></i></span></h5></div>
+        <div class="card-body">
+          <table class="table">
+            <tr>
+              <td><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Reviews</td> <td>Count</td></tr>
+            <tr>
+              <td>This month (so far)</td>
+              <td>{{ facebook_this_month }}</td>
+            </tr>
+            <tr>
+              <td>Last month</td>
+              <td>{{ facebook_last_month }}</td>
+            </tr>
+          </table>
+        </div>
+      </div>
+  </div>
+
+</div>
+
+<!--    canvas-->
+  <canvas class="my-4" id="myChart" width="900" height="300"></canvas>
+ </div>
+
+<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js" integrity="sha256-TQq84xX6vkwR0Qs1qH5ADkP+MvH0W+9E7TdHJsoIQiM=" crossorigin="anonymous"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script>
+
+<script>
+  var ctx = document.getElementById("myChart");
+  var location_id = document.getElementById("location_id").value;
+  console.log(location_id);
+  var endpoint = '/user/api/analytics';
+  params = {
+      "location_id":location_id.trim()
+  }
+  console.log(params)
+  $.ajax({
+        type: "get",
+        url: endpoint,
+        data: params,
+        dataType: 'json',
+        success: function(data) {
+        console.log(data)
+          var myBarChart = new Chart(ctx, {
+          type: 'bar',
+          data: {
+              labels: data.label,
+              datasets: [
+                  {
+                    label: 'Google',
+                    data: data.google,
+                    borderColor: 'rgb(255, 204, 0)',
+                    backgroundColor: 'rgb(255, 204, 0)',
+                    borderWidth: 1,
+                    fill: false
+                },
+                {
+                    label: 'Facebook',
+                    data: data.facebook,
+                    borderColor: 'rgb(0, 51, 204)',
+                    backgroundColor: 'rgb(0, 51, 204)',
+                    borderWidth: 1,
+                    fill: false
+                }]
+            },
+            options: {
+                scales: {
+                    yAxes: [{
+                        display: true,
+                        scaleLabel: {
+                          display: true,
+                          fontSize: 16,
+                          fontStyle: 'italic',
+                          labelString: 'Total review count'
+                        },
+                        ticks: {
+                            beginAtZero: true,
+                            stepSize: 1
+                        }
+                    }],
+                    xAxes: [{
+                        display: true,
+                            scaleLabel: {
+                              display: true,
+                              fontSize: 16,
+                              fontStyle: 'italic',
+                              labelString: 'Day of the month'
+                            },
+                        gridLines: {
+                            drawOnChartArea:false
+                        }
+                    }]
+                },
+                title: {
+                    display: true,
+                    fontSize: 16,
+                    text: "Review of this month in all platforms."
+                }
+            }
+        });
+    },
+
+    error: function(error_data) {
+       console.log(error_data);
+    }
+  });
+</script>
+{% endblock %}

+ 38 - 0
manager/templates/review-list-man.html

@@ -0,0 +1,38 @@
+{% extends 'manager-base.html' %}
+{% block content %}
+<h2 style="text-align: center;">All reviews posted on {{ platform|title }}</h2>
+{% for review in reviews %}
+  {% if platform == 'google' %}
+    {% include '_google_review.html' %}
+  {% elif platform == 'facebook' %}
+    {% include '_facebook_review.html' %}
+  {% elif platform == 'yelp' %}
+    {% include '_yelp_review.html' %}
+  {% endif %}
+{% endfor %}
+
+<div align="center">
+  {% if reviews.has_other_pages %}
+
+    {% if reviews.has_previous %}
+      <a class="btn btn-outline-info mb-4" href="?page=1">First</a>
+      <a class="btn btn-outline-info mb-4" href="?page={{ reviews.previous_page_number }}">Previous</a>
+    {% endif %}
+
+    {% for num in reviews.paginator.page_range %}
+      {% if reviews.number == num %}
+        <a class="btn btn-info mb-4" href="?page={{ num }}">{{ num }}</a>
+      {% elif num > reviews.number|add:'-3' and num < reviews.number|add:'3' %}
+        <a class="btn btn-outline-info mb-4" href="?page={{ num }}">{{ num }}</a>
+      {% endif %}
+    {% endfor %}
+
+    {% if reviews.has_next %}
+      <a class="btn btn-outline-info mb-4" href="?page={{ reviews.next_page_number }}">Next</a>
+      <a class="btn btn-outline-info mb-4" href="?page={{ reviews.paginator.num_pages }}">Last</a>
+    {% endif %}
+
+  {% endif %}
+</div>
+
+{% endblock %}

+ 84 - 0
manager/templates/staff_list_man.html

@@ -0,0 +1,84 @@
+{% extends 'manager-base.html' %}
+{% load crispy_forms_tags %}
+{% block content %}
+
+<!--adding a new staff member.-->
+  {# Django Tempus Dominus assets are included in `{{ form.media }}` #}
+  {{ date_form.media }}
+  <div class="row">
+    <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bd-example-modal-lg" style="margin: 15px 5px 15px 15px; margin-bottom: 30px;">Add a new staff</button>
+    <form method="post" class="form-row align-items-center" action="{% url 'sync-staff-list-man' location.pk %}">
+        {% csrf_token %}
+      <div class="col-auto">
+        {{ date_form.start_date }}
+      </div>
+      <div class="col-auto">
+        {{ date_form.end_date }}
+      </div>
+      <input type="submit" name="Submit" class="btn btn-primary">
+    </form>
+  </div>
+  <div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
+    <div class="modal-dialog modal-lg">
+      <div class="modal-content">
+        <div class="content-section">
+        <form method="POST">
+            {% csrf_token %}
+            <fieldset class="form-group">
+                <legend style="text-align: center;" class="border-bottom mb-4"><b>Add a new staff.</b></legend>
+                {{ form|crispy }}
+            </fieldset>
+            <div class="form-group" style="display: grid;">
+                <button class="btn btn-outline-info" type="submit">Submit</button>
+            </div>
+        </form>
+      </div>
+      </div>
+    </div>
+  </div>
+
+  <div class="row">
+    {% for staff in staffs %}
+    <div class="col-sm-6">
+      <div class="card mt-2 mb-2">
+        <div class="card-header">
+          <span style="font-size: larger; font-family: sans-serif; font-weight: bold;">{{staff.name}}</span>
+          <span style="float: right;">
+            {{ staff.department }}
+              <span data-toggle="modal" data-target="#delete-staff"><i class="fa fa-trash" aria-hidden="true" style="color: blue; margin-left: 2rem;"></i></span>
+          </span>
+        </div>
+        <div class="card-body">
+          Name Mentioned:<span > <i class="fa fa-google" aria-hidden="true" style="color: #ff7700; margin-left: 1rem;"></i> {{ staff.name_mentioned_google }}</span>
+          <span > <i class="fa fa-facebook" aria-hidden="true" style="color: blue; margin-left: 2rem;"></i> {{ staff.name_mentioned_facebook }} </span>
+<!--          <span ><i class="fa fa-yelp" aria-hidden="true" style="color: red; margin-left: 2rem;"></i> {{ staff.name_mentioned_yelp }}</span>-->
+          <span style="float: right;">Bonus: ${{ staff.total_units }}</span>
+        </div>
+      </div>
+    </div>
+
+      <!-- Modal -->
+      <div class="modal fade" id="delete-staff" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
+        <div class="modal-dialog">
+          <div class="modal-content">
+            <div class="modal-header">
+              <h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>
+              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                <span aria-hidden="true">&times;</span>
+              </button>
+            </div>
+            <div class="modal-body">
+              If you delete this staff then you will lose all information about this staff.
+            </div>
+            <div class="modal-footer">
+              <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
+
+              <a type="button" href="{% url 'staff-delete-man' staff.id %}" class="btn btn-danger">Yes, Delete!</a>
+            </div>
+          </div>
+        </div>
+      </div>
+
+    {% endfor %}
+  </div>
+{% endblock %}

+ 15 - 1
manager/urls.py

@@ -2,6 +2,20 @@ from django.urls import path
 
 from .views import LocationListView
 
+from .views import (
+    LocationAnalytics,
+    ReviewListLocationWise,
+    ReviewAnalyticsGraph,
+    StaffLeaderBoard,
+    SyncStaffLeaderBoard,
+    StaffDelete,
+)
 urlpatterns = [
-    path('', LocationListView.as_view(), name='location-list')
+    path('', LocationListView.as_view(), name='location-list'),
+    path('analytics/<str:location_id>', LocationAnalytics.as_view(), name='location-analytics-man'),
+    path('reviews/<platform>/<str:location_id>', ReviewListLocationWise.as_view(), name='location-wise-review-list-man'),
+    path('graph/<str:location_id>', ReviewAnalyticsGraph.as_view(), name='location-analytics-graph-man'),
+    path('staff/<str:location_id>', StaffLeaderBoard.as_view(), name='staff-leaderboard-man'),
+    path('staff/delete/<staff_id>', StaffDelete.as_view(), name='staff-delete-man'),
+    path('sync-staff-list/<str:location_id>', SyncStaffLeaderBoard.as_view(), name='sync-staff-list-man'),
 ]

+ 123 - 4
manager/views.py

@@ -1,10 +1,129 @@
-from django.shortcuts import render
+from gauth.models import Location, LocationManager
+from django.http import Http404
+from django.shortcuts import render, redirect
 from django.views.generic import View
+from django.contrib import messages
+from user.forms import StaffRegistrationForm, StaffSheetDateForm
+from review.models import Review
+from facebook_app.models import FacebookReview
+from yelp.models import YelpReview
+from name_extractor.models import Staff
+from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
+from django.shortcuts import get_object_or_404
 
-from gauth.models import Location, LocationManager
+from name_extractor.utils import extract_names_from_reviews, make_all_staffs_point_zero
+
+from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
+from user.utils import (
+    get_google_review_report,
+    get_facebook_report,
+    date_str2datetime
+)
 
 
-class LocationListView(View):
+class LocationListView(View, PermissionRequiredMixin):
+    permission_required = 'is_staff'
+
     def get(self, request, *args, **kwargs):
         locations = Location.objects.all()
-        return render(request, 'locations.html', {'all_locations': locations})
+        return render(request, 'locations.html', {'all_locations': locations})
+
+
+class LocationAnalytics(LoginRequiredMixin, View):
+    def get(self, request, location_id, *args, **kwargs):
+        location = Location.objects.get(pk=location_id)
+        google_report = get_google_review_report(location_id)
+        facebook_report = get_facebook_report(location_id)
+        context = {
+            'location': location,
+            'google_this_month': google_report.get('this_month'),
+            'google_last_month': google_report.get('last_month'),
+            'facebook_this_month': facebook_report.get('this_month'),
+            'facebook_last_month': facebook_report.get('last_month'),
+        }
+        return render(request, 'manager-dashboard.html', context=context)
+
+
+class ReviewListLocationWise(View):
+    def get(self, request, platform, location_id,  *args, **kwargs):
+        location = Location.objects.get(pk=location_id)
+        if platform == 'google':
+            reviews = Review.objects.filter(location_id=location_id).order_by('-update_time')
+        elif platform == 'facebook':
+            reviews = FacebookReview.objects.filter(page__location_id=location_id).order_by('-create_time')
+        elif platform == 'yelp':
+            reviews = YelpReview.objects.filter(location__location_id=location_id).order_by('-date_posted')
+        else:
+            raise Http404()
+
+        page = request.GET.get('page', 1)
+        paginator = Paginator(reviews, 50)
+        try:
+            reviews = paginator.page(page)
+        except PageNotAnInteger:
+            reviews = paginator.page(1)
+        except EmptyPage:
+            reviews = paginator.page(paginator.num_pages)
+        context = {'reviews': reviews, 'platform': platform, 'location': location}
+        return render(request, 'review-list-man.html', context=context)
+
+
+class ReviewAnalyticsGraph(View):
+
+    def get(self, request, location_id, *args, **kwargs):
+        location = Location.objects.get(pk=location_id)
+        return render(request, 'location-wise-reviews-man.html', context={'location': location})
+
+
+class StaffLeaderBoard(View):
+
+    def get(self, request, location_id, *args, **kwargs):
+        location = Location.objects.get(pk=location_id)
+        staffs = Staff.objects.filter(location=location).order_by('-total_units')
+        form = StaffRegistrationForm()
+        date_form = StaffSheetDateForm()
+
+        context = {
+            'location': location,
+            'staffs': staffs,
+            'date_form': date_form,
+            'form': form
+        }
+        return render(request, 'staff_list_man.html', context)
+
+    def post(self, request, location_id, *args, **kwargs):
+        form = StaffRegistrationForm(request.POST)
+        if form.is_valid():
+            name = form.cleaned_data.get('name')
+            department = form.cleaned_data.get('department')
+            nick_names = form.cleaned_data.get('nick_names')
+            staff = Staff.objects.create(
+                name=name,
+                location_id=location_id,
+                department=department,
+                nick_names=nick_names
+            )
+            messages.success(request, f'A new staff {staff} has been created!')
+        return redirect('staff-leaderboard-man', location_id=location_id)
+
+
+class SyncStaffLeaderBoard(View):
+
+    def post(self, request, location_id, *args, **kwargs):
+        start_date = date_str2datetime(request.POST.get('start_date'))
+        end_date = date_str2datetime(request.POST.get('end_date'))
+
+        extract_names_from_reviews(
+            start_date=start_date,
+            end_date=end_date,
+            location_id=location_id
+        )
+        return redirect('staff-leaderboard-man', location_id=location_id)
+
+
+class StaffDelete(View):
+
+    def get(self, request, staff_id, *args, **kwargs):
+        staff = get_object_or_404(Staff, id=staff_id)
+        staff.delete()
+        return redirect('staff-leaderboard-man', location_id=staff.location_id)

+ 8 - 3
user/views.py

@@ -13,6 +13,7 @@ from yelp.models import YelpReview
 from name_extractor.models import Staff
 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 from django.shortcuts import get_object_or_404
+from rest_framework import status
 
 from name_extractor.utils import extract_names_from_reviews, make_all_staffs_point_zero
 
@@ -56,8 +57,10 @@ class LoginRedirectURL(View):
     def dispatch(self, request, *args, **kwargs):
         if not request.user.is_authenticated:
             return redirect('login')
-        elif request.user.is_staff:
+        elif request.user.is_superuser:
             return redirect('un-replied-review')
+        elif request.user.is_staff:
+            return redirect('location-list')
         else:
             return redirect('location-analytics')
 
@@ -88,6 +91,8 @@ class ChartDataThisMonth(APIView):
 class ChartDataAllPlatform(APIView):
     def get(self, request, *args, **kwargs):
         location_id = request.GET['location_id']
+        if not location_id:
+            return Response({'error': 'No location Found'}, status=status.HTTP_400_BAD_REQUEST)
         g_res = get_review_count_by_month(location_id, 'google')
         f_res = get_review_count_by_month(location_id, 'facebook')
         res = {
@@ -118,7 +123,7 @@ class ReviewListLocationWise(View):
         except EmptyPage:
             reviews = paginator.page(paginator.num_pages)
         context = {'reviews': reviews, 'platform': platform}
-        return render(request, 'review-list.html', context=context)
+        return render(request, 'review-list-man.html', context=context)
 
 
 class ReviewAnalyticsGraph(View):
@@ -139,7 +144,7 @@ class StaffLeaderBoard(View):
             'date_form': date_form,
             'form': form
         }
-        return render(request, 'staff_list.html', context)
+        return render(request, 'staff_list_man.html', context)
 
     def post(self, request, *args, **kwargs):
         form = StaffRegistrationForm(request.POST)