You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
4.8KB

  1. <%
  2. Class SwimLanesController_Class
  3. Private m_useLayout
  4. Private m_title
  5. Private Sub Class_Initialize()
  6. m_useLayout = False
  7. m_title = "Swim Lanes"
  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 /swimlanes
  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, laneName
  21. boardId = CLng(Request.Form("board_id"))
  22. laneName = Trim(CStr(Request.Form("name")))
  23. If boardId = 0 Or Len(laneName) = 0 Then
  24. Response.Write "{""ok"":false,""error"":""board_id and name are required""}"
  25. Exit Sub
  26. End If
  27. Dim nextPos : nextPos = swim_lanes_Repository().MaxPosition(boardId) + 1
  28. Dim username : username = GetCurrentUsername()
  29. Dim lane : Set lane = New POBO_swim_lanes
  30. lane.board_id = boardId
  31. lane.name = laneName
  32. lane.position = nextPos
  33. lane.created_at = Now()
  34. lane.created_by = username
  35. lane.updated_at = Now()
  36. lane.updated_by = username
  37. swim_lanes_Repository().AddNew lane
  38. Response.Write "{""ok"":true,""id"":" & lane.id & ",""name"":" & JsonString(lane.name) & ",""position"":" & lane.position & "}"
  39. End Sub
  40. ' POST /swimlanes/:id
  41. Public Sub Update(id)
  42. Response.ContentType = "application/json"
  43. If Not KeycloakIsLoggedIn() Then
  44. Response.Write "{""ok"":false,""error"":""Unauthorized""}"
  45. Exit Sub
  46. End If
  47. Dim laneName : laneName = Trim(CStr(Request.Form("name")))
  48. If Len(laneName) = 0 Then
  49. Response.Write "{""ok"":false,""error"":""name is required""}"
  50. Exit Sub
  51. End If
  52. On Error Resume Next
  53. Dim lane : Set lane = swim_lanes_Repository().FindByID(CLng(id))
  54. If Err.Number <> 0 Then
  55. Err.Clear
  56. Response.Write "{""ok"":false,""error"":""Not found""}"
  57. Exit Sub
  58. End If
  59. On Error GoTo 0
  60. lane.name = laneName
  61. lane.updated_at = Now()
  62. lane.updated_by = GetCurrentUsername()
  63. swim_lanes_Repository().Update lane
  64. Response.Write "{""ok"":true}"
  65. End Sub
  66. ' POST /swimlanes/:id/delete
  67. Public Sub Destroy(id)
  68. Response.ContentType = "application/json"
  69. If Not KeycloakIsLoggedIn() Then
  70. Response.Write "{""ok"":false,""error"":""Unauthorized""}"
  71. Exit Sub
  72. End If
  73. Dim laneId : laneId = CLng(id)
  74. cards_Repository().DeleteBySwimLaneId laneId
  75. swim_lanes_Repository().Delete laneId
  76. Response.Write "{""ok"":true}"
  77. End Sub
  78. ' POST /swimlanes/reorder — body: JSON array [{id:1,position:0},{id:2,position:1},...]
  79. Public Sub Reorder()
  80. Response.ContentType = "application/json"
  81. If Not KeycloakIsLoggedIn() Then
  82. Response.Write "{""ok"":false,""error"":""Unauthorized""}"
  83. Exit Sub
  84. End If
  85. Dim rawJson : rawJson = GetRawJsonFromRequest()
  86. Dim parsed : Set parsed = JSON.parse(rawJson)
  87. If IsNull(parsed) Or IsEmpty(parsed) Then
  88. Response.Write "{""ok"":false,""error"":""Invalid JSON""}"
  89. Exit Sub
  90. End If
  91. Dim username : username = GetCurrentUsername()
  92. Dim i, item
  93. For i = 0 To parsed.Count - 1
  94. Set item = parsed.Item(i)
  95. swim_lanes_Repository().UpdatePosition CLng(item.Item("id")), CLng(item.Item("position")), Now(), username
  96. Next
  97. Response.Write "{""ok"":true}"
  98. End Sub
  99. Private Function GetCurrentUsername()
  100. Dim u : Set u = KeycloakCurrentUser()
  101. Dim name : name = ""
  102. If Not u Is Nothing Then
  103. On Error Resume Next
  104. name = CStr(u.Item("preferred_username"))
  105. If Err.Number <> 0 Then
  106. name = ""
  107. Err.Clear
  108. End If
  109. On Error GoTo 0
  110. End If
  111. GetCurrentUsername = name
  112. End Function
  113. Private Function JsonString(s)
  114. JsonString = """" & Replace(Replace(CStr(s), "\", "\\"), """", "\""") & """"
  115. End Function
  116. End Class
  117. Dim SwimLanesController_Class__Singleton
  118. Function SwimLanesController()
  119. If IsEmpty(SwimLanesController_Class__Singleton) Then
  120. Set SwimLanesController_Class__Singleton = New SwimLanesController_Class
  121. End If
  122. Set SwimLanesController = SwimLanesController_Class__Singleton
  123. End Function
  124. %>

Powered by TurnKey Linux.