Skip to content
Snippets Groups Projects
Commit bee2970a authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

Small fixes

parent c394169f
No related branches found
No related tags found
No related merge requests found
import kotlinx.atomicfu.AtomicInt
import kotlinx.browser.document
import kotlinx.coroutines.delay
import org.w3c.dom.HTMLDivElement
import org.w3c.dom.MutationObserver
import org.w3c.dom.MutationObserverInit
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
object PekDelay {
private val saveIconElem = document.getElementById("save-icon") as HTMLDivElement
private val isUpdating get() = saveIconElem.style.display == "block"
private val continuations = mutableListOf<Continuation<Unit>>()
private var skips = 0
fun skipNext() {
skips++
}
private val observer = MutationObserver { _, _ ->
if (!isUpdating) {
println("run called")
val conts = continuations.toList()
conts.forEach { it.resume(Unit) }
continuations.removeAll(conts)
}
}
init {
observer.observe(
saveIconElem, MutationObserverInit(
attributes = true,
attributeFilter = arrayOf("style")
)
)
}
suspend operator fun invoke() = suspendCoroutine<Unit> { cont ->
if (skips > 0) {
cont.resume(Unit)
skips--
return@suspendCoroutine
}
continuations += cont
}
}
\ No newline at end of file
......@@ -57,7 +57,11 @@ object PekTable {
elem.style.background = origBg
}
if (elem.value.toIntOrNull() == value) return
if (elem.value.toIntOrNull() == value) { // don't update if up-to-date
// sort of ugly workaround, meh.
PekDelay.skipNext()
return
}
elem.click()
elem.value = value.toString()
......
import kotlin.math.max
class ProcessingError(val errors: List<String>): Exception(errors.toString()) {
class ProcessingError(private val errors: List<String>): Exception(errors.toString()) {
override fun toString(): String {
return "Hiba történt az importálás közben:\n"+
errors.joinToString("\n")
return "${errors.size} hiba történt az importálás közben:\n\n"+
errors.joinToString("\n\n")
}
}
......@@ -29,7 +29,7 @@ suspend fun CSVTable.process(
val pekPrinciple = principleMappings[principle]!!
PekTable[pekPerson, pekPrinciple] = point
pekDelay()
PekDelay()
progress(calcProgress(i, j, people.size, principles.size))
if (person != pekPerson) {
......
import kotlinx.browser.document
import kotlinx.browser.window
import kotlinx.coroutines.delay
import org.w3c.dom.*
import org.w3c.files.Blob
import org.w3c.files.FileReader
......@@ -86,41 +84,13 @@ suspend fun PekTable.clear(
people.forEachIndexed { i, person ->
principles.forEachIndexed { j, principle ->
PekTable[person, principle] = 0
pekDelay()
PekDelay()
progress(calcProgress(i, j, people.size, principles.size))
}
}
}
private val saveIconElem = document.getElementById("save-icon") as HTMLDivElement
val isUpdating get() = saveIconElem.style.display == "block"
fun observeSaveChange(changed: () -> Unit): MutationObserver {
val observer = MutationObserver { _, _ ->
changed()
}
observer.observe(saveIconElem, MutationObserverInit(
attributes = true,
attributeFilter = arrayOf("style")
))
return observer
}
suspend fun pekDelay() = suspendCoroutine<Unit> { cont ->
lateinit var observer: MutationObserver
observer = observeSaveChange {
if (!isUpdating) {
cont.resume(Unit)
observer.disconnect()
}
}
if (!isUpdating) {
cont.resume(Unit)
observer.disconnect()
}
}
fun Double.format() = this.asDynamic().toFixed(1) as String
fun calcProgress(i: Int, j: Int, iMax: Int, jMax: Int) =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment