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.

82 lines
1.9 KiB

  1. const {tz} = require("moment-timezone")
  2. const {logsApi} = require("../../../../../rpdata/api/Log")
  3. module.exports = class {
  4. onCreate(input) {
  5. this.state = {
  6. error: null,
  7. loading: false,
  8. imported: null,
  9. values: {
  10. importer: "MircLike",
  11. timezone: tz.guess() || "UTC",
  12. channelName: "",
  13. date: "",
  14. data: "",
  15. },
  16. timezones: tz.names(),
  17. }
  18. this.first = false
  19. }
  20. change(key, ev) {
  21. this.state.values[key] = ev.target.value
  22. this.state.values = Object.assign({}, this.state.values)
  23. }
  24. open() {
  25. this.state.loading = false
  26. }
  27. close() {
  28. this.emit("close")
  29. this.state.values = {
  30. importer: "MircLike",
  31. timezone: tz.guess() || "UTC",
  32. channelName: "",
  33. date: "",
  34. data: "",
  35. }
  36. this.state.imported = null
  37. this.state.loading = false
  38. }
  39. save() {
  40. if (this.state.loading) {
  41. return
  42. }
  43. this.state.error = null;
  44. const input = Object.assign({}, this.state.values)
  45. if (input.date != "" && input.importer !== "ForumLog") {
  46. input.date = new Date(input.date)
  47. if (Number.isNaN(input.date)) {
  48. this.state.error = "Invalid date"
  49. return
  50. }
  51. } else if (input.importer === "MircLike") {
  52. this.state.error = "Date is required for mIRC-like logs"
  53. return
  54. } else {
  55. input.date = null;
  56. }
  57. if (input.channelName.length < 2 || input.channelName.includes(" ") || input.channelName.includes(" ") || input.channelName.charAt(0) !== "#") {
  58. this.state.error = "A valid channelName name is required"
  59. return
  60. }
  61. this.state.loading = true
  62. logsApi.import(input).then(logs => {
  63. this.state.imported = logs
  64. }).catch(errs => {
  65. console.warn("Import failed:", errs)
  66. this.state.error = "Import failed: " + errs[0].message
  67. }).then(() => {
  68. this.state.loading = false
  69. })
  70. }
  71. }