Skip to content

Commit

Permalink
Merge pull request #5 from AlbatovK/dev
Browse files Browse the repository at this point in the history
💯 Dev
  • Loading branch information
AlbatovK authored Mar 26, 2024
2 parents e99bcce + 5b3f696 commit 40033f9
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 36 deletions.
9 changes: 5 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ 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 {
Expand All @@ -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")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ interface TenderSearchRepository : ElasticsearchRepository<Tender, String> {

fun findAllByRegionContainsIgnoreCase(region: String, pageable: Pageable): Page<Tender>


fun findAllByRegion(region: String, pageable: Pageable): Page<Tender>
fun findAllByRegionIgnoreCase(region: String, pageable: Pageable): Page<Tender>

fun findAllByCategoryIgnoreCase(category: String, pageable: Pageable): Page<Tender>

fun findAllByCategory(category: String, pageable: Pageable): Page<Tender>

fun findAllByEtpEqualsIgnoreCase(etp: String, pageable: Pageable): Page<Tender>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Tender> = 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<ClickEvent<MenuItem>> =
ComponentEventListener<ClickEvent<MenuItem>> {
div.removeAll() // плохой код, потом переделать

val sheet: Grid<Tender> = 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<ClickEvent<MenuItem>> =
ComponentEventListener<ClickEvent<MenuItem>> {
div.removeAll() // плохой код, потом переделать

val sheet: Grid<Tender> = 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<Tender> {
val sheet: Grid<Tender> = Grid<Tender>().apply {
addColumn(Tender::category)
.setHeader("Категория")
Expand Down Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ tender-config:
timeout-ms: 10000

vaadin:
productionMode: true
productionMode: ${PROD_MODE:false}
original:
frontend:
resources: true
Expand Down

0 comments on commit 40033f9

Please sign in to comment.