Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

239 řádky
7.6KB

  1. <%
  2. Class BoardsController_Class
  3. Private m_useLayout
  4. Private m_title
  5. Private Sub Class_Initialize()
  6. m_useLayout = True
  7. m_title = "Boards"
  8. End Sub
  9. Public Property Get useLayout() : useLayout = m_useLayout : End Property
  10. Public Property Let useLayout(v) : m_useLayout = v : End Property
  11. Public Property Get Title() : Title = m_title : End Property
  12. Public Property Let Title(v) : m_title = v : End Property
  13. ' GET /boards
  14. Public Sub Index()
  15. If Not KeycloakRequireLogin("") Then Exit Sub
  16. Dim boards : Set boards = boards_Repository().GetAll()
  17. %>
  18. <!--#include file="../views/Boards/Index.asp" -->
  19. <%
  20. Set boards = Nothing
  21. End Sub
  22. ' GET /boards/create
  23. Public Sub Create()
  24. If Not KeycloakRequireLogin("") Then Exit Sub
  25. m_title = "New Board"
  26. %>
  27. <!--#include file="../views/Boards/Create.asp" -->
  28. <%
  29. End Sub
  30. ' POST /boards
  31. Public Sub Store()
  32. If Not KeycloakRequireLogin("") Then Exit Sub
  33. Dim boardName, slug, currentUsername
  34. boardName = Trim(CStr(Request.Form("name")))
  35. If Len(boardName) = 0 Then
  36. Dim flashCreateErr : Set flashCreateErr = Flash()
  37. flashCreateErr.AddError "Board name is required."
  38. MVC.RedirectTo "Boards", "Create"
  39. Exit Sub
  40. End If
  41. currentUsername = GetCurrentUsername()
  42. slug = boards_Repository().UniqueSlug(GenerateSlug(boardName), 0)
  43. Dim board : Set board = New POBO_boards
  44. board.name = boardName
  45. board.slug = slug
  46. board.created_at = Now()
  47. board.created_by = currentUsername
  48. board.updated_at = Now()
  49. board.updated_by = currentUsername
  50. boards_Repository().AddNew board
  51. Dim flashCreateOk : Set flashCreateOk = Flash()
  52. flashCreateOk.Success = "Board created."
  53. Response.Redirect "/board/" & board.slug
  54. End Sub
  55. ' GET /board/:slug
  56. Public Sub Show(slug)
  57. If Not KeycloakRequireLogin("") Then Exit Sub
  58. m_useLayout = False
  59. Dim board : Set board = boards_Repository().FindBySlug(slug)
  60. If board Is Nothing Then
  61. Response.Status = "404 Not Found"
  62. Response.Write "Board not found."
  63. Exit Sub
  64. End If
  65. m_title = board.name
  66. Dim columns : Set columns = board_columns_Repository().FindByBoardId(board.id)
  67. Dim lanes : Set lanes = swim_lanes_Repository().FindByBoardId(board.id)
  68. Dim allCards : Set allCards = cards_Repository().FindByBoardId(board.id)
  69. ' Build arrays for the view (functions cannot be defined inside a view include)
  70. Dim colCount : colCount = columns.Count
  71. Dim laneCount : laneCount = lanes.Count
  72. Dim colsArr() : ReDim colsArr(IIf(colCount > 0, colCount - 1, 0))
  73. Dim lanesArr() : ReDim lanesArr(IIf(laneCount > 0, laneCount - 1, 0))
  74. Dim colIdx, laneIdx, colIter, laneIter, colItem, laneItem
  75. colIdx = 0
  76. Set colIter = columns.Iterator()
  77. Do While colIter.HasNext()
  78. Set colsArr(colIdx) = colIter.GetNext()
  79. colIdx = colIdx + 1
  80. Loop
  81. laneIdx = 0
  82. Set laneIter = lanes.Iterator()
  83. Do While laneIter.HasNext()
  84. Set lanesArr(laneIdx) = laneIter.GetNext()
  85. laneIdx = laneIdx + 1
  86. Loop
  87. ' Serialise cards to JSON
  88. Dim cardsJson : cardsJson = "["
  89. Dim firstCard : firstCard = True
  90. Dim cardIter, cardItem
  91. Set cardIter = allCards.Iterator()
  92. Do While cardIter.HasNext()
  93. Set cardItem = cardIter.GetNext()
  94. If Not firstCard Then cardsJson = cardsJson & ","
  95. cardsJson = cardsJson & "{""id"":" & cardItem.id & "," & _
  96. """column_id"":" & cardItem.column_id & "," & _
  97. """swim_lane_id"":" & cardItem.swim_lane_id & "," & _
  98. """job_number"":" & JsonStr(cardItem.job_number) & "," & _
  99. """job_name"":" & JsonStr(cardItem.job_name) & "," & _
  100. """position"":" & cardItem.position & "}"
  101. firstCard = False
  102. Loop
  103. cardsJson = cardsJson & "]"
  104. %>
  105. <!--#include file="../views/Boards/Show.asp" -->
  106. <%
  107. Set board = Nothing
  108. Set columns = Nothing
  109. Set lanes = Nothing
  110. Set allCards = Nothing
  111. End Sub
  112. ' GET /board/:slug/edit
  113. Public Sub Edit(slug)
  114. If Not KeycloakRequireLogin("") Then Exit Sub
  115. m_title = "Edit Board"
  116. Dim board : Set board = boards_Repository().FindBySlug(slug)
  117. If board Is Nothing Then
  118. Response.Status = "404 Not Found"
  119. Response.Write "Board not found."
  120. Exit Sub
  121. End If
  122. %>
  123. <!--#include file="../views/Boards/Edit.asp" -->
  124. <%
  125. Set board = Nothing
  126. End Sub
  127. ' POST /board/:slug/update
  128. Public Sub Update(slug)
  129. If Not KeycloakRequireLogin("") Then Exit Sub
  130. Dim board : Set board = boards_Repository().FindBySlug(slug)
  131. If board Is Nothing Then
  132. Response.Status = "404 Not Found"
  133. Response.Write "Board not found."
  134. Exit Sub
  135. End If
  136. Dim newName : newName = Trim(CStr(Request.Form("name")))
  137. If Len(newName) = 0 Then
  138. Dim flashUpdateErr : Set flashUpdateErr = Flash()
  139. flashUpdateErr.AddError "Board name is required."
  140. Response.Redirect "/board/" & slug & "/edit"
  141. Exit Sub
  142. End If
  143. Dim newSlug : newSlug = boards_Repository().UniqueSlug(GenerateSlug(newName), CLng(board.id))
  144. board.name = newName
  145. board.slug = newSlug
  146. board.updated_at = Now()
  147. board.updated_by = GetCurrentUsername()
  148. boards_Repository().Update board
  149. Dim flashUpdateOk : Set flashUpdateOk = Flash()
  150. flashUpdateOk.Success = "Board updated."
  151. Response.Redirect "/board/" & newSlug
  152. End Sub
  153. ' POST /board/:slug/delete
  154. Public Sub Destroy(slug)
  155. If Not KeycloakRequireLogin("") Then Exit Sub
  156. Dim board : Set board = boards_Repository().FindBySlug(slug)
  157. If board Is Nothing Then
  158. Response.Redirect "/boards"
  159. Exit Sub
  160. End If
  161. Dim boardId : boardId = CLng(board.id)
  162. cards_Repository().DeleteByBoardId boardId
  163. board_columns_Repository().DeleteByBoardId boardId
  164. swim_lanes_Repository().DeleteByBoardId boardId
  165. boards_Repository().Delete boardId
  166. Dim flashDeleteOk : Set flashDeleteOk = Flash()
  167. flashDeleteOk.Success = "Board deleted."
  168. MVC.RedirectTo "Boards", "Index"
  169. End Sub
  170. Private Function GetCurrentUsername()
  171. Dim u : Set u = KeycloakCurrentUser()
  172. Dim name : name = ""
  173. If Not u Is Nothing Then
  174. On Error Resume Next
  175. name = CStr(u.Item("preferred_username"))
  176. If Err.Number <> 0 Then
  177. name = ""
  178. Err.Clear
  179. End If
  180. On Error GoTo 0
  181. End If
  182. GetCurrentUsername = name
  183. End Function
  184. Private Function JsonStr(s)
  185. Dim v : v = CStr(s)
  186. v = Replace(v, "\", "\\")
  187. v = Replace(v, """", "\""")
  188. v = Replace(v, vbCrLf, "\n")
  189. v = Replace(v, vbLf, "\n")
  190. v = Replace(v, vbCr, "\n")
  191. JsonStr = """" & v & """"
  192. End Function
  193. End Class
  194. Dim BoardsController_Class__Singleton
  195. Function BoardsController()
  196. If IsEmpty(BoardsController_Class__Singleton) Then
  197. Set BoardsController_Class__Singleton = New BoardsController_Class
  198. End If
  199. Set BoardsController = BoardsController_Class__Singleton
  200. End Function
  201. %>

Powered by TurnKey Linux.