gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf04afc43f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mref04afc43/components/ticket_list.hl

12.5 KB

  1. // components/ticket_list.hl — `/`, `/project/:projectName` (also `/:projectName`, ticket #25),
  2. // `/state/:stateSlug` and both:
  3. // the tickets, newest update first, filtered by project and state. At the right of the heading: "New ticket" (the accent button) and
  4. // "New project" (a quiet one); each opens its form in the theme's modal window (a full-screen window on a phone). Live: a ticket created or changed anywhere (web or API) lands in,
  5. // moves within or leaves this list without a reload. Ticket #12: the summary is edited visually — since mission 016 in the
  6. // Hybriel MdEditor (components/md-editor/; its hidden field keeps the Markdown and fires `input`).
  7. // Ticket #20: a project's page (`/<slug>`, also `/project/<slug>`; `/projects/<slug>` answers 301) shows its title, description
  8. // (Markdown), its tickets and — for an admin — the link to its settings page. The new-ticket form needs the
  9. // role edit or admin: its project choice holds only the projects the user may open tickets in.
  10. parent './main.hl'
  11. import { ticketRows, firstRows, createTicket } from '../lib/tickets.hl'
  12. import { projectLinks, stateLinks, stateOfSlug } from '../lib/tickets-helpers.hl'
  13. import { projectByAnySlug, editableProjects, isAdminOf } from '../lib/projects.hl'
  14. import { markdownBlocks } from '../lib/markdown.hl'
  15. import { siteName } from '../project.hl'
  16. import { canWriteSession, writerOfSession, userOfSession } from '../lib/users.hl'
  17. import { connectionRows, disconnect } from '../lib/connections.hl'
  18. import Markdown from './markdown.hl'
  19. import MdEditor from './md-editor/md-editor.hl'
  20. import Modal from './modal/modal.hl'
  21. import ProjectForm from './project-form.hl'
  22. projectName = null
  23. stateSlug = null
  24. filterState = stateOfSlug(stateSlug)
  25. // the page draws the newest 50 and a button asks for 50 more: all ~500 rows at once (server-built, shipped, drawn) were a 2–4 s first
  26. // paint and a 90 000 px page on a phone. `total` = how many tickets the filters match
  27. pageSize = 50
  28. limit = pageSize
  29. first = firstRows(projectName, filterState, limit)
  30. rows = first.rows
  31. total = first.total
  32. projects = projectLinks(projectName, filterState)
  33. stateFilters = stateLinks(projectName, filterState)
  34. session = null
  35. project = projectName != null ? projectByAnySlug(projectName) : null
  36. noSuchProject = projectName != null && project == null
  37. projectId = project != null ? project.id : ''
  38. hasDescription = project != null && project.description != null && project.description != ''
  39. descriptionMd = hasDescription ? markdownBlocks(project.description) : []
  40. isAdmin = project != null && isAdminOf(project.id, userOfSession(session))
  41. // ticket #21: the apps connected to this project (connections.hl), shown to everybody; an admin can disconnect
  42. connections = project != null ? connectionRows(project.id) : []
  43. hasConnections = connections.length > 0
  44. connectionMessage = ''
  45. settingsHref = project != null ? '/projects/' + project.slug + '/settings' : ''
  46. isEmpty = rows.length == 0
  47. hasMore = rows.length < total
  48. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  49. heading = (projectName != null ? (project != null ? project.title : projectName) : 'All projects') + (filterState != null ? ' · ' + filterState : '')
  50. __title = siteName + ' | ' + heading
  51. // the new-ticket form
  52. myProjects = editableProjects(userOfSession(session))
  53. newProject = projectName != null && project != null ? project.slug : (myProjects.length > 0 ? myProjects[0].slug : '')
  54. newSubject = ''
  55. newSummary = ''
  56. newMessage = ''
  57. // the MdEditor is built once per element: a new key gives the next ticket an empty editor
  58. summarySeq = 0
  59. summaryForms = [{ id = 'summary-0' }]
  60. // only for a member with the role edit or admin (ticket #20): the author is that user
  61. canWrite = myProjects.length > 0
  62. canCreateProject = canWriteSession(session)
  63. mustLogIn = userOfSession(session) == null
  64. noRole = userOfSession(session) != null && myProjects.length == 0
  65. notice = ''
  66. noticeHref = ''
  67. noticeLink = 'open it'
  68. hasNotice = false
  69. View {
  70. ticketBoard {
  71. headingRow {
  72. h1 { id = "heading" heading }
  73. headingActions {
  74. if (canCreateProject) { button { id = "newprojectlink" type = "button" "New project" on click(e) { emit openWindow('newprojectmodal') } } }
  75. if (canWrite) { button { id = "newticketbutton" type = "button" class = "primary" "New ticket" on click(e) { emit openWindow('newticketmodal') } } }
  76. }
  77. }
  78. ticketFilters {
  79. nav { id = "projectfilter"
  80. for (f of projects) { a { href = f.href class = f.cls f.label } }
  81. }
  82. nav { id = "statefilter"
  83. for (f of stateFilters) { a { href = f.href class = f.cls f.label } }
  84. }
  85. }
  86. if (noSuchProject) { p { id = "noproject" class = "empty" "There is no such project." } }
  87. if (hasDescription) { projectDescription { id = "description" Markdown { blocks = descriptionMd } } }
  88. if (hasConnections) { ul { id = "connections" class = "connections"
  89. for (c of connections) {
  90. li { class = "connection"
  91. "Connected to " strong { c.text }
  92. if (isAdmin) { button { type = "button" class = "quiet danger disconnect" "Disconnect" on click(e) { emit dropConnection(c.id) } } }
  93. }
  94. }
  95. } }
  96. p { id = "connectionmessage" class = "message" connectionMessage }
  97. if (isAdmin) { projectActions { a { id = "settingslink" class = "button" href = settingsHref "Project settings" } } }
  98. if (mustLogIn) { p { id = "loginhint" class = "hint" "Reading is open to everyone. To open a ticket, log in with ident (top right)." } }
  99. if (noRole) { p { id = "rolehint" class = "hint" "To open a ticket you need the role edit or admin in a project — ask an admin of the project to invite you." } }
  100. if (canWrite) { Modal { id = "newticketmodal" title = "New ticket"
  101. form { id = "newticketform"
  102. on submit(e) {
  103. e.preventDefault()
  104. emit create(e)
  105. }
  106. label { "Project"
  107. select { id = "newproject" name = "project" value = newProject on change(e) { emit setProject(e.target.value) }
  108. for (p of myProjects) { option { value = p.slug p.title } }
  109. }
  110. }
  111. label { "Subject"
  112. input { id = "newsubject" name = "subject" required = "required" maxlength = "200" value = newSubject on input(e) { emit setSubject(e.target.value) } }
  113. }
  114. mdField { id = "newsummary" on input(e) { emit setSummary(e.target.name, e.target.value) }
  115. span { "Summary" }
  116. for (f of summaryForms) { MdEditor { name = "summary" value = "" rows = 4 placeholder = "" files = "off" } }
  117. }
  118. button { id = "newsubmit" type = "submit" "Open ticket" }
  119. p { id = "newmessage" class = "message" newMessage }
  120. }
  121. } }
  122. if (canCreateProject) { Modal { id = "newprojectmodal" title = "New project"
  123. ProjectForm { onCreated = projectCreated }
  124. } }
  125. if (hasNotice) { p { id = "notice" class = "notice" notice " " a { id = "noticelink" href = noticeHref noticeLink } } }
  126. if (isEmpty) { p { id = "empty" class = "empty" "No tickets here." } }
  127. ol { id = "tickets" class = "tickets"
  128. for (row of rows) {
  129. li {
  130. ticketState { class = row.stateSlug row.state }
  131. a { class = "subject" href = row.href ticketRef { row.ref } row.subject }
  132. ticketMeta {
  133. a { href = row.projectHref row.projectTitle }
  134. if (row.hasAssignee) { assignee { row.assignee } }
  135. time { row.updated }
  136. }
  137. }
  138. }
  139. }
  140. if (hasMore) { button { id = "moretickets" type = "button" class = "quiet" moreLabel on click(e) { emit showMore(e) } } }
  141. }
  142. }
  143. on showMore(e) {
  144. limit = limit + pageSize
  145. r = emit server moreRows(projectName != null ? projectName : '', filterState != null ? filterState : '', limit)
  146. if (r != null && r.rows != null) {
  147. rows = r.rows
  148. total = r.total
  149. isEmpty = rows.length == 0
  150. hasMore = rows.length < total
  151. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  152. }
  153. }
  154. on server moreRows(project, state, n, session) {
  155. return firstRows(project != '' ? project : null, state != '' ? state : null, n)
  156. }
  157. // the window of a form (Esc, the × and a tap beside it close it)
  158. on openWindow(id) { document.getElementById(id).showModal() }
  159. on setProject(v) { newProject = v }
  160. on setSubject(v) { newSubject = v }
  161. // the MdEditor announces its Markdown with an `input` event on its hidden field (named); its other inputs are not it
  162. on setSummary(name, v) { if (name == 'summary') { newSummary = v } }
  163. on create(e) {
  164. if (newProject.trim() == '' || newSubject.trim() == '') { return null }
  165. r = emit server openTicket(newProject, newSubject, newSummary)
  166. if (r != null && r.error == null) {
  167. notice = 'Opened ' + r.project + ' ' + r.ref + '.'
  168. noticeHref = r.href
  169. noticeLink = 'open it'
  170. hasNotice = true
  171. newMessage = ''
  172. document.getElementById('newticketmodal').close('opened')
  173. newSubject = ''
  174. newSummary = ''
  175. summarySeq = summarySeq + 1
  176. summaryForms = [{ id = 'summary-' + summarySeq }]
  177. } else {
  178. newMessage = r != null ? r.error : 'could not open the ticket'
  179. }
  180. }
  181. // the project form (components/project-form.hl) tells the page: the window closes, the page says it and links the settings
  182. projectCreated = (title, settingsHref) => {
  183. notice = 'Created ' + title + '.'
  184. noticeHref = settingsHref
  185. noticeLink = 'open its settings'
  186. hasNotice = true
  187. document.getElementById('newprojectmodal').close('created')
  188. }
  189. // does a row belong in THIS list (its filters)?
  190. belongs = (row) => {
  191. return (projectName == null || row.projectId == projectId) && (filterState == null || row.state == filterState)
  192. }
  193. // the row goes to the top (newest update first) if it belongs, and out if not
  194. place = (row) => {
  195. let wasIn = false
  196. for (r of rows) { if (r.id == row.id) { wasIn = true } }
  197. let allShown = rows.length >= total
  198. next = []
  199. if (belongs(row)) { next.push(row) }
  200. for (r of rows) { if (r.id != row.id) { next.push(r) } }
  201. // a new ticket joins the count when everything was on the page; one that left the filter leaves it
  202. if (belongs(row) && !wasIn && allShown) { total = total + 1 }
  203. if (!belongs(row) && wasIn) { total = total - 1 }
  204. if (allShown && next.length > limit) { limit = next.length }
  205. rows = next.length > limit ? next.slice(0, limit) : next
  206. isEmpty = rows.length == 0
  207. hasMore = rows.length < total
  208. moreLabel = 'Show ' + pageSize + ' more (' + (total - rows.length) + ' left)'
  209. }
  210. on client ticketCreated(row) { place(row) }
  211. on dropConnection(id) {
  212. r = emit server disconnectApp(projectId, id)
  213. if (r == null || r.error != null) {
  214. connectionMessage = r != null ? r.error : 'could not disconnect'
  215. return null
  216. }
  217. connectionMessage = ''
  218. connections = r.connections
  219. hasConnections = r.connections.length > 0
  220. }
  221. on client connectionsChanged(slug) {
  222. r = emit server connectionsOfProject(projectId)
  223. if (r != null && r.connections != null) {
  224. connections = r.connections
  225. hasConnections = r.connections.length > 0
  226. }
  227. }
  228. on client signedIn(tag, info) {
  229. r = emit server whatICanOpen(projectName != null ? projectName : '')
  230. if (r != null && r.projects != null) {
  231. myProjects = r.projects
  232. canWrite = r.projects.length > 0
  233. noRole = r.projects.length == 0 && info.named
  234. canCreateProject = info.named
  235. mustLogIn = false
  236. isAdmin = r.admin == true
  237. if (newProject == '' && r.projects.length > 0) { newProject = r.projects[0].slug }
  238. }
  239. }
  240. on client signedOut(tag) {
  241. canWrite = false
  242. canCreateProject = false
  243. isAdmin = false
  244. noRole = false
  245. mustLogIn = true
  246. myProjects = []
  247. }
  248. on client ticketEvent(ticketId, ev, row) { place(row) }
  249. // THE FACE: a ticket opened from the web by the session's user (#31: only a real session).
  250. // The same push the API sends.
  251. on server openTicket(project, subject, summary, session) {
  252. w = writerOfSession(session)
  253. if (w.error != null) { return { error = w.error } }
  254. r = createTicket(project, subject, summary, w.user, null, null)
  255. if (r.error != null) { return { error = r.error } }
  256. emit client ticketCreated(r.ticket)
  257. return r.ticket
  258. }
  259. // what this session's user may do here after a login without a reload: the projects they may open tickets in,
  260. // and whether they are an admin of THIS page's project (`slug` null = the all-projects page)
  261. on server whatICanOpen(slug, session) {
  262. u = userOfSession(session)
  263. if (u == null) { return { error = 'log in first' } }
  264. p = slug != null && slug != '' ? projectByAnySlug(slug) : null
  265. return { projects = editableProjects(u) admin = p != null && isAdminOf(p.id, u) }
  266. }
  267. // ticket #21: an admin ends a connection — the key is dead at once (connections.hl)
  268. on server disconnectApp(projectId, connectionId, session) {
  269. w = writerOfSession(session)
  270. if (w.error != null) { return { error = w.error } }
  271. r = disconnect('' + projectId, w.user, '' + connectionId)
  272. if (r.error != null) { return { error = r.error } }
  273. emit client connectionsChanged('')
  274. return { connections = r.connections }
  275. }
  276. on server connectionsOfProject(projectId, session) {
  277. return { connections = connectionRows('' + projectId) }
  278. }

Branches

Latest commits

  • f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mre
  • 06599fa0tickets: MdEditor from components b0f1ec2 (a clipboard with text always pastes the text, tickets#49); real Ctrl+V gatemre
  • 2e1b116ftickets: re-vendor Hybriel master acaceaf3 (framework ec8d6c1d): plugins/web patch queue while a page is built, anonymous session cookies refresh; gate waits for the comment editors to draw (W174) and clicks the form editor when it stands still; security gate: main's code runs on its own binary, lazy-session cookie checksmre
  • 361bc0fetickets: re-vendor Hybriel 7a684920 (WIP, not deployed); on Error exits 1 at startup; migrate passes its log by reference; gate checks follow lazy sessions and the 413 refusalmre
  • 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
  • 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
  • 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre
  • 8179d287tickets: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
  • 0398145ctickets: the table grid rule is marked functional for check-thememre
  • 40fddc20tickets takes components e54f83a: tables get thin grey lines from the theme, desktop toolbar stays one row with the Table button, F4 check counts 11 buttonsmre
  • c1b77d61tickets#35: text typed before the editor is built is taken in once by the build (the input handler no longer writes it to the field first, which doubled the first letters); the gate failure shows the surfacemre
  • 32bf1873tickets#35: the gate types right after the load with the CPU slowed, no waitingmre
  • 64ea9ca2tickets#35: text typed into the reply editor before the page has finished starting is kept; the gate types right after loadmre
  • ccd3a327tickets: the security gate expects frame-src to be exactly the ident address (the sign-in frame), still no wildcard or selfmre
  • 4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 66ef3005Merge branch 'iw-ident-widget'mre
  • bc0ad663tickets: a gap between your name and Log out in the phone header (they touched); gate checks itmre
  • 2f818d46UX2: report, LOG line, e2e fixes, gate pause after loadmre
  • af3ef7c4gate: the legacy state line says progressmre
  • 62480a00tickets#33: a state change with a note is a comment card in the feed (same framework rendering, can be liked, edited, deleted), its state line stands alone; gate checks for a new comment with and without a state change, at once and after a reloadmre