Spaces:
Sleeping
Sleeping
work in pgroesss
Browse files- Dockerfile +7 -0
- README.md +2 -0
- app.R +235 -210
Dockerfile
CHANGED
|
@@ -1,4 +1,11 @@
|
|
| 1 |
ARG GITHUB_PAT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
FROM rocker/r2u:22.04
|
| 3 |
|
| 4 |
ENV RUSTUP_HOME=/usr/local/rustup \
|
|
|
|
| 1 |
ARG GITHUB_PAT
|
| 2 |
+
ARG AMBHTMX_USER
|
| 3 |
+
ARG AMBHTMX_PASSWORD
|
| 4 |
+
ARG AMBHTMX_SECRET
|
| 5 |
+
ARG AMBHTMX_PROTOCOL
|
| 6 |
+
ARG AMBHTMX_HOST
|
| 7 |
+
ARG AMBHTMX_PORT
|
| 8 |
+
|
| 9 |
FROM rocker/r2u:22.04
|
| 10 |
|
| 11 |
ENV RUSTUP_HOME=/usr/local/rustup \
|
README.md
CHANGED
|
@@ -7,6 +7,8 @@ sdk: docker
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
|
|
|
|
|
|
| 10 |
## Runing the example in Docker
|
| 11 |
|
| 12 |
You may need to set some environment variables in the .Renviron file:
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
**Work in progress: It's still not working.**
|
| 11 |
+
|
| 12 |
## Runing the example in Docker
|
| 13 |
|
| 14 |
You may need to set some environment variables in the .Renviron file:
|
app.R
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
options(
|
| 2 |
'ambiorix.host'=Sys.getenv('AMBHTMX_HOST'),
|
| 3 |
'ambiorix.port'=Sys.getenv('AMBHTMX_PORT')
|
| 4 |
)
|
|
|
|
| 5 |
library(ambhtmx)
|
| 6 |
# devtools::load_all()
|
| 7 |
library(ambiorix)
|
|
@@ -119,229 +140,233 @@ app$use(\(req, res){
|
|
| 119 |
|
| 120 |
#' Some CRUD operations examples
|
| 121 |
cat("\nBe sure is initially empty:\n")
|
| 122 |
-
|
| 123 |
-
items$read_rows() |> print()
|
| 124 |
|
| 125 |
-
cat("\
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
tibble(name = "Que bombolles", content = "T\'empatolles.") |>
|
| 129 |
-
items$add_row() -> some_id
|
| 130 |
-
tibble(name = "Holi", content = "Guapi.") |>
|
| 131 |
-
items$add_row() -> last_id
|
| 132 |
-
items$read_rows() |> print()
|
| 133 |
|
| 134 |
-
cat(
|
| 135 |
-
|
| 136 |
-
items$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
cat("\
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
items$read_rows() |> print()
|
| 142 |
|
| 143 |
-
cat("\
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
cat()
|
| 148 |
|
| 149 |
-
cat("\
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
-
#' The main page
|
| 156 |
-
app$get("/", \(req, res){
|
| 157 |
-
# r <- process_loggedin_redirect(req, res)
|
| 158 |
-
# if(!is.null(r)) return(r)
|
| 159 |
-
if (!req$loggedin) {
|
| 160 |
-
return(res$redirect("/login", status = 302L))
|
| 161 |
-
}
|
| 162 |
-
html <- ""
|
| 163 |
-
tryCatch({
|
| 164 |
-
html <- render_page(
|
| 165 |
-
page_title = page_title,
|
| 166 |
-
main = items$render_index()
|
| 167 |
-
)
|
| 168 |
-
},
|
| 169 |
-
error = \(e) print(e)
|
| 170 |
-
)
|
| 171 |
-
res$send(html)
|
| 172 |
-
})
|
| 173 |
|
| 174 |
-
#'
|
| 175 |
-
app$get("/
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
-
#'
|
| 183 |
-
app$get("/items
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
h2("New item"),
|
| 190 |
-
div(label("Name", p(input(name = "name")))),
|
| 191 |
-
div(label("Content", p(textarea(name = "content")))),
|
| 192 |
-
a(
|
| 193 |
-
"Go back",
|
| 194 |
-
href = "/",
|
| 195 |
-
style = "margin-right:20px",
|
| 196 |
-
`hx-confirm` = "Are you sure you want to go back?",
|
| 197 |
-
`hx-get` = "/items",
|
| 198 |
-
`hx-target` = "#page",
|
| 199 |
-
`hx-swap` = "outerHTML",
|
| 200 |
-
`hx-encoding` = "multipart/form-data"
|
| 201 |
-
),
|
| 202 |
-
button(
|
| 203 |
-
"Create",
|
| 204 |
-
style = "margin-top:20px",
|
| 205 |
-
`hx-post` = "/items",
|
| 206 |
-
`hx-target` = "#page",
|
| 207 |
-
`hx-swap` = "outerHTML",
|
| 208 |
-
`hx-include` = "[name='name'], [name='content']",
|
| 209 |
-
),
|
| 210 |
-
errors
|
| 211 |
-
)))
|
| 212 |
-
res$send(html)
|
| 213 |
-
})
|
| 214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
-
#' Show an existing item
|
| 217 |
-
app$get("/items/:id", \(req, res){
|
| 218 |
-
if (!req$loggedin) {
|
| 219 |
-
return(res$redirect("/login", status = 302L))
|
| 220 |
-
}
|
| 221 |
-
item_id <- req$params$id %||% ""
|
| 222 |
-
item <- items$read_row(id = item_id)
|
| 223 |
-
html <- render_tags(withTags(tagList(
|
| 224 |
-
h2("Show item details"),
|
| 225 |
-
items$render_row(item),
|
| 226 |
-
a(
|
| 227 |
-
"Go back",
|
| 228 |
-
href = "/",
|
| 229 |
-
style = "margin-right:20px",
|
| 230 |
-
`hx-get` = "/items",
|
| 231 |
-
`hx-target` = "#page",
|
| 232 |
-
`hx-swap` = "outerHTML",
|
| 233 |
-
),
|
| 234 |
-
a(
|
| 235 |
-
"Delete",
|
| 236 |
-
href = "/",
|
| 237 |
-
style = "color: red; margin-right:20px",
|
| 238 |
-
`hx-confirm` = "Are you sure you want to delete the item?",
|
| 239 |
-
`hx-delete` = glue("/items/{item$id}"),
|
| 240 |
-
`hx-target` = "#page",
|
| 241 |
-
`hx-swap` = "outerHTML",
|
| 242 |
-
`hx-encoding` = "multipart/form-data"
|
| 243 |
-
),
|
| 244 |
-
button(
|
| 245 |
-
"Edit",
|
| 246 |
-
style = "margin-top:20px",
|
| 247 |
-
`hx-get` = glue("/items/{item_id}/edit"),
|
| 248 |
-
`hx-target` = "#main",
|
| 249 |
-
`hx-swap` = "innerHTML"
|
| 250 |
-
)
|
| 251 |
-
)))
|
| 252 |
-
res$send(html)
|
| 253 |
-
})
|
| 254 |
|
| 255 |
-
#'
|
| 256 |
-
app$get("/items/:id
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
-
#'
|
| 290 |
-
app$
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
-
#'
|
| 317 |
-
app$
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
|
| 336 |
-
#'
|
| 337 |
-
app$
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
-
#' Start the app with all the previous defined routes
|
| 347 |
-
app$start(open = FALSE)
|
|
|
|
| 1 |
+
if(!"rlang" %in% installed.packages()){
|
| 2 |
+
if(!interactive()) { stop("The package \"rlang\" is required.") }
|
| 3 |
+
cat("The package \"rlang\" is required.\n✖ Would you like to install it?\n\n1: Yes\n2: No\n\nSelection:")
|
| 4 |
+
if (readLines(n = 1) == "1"){
|
| 5 |
+
install.packages("rlang")
|
| 6 |
+
}
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
rlang::check_installed("remotes")
|
| 10 |
+
remotes::install_github("jrosell/ambhtmx", force = TRUE)
|
| 11 |
+
rlang::check_installed("ambiorix", action = \(pkg, ... ) remotes::install_github("devOpifex/ambiorix"))
|
| 12 |
+
rlang::check_installed("ambiorix", action = \(pkg, ... ) remotes::install_github("devOpifex/ambiorix"))
|
| 13 |
+
rlang::check_installed("scilis", action = \(pkg, ... ) remotes::install_github("devOpifex/scilis"))
|
| 14 |
+
rlang::check_installed("signaculum", action = \(pkg, ... ) remotes::install_github("devOpifex/signaculum"))
|
| 15 |
+
rlang::check_installed("tidyverse")
|
| 16 |
+
rlang::check_installed("zeallot")
|
| 17 |
+
rlang::check_installed("glue")
|
| 18 |
+
rlang::check_installed("htmltools")
|
| 19 |
+
rlang::check_installed("this.path")
|
| 20 |
+
|
| 21 |
options(
|
| 22 |
'ambiorix.host'=Sys.getenv('AMBHTMX_HOST'),
|
| 23 |
'ambiorix.port'=Sys.getenv('AMBHTMX_PORT')
|
| 24 |
)
|
| 25 |
+
|
| 26 |
library(ambhtmx)
|
| 27 |
# devtools::load_all()
|
| 28 |
library(ambiorix)
|
|
|
|
| 140 |
|
| 141 |
#' Some CRUD operations examples
|
| 142 |
cat("\nBe sure is initially empty:\n")
|
| 143 |
+
items$read_rows(context = context) |> print()
|
|
|
|
| 144 |
|
| 145 |
+
# cat("\nNot, it should be empty:\n")
|
| 146 |
+
# walk(items$read_rows()$id, \(x) items$delete_row(id = x))
|
| 147 |
+
# items$read_rows() |> print()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
+
# cat("\nAdd some items:\n")
|
| 150 |
+
# tibble(name = "Elis elis", content = "Putxinelis.",) |>
|
| 151 |
+
# items$add_row() -> first_id
|
| 152 |
+
# tibble(name = "Que bombolles", content = "T\'empatolles.") |>
|
| 153 |
+
# items$add_row() -> some_id
|
| 154 |
+
# tibble(name = "Holi", content = "Guapi.") |>
|
| 155 |
+
# items$add_row() -> last_id
|
| 156 |
+
# items$read_rows() |> print()
|
| 157 |
|
| 158 |
+
# cat(glue("\nDelete last item id={last_id}:\n"))
|
| 159 |
+
# items$delete_row(context = context, id = last_id)
|
| 160 |
+
# cat(glue("\nDelete last item id={last_id}:\n"))
|
| 161 |
+
# items$read_rows() |> print()
|
| 162 |
|
| 163 |
+
# cat("\nUpdate first items:\n")
|
| 164 |
+
# tibble(name = "First", content = "Hello in <span style='color:red'>red</span>.") |>
|
| 165 |
+
# items$update_row(id = first_id)
|
| 166 |
+
# items$read_rows() |> print()
|
|
|
|
| 167 |
|
| 168 |
+
# cat("\nRender the first item:\n")
|
| 169 |
+
# items$read_row(id = first_id) |>
|
| 170 |
+
# items$read_row() |>
|
| 171 |
+
# as.character() |>
|
| 172 |
+
# cat()
|
| 173 |
|
| 174 |
+
# cat("\nAdd an item with id 1:\n")
|
| 175 |
+
# tibble(id = "1", name = "Quines postres", content = "Tant bones.") |>
|
| 176 |
+
# items$add_row()
|
| 177 |
+
# items$read_rows() |> print()
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
+
# #' The main page
|
| 181 |
+
# app$get("/", \(req, res){
|
| 182 |
+
# # r <- process_loggedin_redirect(req, res)
|
| 183 |
+
# # if(!is.null(r)) return(r)
|
| 184 |
+
# if (!req$loggedin) {
|
| 185 |
+
# return(res$redirect("/login", status = 302L))
|
| 186 |
+
# }
|
| 187 |
+
# html <- ""
|
| 188 |
+
# tryCatch({
|
| 189 |
+
# html <- render_page(
|
| 190 |
+
# page_title = page_title,
|
| 191 |
+
# main = items$render_index()
|
| 192 |
+
# )
|
| 193 |
+
# },
|
| 194 |
+
# error = \(e) print(e)
|
| 195 |
+
# )
|
| 196 |
+
# res$send(html)
|
| 197 |
+
# })
|
| 198 |
|
| 199 |
+
# #' Read the index of the items
|
| 200 |
+
# app$get("/items", \(req, res){
|
| 201 |
+
# if (!req$loggedin) {
|
| 202 |
+
# return(res$redirect("/login", status = 302L))
|
| 203 |
+
# }
|
| 204 |
+
# res$send(items$render_index())
|
| 205 |
+
# })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
+
# #' New item form
|
| 208 |
+
# app$get("/items/new", \(req, res){
|
| 209 |
+
# if (!req$loggedin) {
|
| 210 |
+
# return(res$redirect("/login", status = 302L))
|
| 211 |
+
# }
|
| 212 |
+
# errors <- process_error_get(req, res)
|
| 213 |
+
# html <- render_tags(withTags(tagList(
|
| 214 |
+
# h2("New item"),
|
| 215 |
+
# div(label("Name", p(input(name = "name")))),
|
| 216 |
+
# div(label("Content", p(textarea(name = "content")))),
|
| 217 |
+
# a(
|
| 218 |
+
# "Go back",
|
| 219 |
+
# href = "/",
|
| 220 |
+
# style = "margin-right:20px",
|
| 221 |
+
# `hx-confirm` = "Are you sure you want to go back?",
|
| 222 |
+
# `hx-get` = "/items",
|
| 223 |
+
# `hx-target` = "#page",
|
| 224 |
+
# `hx-swap` = "outerHTML",
|
| 225 |
+
# `hx-encoding` = "multipart/form-data"
|
| 226 |
+
# ),
|
| 227 |
+
# button(
|
| 228 |
+
# "Create",
|
| 229 |
+
# style = "margin-top:20px",
|
| 230 |
+
# `hx-post` = "/items",
|
| 231 |
+
# `hx-target` = "#page",
|
| 232 |
+
# `hx-swap` = "outerHTML",
|
| 233 |
+
# `hx-include` = "[name='name'], [name='content']",
|
| 234 |
+
# ),
|
| 235 |
+
# errors
|
| 236 |
+
# )))
|
| 237 |
+
# res$send(html)
|
| 238 |
+
# })
|
| 239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
+
# #' Show an existing item
|
| 242 |
+
# app$get("/items/:id", \(req, res){
|
| 243 |
+
# if (!req$loggedin) {
|
| 244 |
+
# return(res$redirect("/login", status = 302L))
|
| 245 |
+
# }
|
| 246 |
+
# item_id <- req$params$id %||% ""
|
| 247 |
+
# item <- items$read_row(id = item_id)
|
| 248 |
+
# html <- render_tags(withTags(tagList(
|
| 249 |
+
# h2("Show item details"),
|
| 250 |
+
# items$render_row(item),
|
| 251 |
+
# a(
|
| 252 |
+
# "Go back",
|
| 253 |
+
# href = "/",
|
| 254 |
+
# style = "margin-right:20px",
|
| 255 |
+
# `hx-get` = "/items",
|
| 256 |
+
# `hx-target` = "#page",
|
| 257 |
+
# `hx-swap` = "outerHTML",
|
| 258 |
+
# ),
|
| 259 |
+
# a(
|
| 260 |
+
# "Delete",
|
| 261 |
+
# href = "/",
|
| 262 |
+
# style = "color: red; margin-right:20px",
|
| 263 |
+
# `hx-confirm` = "Are you sure you want to delete the item?",
|
| 264 |
+
# `hx-delete` = glue("/items/{item$id}"),
|
| 265 |
+
# `hx-target` = "#page",
|
| 266 |
+
# `hx-swap` = "outerHTML",
|
| 267 |
+
# `hx-encoding` = "multipart/form-data"
|
| 268 |
+
# ),
|
| 269 |
+
# button(
|
| 270 |
+
# "Edit",
|
| 271 |
+
# style = "margin-top:20px",
|
| 272 |
+
# `hx-get` = glue("/items/{item_id}/edit"),
|
| 273 |
+
# `hx-target` = "#main",
|
| 274 |
+
# `hx-swap` = "innerHTML"
|
| 275 |
+
# )
|
| 276 |
+
# )))
|
| 277 |
+
# res$send(html)
|
| 278 |
+
# })
|
| 279 |
|
| 280 |
+
# #' Edit item form
|
| 281 |
+
# app$get("/items/:id/edit", \(req, res){
|
| 282 |
+
# if (!req$loggedin) {
|
| 283 |
+
# return(res$redirect("/login", status = 302L))
|
| 284 |
+
# }
|
| 285 |
+
# item_id <- req$params$id %||% ""
|
| 286 |
+
# item <- items$read_row(id = item_id)
|
| 287 |
+
# html <- render_tags(withTags(tagList(
|
| 288 |
+
# h2("Edit item"),
|
| 289 |
+
# input(type = "hidden", name = "id", value = item$id),
|
| 290 |
+
# div(label("Name", p(input(name = "name", value = item$name)))),
|
| 291 |
+
# div(HTML(glue('<textarea rows=5 name="content">{item$content}</textarea>'))),
|
| 292 |
+
# a(
|
| 293 |
+
# "Go back",
|
| 294 |
+
# href = "/",
|
| 295 |
+
# style = "margin-right:20px",
|
| 296 |
+
# `hx-confirm` = "Are you sure you want to go back?",
|
| 297 |
+
# `hx-get` = "/items",
|
| 298 |
+
# `hx-target` = "#page",
|
| 299 |
+
# `hx-swap` = "outerHTML",
|
| 300 |
+
# `hx-encoding` = "multipart/form-data"
|
| 301 |
+
# ),
|
| 302 |
+
# button(
|
| 303 |
+
# "Update",
|
| 304 |
+
# style = "margin-top:20px",
|
| 305 |
+
# `hx-put` = glue("/items/{item$id}"),
|
| 306 |
+
# `hx-target` = "#page",
|
| 307 |
+
# `hx-swap` = "outerHTML",
|
| 308 |
+
# `hx-include` = "[name='name'], [name='content']",
|
| 309 |
+
# )
|
| 310 |
+
# )))
|
| 311 |
+
# res$send(html)
|
| 312 |
+
# })
|
| 313 |
|
| 314 |
+
# #' Create a new item
|
| 315 |
+
# app$post("/items", \(req, res){
|
| 316 |
+
# if (!req$loggedin) {
|
| 317 |
+
# return(res$redirect("/login", status = 302L))
|
| 318 |
+
# }
|
| 319 |
+
# params <- parse_multipart(req)
|
| 320 |
+
# if (is.null(params[["name"]])) {
|
| 321 |
+
# return(process_error_post(
|
| 322 |
+
# req,
|
| 323 |
+
# res,
|
| 324 |
+
# errors = "Name is required",
|
| 325 |
+
# error_url = "/items/new"
|
| 326 |
+
# ))
|
| 327 |
+
# }
|
| 328 |
+
# if (is.null(params[["content"]])) {
|
| 329 |
+
# params[["content"]] = ""
|
| 330 |
+
# }
|
| 331 |
+
# tryCatch({
|
| 332 |
+
# params |>
|
| 333 |
+
# as_tibble() |>
|
| 334 |
+
# items$add_row()
|
| 335 |
+
# },
|
| 336 |
+
# error = \(e) print(e)
|
| 337 |
+
# )
|
| 338 |
+
# res$send(items$render_index())
|
| 339 |
+
# })
|
| 340 |
|
| 341 |
+
# #' Update an existing item
|
| 342 |
+
# app$put("/items/:id", \(req, res){
|
| 343 |
+
# if (!req$loggedin) {
|
| 344 |
+
# return(res$redirect("/login", status = 302L))
|
| 345 |
+
# }
|
| 346 |
+
# item_id <- req$params$id %||% ""
|
| 347 |
+
# params <- parse_multipart(req) |>
|
| 348 |
+
# as_tibble() |>
|
| 349 |
+
# mutate(id = item_id)
|
| 350 |
+
# item <- items$read_row(id = item_id)
|
| 351 |
+
# tryCatch({
|
| 352 |
+
# item |>
|
| 353 |
+
# dplyr::rows_upsert(params, by = "id") |>
|
| 354 |
+
# items$update_row()
|
| 355 |
+
# },
|
| 356 |
+
# error = \(e) print(e)
|
| 357 |
+
# )
|
| 358 |
+
# res$send(items$render_index())
|
| 359 |
+
# })
|
| 360 |
+
|
| 361 |
+
# #' Delete an existing item
|
| 362 |
+
# app$delete("/items/:id", \(req, res){
|
| 363 |
+
# if (!req$loggedin) {
|
| 364 |
+
# return(res$redirect("/login", status = 302L))
|
| 365 |
+
# }
|
| 366 |
+
# item_id <- req$params$id %||% ""
|
| 367 |
+
# items$delete_row(id = item_id)
|
| 368 |
+
# res$send(items$render_index())
|
| 369 |
+
# })
|
| 370 |
|
| 371 |
+
# #' Start the app with all the previous defined routes
|
| 372 |
+
# app$start(open = FALSE)
|