2020-11-27 19:14:20 +01:00
|
|
|
library(shiny)
|
2020-12-04 18:06:31 +01:00
|
|
|
library(shiny.router)
|
2020-12-03 11:39:38 +01:00
|
|
|
library(magrittr)
|
|
|
|
library(ggplot2)
|
|
|
|
library(plotly)
|
|
|
|
library(DT)
|
2020-12-06 19:45:27 +01:00
|
|
|
library(shinyjs)
|
2020-11-27 19:14:20 +01:00
|
|
|
|
2020-12-04 18:06:31 +01:00
|
|
|
#source(".R/home_module.R",encoding="utf-8")
|
|
|
|
#source(".R/about_module.R",encoding="utf-8")
|
|
|
|
#source(".R/profil_module.R",encoding="utf-8")
|
2020-12-03 12:25:08 +01:00
|
|
|
|
2020-12-04 18:06:31 +01:00
|
|
|
source("routing_module.R",encoding="utf-8")
|
2020-11-27 19:14:20 +01:00
|
|
|
|
|
|
|
|
2020-12-06 19:45:27 +01:00
|
|
|
ui <- fluidPage(
|
2020-12-14 13:47:03 +01:00
|
|
|
useShinyjs(),
|
|
|
|
tags$head(
|
2020-12-19 23:13:44 +01:00
|
|
|
tags$script(src="js.cookie.js"),
|
|
|
|
|
2020-12-20 15:46:02 +01:00
|
|
|
|
|
|
|
tags$script('var token = sessionStorage.getItem(\'token\');
|
|
|
|
$(document).on("shiny:sessioninitialized",function(event){
|
|
|
|
Shiny.onInputChange("token", token);});'),
|
|
|
|
tags$script('Shiny.addCustomMessageHandler("tokenHandler",
|
2020-12-19 23:13:44 +01:00
|
|
|
function(token) {
|
2020-12-20 15:46:02 +01:00
|
|
|
sessionStorage.setItem(\'token\', token);
|
|
|
|
Shiny.onInputChange("token", token);
|
2020-12-19 23:13:44 +01:00
|
|
|
|
|
|
|
}
|
2020-12-28 16:04:02 +01:00
|
|
|
);'),
|
|
|
|
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());});')
|
2020-12-14 13:47:03 +01:00
|
|
|
),
|
|
|
|
uiOutput("logged"),
|
|
|
|
|
2020-12-06 19:45:27 +01:00
|
|
|
|
|
|
|
router$ui)
|
2020-12-04 18:06:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server <- shinyServer(function(input, output, session){
|
2020-12-28 16:04:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2020-12-14 13:47:03 +01:00
|
|
|
|
|
|
|
output$logged<-renderUI({
|
|
|
|
|
|
|
|
|
|
|
|
if(is.null(input$token)){
|
|
|
|
fluidRow(
|
|
|
|
|
|
|
|
inlineCSS(list(.clicked = "background-color: #008375 !important")),
|
|
|
|
column(12,
|
|
|
|
navbarPage("",
|
|
|
|
tabPanel(a("TakeCareApp",id='takeCareApp',class = "tab-link", href = route_link("home"))),
|
2020-12-28 16:04:02 +01:00
|
|
|
tabPanel(a("Firmy",id="tab1",class = "tab-link", href = route_link("firms"))),
|
2020-12-14 13:47:03 +01:00
|
|
|
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"))),
|
2020-12-28 16:04:02 +01:00
|
|
|
tabPanel(a("Rejestracja",id="tab6",class="tab-link", href = route_link("register")))),
|
2020-12-19 19:25:04 +01:00
|
|
|
|
2020-12-14 13:47:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}else{
|
|
|
|
fluidRow(
|
|
|
|
|
|
|
|
inlineCSS(list(.clicked = "background-color: #008375 !important")),
|
|
|
|
column(12,
|
|
|
|
navbarPage("",
|
|
|
|
tabPanel(a("TakeCareApp",id='takeCareApp',class = "tab-link", href = route_link("home"))),
|
2020-12-28 16:04:02 +01:00
|
|
|
tabPanel(a("Firmy",id="tab1",class = "tab-link", href = route_link("firms"))),
|
2020-12-14 13:47:03 +01:00
|
|
|
tabPanel(a("O nas",id="tab2",class = "tab-link", href = route_link("about"))),
|
2020-12-19 22:21:48 +01:00
|
|
|
tabPanel(a("Kalkulator", id ="tab5",class="tab-link", href = route_link("calculator"))),
|
2020-12-28 16:04:02 +01:00
|
|
|
tabPanel(a("Wyloguj",id="tab7",class = "tab-link")),
|
2020-12-19 19:25:04 +01:00
|
|
|
tabPanel(a("Profil",id="tab4",class="tab-link", href = route_link("profil")))),
|
|
|
|
|
2020-12-14 13:47:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2020-12-06 19:45:27 +01:00
|
|
|
|
2020-12-28 16:04:02 +01:00
|
|
|
|
2020-12-06 19:45:27 +01:00
|
|
|
|
2020-12-28 16:04:02 +01:00
|
|
|
shinyjs::onclick(id="tab7",expr = {
|
|
|
|
|
|
|
|
shinyjs::runjs( 'sessionStorage.removeItem(\'token\');
|
2020-12-14 13:47:03 +01:00
|
|
|
|
|
|
|
Shiny.onInputChange("token", null);
|
|
|
|
window.location.replace(\'/#!/login\');')
|
2020-12-28 16:04:02 +01:00
|
|
|
|
2020-12-12 12:38:54 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-12-28 16:04:02 +01:00
|
|
|
observeEvent((session$clientData)$url_hash,{
|
|
|
|
|
|
|
|
barSelected()
|
|
|
|
|
|
|
|
})
|
2020-12-06 19:45:27 +01:00
|
|
|
|
2020-12-28 16:04:02 +01:00
|
|
|
observeEvent(input$reload,{
|
|
|
|
barSelected()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
)
|
2020-12-06 19:45:27 +01:00
|
|
|
|
|
|
|
|
2020-12-04 18:06:31 +01:00
|
|
|
router$server(input, output, session)
|
|
|
|
})
|
2020-11-27 19:14:20 +01:00
|
|
|
|
2020-12-03 11:39:38 +01:00
|
|
|
shinyApp(ui=ui,server=server)
|