Advertisement
Guest User

Untitled

a guest
May 25th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.68 KB | None | 0 0
  1. {% extends 'base.html' %}
  2. {%load staticfiles%}
  3. {% block content %}
  4.  
  5. <style>
  6. select.form-control:not([size]):not([multiple]) {
  7. height: calc(2.25rem + 10px);
  8. }
  9. #graph-card {
  10. background-color:#fff;
  11. box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  12. width: 98%;
  13. min-height: 200px ;
  14. margin: 5px;
  15. transition: 0.3s;
  16. border-radius: 5px;
  17. border: 1px solid white;
  18.  
  19. }
  20. .buttontoggle {
  21. background-color: #3d6bce; /* Green */
  22. border: none;
  23. color: white;
  24. padding: 16px 32px;
  25. text-align: center;
  26. text-decoration: none;
  27. display: inline-block;
  28. font-size: 16px;
  29. margin: 4px 2px;
  30. -webkit-transition-duration: 0.4s; /* Safari */
  31. transition-duration: 0.4s;
  32. cursor: pointer;
  33. }
  34.  
  35. .buttontoogle {
  36. background-color: white;
  37. color: black;
  38. border: 2px solid #008CBA;
  39. }
  40.  
  41. .button2toggle:hover {
  42. background-color: #008CBA;
  43. color: white;
  44. }
  45.  
  46. </style>
  47. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  48. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  49. <div id="content" style="background-color: #f4f4f4">
  50. <button onclick="topFunction()" id="myBtn" title="Go to top"><i class="glyphicon glyphicon-hand-up"></i></button>
  51. <div>
  52. <button class="buttontoggle button2toggle" type="button" id="sidebarCollapse"><i class="glyphicon glyphicon-align-left" style="color: white;"></i>
  53. <span style="color: white;">Toggle Sidebar</span></button>
  54. </div>
  55. <br>
  56. <!---------------Start of Report ------------>
  57. <h3 style="font-family:sans-serif;" align="center" >My Influencer's : {{ user }} </h3>
  58. <div class="col-md-12 pgraph">
  59. <div id="treedata"></div>
  60. </div>
  61.  
  62. <!----div class="row"------>
  63.  
  64. <div class="col-md-12 graph ">
  65. <h3 class="text-center">Segmentation by Influence</h3><hr>
  66.  
  67.  
  68. <!----table -------->
  69. <div id="graph-card">
  70. <div class="col-md-12" id="tt_cat">
  71. </br>
  72. <form method="get" action="{% url 'dashboard:influencer_analysis' %}" enctype="multipart/form-data" class="cts"> {% csrf_token %}
  73. <select id = "category" name ="cat_sel" class="form-control" required >
  74. <option value="all" selected="selected">Choose Categories</option>
  75. {%for i in follower_cat %}
  76. <option name = '{{i}}' value="{{i}}">{{i}}</option>
  77. {% endfor %}
  78. </select>
  79. <button type="submit" class="btn btn-success btn-block" style="background: #3d6bce;">Submit</button>
  80. </form>
  81. </div>
  82. <!--- graphs------>
  83. <div class="table-responsive">
  84. <table class="table" style="font-size: 13px;">
  85. <thead>
  86. <tr>
  87. <th scope="col">User</th>
  88. <th scope="col">Name</th>
  89. <th scope="col">Bio</th>
  90. <th scope="col"># of followers</th>
  91. <th scope="col">Last Active in Days</th>
  92. </tr>
  93. </thead>
  94. <tbody id="d1" style=""></tbody>
  95. </table>
  96. </div>
  97. <div id="pagination_block"></div>
  98. </div>
  99. </div>
  100.  
  101. </div>
  102. <!---Loading on default----->
  103.  
  104. <script>
  105.  
  106. $(function(){
  107.  
  108. var page = 1,
  109. pagelimit = 10,
  110. totalrecord = 0;
  111.  
  112. fetchData(page);
  113.  
  114. // handling the prev-btn
  115. $(document).on('click', ".page-link", function(){
  116. page = $(this).data('page');
  117. fetchData(page);
  118. console.log("current Page: " + page);
  119. })
  120.  
  121. $(document).on('click', "#previous", function(){
  122. if (page > 1) {
  123. page--;
  124. fetchData(page);
  125. }
  126. console.log("Prev Page: " + page);
  127. });
  128.  
  129. // handling the next-btn
  130. $(document).on('click', "#next", function(){
  131. if (page * 10 < totalrecord) {
  132. page++;
  133. fetchData(page);
  134. }
  135. console.log("Next Page: " + page);
  136. });
  137.  
  138.  
  139. function fetchData(page){
  140.  
  141. var category = document.getElementById('category').value;
  142. var url = "{% url 'api:influencer_list' %}?";
  143. if (category && category != "all")
  144. {
  145. url += "cat_sel=" + category + "&";
  146. }
  147. if(page)
  148. {
  149. url += "page=" + page;
  150. }
  151. $.ajax({
  152. url: url,
  153. method: 'get',
  154. success:function(data){
  155. totalrecord = data.count;
  156. var cat_option = ''
  157. for(var customer in data.results){
  158. cat_option+= '<tr><td><img src='+data.results[customer].t_profile_image_url +' class="img-circle" alt="image description" width="45" height="45"/></td><td><a href="http://twitter.com/'+data.results[customer].t_screen_name+'" target="_blank">'+data.results[customer].t_screen_name+'</a></td> <td>'+data.results[customer].t_description+'</td><td>'+data.results[customer].t_followers_count+'</td><td>'+data.results[customer].t_status_created_at_daydiff+'</td></tr>'
  159. }
  160. $('#d1').html(cat_option)
  161. var pagination_html = "<ul class=\"pager\">";
  162. pagination_html += "<li><button id='previous' class='btn btn-primary'><<</button></li>";
  163. for(var page_item = 0; page_item < data.total_pages; page_item++)
  164. {
  165. if(page_item >= (page - 1) && page_item <= (page + 1))
  166. {
  167. pagination_html += "<li class=\"page-item\">";
  168. pagination_html += "<a data-page=\""+ page_item + "\" class=\"page-link\" href=\"#\">" + page_item + " </a>";
  169. pagination_html += "</li>";
  170. }
  171. }
  172. pagination_html += "</li>";
  173. pagination_html += "</ul>";
  174. $('#pagination_block').html(pagination_html);
  175. },
  176. error:function(errorData){
  177. console.log('error')
  178. console.log(errorData)
  179. }
  180. });
  181. }
  182. });
  183.  
  184. </script>
  185.  
  186.  
  187.  
  188. <!-- graph and customer selection with pagination -->
  189. <script>
  190. $(document).ready(function(){
  191. var t20 = $(".cts")
  192. t20.submit(function(event){
  193. event.preventDefault();
  194. var page = 1,
  195. pagelimit = 10,
  196. totalrecord = 0;
  197. fData();
  198. // handling the prev-btn
  199. $("#previous").on("click", function(){
  200. if (page > 1) {
  201. page--;
  202. fData();
  203. }
  204. console.log("Prev Page cat: " + page);
  205. });
  206.  
  207. // handling the next-btn
  208. $("#next").on("click", function(){
  209. if (page * 10 < totalrecord) {
  210. page++;
  211. fData();
  212. }
  213. console.log("Next Page cat: " + page);
  214. });
  215.  
  216.  
  217. function fData(){
  218. var category = document.getElementById('category').value;
  219. $.ajax({
  220.  
  221. url: "{% url 'api:influencer_list' %}?cat_sel="+category,
  222. method: 'get',
  223. data: {
  224. page: page,
  225. },
  226. success:function(data){
  227. var cat_option = ''
  228. for(var customer in data.results){
  229. cat_option+= '<tr><td><img src='+data.results[customer].t_profile_image_url +' class="img-circle" alt="image description" width="45" height="45"/></td><td><a href="http://twitter.com/'+data.results[customer].t_screen_name+'" target="_blank">'+data.results[customer].t_screen_name+'</a></td> <td>'+data.results[customer].t_description+'</td><td>'+data.results[customer].t_followers_count+'</td><td>'+data.results[customer].t_status_created_at_daydiff+'</td></tr>'
  230. }
  231. $('#d1').html(cat_option)
  232. },
  233. error:function(errorData){
  234. console.log('error')
  235. console.log(errorData)
  236. }
  237. });
  238.  
  239. }
  240. });
  241.  
  242. return false;
  243. });
  244.  
  245. </script>
  246.  
  247.  
  248.  
  249.  
  250. <!-- treemap -->
  251.  
  252. <script src="https://code.highcharts.com/highcharts.js"></script>
  253. <script src="https://code.highcharts.com/modules/treemap.js"></script>
  254. <div id="container"></div>
  255.  
  256. <style>
  257. #treedata {
  258. min-length: 100%;
  259. min-width: 100%;
  260. max-width: 100%;
  261. margin: 0 auto;
  262.  
  263. }
  264. </style>
  265.  
  266. <script>
  267.  
  268. Highcharts.chart('treedata', {
  269. series: [{
  270. type: "treemap",
  271. layoutAlgorithm: 'stripes',
  272. alternateStartingDirection: true,
  273. levels: [{
  274. level: 1,
  275. layoutAlgorithm: 'sliceAndDice',
  276. dataLabels: {
  277. enabled: true,
  278. align: 'center',
  279. verticalAlign: 'center',
  280. style: {
  281. fontSize: '18px',
  282. fontWeight: 'lighter'
  283.  
  284. }
  285. }
  286. }],
  287. data: {{ data | safe}}
  288. }],
  289. title: {
  290. text: ' '
  291. }
  292. });
  293. </script>
  294.  
  295.  
  296. {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement