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.

118 lines
2.8 KiB

  1. const moment = require("moment")
  2. module.exports = class {
  3. onCreate() {
  4. this.state = {
  5. operation: "",
  6. links: [],
  7. parentLink: null,
  8. }
  9. }
  10. onInput(input) {
  11. if (input.data) {
  12. this.refresh(input.data)
  13. }
  14. }
  15. refresh(data) {
  16. this.state.links = []
  17. this.state.operation = opText[data.op]
  18. this.state.parentLink = null
  19. switch (data.model) {
  20. case "Channel": {
  21. const key = data.keys.find(k => k.id !== "*")
  22. this.state.operation += " channel"
  23. this.state.links = [{
  24. text: key.id,
  25. href: `/data/channels/`,
  26. }]
  27. break
  28. }
  29. case "Character": {
  30. const character = data.objects.find(o => o.type === "Character")
  31. this.state.operation += " character"
  32. this.state.links = [{
  33. text: `${character.name} (${character.id})`,
  34. href: `/data/characters/`,
  35. }]
  36. break
  37. }
  38. case "Story": {
  39. const key = data.keys.find(k => k.model === "Story" && k.id !== "*")
  40. const story = data.objects.find(o => o.type === "Story")
  41. this.state.operation += " story"
  42. this.state.links = [{
  43. text: story.name,
  44. href: `/story/${key.id}`,
  45. }]
  46. break
  47. }
  48. case "Chapter": {
  49. const storyKey = data.keys.find(k => k.model === "Story")
  50. const chapterKey = data.keys.find(k => k.model === "Chapter")
  51. const chapter = data.objects.find(o => o.type === "Chapter")
  52. this.state.operation += " chapter"
  53. this.state.links = [{
  54. text: chapter.title || `Untitled chapter (${chapterKey.id})`,
  55. href: `/story/${storyKey.id}#${chapterKey.id}`,
  56. }]
  57. break
  58. }
  59. case "Log": {
  60. const key = data.keys.find(k => k.id !== "*")
  61. this.state.operation += " log"
  62. this.state.links = [{
  63. text: key.id,
  64. href: `/logs/${key.id}`,
  65. }]
  66. break
  67. }
  68. case "Post": {
  69. const logKey = data.keys.find(k => k.model === "Log")
  70. const postKeys = data.keys.filter(k => k.model === "Post")
  71. const postObjs = data.objects.filter(o => o.type === "Post")
  72. this.state.operation += (postKeys.length > 1) ? " posts" : " post"
  73. this.state.links = postObjs.map(po => ({
  74. text: `[${moment(po.time).format("HH:mm")}] ${po.nick}`,
  75. href: `/logs/${logKey.id}#${po.id}`,
  76. }))
  77. this.state.parentLink = {
  78. prefix: "in log",
  79. text: `${logKey.id}`,
  80. href: `/logs/${logKey.id}`,
  81. }
  82. break
  83. }
  84. }
  85. }
  86. }
  87. const opText = {
  88. add: "added",
  89. remove: "removed",
  90. move: "moved",
  91. edit: "edited",
  92. import: "imported",
  93. tag: "tagged",
  94. untag: "untagged",
  95. "move-in": "moved in",
  96. "move-out": "moved out",
  97. }