From 762c13c4fae6fbd9bca66e0eef68af004da2de01 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 27 Jan 2025 11:14:20 +0700 Subject: [PATCH 01/22] remove AddCatalogPriceForm --- .../src/components/AddCatalogPriceForm.js | 190 ------------------ src/main/frontend/webpack.config.js | 1 - .../web/feature/site/ResourceUrl.java | 2 - .../webapp/WEB-INF/views/series/info.html | 27 --- 4 files changed, 220 deletions(-) delete mode 100644 src/main/frontend/src/components/AddCatalogPriceForm.js diff --git a/src/main/frontend/src/components/AddCatalogPriceForm.js b/src/main/frontend/src/components/AddCatalogPriceForm.js deleted file mode 100644 index e3a8234d3e..0000000000 --- a/src/main/frontend/src/components/AddCatalogPriceForm.js +++ /dev/null @@ -1,190 +0,0 @@ -// -// IMPORTANT: -// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file! -// -// @todo #1342 AddCatalogPriceForm: add tests -// @todo #1388 AddCatalogPriceForm: consider using a tooltip for currency - -class AddCatalogPriceForm extends React.PureComponent { - constructor(props) { - super(props); - this.state = { - price: null, - catalog: 'michel', - hasServerError: false, - validationErrors: [], - isDisabled: false - }; - this.handleSubmit = this.handleSubmit.bind(this); - this.handleChangePrice = this.handleChangePrice.bind(this); - this.handleChangeCatalog = this.handleChangeCatalog.bind(this); - } - - handleChangePrice(event) { - event.preventDefault(); - this.setState({ - price: event.target.value - }); - } - - handleChangeCatalog(event) { - event.preventDefault(); - this.setState({ - catalog: event.target.value - }); - } - - handleSubmit(event) { - event.preventDefault(); - - this.setState({ - isDisabled: true, - hasServerError: false, - validationErrors: [] - }); - - axios.patch( - this.props.url, - [ - { - op: 'add', - path: `/${this.state.catalog}_price`, - value: this.state.price - } - ], - { - headers: { - [this.props.csrfHeaderName]: this.props.csrfTokenValue, - 'Cache-Control': 'no-store' - }, - validateStatus: status => { - return status == 204 || status == 400; - } - } - ) - .then(response => { - const data = response.data; - if (data.hasOwnProperty('fieldErrors')) { - const fieldErrors = []; - if (data.fieldErrors.value) { - fieldErrors.push(...data.fieldErrors.value); - } - - this.setState({ - isDisabled: false, - validationErrors: fieldErrors - }); - return; - } - - // no need to reset the state as page will be reloaded - window.location.reload(); - }) - .catch(error => { - console.error(error); - this.setState({ isDisabled: false, hasServerError: true }); - }); - } - render() { - - return ( - - ); - } -} - -class AddCatalogPriceFormView extends React.PureComponent { - - getCurrencyByCatalogName(catalog) { - switch (catalog) { - case 'michel': - case 'yvert': - return ['\u20AC', 'EUR']; - case 'scott': - return ['$', 'USD']; - case 'gibbons': - return ['\u00A3', 'GBP']; - case 'solovyov': - case 'zagorski': - return ['\u20BD', 'RUB']; - } - } - render() { - const {handleSubmit, hasServerError, handleChangeCatalog, handleChangePrice, validationErrors, isDisabled, catalog, l10n} = this.props; - const hasValidationErrors = validationErrors.length > 0; - const [currencySymbol, currencyName] = this.getCurrencyByCatalogName(catalog); - return ( -
-
-
- { l10n['t_server_error'] || 'Server error' } -
-
- -
- -
-
-
- -
-
- { currencySymbol } - -
-
-
-
- - { validationErrors.join(', ') } - - -
-
-
- ); - } -} - -window.AddCatalogPriceForm = AddCatalogPriceForm; diff --git a/src/main/frontend/webpack.config.js b/src/main/frontend/webpack.config.js index d6ca663877..33c3da36da 100644 --- a/src/main/frontend/webpack.config.js +++ b/src/main/frontend/webpack.config.js @@ -8,7 +8,6 @@ module.exports = { 'utils/CatalogUtils': './src/utils/CatalogUtils.js', 'utils/DateUtils': './src/utils/DateUtils.js', - 'components/AddCatalogPriceForm': './src/components/AddCatalogPriceForm.js', 'components/AddReleaseYearForm': './src/components/AddReleaseYearForm.js', 'components/HideImageForm': './src/components/HideImageForm.js', 'components/SeriesSaleImportForm': './src/components/SeriesSaleImportForm.js', diff --git a/src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java b/src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java index 12f01abf0e..c291be3433 100644 --- a/src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java +++ b/src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java @@ -42,7 +42,6 @@ public final class ResourceUrl { private static final String SERIES_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/series/info.min.js"; private static final String SALE_IMPORT_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/SeriesSaleImportForm.min.js"; private static final String SIMILAR_SERIES_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/SimilarSeriesForm.min.js"; - private static final String CATALOG_PRICE_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCatalogPriceForm.min.js"; private static final String RELEASE_YEAR_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddReleaseYearForm.min.js"; private static final String HIDE_IMAGE_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/HideImageForm.min.js"; private static final String SERIES_SALES_LIST_JS = "/public/js/" + RESOURCES_VERSION + "/components/SeriesSalesList.min.js"; @@ -81,7 +80,6 @@ public static void exposeResourcesToView(Map resources, String h put(resources, host, "SERIES_INFO_JS", SERIES_INFO_JS); put(resources, host, "SALE_IMPORT_FORM_JS", SALE_IMPORT_FORM_JS); put(resources, host, "SIMILAR_SERIES_FORM_JS", SIMILAR_SERIES_FORM_JS); - put(resources, host, "CATALOG_PRICE_FORM_JS", CATALOG_PRICE_FORM_JS); put(resources, host, "RELEASE_YEAR_FORM_JS", RELEASE_YEAR_FORM_JS); put(resources, host, "HIDE_IMAGE_FORM_JS", HIDE_IMAGE_FORM_JS); put(resources, host, "SERIES_SALES_LIST_JS", SERIES_SALES_LIST_JS); diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index 0afd487130..e0fbfa418b 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -1318,29 +1318,8 @@
Add info about selling/buying thi /*/--> - - + + From 309345a8a764bd5864d8793e2ebda22ee1efb923 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Tue, 4 Feb 2025 10:26:03 +0700 Subject: [PATCH 05/22] remove errors --- src/main/webapp/WEB-INF/views/series/info.html | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index dad26de4b2..6d7c9ee05c 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -411,12 +411,7 @@
Hidden images
-
-
- Server error -
+
- - Invalid value - From c841b338480d9eafb3e518ea4efdd7a33260684d Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 21 Apr 2025 10:12:08 +0700 Subject: [PATCH 07/22] send patch request & add the simplest handler --- .../feature/series/HtmxSeriesController.java | 25 +++++++++++++++++++ .../webapp/WEB-INF/views/series/info.html | 4 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/mystamps/web/feature/series/HtmxSeriesController.java b/src/main/java/ru/mystamps/web/feature/series/HtmxSeriesController.java index 1b6e101069..12c5c0384a 100644 --- a/src/main/java/ru/mystamps/web/feature/series/HtmxSeriesController.java +++ b/src/main/java/ru/mystamps/web/feature/series/HtmxSeriesController.java @@ -132,5 +132,30 @@ public String addCatalogNumbers( return null; } + + @PatchMapping( + path = SeriesUrl.INFO_SERIES_PAGE, + headers = "HX-Trigger=add-catalog-price-form" + ) + public String addCatalogPrice( + @PathVariable("id") Integer seriesId, + HttpServletResponse response + ) throws IOException { + + if (seriesId == null) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + return null; + } + + if (!seriesService.isSeriesExist(seriesId)) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + return null; + } + + // XXX: implement + System.out.println("PATCH add catalog price"); + + return null; + } } diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index df862f15f9..865f6d1536 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -411,7 +411,9 @@
Hidden images
- +
@@ -531,13 +529,11 @@
Hidden images
@@ -560,13 +556,11 @@
Hidden images
th:placeholder="|#{t_example}: 90-92,117|" th:value="${addCatalogNumbersForm != null ? addCatalogNumbersForm.catalogNumbers : ''}" />
@@ -614,13 +608,11 @@
Hidden images
required="required" th:text="${addCommentForm != null ? addCommentForm.comment : ''}"> From 25bcf1bc96420ba414172bbc971d9ad371ab66e8 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 3 May 2025 19:31:42 +0700 Subject: [PATCH 19/22] Revert "refactor: move th:if from with a single element to that element" This reverts commit ed64365282a26dda6dc5c223915f818de353b938. --- .../webapp/WEB-INF/views/series/info.html | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index 9922041e4b..eb2a39d044 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -436,11 +436,13 @@
Hidden images
@@ -529,11 +531,13 @@
Hidden images
@@ -556,11 +560,13 @@
Hidden images
th:placeholder="|#{t_example}: 90-92,117|" th:value="${addCatalogNumbersForm != null ? addCatalogNumbersForm.catalogNumbers : ''}" /> @@ -608,11 +614,13 @@
Hidden images
required="required" th:text="${addCommentForm != null ? addCommentForm.comment : ''}"> From 0ad1647c022a87332bb01c16558c16a471fe35f9 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 4 May 2025 16:30:36 +0700 Subject: [PATCH 20/22] fix re-displaying price and catalog name on validation error --- .../webapp/WEB-INF/views/series/info.html | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index eb2a39d044..578acd9252 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -427,13 +427,29 @@
Hidden images
Catalog
- + + + + + + @@ -1173,6 +1167,16 @@
Add info about selling/buying thi } } }); + + // https://htmx.org/events/#htmx:load + document.body.addEventListener('htmx:load', function htmxLoadEventHandler(event) { + // NOTE: htmx:load event fires in the beginning, when a page has been loaded, and when a new element + // has been placed after AJAX request. In both cases we need to register custom event listener for the + // add catalog price form. Also, we don't need to do anything, if updated element belongs to another form. + if (event.detail.elt.querySelector('#price-catalog-name') != null) { + initPriceCatalog(); + } + }); /*/-->