Punishments.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div>
  3. <page-metadata title="Admin | Punishments" />
  4. <div class="container">
  5. <table class="table is-striped">
  6. <thead>
  7. <tr>
  8. <td>Status</td>
  9. <td>Type</td>
  10. <td>Value</td>
  11. <td>Reason</td>
  12. <td>Options</td>
  13. </tr>
  14. </thead>
  15. <tbody>
  16. <tr
  17. v-for="punishment in sortedPunishments"
  18. :key="punishment._id"
  19. >
  20. <td>
  21. {{
  22. punishment.active &&
  23. new Date(punishment.expiresAt).getTime() >
  24. Date.now()
  25. ? "Active"
  26. : "Inactive"
  27. }}
  28. </td>
  29. <td v-if="punishment.type === 'banUserId'">User ID</td>
  30. <td v-else>IP Address</td>
  31. <td v-if="punishment.type === 'banUserId'">
  32. <user-id-to-username
  33. :user-id="punishment.value"
  34. :alt="punishment.value"
  35. :link="true"
  36. />
  37. ({{ punishment.value }})
  38. </td>
  39. <td v-else>
  40. {{ punishment.value }}
  41. </td>
  42. <td>{{ punishment.reason }}</td>
  43. <td>
  44. <a
  45. class="button is-primary"
  46. @click="view(punishment)"
  47. content="Expand"
  48. v-tippy
  49. >
  50. <i class="material-icons icon-with-button">
  51. open_in_full
  52. </i>
  53. Expand
  54. </a>
  55. </td>
  56. </tr>
  57. </tbody>
  58. </table>
  59. <div class="card">
  60. <header class="card-header">
  61. <p>Ban an IP</p>
  62. </header>
  63. <div class="card-content">
  64. <label class="label">Expires In</label>
  65. <select v-model="ipBan.expiresAt">
  66. <option value="1h">1 Hour</option>
  67. <option value="12h">12 Hours</option>
  68. <option value="1d">1 Day</option>
  69. <option value="1w">1 Week</option>
  70. <option value="1m">1 Month</option>
  71. <option value="3m">3 Months</option>
  72. <option value="6m">6 Months</option>
  73. <option value="1y">1 Year</option>
  74. </select>
  75. <label class="label">IP</label>
  76. <p class="control is-expanded">
  77. <input
  78. v-model="ipBan.ip"
  79. class="input"
  80. type="text"
  81. placeholder="IP address (xxx.xxx.xxx.xxx)"
  82. />
  83. </p>
  84. <label class="label">Reason</label>
  85. <p class="control is-expanded">
  86. <input
  87. v-model="ipBan.reason"
  88. class="input"
  89. type="text"
  90. placeholder="Reason"
  91. />
  92. </p>
  93. <button class="button is-primary" @click="banIP()">
  94. Ban IP
  95. </button>
  96. </div>
  97. </div>
  98. </div>
  99. <view-punishment
  100. v-if="modals.viewPunishment"
  101. :punishment-id="viewingPunishmentId"
  102. sector="admin"
  103. />
  104. </div>
  105. </template>
  106. <script>
  107. import { mapState, mapGetters, mapActions } from "vuex";
  108. import Toast from "toasters";
  109. import { defineAsyncComponent } from "vue";
  110. import ws from "@/ws";
  111. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  112. export default {
  113. components: {
  114. ViewPunishment: defineAsyncComponent(() =>
  115. import("@/components/modals/ViewPunishment.vue")
  116. ),
  117. UserIdToUsername
  118. },
  119. data() {
  120. return {
  121. viewingPunishmentId: "",
  122. punishments: [],
  123. ipBan: {
  124. expiresAt: "1h"
  125. }
  126. };
  127. },
  128. computed: {
  129. sortedPunishments() {
  130. return this.punishments;
  131. },
  132. ...mapState("modalVisibility", {
  133. modals: state => state.modals
  134. }),
  135. ...mapGetters({
  136. socket: "websockets/getSocket"
  137. })
  138. },
  139. mounted() {
  140. ws.onConnect(this.init);
  141. this.socket.on("event:admin.punishment.created", res =>
  142. this.punishments.push(res.data.punishment)
  143. );
  144. },
  145. methods: {
  146. view(punishment) {
  147. this.viewingPunishmentId = punishment._id;
  148. this.openModal("viewPunishment");
  149. },
  150. banIP() {
  151. this.socket.dispatch(
  152. "punishments.banIP",
  153. this.ipBan.ip,
  154. this.ipBan.reason,
  155. this.ipBan.expiresAt,
  156. res => {
  157. new Toast(res.message);
  158. }
  159. );
  160. },
  161. init() {
  162. this.socket.dispatch("punishments.index", res => {
  163. if (res.status === "success")
  164. this.punishments = res.data.punishments;
  165. });
  166. this.socket.dispatch("apis.joinAdminRoom", "punishments", () => {});
  167. },
  168. ...mapActions("modalVisibility", ["openModal"]),
  169. ...mapActions("admin/punishments", ["viewPunishment"])
  170. }
  171. };
  172. </script>
  173. <style lang="scss" scoped>
  174. .night-mode {
  175. .table {
  176. color: var(--light-grey-2);
  177. background-color: var(--dark-grey-3);
  178. thead tr {
  179. background: var(--dark-grey-3);
  180. td {
  181. color: var(--white);
  182. }
  183. }
  184. tbody tr:hover {
  185. background-color: var(--dark-grey-4) !important;
  186. }
  187. tbody tr:nth-child(even) {
  188. background-color: var(--dark-grey-2);
  189. }
  190. strong {
  191. color: var(--light-grey-2);
  192. }
  193. }
  194. .card {
  195. background: var(--dark-grey-3);
  196. p,
  197. .label {
  198. color: var(--light-grey-2);
  199. }
  200. }
  201. }
  202. .card {
  203. display: flex;
  204. flex-grow: 1;
  205. flex-direction: column;
  206. padding: 20px;
  207. margin: 10px 0;
  208. border-radius: 5px;
  209. background-color: var(--white);
  210. color: var(--dark-grey);
  211. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  212. .card-header {
  213. font-weight: 700;
  214. padding-bottom: 10px;
  215. }
  216. .button.is-primary {
  217. width: 100%;
  218. }
  219. }
  220. td {
  221. vertical-align: middle;
  222. }
  223. select {
  224. margin-bottom: 10px;
  225. }
  226. </style>