diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/admin/GenerateOverview.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/admin/GenerateOverview.kt index 4959fb7ae..69f16e79e 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/admin/GenerateOverview.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/admin/GenerateOverview.kt @@ -41,16 +41,33 @@ fun GenerateOverview.sorter(): String { } } -fun GenerateOverview.extra(): String { +fun GenerateOverview.formatValue(value: Any?): Any = + if (renderer == OVERVIEW_TYPE_CDN_IMAGE) { + if (value is String && value.isNotBlank()) + "/cdn/${cdnImageFolder}/${value}" + else + "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" // empty image + } else if (renderer == OVERVIEW_TYPE_TEXT || renderer == OVERVIEW_TYPE_ICON) { + value ?: "" + } else { + value ?: 0 + } + +fun GenerateOverview.extra(): Array> { return when (this.renderer) { - OVERVIEW_TYPE_ID -> ", \"width\":100, \"vertAlign\":\"middle\", \"visible\":false" - OVERVIEW_TYPE_TEXT -> ", \"vertAlign\":\"middle\"" - OVERVIEW_TYPE_DATE -> ", \"vertAlign\":\"middle\",\"formatter\":\"datetime\"" - OVERVIEW_TYPE_BOOLEAN -> ", \"formatter\":\"tickCross\", \"width\":120" - OVERVIEW_TYPE_CDN_IMAGE -> ", \"formatter\":\"image\", \"width\":120, \"formatterParams\":{\"height\":\"100px\"}" - OVERVIEW_TYPE_TIME -> ", \"vertAlign\":\"middle\"" - OVERVIEW_TYPE_NUMBER -> ", \"vertAlign\":\"middle\"" - OVERVIEW_TYPE_ICON -> ", \"vertAlign\":\"middle\", \"formatter\":\"enumIconsFormatter\", \"width\":120" - else -> "" + OVERVIEW_TYPE_ID -> arrayOf("width" to 100, "vertAlign" to "middle", "visible" to false) + OVERVIEW_TYPE_TEXT -> arrayOf("vertAlign" to "middle") + OVERVIEW_TYPE_DATE -> arrayOf("vertAlign" to "middle", "formatter" to "datetime") + OVERVIEW_TYPE_BOOLEAN -> arrayOf("formatter" to "tickCross", "width" to 120) + OVERVIEW_TYPE_CDN_IMAGE -> arrayOf( + "formatter" to "image", + "width" to 120, + "formatterParams" to mapOf("height" to "100px") + ) + + OVERVIEW_TYPE_TIME -> arrayOf("vertAlign" to "middle") + OVERVIEW_TYPE_NUMBER -> arrayOf("vertAlign" to "middle") + OVERVIEW_TYPE_ICON -> arrayOf("vertAlign" to "middle", "formatter" to "enumIconsFormatter", "width" to 120) + else -> emptyArray() } } diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/admin/OverviewBuilder.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/admin/OverviewBuilder.kt index 43a565f82..8b434e099 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/admin/OverviewBuilder.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/admin/OverviewBuilder.kt @@ -1,8 +1,5 @@ package hu.bme.sch.cmsch.admin -import com.fasterxml.jackson.core.type.TypeReference -import com.fasterxml.jackson.databind.ObjectMapper -import hu.bme.sch.cmsch.controller.admin.ControlAction import java.io.ByteArrayOutputStream import kotlin.reflect.KClass import kotlin.reflect.KProperty1 @@ -15,51 +12,37 @@ class OverviewBuilder(val type: KClass) { private fun getColumnDefinitions(): List, GenerateOverview>> { return type.memberProperties.asSequence() - .filter { it.findAnnotation() != null } - .map { Pair(it, it.findAnnotation()!!) } - .filter { it.second.visible } - .sortedBy { it.second.order } - .toList() + .filter { it.findAnnotation() != null } + .map { Pair(it, it.findAnnotation()!!) } + .filter { it.second.visible } + .sortedBy { it.second.order } + .toList() } - fun getColumnsAsJson(): String { - return "[" + (getColumnDefinitions().joinToString(",") { - "{\"title\":\"${it.second.columnName}\", " + - "\"field\":\"${it.first.name}\", " + - "\"hozAlign\":\"${it.second.alignment()}\", " + - "\"sorter\":\"${it.second.sorter()}\"" + - it.second.extra() + - "}" - }) + "]" + fun getColumns(): List> = getColumnDefinitions().map { + mapOf( + "title" to it.second.columnName, + "field" to it.first.name, + "hozAlign" to it.second.alignment(), + "sorter" to it.second.sorter(), + *it.second.extra() + ) } - private fun formatValue(type: GenerateOverview, value: Any?): String { - return if (type.renderer == OVERVIEW_TYPE_CDN_IMAGE) { - if (value is String && !value.isNullOrBlank()) - "\"/cdn/${type.cdnImageFolder}/${value}\"" - else - "\"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\"" // empty image - } else if (type.renderer == OVERVIEW_TYPE_TEXT || type.renderer == OVERVIEW_TYPE_ICON) { - "\"${(value ?: "").toString().replace("\"", "")}\"" - } else { - (value ?: "0").toString().replace("\"", "") - } - } - - fun getTableDataAsJson(overview: Iterable): String { + fun getTableData(overview: Iterable): List> { val fields = getColumnDefinitions() - return "[" + (overview.toList() - .map { row -> fields.map { "\"${it.first.name}\":${formatValue(it.second, it.first.get(row))}" } } - .joinToString(",") { row -> "{${row.joinToString(",")}}" }) + "]" + return overview.map { row -> + fields.map { it.first.name to it.second.formatValue(it.first.get(row)) }.toMap() + } } fun getInputs(): List, GenerateInput>> { return type.memberProperties.asSequence() - .filter { it.findAnnotation() != null } - .map { Pair(it, it.findAnnotation()!!) } - .filter { it.second.visible } - .sortedBy { it.second.order } - .toList() + .filter { it.findAnnotation() != null } + .map { Pair(it, it.findAnnotation()!!) } + .filter { it.second.visible } + .sortedBy { it.second.order } + .toList() } fun exportToCsv(entities: List): String { @@ -67,13 +50,6 @@ class OverviewBuilder(val type: KClass) { csv.exportToCsv(entities, outputStream) return outputStream.toString().trim() } - - fun toJson(list: List, objectMapper: ObjectMapper): String { - return objectMapper - .writerFor(object : TypeReference>() {}) - .writeValueAsString(list) - } - } object DetailsHelper { diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/MenuAdminController.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/MenuAdminController.kt index 6b4758871..53e04264e 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/MenuAdminController.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/app/MenuAdminController.kt @@ -114,13 +114,11 @@ class MenuAdminController( model.addAttribute("description", description) model.addAttribute("view", view) - model.addAttribute("columnData", overviewDescriptor.getColumnsAsJson()) - model.addAttribute("tableData", overviewDescriptor.getTableDataAsJson(fetchOverview())) + model.addAttribute("columnData", overviewDescriptor.getColumns()) + model.addAttribute("tableData", overviewDescriptor.getTableData(fetchOverview())) model.addAttribute("user", user) - model.addAttribute("controlActions", overviewDescriptor.toJson( - controlActions.filter { it.permission.validate(user) }, - objectMapper)) + model.addAttribute("controlActions", controlActions.filter { it.permission.validate(user) }) model.addAttribute("allControlActions", controlActions) model.addAttribute("buttonActions", buttonActions) diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TaskAdminRateController.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TaskAdminRateController.kt index 4ccaced83..83d117418 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TaskAdminRateController.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/component/task/TaskAdminRateController.kt @@ -120,16 +120,14 @@ class TaskAdminRateController( model.addAttribute("titleSingular", titleSingular) model.addAttribute("view", view) - model.addAttribute("columnData", descriptor.getColumnsAsJson()) + model.addAttribute("columnData", descriptor.getColumns()) val submissions = transactionManager.transaction(readOnly = true) { submittedRepository.findByTask_IdAndRejectedIsFalseAndApprovedIsFalseWithoutLobs(id) } - model.addAttribute("tableData", descriptor.getTableDataAsJson(submissions)) + model.addAttribute("tableData", descriptor.getTableData(submissions)) model.addAttribute("user", user) - model.addAttribute("controlActions", descriptor.toJson( - rateControlActions.filter { it.permission.validate(user) }, - objectMapper)) + model.addAttribute("controlActions", rateControlActions.filter { it.permission.validate(user) }) model.addAttribute("allControlActions", rateControlActions) model.addAttribute("buttonActions", buttonActions.filter { it.permission.validate(user) }) diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/FilesByViewController.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/FilesByViewController.kt index ed8f1264b..1e08e6ad0 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/FilesByViewController.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/FilesByViewController.kt @@ -90,13 +90,11 @@ class FilesByViewController( model.addAttribute("description", description) model.addAttribute("view", view) - model.addAttribute("columnData", overviewDescriptor.getColumnsAsJson()) - model.addAttribute("tableData", overviewDescriptor.getTableDataAsJson(fetchOverview())) + model.addAttribute("columnData", overviewDescriptor.getColumns()) + model.addAttribute("tableData", overviewDescriptor.getTableData(fetchOverview())) model.addAttribute("user", user) - model.addAttribute("controlActions", overviewDescriptor.toJson( - controlActions.filter { it.permission.validate(user) }, - objectMapper)) + model.addAttribute("controlActions", controlActions.filter { it.permission.validate(user) }) model.addAttribute("allControlActions", controlActions) model.addAttribute("buttonActions", listOf()) @@ -126,8 +124,8 @@ class FilesByViewController( model.addAttribute("description", description) model.addAttribute("view", view) - model.addAttribute("columnData", submittedDescriptor.getColumnsAsJson()) - model.addAttribute("tableData", submittedDescriptor.getTableDataAsJson(listFilesInView(id))) + model.addAttribute("columnData", submittedDescriptor.getColumns()) + model.addAttribute("tableData", submittedDescriptor.getTableData(listFilesInView(id))) model.addAttribute("user", user) val controlActionForCategory = listOf( @@ -152,9 +150,7 @@ class FilesByViewController( basic = true ) ) - model.addAttribute("controlActions", overviewDescriptor.toJson( - controlActionForCategory.filter { it.permission.validate(user) }, - objectMapper)) + model.addAttribute("controlActions", controlActionForCategory.filter { it.permission.validate(user) }) model.addAttribute("allControlActions", controlActionForCategory) model.addAttribute("buttonActions", listOf()) diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/OneDeepEntityPage.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/OneDeepEntityPage.kt index 68d41069b..69ce7c7e8 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/OneDeepEntityPage.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/OneDeepEntityPage.kt @@ -283,14 +283,12 @@ open class OneDeepEntityPage( model.addAttribute("description", description) model.addAttribute("view", view) - model.addAttribute("columnData", descriptor.getColumnsAsJson()) + model.addAttribute("columnData", descriptor.getColumns()) val overview = transactionManager.transaction(readOnly = true) { fetchOverview(user) } - model.addAttribute("tableData", descriptor.getTableDataAsJson(filterOverview(user, overview))) + model.addAttribute("tableData", descriptor.getTableData(filterOverview(user, overview))) model.addAttribute("user", user) - model.addAttribute("controlActions", descriptor.toJson( - controlActions.filter { it.permission.validate(user) }, - objectMapper)) + model.addAttribute("controlActions", controlActions.filter { it.permission.validate(user) }) model.addAttribute("allControlActions", controlActions) model.addAttribute("buttonActions", buttonActions.filter { it.permission.validate(user) }) model.addAttribute("searchSettings", searchSettings) diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/TwoDeepEntityPage.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/TwoDeepEntityPage.kt index ac6292465..fa2fb6abd 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/TwoDeepEntityPage.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/admin/TwoDeepEntityPage.kt @@ -137,14 +137,12 @@ abstract class TwoDeepEntityPage()) diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/userhandling/PermissionGroupAssignPage.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/userhandling/PermissionGroupAssignPage.kt index 406cd2d9e..6e39ba0ce 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/userhandling/PermissionGroupAssignPage.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/userhandling/PermissionGroupAssignPage.kt @@ -129,7 +129,7 @@ class PermissionGroupAssignPage( model.addAttribute("description", "Válassz, hogy melyik felhasználó kapja meg a(z) ${permissionGroup.displayName} jogkört") model.addAttribute("view", view) - model.addAttribute("columnData", descriptor.getColumnsAsJson()) + model.addAttribute("columnData", descriptor.getColumns()) val overview = transactionManager.transaction(readOnly = true) { userRepository.findAll() .filter { permissionGroup.key.isNotEmpty() && !it.permissionGroups.split(",").contains(permissionGroup.key) } @@ -143,12 +143,10 @@ class PermissionGroupAssignPage( ) } } - model.addAttribute("tableData", descriptor.getTableDataAsJson(filterOverview(user, overview))) + model.addAttribute("tableData", descriptor.getTableData(filterOverview(user, overview))) model.addAttribute("user", user) - model.addAttribute("controlActions", descriptor.toJson( - controlActionsForView.filter { it.permission.validate(user) }, - objectMapper)) + model.addAttribute("controlActions", controlActionsForView.filter { it.permission.validate(user) }) model.addAttribute("allControlActions", controlActionsForView) model.addAttribute("buttonActions", buttonActionsForView.filter { it.permission.validate(user) }) model.addAttribute("searchSettings", searchSettings) @@ -188,4 +186,3 @@ class PermissionGroupAssignPage( fun redirectToUsersView(@PathVariable id: Int) = "redirect:/admin/control/permission-groups-for-users/${id}" } - diff --git a/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/userhandling/PermissionGroupUserListPage.kt b/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/userhandling/PermissionGroupUserListPage.kt index f734a8c7f..f762a1e0d 100644 --- a/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/userhandling/PermissionGroupUserListPage.kt +++ b/backend/src/main/kotlin/hu/bme/sch/cmsch/controller/userhandling/PermissionGroupUserListPage.kt @@ -140,7 +140,7 @@ class PermissionGroupUserListPage( model.addAttribute("description", description) model.addAttribute("view", view) - model.addAttribute("columnData", descriptor.getColumnsAsJson()) + model.addAttribute("columnData", descriptor.getColumns()) val overview = transactionManager.transaction(readOnly = true) { userRepository.findAllByPermissionGroupsNot("") .filter { permissionGroup.key.isNotEmpty() && it.permissionGroups.split(",").contains(permissionGroup.key) } @@ -154,12 +154,10 @@ class PermissionGroupUserListPage( ) } } - model.addAttribute("tableData", descriptor.getTableDataAsJson(filterOverview(user, overview))) + model.addAttribute("tableData", descriptor.getTableData(filterOverview(user, overview))) model.addAttribute("user", user) - model.addAttribute("controlActions", descriptor.toJson( - controlActionsForView.filter { it.permission.validate(user) }, - objectMapper)) + model.addAttribute("controlActions", controlActionsForView.filter { it.permission.validate(user) }) model.addAttribute("allControlActions", controlActionsForView) model.addAttribute("buttonActions", buttonActionsForView.filter { it.permission.validate(user) }) model.addAttribute("searchSettings", searchSettings) @@ -201,4 +199,3 @@ class PermissionGroupUserListPage( fun redirectToUsersView() = "redirect:/admin/control/permission-groups" } - diff --git a/backend/src/main/resources/templates/overview4.html b/backend/src/main/resources/templates/overview4.html index 3be055bed..d0ad70e93 100644 --- a/backend/src/main/resources/templates/overview4.html +++ b/backend/src/main/resources/templates/overview4.html @@ -110,8 +110,8 @@
Usage text
return dt.toFormat("yyyy-MM-dd HH:mm"); } - const buttons = JSON.parse(/*[[${controlActions}]]*/ "[]"); - let tableData = JSON.parse(/*[[${tableData}]]*/ "[]"); + const buttons = /*[[${controlActions}]]*/ []; + let tableData = /*[[${tableData}]]*/ []; let view = /*[[${view}]]*/ ""; for (let rowId in tableData) { const row = tableData[rowId]; @@ -140,7 +140,7 @@
Usage text
return enumElementMap[value] || ""; } - let columData = JSON.parse(/*[[${columnData}]]*/ "[]"); + let columData = /*[[${columnData}]]*/ []; for (let columnId in columData) { if (columData[columnId].formatter === 'tickCross') { columData[columnId]['formatterParams'] = {