AdminModeration.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <div class='admin_moderation'>
  3. <tab-view
  4. :transparent='true'
  5. :padding='true'
  6. :tabs='["User reports", "Banned users"]'
  7. v-model='showTab'
  8. >
  9. <div slot='User reports' class='admin_moderation__tab admin_moderation__tab--boom'>
  10. Below are posts reported by users - to remove the thread or block the user, click 'More options&hellip;'<br/>
  11. Note that all actions here are <strong>permanent</strong>
  12. <div class='admin_moderation__reports' v-if='reports.length'>
  13. <div class='admin_moderation__report admin_moderation__report--header'>
  14. <div class='admin_moderation__report__post admin_moderation__report--cell_border admin_moderation__report--cell_border-hidden'>
  15. Post and thread reported
  16. </div>
  17. <div class='admin_moderation__report__reason admin_moderation__report--cell_border admin_moderation__report--cell_border-hidden'>Report reason</div>
  18. <div class='admin_moderation__report__flagged_by admin_moderation__report--cell_border admin_moderation__report--cell_border-hidden'>
  19. Reported by user
  20. </div>
  21. <div class='admin_moderation__report__actions'>
  22. Actions
  23. </div>
  24. </div>
  25. <div class='admin_moderation__report' v-for='(report, $index) in reports'>
  26. <div class='admin_moderation__report__post admin_moderation__report--cell_border'>
  27. <div class='admin_moderation__report__post__header'>
  28. <div class='admin_moderation__report__post__thread'>{{report.Post.Thread.name}}</div>
  29. <div class='admin_moderation__report__post__user'>{{report.Post.User.username}}</div>
  30. </div>
  31. <div class='admin_moderation__report__post__content'>{{report.Post.content | stripTags | truncate(150)}}</div>
  32. </div>
  33. <div class='admin_moderation__report__reason admin_moderation__report--cell_border'>{{report.reason}}</div>
  34. <div class='admin_moderation__report__flagged_by admin_moderation__report--cell_border'>
  35. <avatar-icon class='admin_moderation__report__flagged_by__avatar' :user='report.FlaggedByUser'></avatar-icon>
  36. <div class='admin_moderation__report__flagged_by__text_info'>
  37. <div class='admin_moderation__report__flagged_by__user'>{{report.FlaggedByUser.username}}</div>
  38. <div class='admin_moderation__report__flagged_by__date'>{{report.createdAt| formatDate}}</div>
  39. </div>
  40. </div>
  41. <div class='admin_moderation__report__actions'>
  42. <button class='button button--red' @click='removePost(report, $index)'>Remove post</button>
  43. <menu-button
  44. @delete='deleteReport(report.id, $index)'
  45. :options='reportMenuOptions'
  46. >
  47. <button class='button'>More options&hellip;</button>
  48. </menu-button>
  49. </div>
  50. </div>
  51. </div>
  52. <div class='admin_moderation__no_reports' v-else>
  53. <span class='fa fa-hand-peace-o'></span>
  54. No user reports
  55. </div>
  56. </div>
  57. <div slot='Banned users' class='admin_moderation__tab'>
  58. <div class='admin_moderation__header'>
  59. <div>
  60. Remove or edit banned users below, or add a new ban
  61. </div>
  62. <button class='button button--blue' @click='toggleShowAddNewBanModal'>Add new ban</button>
  63. </div>
  64. <table class='admin_moderation__table'>
  65. <tr>
  66. <th>User</th>
  67. <th>Ban type</th>
  68. <th>Date banned</th>
  69. <th>Message</th>
  70. </tr>
  71. <tr v-for='ban in bans'>
  72. <td>{{ban.user}}</td>
  73. <td>{{ban.type}}</td>
  74. <td>{{ban.date | formatDate}}</td>
  75. <td>
  76. <template v-if='ban.message'>{{ban.message}}</template>
  77. <i v-else>No message given</i>
  78. </td>
  79. </tr>
  80. </table>
  81. <modal-window v-model='showAddNewBanModal' width='30rem'>
  82. <div class='admin_moderation__add_new_ban_modal'>
  83. <h2>Ban or block a user</h2>
  84. <p>Search for the user to ban, then select the relevant ban type for the user</p>
  85. <div>
  86. <fancy-input placeholder='Username to ban' v-model='username' width='15rem' :large='true'></fancy-input>
  87. </div>
  88. <div>
  89. <fancy-input placeholder='Message to user (optional)' v-model='message' width='15rem' :large='true'></fancy-input>
  90. </div>
  91. <div>
  92. <select-button
  93. :options='options'
  94. name='test'
  95. v-model='selectedOption'
  96. >
  97. </select-button>
  98. </div>
  99. <div>
  100. <button class='button button--modal' @click='toggleShowAddNewBanModal'>Cancel</button>
  101. <button class='button button--modal button--green'>Add ban</button>
  102. </div>
  103. </div>
  104. </modal-window>
  105. </div>
  106. </tab-view>
  107. </div>
  108. </template>
  109. <script>
  110. import TabView from '../TabView'
  111. import ModalWindow from '../ModalWindow'
  112. import FancyInput from '../FancyInput'
  113. import SelectButton from '../SelectButton'
  114. import MenuButton from '../MenuButton'
  115. import AvatarIcon from '../AvatarIcon'
  116. import AjaxErrorHandler from '../../assets/js/errorHandler'
  117. export default {
  118. name: 'AdminDashboard',
  119. components: {
  120. TabView,
  121. ModalWindow,
  122. FancyInput,
  123. SelectButton,
  124. MenuButton,
  125. AvatarIcon
  126. },
  127. data () {
  128. return {
  129. showTab: 0,
  130. showAddNewBanModal: false,
  131. username: '',
  132. message: '',
  133. options: [
  134. { name: "Select a ban type", disabled: true },
  135. { name: "Block user's known ip addresses", value: "ip" },
  136. { name: "Ban from creating new threads", value: "thread"},
  137. { name: "Ban from replying to threads", value: "post"}
  138. ],
  139. selectedOption: 0,
  140. reportMenuOptions: [
  141. { value: "Delete report", event: 'delete' },
  142. { value: "Ban or block user" },
  143. { value: "Remove thread" }
  144. ],
  145. user: {
  146. username: 'Username',
  147. color: '#9bd0eb'
  148. },
  149. bans_: [],
  150. reports: []
  151. }
  152. },
  153. computed: {
  154. bans () {
  155. return this.bans_.map(ban => {
  156. let type = ban.type
  157. if(type === 'ip') {
  158. ban.type = 'IP block'
  159. } else if (type === 'thread') {
  160. ban.type = 'New threads'
  161. } else {
  162. ban.type = 'New threads and replies'
  163. }
  164. return ban
  165. })
  166. }
  167. },
  168. methods: {
  169. toggleShowAddNewBanModal () {
  170. this.showAddNewBanModal = !this.showAddNewBanModal
  171. },
  172. deleteReport (id, index) {
  173. this.axios
  174. .delete('/api/v1/report/' + id)
  175. .then(_ => {
  176. this.reports.splice(index, 1)
  177. })
  178. .catch(AjaxErrorHandler())
  179. },
  180. removePost (report, index) {
  181. this.axios
  182. .delete('/api/v1/post/' + report.Post.id)
  183. .then(_ => {
  184. return this.axios.delete('/api/v1/report/' + report.id)
  185. })
  186. .then(_ => {
  187. this.reports.splice(index, 1)
  188. })
  189. .catch(AjaxErrorHandler())
  190. }
  191. },
  192. mounted () {
  193. this.$store.dispatch('setTitle', 'admin | moderation')
  194. this.axios
  195. .get('/api/v1/report')
  196. .then(res => {
  197. this.reports = res.data
  198. })
  199. .catch(AjaxErrorHandler())
  200. }
  201. }
  202. </script>
  203. <style lang='scss' scoped>
  204. @import '../../assets/scss/variables.scss';
  205. .admin_moderation {
  206. padding: 1rem;
  207. padding-top: 0.5rem;
  208. @at-root #{&}__tab {
  209. height: 100%;
  210. }
  211. @at-root #{&}__reports {
  212. margin-top: 1rem;
  213. @extend .shadow_border;
  214. border-radius: 0.25rem;
  215. &> :first-child {
  216. border-radius: 0.25rem 0.25rem 0 0;
  217. }
  218. &> :last-child {
  219. border-radius: 0 0 0.25rem 0.25rem;
  220. }
  221. }
  222. @at-root #{&}__no_reports {
  223. display: flex;
  224. flex-direction: column;
  225. align-items: center;
  226. justify-content: center;
  227. padding-top: 5rem;
  228. font-size: 2rem;
  229. user-select: none;
  230. cursor: default;
  231. transition: none;
  232. color: $color__gray--darkest;
  233. span {
  234. font-size: 4rem;
  235. color: $color__gray--darker;
  236. }
  237. }
  238. @at-root #{&}__report {
  239. display: flex;
  240. background-color: #fff;
  241. border-bottom: thin solid $color__lightgray--primary;
  242. padding: 0.5rem;
  243. @at-root #{&}--header {
  244. font-weight: bold;
  245. }
  246. @at-root #{&}--cell_border {
  247. padding-right: 0.5rem;
  248. margin-right: 0.5rem;
  249. border-right: thin solid $color__lightgray--primary;
  250. @at-root #{&}-hidden {
  251. border-right-color: transparent;
  252. }
  253. }
  254. @at-root #{&}__post {
  255. width: 40%;
  256. @at-root #{&}__header {
  257. display: flex;
  258. justify-content: space-between;
  259. }
  260. @at-root #{&}__thread {
  261. font-size: 1rem;
  262. text-decoration: underline;
  263. }
  264. @at-root #{&}__content {
  265. }
  266. }
  267. @at-root #{&}__reason {
  268. width: 15%;
  269. }
  270. @at-root #{&}__flagged_by {
  271. width: 20%;
  272. display: flex;
  273. @at-root #{&}__text_info {
  274. margin-left: 0.5rem;
  275. display: flex;
  276. flex-direction: column;
  277. }
  278. @at-root #{&}__date {
  279. color: $color__darkgray--primary;
  280. }
  281. }
  282. @at-root #{&}__actions {
  283. width: 25%;
  284. display: flex;
  285. align-items: center;
  286. .button--red {
  287. margin-right: 0.5rem;
  288. }
  289. }
  290. }
  291. @at-root #{&}__header {
  292. display: flex;
  293. justify-content: space-between;
  294. align-items: center;
  295. }
  296. @at-root #{&}__add_new_ban_modal {
  297. padding: 1rem;
  298. h2 {
  299. padding: 0;
  300. margin: 0;
  301. margin-bottom: -0.5rem;
  302. }
  303. }
  304. @at-root #{&}__table {
  305. width: calc(100%);
  306. overflow: hidden;
  307. margin-top: 1rem;
  308. padding: 0.5rem;
  309. background-color: #fff;
  310. border-radius: 0.25rem;
  311. border-collapse: collapse;
  312. @extend .shadow_border;
  313. td, th {
  314. padding: 0.5rem;
  315. }
  316. th {
  317. text-align: left;
  318. }
  319. tr:nth-child(even) {
  320. background-color: $color__lightgray--darker;
  321. }
  322. }
  323. }
  324. </style>