選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

174 行
5.6KB

  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 parser : Set parser = New aspJSON
  87. Dim parsed
  88. On Error Resume Next
  89. parser.loadJSON rawJson
  90. If Err.Number <> 0 Then
  91. Err.Clear
  92. Set parser = Nothing
  93. Response.Write "{""ok"":false,""error"":""Invalid JSON payload""}"
  94. Exit Sub
  95. End If
  96. Set parsed = parser.data
  97. On Error GoTo 0
  98. If parsed Is Nothing Or parsed.Count = 0 Then
  99. Set parser = Nothing
  100. Response.Write "{""ok"":false,""error"":""Invalid JSON payload""}"
  101. Exit Sub
  102. End If
  103. Dim username : username = GetCurrentUsername()
  104. Dim i, item
  105. On Error Resume Next
  106. For i = 0 To parsed.Count - 1
  107. Set item = parsed.Item(i)
  108. board_columns_Repository().UpdatePosition CLng(item.Item("id")), CLng(item.Item("position")), Now(), username
  109. If Err.Number <> 0 Then
  110. Err.Clear
  111. On Error GoTo 0
  112. Set parser = Nothing
  113. Response.Write "{""ok"":false,""error"":""Invalid reorder item at index " & i & """}"
  114. Exit Sub
  115. End If
  116. Next
  117. On Error GoTo 0
  118. Set parser = Nothing
  119. Response.Write "{""ok"":true}"
  120. End Sub
  121. Private Function GetCurrentUsername()
  122. Dim u : Set u = KeycloakCurrentUser()
  123. Dim name : name = ""
  124. If Not u Is Nothing Then
  125. On Error Resume Next
  126. name = CStr(u.Item("preferred_username"))
  127. If Err.Number <> 0 Then
  128. name = ""
  129. Err.Clear
  130. End If
  131. On Error GoTo 0
  132. End If
  133. GetCurrentUsername = name
  134. End Function
  135. Private Function JsonString(s)
  136. JsonString = """" & Replace(Replace(CStr(s), "\", "\\"), """", "\""") & """"
  137. End Function
  138. End Class
  139. Dim ColumnsController_Class__Singleton
  140. Function ColumnsController()
  141. If IsEmpty(ColumnsController_Class__Singleton) Then
  142. Set ColumnsController_Class__Singleton = New ColumnsController_Class
  143. End If
  144. Set ColumnsController = ColumnsController_Class__Singleton
  145. End Function
  146. %>

Powered by TurnKey Linux.