TAK-67 navigation fix

This commit is contained in:
Rafał Piskorski 2020-12-28 16:04:02 +01:00
parent 0230093d8c
commit c96c084266
6 changed files with 147 additions and 57 deletions

166
app/app.R
View File

@ -28,7 +28,19 @@ tags$script('Shiny.addCustomMessageHandler("tokenHandler",
Shiny.onInputChange("token", token); Shiny.onInputChange("token", token);
} }
);') );'),
tags$script('Shiny.addCustomMessageHandler("tokenHandlerAccess",
function(token) {
if(token=="#!/profil" || token=="#!/calculator"){
let token = sessionStorage.getItem(\'token\');
if(token==null || token==undefined){
window.location.replace(\'/#!/home\');
}}}
);'),
tags$script('
$(document).on("shiny:visualchange",function(event){
Shiny.onInputChange("reload", new Date().getTime());});')
), ),
uiOutput("logged"), uiOutput("logged"),
@ -39,6 +51,102 @@ tags$script('Shiny.addCustomMessageHandler("tokenHandler",
server <- shinyServer(function(input, output, session){ server <- shinyServer(function(input, output, session){
barSelected<-function(){
if(( (session$clientData)$url_hash=="#!/profil")){
shinyjs::addCssClass(id="tab4",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab5",class = "clicked")
shinyjs::removeCssClass(id="tab6",class = "clicked")
shinyjs::removeCssClass(id="tab7",class = "clicked")
}else if(( (session$clientData)$url_hash=="#!/login")){
shinyjs::addCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
shinyjs::removeCssClass(id="tab5",class = "clicked")
shinyjs::removeCssClass(id="tab6",class = "clicked")
shinyjs::removeCssClass(id="tab7",class = "clicked")
}
else if(( (session$clientData)$url_hash=="#!/register")){
shinyjs::addCssClass(id="tab6",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
shinyjs::removeCssClass(id="tab5",class = "clicked")
shinyjs::removeCssClass(id="tab7",class = "clicked")
}else if(( (session$clientData)$url_hash=="#!/calculator")){
shinyjs::addCssClass(id="tab5",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
shinyjs::removeCssClass(id="tab6",class = "clicked")
shinyjs::removeCssClass(id="tab7",class = "clicked")
}else if(( (session$clientData)$url_hash=="#!/about")){
shinyjs::addCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
shinyjs::removeCssClass(id="tab5",class = "clicked")
shinyjs::removeCssClass(id="tab6",class = "clicked")
shinyjs::removeCssClass(id="tab7",class = "clicked")
}else if(( (session$clientData)$url_hash=="#!/firms")){
shinyjs::addCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
shinyjs::removeCssClass(id="tab5",class = "clicked")
shinyjs::removeCssClass(id="tab6",class = "clicked")
shinyjs::removeCssClass(id="tab7",class = "clicked")
}
else if(( (session$clientData)$url_hash=="#!/home" || (session$clientData)$url_hash=="#!/" )){
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
shinyjs::removeCssClass(id="tab5",class = "clicked")
shinyjs::removeCssClass(id="tab6",class = "clicked")
shinyjs::removeCssClass(id="tab7",class = "clicked")
}
}
output$logged<-renderUI({ output$logged<-renderUI({
@ -49,10 +157,10 @@ server <- shinyServer(function(input, output, session){
column(12, column(12,
navbarPage("", navbarPage("",
tabPanel(a("TakeCareApp",id='takeCareApp',class = "tab-link", href = route_link("home"))), tabPanel(a("TakeCareApp",id='takeCareApp',class = "tab-link", href = route_link("home"))),
tabPanel(a("Firmy",id="tab1",class = "tab-link", href = route_link("firmy"))), tabPanel(a("Firmy",id="tab1",class = "tab-link", href = route_link("firms"))),
tabPanel(a("O nas",id="tab2",class = "tab-link", href = route_link("about"))), tabPanel(a("O nas",id="tab2",class = "tab-link", href = route_link("about"))),
tabPanel(a("Zaloguj",id="tab3",class="tab-link", href = route_link("login"))), tabPanel(a("Zaloguj",id="tab3",class="tab-link", href = route_link("login"))),
tabPanel(a("Rejestracja",id="tab4",class="tab-link", href = route_link("register")))), tabPanel(a("Rejestracja",id="tab6",class="tab-link", href = route_link("register")))),
@ -66,10 +174,10 @@ server <- shinyServer(function(input, output, session){
column(12, column(12,
navbarPage("", navbarPage("",
tabPanel(a("TakeCareApp",id='takeCareApp',class = "tab-link", href = route_link("home"))), tabPanel(a("TakeCareApp",id='takeCareApp',class = "tab-link", href = route_link("home"))),
tabPanel(a("Firmy",id="tab1",class = "tab-link", href = route_link("profil"))), tabPanel(a("Firmy",id="tab1",class = "tab-link", href = route_link("firms"))),
tabPanel(a("O nas",id="tab2",class = "tab-link", href = route_link("about"))), tabPanel(a("O nas",id="tab2",class = "tab-link", href = route_link("about"))),
tabPanel(a("Kalkulator", id ="tab5",class="tab-link", href = route_link("calculator"))), tabPanel(a("Kalkulator", id ="tab5",class="tab-link", href = route_link("calculator"))),
tabPanel(a("Wyloguj",id="tab3",class = "tab-link")), tabPanel(a("Wyloguj",id="tab7",class = "tab-link")),
tabPanel(a("Profil",id="tab4",class="tab-link", href = route_link("profil")))), tabPanel(a("Profil",id="tab4",class="tab-link", href = route_link("profil")))),
@ -86,51 +194,31 @@ server <- shinyServer(function(input, output, session){
}) })
shinyjs::onclick(id="takeCareApp",expr = {
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
})
shinyjs::onclick(id="tab1",expr = {
shinyjs::addCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
})
shinyjs::onclick(id="tab2",expr = { shinyjs::onclick(id="tab7",expr = {
shinyjs::addCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
})
shinyjs::onclick(id="tab3",expr = {
if(is.null(input$token)){
shinyjs::addCssClass(id="tab3",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab4",class = "clicked")
}else{
shinyjs::runjs( 'sessionStorage.removeItem(\'token\'); shinyjs::runjs( 'sessionStorage.removeItem(\'token\');
Shiny.onInputChange("token", null); Shiny.onInputChange("token", null);
window.location.replace(\'/#!/login\');') window.location.replace(\'/#!/login\');')
})
observeEvent((session$clientData)$url_hash,{
barSelected()
})
observeEvent(input$reload,{
barSelected()
} }
})
shinyjs::onclick(id="tab4",expr = {
shinyjs::addCssClass(id="tab4",class = "clicked")
shinyjs::removeCssClass(id="tab2",class = "clicked")
shinyjs::removeCssClass(id="tab1",class = "clicked")
shinyjs::removeCssClass(id="tab3",class = "clicked")
})
)
router$server(input, output, session) router$server(input, output, session)

View File

@ -97,6 +97,7 @@ loginServer <- function(input, output,session) {
shinyjs::runjs('window.location.replace(\'/#!/home\');') shinyjs::runjs('window.location.replace(\'/#!/home\');')
} }
}) })

View File

@ -10,6 +10,12 @@ profilUI <- function(id) {
useShinyjs(), useShinyjs(),
tags$head( tags$head(
tags$script(src="js.cookie.js"), tags$script(src="js.cookie.js"),
tags$script('Shiny.addCustomMessageHandler("tokenHandlerUpdate",
function(token) {
sessionStorage.setItem(\'token\', token);
Shiny.onInputChange("token", token);
}
);'),
tags$style(HTML(" tags$style(HTML("
@ -86,17 +92,7 @@ profilServer <- function(input, output,session) {
observe({ observe({
if(( (session$clientData)$url_hash=="#!/profil")){ session$sendCustomMessage(type='tokenHandlerAccess',(session$clientData)$url_hash)
if( (is.null(input$token) | length(input$token)<=0 )){
shinyjs::runjs('window.location.replace(\'/#!/home\');')
}
}
}) })
@ -110,7 +106,7 @@ profilServer <- function(input, output,session) {
response<-(content(r)) response<-(content(r))
session$sendCustomMessage(type='tokenHandlerAfterLogin', response$token) session$sendCustomMessage(type='tokenHandlerUpdate', response$token)
fluidRow(column(12, fluidRow(column(12,

View File

@ -37,6 +37,7 @@ registerUI <- function(id) {
} }
registerServer <- function(input, output,session) { registerServer <- function(input, output,session) {
result <-reactiveValues(name=NULL,surname=NULL,mail=NULL,age=NULL,gender=NULL,login=NULL,pass=NULL,permission=NULL) result <-reactiveValues(name=NULL,surname=NULL,mail=NULL,age=NULL,gender=NULL,login=NULL,pass=NULL,permission=NULL)
status <-reactiveValues(status=NULL,first=TRUE) status <-reactiveValues(status=NULL,first=TRUE)

View File

@ -21,7 +21,7 @@ profil_page <-profilUI(id="profil")
login_page <-loginUI(id="login") login_page <-loginUI(id="login")
register_page <-registerUI(id="register") register_page <-registerUI(id="register")
calculator_page <- calculatorUI(id="calculator") calculator_page <- calculatorUI(id="calculator")
firmy_page <- firmyUI(id="firmy") firmy_page <- firmyUI(id="firms")
router <- make_router( router <- make_router(
route("home", home_page,homeServer), route("home", home_page,homeServer),
@ -30,7 +30,7 @@ router <- make_router(
route("login", login_page,loginServer), route("login", login_page,loginServer),
route("register", register_page,registerServer), route("register", register_page,registerServer),
route("calculator", calculator_page, calculatorServer), route("calculator", calculator_page, calculatorServer),
route("firmy", firmy_page, firmyServer) route("firms", firmy_page, firmyServer)
) )

View File

@ -133,6 +133,10 @@ background-color:#00A896;
} }
.clicked{
background-color: #008375 !important;
}
#row-content{ #row-content{
margin-left:0; margin-left:0;