Skip to content

Commit 90425fb

Browse files
committed
fix checkbox
1 parent 9196bc6 commit 90425fb

File tree

6 files changed

+57
-15
lines changed

6 files changed

+57
-15
lines changed

backend/src/main/kotlin/alfio/pi/manager/KVStore.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import ch.digitalfondue.synckv.SyncKV
55
import ch.digitalfondue.synckv.SyncKVTable
66
import com.google.gson.Gson
77
import org.jgroups.util.Tuple
8+
import org.slf4j.Logger
9+
import org.slf4j.LoggerFactory
810
import org.springframework.stereotype.Component
911
import java.time.Instant
1012
import java.time.ZoneId
1113
import java.time.ZonedDateTime
1214
import java.util.*
1315
import kotlin.collections.ArrayList
1416

17+
private val logger: Logger = LoggerFactory.getLogger("alfio.pi.manager.KVStore")
18+
1519
@Component
1620
open class KVStore(private val gson: Gson) {
1721

@@ -259,6 +263,7 @@ open class KVStore(private val gson: Gson) {
259263

260264
fun loadLabelConfiguration(eventKey: String) : Optional<LabelConfiguration> {
261265
val res = labelConfigurationTable.getAsString(eventKey)
266+
logger.trace("loaded labelConfiguration: {}", res)
262267
return if (res == null) {
263268
Optional.empty()
264269
} else {

backend/src/main/kotlin/alfio/pi/manager/LabelManager.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,19 @@ open class ZebraZD410: LabelTemplate {
141141
val font = fontLoader.invoke(ZebraZD410::class.java.getResourceAsStream("/font/DejaVuSansMono.ttf"))
142142
stream.use {
143143
it.transform(Matrix(0F, 1F, -1F, 0F, pageWidth, 0F))
144-
val firstRowContent = optimizeText(labelContent.firstRow, arrayOf(11 to 26F, 12 to 24F, 14 to 22F, 15 to 20F, 17 to 18F), true)
144+
val firstRowContent = optimizeText(labelContent.firstRow, arrayOf(11 to 26F, 12 to 24F, 14 to 22F, 15 to 20F, 16 to 18F, 17 to 17F), true)
145145
it.setFont(font, firstRowContent.second)
146146
it.beginText()
147147
it.newLineAtOffset(10F, 115F)
148148
it.showText(firstRowContent.first)
149-
val secondRowContent = optimizeText(labelContent.secondRow, arrayOf(16 to 18F, 18 to 16F, 21 to 14F), true)
149+
val secondRowContent = optimizeText(labelContent.secondRow, arrayOf(16 to 18F, 17 to 17F, 18 to 16F, 21 to 14F), true)
150150

151151
it.setFont(font, secondRowContent.second)
152152
it.newLineAtOffset(0F, -25F)
153153
it.showText(secondRowContent.first)
154154

155-
val maxLengthAdditionalRows = arrayOf(29 to 10F)
156-
printAdditionalRows(labelContent.additionalRows.orEmpty().take(3), it, -20F, labelContent, font, maxLengthAdditionalRows)
155+
val maxLengthAdditionalRows = arrayOf(20 to 11F, 29 to 10F)
156+
printAdditionalRows(labelContent.additionalRows.orEmpty().take(3), it, -25F, labelContent, font, maxLengthAdditionalRows)
157157

158158
it.endText()
159159

backend/src/main/kotlin/alfio/pi/manager/LocalResourceManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ fun reprintBadge(scanLogId: String, printerId: Int?, username: String, content:
116116
else -> Optional.empty()
117117
}
118118
}.map { (printer, ticket, eventKey) ->
119-
val labelConfiguration = kvStore.loadLabelConfiguration(eventKey).map { LabelConfigurationAndContent(it, content) }.orElse(LabelConfigurationAndContent(null, content))
119+
val labelConfiguration = kvStore.loadLabelConfiguration(eventKey).map {
120+
LabelConfigurationAndContent(it, content?.copy(checkbox = it.layout?.content?.checkbox ?: false))
121+
}.orElse(LabelConfigurationAndContent(null, content))
120122
printManager.printLabel(printer, ticket, labelConfiguration)
121123
}.orElse(false)
122124
}, {

backend/src/main/kotlin/alfio/pi/manager/PrintManager.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import javax.jmdns.ServiceListener
4141
import javax.net.ssl.SSLContext
4242
import javax.net.ssl.X509TrustManager
4343

44+
internal const val STATIC_TEXT_PREFIX = "static-text:"
45+
private const val MDNS_NAME = "alfio-server"
4446

4547
private val logger = LoggerFactory.getLogger(PrintManager::class.java)
4648

@@ -60,7 +62,6 @@ open class PrinterAnnouncer(private val trustManager: X509TrustManager,
6062
private val gson: Gson) {
6163

6264
private val masterUrl = AtomicReference<String>()
63-
private val MDNS_NAME = "alfio-server"
6465

6566
init {
6667

@@ -193,17 +194,24 @@ open class LocalPrintManager(private val labelTemplates: List<LabelTemplate>,
193194
val ticketInfo = getAllTicketInfo(ticket)
194195
val firstRow = ticketInfo[layout.content.firstRow] ?: ticket.firstName
195196
val secondRow = ticketInfo[layout.content.secondRow] ?: ticket.lastName
196-
ConfigurableLabelContent(firstRow, secondRow, retrieveAllAdditionalInfo(layout, ticket), qrContent, partialID)
197+
ConfigurableLabelContent(firstRow, secondRow, retrieveAllAdditionalInfo(layout, ticket), qrContent, partialID, layout.content.checkbox?:false)
197198
} else {
198-
ConfigurableLabelContent(ticket.firstName, ticket.lastName, listOf(ticket.additionalInfo?.get("company").orEmpty()), ticket.uuid, ticket.uuid.substringBefore('-').toUpperCase())
199+
ConfigurableLabelContent(ticket.firstName, ticket.lastName, listOf(ticket.additionalInfo?.get("company").orEmpty()), ticket.uuid, ticket.uuid.substringBefore('-').toUpperCase(), false)
199200
}
200201
}
201202

202-
private fun retrieveAllAdditionalInfo(layout: LabelLayout, ticket: Ticket) : List<String> =
203-
layout.content.thirdRow.orEmpty().asSequence()
203+
private fun retrieveAllAdditionalInfo(layout: LabelLayout, ticket: Ticket) : List<String> {
204+
return layout.content.thirdRow.orEmpty().asSequence()
204205
.plus(layout.content.additionalRows.orEmpty())
205206
.filter { it.isNotEmpty() }
206-
.map { ticket.additionalInfo?.get(it).orEmpty() }.toList()
207+
.map {
208+
if(it.startsWith(STATIC_TEXT_PREFIX)) {
209+
it.substringAfter(":", "")
210+
} else {
211+
ticket.additionalInfo?.get(it).orEmpty()
212+
}
213+
}.toList()
214+
}
207215

208216
private fun retrieveQRCodeContent(layout: LabelLayout, ticket: Ticket) : List<String> {
209217
val info = getAllTicketInfo(ticket)
@@ -321,7 +329,7 @@ data class ConfigurableLabelContent(val firstRow: String,
321329
val additionalRows: List<String>?,
322330
val qrContent: String,
323331
val partialID: String,
324-
val checkbox: Boolean = false)
332+
val checkbox: Boolean)
325333

326334

327335

backend/src/main/kotlin/alfio/pi/model/ScanModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ data class UserAndPrinter(@Column("username") private val username: String,
8585
val printer = Printer(printerId, printerName, printerDescription, printerActive)
8686
}
8787

88-
data class LabelConfiguration(@Column("event_key_fk") val eventKey: String, @Column("json") val json: String?, @Column("enabled") val enabled: Boolean) : Serializable {
88+
data class LabelConfiguration(@Column("event_key_fk") val eventKey: String,
89+
@Column("json") val json: String?,
90+
@Column("enabled") val enabled: Boolean) : Serializable {
8991
val layout: LabelLayout? = GsonContainer.GSON?.fromJson(json, LabelLayout::class.java)
9092
}
9193

backend/src/test/kotlin/alfio/pi/manager/LabelManagerTest.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ package alfio.pi.manager
2020
import alfio.pi.model.LabelLayout
2121
import alfio.pi.model.Ticket
2222
import com.google.gson.Gson
23-
import org.junit.Assert.assertEquals
24-
import org.junit.Assert.assertTrue
23+
import org.junit.Assert.*
2524
import org.junit.Test
2625
import org.mockito.Mockito
2726
import java.util.*
@@ -115,6 +114,32 @@ class LabelManagerTest {
115114
assertTrue(result.partialID.isEmpty())
116115
}
117116

117+
@Test
118+
fun testBuildLabelWithStaticText() {
119+
val localPrintManager = LocalPrintManager(emptyList(), Mockito.mock(SystemEventHandler::class.java), Mockito.mock(KVStore::class.java))
120+
val jsonString = """
121+
{
122+
"qrCode": {
123+
"additionalInfo": ["firstName", "lastName", "fullName", "emailAddress", "word1","word2","word3"],
124+
"infoSeparator": "::"
125+
},
126+
"content": {
127+
"additionalRows": ["word1", "${STATIC_TEXT_PREFIX}this is a test"]
128+
},
129+
"general": {
130+
"printPartialID": true
131+
}
132+
}"""
133+
val labelLayout = Gson().fromJson(jsonString, LabelLayout::class.java)
134+
val ticket = ticket(mapOf("word1" to "thisIsTheFirstWord", "word2" to "thisIsTheSecondWord", "word3" to "thisIsTheThirdWord"))
135+
val result = localPrintManager.buildConfigurableLabelContent(labelLayout, ticket)
136+
assertEquals(ticket.firstName, result.firstRow)
137+
assertEquals(ticket.lastName, result.secondRow)
138+
assertEquals("thisIsTheFirstWord this is a test", result.additionalRows.orEmpty().joinToString(" "))
139+
assertEquals("${ticket.uuid}::${ticket.firstName}::${ticket.lastName}::${ticket.fullName}::${ticket.email.orEmpty()}::thisIsTheFirstWord::thisIsTheSecondWord::thisIsTheThirdWord", result.qrContent)
140+
assertFalse(result.partialID.isEmpty())
141+
}
142+
118143
private fun ticket(additionalInfo: Map<String, String>? = mapOf("company" to "company")): Ticket = Ticket(uuid = "12345-678", firstName = "firstName", lastName = "lastName", additionalInfo = additionalInfo, email = null)
119144

120145

0 commit comments

Comments
 (0)