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.

70 lines
1.5 KiB

  1. const moment = require("moment")
  2. const {logsApi} = require("../../../../../rpdata/api/Log")
  3. module.exports = class {
  4. onCreate(input) {
  5. this.state = {
  6. error: null,
  7. loading: false,
  8. values: {
  9. date: "",
  10. channel: "",
  11. title: "",
  12. event: "",
  13. description: "",
  14. open: false,
  15. },
  16. }
  17. this.first = false
  18. }
  19. change(key, ev) {
  20. this.state.values[key] = ev.target.value
  21. this.state.values = Object.assign({}, this.state.values)
  22. }
  23. open() {
  24. this.state.loading = false
  25. }
  26. close() {
  27. this.first = false
  28. this.emit("close")
  29. }
  30. save() {
  31. if (this.state.loading) {
  32. return
  33. }
  34. const input = Object.assign({}, this.state.values)
  35. if (input.date == "") {
  36. this.state.error = "You need to specify a date (Did you mean "+moment().format("YYYY-MM-DD HH:mm:ss")+"?)"
  37. return
  38. }
  39. input.date = new Date(input.date)
  40. if (Number.isNaN(input.date)) {
  41. this.state.error = "Invalid date"
  42. return
  43. }
  44. // They're not the same space!
  45. if (input.channel.length < 2 || input.channel.includes(" ") || input.channel.includes(" ") || input.channel.charAt(0) !== "#") {
  46. this.state.error = "Invalid channel name"
  47. return
  48. }
  49. this.state.loading = true
  50. logsApi.add(input).then(log => {
  51. window.location = `/logs/${log.id}/`
  52. }).catch(errs => {
  53. console.warn("Failed to add:", errs)
  54. this.state.error = "Failed to add: " + errs[0].message
  55. }).then(() => {
  56. this.state.loading = false
  57. })
  58. }
  59. }