gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2aa22d232aa22d23log: #36 GOmre2aa22d23/components/timelineedit.hl

7.1 KB

  1. // components/timelineedit.hl — `/timelines/:slug/edit` (tracker.worldapi.org#19, mission 066): the creator's editor of ONE
  2. // timeline — its franchise (a row of chips: None + every franchise; a tap attaches it), its titles in their in-world order
  3. // (↑ / ↓ move one place, ✕ removes), and "Add titles": our database as you type (search.hl's index), "Add" puts the title at
  4. // the end. Mobile first: one column, big tap targets. Only the creator (franchises.hl isEditorSession) sees the controls; every
  5. // face checks it again.
  6. //
  7. // HYBRIEL TRAPS (as components/search.hl, hybriel#121/#122): no member reads both the route param and `session` — the
  8. // timeline's data come from `slug` alone, the editor state from `session` alone; every list is replaced whole with the
  9. // face's answer, never appended to.
  10. parent './main.hl'
  11. import { appTitle } from '../project.hl'
  12. import { isEditorSession, editPageOf, addToTimeline, removeFromTimeline, moveInTimeline, setTimelineFranchise, editSearch } from '../lib/franchises.hl'
  13. import { warmReady, warmText } from '../lib/warm.hl'
  14. static editorOf = (&session) => { return isEditorSession(&session) }
  15. static startOf = (&slug) => { return editPageOf(slug) }
  16. slug = null
  17. session = null
  18. isEditor = editorOf(&session)
  19. notEditor = isEditor == false
  20. start = startOf(&slug)
  21. found = start.found
  22. notFound = start.found == false
  23. timelineId = start.id
  24. name = start.name
  25. viewHref = start.viewHref
  26. rows = start.rows
  27. hasRows = rows.length > 0
  28. noRows = rows.length == 0
  29. countText = rows.length == 1 ? '1 title' : rows.length + ' titles'
  30. chips = start.chips
  31. searchText = ''
  32. results = []
  33. hasResults = results.length > 0
  34. searchNote = ''
  35. hasSearchNote = searchNote != ''
  36. message = ''
  37. hasMessage = message != ''
  38. __title = found ? 'Edit ' + name + ' — ' + appTitle : appTitle
  39. // mission T17 (boot time): the server listens while bootscan.hl still builds the lists / slug maps / search index (lib/warm.hl); until the 'all'
  40. // stage is there this page says so instead of showing half a map
  41. warming = !warmReady('all')
  42. warmNote = warming ? warmText() : ''
  43. View {
  44. timelineEditPage { "data-timeline" = timelineId
  45. if (warming) { p { id = "warming" class = "message banner" warmNote } }
  46. if (notFound) {
  47. h1 { "Not found" }
  48. p { "This timeline doesn't exist." }
  49. }
  50. if (found) {
  51. franchisesHead {
  52. h1 { class = "typed" typeWord { class = "type-word type-timeline" "Timeline" } typeSep { "|" } typeName { name } }
  53. a { id = "timeline-view" class = "button" href = viewHref "View" }
  54. }
  55. if (notEditor) { p { id = "edit-refused" class = "muted" "Only the creator can edit franchises and timelines." } }
  56. if (isEditor) {
  57. if (hasMessage) { p { id = "edit-message" class = "message" message } }
  58. editSection {
  59. h2 { class = "film-heading" "Franchise" }
  60. chipRow { id = "franchise-chips"
  61. for (c of chips) { button { type = "button" class = c.cls value = c.id c.name on click(e) { emit pickFranchise(c.id) } } }
  62. }
  63. a { class = "edit-new-franchise" href = "/franchises/edit" "New franchise …" }
  64. }
  65. editSection {
  66. h2 { class = "film-heading" "Titles in timeline order" }
  67. p { class = "muted list-count" countText }
  68. if (noRows) { p { class = "muted" "No titles yet — add some below." } }
  69. if (hasRows) {
  70. editRows { id = "edit-rows"
  71. for (row of rows) {
  72. editRow { "data-show" = row.id
  73. editPos { row.pos }
  74. img { class = "film-poster" src = row.posterUrl alt = "" }
  75. filmText {
  76. filmTitle { row.title }
  77. filmMeta { span { class = row.typeClass row.typeLabel } }
  78. }
  79. button { type = "button" class = row.upClass value = "up" title = "Move up" "aria-label" = "Move up" "↑" on click(e) { emit moveRow(row.id, -1) } }
  80. button { type = "button" class = row.downClass value = "down" title = "Move down" "aria-label" = "Move down" "↓" on click(e) { emit moveRow(row.id, 1) } }
  81. button { type = "button" class = "quiet mv rm" value = "remove" title = "Remove" "aria-label" = "Remove" "✕" on click(e) { emit removeRow(row.id) } }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. editSection {
  88. h2 { class = "film-heading" "Add titles" }
  89. input { id = "ted-search" value = searchText type = "search" placeholder = "Search our movies and series" autocomplete = "off" "aria-label" = "Search titles" on input(e) { emit searchTyped(e) } }
  90. if (hasSearchNote) { p { id = "ted-note" class = "muted" searchNote } }
  91. if (hasResults) {
  92. editRows { id = "ted-results"
  93. for (r of results) {
  94. editRow { "data-show" = r.id
  95. img { class = "film-poster" src = r.posterUrl alt = "" }
  96. filmText {
  97. filmTitle { r.title }
  98. filmMeta { span { class = r.typeClass r.typeLabel } }
  99. }
  100. button { type = "button" class = "inverted add" value = r.id "Add" on click(e) { emit addRow(r.id) } }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. on pickFranchise(franchiseId) {
  111. let r = emit server tedSetFranchise(timelineId, '' + franchiseId)
  112. if (r == null || r.error != null) { message = r != null ? r.error : 'Could not save it.' return null }
  113. message = ''
  114. chips = r.chips
  115. }
  116. on moveRow(showId, delta) {
  117. let r = emit server tedMove(timelineId, '' + showId, delta)
  118. if (r == null || r.error != null) { message = r != null ? r.error : 'Could not save it.' return null }
  119. message = ''
  120. rows = r.rows
  121. }
  122. on removeRow(showId) {
  123. let r = emit server tedRemove(timelineId, '' + showId)
  124. if (r == null || r.error != null) { message = r != null ? r.error : 'Could not save it.' return null }
  125. message = ''
  126. rows = r.rows
  127. }
  128. on addRow(showId) {
  129. let r = emit server tedAdd(timelineId, '' + showId)
  130. if (r == null || r.error != null) { message = r != null ? r.error : 'Could not save it.' return null }
  131. message = ''
  132. rows = r.rows
  133. // the added title leaves the results (it is in the timeline now)
  134. left = []
  135. for (x of results) { if (x.id != showId) { left.push(x) } }
  136. results = left
  137. }
  138. on searchTyped(e) {
  139. v = e.target.value
  140. searchText = v
  141. let r = emit server tedSearch(timelineId, v)
  142. if (r == null || searchText != v) { return null }
  143. results = r.rows
  144. searchNote = v.trim() == '' ? '' : r.note
  145. }
  146. // ---- the faces (unique names; the trailing `session` is the server's) ----
  147. on server tedSetFranchise(timelineId, franchiseId, session) {
  148. if (!isEditorSession(&session)) { return { error = 'only the creator can do that' } }
  149. return setTimelineFranchise(&timelineId, franchiseId)
  150. }
  151. on server tedMove(timelineId, showId, delta, session) {
  152. if (!isEditorSession(&session)) { return { error = 'only the creator can do that' } }
  153. return moveInTimeline(&timelineId, &showId, &delta)
  154. }
  155. on server tedRemove(timelineId, showId, session) {
  156. if (!isEditorSession(&session)) { return { error = 'only the creator can do that' } }
  157. return removeFromTimeline(&timelineId, &showId)
  158. }
  159. on server tedAdd(timelineId, showId, session) {
  160. if (!isEditorSession(&session)) { return { error = 'only the creator can do that' } }
  161. return addToTimeline(&timelineId, &showId)
  162. }
  163. // the search is our public database (like /search) — no session
  164. on server tedSearch(timelineId, text) {
  165. return editSearch(&timelineId, text)
  166. }

Branches

Latest commits

  • 2aa22d23log: #36 GOmre
  • 833aee2flog: #50 closed, HM56 startedmre
  • ac58c1e5mission: HM56mre
  • 58979c0clog: HM54 held for decision, DP65 startedmre
  • bb2ebc67log: #64 live, #53 mergedmre
  • 27cde42fMerge hm53-dom: tracker#53 inputs bound to membersmre
  • 2156cc7flog: HM54 reviewmre
  • 9fb82efclog: HM54 gap, fill continuesmre
  • b632eb8dlog: HM53 done, HM54 startedmre
  • ccb1a263tracker#53: bind editor drafts and use key event focus targetmre
  • 3356fcfclog: #52 blocked, HM53 startedmre
  • 833dcfc9Merge hm52-search: report only, tracker#52 blocked by framework gapmre
  • 73010cc0HM52: report replace-navigation search draft regressionmre
  • 1742e92bstatus: DP64 and HM52 runningmre
  • 29ad5b58log: #64 merged, DP64 and HM52 startedmre
  • fafddbf9Merge hm64-catalog: tracker#64 catalog from packed entriesmre
  • b2e2206dlog: #63 livemre
  • 5831e0e0log: HM64 donemre
  • 4042b923Flatten catalog membership rows into paired slotsmre
  • ea8a759elog: #61 #62 live, DP63 and HM64 startedmre