Punishments.vue 4.2 KB

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