From 97dafb07f9b2a1f98b2aab8f5664725731232707 Mon Sep 17 00:00:00 2001 From: Adrien Guichard Date: Mon, 29 Apr 2024 14:07:53 +0200 Subject: [PATCH] remove ajaxBlock around show, improve table rendering, clean up --- .../taack/render/TaackUiService.groovy | 42 +------------------ .../groovy/taack/ui/base/show/ShowSpec.groovy | 31 +------------- .../taack/ui/dump/RawHtmlShowDump.groovy | 1 + .../taack/ui/dump/RawHtmlTableDump.groovy | 13 +++++- 4 files changed, 16 insertions(+), 71 deletions(-) diff --git a/taack-ui/grails-app/services/taack/render/TaackUiService.groovy b/taack-ui/grails-app/services/taack/render/TaackUiService.groovy index 775fa0dd..ad81490a 100644 --- a/taack-ui/grails-app/services/taack/render/TaackUiService.groovy +++ b/taack-ui/grails-app/services/taack/render/TaackUiService.groovy @@ -402,7 +402,7 @@ final class TaackUiService implements WebAttributes, ResponseRenderer, DataBinde } /** - * Retrieve hidden field passed with {@link UiFilterSpecifier#ui(java.lang.Class, groovy.lang.Closure, taack.ast.type.FieldInfo[])}. + * Retrieve hidden field passed with {@link UiFilterSpecifier#ui(java.lang.Class, groovy.lang.Closure, taack.ast.type.FieldInf o [])}. * * @param aClass * @return objectClass initialized @@ -460,42 +460,4 @@ final class TaackUiService implements WebAttributes, ResponseRenderer, DataBinde ] html } - - /** - * Helper displaying a dialog allowing to confirm before processing the action. - * - *
{@code
-     * Long option = taackUiSimpleService.showOptions(tr('default.button.confirm.message'), ['Yes', 'No'])
-     * if (option == 0) // do things
-     * }
- * @param i18n content of the text - * @param options list of options - * @param isAjax set to true if the next action is ajax - * @return the index, starting from zero the user click on - */ - final Long showOptions(String i18n, List options, boolean isAjax = true) { - final String confirmKey = 'showOptions' - Long confirm = params.containsKey(confirmKey) ? params.long(confirmKey) : null - params.remove(confirmKey) - def b = new UiBlockSpecifier() - if (confirm == null) - show(b.ui { - modal { - ajaxBlock "showConfirm", { - delegate.show("Action Options", new UiShowSpecifier().ui({ - field(i18n) - int i = 0 - for (String opt in options) { - showAction("
${opt}", controllerName, actionName, null, params + [showOptions: "${i}"], isAjax) - i++ - } - }), BlockSpec.Width.MAX) - } - } - }) - else { - closeModal() - } - return confirm - } -} +} \ No newline at end of file diff --git a/taack-ui/src/main/groovy/taack/ui/base/show/ShowSpec.groovy b/taack-ui/src/main/groovy/taack/ui/base/show/ShowSpec.groovy index a521c078..9b5ea312 100644 --- a/taack-ui/src/main/groovy/taack/ui/base/show/ShowSpec.groovy +++ b/taack-ui/src/main/groovy/taack/ui/base/show/ShowSpec.groovy @@ -29,22 +29,8 @@ class ShowSpec extends SectionSpec { showVisitor.visitSectionEnd() } - /** - * Link action to insert in the show block - * - * @param i18n label of the action - * @param controller controller targeted by a click on the link - * @param action action targeted by a click on the link - * @param id object ID to pass - * @param params additional params - * @param isAjax if true, target action is an ajax one - */ - void showAction(final String i18n, final String controller, final String action, final Long id = null, final Map params = null, boolean isAjax = true) { - showVisitor.visitShowAction(i18n, controller, action, id, params, isAjax) - } /** - * see {@link #showAction(java.lang.String, java.lang.String, java.lang.String, java.lang.Long, java.util.Map)} * * @param i18n * @param action action closure @@ -52,20 +38,7 @@ class ShowSpec extends SectionSpec { * @param params * @param isAjax */ - void showAction(final String i18n, final MethodClosure action, final Long id = null, final Map params = null, boolean isAjax = true) { - showVisitor.visitShowAction(i18n, Utils.getControllerName(action), action.method, id, params, isAjax) + void showAction(final MethodClosure action, final Long id = null, final Map params = null) { + showVisitor.visitShowAction(null, Utils.getControllerName(action), action.method, id, params, true) } - - /** - * see {@link #showAction(java.lang.String, java.lang.String, java.lang.String, java.lang.Long, java.util.Map)} - * - * @param i18n - * @param action - * @param id - * @param isAjax - */ - void showAction(final String i18n, final MethodClosure action, final Long id, boolean isAjax) { - showVisitor.visitShowAction(i18n, Utils.getControllerName(action), action.method, id, null, isAjax) - } - } diff --git a/taack-ui/src/main/groovy/taack/ui/dump/RawHtmlShowDump.groovy b/taack-ui/src/main/groovy/taack/ui/dump/RawHtmlShowDump.groovy index 1a28ab64..809033b7 100644 --- a/taack-ui/src/main/groovy/taack/ui/dump/RawHtmlShowDump.groovy +++ b/taack-ui/src/main/groovy/taack/ui/dump/RawHtmlShowDump.groovy @@ -116,6 +116,7 @@ final class RawHtmlShowDump implements IUiShowVisitor { @Override void visitShowAction(String i18n, String controller, String action, Long id, Map additionalParams, boolean isAjax = true) { + i18n ?= parameter.trField(controller, action) additionalParams ?= [:] additionalParams['isAjax'] = isAjax out << """${i18n}""" diff --git a/taack-ui/src/main/groovy/taack/ui/dump/RawHtmlTableDump.groovy b/taack-ui/src/main/groovy/taack/ui/dump/RawHtmlTableDump.groovy index c154250c..fc36850d 100644 --- a/taack-ui/src/main/groovy/taack/ui/dump/RawHtmlTableDump.groovy +++ b/taack-ui/src/main/groovy/taack/ui/dump/RawHtmlTableDump.groovy @@ -31,6 +31,7 @@ final class RawHtmlTableDump implements IUiTableVisitor { int level = 0 private Style rowStyle = null int stripped = 0 + private boolean firstSurround = false RawHtmlTableDump(final String id, final ByteArrayOutputStream out, final Parameter parameter) { this.out = out @@ -151,6 +152,8 @@ final class RawHtmlTableDump implements IUiTableVisitor { @Override void visitRowColumnEnd() { + firstSurround = false + isInCol = false out << "" } @@ -163,6 +166,7 @@ final class RawHtmlTableDump implements IUiTableVisitor { } else { out << """""" } + firstSurround = true } void visitRowFieldCommon(Class type, Object value, final String format = null, final Style style, final String controller = null, final String action = null, final Long id = null) { @@ -196,7 +200,7 @@ final class RawHtmlTableDump implements IUiTableVisitor { visitRowFieldCommon (fieldInfo.getMethod().returnType, fieldInfo.value, null, style, controller, action, id) } - private static String surroundCell(final String cell, final Style style = null, final String url = null) { + private String surroundCell(final String cell, final Style style = null, final String url = null) { if (style) { if (!cell || cell.empty) return "" return """ @@ -204,7 +208,12 @@ final class RawHtmlTableDump implements IUiTableVisitor { ${url ? "${cell ?: ''}" : "${cell ?: ''}"} """ - } else return "${cell && !cell.empty ? "${url ? "${cell ?: ''}" : "${cell}"}
" : ''}" + } else { + String ret = "${cell && !cell.empty ? "${url ? "${cell ?: ''}" : "${cell}"}" : ''}" + ret = ret.empty ? '' : ((!firstSurround ? '
' : '') + ret) + firstSurround = false + return ret + } } @Override