Skip to content

Commit

Permalink
Merge pull request #4 from AkkaRin11/ui
Browse files Browse the repository at this point in the history
🚑 modified ui
  • Loading branch information
AlbatovK authored Mar 26, 2024
2 parents ac363d0 + 49b5530 commit 5b3f696
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 31 deletions.
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
}
}

0 comments on commit 5b3f696

Please sign in to comment.