Punishments.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div class='container'>
  3. <table class='table is-striped'>
  4. <thead>
  5. <tr>
  6. <td>Type</td>
  7. <td>Value</td>
  8. <td>Reason</td>
  9. <td>Active</td>
  10. </tr>
  11. </thead>
  12. <tbody>
  13. <tr v-for='(index, punishment) in punishments' track-by='$index'>
  14. <td>{{ punishment.type }}</td>
  15. <td>{{ punishment.value }}</td>
  16. <td>{{ punishment.reason }}</td>
  17. <td>{{ (punishment.active && new Date(punishment.expiresAt).getTime() > Date.now()) ? 'Active' : 'Inactive' }}</td>
  18. <td>
  19. <button class='button is-primary' @click='view(punishment)'>View</button>
  20. </td>
  21. </tr>
  22. </tbody>
  23. </table>
  24. <div class='card is-fullwidth'>
  25. <header class='card-header'>
  26. <p class='card-header-title'>Ban an IP</p>
  27. </header>
  28. <div class='card-content'>
  29. <div class='content'>
  30. <label class='label'>IP</label>
  31. <p class='control is-expanded'>
  32. <input class='input' type='text' placeholder='IP address (xxx.xxx.xxx.xxx)' v-model='ipBan.ip'>
  33. </p>
  34. <label class='label'>Reason</label>
  35. <p class='control is-expanded'>
  36. <input class='input' type='text' placeholder='Reason' v-model='ipBan.reason'>
  37. </p>
  38. </div>
  39. </div>
  40. <footer class='card-footer'>
  41. <a class='card-footer-item' @click='banIP()' href='#'>Ban IP</a>
  42. </footer>
  43. </div>
  44. </div>
  45. <view-punishment v-show='modals.viewPunishment'></view-punishment>
  46. </template>
  47. <script>
  48. import ViewPunishment from '../Modals/ViewPunishment.vue';
  49. import { Toast } from 'vue-roaster';
  50. import io from '../../io';
  51. export default {
  52. components: { ViewPunishment },
  53. data() {
  54. return {
  55. punishments: [],
  56. modals: { viewPunishment: false },
  57. ipBan: {}
  58. }
  59. },
  60. methods: {
  61. toggleModal: function () {
  62. this.modals.viewPunishment = !this.modals.viewPunishment;
  63. },
  64. view: function (punishment) {
  65. this.$broadcast('viewPunishment', punishment);
  66. },
  67. banIP: function() {
  68. let _this = this;
  69. _this.socket.emit('punishments.banIP', res => {
  70. Toast.methods.addToast(res.message, 6000);
  71. });
  72. },
  73. init: function () {
  74. let _this = this;
  75. _this.socket.emit('punishments.index', result => {
  76. if (result.status === 'success') _this.punishments = result.data;
  77. });
  78. //_this.socket.emit('apis.joinAdminRoom', 'punishments', () => {});
  79. }
  80. },
  81. ready: function () {
  82. let _this = this;
  83. io.getSocket(socket => {
  84. _this.socket = socket;
  85. if (_this.socket.connected) _this.init();
  86. io.onConnect(() => _this.init());
  87. });
  88. }
  89. }
  90. </script>
  91. <style lang='scss' scoped>
  92. body { font-family: 'Roboto', sans-serif; }
  93. </style>