Skip to content

Commit

Permalink
fixes #120 (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-claw authored Sep 14, 2023
1 parent a362a3f commit d8cba97
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package me.mnlr.vripper.view

import javafx.application.Platform
import reactor.core.scheduler.Schedulers

val FxScheduler = Schedulers.fromExecutor(Platform::runLater)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import me.mnlr.vripper.controller.ImageController
import me.mnlr.vripper.event.Event
import me.mnlr.vripper.event.EventBus
import me.mnlr.vripper.model.ImageModel
import me.mnlr.vripper.view.FxScheduler
import tornadofx.*

class ImagesTableView : Fragment("Photos") {
Expand All @@ -27,31 +28,31 @@ class ImagesTableView : Fragment("Photos") {
runLater {
items.addAll(imageController.findImages(postId))
tableView.sort()
}

val disposable = eventBus.flux()
.filter { it!!.kind == Event.Kind.IMAGE_UPDATE }
.subscribe { event ->
imageController
.findImageById(event!!.data as Long)
.filter { it.postId == postId }
.ifPresent {
// search
val find = items
.find { image -> image.id == it.id }
if (find != null) {
find.apply {
progress = it.progress
status = it.status
}
} else {
items.add(it)
}
}
val disposable = eventBus
.flux()
.filter { it!!.kind == Event.Kind.IMAGE_UPDATE }
.map { imageController.findImageById(it!!.data as Long) }
.filter { it.isPresent }
.map { it.get() }
.filter { it.postId == postId }
.publishOn(FxScheduler)
.subscribe {
val find = items
.find { image -> image.id == it.id }
if (find != null) {
find.apply {
progress = it.progress
status = it.status
}
} else {
items.add(it)
}

whenUndocked {
disposable.dispose()
}

whenUndocked {
disposable.dispose()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import me.mnlr.vripper.controller.LogController
import me.mnlr.vripper.event.Event
import me.mnlr.vripper.event.EventBus
import me.mnlr.vripper.model.LogModel
import me.mnlr.vripper.view.FxScheduler
import tornadofx.*

class LogTableView : View() {
Expand All @@ -29,28 +30,33 @@ class LogTableView : View() {
})
items.addAll(logController.findAll())

eventBus.flux()
.doOnNext { event ->
if (event!!.kind.equals(Event.Kind.LOG_EVENT_UPDATE)) {
logController.find(event.data as Long)
.ifPresent {
// search
val find = items
.find { threadModel -> threadModel.id == it.id }
if (find != null) {
find.apply {
status = it.status
message = it.message
}
} else {
items.add(it)
}
}
} else if (event.kind.equals(Event.Kind.LOG_EVENT_REMOVE)) {
items.removeIf { it.id == event.data }
eventBus
.flux()
.filter { it!!.kind == Event.Kind.LOG_EVENT_UPDATE }
.map { logController.find(it.data as Long) }
.filter { it.isPresent }
.map { it.get() }
.publishOn(FxScheduler)
.subscribe {
val find = items
.find { threadModel -> threadModel.id == it.id }
if (find != null) {
find.apply {
status = it.status
message = it.message
}
} else {
items.add(it)
}
}
.subscribe()

eventBus
.flux()
.filter { it.kind == Event.Kind.LOG_EVENT_REMOVE }
.publishOn(FxScheduler)
.subscribe { event ->
items.removeIf { it.id == event.data }
}
}

override fun onDock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import me.mnlr.vripper.event.Event
import me.mnlr.vripper.event.EventBus
import me.mnlr.vripper.model.PostModel
import me.mnlr.vripper.utils.Shell32
import me.mnlr.vripper.view.FxScheduler
import tornadofx.*


Expand All @@ -32,11 +33,14 @@ class PostsTableView : View() {
})
items.addAll(postController.findAllPosts())

eventBus.flux().filter {
it!!.kind == Event.Kind.POST_UPDATE || it.kind == Event.Kind.METADATA_UPDATE
}.subscribe { event ->
postController.findById(event!!.data as Long).ifPresent {
// search
eventBus
.flux()
.filter { it!!.kind == Event.Kind.POST_UPDATE || it.kind == Event.Kind.METADATA_UPDATE }
.map { postController.findById(it!!.data as Long) }
.filter { it.isPresent }
.map { it.get() }
.publishOn(FxScheduler)
.subscribe {
val find = items.find { postModel -> postModel.postId == it.postId }
if (find != null) {
find.apply {
Expand All @@ -49,19 +53,17 @@ class PostsTableView : View() {
}
} else {
items.add(it)
runLater {
this.tableView.refresh()
}
this.tableView.refresh()
}
}

}

eventBus.flux().filter {
it!!.kind == Event.Kind.POST_REMOVE
}.subscribe { event ->
items.removeIf { p -> p.postId == event.data as String }
}
eventBus
.flux()
.filter { it!!.kind == Event.Kind.POST_REMOVE }
.publishOn(FxScheduler)
.subscribe {
items.removeIf { p -> p.postId == it.data as String }
}
}

override fun onDock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import me.mnlr.vripper.controller.ThreadController
import me.mnlr.vripper.event.Event
import me.mnlr.vripper.event.EventBus
import me.mnlr.vripper.model.ThreadModel
import me.mnlr.vripper.view.FxScheduler
import tornadofx.*

class ThreadTableView : View() {
Expand All @@ -29,35 +30,39 @@ class ThreadTableView : View() {
})
items.addAll(threadController.findAll())

eventBus.flux()
.filter { it!!.kind == Event.Kind.THREAD_UPDATE || it.kind == Event.Kind.THREAD_REMOVE || it.kind == Event.Kind.THREAD_CLEAR }
.subscribe { event ->
when (event!!.kind) {
Event.Kind.THREAD_UPDATE -> {
threadController.find(event.data as Long).ifPresent {
// search
val find =
items.find { threadModel -> threadModel.threadId == it.threadId }
if (find != null) {
find.apply {
total = it.total
}
} else {
items.add(it)
}
}
}

Event.Kind.THREAD_REMOVE -> {
tableView.items.removeIf { it.threadId == event.data as String }
eventBus
.flux()
.filter { it!!.kind == Event.Kind.THREAD_UPDATE }
.map { threadController.find(it.data as Long) }
.filter { it.isPresent }
.map { it.get() }
.publishOn(FxScheduler)
.subscribe {
val find =
items.find { threadModel -> threadModel.threadId == it.threadId }
if (find != null) {
find.apply {
total = it.total
}
} else {
items.add(it)
}
}

Event.Kind.THREAD_CLEAR -> {
tableView.items.clear()
}
eventBus
.flux()
.filter { it.kind == Event.Kind.THREAD_REMOVE }
.publishOn(FxScheduler)
.subscribe { event ->
tableView.items.removeIf { it.threadId == event.data as String }
}

else -> {}
}
eventBus
.flux()
.filter { it.kind == Event.Kind.THREAD_CLEAR }
.publishOn(FxScheduler)
.subscribe {
tableView.items.clear()
}
}

Expand Down

0 comments on commit d8cba97

Please sign in to comment.