[Git][ultreiaio/ird-observe][feature/issue_2755] stash
Tony CHEMIT pushed to branch feature/issue_2755 at ultreiaio / ird-observe Commits: 45538604 by Tony Chemit at 2023-11-16T18:49:02+01:00 stash - - - - - 7 changed files: - client/datasource/actions/src/main/resources/report/html/default/report.html → client/datasource/actions/src/main/i18n/templates/reportHtmlExport_en_GB.ftl - + client/datasource/actions/src/main/i18n/templates/reportHtmlExport_es_ES.ftl - + client/datasource/actions/src/main/i18n/templates/reportHtmlExport_fr_FR.ftl - client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ResultJsonModel.java → client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/HtmlExportModel.java - client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ReportModel.java - client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ResultTableModel.java - client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/actions/ExportToHtml.java Changes: ===================================== client/datasource/actions/src/main/resources/report/html/default/report.html → client/datasource/actions/src/main/i18n/templates/reportHtmlExport_en_GB.ftl ===================================== @@ -74,7 +74,7 @@ } new gridjs.Grid(config).render(container); } - var json = ${json}; + var json = ${data}; </script> </head> <body> ===================================== client/datasource/actions/src/main/i18n/templates/reportHtmlExport_es_ES.ftl ===================================== @@ -0,0 +1,21 @@ +<#-- + #%L + ObServe Client :: DataSource :: Actions + %% + Copyright (C) 2008 - 2023 IRD, Ultreia.io + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% +--> ===================================== client/datasource/actions/src/main/i18n/templates/reportHtmlExport_fr_FR.ftl ===================================== @@ -0,0 +1,263 @@ +<#-- @ftlvariable name=".data_model" type="fr.ird.observe.client.datasource.actions.report.HtmlExportModel" --> +<!DOCTYPE html> +<!-- + #%L + ObServe Client :: DataSource :: Actions + %% + Copyright (C) 2008 - 2023 IRD, Ultreia.io + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> + +<html lang="en"> +<head> + <link href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css" rel="stylesheet"/> + <title>Report...</title> + <script src="https://unpkg.com/gridjs/dist/gridjs.umd.js"></script> + <style> + .config-panel { + padding: 10px; + margin: 10px 0; + background: #fcfcfc; + border: 1px solid #e9e9e9; + display: inline-block; + } + + .config-panel label { + margin-right: 10px; + } + + td.gridjs-td { + background-color: transparent; + } + + tr:nth-child(even) { + background-color: #dddddd; + } + </style> + <script type="application/javascript"> + const config = { + language: { + 'search': { + 'placeholder': '🔍 Recherche...' + } + } + }; + const json = ${.data_model.json}; + </script> +</head> +<body> +<h1>Rapport ${.data_model.selectedReport.name}</h1> +<h2>Configuration</h2> +<h3>Données sélectionnées :</h3> +<ul> + <li> + <#assign selectDataModel = .data_model.selectDataModel.selectionDataModel /> + <#assign selectDataCount = selectDataModel.getSelectedCount() /> + + <#if selectDataCount == 1> 1 marée <#else> ${selectDataCount} marées</#if>. + <ul> + <#list selectDataModel.getSelectedLabels() as key, value> + <li> + ${key} + <ul> + <#list value as trip> + <li>${trip}</li> + </#list> + </ul> + </li> + </#list> + </ul> + </li> +</ul> +<h3>Rapport sélectionné :</h3> + +<#assign selectedReport = .data_model.selectedReport /> +<p><b>${selectedReport.name}</b></p> +<#list selectedReport.getVariables() as variable> + <li> + Variable ${variable.name} : ${variable.selectedValue}. + </li> +</#list> +<h2>Résultat</h2> + +<div class="config-panel"> + <label><input id="search" type="checkbox" class="action" checked/> Search</label> + <label><input id="resizable" type="checkbox" class="action" checked/> Colonnes redimensionnables</label> + <label><input id="sort" type="checkbox" class="action" checked/> Sorting</label> + <label><input id="pagination" type="checkbox" class="action"/> Pagination</label> + <label>Page size<input id="paginationSize" type="number" disabled value="20"/></label> +</div> +<div id="wrapperParent"> + <div id="wrapper"></div> +</div> +<script type="application/javascript"> + const gridContainerParent = document.getElementById("wrapperParent"); + const searchOption = document.getElementById("search"); + const resizableOption = document.getElementById("resizable"); + const paginationOption = document.getElementById("pagination"); + const paginationSizeOption = document.getElementById("paginationSize"); + const sortOption = document.getElementById("sort"); + + // FIXME Use options value from the very beginning :) + + let grid = new gridjs.Grid({ + search: true, resizable: true, sort: true, + language: config.language, data: [] + }); + + function initGrid(json, container) { + let config = {data: json.data.data}; + if (!!json.columnNames) { + config.columns = json.columnNames; + } else { + config.columns = null; + } + grid.updateConfig(config).render(container); + } + + initGrid(json, document.getElementById("wrapper")); + + function toggle(source) { + let newValue = source.checked; + let option = source.id; + switch (option) { + case "search": + toggleSearch(newValue); + break; + case "resizable": + toggleResizable(newValue); + break; + case "pagination": + togglePagination(newValue); + break; + case "paginationSize": + changePaginationSize(newValue); + break; + case "sort": + toggleSort(newValue); + break; + } + } + + function toggleSearch(newValue) { + console.info("Toggle search to: " + newValue); + let newConfig = { + language: config.language, + data: grid.config.data, + columns: grid.config.columns, + resizable: resizableOption.checked, + pagination: paginationOption.checked ? {limit: paginationSizeOption.value} : false, + sort: sortOption.checked + }; + if (newValue) { + newConfig.search = true; + } + updateGrid(newConfig); + } + + function toggleResizable(newValue) { + console.info("Toggle resizable to: " + newValue); + let newConfig = { + language: config.language, + data: grid.config.data, + columns: grid.config.columns, + search: searchOption.checked, + pagination: paginationOption.checked ? {limit: paginationSizeOption.value} : false, + sort: sortOption.checked + }; + if (newValue) { + newConfig.resizable = true; + } + updateGrid(newConfig); + } + + function toggleSort(newValue) { + console.info("Toggle sort to: " + newValue); + let newConfig = { + language: config.language, + data: grid.config.data, + columns: grid.config.columns, + search: searchOption.checked, + pagination: paginationOption.checked ? {limit: paginationSizeOption.value} : false, + resizable: resizableOption.checked + }; + if (newValue) { + newConfig.sort = true; + } + updateGrid(newConfig); + } + + function togglePagination(newValue) { + console.info("Toggle pagination to: " + newValue); + let newConfig = { + language: config.language, + data: grid.config.data, + columns: grid.config.columns, + search: searchOption.checked, + resizable: resizableOption.checked, + sort: sortOption.checked, + }; + if (newValue) { + newConfig.pagination = { + limit: paginationSizeOption.value + }; + paginationSizeOption["disabled"] = null; + } else { + + paginationSizeOption.disabled = true; + } + + + updateGrid(newConfig); + } + + function changePaginationSize(newValue) { + console.info("Change pagination size to: " + newValue); + let newConfig = { + language: config.language, + data: grid.config.data, + columns: grid.config.columns, + search: searchOption.checked, + resizable: resizableOption.checked, + sort: sortOption.checked, + pagination: { + limit: paginationSizeOption.value + } + }; + updateGrid(newConfig); + } + + function updateGrid(newConfig) { + gridContainerParent.innerHTML = "<div id=\"wrapper\"></div>"; + console.info(newConfig); + setTimeout(() => { + grid = new gridjs.Grid(newConfig).render(document.getElementById("wrapper")); + }, 200); + } + + let actions = document.getElementsByClassName("action"); + for (const action of document.getElementsByClassName("action")) { + action.addEventListener("click", function (event) { + toggle(this); + }); + } + paginationSizeOption.addEventListener("change", function (event) { + toggle(this); + }); +</script> +</body> +</html> ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ResultJsonModel.java → client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/HtmlExportModel.java ===================================== @@ -22,6 +22,10 @@ package fr.ird.observe.client.datasource.actions.report; * #L% */ +import com.google.gson.Gson; +import fr.ird.observe.client.datasource.actions.config.SelectDataModel; +import fr.ird.observe.report.Report; +import io.ultreia.java4all.application.template.spi.GenerateTemplate; import io.ultreia.java4all.util.matrix.DataMatrix; import java.util.List; @@ -34,24 +38,52 @@ import java.util.List; * @author Tony Chemit - dev@tchemit.fr * @since 9.3.0 */ -public class ResultJsonModel { +@GenerateTemplate(template = "reportHtmlExport.ftl") +public class HtmlExportModel { + /** + * Selected report. + */ + private final transient Report selectedReport; + /** + * Selected data model. + */ + private final transient SelectDataModel selectDataModel; private final List<String> columnNames; private final List<String> rowNames; private final DataMatrix data; private final boolean withColumnHeader; private final boolean withRowHeader; + private final transient String json; - public ResultJsonModel(List<String> columnNames, + public HtmlExportModel(Gson gson, + Report selectedReport, + SelectDataModel selectDataModel, + List<String> columnNames, List<String> rowNames, DataMatrix data, boolean withColumnHeader, boolean withRowHeader) { + this.selectedReport = selectedReport; + this.selectDataModel = selectDataModel; this.columnNames = columnNames; this.rowNames = rowNames; this.data = data; this.withColumnHeader = withColumnHeader; this.withRowHeader = withRowHeader; + this.json = gson.toJson(this); + } + + public String getJson() { + return json; + } + + public Report getSelectedReport() { + return selectedReport; + } + + public SelectDataModel getSelectDataModel() { + return selectDataModel; } public List<String> getColumnNames() { ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ReportModel.java ===================================== @@ -601,6 +601,11 @@ public class ReportModel extends AdminActionModel { } } + public HtmlExportModel toJsonModel() { + + return new HtmlExportModel(getClientConfig().getGsonSupplier().get(), getSelectedReport(), selectDataModel, getResultModel().getColumnNames(), getResultModel().getRowNames(), getResultModel().getData(), getResultModel().isWithColumnHeader(), getResultModel().isWithRowHeader()); + } + private Map<String, FilterableComboBox<?>> initVariableComponents(ReportUI ui, Report report) { Map<String, FilterableComboBox<?>> result = new TreeMap<>(); JPanel variablesPanel = ui.getReportVariableSelectorPanel(); ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ResultTableModel.java ===================================== @@ -236,6 +236,26 @@ public class ResultTableModel extends AbstractTableModel { return data == null ? null : data.getValue(columnIndex, rowIndex); } + public List<String> getColumnNames() { + return columnNames; + } + + public List<String> getRowNames() { + return rowNames; + } + + public DataMatrix getData() { + return data; + } + + public boolean isWithColumnHeader() { + return withColumnHeader; + } + + public boolean isWithRowHeader() { + return withRowHeader; + } + public String getClipboardContent(boolean copyRowHeaders, boolean copyColumnHeaders) { return getDataContent(copyRowHeaders, copyColumnHeaders, true, '\t'); } @@ -264,8 +284,4 @@ public class ResultTableModel extends AbstractTableModel { result += data.getClipboardContent(copyRowHeaders || !withRowHeader, true, escapeCell, separator); return result; } - - public ResultJsonModel toJsonModel() { - return new ResultJsonModel(columnNames, rowNames, data, withColumnHeader, withRowHeader); - } } ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/actions/ExportToHtml.java ===================================== @@ -22,13 +22,12 @@ package fr.ird.observe.client.datasource.actions.report.actions; * #L% */ -import com.google.common.base.Charsets; -import com.google.common.io.Resources; import fr.ird.observe.client.datasource.actions.ObserveKeyStrokesActions; import fr.ird.observe.client.datasource.actions.actions.AdminTabUIActionSupport; +import fr.ird.observe.client.datasource.actions.report.HtmlExportModel; +import fr.ird.observe.client.datasource.actions.report.HtmlExportModelTemplate; import fr.ird.observe.client.datasource.actions.report.ReportModel; import fr.ird.observe.client.datasource.actions.report.ReportUI; -import fr.ird.observe.client.datasource.actions.report.ResultJsonModel; import fr.ird.observe.client.util.UIHelper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -79,20 +78,14 @@ public class ExportToHtml extends AdminTabUIActionSupport<ReportUI> { // generate data file Path dataFile = exportDirectory.resolve("data.json"); log.info("Generate data file for report ({}) at {}", reportId, dataFile); - ResultJsonModel dataModel = stepModel.getResultModel().toJsonModel(); - String dataContent = getClientConfig().getGsonSupplier().get().toJson(dataModel); + HtmlExportModel dataModel = stepModel.toJsonModel(); + String dataContent = dataModel.getJson(); Files.writeString(dataFile, dataContent); -// // generate javascript file -// Path jsFile = exportDirectory.resolve("report.js"); -// log.info("Generate js file for report ({}) at {}", reportId, jsFile); -// String jsContent = Resources.asCharSource(Resources.getResource("report/html/default/report.js"), Charsets.UTF_8).read(); -// Files.writeString(jsFile, jsContent); - // generate html file Path htmlFile = exportDirectory.resolve("report.html"); log.info("Generate html file for report ({}) at {}", reportId, htmlFile); - String fileContent = Resources.asCharSource(Resources.getResource("report/html/default/report.html"), Charsets.UTF_8).read().replace("${json}", dataContent); + String fileContent = HtmlExportModelTemplate.generate(dataModel); Files.writeString(htmlFile, fileContent); // open html file View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/455386042bf6ae7140dabc8a2d... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/455386042bf6ae7140dabc8a2d... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT (@tchemit)