Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

163 lignes
5.5KB

  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.position = nextPos
  39. card.created_at = Now()
  40. card.created_by = username
  41. card.updated_at = Now()
  42. card.updated_by = username
  43. cards_Repository().AddNew card
  44. Response.Write "{""ok"":true,""id"":" & card.id & "," & _
  45. """job_number"":" & JsonString(card.job_number) & "," & _
  46. """job_name"":" & JsonString(card.job_name) & "," & _
  47. """column_id"":" & card.column_id & "," & _
  48. """swim_lane_id"":" & card.swim_lane_id & "," & _
  49. """position"":" & card.position & "}"
  50. End Sub
  51. ' POST /cards/:id
  52. Public Sub Update(id)
  53. Response.ContentType = "application/json"
  54. If Not KeycloakIsLoggedIn() Then
  55. Response.Write "{""ok"":false,""error"":""Unauthorized""}"
  56. Exit Sub
  57. End If
  58. On Error Resume Next
  59. Dim card : Set card = cards_Repository().FindByID(CLng(id))
  60. If Err.Number <> 0 Then
  61. Err.Clear
  62. Response.Write "{""ok"":false,""error"":""Not found""}"
  63. Exit Sub
  64. End If
  65. On Error GoTo 0
  66. card.job_number = Trim(CStr(Request.Form("job_number")))
  67. card.job_name = Trim(CStr(Request.Form("job_name")))
  68. card.updated_at = Now()
  69. card.updated_by = GetCurrentUsername()
  70. cards_Repository().Update card
  71. Response.Write "{""ok"":true," & _
  72. """job_number"":" & JsonString(card.job_number) & "," & _
  73. """job_name"":" & JsonString(card.job_name) & "}"
  74. End Sub
  75. ' POST /cards/:id/move — form: column_id, swim_lane_id, position, [sibling_ids CSV for reorder]
  76. Public Sub Move(id)
  77. Response.ContentType = "application/json"
  78. If Not KeycloakIsLoggedIn() Then
  79. Response.Write "{""ok"":false,""error"":""Unauthorized""}"
  80. Exit Sub
  81. End If
  82. Dim columnId, swimLaneId, position
  83. columnId = CLng(Request.Form("column_id"))
  84. swimLaneId = CLng(Request.Form("swim_lane_id"))
  85. position = CLng(Request.Form("position"))
  86. Dim username : username = GetCurrentUsername()
  87. cards_Repository().Move CLng(id), columnId, swimLaneId, position, Now(), username
  88. ' Reorder siblings if provided
  89. Dim siblings : siblings = Trim(CStr(Request.Form("sibling_ids")))
  90. If Len(siblings) > 0 Then
  91. Dim ids, idx
  92. ids = Split(siblings, ",")
  93. For idx = 0 To UBound(ids)
  94. Dim sibId : sibId = CLng(Trim(ids(idx)))
  95. If sibId > 0 Then
  96. cards_Repository().UpdatePosition sibId, idx, Now(), username
  97. End If
  98. Next
  99. End If
  100. Response.Write "{""ok"":true}"
  101. End Sub
  102. ' POST /cards/:id/delete
  103. Public Sub Destroy(id)
  104. Response.ContentType = "application/json"
  105. If Not KeycloakIsLoggedIn() Then
  106. Response.Write "{""ok"":false,""error"":""Unauthorized""}"
  107. Exit Sub
  108. End If
  109. cards_Repository().Delete CLng(id)
  110. Response.Write "{""ok"":true}"
  111. End Sub
  112. Private Function GetCurrentUsername()
  113. Dim u : Set u = KeycloakCurrentUser()
  114. Dim name : name = ""
  115. If Not u Is Nothing Then
  116. On Error Resume Next
  117. name = CStr(u.Item("preferred_username"))
  118. If Err.Number <> 0 Then
  119. name = ""
  120. Err.Clear
  121. End If
  122. On Error GoTo 0
  123. End If
  124. GetCurrentUsername = name
  125. End Function
  126. Private Function JsonString(s)
  127. JsonString = """" & Replace(Replace(CStr(s), "\", "\\"), """", "\""") & """"
  128. End Function
  129. End Class
  130. Dim CardsController_Class__Singleton
  131. Function CardsController()
  132. If IsEmpty(CardsController_Class__Singleton) Then
  133. Set CardsController_Class__Singleton = New CardsController_Class
  134. End If
  135. Set CardsController = CardsController_Class__Singleton
  136. End Function
  137. %>

Powered by TurnKey Linux.