Punishments.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div>
  3. <metadata title="Admin | Punishments" />
  4. <div class="container">
  5. <table class="table is-striped">
  6. <thead>
  7. <tr>
  8. <td>Type</td>
  9. <td>Value</td>
  10. <td>Reason</td>
  11. <td>Status</td>
  12. <td>Options</td>
  13. </tr>
  14. </thead>
  15. <tbody>
  16. <tr
  17. v-for="(punishment, index) in sortedPunishments"
  18. :key="index"
  19. >
  20. <td v-if="punishment.type === 'banUserId'">
  21. User ID
  22. </td>
  23. <td v-else>
  24. IP Address
  25. </td>
  26. <td>{{ punishment.value }}</td>
  27. <td>{{ punishment.reason }}</td>
  28. <td>
  29. {{
  30. punishment.active &&
  31. new Date(punishment.expiresAt).getTime() >
  32. Date.now()
  33. ? "Active"
  34. : "Inactive"
  35. }}
  36. </td>
  37. <td>
  38. <button
  39. class="button is-primary"
  40. @click="view(punishment)"
  41. >
  42. View
  43. </button>
  44. </td>
  45. </tr>
  46. </tbody>
  47. </table>
  48. <div class="card is-fullwidth">
  49. <header class="card-header">
  50. <p class="card-header-title">
  51. Ban an IP
  52. </p>
  53. </header>
  54. <div class="card-content">
  55. <div class="content">
  56. <label class="label">Expires In</label>
  57. <select v-model="ipBan.expiresAt">
  58. <option value="1h">
  59. 1 Hour
  60. </option>
  61. <option value="12h">
  62. 12 Hours
  63. </option>
  64. <option value="1d">
  65. 1 Day
  66. </option>
  67. <option value="1w">
  68. 1 Week
  69. </option>
  70. <option value="1m">
  71. 1 Month
  72. </option>
  73. <option value="3m">
  74. 3 Months
  75. </option>
  76. <option value="6m">
  77. 6 Months
  78. </option>
  79. <option value="1y">
  80. 1 Year
  81. </option>
  82. </select>
  83. <label class="label">IP</label>
  84. <p class="control is-expanded">
  85. <input
  86. v-model="ipBan.ip"
  87. class="input"
  88. type="text"
  89. placeholder="IP address (xxx.xxx.xxx.xxx)"
  90. />
  91. </p>
  92. <label class="label">Reason</label>
  93. <p class="control is-expanded">
  94. <input
  95. v-model="ipBan.reason"
  96. class="input"
  97. type="text"
  98. placeholder="Reason"
  99. />
  100. </p>
  101. </div>
  102. </div>
  103. <footer class="card-footer">
  104. <a class="card-footer-item" v-on:click="banIP()" href="#"
  105. >Ban IP</a
  106. >
  107. </footer>
  108. </div>
  109. </div>
  110. <view-punishment v-if="modals.viewPunishment" />
  111. </div>
  112. </template>
  113. <script>
  114. import { mapState, mapActions } from "vuex";
  115. import Toast from "toasters";
  116. import ViewPunishment from "../Modals/ViewPunishment.vue";
  117. import io from "../../io";
  118. export default {
  119. components: { ViewPunishment },
  120. data() {
  121. return {
  122. punishments: [],
  123. ipBan: {
  124. expiresAt: "1h"
  125. }
  126. };
  127. },
  128. computed: {
  129. sortedPunishments() {
  130. // return _.orderBy(this.punishments, -1);
  131. return this.punishments;
  132. },
  133. ...mapState("modals", {
  134. modals: state => state.modals.admin
  135. })
  136. },
  137. methods: {
  138. view(punishment) {
  139. this.viewPunishment(punishment);
  140. this.openModal({ sector: "admin", modal: "viewPunishment" });
  141. },
  142. banIP() {
  143. this.socket.emit(
  144. "punishments.banIP",
  145. this.ipBan.ip,
  146. this.ipBan.reason,
  147. this.ipBan.expiresAt,
  148. res => {
  149. new Toast({ content: res.message, timeout: 6000 });
  150. }
  151. );
  152. },
  153. init() {
  154. this.socket.emit("punishments.index", res => {
  155. if (res.status === "success") this.punishments = res.data;
  156. });
  157. this.socket.emit("apis.joinAdminRoom", "punishments", () => {});
  158. },
  159. ...mapActions("modals", ["openModal"]),
  160. ...mapActions("admin/punishments", ["viewPunishment"])
  161. },
  162. mounted() {
  163. io.getSocket(socket => {
  164. this.socket = socket;
  165. if (this.socket.connected) this.init();
  166. io.onConnect(() => this.init());
  167. socket.on("event:admin.punishment.added", punishment => {
  168. this.punishments.push(punishment);
  169. });
  170. });
  171. }
  172. };
  173. </script>
  174. <style lang="scss" scoped>
  175. @import "styles/global.scss";
  176. body {
  177. font-family: "Roboto", sans-serif;
  178. }
  179. td {
  180. vertical-align: middle;
  181. }
  182. select {
  183. margin-bottom: 10px;
  184. }
  185. </style>