From b08609bec814cb7fbd0104fc99df3c111539bb13 Mon Sep 17 00:00:00 2001 From: AkkaRin11 Date: Tue, 26 Mar 2024 19:11:28 +0300 Subject: [PATCH 1/7] :ambulance: modified ui --- .../data/repository/TenderSearchRepository.kt | 6 + .../presentation/route/TestRoute.kt | 199 +++++++++++++++--- 2 files changed, 174 insertions(+), 31 deletions(-) diff --git a/src/main/kotlin/com/albatros/springsecurity/data/repository/TenderSearchRepository.kt b/src/main/kotlin/com/albatros/springsecurity/data/repository/TenderSearchRepository.kt index 3532378..53072b6 100644 --- a/src/main/kotlin/com/albatros/springsecurity/data/repository/TenderSearchRepository.kt +++ b/src/main/kotlin/com/albatros/springsecurity/data/repository/TenderSearchRepository.kt @@ -80,6 +80,12 @@ interface TenderSearchRepository : ElasticsearchRepository { fun findAllByRegionContainsIgnoreCase(region: String, pageable: Pageable): Page + + fun findAllByRegion(region: String, pageable: Pageable): Page + fun findAllByRegionIgnoreCase(region: String, pageable: Pageable): Page + + fun findAllByCategoryIgnoreCase(category: String, pageable: Pageable): Page + fun findAllByCategory(category: String, pageable: Pageable): Page fun findAllByEtpEqualsIgnoreCase(etp: String, pageable: Pageable): Page diff --git a/src/main/kotlin/com/albatros/springsecurity/presentation/route/TestRoute.kt b/src/main/kotlin/com/albatros/springsecurity/presentation/route/TestRoute.kt index 645c260..9478ea5 100644 --- a/src/main/kotlin/com/albatros/springsecurity/presentation/route/TestRoute.kt +++ b/src/main/kotlin/com/albatros/springsecurity/presentation/route/TestRoute.kt @@ -1,32 +1,193 @@ package com.albatros.springsecurity.presentation.route import com.albatros.springsecurity.data.model.database.Tender -import com.albatros.springsecurity.data.model.database.TenderProvider -import com.albatros.springsecurity.data.repository.TenderProviderRepository import com.albatros.springsecurity.data.repository.TenderSearchRepository -import com.vaadin.flow.component.Text +import com.vaadin.flow.component.ClickEvent +import com.vaadin.flow.component.ComponentEventListener import com.vaadin.flow.component.button.Button import com.vaadin.flow.component.button.ButtonVariant +import com.vaadin.flow.component.contextmenu.MenuItem import com.vaadin.flow.component.grid.Grid -import com.vaadin.flow.component.html.Paragraph +import com.vaadin.flow.component.html.Div import com.vaadin.flow.component.icon.VaadinIcon -import com.vaadin.flow.component.notification.Notification +import com.vaadin.flow.component.menubar.MenuBar +import com.vaadin.flow.component.menubar.MenuBarVariant import com.vaadin.flow.component.orderedlayout.HorizontalLayout import com.vaadin.flow.component.orderedlayout.VerticalLayout +import com.vaadin.flow.component.tabs.TabSheet import com.vaadin.flow.component.textfield.TextField import com.vaadin.flow.router.Route import com.vaadin.flow.spring.data.VaadinSpringDataHelpers - +import org.springframework.data.domain.Pageable @Route("test") class TestRoute(repository: TenderSearchRepository) : VerticalLayout() { init { + + val tabSheet = TabSheet().apply { + width = "100%" + } + + tabSheet.add( + "Свободный поиск", + getWildSearch(repository), + ) + + tabSheet.add( + "Поиск по столбцам", + Div( + getLockedSearch(repository), + ) + ) + + add( + tabSheet + ) + } + + private fun getWildSearch(repository: TenderSearchRepository): Div { val includeTextField = TextField() val excludeTextField = TextField() includeTextField.placeholder = "Ключевые слова" excludeTextField.placeholder = "Нежелательные слова" + val sheet: Grid = getBaseTable() + +// val dialog = Dialog().apply { +// headerTitle = "Test" +// } + + val button = Button("Найти", VaadinIcon.SEARCH.create()) { + val includeText = includeTextField.value + val excludeText = excludeTextField.value + +// dialog.open() + + sheet.setItems( + repository.fullTextSearchOr( + includeText, + excludeText, + ) + ) + } + + button.addThemeVariants( + ButtonVariant.LUMO_PRIMARY, + ButtonVariant.LUMO_CONTRAST, + ) + + val horizontalLayout = HorizontalLayout( + includeTextField, + excludeTextField, + button, + ) + + return Div( + horizontalLayout, + sheet, +// dialog + ) + } + + // нейминг отдыхает + private fun getLockedSearch(repository: TenderSearchRepository): Div { + val menuBar = MenuBar() + val div = Div(getBaseTable()) + val listener1: ComponentEventListener> = + ComponentEventListener> { + div.removeAll() // плохой код, потом переделать + + val sheet: Grid = getBaseTable() + + val categoryText = TextField() + categoryText.placeholder = "Категория" + + val button = Button("Найти", VaadinIcon.SEARCH.create()) { + val category = categoryText.value + + sheet.setItems { + repository.findAllByCategoryIgnoreCase( + category, + VaadinSpringDataHelpers.toSpringPageRequest(it) + ).stream() + } + } + + button.addThemeVariants( + ButtonVariant.LUMO_PRIMARY, + ButtonVariant.LUMO_CONTRAST, + ) + + val hl = HorizontalLayout( + menuBar, + categoryText, + button, + ) + + div.add( + hl, + sheet, + ) + } + + val listener2: ComponentEventListener> = + ComponentEventListener> { + div.removeAll() // плохой код, потом переделать + + val sheet: Grid = getBaseTable() + + val regionText = TextField() + + regionText.placeholder = "Регион" + + val button = Button("Найти", VaadinIcon.SEARCH.create()) { + val region = regionText.value + + sheet.setItems { + repository.findAllByRegionIgnoreCase( + region, + VaadinSpringDataHelpers.toSpringPageRequest(it) + ).stream() + } + } + + button.addThemeVariants( + ButtonVariant.LUMO_PRIMARY, + ButtonVariant.LUMO_CONTRAST, + ) + + val hl = HorizontalLayout( + menuBar, + regionText, + button, + ) + + div.add( + hl, + sheet, + ) + } + + menuBar.addItem("Поиск по категории", listener1) + menuBar.addItem("Поиск по регионам", listener2) + + menuBar.addThemeVariants( + MenuBarVariant.LUMO_PRIMARY, + MenuBarVariant.LUMO_CONTRAST, + ) + + val horizontalLayout = HorizontalLayout( + menuBar, + ) + + return Div( + horizontalLayout, + div, + ) + } + + private fun getBaseTable(): Grid { val sheet: Grid = Grid().apply { addColumn(Tender::category) .setHeader("Категория") @@ -59,30 +220,6 @@ class TestRoute(repository: TenderSearchRepository) : VerticalLayout() { height = "600px" } - val button = Button("Найти", VaadinIcon.SEARCH.create()){ - val includeText = includeTextField.value - val excludeText = excludeTextField.value - - sheet.setItems( - repository.fullTextSearchOr( - includeText, - excludeText, - ) - ) - } - - button.addThemeVariants( - ButtonVariant.LUMO_PRIMARY, - ButtonVariant.LUMO_CONTRAST, - ) - - add( - HorizontalLayout( - includeTextField, - excludeTextField, - button - ), - sheet, - ) + return sheet } } From 913402d405d9dfd7c5a3e8d94578c93cdbf8fc9c Mon Sep 17 00:00:00 2001 From: Konstantin Albatov Date: Tue, 26 Mar 2024 19:19:29 +0300 Subject: [PATCH 2/7] :zap: production mode env check --- build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 857dab0..8c15630 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -54,11 +54,11 @@ repositories { maven { setUrl("https://maven.vaadin.com/vaadin-addons") } } -vaadin.productionMode = true +vaadin.productionMode = System.getenv("PROD_MODE")?.toBoolean() ?: false vaadin { - forceProductionBuild = true - productionMode = true + forceProductionBuild = System.getenv("PROD_MODE")?.toBoolean() ?: false + productionMode = System.getenv("PROD_MODE")?.toBoolean() ?: false } dependencies { From 0af0c6904ebd95b467e05952ce3c55aa5d24adce Mon Sep 17 00:00:00 2001 From: Konstantin Albatov Date: Tue, 26 Mar 2024 19:23:16 +0300 Subject: [PATCH 3/7] :zap: production mode env check --- src/main/resources/application.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 3023ee0..2d21db1 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -88,7 +88,7 @@ tender-config: timeout-ms: 10000 vaadin: - productionMode: true + productionMode: ${PROD_MODE:false} original: frontend: resources: true From ac363d005466a79356ce3e65f8b0bdb105076737 Mon Sep 17 00:00:00 2001 From: Konstantin Albatov Date: Tue, 26 Mar 2024 20:00:01 +0300 Subject: [PATCH 4/7] :zap: production mode env check --- build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8c15630..de0a08a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -56,6 +56,7 @@ repositories { vaadin.productionMode = System.getenv("PROD_MODE")?.toBoolean() ?: false + vaadin { forceProductionBuild = System.getenv("PROD_MODE")?.toBoolean() ?: false productionMode = System.getenv("PROD_MODE")?.toBoolean() ?: false @@ -74,7 +75,7 @@ dependencies { // Vaadin implementation("com.vaadin:vaadin-spring-boot-starter") { - if (vaadin.effective.productionMode.get()) { + if (System.getenv("PROD_MODE")?.toBoolean() == true) { exclude(module = "vaadin-dev") } } From a818f8f7721dc7a5e738fc57600ab746a4fb973e Mon Sep 17 00:00:00 2001 From: Konstantin Albatov Date: Tue, 26 Mar 2024 19:19:29 +0300 Subject: [PATCH 5/7] :zap: production mode env check --- build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 857dab0..8c15630 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -54,11 +54,11 @@ repositories { maven { setUrl("https://maven.vaadin.com/vaadin-addons") } } -vaadin.productionMode = true +vaadin.productionMode = System.getenv("PROD_MODE")?.toBoolean() ?: false vaadin { - forceProductionBuild = true - productionMode = true + forceProductionBuild = System.getenv("PROD_MODE")?.toBoolean() ?: false + productionMode = System.getenv("PROD_MODE")?.toBoolean() ?: false } dependencies { From b5df817bd111b2c3e6a62f59031c55859dd84eb9 Mon Sep 17 00:00:00 2001 From: Konstantin Albatov Date: Tue, 26 Mar 2024 19:23:16 +0300 Subject: [PATCH 6/7] :zap: production mode env check --- src/main/resources/application.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 3023ee0..2d21db1 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -88,7 +88,7 @@ tender-config: timeout-ms: 10000 vaadin: - productionMode: true + productionMode: ${PROD_MODE:false} original: frontend: resources: true From 49b553050638efc9359132706647a9e5d706c6ea Mon Sep 17 00:00:00 2001 From: Konstantin Albatov Date: Tue, 26 Mar 2024 20:00:01 +0300 Subject: [PATCH 7/7] :zap: production mode env check --- build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8c15630..de0a08a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -56,6 +56,7 @@ repositories { vaadin.productionMode = System.getenv("PROD_MODE")?.toBoolean() ?: false + vaadin { forceProductionBuild = System.getenv("PROD_MODE")?.toBoolean() ?: false productionMode = System.getenv("PROD_MODE")?.toBoolean() ?: false @@ -74,7 +75,7 @@ dependencies { // Vaadin implementation("com.vaadin:vaadin-spring-boot-starter") { - if (vaadin.effective.productionMode.get()) { + if (System.getenv("PROD_MODE")?.toBoolean() == true) { exclude(module = "vaadin-dev") } }