devel: forms in forms
This commit is contained in:
100
app.R
100
app.R
@@ -42,27 +42,39 @@ rmarkdown::find_pandoc(dir = "/opt/homebrew/bin/")
|
|||||||
if (!rmarkdown::pandoc_available()) warning("Can't find pandoc!")
|
if (!rmarkdown::pandoc_available()) warning("Can't find pandoc!")
|
||||||
|
|
||||||
|
|
||||||
# SCHEME_MAIN UNPACK ==========================
|
load_scheme_from_xlsx <- function(
|
||||||
# load scheme
|
filename,
|
||||||
SCHEME_MAIN <- readxl::read_xlsx(FILE_SCHEME) %>%
|
colnames = c("part", "subgroup", "form_id", "form_label", "form_type")
|
||||||
|
) {
|
||||||
|
|
||||||
|
readxl::read_xlsx(filename) |>
|
||||||
# fill NA down
|
# fill NA down
|
||||||
tidyr::fill(c(part, subgroup, form_id, form_label, form_type), .direction = "down") %>%
|
tidyr::fill(all_of(colnames), .direction = "down") |>
|
||||||
dplyr::group_by(form_id) %>%
|
dplyr::group_by(form_id) |>
|
||||||
tidyr::fill(c(condition, required), .direction = "down") %>%
|
tidyr::fill(c(condition, required), .direction = "down") |>
|
||||||
dplyr::ungroup()
|
dplyr::ungroup()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# SCHEME_MAIN UNPACK ==========================
|
||||||
|
# load scheme
|
||||||
|
SCHEME_MAIN <- load_scheme_from_xlsx(FILE_SCHEME)
|
||||||
|
|
||||||
# get list of simple inputs
|
# get list of simple inputs
|
||||||
inputs_simple_list <- SCHEME_MAIN %>%
|
inputs_simple_list <- SCHEME_MAIN |>
|
||||||
dplyr::filter(!form_type %in% c("inline_table", "description", "description_header")) %>%
|
dplyr::filter(!form_type %in% c("inline_table", "inline_table2","description", "description_header")) |>
|
||||||
dplyr::distinct(form_id, form_type) %>%
|
dplyr::distinct(form_id, form_type) |>
|
||||||
tibble::deframe()
|
tibble::deframe()
|
||||||
|
|
||||||
# get list of inputs with inline tables
|
# get list of inputs with inline tables
|
||||||
inputs_tables_list <- SCHEME_MAIN %>%
|
inputs_tables_list <- SCHEME_MAIN |>
|
||||||
dplyr::filter(form_type == "inline_table") %>%
|
dplyr::filter(form_type == "inline_table") |>
|
||||||
dplyr::distinct(form_id) %>%
|
dplyr::distinct(form_id) |>
|
||||||
tibble::deframe()
|
tibble::deframe()
|
||||||
|
|
||||||
|
inputs_table_df <- SCHEME_MAIN |>
|
||||||
|
dplyr::filter(form_type == "inline_table2") |>
|
||||||
|
dplyr::distinct(form_id, .keep_all = TRUE)
|
||||||
|
|
||||||
# establish connection
|
# establish connection
|
||||||
con <- db$make_db_connection()
|
con <- db$make_db_connection()
|
||||||
@@ -160,14 +172,23 @@ inline_tables <- purrr::map(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# get pages list
|
|
||||||
pages_list <- unique(SCHEME_MAIN$part)
|
|
||||||
|
|
||||||
# generate nav panels for each page
|
# generate nav panels for each page
|
||||||
nav_panels_list <- purrr::map(
|
nav_panels_list <- purrr::map(
|
||||||
.x = pages_list,
|
.x = unique(SCHEME_MAIN$part),
|
||||||
.f = utils$make_panels,
|
.f = \(page_name) {
|
||||||
main_scheme = SCHEME_MAIN
|
|
||||||
|
# отделить схему для каждой страницы
|
||||||
|
this_page_panels_scheme <- SCHEME_MAIN |>
|
||||||
|
dplyr::filter(part == {{page_name}})
|
||||||
|
|
||||||
|
this_page_panels <- utils$make_panels(this_page_panels_scheme)
|
||||||
|
|
||||||
|
# add panel wrap to nav_panel
|
||||||
|
bslib::nav_panel(
|
||||||
|
title = page_name,
|
||||||
|
this_page_panels
|
||||||
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# UI =======================
|
# UI =======================
|
||||||
@@ -253,6 +274,49 @@ server <- function(input, output) {
|
|||||||
values <- reactiveValues(data = NULL)
|
values <- reactiveValues(data = NULL)
|
||||||
rhand_tables <- reactiveValues()
|
rhand_tables <- reactiveValues()
|
||||||
|
|
||||||
|
# inline tables 2 ========================
|
||||||
|
purrr::walk(
|
||||||
|
.x = inputs_table_df$form_id,
|
||||||
|
.f = \(table_name) {
|
||||||
|
|
||||||
|
observeEvent(input[[table_name]], {
|
||||||
|
|
||||||
|
this_inline_table2_info <- inputs_table_df |>
|
||||||
|
dplyr::filter(form_id == {table_name})
|
||||||
|
|
||||||
|
inline_table2_file_name <- this_inline_table2_info$choices
|
||||||
|
|
||||||
|
this_inline_table2_scheme <- fs::path(folder_with_schemas, inline_table2_file_name) |>
|
||||||
|
load_scheme_from_xlsx(colnames = c("form_id", "form_label", "form_type"))
|
||||||
|
|
||||||
|
yay_its_fun <- purrr::pmap(
|
||||||
|
.l = dplyr::distinct(this_inline_table2_scheme, form_id, form_label, form_type),
|
||||||
|
.f = utils$render_forms,
|
||||||
|
main_scheme = this_inline_table2_scheme
|
||||||
|
)
|
||||||
|
|
||||||
|
ui_for_inline_table <- card(
|
||||||
|
height = "800px",
|
||||||
|
layout_sidebar(
|
||||||
|
sidebar = selectizeInput(
|
||||||
|
inputId = "aboba",
|
||||||
|
label = "key",
|
||||||
|
choices = c("a", "b")
|
||||||
|
),
|
||||||
|
yay_its_fun
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
showModal(modalDialog(
|
||||||
|
ui_for_inline_table,
|
||||||
|
# title = modalButton("Dismiss"),,
|
||||||
|
footer = modalButton("Dismiss"),
|
||||||
|
size = "l"
|
||||||
|
))
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# VALIDATIONS ============================
|
# VALIDATIONS ============================
|
||||||
# create new validator
|
# create new validator
|
||||||
|
|||||||
Binary file not shown.
BIN
configs/schemas/test_inline2.xlsx
Normal file
BIN
configs/schemas/test_inline2.xlsx
Normal file
Binary file not shown.
@@ -6,68 +6,16 @@
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# asdasd
|
#
|
||||||
#' @export
|
#' @export
|
||||||
make_panels <- function(page_name, main_scheme) {
|
make_panels <- function(scheme) {
|
||||||
|
|
||||||
# get info about inputs for current page
|
|
||||||
page_forms <- main_scheme |>
|
|
||||||
dplyr::filter(part == {{page_name}}) |>
|
|
||||||
dplyr::distinct(subgroup, form_id, form_label, form_type)
|
|
||||||
|
|
||||||
# get list of columns
|
|
||||||
cols_list <- unique(page_forms$subgroup)
|
|
||||||
|
|
||||||
# making cards
|
|
||||||
cards <- purrr::map(
|
cards <- purrr::map(
|
||||||
.x = cols_list,
|
.x = unique(scheme$subgroup),
|
||||||
.f = render_cards_with_forms,
|
.f = \(sub_group) {
|
||||||
main_scheme = main_scheme
|
|
||||||
)
|
|
||||||
|
|
||||||
# make page wrap
|
this_column_cards_scheme <- scheme |>
|
||||||
page_wrap <- bslib::layout_column_wrap(
|
dplyr::filter(subgroup == {{sub_group}})
|
||||||
# width = "350px", height = NULL, #was 800
|
|
||||||
width = 1 / 4, height = NULL, # was 800
|
|
||||||
fixed_width = TRUE,
|
|
||||||
# unpack list of cards
|
|
||||||
!!!cards
|
|
||||||
)
|
|
||||||
|
|
||||||
# add panel wrap to nav_panel
|
|
||||||
bslib::nav_panel(
|
|
||||||
title = page_name,
|
|
||||||
page_wrap
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# functions for making cards
|
|
||||||
# DO THIS INSTEAD !!!
|
|
||||||
#' @export
|
|
||||||
# make_forms_by_scheme <- function(tool_id, main_scheme, ns) {
|
|
||||||
|
|
||||||
# ns <- NS(ns(tool_id))
|
|
||||||
|
|
||||||
# main_scheme <<- main_scheme
|
|
||||||
# subgroup_schema <- main_scheme |>
|
|
||||||
# dplyr::filter(tool_id == {{tool_id}})
|
|
||||||
|
|
||||||
# purrr::pmap(
|
|
||||||
# .l = dplyr::distinct(subgroup_schema, form_id, form_label, form_type),
|
|
||||||
# .f = render_forms,
|
|
||||||
# schema = subgroup_schema,
|
|
||||||
# ns = ns
|
|
||||||
# )
|
|
||||||
# }
|
|
||||||
|
|
||||||
# functions for making cards
|
|
||||||
#' @export
|
|
||||||
render_cards_with_forms <- function(sub_group, main_scheme) {
|
|
||||||
|
|
||||||
main_scheme <<- main_scheme
|
|
||||||
subgroups_inputs <- main_scheme |>
|
|
||||||
dplyr::filter(subgroup == {{sub_group}}) |>
|
|
||||||
dplyr::distinct(form_id, form_label, form_type)
|
|
||||||
|
|
||||||
bslib::card(
|
bslib::card(
|
||||||
bslib::card_header(sub_group, container = htmltools::h5),
|
bslib::card_header(sub_group, container = htmltools::h5),
|
||||||
@@ -78,15 +26,25 @@ render_cards_with_forms <- function(sub_group, main_scheme) {
|
|||||||
fill = TRUE,
|
fill = TRUE,
|
||||||
# передаем все аргументы в функцию для создания елементов
|
# передаем все аргументы в функцию для создания елементов
|
||||||
purrr::pmap(
|
purrr::pmap(
|
||||||
.l = subgroups_inputs,
|
.l = dplyr::distinct(this_column_cards_scheme, form_id, form_label, form_type),
|
||||||
.f = render_forms,
|
.f = render_forms,
|
||||||
main_scheme = main_scheme
|
main_scheme = scheme
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# make page wrap
|
||||||
|
page_wrap <- bslib::layout_column_wrap(
|
||||||
|
# width = "350px", height = NULL, #was 800
|
||||||
|
width = 1 / 4, height = NULL, # was 800
|
||||||
|
fixed_width = TRUE,
|
||||||
|
# unpack list of cards
|
||||||
|
!!!cards
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# UI RELATED ============================
|
|
||||||
#' @export
|
#' @export
|
||||||
render_forms <- function(
|
render_forms <- function(
|
||||||
form_id,
|
form_id,
|
||||||
@@ -95,6 +53,7 @@ render_forms <- function(
|
|||||||
main_scheme
|
main_scheme
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
form <- NULL
|
||||||
filterd_line <- dplyr::filter(main_scheme, form_id == {{form_id}})
|
filterd_line <- dplyr::filter(main_scheme, form_id == {{form_id}})
|
||||||
|
|
||||||
# check if have condition
|
# check if have condition
|
||||||
@@ -225,6 +184,10 @@ render_forms <- function(
|
|||||||
form <- rhandsontable::rHandsontableOutput(outputId = form_id)
|
form <- rhandsontable::rHandsontableOutput(outputId = form_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (form_type == "inline_table2") {
|
||||||
|
form <- shiny::actionButton(inputId = form_id, label = label)
|
||||||
|
}
|
||||||
|
|
||||||
# description part
|
# description part
|
||||||
if (form_type == "description") {
|
if (form_type == "description") {
|
||||||
if(is.na(form_label)) {
|
if(is.na(form_label)) {
|
||||||
@@ -249,6 +212,7 @@ render_forms <- function(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is.null(form)) cli::cli_abort("невозможно создать форму типа '{form_type}' (id: '{form_id}') !")
|
||||||
form
|
form
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user