Punishments.vue 4.0 KB

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