Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

221 lines
8.0KB

  1. <%
  2. Class CardsController_Class
  3. Private m_useLayout
  4. Private m_title
  5. Private Sub Class_Initialize()
  6. m_useLayout = False
  7. m_title = "Cards"
  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. ' POST /cards
  14. Public Sub Store()
  15. Response.ContentType = "application/json"
  16. If Not KeycloakIsLoggedIn() Then
  17. Response.Write "{""ok"":false,""error"":""Unauthorized""}"
  18. Exit Sub
  19. End If
  20. Dim boardId, columnId, swimLaneId, jobNum, jobName
  21. boardId = CLng(Request.Form("board_id"))
  22. columnId = CLng(Request.Form("column_id"))
  23. swimLaneId = CLng(Request.Form("swim_lane_id"))
  24. jobNum = Trim(CStr(Request.Form("job_number")))
  25. jobName = Trim(CStr(Request.Form("job_name")))
  26. If boardId = 0 Or columnId = 0 Or swimLaneId = 0 Then
  27. Response.Write "{""ok"":false,""error"":""board_id, column_id, and swim_lane_id are required""}"
  28. Exit Sub
  29. End If
  30. Dim nextPos : nextPos = cards_Repository().MaxPosition(columnId, swimLaneId) + 1
  31. Dim username : username = GetCurrentUsername()
  32. Dim card : Set card = New POBO_cards
  33. card.board_id = boardId
  34. card.column_id = columnId
  35. card.swim_lane_id = swimLaneId
  36. card.job_number = jobNum
  37. card.job_name = jobName
  38. card.customer_name = Trim(CStr(Request.Form("customer_name") & ""))
  39. card.delivery_date = Trim(CStr(Request.Form("delivery_date") & ""))
  40. card.quantity = Trim(CStr(Request.Form("quantity") & ""))
  41. card.notes = Trim(CStr(Request.Form("notes") & ""))
  42. card.full_note = CStr(Request.Form("full_note") & "")
  43. card.position = nextPos
  44. card.created_at = Now()
  45. card.created_by = username
  46. card.updated_at = Now()
  47. card.updated_by = username
  48. On Error Resume Next
  49. cards_Repository().AddNew card
  50. If Err.Number <> 0 Then
  51. Response.Write "{""ok"":false,""error"":" & JsonString(Err.Description) & "}"
  52. Err.Clear
  53. Exit Sub
  54. End If
  55. On Error GoTo 0
  56. Response.Write "{""ok"":true,""id"":" & card.id & "," & _
  57. """job_number"":" & JsonString(card.job_number) & "," & _
  58. """job_name"":" & JsonString(card.job_name) & "," & _
  59. """customer_name"":" & JsonString(card.customer_name) & "," & _
  60. """delivery_date"":" & JsonDateStr(card.delivery_date) & "," & _
  61. """quantity"":" & JsonString(card.quantity) & "," & _
  62. """notes"":" & JsonString(card.notes) & "," & _
  63. """full_note"":" & JsonString(card.full_note) & "," & _
  64. """column_id"":" & card.column_id & "," & _
  65. """swim_lane_id"":" & card.swim_lane_id & "," & _
  66. """position"":" & card.position & "}"
  67. End Sub
  68. ' POST /cards/:id
  69. Public Sub Update(id)
  70. Response.ContentType = "application/json"
  71. If Not KeycloakIsLoggedIn() Then
  72. Response.Write "{""ok"":false,""error"":""Unauthorized""}"
  73. Exit Sub
  74. End If
  75. On Error Resume Next
  76. Dim card : Set card = cards_Repository().FindByID(CLng(id))
  77. If Err.Number <> 0 Then
  78. Err.Clear
  79. Response.Write "{""ok"":false,""error"":""Not found""}"
  80. Exit Sub
  81. End If
  82. On Error GoTo 0
  83. card.job_number = Trim(CStr(Request.Form("job_number")))
  84. card.job_name = Trim(CStr(Request.Form("job_name")))
  85. card.customer_name = Trim(CStr(Request.Form("customer_name") & ""))
  86. card.delivery_date = Trim(CStr(Request.Form("delivery_date") & ""))
  87. card.quantity = Trim(CStr(Request.Form("quantity") & ""))
  88. card.notes = Trim(CStr(Request.Form("notes") & ""))
  89. card.full_note = CStr(Request.Form("full_note") & "")
  90. card.updated_at = Now()
  91. card.updated_by = GetCurrentUsername()
  92. On Error Resume Next
  93. cards_Repository().Update card
  94. If Err.Number <> 0 Then
  95. Response.Write "{""ok"":false,""error"":" & JsonString(Err.Description) & "}"
  96. Err.Clear
  97. Exit Sub
  98. End If
  99. On Error GoTo 0
  100. Response.Write "{""ok"":true," & _
  101. """job_number"":" & JsonString(card.job_number) & "," & _
  102. """job_name"":" & JsonString(card.job_name) & "," & _
  103. """customer_name"":" & JsonString(card.customer_name) & "," & _
  104. """delivery_date"":" & JsonDateStr(card.delivery_date) & "," & _
  105. """quantity"":" & JsonString(card.quantity) & "," & _
  106. """notes"":" & JsonString(card.notes) & "," & _
  107. """full_note"":" & JsonString(card.full_note) & "}"
  108. End Sub
  109. ' POST /cards/:id/move — form: column_id, swim_lane_id, position, [sibling_ids CSV for reorder]
  110. Public Sub Move(id)
  111. Response.ContentType = "application/json"
  112. If Not KeycloakIsLoggedIn() Then
  113. Response.Write "{""ok"":false,""error"":""Unauthorized""}"
  114. Exit Sub
  115. End If
  116. Dim columnId, swimLaneId, position
  117. columnId = CLng(Request.Form("column_id"))
  118. swimLaneId = CLng(Request.Form("swim_lane_id"))
  119. position = CLng(Request.Form("position"))
  120. Dim username : username = GetCurrentUsername()
  121. cards_Repository().Move CLng(id), columnId, swimLaneId, position, Now(), username
  122. ' Reorder siblings if provided
  123. Dim siblings : siblings = Trim(CStr(Request.Form("sibling_ids")))
  124. If Len(siblings) > 0 Then
  125. Dim ids, idx
  126. ids = Split(siblings, ",")
  127. For idx = 0 To UBound(ids)
  128. Dim sibId : sibId = CLng(Trim(ids(idx)))
  129. If sibId > 0 Then
  130. cards_Repository().UpdatePosition sibId, idx, Now(), username
  131. End If
  132. Next
  133. End If
  134. Response.Write "{""ok"":true}"
  135. End Sub
  136. ' POST /cards/:id/delete
  137. Public Sub Destroy(id)
  138. Response.ContentType = "application/json"
  139. If Not KeycloakIsLoggedIn() Then
  140. Response.Write "{""ok"":false,""error"":""Unauthorized""}"
  141. Exit Sub
  142. End If
  143. cards_Repository().Delete CLng(id)
  144. Response.Write "{""ok"":true}"
  145. End Sub
  146. Private Function GetCurrentUsername()
  147. Dim u : Set u = KeycloakCurrentUser()
  148. Dim name : name = ""
  149. If Not u Is Nothing Then
  150. On Error Resume Next
  151. name = CStr(u.Item("preferred_username"))
  152. If Err.Number <> 0 Then
  153. name = ""
  154. Err.Clear
  155. End If
  156. On Error GoTo 0
  157. End If
  158. GetCurrentUsername = name
  159. End Function
  160. Private Function JsonString(s)
  161. Dim v : v = CStr(s & "")
  162. v = Replace(v, "\", "\\")
  163. v = Replace(v, """", "\""")
  164. v = Replace(v, vbCrLf, "\n")
  165. v = Replace(v, vbLf, "\n")
  166. v = Replace(v, vbCr, "\n")
  167. JsonString = """" & v & """"
  168. End Function
  169. Private Function JsonDateStr(d)
  170. If IsNull(d) Or IsEmpty(d) Then
  171. JsonDateStr = "null"
  172. Exit Function
  173. End If
  174. On Error Resume Next
  175. Dim dt, s
  176. dt = CDate(d)
  177. s = Year(dt) & "-" & Right("0" & Month(dt), 2) & "-" & Right("0" & Day(dt), 2)
  178. If Err.Number <> 0 Then
  179. Err.Clear
  180. JsonDateStr = "null"
  181. Else
  182. JsonDateStr = """" & s & """"
  183. End If
  184. On Error GoTo 0
  185. End Function
  186. End Class
  187. Dim CardsController_Class__Singleton
  188. Function CardsController()
  189. If IsEmpty(CardsController_Class__Singleton) Then
  190. Set CardsController_Class__Singleton = New CardsController_Class
  191. End If
  192. Set CardsController = CardsController_Class__Singleton
  193. End Function
  194. %>

Powered by TurnKey Linux.