Users.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div>
  3. <div class="container">
  4. <table class="table is-striped">
  5. <thead>
  6. <tr>
  7. <td>Profile Picture</td>
  8. <td>User ID</td>
  9. <td>GitHub ID</td>
  10. <td>Password</td>
  11. <td>Username</td>
  12. <td>Role</td>
  13. <td>Email Address</td>
  14. <td>Email Verified</td>
  15. <td>Likes</td>
  16. <td>Dislikes</td>
  17. <td>Songs Requested</td>
  18. <td>Options</td>
  19. </tr>
  20. </thead>
  21. <tbody>
  22. <tr v-for="(user, index) in users" :key="index">
  23. <td>
  24. <img class="user-avatar" src="/assets/notes-transparent.png" />
  25. </td>
  26. <td>{{ user._id }}</td>
  27. <td v-if="user.services.github">{{ user.services.github.id }}</td>
  28. <td v-else>Not Linked</td>
  29. <td v-if="user.hasPassword">Yes</td>
  30. <td v-else>Not Linked</td>
  31. <td>{{ user.username }}</td>
  32. <td>{{ user.role }}</td>
  33. <td>{{ user.email.address }}</td>
  34. <td>{{ user.email.verified }}</td>
  35. <td>{{ user.liked.length }}</td>
  36. <td>{{ user.disliked.length }}</td>
  37. <td>{{ user.songsRequested }}</td>
  38. <td>
  39. <button class="button is-primary" v-on:click="edit(user)">Edit</button>
  40. </td>
  41. </tr>
  42. </tbody>
  43. </table>
  44. </div>
  45. <edit-user v-if="modals.editUser"></edit-user>
  46. </div>
  47. </template>
  48. <script>
  49. import { mapState, mapActions } from "vuex";
  50. import EditUser from "../Modals/EditUser.vue";
  51. import io from "../../io";
  52. export default {
  53. components: { EditUser },
  54. data() {
  55. return {
  56. users: []
  57. };
  58. },
  59. computed: {
  60. ...mapState("modals", {
  61. modals: state => state.modals.admin
  62. })
  63. },
  64. methods: {
  65. edit: function(user) {
  66. this.editUser(user);
  67. this.toggleModal({ sector: "admin", modal: "editUser" });
  68. },
  69. init: function() {
  70. let _this = this;
  71. _this.socket.emit("users.index", result => {
  72. if (result.status === "success") _this.users = result.data;
  73. });
  74. _this.socket.emit("apis.joinAdminRoom", "users", () => {});
  75. _this.socket.on("event:user.username.changed", username => {
  76. _this.$parent.$parent.username = username;
  77. });
  78. },
  79. ...mapActions("admin/users", ["editUser"]),
  80. ...mapActions("modals", ["toggleModal"])
  81. },
  82. mounted: function() {
  83. let _this = this;
  84. io.getSocket(socket => {
  85. _this.socket = socket;
  86. if (_this.socket.connected) _this.init();
  87. io.onConnect(() => _this.init());
  88. });
  89. }
  90. };
  91. </script>
  92. <style lang='scss' scoped>
  93. body {
  94. font-family: "Roboto", sans-serif;
  95. }
  96. .user-avatar {
  97. display: block;
  98. max-width: 50px;
  99. margin: 0 auto;
  100. }
  101. td {
  102. vertical-align: middle;
  103. }
  104. .is-primary:focus {
  105. background-color: #029ce3 !important;
  106. }
  107. </style>