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.

83 lines
2.3 KiB

6 years ago
  1. const {query} = require("../client")
  2. class LogHeader {
  3. /**
  4. * Construct a log header. You should probably use the logHeaderApi instead of doing
  5. * this manually, even for mutations.
  6. *
  7. * @param {string} id
  8. * @param {Date|string} date
  9. * @param {string} channelName
  10. * @param {string} title
  11. * @param {string} description
  12. * @param {string} event
  13. * @param {boolean} open
  14. * @param {{id:string,name:string,shortName:string,author:string}[]} characters
  15. */
  16. constructor(id, shortId, date, channelName, title, description, event, open, characters) {
  17. this.id = id
  18. this.shortId = shortId
  19. this.date = new Date(date)
  20. this.channelName = channelName
  21. this.title = title || null
  22. this.description = description || null
  23. this.event = event || null
  24. this.open = open
  25. this.characters = characters.map(ch => new LogHeaderCharacter(ch.id, ch.name, ch.shortName, ch.author))
  26. }
  27. }
  28. class LogHeaderCharacter {
  29. /**
  30. * Construct a log header character list entry.
  31. *
  32. * @param {string} id
  33. * @param {string} name
  34. * @param {string} shortName
  35. * @param {string} author
  36. */
  37. constructor(id, name, shortName, author) {
  38. this.id = id
  39. this.name = name
  40. this.shortName = shortName
  41. this.author = author
  42. }
  43. }
  44. /**
  45. * logHeaderApi contains the API queries for the LogHeader frontend model, which is a subset of the
  46. * logs model.
  47. */
  48. const logHeaderApi = {
  49. /**
  50. * Call `stories(filter)` query
  51. *
  52. * @param {{search:string, channels:string|string[], events:string|string[], open:boolean, characters:string|string[], limit:number}} filter
  53. * @returns {Promise<LogHeader[]>}
  54. */
  55. list(filter = {}) {
  56. return query(`
  57. query LogHeaders($filter: LogsFilter) {
  58. headers: logs(filter:$filter) {
  59. id
  60. shortId
  61. date
  62. channelName
  63. title
  64. description
  65. event
  66. open
  67. characters {
  68. id
  69. name
  70. shortName
  71. author
  72. }
  73. }
  74. }
  75. `, {filter}).then(({headers}) => {
  76. return headers.map(h => new LogHeader(h.id, h.shortId, h.date, h.channelName, h.title, h.description, h.event, h.open, h.characters))
  77. })
  78. },
  79. }
  80. module.exports = {LogHeader, LogHeaderCharacter, logHeaderApi}