|
- <%
- Class SwimLanesController_Class
- Private m_useLayout
- Private m_title
-
- Private Sub Class_Initialize()
- m_useLayout = False
- m_title = "Swim Lanes"
- End Sub
-
- Public Property Get useLayout() : useLayout = m_useLayout : End Property
- Public Property Let useLayout(v) : m_useLayout = v : End Property
- Public Property Get Title() : Title = m_title : End Property
- Public Property Let Title(v) : m_title = v : End Property
-
- ' POST /swimlanes
- Public Sub Store()
- Response.ContentType = "application/json"
- If Not KeycloakIsLoggedIn() Then
- Response.Write "{""ok"":false,""error"":""Unauthorized""}"
- Exit Sub
- End If
-
- Dim boardId, laneName
- boardId = CLng(Request.Form("board_id"))
- laneName = Trim(CStr(Request.Form("name")))
-
- If boardId = 0 Or Len(laneName) = 0 Then
- Response.Write "{""ok"":false,""error"":""board_id and name are required""}"
- Exit Sub
- End If
-
- Dim nextPos : nextPos = swim_lanes_Repository().MaxPosition(boardId) + 1
- Dim username : username = GetCurrentUsername()
-
- Dim lane : Set lane = New POBO_swim_lanes
- lane.board_id = boardId
- lane.name = laneName
- lane.position = nextPos
- lane.created_at = Now()
- lane.created_by = username
- lane.updated_at = Now()
- lane.updated_by = username
-
- swim_lanes_Repository().AddNew lane
-
- Response.Write "{""ok"":true,""id"":" & lane.id & ",""name"":" & JsonString(lane.name) & ",""position"":" & lane.position & "}"
- End Sub
-
- ' POST /swimlanes/:id
- Public Sub Update(id)
- Response.ContentType = "application/json"
- If Not KeycloakIsLoggedIn() Then
- Response.Write "{""ok"":false,""error"":""Unauthorized""}"
- Exit Sub
- End If
-
- Dim laneName : laneName = Trim(CStr(Request.Form("name")))
- If Len(laneName) = 0 Then
- Response.Write "{""ok"":false,""error"":""name is required""}"
- Exit Sub
- End If
-
- On Error Resume Next
- Dim lane : Set lane = swim_lanes_Repository().FindByID(CLng(id))
- If Err.Number <> 0 Then
- Err.Clear
- Response.Write "{""ok"":false,""error"":""Not found""}"
- Exit Sub
- End If
- On Error GoTo 0
-
- lane.name = laneName
- lane.updated_at = Now()
- lane.updated_by = GetCurrentUsername()
- swim_lanes_Repository().Update lane
-
- Response.Write "{""ok"":true}"
- End Sub
-
- ' POST /swimlanes/:id/delete
- Public Sub Destroy(id)
- Response.ContentType = "application/json"
- If Not KeycloakIsLoggedIn() Then
- Response.Write "{""ok"":false,""error"":""Unauthorized""}"
- Exit Sub
- End If
-
- Dim laneId : laneId = CLng(id)
- cards_Repository().DeleteBySwimLaneId laneId
- swim_lanes_Repository().Delete laneId
-
- Response.Write "{""ok"":true}"
- End Sub
-
- ' POST /swimlanes/reorder — body: JSON array [{id:1,position:0},{id:2,position:1},...]
- Public Sub Reorder()
- Response.ContentType = "application/json"
- If Not KeycloakIsLoggedIn() Then
- Response.Write "{""ok"":false,""error"":""Unauthorized""}"
- Exit Sub
- End If
-
- Dim rawJson : rawJson = GetRawJsonFromRequest()
- Dim parser : Set parser = New aspJSON
- Dim parsed
-
- On Error Resume Next
- parser.loadJSON rawJson
- If Err.Number <> 0 Then
- Err.Clear
- Set parser = Nothing
- Response.Write "{""ok"":false,""error"":""Invalid JSON payload""}"
- Exit Sub
- End If
- Set parsed = parser.data
- On Error GoTo 0
-
- If parsed Is Nothing Or parsed.Count = 0 Then
- Set parser = Nothing
- Response.Write "{""ok"":false,""error"":""Invalid JSON payload""}"
- Exit Sub
- End If
-
- Dim username : username = GetCurrentUsername()
- Dim i, item
- On Error Resume Next
- For i = 0 To parsed.Count - 1
- Set item = parsed.Item(i)
- swim_lanes_Repository().UpdatePosition CLng(item.Item("id")), CLng(item.Item("position")), Now(), username
- If Err.Number <> 0 Then
- Err.Clear
- On Error GoTo 0
- Set parser = Nothing
- Response.Write "{""ok"":false,""error"":""Invalid reorder item at index " & i & """}"
- Exit Sub
- End If
- Next
- On Error GoTo 0
- Set parser = Nothing
-
- Response.Write "{""ok"":true}"
- End Sub
-
- Private Function GetCurrentUsername()
- Dim u : Set u = KeycloakCurrentUser()
- Dim name : name = ""
- If Not u Is Nothing Then
- On Error Resume Next
- name = CStr(u.Item("preferred_username"))
- If Err.Number <> 0 Then
- name = ""
- Err.Clear
- End If
- On Error GoTo 0
- End If
- GetCurrentUsername = name
- End Function
-
- Private Function JsonString(s)
- JsonString = """" & Replace(Replace(CStr(s), "\", "\\"), """", "\""") & """"
- End Function
-
- End Class
-
- Dim SwimLanesController_Class__Singleton
- Function SwimLanesController()
- If IsEmpty(SwimLanesController_Class__Singleton) Then
- Set SwimLanesController_Class__Singleton = New SwimLanesController_Class
- End If
- Set SwimLanesController = SwimLanesController_Class__Singleton
- End Function
- %>
|