|
- <%
- Class ColumnsController_Class
- Private m_useLayout
- Private m_title
-
- Private Sub Class_Initialize()
- m_useLayout = False
- m_title = "Columns"
- 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 /columns
- Public Sub Store()
- Response.ContentType = "application/json"
- If Not KeycloakIsLoggedIn() Then
- Response.Write "{""ok"":false,""error"":""Unauthorized""}"
- Exit Sub
- End If
-
- Dim boardId, colName
- boardId = CLng(Request.Form("board_id"))
- colName = Trim(CStr(Request.Form("name")))
-
- If boardId = 0 Or Len(colName) = 0 Then
- Response.Write "{""ok"":false,""error"":""board_id and name are required"",""debug_board_id_raw"":""" & Request.Form("board_id") & """,""debug_name_raw"":""" & Request.Form("name") & """,""debug_board_id_clng"":" & boardId & "}"
- Exit Sub
- End If
-
- Dim nextPos : nextPos = board_columns_Repository().MaxPosition(boardId) + 1
- Dim username : username = GetCurrentUsername()
-
- Dim col : Set col = New POBO_board_columns
- col.board_id = boardId
- col.name = colName
- col.position = nextPos
- col.created_at = Now()
- col.created_by = username
- col.updated_at = Now()
- col.updated_by = username
-
- board_columns_Repository().AddNew col
-
- Response.Write "{""ok"":true,""id"":" & col.id & ",""name"":" & JsonString(col.name) & ",""position"":" & col.position & "}"
- End Sub
-
- ' POST /columns/:id
- Public Sub Update(id)
- Response.ContentType = "application/json"
- If Not KeycloakIsLoggedIn() Then
- Response.Write "{""ok"":false,""error"":""Unauthorized""}"
- Exit Sub
- End If
-
- Dim colName : colName = Trim(CStr(Request.Form("name")))
- If Len(colName) = 0 Then
- Response.Write "{""ok"":false,""error"":""name is required""}"
- Exit Sub
- End If
-
- On Error Resume Next
- Dim col : Set col = board_columns_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
-
- col.name = colName
- col.updated_at = Now()
- col.updated_by = GetCurrentUsername()
- board_columns_Repository().Update col
-
- Response.Write "{""ok"":true}"
- End Sub
-
- ' POST /columns/: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 colId : colId = CLng(id)
- cards_Repository().DeleteByColumnId colId
- board_columns_Repository().Delete colId
-
- Response.Write "{""ok"":true}"
- End Sub
-
- ' POST /columns/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 parsed : Set parsed = JSON.parse(rawJson)
-
- If IsNull(parsed) Or IsEmpty(parsed) Then
- Response.Write "{""ok"":false,""error"":""Invalid JSON""}"
- Exit Sub
- End If
-
- Dim username : username = GetCurrentUsername()
- Dim i, item
- For i = 0 To parsed.Count - 1
- Set item = parsed.Item(i)
- board_columns_Repository().UpdatePosition CLng(item.Item("id")), CLng(item.Item("position")), Now(), username
- Next
-
- 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 ColumnsController_Class__Singleton
- Function ColumnsController()
- If IsEmpty(ColumnsController_Class__Singleton) Then
- Set ColumnsController_Class__Singleton = New ColumnsController_Class
- End If
- Set ColumnsController = ColumnsController_Class__Singleton
- End Function
- %>
|