Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

151 řádky
4.9KB

  1. <%
  2. Class ColumnsController_Class
  3. Private m_useLayout
  4. Private m_title
  5. Private Sub Class_Initialize()
  6. m_useLayout = False
  7. m_title = "Columns"
  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 /columns
  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, colName
  21. boardId = CLng(Request.Form("board_id"))
  22. colName = Trim(CStr(Request.Form("name")))
  23. If boardId = 0 Or Len(colName) = 0 Then
  24. 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 & "}"
  25. Exit Sub
  26. End If
  27. Dim nextPos : nextPos = board_columns_Repository().MaxPosition(boardId) + 1
  28. Dim username : username = GetCurrentUsername()
  29. Dim col : Set col = New POBO_board_columns
  30. col.board_id = boardId
  31. col.name = colName
  32. col.position = nextPos
  33. col.created_at = Now()
  34. col.created_by = username
  35. col.updated_at = Now()
  36. col.updated_by = username
  37. board_columns_Repository().AddNew col
  38. Response.Write "{""ok"":true,""id"":" & col.id & ",""name"":" & JsonString(col.name) & ",""position"":" & col.position & "}"
  39. End Sub
  40. ' POST /columns/: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 colName : colName = Trim(CStr(Request.Form("name")))
  48. If Len(colName) = 0 Then
  49. Response.Write "{""ok"":false,""error"":""name is required""}"
  50. Exit Sub
  51. End If
  52. On Error Resume Next
  53. Dim col : Set col = board_columns_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. col.name = colName
  61. col.updated_at = Now()
  62. col.updated_by = GetCurrentUsername()
  63. board_columns_Repository().Update col
  64. Response.Write "{""ok"":true}"
  65. End Sub
  66. ' POST /columns/: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 colId : colId = CLng(id)
  74. cards_Repository().DeleteByColumnId colId
  75. board_columns_Repository().Delete colId
  76. Response.Write "{""ok"":true}"
  77. End Sub
  78. ' POST /columns/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. board_columns_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 ColumnsController_Class__Singleton
  118. Function ColumnsController()
  119. If IsEmpty(ColumnsController_Class__Singleton) Then
  120. Set ColumnsController_Class__Singleton = New ColumnsController_Class
  121. End If
  122. Set ColumnsController = ColumnsController_Class__Singleton
  123. End Function
  124. %>

Powered by TurnKey Linux.