Punishments.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div>
  3. <page-metadata title="Admin | Punishments" />
  4. <div class="container">
  5. <advanced-table
  6. :column-default="columnDefault"
  7. :columns="columns"
  8. :filters="filters"
  9. data-action="punishments.getData"
  10. name="admin-punishments"
  11. max-width="1200"
  12. >
  13. <template #column-options="slotProps">
  14. <div class="row-options">
  15. <button
  16. class="
  17. button
  18. is-primary
  19. icon-with-button
  20. material-icons
  21. "
  22. @click="view(slotProps.item._id)"
  23. :disabled="slotProps.item.removed"
  24. content="View Punishment"
  25. v-tippy
  26. >
  27. open_in_full
  28. </button>
  29. </div>
  30. </template>
  31. <template #column-status="slotProps">
  32. <span>{{ slotProps.item.status }}</span>
  33. </template>
  34. <template #column-type="slotProps">
  35. <span
  36. :title="
  37. slotProps.item.type === 'banUserId'
  38. ? 'User ID'
  39. : 'IP Address'
  40. "
  41. >{{
  42. slotProps.item.type === "banUserId"
  43. ? "User ID"
  44. : "IP Address"
  45. }}</span
  46. >
  47. </template>
  48. <template #column-value="slotProps">
  49. <user-id-to-username
  50. v-if="slotProps.item.type === 'banUserId'"
  51. :user-id="slotProps.item.value"
  52. :alt="slotProps.item.value"
  53. :link="true"
  54. />
  55. <span v-else :title="slotProps.item.value">{{
  56. slotProps.item.value
  57. }}</span>
  58. </template>
  59. <template #column-reason="slotProps">
  60. <span :title="slotProps.item.reason">{{
  61. slotProps.item.reason
  62. }}</span>
  63. </template>
  64. <template #column-punishedBy="slotProps">
  65. <user-id-to-username
  66. :user-id="slotProps.item.punishedBy"
  67. :link="true"
  68. />
  69. </template>
  70. <template #column-punishedAt="slotProps">
  71. <span :title="new Date(slotProps.item.punishedAt)">{{
  72. getDateFormatted(slotProps.item.punishedAt)
  73. }}</span>
  74. </template>
  75. <template #column-expiresAt="slotProps">
  76. <span :title="new Date(slotProps.item.expiresAt)">{{
  77. getDateFormatted(slotProps.item.expiresAt)
  78. }}</span>
  79. </template>
  80. </advanced-table>
  81. <div class="card">
  82. <header class="card-header">
  83. <p>Ban an IP</p>
  84. </header>
  85. <div class="card-content">
  86. <label class="label">Expires In</label>
  87. <select v-model="ipBan.expiresAt">
  88. <option value="1h">1 Hour</option>
  89. <option value="12h">12 Hours</option>
  90. <option value="1d">1 Day</option>
  91. <option value="1w">1 Week</option>
  92. <option value="1m">1 Month</option>
  93. <option value="3m">3 Months</option>
  94. <option value="6m">6 Months</option>
  95. <option value="1y">1 Year</option>
  96. </select>
  97. <label class="label">IP</label>
  98. <p class="control is-expanded">
  99. <input
  100. v-model="ipBan.ip"
  101. class="input"
  102. type="text"
  103. placeholder="IP address (xxx.xxx.xxx.xxx)"
  104. />
  105. </p>
  106. <label class="label">Reason</label>
  107. <p class="control is-expanded">
  108. <input
  109. v-model="ipBan.reason"
  110. class="input"
  111. type="text"
  112. placeholder="Reason"
  113. />
  114. </p>
  115. <button class="button is-primary" @click="banIP()">
  116. Ban IP
  117. </button>
  118. </div>
  119. </div>
  120. </div>
  121. <view-punishment
  122. v-if="modals.viewPunishment"
  123. :punishment-id="viewingPunishmentId"
  124. sector="admin"
  125. />
  126. </div>
  127. </template>
  128. <script>
  129. import { mapState, mapGetters, mapActions } from "vuex";
  130. import Toast from "toasters";
  131. import { defineAsyncComponent } from "vue";
  132. import AdvancedTable from "@/components/AdvancedTable.vue";
  133. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  134. export default {
  135. components: {
  136. ViewPunishment: defineAsyncComponent(() =>
  137. import("@/components/modals/ViewPunishment.vue")
  138. ),
  139. AdvancedTable,
  140. UserIdToUsername
  141. },
  142. data() {
  143. return {
  144. viewingPunishmentId: "",
  145. ipBan: {
  146. expiresAt: "1h"
  147. },
  148. columnDefault: {
  149. sortable: true,
  150. hidable: true,
  151. defaultVisibility: "shown",
  152. draggable: true,
  153. resizable: true,
  154. minWidth: 150,
  155. maxWidth: 600
  156. },
  157. columns: [
  158. {
  159. name: "options",
  160. displayName: "Options",
  161. properties: ["_id"],
  162. sortable: false,
  163. hidable: false,
  164. resizable: false,
  165. minWidth: 76,
  166. defaultWidth: 76
  167. },
  168. {
  169. name: "status",
  170. displayName: "Status",
  171. properties: ["status"],
  172. sortable: false,
  173. defaultWidth: 150
  174. },
  175. {
  176. name: "type",
  177. displayName: "Type",
  178. properties: ["type"],
  179. sortProperty: "type"
  180. },
  181. {
  182. name: "value",
  183. displayName: "Value",
  184. properties: ["value"],
  185. sortProperty: "value",
  186. defaultWidth: 150
  187. },
  188. {
  189. name: "reason",
  190. displayName: "Reason",
  191. properties: ["reason"],
  192. sortProperty: "reason"
  193. },
  194. {
  195. name: "punishedBy",
  196. displayName: "Punished By",
  197. properties: ["punishedBy"],
  198. sortProperty: "punishedBy",
  199. defaultWidth: 200,
  200. defaultVisibility: "hidden"
  201. },
  202. {
  203. name: "punishedAt",
  204. displayName: "Punished At",
  205. properties: ["punishedAt"],
  206. sortProperty: "punishedAt",
  207. defaultWidth: 200,
  208. defaultVisibility: "hidden"
  209. },
  210. {
  211. name: "expiresAt",
  212. displayName: "Expires At",
  213. properties: ["expiresAt"],
  214. sortProperty: "verifiedAt",
  215. defaultWidth: 200,
  216. defaultVisibility: "hidden"
  217. }
  218. ],
  219. filters: [
  220. {
  221. name: "status",
  222. displayName: "Status",
  223. property: "status",
  224. filterTypes: ["exact"],
  225. defaultFilterType: "exact",
  226. dropdown: [
  227. ["Active", "Active"],
  228. ["Inactive", "Inactive"]
  229. ]
  230. },
  231. {
  232. name: "type",
  233. displayName: "Type",
  234. property: "type",
  235. filterTypes: ["exact"],
  236. defaultFilterType: "exact",
  237. dropdown: [
  238. ["banUserId", "User ID"],
  239. ["banUserIp", "IP Address"]
  240. ]
  241. },
  242. {
  243. name: "value",
  244. displayName: "Value",
  245. property: "value",
  246. filterTypes: ["contains", "exact", "regex"],
  247. defaultFilterType: "contains"
  248. },
  249. {
  250. name: "reason",
  251. displayName: "Reason",
  252. property: "reason",
  253. filterTypes: ["contains", "exact", "regex"],
  254. defaultFilterType: "contains"
  255. },
  256. {
  257. name: "punishedBy",
  258. displayName: "Punished By",
  259. property: "punishedBy",
  260. filterTypes: ["contains", "exact", "regex"],
  261. defaultFilterType: "contains"
  262. },
  263. {
  264. name: "punishedAt",
  265. displayName: "Punished At",
  266. property: "punishedAt",
  267. filterTypes: ["datetimeBefore", "datetimeAfter"],
  268. defaultFilterType: "datetimeBefore"
  269. },
  270. {
  271. name: "expiresAt",
  272. displayName: "Expires At",
  273. property: "expiresAt",
  274. filterTypes: ["datetimeBefore", "datetimeAfter"],
  275. defaultFilterType: "datetimeBefore"
  276. }
  277. ]
  278. };
  279. },
  280. computed: {
  281. ...mapState("modalVisibility", {
  282. modals: state => state.modals
  283. }),
  284. ...mapGetters({
  285. socket: "websockets/getSocket"
  286. })
  287. },
  288. methods: {
  289. view(punishmentId) {
  290. this.viewingPunishmentId = punishmentId;
  291. this.openModal("viewPunishment");
  292. },
  293. banIP() {
  294. this.socket.dispatch(
  295. "punishments.banIP",
  296. this.ipBan.ip,
  297. this.ipBan.reason,
  298. this.ipBan.expiresAt,
  299. res => {
  300. new Toast(res.message);
  301. }
  302. );
  303. },
  304. getDateFormatted(createdAt) {
  305. const date = new Date(createdAt);
  306. const year = date.getFullYear();
  307. const month = `${date.getMonth() + 1}`.padStart(2, 0);
  308. const day = `${date.getDate()}`.padStart(2, 0);
  309. const hour = `${date.getHours()}`.padStart(2, 0);
  310. const minute = `${date.getMinutes()}`.padStart(2, 0);
  311. return `${year}-${month}-${day} ${hour}:${minute}`;
  312. },
  313. ...mapActions("modalVisibility", ["openModal"]),
  314. ...mapActions("admin/punishments", ["viewPunishment"])
  315. }
  316. };
  317. </script>
  318. <style lang="scss" scoped>
  319. .night-mode {
  320. .card {
  321. background: var(--dark-grey-3);
  322. p,
  323. .label {
  324. color: var(--light-grey-2);
  325. }
  326. }
  327. }
  328. .card {
  329. display: flex;
  330. flex-grow: 1;
  331. flex-direction: column;
  332. padding: 20px;
  333. margin: 10px 0;
  334. border-radius: 5px;
  335. background-color: var(--white);
  336. color: var(--dark-grey);
  337. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  338. .card-header {
  339. font-weight: 700;
  340. padding-bottom: 10px;
  341. }
  342. .button.is-primary {
  343. width: 100%;
  344. }
  345. select {
  346. margin-bottom: 10px;
  347. }
  348. }
  349. </style>