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

172
app/app.R
View File

@ -28,7 +28,19 @@ tags$script('Shiny.addCustomMessageHandler("tokenHandler",
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"),
@ -38,6 +50,102 @@ tags$script('Shiny.addCustomMessageHandler("tokenHandler",
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({
@ -49,10 +157,10 @@ server <- shinyServer(function(input, output, session){
column(12,
navbarPage("",
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("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,
navbarPage("",
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("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")))),
@ -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::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::onclick(id="tab7",expr = {
shinyjs::runjs( 'sessionStorage.removeItem(\'token\');
Shiny.onInputChange("token", null);
window.location.replace(\'/#!/login\');')
}
})
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")
})
observeEvent((session$clientData)$url_hash,{
barSelected()
})
observeEvent(input$reload,{
barSelected()
}
)
router$server(input, output, session)

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@ profil_page <-profilUI(id="profil")
login_page <-loginUI(id="login")
register_page <-registerUI(id="register")
calculator_page <- calculatorUI(id="calculator")
firmy_page <- firmyUI(id="firmy")
firmy_page <- firmyUI(id="firms")
router <- make_router(
route("home", home_page,homeServer),
@ -30,7 +30,7 @@ router <- make_router(
route("login", login_page,loginServer),
route("register", register_page,registerServer),
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{
margin-left:0;