Skip to content

Commit

Permalink
add button to results view to apply filter (#23)
Browse files Browse the repository at this point in the history
pass league trial period into the results to use as filter threshold
upgrade to kotlin 1.2.31

update to version 0.9.0

Signed-off-by: John Burns <[email protected]>
  • Loading branch information
wakingrufus authored Jun 19, 2018
1 parent 4210db9 commit bef01cb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
15 changes: 7 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
buildscript {
ext.kotlin_version = '1.2.21'
ext.jackson_version = '2.9.2'
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
Expand All @@ -13,7 +12,7 @@ plugins {
id 'java'
id 'application'
id 'idea'
id "org.jetbrains.kotlin.jvm" version "1.2.21"
id "org.jetbrains.kotlin.jvm" version "1.2.31"
id 'jacoco'
}
apply plugin: 'javafx-gradle-plugin'
Expand All @@ -24,10 +23,10 @@ repositories {
maven { url 'https://jitpack.io' }
}

version = "0.8.0"
version = "0.9.0"

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.17'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
Expand All @@ -38,13 +37,13 @@ dependencies {
compile "com.fasterxml.jackson.module:jackson-module-kotlin:$jackson_version"

compile 'io.github.microutils:kotlin-logging:1.4.4'
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect"
compile 'no.tornado:tornadofx:1.7.12'
compile 'no.tornado:tornadofx-controls:1.0.6'
compile 'com.github.wakingrufus:lib-elo:0.3.1'

testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test"
testCompile "org.jetbrains.kotlin:kotlin-test-junit"
testCompile 'org.mockito:mockito-core:2.8.9'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile "org.testfx:testfx-core:4.0.7-alpha"
Expand All @@ -71,7 +70,7 @@ idea {
}

task wrapper(type: Wrapper) {
gradleVersion = '4.2.1'
gradleVersion = '4.7'
}

jacocoTestReport {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class LeagueView : View("League View") {

val model: LeagueModel by inject()
val playerModel: PlayerModel by inject()
val gameModel: GameModel by inject()
val tournamentModel: SwissTournamentModel by inject()

override val root = vbox {
Expand Down Expand Up @@ -106,6 +105,7 @@ class LeagueView : View("League View") {
button("View Results").setOnAction {
val games = games(model.games.value.map(GameItem::toData))
find<ResultsView>(mapOf(
"trialPeriod" to model.item.trialPeriod,
"leagueResultItem" to results(
leagueItem = model.item,
leagueState = calculateNewLeague(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package com.github.wakingrufus.eloleague.results

import javafx.beans.property.SimpleListProperty
import javafx.collections.FXCollections
import tornadofx.getValue
import tornadofx.setValue
import tornadofx.*

class LeagueResultItem {
val playersProperty = SimpleListProperty<PlayerResultItem>(this, "players", FXCollections.observableArrayList())
var players by playersProperty

val gamesProperty = SimpleListProperty<GameResultItem>(this, "games", FXCollections.observableArrayList())
var games by gamesProperty
var games by gamesProperty
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ import tornadofx.*
class ResultsView : Fragment() {
companion object : KLogging()

val trialPeriod: Int by param(0)
val leagueResultItem: LeagueResultItem by param()
val gameResults: ObservableList<GameResultItem> = FXCollections.observableArrayList()
lateinit var playerList: SortedFilteredList<PlayerResultItem>

override val root = borderpane {

if (!this@ResultsView::playerList.isInitialized) {
playerList = SortedFilteredList(leagueResultItem.players)
}
center {
id = "results-wrapper"

val table = tableview(leagueResultItem.players) {
val table = tableview(playerList) {
id = "results-tableview"
column("Name", PlayerResultItem::nameProperty)
column("Rating", PlayerResultItem::currentRatingProperty)
column("Games", PlayerResultItem::gamesPlayedProperty)
Expand All @@ -32,6 +37,7 @@ class ResultsView : Fragment() {
table.columns[1].sortType = javafx.scene.control.TableColumn.SortType.DESCENDING
table.columns[1].sortableProperty().set(true)
table.sortOrder.add(table.columns[1])

table.sort()

table.onSelectionChange { player ->
Expand All @@ -42,14 +48,22 @@ class ResultsView : Fragment() {

}
bottom {
button("View Details") {
enableWhen { Bindings.isNotEmpty(gameResults) }
setOnAction {
find<ResultsDetailsView>(mapOf("gameResults" to gameResults)).apply {
openModal(
stageStyle = StageStyle.UTILITY,
block = true
)
buttonbar {
button("View Details") {
enableWhen { Bindings.isNotEmpty(gameResults) }
setOnAction {
find<ResultsDetailsView>(mapOf("gameResults" to gameResults)).apply {
openModal(
stageStyle = StageStyle.UTILITY,
block = true
)
}
}
}
button("Filter out trial players") {
id = "filter-newbies-button"
setOnAction {
playerList.predicate = { it.gamesPlayedProperty >= trialPeriod }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.wakingrufus.eloleague.results

import com.github.wakingrufus.eloleague.TornadoFxTest
import javafx.scene.control.TableView
import mu.KLogging
import org.junit.Test
import org.testfx.api.FxAssert
Expand All @@ -11,12 +12,20 @@ class ResultsViewTest : TornadoFxTest() {

@Test
fun test() {
val results: LeagueResultItem = LeagueResultItem()
val results: LeagueResultItem = LeagueResultItem().apply {
players.add(PlayerResultItem(id = "1", name = "1", gamesPlayed = 0, losses = 0, wins = 0, currentRating = 1500))
players.add(PlayerResultItem(id = "2", name = "2", gamesPlayed = 1, losses = 1, wins = 0, currentRating = 1490))
players.add(PlayerResultItem(id = "3", name = "3", gamesPlayed = 2, losses = 1, wins = 1, currentRating = 1501))
}
showViewWithParams<ResultsView>(mapOf(
"trialPeriod" to 1,
"leagueResultItem" to results
))

FxAssert.verifyThat("#results-wrapper", NodeMatchers.isVisible())
FxAssert.verifyThat<TableView<PlayerResultItem>>("#results-tableview", { it.items.size == 3 })
clickOn("#filter-newbies-button")
FxAssert.verifyThat<TableView<PlayerResultItem>>("#results-tableview", { it.items.size == 2 })
}

}

0 comments on commit bef01cb

Please sign in to comment.