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.

147 lines
3.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||chapter).id})`,
  55. href: `/story/${storyKey.id}#${(chapterKey||chapter).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 "File": {
  81. const key = data.keys.find(k => k.id !== "*")
  82. const fileObj = data.objects.find(o => o.type === "File") || {name: key.id}
  83. this.state.operation += " file"
  84. this.state.links = [{
  85. text: fileObj.name,
  86. href: `/data/files#${key.id}`,
  87. }]
  88. break
  89. }
  90. case "Post": {
  91. const logKey = data.keys.find(k => k.model === "Log")
  92. const postKeys = data.keys.filter(k => k.model === "Post")
  93. const postObjs = data.objects.filter(o => o.type === "Post")
  94. this.state.operation += (postKeys.length > 1) ? " posts" : " post"
  95. this.state.links = postObjs.map(po => ({
  96. text: `[${moment(po.time).format("HH:mm")}] ${po.nick}`,
  97. href: `/logs/${logKey.id}#${po.id}`,
  98. }))
  99. this.state.parentLink = {
  100. prefix: "in log",
  101. text: `${logKey.id}`,
  102. href: `/logs/${logKey.id}`,
  103. }
  104. break
  105. }
  106. }
  107. }
  108. }
  109. const opText = {
  110. add: "added",
  111. remove: "removed",
  112. upload: "uploaded",
  113. move: "moved",
  114. edit: "edited",
  115. import: "imported",
  116. tag: "tagged",
  117. untag: "untagged",
  118. "move-in": "moved in",
  119. "move-out": "moved out",
  120. }