|
- <%
- Class CardsController_Class
- Private m_useLayout
- Private m_title
-
- Private Sub Class_Initialize()
- m_useLayout = False
- m_title = "Cards"
- 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 /cards
- Public Sub Store()
- Response.ContentType = "application/json"
- If Not KeycloakIsLoggedIn() Then
- Response.Write "{""ok"":false,""error"":""Unauthorized""}"
- Exit Sub
- End If
-
- Dim boardId, columnId, swimLaneId, jobNum, jobName
- boardId = CLng(Request.Form("board_id"))
- columnId = CLng(Request.Form("column_id"))
- swimLaneId = CLng(Request.Form("swim_lane_id"))
- jobNum = Trim(CStr(Request.Form("job_number")))
- jobName = Trim(CStr(Request.Form("job_name")))
-
- If boardId = 0 Or columnId = 0 Or swimLaneId = 0 Then
- Response.Write "{""ok"":false,""error"":""board_id, column_id, and swim_lane_id are required""}"
- Exit Sub
- End If
-
- Dim nextPos : nextPos = cards_Repository().MaxPosition(columnId, swimLaneId) + 1
- Dim username : username = GetCurrentUsername()
-
- Dim card : Set card = New POBO_cards
- card.board_id = boardId
- card.column_id = columnId
- card.swim_lane_id = swimLaneId
- card.job_number = jobNum
- card.job_name = jobName
- card.position = nextPos
- card.created_at = Now()
- card.created_by = username
- card.updated_at = Now()
- card.updated_by = username
-
- cards_Repository().AddNew card
-
- Response.Write "{""ok"":true,""id"":" & card.id & "," & _
- """job_number"":" & JsonString(card.job_number) & "," & _
- """job_name"":" & JsonString(card.job_name) & "," & _
- """column_id"":" & card.column_id & "," & _
- """swim_lane_id"":" & card.swim_lane_id & "," & _
- """position"":" & card.position & "}"
- End Sub
-
- ' POST /cards/:id
- Public Sub Update(id)
- Response.ContentType = "application/json"
- If Not KeycloakIsLoggedIn() Then
- Response.Write "{""ok"":false,""error"":""Unauthorized""}"
- Exit Sub
- End If
-
- On Error Resume Next
- Dim card : Set card = cards_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
-
- card.job_number = Trim(CStr(Request.Form("job_number")))
- card.job_name = Trim(CStr(Request.Form("job_name")))
- card.updated_at = Now()
- card.updated_by = GetCurrentUsername()
-
- cards_Repository().Update card
-
- Response.Write "{""ok"":true," & _
- """job_number"":" & JsonString(card.job_number) & "," & _
- """job_name"":" & JsonString(card.job_name) & "}"
- End Sub
-
- ' POST /cards/:id/move — form: column_id, swim_lane_id, position, [sibling_ids CSV for reorder]
- Public Sub Move(id)
- Response.ContentType = "application/json"
- If Not KeycloakIsLoggedIn() Then
- Response.Write "{""ok"":false,""error"":""Unauthorized""}"
- Exit Sub
- End If
-
- Dim columnId, swimLaneId, position
- columnId = CLng(Request.Form("column_id"))
- swimLaneId = CLng(Request.Form("swim_lane_id"))
- position = CLng(Request.Form("position"))
-
- Dim username : username = GetCurrentUsername()
- cards_Repository().Move CLng(id), columnId, swimLaneId, position, Now(), username
-
- ' Reorder siblings if provided
- Dim siblings : siblings = Trim(CStr(Request.Form("sibling_ids")))
- If Len(siblings) > 0 Then
- Dim ids, idx
- ids = Split(siblings, ",")
- For idx = 0 To UBound(ids)
- Dim sibId : sibId = CLng(Trim(ids(idx)))
- If sibId > 0 Then
- cards_Repository().UpdatePosition sibId, idx, Now(), username
- End If
- Next
- End If
-
- Response.Write "{""ok"":true}"
- End Sub
-
- ' POST /cards/:id/delete
- Public Sub Destroy(id)
- Response.ContentType = "application/json"
- If Not KeycloakIsLoggedIn() Then
- Response.Write "{""ok"":false,""error"":""Unauthorized""}"
- Exit Sub
- End If
-
- cards_Repository().Delete CLng(id)
- 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 CardsController_Class__Singleton
- Function CardsController()
- If IsEmpty(CardsController_Class__Singleton) Then
- Set CardsController_Class__Singleton = New CardsController_Class
- End If
- Set CardsController = CardsController_Class__Singleton
- End Function
- %>
|