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 18 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
77 changes: 73 additions & 4 deletions R/mod_code_explorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ 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(),
fluidRow(
narayanan-iyer-pfizer marked this conversation as resolved.
Show resolved Hide resolved
column(3,
wellPanel(
Expand Down Expand Up @@ -69,7 +68,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 +147,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 +164,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 @@ -166,7 +186,56 @@ mod_code_explorer_server <- function(id, selected_pkg, pkgarchive = reactiveVal(
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
narayanan-iyer-pfizer marked this conversation as resolved.
Show resolved Hide resolved
{
$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;
}
"))
)
}
Loading
Loading