Punishments.vue 3.9 KB

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