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.

133 lines
3.4 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 "Comment": {
  60. const storyKey = data.keys.find(k => k.model === "Story") || {}
  61. const chapterKey = data.keys.find(k => k.model === "Chapter")
  62. const chapter = data.objects.find(o => o.type === "Chapter") || {}
  63. const comment = data.objects.find(o => o.type === "Comment") || {}
  64. this.state.operation += ' ' + comment.characterName + " comment in chapter"
  65. this.state.links = [{
  66. text: chapter.title || `ID (${chapterKey.id})`,
  67. href: `/story/${storyKey.id}#${chapterKey.id}`,
  68. }]
  69. break
  70. }
  71. case "Log": {
  72. const key = data.keys.find(k => k.id !== "*")
  73. this.state.operation += " log"
  74. this.state.links = [{
  75. text: key.id,
  76. href: `/logs/${key.id}`,
  77. }]
  78. break
  79. }
  80. case "Post": {
  81. const logKey = data.keys.find(k => k.model === "Log")
  82. const postKeys = data.keys.filter(k => k.model === "Post")
  83. const postObjs = data.objects.filter(o => o.type === "Post")
  84. this.state.operation += (postKeys.length > 1) ? " posts" : " post"
  85. this.state.links = postObjs.map(po => ({
  86. text: `[${moment(po.time).format("HH:mm")}] ${po.nick}`,
  87. href: `/logs/${logKey.id}#${po.id}`,
  88. }))
  89. this.state.parentLink = {
  90. prefix: "in log",
  91. text: `${logKey.id}`,
  92. href: `/logs/${logKey.id}`,
  93. }
  94. break
  95. }
  96. }
  97. }
  98. }
  99. const opText = {
  100. add: "added",
  101. remove: "removed",
  102. move: "moved",
  103. edit: "edited",
  104. import: "imported",
  105. tag: "tagged",
  106. untag: "untagged",
  107. "move-in": "moved in",
  108. "move-out": "moved out",
  109. }