The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.6 KiB

6 years ago
6 years ago
6 years ago
  1. const { logHeaderApi } = require("../../../../../rpdata/api/LogHeader")
  2. module.exports = class {
  3. onCreate(input) {
  4. this.state = {
  5. filter: input.filter,
  6. logs: input.logs,
  7. modal: null,
  8. }
  9. }
  10. open(modal) {
  11. this.state.modal = modal
  12. }
  13. close() {
  14. this.state.modal = null
  15. }
  16. addFilter(type, filter) {
  17. if (type === "search") {
  18. if (filter.trim().length > 0) {
  19. this.state.filter = Object.assign({}, this.state.filter, {search: filter})
  20. } else {
  21. this.state.filter = Object.assign({}, this.state.filter, {search: null})
  22. }
  23. } else {
  24. this.state.filter = Object.assign({}, this.state.filter, {[type]: (this.state.filter[type] || []).filter(f => f !== filter).concat(filter)})
  25. }
  26. this.state.filter = Object.assign({}, this.state.filter, {limit: 0})
  27. this.updateQuery(this.state.filter)
  28. this.refresh()
  29. }
  30. removeFilter(type, filter) {
  31. if (type === "search") {
  32. this.state.filter = Object.assign({}, this.state.filter, {search: null})
  33. this.refresh()
  34. } else if ((this.state.filter[type] || []).length === 1) {
  35. this.state.filter = Object.assign({}, this.state.filter, {[type]: null})
  36. this.refresh()
  37. } else {
  38. const index = (this.state.filter[type] || []).indexOf(filter)
  39. if (index !== -1) {
  40. this.state.filter = Object.assign({}, this.state.filter, {[type]: this.state.filter[type].splice(0, index).concat(this.state.filter[type].splice(index + 1))},)
  41. this.refresh()
  42. }
  43. }
  44. this.updateQuery(this.state.filter)
  45. }
  46. updateQuery(filter) {
  47. const queries = []
  48. if (filter.characters) {
  49. queries.push("characters=" + filter.characters.join(","))
  50. }
  51. if (filter.channels) {
  52. queries.push("channels=" + filter.channels.map(c => encodeURIComponent(c)).join(","))
  53. }
  54. if (filter.events) {
  55. queries.push("events=" + filter.events.map(e => encodeURIComponent(e)).join(","))
  56. }
  57. if (filter.search) {
  58. queries.push("search=" + encodeURIComponent(filter.search))
  59. }
  60. if (filter.limit) {
  61. queries.push("limit=" + encodeURIComponent(filter.limit.toString()))
  62. }
  63. if (queries.length > 0) {
  64. history.replaceState("", "", `/logs/?${queries.join("&")}`)
  65. } else {
  66. history.replaceState("", "", "/logs/")
  67. }
  68. }
  69. clearLimit() {
  70. this.state.filter = Object.assign({}, this.state.filter, {limit: 0})
  71. this.refresh()
  72. this.updateQuery(this.state.filter)
  73. }
  74. refresh() {
  75. logHeaderApi.list(this.state.filter).then(logs => {
  76. this.state.logs = logs
  77. })
  78. }
  79. }