Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autonavigation #779

Merged
merged 21 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: riskassessment
Title: A web app designed to interface with the `riskmetric` package
Version: 3.1.0.9000
Version: 3.1.0.9001
Authors@R: c(
person("Aaron", "Clark", role = c("aut", "cre"), email = "[email protected]"),
person("Jeff", "Thompson", role = c("aut"), email = "[email protected]", comment = "Co-Lead"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# riskassessment (development version)

* Added navigation controls in Function Explorer tab (#644)

# riskassessment 3.1.0

### User Enhancements
Expand Down
83 changes: 79 additions & 4 deletions R/mod_code_explorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod_code_explorer_server <- function(id, selected_pkg, pkgarchive = reactiveVal(
showHelperMessage(message = glue::glue("Source code not available for {{{selected_pkg$name()}}}"))
} else {
div(introJSUI(NS(id, "introJS")),
br(),
br(),
fluidRow(
narayanan-iyer-pfizer marked this conversation as resolved.
Show resolved Hide resolved
column(3,
wellPanel(
Expand Down Expand Up @@ -69,7 +69,28 @@ mod_code_explorer_server <- function(id, selected_pkg, pkgarchive = reactiveVal(
div(id = ns("file_viewer"),
uiOutput(ns("file_output"), class = "file_browser"),
style = "height: 62vh; overflow: auto; border: 1px solid var(--bs-border-color-translucent);"
)
),
br(),
fluidRow(style = "height:35px !important;",
column(4,offset = 8,
conditionalPanel(
condition = "typeof(window.$highlights_list) != 'undefined' && window.$highlights_list.length > 1",
actionButton(ns("prev_button"),label = "",icon = icon("chevron-left"),
style ="width: 32px !important;
height: 32px !important;
font-size: 16px !important;
line-height: 5px !important;
padding: 0px !important;") |>bslib::tooltip("Previous occurence"), style = "display: inline-block;",

div(id = "search_index","",style ="display:inline"),
actionButton(ns("next_button"),label = "",icon = icon("chevron-right"),
style = "width: 32px !important;
height: 32px !important;
font-size: 16px !important;
line-height: 5px !important;
padding: 0px !important;
display:inline;
")|>bslib::tooltip("Next occurence",placement ="right"), style = "display: inline-block;")))
)
),
br(), br(),
Expand Down Expand Up @@ -127,7 +148,7 @@ mod_code_explorer_server <- function(id, selected_pkg, pkgarchive = reactiveVal(
close(con)
func_list <- c(input$exported_function, paste0("`", input$exported_function, "`"))
highlight_index <- parse_data() %>%
filter(stringr::str_ends(file, input$test_files) & func %in% func_list) %>%
filter(basename(file) == input$test_files & func %in% func_list) %>%
pull(line)
renderCode(lines, highlight_index)
}) %>%
Expand All @@ -144,7 +165,7 @@ mod_code_explorer_server <- function(id, selected_pkg, pkgarchive = reactiveVal(
close(con)
func_list <- c(input$exported_function, paste0("`", input$exported_function, "`"))
highlight_index <- parse_data() %>%
filter(stringr::str_ends(file, input$source_files) & func %in% func_list) %>%
filter(basename(file) == input$source_files & func %in% func_list) %>%
pull(line)
renderCode(lines, highlight_index)
}) %>%
Expand All @@ -157,16 +178,70 @@ mod_code_explorer_server <- function(id, selected_pkg, pkgarchive = reactiveVal(
con <- archive::archive_read(file.path("tarballs",
glue::glue("{selected_pkg$name()}_{selected_pkg$version()}.tar.gz")),
file = fp)

Rdfile <-tools::parse_Rd(con)
close(con)
shinyjs::runjs('
$highlights_list = undefined;')

HTML(paste0(utils::capture.output(tools::Rd2HTML(Rdfile,
package = c(selected_pkg$name(),
selected_pkg$version()), out = "")), collapse = "\n"))
}) %>%
bindEvent(input$man_files, input$exported_function, ignoreNULL = FALSE)

introJSServer("introJS", text = reactive(fe_steps), user, credentials)
search_index_value <- reactiveVal(1)
highlight_list <- reactiveVal(1)

observeEvent(input$next_button,{
if (input$next_button > 0){
shinyjs::runjs('
var $index =Array.from($highlights_list).findIndex(node => node.isEqualNode($curr_sel));
narayanan-iyer-pfizer marked this conversation as resolved.
Show resolved Hide resolved
if( $index == $highlights_list.length -1)
{

$curr_sel = $highlights_list[0]
search_index.innerHTML = 1 + " of " + $highlights_list.length;

}
else
{
$curr_sel = $highlights_list[$index +1]
search_index.innerHTML = ( $index+2) + " of " + $highlights_list.length;
}

var $target = document.querySelector("#code_explorer-file_viewer")
$target.scrollTop = 0;
$target.scrollTop =$curr_sel.offsetTop -40; ')

}

})

observeEvent(input$prev_button,{
if (input$prev_button > 0){

shinyjs::runjs('var $index =Array.from($highlights_list).findIndex(node => node.isEqualNode($curr_sel));
if( $index ==0)
{
$curr_sel = $highlights_list[$highlights_list.length -1]
search_index.innerHTML = $highlights_list.length + " of " + $highlights_list.length;
}
else
{
$curr_sel = $highlights_list[$index -1]
search_index.innerHTML = ($index) + " of " + $highlights_list.length;
}
var $target = document.querySelector("#code_explorer-file_viewer")

$target.scrollTop = 0;
$target.scrollTop = $curr_sel.offsetTop - 40;

')
}

})
output$file_output <- renderUI({
switch (input$file_type,
test = test_code(),
Expand Down
10 changes: 10 additions & 0 deletions R/mod_code_explorer_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,19 @@ renderCode <- function(lines, hlindex) {
})
),
tags$script(HTML("

document.querySelectorAll('.code pre').forEach(bl => {
hljs.highlightBlock(bl);
});
var $highlights_list = document.querySelectorAll('.highlight')
var $curr_sel = document.querySelector('.highlight')
if(typeof($highlights_list) != 'undefined' & $curr_sel != null){
var $target = document.querySelector('#code_explorer-file_viewer')
$target.scrollTop = 0;
$target.scrollTop = $curr_sel.offsetTop - 40;
var $index1 =Array.from($highlights_list).findIndex(node => node.isEqualNode($curr_sel)) +1;
search_index.innerHTML = $index1 + ' of ' + $highlights_list.length;
}
"))
)
}
16 changes: 8 additions & 8 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4367,7 +4367,7 @@
"Maintainer": "Kevin Ushey <[email protected]>",
"Repository": "RSPM",
"Date/Publication": "2024-02-29 01:10:07 UTC",
"Built": "R 4.3.3; ; 2024-06-26 14:42:15 UTC; unix"
"Built": "R 4.3.3; ; 2024-07-08 12:36:44 UTC; unix"
}
},
"reprex": {
Expand Down Expand Up @@ -6202,7 +6202,7 @@
"checksum": "b92bdc0d72dbb64e7cf767514486ec62"
},
"data-raw/internal-data.R": {
"checksum": "33c0142c3bb1bbba56e83fa0439778e7"
"checksum": "1012b9a74fd027e081b3a81bc863358e"
},
"data-raw/maintenance.csv": {
"checksum": "f5bb530b482daa092e9e20f6a069f1aa"
Expand All @@ -6220,7 +6220,7 @@
"checksum": "99c5575cb81828e20a7fe1d205551316"
},
"DESCRIPTION": {
"checksum": "9bc40f8d2e36a15c64868dc35aa47977"
"checksum": "ea81f750b1ae3fa6b3ebf79e5668a3ee"
},
"inst/app/www/css/community_metrics.css": {
"checksum": "f08eb25c2ee48ac22ed63b0d18994a04"
Expand Down Expand Up @@ -6463,7 +6463,7 @@
"checksum": "97d1232340e04c53088bc8f814133dcd"
},
"NEWS.md": {
"checksum": "9fd91891f54e18c5f702df550768e91a"
"checksum": "29db451dbb57771e940e1911eac5407f"
},
"R/app_config.R": {
"checksum": "c2b61f270b86b6833f0ee39c44a1a440"
Expand All @@ -6481,7 +6481,7 @@
"checksum": "23ff3c99869bd59ed973d031ee2962fd"
},
"R/mod_aboutInfo.R": {
"checksum": "5240534ac7d4291a0514c01106442e6f"
"checksum": "1ccb24c4960467461139c1050aafc91e"
},
"R/mod_addComment.R": {
"checksum": "9a4f5a5b10f127040705dbdaa312b693"
Expand All @@ -6490,10 +6490,10 @@
"checksum": "61459e71d1e62587597ac1dac2c7c650"
},
"R/mod_code_explorer_utils.R": {
"checksum": "fe3bd5c1243d0ba649d070a6ecf29560"
"checksum": "2588e180a69a79b7be4e3818eb3931dc"
},
"R/mod_code_explorer.R": {
"checksum": "72a36a8c4d7f15e0da013104177328b1"
"checksum": "1ec3f3aac096efff1e0c360b347e2d32"
},
"R/mod_communityMetrics.R": {
"checksum": "fdd39bd2a7e19b8dccc195aaec57a3d8"
Expand Down Expand Up @@ -6562,7 +6562,7 @@
"checksum": "6c4740fd1aea22825c231eec5d8d9578"
},
"R/sysdata.rda": {
"checksum": "b610fc73187b7cd23521deb9339d54cf"
"checksum": "e5835b81f48d93ee0175507abbb3186f"
},
"R/utils_build_cards.R": {
"checksum": "f79316fe637bb1f4038f085621d298f5"
Expand Down