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

Fix off by one

parent b3ea7c50
No related branches found
No related tags found
No related merge requests found
...@@ -9,17 +9,17 @@ import pekstuff.trimAsPrinciple ...@@ -9,17 +9,17 @@ import pekstuff.trimAsPrinciple
import kotlin.coroutines.resume import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine import kotlin.coroutines.suspendCoroutine
class GSheet private constructor(sheet: sheets.Spreadsheet): DataSource, NoteDataSource { class GSheet private constructor(sheet: sheets.Spreadsheet, sheetNum: Int = 0): DataSource, NoteDataSource {
companion object { companion object {
private val filterList = listOf( private val filterList = listOf(
"szumma", "színes belépő" "szumma", "színes belépő"
) )
suspend fun new(url: String): GSheet { suspend fun new(url: String, sheetNum: Int = 0): GSheet {
if (!isSignedIn) throw Error("You must sign in to get gapi.sheets") if (!isSignedIn) throw Error("You must sign in to get gapi.sheets")
val sheet = getSheetFromUrl(url) val sheet = getSheetFromUrl(url)
window.asDynamic().test = sheet window.asDynamic().test = sheet
return GSheet(sheet) return GSheet(sheet, sheetNum)
} }
@NoLiveLiterals @NoLiveLiterals
...@@ -36,7 +36,7 @@ class GSheet private constructor(sheet: sheets.Spreadsheet): DataSource, NoteDat ...@@ -36,7 +36,7 @@ class GSheet private constructor(sheet: sheets.Spreadsheet): DataSource, NoteDat
} }
} }
private val rows = sheet.sheets!![0].data!![0].rowData!! private val rows = sheet.sheets!![sheetNum].data!![0].rowData!!
private val principleIndexes = rows[0].values!!.mapIndexed { i, data -> private val principleIndexes = rows[0].values!!.mapIndexed { i, data ->
(data.formattedValue?.trimAsPrinciple() ?: "") to i (data.formattedValue?.trimAsPrinciple() ?: "") to i
......
...@@ -37,6 +37,7 @@ private object SheetsModal: ModalType { ...@@ -37,6 +37,7 @@ private object SheetsModal: ModalType {
} }
var sheetUrl by remember { mutableStateOf("") } var sheetUrl by remember { mutableStateOf("") }
var sheetNum by remember { mutableStateOf(1) }
var sheet by remember { mutableStateOf<GSheet?>(null) } var sheet by remember { mutableStateOf<GSheet?>(null) }
setHint( setHint(
...@@ -86,13 +87,26 @@ private object SheetsModal: ModalType { ...@@ -86,13 +87,26 @@ private object SheetsModal: ModalType {
value(sheetUrl) value(sheetUrl)
}) })
} }
withLabel("Hányadik sheet (fül)") { id ->
Input(type = InputType.Number, attrs = {
id(id)
classes("uk-input")
onInput {
sheetNum = it.value?.toInt() ?: return@onInput
if (sheetNum <= 0) {
sheetNum = 1
}
}
value(sheetNum)
})
}
Hr { } Hr { }
divFloatRight { divFloatRight {
Button({ Button({
classes("uk-button", "uk-button-primary") classes("uk-button", "uk-button-primary")
onClick { onClick {
scope.launch { scope.launch {
sheet = GSheet.new(sheetUrl) sheet = GSheet.new(sheetUrl, sheetNum-1)
sheet?.process { setState(ImportInProgress(it)) } sheet?.process { setState(ImportInProgress(it)) }
setState(Ready) setState(Ready)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment