Punishments.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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" @click="banIP()" href="#"
  83. >Ban IP</a
  84. >
  85. </footer>
  86. </div>
  87. </div>
  88. <view-punishment
  89. v-if="modals.viewPunishment"
  90. :punishment-id="viewingPunishmentId"
  91. sector="admin"
  92. />
  93. </div>
  94. </template>
  95. <script>
  96. import { mapState, mapActions } from "vuex";
  97. import Toast from "toasters";
  98. import ViewPunishment from "../ViewPunishment.vue";
  99. import io from "../../../io";
  100. export default {
  101. components: { ViewPunishment },
  102. data() {
  103. return {
  104. viewingPunishmentId: "",
  105. punishments: [],
  106. ipBan: {
  107. expiresAt: "1h"
  108. }
  109. };
  110. },
  111. computed: {
  112. sortedPunishments() {
  113. // return _.orderBy(this.punishments, -1);
  114. return this.punishments;
  115. },
  116. ...mapState("modals", {
  117. modals: state => state.modals.admin
  118. })
  119. },
  120. mounted() {
  121. io.getSocket(socket => {
  122. this.socket = socket;
  123. if (this.socket.connected) this.init();
  124. io.onConnect(() => this.init());
  125. socket.on("event:admin.punishment.added", punishment => {
  126. this.punishments.push(punishment);
  127. });
  128. });
  129. },
  130. methods: {
  131. view(punishment) {
  132. // this.viewPunishment(punishment);
  133. this.viewingPunishmentId = punishment._id;
  134. this.openModal({ sector: "admin", modal: "viewPunishment" });
  135. },
  136. banIP() {
  137. this.socket.emit(
  138. "punishments.banIP",
  139. this.ipBan.ip,
  140. this.ipBan.reason,
  141. this.ipBan.expiresAt,
  142. res => {
  143. new Toast({ content: res.message, timeout: 6000 });
  144. }
  145. );
  146. },
  147. init() {
  148. this.socket.emit("punishments.index", res => {
  149. if (res.status === "success") this.punishments = res.data;
  150. });
  151. this.socket.emit("apis.joinAdminRoom", "punishments", () => {});
  152. },
  153. ...mapActions("modals", ["openModal"]),
  154. ...mapActions("admin/punishments", ["viewPunishment"])
  155. }
  156. };
  157. </script>
  158. <style lang="scss" scoped>
  159. @import "../../../styles/global.scss";
  160. .night-mode {
  161. .table {
  162. color: $night-mode-text;
  163. background-color: $night-mode-bg-secondary;
  164. thead tr {
  165. background: $night-mode-bg-secondary;
  166. td {
  167. color: #fff;
  168. }
  169. }
  170. tbody tr:hover {
  171. background-color: #111 !important;
  172. }
  173. tbody tr:nth-child(even) {
  174. background-color: #444;
  175. }
  176. strong {
  177. color: $night-mode-text;
  178. }
  179. }
  180. .card {
  181. background: $night-mode-bg-secondary;
  182. .card-header {
  183. box-shadow: 0 1px 2px rgba(10, 10, 10, 0.8);
  184. }
  185. p,
  186. .label {
  187. color: $night-mode-text;
  188. }
  189. }
  190. }
  191. body {
  192. font-family: "Hind", sans-serif;
  193. }
  194. td {
  195. vertical-align: middle;
  196. }
  197. select {
  198. margin-bottom: 10px;
  199. }
  200. </style>