gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit17d66fee17d66feelog: #58 mergedmre17d66fee/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

  • 17d66feelog: #58 mergedmre
  • 69a6640bMerge hm58-map: tracker#58 project.hl only the mapmre
  • a85f7900Move route logic out of the project mapmre
  • 13dea5belog: #56 live, HM49 and HM58 startedmre
  • a31c8f2fdocs: tracker#36 remaining listmre
  • 975d06d1log: #36 live, DP66 startedmre
  • d6d03fa3mission: T36Bmre
  • e7512d00status: #36 rolled back, retry askedmre
  • c98e2043log: T36A rollbackmre
  • ae905f15Merge t36a: tracker#36 apply rechecks, reportmre
  • 796bfaceT36A: report validated fixes, failed live SSH check and verified rollbackmre
  • 55257852log: #53 live, #56 mergedmre
  • 78b39f1bMerge hm56-rows: tracker#56 list builders insert oncemre
  • 7aea52batmdb fix: protect owners without slugs and record passing gatesmre
  • 9b3c2559tmdb fix: revalidate planned identities and reserve target idsmre
  • 6da612fclog: T36A tool defectmre
  • d56ee0daT36A: report unsafe TMDB apply revalidation and stop before livemre
  • 08e55255log: HM56 done, T36A startedmre
  • 91bcdf0eAvoid per-row list copies and reproduce keyed-row blockersmre
  • 5fd2ac75status: #36 GOmre