Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

266 строки
8.9KB

  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.import_from_printstream = (Request.Form("import_from_printstream") = "on")
  47. board.printstream_job_name = Trim(CStr(Request.Form("printstream_job_name")))
  48. board.created_at = Now()
  49. board.created_by = currentUsername
  50. board.updated_at = Now()
  51. board.updated_by = currentUsername
  52. boards_Repository().AddNew board
  53. Dim flashCreateOk : Set flashCreateOk = Flash()
  54. flashCreateOk.Success = "Board created."
  55. Response.Redirect "/board/" & board.slug
  56. End Sub
  57. ' GET /board/:slug
  58. Public Sub Show(slug)
  59. If Not KeycloakRequireLogin("") Then Exit Sub
  60. m_useLayout = False
  61. Dim board : Set board = boards_Repository().FindBySlug(slug)
  62. If board Is Nothing Then
  63. Response.Status = "404 Not Found"
  64. Response.Write "Board not found."
  65. Exit Sub
  66. End If
  67. m_title = board.name
  68. Dim columns : Set columns = board_columns_Repository().FindByBoardId(board.id)
  69. Dim lanes : Set lanes = swim_lanes_Repository().FindByBoardId(board.id)
  70. Dim allCards : Set allCards = cards_Repository().FindByBoardId(board.id)
  71. ' Build arrays for the view (functions cannot be defined inside a view include)
  72. Dim colCount : colCount = columns.Count
  73. Dim laneCount : laneCount = lanes.Count
  74. Dim colsArr() : ReDim colsArr(IIf(colCount > 0, colCount - 1, 0))
  75. Dim lanesArr() : ReDim lanesArr(IIf(laneCount > 0, laneCount - 1, 0))
  76. Dim colIdx, laneIdx, colIter, laneIter, colItem, laneItem
  77. colIdx = 0
  78. Set colIter = columns.Iterator()
  79. Do While colIter.HasNext()
  80. Set colsArr(colIdx) = colIter.GetNext()
  81. colIdx = colIdx + 1
  82. Loop
  83. laneIdx = 0
  84. Set laneIter = lanes.Iterator()
  85. Do While laneIter.HasNext()
  86. Set lanesArr(laneIdx) = laneIter.GetNext()
  87. laneIdx = laneIdx + 1
  88. Loop
  89. ' Serialise cards to JSON
  90. Dim cardsJson : cardsJson = "["
  91. Dim firstCard : firstCard = True
  92. Dim cardIter, cardItem
  93. Set cardIter = allCards.Iterator()
  94. Do While cardIter.HasNext()
  95. Set cardItem = cardIter.GetNext()
  96. If Not firstCard Then cardsJson = cardsJson & ","
  97. cardsJson = cardsJson & "{""id"":" & cardItem.id & "," & _
  98. """column_id"":" & cardItem.column_id & "," & _
  99. """swim_lane_id"":" & cardItem.swim_lane_id & "," & _
  100. """job_number"":" & JsonStr(cardItem.job_number) & "," & _
  101. """job_name"":" & JsonStr(cardItem.job_name) & "," & _
  102. """customer_name"":" & JsonStr(cardItem.customer_name) & "," & _
  103. """delivery_date"":" & JsonDateStr(cardItem.delivery_date) & "," & _
  104. """quantity"":" & JsonStr(cardItem.quantity) & "," & _
  105. """notes"":" & JsonStr(cardItem.notes) & "," & _
  106. """full_note"":" & JsonStr(cardItem.full_note) & "," & _
  107. """position"":" & cardItem.position & "}"
  108. firstCard = False
  109. Loop
  110. cardsJson = cardsJson & "]"
  111. %>
  112. <!--#include file="../views/Boards/Show.asp" -->
  113. <%
  114. Set board = Nothing
  115. Set columns = Nothing
  116. Set lanes = Nothing
  117. Set allCards = Nothing
  118. End Sub
  119. ' GET /board/:slug/edit
  120. Public Sub Edit(slug)
  121. If Not KeycloakRequireLogin("") Then Exit Sub
  122. m_title = "Edit Board"
  123. Dim board : Set board = boards_Repository().FindBySlug(slug)
  124. If board Is Nothing Then
  125. Response.Status = "404 Not Found"
  126. Response.Write "Board not found."
  127. Exit Sub
  128. End If
  129. %>
  130. <!--#include file="../views/Boards/Edit.asp" -->
  131. <%
  132. Set board = Nothing
  133. End Sub
  134. ' POST /board/:slug/update
  135. Public Sub Update(slug)
  136. If Not KeycloakRequireLogin("") Then Exit Sub
  137. Dim board : Set board = boards_Repository().FindBySlug(slug)
  138. If board Is Nothing Then
  139. Response.Status = "404 Not Found"
  140. Response.Write "Board not found."
  141. Exit Sub
  142. End If
  143. Dim newName : newName = Trim(CStr(Request.Form("name")))
  144. If Len(newName) = 0 Then
  145. Dim flashUpdateErr : Set flashUpdateErr = Flash()
  146. flashUpdateErr.AddError "Board name is required."
  147. Response.Redirect "/board/" & slug & "/edit"
  148. Exit Sub
  149. End If
  150. Dim newSlug : newSlug = boards_Repository().UniqueSlug(GenerateSlug(newName), CLng(board.id))
  151. board.name = newName
  152. board.slug = newSlug
  153. board.import_from_printstream = (Request.Form("import_from_printstream") = "on")
  154. board.printstream_job_name = Trim(CStr(Request.Form("printstream_job_name")))
  155. board.updated_at = Now()
  156. board.updated_by = GetCurrentUsername()
  157. boards_Repository().Update board
  158. Dim flashUpdateOk : Set flashUpdateOk = Flash()
  159. flashUpdateOk.Success = "Board updated."
  160. Response.Redirect "/board/" & newSlug
  161. End Sub
  162. ' POST /board/:slug/delete
  163. Public Sub Destroy(slug)
  164. If Not KeycloakRequireLogin("") Then Exit Sub
  165. Dim board : Set board = boards_Repository().FindBySlug(slug)
  166. If board Is Nothing Then
  167. Response.Redirect "/boards"
  168. Exit Sub
  169. End If
  170. Dim boardId : boardId = CLng(board.id)
  171. cards_Repository().DeleteByBoardId boardId
  172. board_columns_Repository().DeleteByBoardId boardId
  173. swim_lanes_Repository().DeleteByBoardId boardId
  174. boards_Repository().Delete boardId
  175. Dim flashDeleteOk : Set flashDeleteOk = Flash()
  176. flashDeleteOk.Success = "Board deleted."
  177. MVC.RedirectTo "Boards", "Index"
  178. End Sub
  179. Private Function GetCurrentUsername()
  180. Dim u : Set u = KeycloakCurrentUser()
  181. Dim name : name = ""
  182. If Not u Is Nothing Then
  183. On Error Resume Next
  184. name = CStr(u.Item("preferred_username"))
  185. If Err.Number <> 0 Then
  186. name = ""
  187. Err.Clear
  188. End If
  189. On Error GoTo 0
  190. End If
  191. GetCurrentUsername = name
  192. End Function
  193. Private Function JsonStr(s)
  194. Dim v : v = CStr(s)
  195. v = Replace(v, "\", "\\")
  196. v = Replace(v, """", "\""")
  197. v = Replace(v, vbCrLf, "\n")
  198. v = Replace(v, vbLf, "\n")
  199. v = Replace(v, vbCr, "\n")
  200. JsonStr = """" & v & """"
  201. End Function
  202. Private Function JsonDateStr(d)
  203. If IsNull(d) Or IsEmpty(d) Then
  204. JsonDateStr = "null"
  205. Exit Function
  206. End If
  207. On Error Resume Next
  208. Dim dt, s
  209. dt = CDate(d)
  210. s = Year(dt) & "-" & Right("0" & Month(dt), 2) & "-" & Right("0" & Day(dt), 2)
  211. If Err.Number <> 0 Then
  212. Err.Clear
  213. JsonDateStr = "null"
  214. Else
  215. JsonDateStr = """" & s & """"
  216. End If
  217. On Error GoTo 0
  218. End Function
  219. End Class
  220. Dim BoardsController_Class__Singleton
  221. Function BoardsController()
  222. If IsEmpty(BoardsController_Class__Singleton) Then
  223. Set BoardsController_Class__Singleton = New BoardsController_Class
  224. End If
  225. Set BoardsController = BoardsController_Class__Singleton
  226. End Function
  227. %>

Powered by TurnKey Linux.