From 0f64f92b0de029fb401c0412b26edc31f45e64c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Piskorski?= Date: Sun, 20 Dec 2020 15:46:02 +0100 Subject: [PATCH] TAK-57 edit tab --- .gitignore | 5 + app/app.R | 15 +- app/home_module.R | 7 - app/login_module.R | 12 +- app/profil_module.R | 152 +++++++++++++++++- app/register_module.R | 6 +- app/www/profile.css | 17 ++ app/www/style.css | 2 +- backend/.idea/compiler.xml | 3 + backend/.idea/workspace.xml | 35 ++-- .../src/main/java/project/DTO/UserDTO.java | 1 + .../main/java/project/config/TokenHelper.java | 2 +- .../controllers/AuthenticationController.java | 4 - .../project/controllers/UserController.java | 127 +++++++++------ .../java/project/services/UserService.java | 2 + .../project/services/UserServiceImpl.java | 26 +++ 16 files changed, 312 insertions(+), 104 deletions(-) create mode 100644 .gitignore create mode 100644 app/www/profile.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..093c99e --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea +app/.Rhistory +backend/target/ +db.sqlite +backend/.idea/ diff --git a/app/app.R b/app/app.R index fa6f856..d8f9c5c 100644 --- a/app/app.R +++ b/app/app.R @@ -18,13 +18,14 @@ ui <- fluidPage( tags$head( tags$script(src="js.cookie.js"), - tags$script('var cookie = Cookies.get(\'token\'); - $(document).on("shiny:sessioninitialized",function(event){ - Shiny.onInputChange("token", cookie);});'), - tags$script('Shiny.addCustomMessageHandler("tokenHandler", + +tags$script('var token = sessionStorage.getItem(\'token\'); + $(document).on("shiny:sessioninitialized",function(event){ + Shiny.onInputChange("token", token);});'), +tags$script('Shiny.addCustomMessageHandler("tokenHandler", function(token) { - var cookie = Cookies.set(\'token\', token, { expires: 7 }); - Shiny.onInputChange("token", cookie); + sessionStorage.setItem(\'token\', token); + Shiny.onInputChange("token", token); } );') @@ -114,7 +115,7 @@ shinyjs::onclick(id="tab1",expr = { shinyjs::removeCssClass(id="tab1",class = "clicked") shinyjs::removeCssClass(id="tab4",class = "clicked") }else{ - shinyjs::runjs( 'Cookies.remove(\'token\'); + shinyjs::runjs( 'sessionStorage.removeItem(\'token\'); Shiny.onInputChange("token", null); window.location.replace(\'/#!/login\');') diff --git a/app/home_module.R b/app/home_module.R index 208a8cc..00f8f9b 100644 --- a/app/home_module.R +++ b/app/home_module.R @@ -11,19 +11,12 @@ homeUI <- function(id) { tags$style(HTML(" @import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700'); @import url('//fonts.googleapis.com/css2?family=Fjalla+One'); - - - "))), theme = "style.css", - # App title ---- - # App title ---- - -# h4("Aplikacja wspomagajaca diagnozowanie i monitorowanie stanu zdrowia", align = "center"), fluidRow(column(12, h1("TakeCareApp"))%>% tagAppendAttributes(id = 'column-title') diff --git a/app/login_module.R b/app/login_module.R index 081ac74..bcb570e 100644 --- a/app/login_module.R +++ b/app/login_module.R @@ -13,10 +13,11 @@ loginUI <- function(id) { useShinyjs(), tags$head( tags$script(src="js.cookie.js"), - tags$script('Shiny.addCustomMessageHandler("tokenHandlerAfterLogin", + +tags$script('Shiny.addCustomMessageHandler("tokenHandlerAfterLogin", function(token) { - var cookie = Cookies.set(\'token\', token, { expires: 7 }); - Shiny.onInputChange("token", cookie); + sessionStorage.setItem(\'token\', token); + Shiny.onInputChange("token", token); window.location.replace(\'/#!/profil\'); } @@ -66,9 +67,8 @@ loginServer <- function(input, output,session) { if(r$status_code==200){ response<-(content(r)) - session$sendCustomMessage(type='tokenHandlerAfterLogin', response$token) - + session$sendCustomMessage(type='tokenHandlerAfterLogin', response$token) TRUE } @@ -95,7 +95,7 @@ loginServer <- function(input, output,session) { observe({ if(((session$clientData)$url_hash=="#!/login") & (!is.null(input$token) & length(input$token)>0 )){ - print("dziala") + shinyjs::runjs('window.location.replace(\'/#!/home\');') } }) diff --git a/app/profil_module.R b/app/profil_module.R index bc5671a..a3b9629 100644 --- a/app/profil_module.R +++ b/app/profil_module.R @@ -11,14 +11,16 @@ profilUI <- function(id) { tags$head( tags$script(src="js.cookie.js"), + tags$style(HTML(" @import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700'); @import url('//fonts.googleapis.com/css2?family=Fjalla+One'); - - "))), + ")), + tags$link(rel = "stylesheet", type = "text/css", href = "profile.css") + ), - theme = "style.css", + # theme = "style.css", # App title ---- @@ -41,21 +43,111 @@ profilServer <- function(input, output,session) { + getEditStatus <- eventReactive(input$editSubmit, { + editedPersonalData<-data.frame(name<-input$editName, + surname<-input$editSurname, + mail<-input$editMail, + datebirth<-input$editAge, + gender<-input$editGender) + + reg<-c(grepl("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,15}$",editedPersonalData$name), + grepl("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,20}$",editedPersonalData$surname), + grepl("^[a-z]+[0-9]*@([a-z]{2,10}\\.)+[a-z]{2,5}$",editedPersonalData$mail)) + if(all(reg)){ + # status$status = register(result) + + # status$first = FALSE + + + + to_send = list(name = editedPersonalData$name, + surname = editedPersonalData$surname, + email = editedPersonalData$mail, + datebirth = editedPersonalData$datebirth, + gender = editedPersonalData$gender) + + r<-httr::PUT("http://localhost:8080/api/profile",add_headers(Authorization=paste("Bearer",input$token,sep=" ")),body=to_send,encode = 'json') + + if (r$status_code==200){ + TRUE + }else{ + FALSE + } + }else{ + + FALSE + } + + + + }) + + + observe({ if(( (session$clientData)$url_hash=="#!/profil")){ - + if( (is.null(input$token) | length(input$token)<=0 )){ shinyjs::runjs('window.location.replace(\'/#!/home\');') + } + } - } + }) + + output$profileData<-renderUI({ + + r<-httr::GET("http://localhost:8080/api/profile",add_headers(Authorization=paste("Bearer",input$token,sep=" "))) + + if(r$status_code==200){ + + response<-(content(r)) + + session$sendCustomMessage(type='tokenHandlerAfterLogin', response$token) + + + fluidRow(column(12, + wellPanel( + textInput("editName", label = strong("Imie"),value=response$profil$name), + uiOutput("editName"), + textInput("editSurname", label = strong("Nazwisko"),value=response$profil$surname), + uiOutput("editSurname"), + textInput("editMail", label = strong("Adres email"),value=response$profil$email), + uiOutput("editMail"), + dateInput("editAge", label = strong("Data urodzenia") ,value=response$profil$datebirth), + + selectInput("editGender", label = strong("Plec"), + choices = list("Żenska" = 0, "Meska" = 1), + selected = as.numeric(response$profil$gender)), + + ), + + actionButton("editSubmit","Zapisz"), + uiOutput("btnEditProfile",style="color:red;") + + )) + + + } + + }) + output$btnEditProfile<-renderUI({ + + if (getEditStatus()==TRUE){ + p("OK",style="color:green;text-align:center;") + }else{ + p("Uzytkownik istnieje lub wprowadzono bledne dane",style="color:red;text-align:center;") + } + + + }) output$afterLogin<-renderUI({ @@ -70,7 +162,8 @@ profilServer <- function(input, output,session) { )%>% tagAppendAttributes(id = 'column-panel'), column(9, tabsetPanel(type = "tabs", - tabPanel("Zakładka 1", tags$div(plotlyOutput("plot1",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), + tabPanel("Dane profilowe", tags$div(uiOutput("profileData") + )%>% tagAppendAttributes(class = 'content-wrapper')), tabPanel("Zakładka 2", tags$div(plotlyOutput("plot2",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), tabPanel("Zakładka 3", tags$div(plotlyOutput("plot3",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), tabPanel("Zakładka 4", tags$div(plotlyOutput("plot4",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')), @@ -145,6 +238,53 @@ profilServer <- function(input, output,session) { output$table1 <- DT::renderDataTable(iris,options = list(scrollX = TRUE,language=pl)) + output$btnResponse<-renderUI({ + + if (getStatus()==TRUE){ + p("OK",style="color:white;text-align:center;") + }else{ + p("Uzytkownik istnieje lub wprowadzono bledne dane",style="color:yellow;text-align:center;") + } + + + }) + + output$editName<-renderUI({ + s<-toString(input$editName) + + if (s=="" | grepl("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,15}$",s)==TRUE){ + return() + }else{ + p("Bład: Imie powinno zaczynac sie od wielkiej litery, zawierac jedynie litery i miec dlugosc od 3 do 15 znaków",style="color:yellow") + } + + }) + + output$editSurname<-renderUI({ + s<-toString(input$editSurname) + + if (s=="" | grepl("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,20}$",s)==TRUE){ + return() + }else{ + p("Bład: Nazwisko powinno zaczynac sie od wielkiej litery, zawierac jedynie litery i miec dlugosc od 3 do 15 znaków",style="color:yellow") + + + } + + }) + + output$editMail<-renderUI({ + s<-toString(input$editMail) + + if (s=="" | grepl("^[a-z]+[0-9]*@([a-z]{2,10}\\.)+[a-z]{2,5}$",s)==TRUE){ + return() + }else{ + p("Bład: Mail powinien miec budowe adres@nazwa.domena",style="color:yellow") + + + } + + }) diff --git a/app/register_module.R b/app/register_module.R index 6928565..d140737 100644 --- a/app/register_module.R +++ b/app/register_module.R @@ -44,7 +44,7 @@ registerServer <- function(input, output,session) { observe({ if(((session$clientData)$url_hash=="#!/register") & (!is.null(input$token) & length(input$token)>0 )){ - print("dziala") + shinyjs::runjs('window.location.replace(\'/#!/home\');') } }) @@ -67,7 +67,7 @@ registerServer <- function(input, output,session) { grepl("^([a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]+[0-9\\-\\_]*){5,20}$",result$username), grepl("^([a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{5,}[0-9]{5,}[a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż0-9]*)+$",result$password)) if(all(reg) & all(result$permission==c(1,2))){ - # status$status = register(result) + status$first = FALSE @@ -80,7 +80,7 @@ registerServer <- function(input, output,session) { password= result$password, roleDTO= "IND") r<-httr::POST("http://localhost:8080/api/register",body=to_send,encode = 'json') - print(content(r, "text")) + if (r$status_code==200){ status$status = TRUE }else{ diff --git a/app/www/profile.css b/app/www/profile.css new file mode 100644 index 0000000..55e470a --- /dev/null +++ b/app/www/profile.css @@ -0,0 +1,17 @@ +#profileData{ + display:flex; + justify-content:center; + +} + +#profileData > .row,#profileData > .row > .well{ + width:100%; +} + +#profileData > .row .well{ + #display:flex; + color:white; + background-color:#00A896; + +} + diff --git a/app/www/style.css b/app/www/style.css index a69da1f..b6ef093 100644 --- a/app/www/style.css +++ b/app/www/style.css @@ -281,7 +281,7 @@ font-family:Fjalla One; justify-content: center; } -#submit,#loginBtn{ +#submit,#loginBtn,#editSubmit{ margin-top:20px; align-self:center; min-width:25%; diff --git a/backend/.idea/compiler.xml b/backend/.idea/compiler.xml index eff75d1..6fd036f 100644 --- a/backend/.idea/compiler.xml +++ b/backend/.idea/compiler.xml @@ -12,6 +12,9 @@ + + +