From 2b936636b88c6cb6aaa374e02baea94108817eef Mon Sep 17 00:00:00 2001 From: Konstantin Albatov Date: Fri, 29 Mar 2024 18:26:09 +0300 Subject: [PATCH] :medal: Last Dev --- build.gradle.kts | 1 - .../data/repository/TenderSearchRepository.kt | 4 + .../presentation/route/MainRoute.kt | 38 --- .../presentation/route/TestRoute.kt | 270 +++++++++++++++--- 4 files changed, 239 insertions(+), 74 deletions(-) delete mode 100644 src/main/kotlin/com/albatros/springsecurity/presentation/route/MainRoute.kt diff --git a/build.gradle.kts b/build.gradle.kts index de0a08a..9b25b66 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -56,7 +56,6 @@ repositories { vaadin.productionMode = System.getenv("PROD_MODE")?.toBoolean() ?: false - vaadin { forceProductionBuild = System.getenv("PROD_MODE")?.toBoolean() ?: false productionMode = System.getenv("PROD_MODE")?.toBoolean() ?: false 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..ed197ab 100644 --- a/src/main/kotlin/com/albatros/springsecurity/data/repository/TenderSearchRepository.kt +++ b/src/main/kotlin/com/albatros/springsecurity/data/repository/TenderSearchRepository.kt @@ -73,7 +73,11 @@ interface TenderSearchRepository : ElasticsearchRepository { } """ ) + + fun findAllByCategoryIgnoreCase(category: String, pageable: Pageable): List + fun fullTextSearchOr(keywords: String, exclude: String): List + fun findAllByTenderId(tenderId: String, pageable: Pageable): Page fun findAllByCustomerContainsIgnoreCase(customer: String, pageable: Pageable): Page diff --git a/src/main/kotlin/com/albatros/springsecurity/presentation/route/MainRoute.kt b/src/main/kotlin/com/albatros/springsecurity/presentation/route/MainRoute.kt deleted file mode 100644 index 055f240..0000000 --- a/src/main/kotlin/com/albatros/springsecurity/presentation/route/MainRoute.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.albatros.springsecurity.presentation.route - -import com.albatros.springsecurity.data.model.database.TenderProvider -import com.albatros.springsecurity.data.repository.TenderProviderRepository -import com.vaadin.flow.component.Text -import com.vaadin.flow.component.button.Button -import com.vaadin.flow.component.grid.Grid -import com.vaadin.flow.component.notification.Notification -import com.vaadin.flow.component.orderedlayout.VerticalLayout -import com.vaadin.flow.router.Route -import com.vaadin.flow.spring.data.VaadinSpringDataHelpers - -@Route("") -class MainRoute( - repository: TenderProviderRepository -) : VerticalLayout() { - - init { - add( - Text("Lig ma who?"), - Button( - "Lig ma Balls" - ) { - Notification.show("CDs nuts").open() - }, - Grid().apply { - addColumn(TenderProvider::tenderId).setHeader("Tender Id") - addColumn(TenderProvider::etpName).setHeader("Name") - - setItems { - repository.findAll( - VaadinSpringDataHelpers.toSpringPageRequest(it) - ).stream() - } - } - ) - } -} 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..0c52a5a 100644 --- a/src/main/kotlin/com/albatros/springsecurity/presentation/route/TestRoute.kt +++ b/src/main/kotlin/com/albatros/springsecurity/presentation/route/TestRoute.kt @@ -1,45 +1,265 @@ 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.button.Button import com.vaadin.flow.component.button.ButtonVariant import com.vaadin.flow.component.grid.Grid -import com.vaadin.flow.component.html.Paragraph +import com.vaadin.flow.component.grid.GridVariant +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.orderedlayout.HorizontalLayout import com.vaadin.flow.component.orderedlayout.VerticalLayout +import com.vaadin.flow.component.select.Select +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 - -@Route("test") +@Route("") 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 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, + ) + + val horizontalLayout = HorizontalLayout( + includeTextField, + excludeTextField, + button, + ) + + return Div( + horizontalLayout, + sheet, + ) + } + + private fun getLockedSearch(repository: TenderSearchRepository): Div { + + val select: Select = Select() + select.label = "Тип поиска" + select.setItems( + "По категории", + "По площадке", + "По тендеру", + "По покупателю", + ) + + val div = Div(getBaseTable()) + + select.addValueChangeListener { + if (select.value == "По категории") { + 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( + categoryText, + button, + ) + + div.add( + hl, + sheet, + ) + } + if (select.value == "По площадке") { + div.removeAll() + + val sheet: Grid = getBaseTable() + + val etpText = TextField() + + etpText.placeholder = "Площадка" + + val button = Button("Найти", VaadinIcon.SEARCH.create()) { + val etp = etpText.value + + sheet.setItems { + repository.findAllByEtpEqualsIgnoreCase( + etp, + VaadinSpringDataHelpers.toSpringPageRequest(it) + ).stream() + } + } + + button.addThemeVariants( + ButtonVariant.LUMO_PRIMARY, + ButtonVariant.LUMO_CONTRAST, + ) + + val hl = HorizontalLayout( + etpText, + button, + ) + + div.add( + hl, + sheet, + ) + } + if (select.value == "По тендеру") { + div.removeAll() + + val sheet: Grid = getBaseTable() + + val tenderText = TextField() + + tenderText.placeholder = "Тендер" + + val button = Button("Найти", VaadinIcon.SEARCH.create()) { + val tender = tenderText.value + + sheet.setItems { + repository.findAllByTenderNameContainingIgnoreCase( + tender, + VaadinSpringDataHelpers.toSpringPageRequest(it) + ).stream() + } + } + + button.addThemeVariants( + ButtonVariant.LUMO_PRIMARY, + ButtonVariant.LUMO_CONTRAST, + ) + + val hl = HorizontalLayout( + tenderText, + button, + ) + + div.add( + hl, + sheet, + ) + } + if (select.value == "По покупателю") { + div.removeAll() + + val sheet: Grid = getBaseTable() + + val customerText = TextField() + + customerText.placeholder = "Покупатель" + + val button = Button("Найти", VaadinIcon.SEARCH.create()) { + val customer = customerText.value + + sheet.setItems { + repository.findAllByCustomerContainsIgnoreCase( + customer, + VaadinSpringDataHelpers.toSpringPageRequest(it) + ).stream() + } + } + + button.addThemeVariants( + ButtonVariant.LUMO_PRIMARY, + ButtonVariant.LUMO_CONTRAST, + ) + + val hl = HorizontalLayout( + customerText, + button, + ) + + div.add( + hl, + sheet, + ) + } + } + + val horizontalLayout = HorizontalLayout( + select, + ) + + return Div( + horizontalLayout, + div, + ) + } + + private fun getBaseTable(): Grid { + val sheet: Grid = Grid().apply { + addColumn(Tender::tenderName) + .setHeader("Тендер") + .setSortable(true) addColumn(Tender::category) .setHeader("Категория") + .setAutoWidth(true) + .setFlexGrow(0) .setSortable(true) - addColumn(Tender::region) - .setHeader("Регион") + addColumn(Tender::etp) + .setHeader("Площадка") .setSortable(true) addColumn(Tender::customer) .setHeader("Покупатель") .setSortable(true) - addColumn(Tender::tenderName) - .setHeader("Тендер") - .setSortable(true) addColumn(Tender::date) .setHeader("Дата начала") .setAutoWidth(true) @@ -59,30 +279,10 @@ 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, + sheet.addThemeVariants( + GridVariant.LUMO_WRAP_CELL_CONTENT ) - add( - HorizontalLayout( - includeTextField, - excludeTextField, - button - ), - sheet, - ) + return sheet } }