home.blade.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. @extends('admin.partial.template-full')
  2. @section('section')
  3. <div class="title d-flex justify-content-between align-items-center">
  4. <h3 class="font-weight-bold">Users</h3>
  5. <form method="get">
  6. <input type="hidden" name="a" value="search">
  7. <div class="input-group">
  8. <input class="form-control" name="q" placeholder="Search usernames" value="{{request()->input('q')}}">
  9. <div class="input-group-append">
  10. <button type="submit" class="btn btn-primary">
  11. <i class="fas fa-search"></i>
  12. </button>
  13. </div>
  14. </div>
  15. </form>
  16. </div>
  17. <hr>
  18. <div v-if="selectedAll">
  19. <button class="btn btn-danger font-weight-bold mb-3" id="selectedAllInput" @@click="deleteSelected">Delete selected accounts</button>
  20. </div>
  21. <div class="table-responsive">
  22. <table class="table">
  23. <thead class="bg-light">
  24. <tr class="text-center">
  25. <th scope="col" class="border-0" width="1%">
  26. <div class="custom-control custom-checkbox account-select-check">
  27. <input type="checkbox" class="custom-control-input" id="allCheck" v-model="selectedAll">
  28. <label class="custom-control-label" for="allCheck"></label>
  29. </div>
  30. </th>
  31. <th scope="col" class="border-0" width="5%">
  32. <span>ID</span>
  33. </th>
  34. <th scope="col" class="border-0" width="40%">
  35. <span>Username</span>
  36. </th>
  37. <th scope="col" class="border-0" width="5%">
  38. <span>Statuses</span>
  39. </th>
  40. <th scope="col" class="border-0" width="5%">
  41. <span>Followers</span>
  42. </th>
  43. <th scope="col" class="border-0" width="5%">
  44. <span>Following</span>
  45. </th>
  46. <th scope="col" class="border-0" width="30%">
  47. <span>Actions</span>
  48. </th>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. @foreach($users as $key => $user)
  53. @if($user->status == 'deleted')
  54. <tr class="font-weight-bold text-center user-row">
  55. <th scope="row">
  56. <div class="custom-control custom-checkbox account-select-check">
  57. <input type="checkbox" class="custom-control-input" disabled>
  58. <label class="custom-control-label"></label>
  59. </div>
  60. </th>
  61. <td>
  62. <span class="text-danger" class="text-monospace">{{$user->id}}</span>
  63. </td>
  64. <td class="text-left">
  65. <img src="/storage/avatars/default.jpg" width="20" height="20" class="rounded-circle mr-1" />
  66. <span title="{{$user->username}}" data-toggle="tooltip" data-placement="bottom">
  67. <span class="text-danger">{{$user->username}}</span>
  68. </span>
  69. </td>
  70. <td>0</td>
  71. <td>0</td>
  72. <td>0</td>
  73. <td>
  74. <span class="font-weight-bold small">
  75. <span class="text-danger">Account Deleted</span>
  76. </span>
  77. </td>
  78. </tr>
  79. @else
  80. <tr class="font-weight-bold text-center user-row">
  81. <th scope="row">
  82. <div class="custom-control custom-checkbox account-select-check">
  83. <input type="checkbox" id="{{$key}}" class="custom-control-input action-check" data-id="{{$user->id}}" data-username="{{$user->username}}">
  84. <label class="custom-control-label" for="{{$key}}"></label>
  85. </div>
  86. </th>
  87. <td>
  88. <span class="text-monospace">{{$user->id}}</span>
  89. </td>
  90. <td class="d-flex align-items-center">
  91. @if($user->account)
  92. <img src="{{$user->account['avatar']}}" width="20" height="20" class="rounded-circle mr-2" onerror="this.src='/storage/avatars/default.jpg';this.onerror=null;" />
  93. @endif
  94. <span title="{{$user->username}}" data-toggle="tooltip" data-placement="bottom">
  95. <span>{{$user->username}}</span>
  96. @if($user->is_admin)
  97. <i class="text-danger fas fa-certificate" title="Admin"></i>
  98. @endif
  99. </span>
  100. </td>
  101. <td>
  102. @if($user->account)
  103. {{$user->account['statuses_count']}}
  104. @else
  105. 0
  106. @endif
  107. </td>
  108. <td>
  109. @if($user->account)
  110. {{$user->account['followers_count']}}
  111. @else
  112. 0
  113. @endif
  114. </td>
  115. <td>
  116. @if($user->account)
  117. {{$user->account['following_count']}}
  118. @else
  119. 0
  120. @endif
  121. </td>
  122. <td>
  123. <span class="action-row font-weight-lighter">
  124. <a href="/{{$user->username}}" class="pr-2 text-muted small font-weight-bold" title="View Profile" data-toggle="tooltip" data-placement="bottom">
  125. Profile
  126. </a>
  127. <a href="/i/admin/users/show/{{$user->id}}" class="pr-2 text-muted small font-weight-bold" title="Profile Review" data-toggle="tooltip" data-placement="bottom">
  128. Review
  129. </a>
  130. <a href="/i/admin/users/modtools/{{$user->id}}" class="pr-2 text-muted small font-weight-bold" title="Moderation Logs" data-toggle="tooltip" data-placement="bottom">
  131. Mod Tools
  132. </a>
  133. @if($user->status !== 'deleted' && !$user->is_admin)
  134. <a href="/i/admin/users/delete/{{$user->id}}" class="pr-2 text-muted small font-weight-bold" title="Delete account" data-toggle="tooltip" data-placement="bottom" onclick="deleteAccount({{$user->id}})">
  135. Delete
  136. </a>
  137. @endif
  138. </span>
  139. </td>
  140. </tr>
  141. @endif
  142. @endforeach
  143. </tbody>
  144. </table>
  145. </div>
  146. <div class="d-flex justify-content-center mt-5 small">
  147. <ul class="pagination">
  148. @if($pagination['prev'] !== null || $pagination['prev'] == 1)
  149. <li class="page-item"><a class="page-link pagination__prev" href="?page={{$pagination['prev']}}{{$pagination['query']}}" rel="prev">« Previous</a></li>
  150. @else
  151. <li class="page-item disabled"><span class="page-link" >« Previous</span></li>
  152. @endif
  153. <li class="page-item"><a class="page-link pagination__next" href="?page={{$pagination['next']}}{{$pagination['query']}}" rel="next">Next »</a></li>
  154. </ul>
  155. </div>
  156. @endsection
  157. @push('styles')
  158. <style type="text/css">
  159. .user-row:hover {
  160. background-color: #eff8ff;
  161. }
  162. .user-row:hover .action-row {
  163. display: block;
  164. }
  165. .user-row:hover .last-active {
  166. display: none;
  167. }
  168. </style>
  169. @endpush
  170. @push('scripts')
  171. <script type="text/javascript">
  172. $(document).ready(function() {
  173. $('.human-size').each(function(d,a) {
  174. let el = $(a);
  175. let size = el.data('bytes');
  176. el.text(filesize(size, {round: 0}));
  177. });
  178. });
  179. function deleteAccount(id) {
  180. event.preventDefault();
  181. if(!window.confirm('Are you sure you want to delete this account?')) {
  182. return;
  183. }
  184. axios.post('/i/admin/users/delete/' + id)
  185. .then(res => {
  186. swal('Account Deleted', 'Successfully deleted this account! This page will refresh once you press OK.', 'success')
  187. .then(res => {
  188. window.location.reload();
  189. });
  190. })
  191. }
  192. let app = new Vue({
  193. el: '#panel',
  194. data() {
  195. return {
  196. selectedAll: false
  197. }
  198. },
  199. watch: {
  200. selectedAll(val) {
  201. if(val) {
  202. if(document.querySelectorAll('.action-check').length == 0) {
  203. this.selectedAll = false;
  204. return;
  205. }
  206. document.querySelectorAll('.action-check').forEach(v => v.checked = true)
  207. } else {
  208. document.querySelectorAll('.action-check').forEach(v => v.checked = false)
  209. }
  210. }
  211. },
  212. methods: {
  213. async deleteSelected() {
  214. let usernames = [...document.querySelectorAll('.action-check:checked')].map(el => el.dataset.username);
  215. let ids = [...document.querySelectorAll('.action-check:checked')].map(el => el.dataset.id);
  216. swal({
  217. title: 'Confirm mass deletion',
  218. text: "Are you sure you want to delete the following accounts: \n\n" + usernames.join(" \n"),
  219. icon: 'warning',
  220. dangerMode: true,
  221. buttons: {
  222. cancel: {
  223. text: "Cancel",
  224. value: false,
  225. closeModal: true,
  226. visible: true,
  227. },
  228. delete: {
  229. text: "Delete",
  230. value: "delete",
  231. className: "btn-danger"
  232. }
  233. }
  234. })
  235. .then(async (res) => {
  236. if(res !== 'delete') {
  237. swal('Mass delete cancelled', '', 'success');
  238. } else {
  239. swal({
  240. title: 'Processing mass deletes',
  241. text: 'Do not close or navigate away from this page while we process this request',
  242. icon: 'warning',
  243. timer: 4000
  244. })
  245. await axios.all(ids.map((acct) => this.deleteAccountById(acct)))
  246. .finally(() => {
  247. swal({
  248. title: 'Accounts successfully deleted!',
  249. text: 'This page will refresh shortly!',
  250. icon: 'success',
  251. timer: 1000
  252. })
  253. setTimeout(() => {
  254. window.location.reload();
  255. }, 10000)
  256. })
  257. }
  258. })
  259. },
  260. async deleteAccountById(id) {
  261. await axios.post('/i/admin/users/delete/' + id)
  262. }
  263. }
  264. });
  265. </script>
  266. @endpush