Skip to content

Commit

Permalink
JNG-4837 debugPrint as boolean (#97)
Browse files Browse the repository at this point in the history
* JNG-4837 debugPrint as boolean

* JNG-4837 Remove unneccessary method parameter
  • Loading branch information
robertcsakany authored May 13, 2023
1 parent 08928d0 commit 125d420
Show file tree
Hide file tree
Showing 38 changed files with 161 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package hu.blackbelt.judo.ui.generator.react;

/*-
* #%L
* JUDO UI React Frontend Generator
* %%
* Copyright (C) 2018 - 2023 BlackBelt Technology
* %%
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License, v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is
* available at https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
* #L%
*/

import hu.blackbelt.judo.generator.commons.StaticMethodValueResolver;
import hu.blackbelt.judo.generator.commons.ThreadLocalContextHolder;
import hu.blackbelt.judo.generator.commons.annotations.ContextAccessor;
import hu.blackbelt.judo.generator.commons.annotations.TemplateHelper;

import java.util.Map;

/**
* The handlebars context inaccessible in helpers / value resolvers
* because there is no state for them. The ThreadLocal is used
* to init variable values from template execution.
*/
@TemplateHelper
@ContextAccessor
public class StoredVariableHelper extends StaticMethodValueResolver {

public static void bindContext(Map<String, ?> context) {
ThreadLocalContextHolder.bindContext(context);
}

public static synchronized Boolean isDebugPrint() {
return Boolean.parseBoolean((String) ThreadLocalContextHolder.getVariable("debugPrint"));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {{ link.dataElement.name }}SortModel: GridSortModel = {{{ getDefaultSortParamsForLink link }}};

{{# unless link.dataElement.isReadOnly }}
{{# if debugPrint }}// include: actor/src/fragments/relation/hook-variables.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/relation/hook-variables.fragment.hbs{{/ if }}
{{> actor/src/fragments/relation/hook-variables.fragment.hbs rel=link }}
{{/ unless }}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const {{ rel.dataElement.name }}Columns: GridColDef<{{ classDataName rel.dataEle
field: '{{ column.attributeType.name }}',
headerName: t('{{ idToTranslationKey column.fQName application }}', { defaultValue: '{{ column.label }}' }) as string,
headerClassName: 'data-grid-column-header',
{{# if debugPrint }}// include: actor/src/fragments/relation/column.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/relation/column.fragment.hbs{{/ if }}
{{> actor/src/fragments/relation/column.fragment.hbs column=column dataElement=rel.dataElement name=rel.name }}
},
{{/ each }}
];

const {{ rel.dataElement.name }}RangeFilterOptions: FilterOption[] = [
{{# each rel.filters as |filter| }}
{{# if debugPrint }}// include: actor/src/fragments/table/filter-option.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/table/filter-option.fragment.hbs{{/ if }}
{{> actor/src/fragments/table/filter-option.fragment.hbs filter=filter application=application }}
{{/ each }}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ const {{ rel.dataElement.name }}Columns: GridColDef<{{ classDataName rel.dataEle
field: '{{ column.attributeType.name }}',
headerName: t('{{ idToTranslationKey column.fQName application }}', { defaultValue: '{{ column.label }}' }) as string,
headerClassName: 'data-grid-column-header',
{{# if debugPrint }}// include: actor/src/fragments/relation/column.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/relation/column.fragment.hbs{{/ if }}
{{> actor/src/fragments/relation/column.fragment.hbs column=column dataElement=rel.dataElement name=rel.name }}
},
{{/ each }}
];

const {{ rel.dataElement.name }}RangeFilterOptions: FilterOption[] = [
{{# each rel.filters as |filter| }}
{{# if debugPrint }}// include: actor/src/fragments/table/filter-option.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/table/filter-option.fragment.hbs{{/ if }}
{{> actor/src/fragments/table/filter-option.fragment.hbs filter=filter application=application }}
{{/ each }}
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {{ table.dataElement.name }}SortModel: GridSortModel = {{{ getDefaultSortParamsForTable table }}};

{{# if debugPrint }}// include: actor/src/fragments/relation/hook-variables.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/relation/hook-variables.fragment.hbs{{/ if }}
{{> actor/src/fragments/relation/hook-variables.fragment.hbs rel=table }}
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ export default function {{ pageName page }}() {
const [payloadDiff, setPayloadDiff] = useState<Record<keyof {{ classDataName page.dataElement.target '' }}, any>>({} as unknown as Record<keyof {{ classDataName page.dataElement.target '' }}, any>);
const [editMode, setEditMode] = useState<boolean>(true);
const storeDiff: (attributeName: keyof {{ classDataName page.dataElement.target '' }}, value: any) => void = useCallback((attributeName: keyof {{ classDataName page.dataElement.target '' }}, value: any) => {
{{# if debugPrint }}// include: actor/src/fragments/page/store-diff-body.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/page/store-diff-body.hbs{{/ if }}
{{> actor/src/fragments/page/store-diff-body.hbs classType=page.dataElement.target }}
}, [data]);
const [validation, setValidation] = useState<Map<keyof {{ classDataName page.dataElement.target ''}}, string>>(new Map<keyof {{ classDataName page.dataElement.target ''}}, string>());
const title: string = t('{{ idToTranslationKey page.fQName application }}', { defaultValue: '{{ page.label }}' });

{{# if debugPrint }}// include: actor/src/fragments/page/input-form-flags.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/page/input-form-flags.hbs{{/ if }}
{{> actor/src/fragments/page/input-form-flags.hbs }}

{{# if page.dataElement.target.isTemplateable }}
Expand Down Expand Up @@ -135,7 +135,7 @@ export default function {{ pageName page }}() {
<Box sx={mainContainerPadding}>
<Grid container xs={12} sm={12} spacing={2} direction="{{# if rootChild.isDirectionHorizontal }}row{{ else }}column{{/ if }}" alignItems="{{ alignItems rootChild }}" justifyContent="{{ justifyContent rootChild }}">
{{# each rootChild.children as |child| }}
{{# if debugPrint }}{/* include: getWidgetTemplate() */}{{/ if }}
{{# if isDebugPrint }}{/* include: getWidgetTemplate() */}{{/ if }}
{{> (getWidgetTemplate child) }}
{{/ each }}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Page DataElement name: {{ page.dataElement.name }}
// Page DataElement owner name: {{ page.dataElement.owner.name }}

{{# if debugPrint }}// include: actor/src/fragments/page/common-table-imports.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/page/common-table-imports.fragment.hbs{{/ if }}
{{> actor/src/fragments/page/common-table-imports.fragment.hbs }}

import { PageActions } from './components/PageActions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Page DataElement name: {{ page.dataElement.name }}
// Page DataElement owner name: {{ page.dataElement.owner.name }}

{{# if debugPrint }}// include: actor/src/fragments/page/common-view-imports.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/page/common-view-imports.fragment.hbs{{/ if }}
{{> actor/src/fragments/page/common-view-imports.fragment.hbs }}

import {
Expand Down Expand Up @@ -71,7 +71,7 @@ export default function {{ pageName page }}() {
const [payloadDiff, setPayloadDiff] = useState<Record<keyof {{ classDataName page.dataElement.target 'Stored' }}, any>>({} as unknown as Record<keyof {{ classDataName page.dataElement.target 'Stored' }}, any>);
const [editMode, setEditMode] = useState<boolean>(false);
const storeDiff: (attributeName: keyof {{ classDataName page.dataElement.target 'Stored' }}, value: any) => void = useCallback((attributeName: keyof {{ classDataName page.dataElement.target 'Stored' }}, value: any) => {
{{# if debugPrint }}// include: actor/src/fragments/page/store-diff-body.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/page/store-diff-body.hbs{{/ if }}
{{> actor/src/fragments/page/store-diff-body.hbs classType=page.dataElement.target }}
}, [data]);
const [validation, setValidation] = useState<Map<keyof {{ classDataName page.dataElement.target '' }}, string>>(new Map<keyof {{ classDataName page.dataElement.target '' }}, string>());
Expand All @@ -94,7 +94,7 @@ export default function {{ pageName page }}() {
const title: string = t('{{ idToTranslationKey page.fQName application }}', { defaultValue: '{{ page.label }}' });
{{/ if }}

{{# if debugPrint }}// include: actor/src/fragments/page/mapped-form-flags.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/page/mapped-form-flags.hbs{{/ if }}
{{> actor/src/fragments/page/mapped-form-flags.hbs }}

useConfirmationBeforeChange(editMode, t('judo.form.navigation.confirmation', { defaultValue: 'You have potential unsaved changes in your form, are you sure you would like to navigate away?' }));
Expand Down Expand Up @@ -231,7 +231,7 @@ export default function {{ pageName page }}() {
<Box sx={mainContainerPadding}>
<Grid className="access-page-data" container xs={12} sm={12} spacing={2} direction="{{# if rootChild.isDirectionHorizontal }}row{{ else }}column{{/ if }}" alignItems="{{ alignItems rootChild }}" justifyContent="{{ justifyContent rootChild }}">
{{# each rootChild.children as |child| }}
{{# if debugPrint }}{/* include: getWidgetTemplate() */}{{/ if }}
{{# if isDebugPrint }}{/* include: getWidgetTemplate() */}{{/ if }}
{{> (getWidgetTemplate child) }}
{{/ each }}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export function PageActions (props: PageActionsProps) {
const {{ actionFunctionName action }} = {{ actionFunctionHookName action }}();
{{/ each }}

{{# if debugPrint }}// include: actor/src/fragments/page/mapped-form-flags.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/page/mapped-form-flags.hbs{{/ if }}
{{> actor/src/fragments/page/mapped-form-flags.hbs }}

return (
<>
{{# if debugPrint }}{/* include: actor/src/fragments/page/page-crud-actions.hbs */}{{/ if }}
{{# if isDebugPrint }}{/* include: actor/src/fragments/page/page-crud-actions.hbs */}{{/ if }}
{{> actor/src/fragments/page/page-crud-actions.hbs }}
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
{{# if action.isFilterAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/filter-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/filter-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/filter-action.tsx.hbs }}
{{ else if action.isFilterRelationAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/filter-relation-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/filter-relation-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/filter-relation-action.tsx.hbs }}
{{ else if action.isRefreshAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/refresh-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/refresh-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/refresh-action.tsx.hbs }}
{{ else if action.isRefreshRelationAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/refresh-relation-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/refresh-relation-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/refresh-relation-action.tsx.hbs }}
{{ else if action.isCreateAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/create-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/create-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/create-action.tsx.hbs }}
{{ else if action.isClearAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/clear-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/clear-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/clear-action.tsx.hbs }}
{{ else if action.isAddAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/add-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/add-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/add-action.tsx.hbs }}
{{ else if action.isViewAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/row/row-view-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/row/row-view-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/row/row-view-action.tsx.hbs }}
{{ else if action.isRemoveAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/row/row-remove-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/row/row-remove-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/row/row-remove-action.tsx.hbs }}
{{ else if action.isDeleteAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/row/row-delete-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/row/row-delete-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/row/row-delete-action.tsx.hbs }}
{{ else if action.isNavigationToPageAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/navigate-to-page-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/navigate-to-page-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/navigate-to-page-action.tsx.hbs }}
{{ else if action.isCallOperationAction }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/call-operation-action.tsx.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/call-operation-action.tsx.hbs{{/ if }}
{{> actor/src/pages/actions/action/call-operation-action.tsx.hbs }}
{{ else }}
{{> fragment.header.hbs }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export const {{ actionFunctionHookName action }}: {{ actionFunctionTypeName acti
...baseColumnConfig,
field: '{{ column.attributeType.name }}',
headerName: t('{{ idToTranslationKey column.fQName application }}', { defaultValue: '{{ column.label }}' }) as string,
{{# if debugPrint }}// include: actor/src/fragments/relation/column.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/relation/column.fragment.hbs{{/ if }}
{{> actor/src/fragments/relation/column.fragment.hbs column=column dataElement=table.dataElement name=table.name }}
},
{{/ each }}
];

const filterOptions: FilterOption[] = [
{{# each table.filters as |filter| }}
{{# if debugPrint }}// include: actor/src/fragments/table/filter-option.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/table/filter-option.fragment.hbs{{/ if }}
{{> actor/src/fragments/table/filter-option.fragment.hbs filter=filter application=application }}
{{/ each }}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export const {{ actionFunctionHookName action }}: {{ actionFunctionTypeName acti
const postHandler: {{ actionFunctionHandlerTypeName action 'PostHandler' }} | undefined = customPostHandler && customPostHandler();

{{# if (actionHasInputForm action) }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/call-operation-action/with-input-form.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/call-operation-action/with-input-form.fragment.hbs{{/ if }}
{{> actor/src/pages/actions/action/call-operation-action/with-input-form.fragment.hbs action=action page=page }}
{{ else }}
{{# if debugPrint }}// include: actor/src/pages/actions/action/call-operation-action/without-input-form.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/pages/actions/action/call-operation-action/without-input-form.fragment.hbs{{/ if }}
{{> actor/src/pages/actions/action/call-operation-action/without-input-form.fragment.hbs action=action page=page }}
{{/ if }}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{> fragment.header.hbs }}

{{# if debugPrint }}// include: actor/src/fragments/link/common-imports.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/link/common-imports.fragment.hbs{{/ if }}
{{> actor/src/fragments/link/common-imports.fragment.hbs }}

import {
Expand Down Expand Up @@ -39,7 +39,7 @@ export function {{ linkComponentName link }}(props: {{ linkComponentName link }}
const { downloadFile, extractFileNameFromToken, uploadFile } = fileHandling();
const { locale: l10nLocale } = useL10N();

{{# if debugPrint }}// include: actor/src/fragments/link/hook-variables.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/link/hook-variables.fragment.hbs{{/ if }}
{{> actor/src/fragments/link/hook-variables.fragment.hbs link=link }}

{{# each (getFilteredLinkActions link) as |action| }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{> fragment.header.hbs }}

{{# if debugPrint }}// include: actor/src/fragments/table/common-imports.fragment.hbs{{/ if }}
{{# if isDebugPrint }}// include: actor/src/fragments/table/common-imports.fragment.hbs{{/ if }}
{{> actor/src/fragments/table/common-imports.fragment.hbs }}

import {
Expand Down
Loading

0 comments on commit 125d420

Please sign in to comment.