Skip to content

Adding catalog numbers to a series #1392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions src/main/frontend/src/components/AddCatalogNumbersForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
//
// IMPORTANT:
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
//

class AddCatalogNumbersForm extends React.Component {
constructor(props) {
super(props);
this.state = {
numbers: null,
catalog: 'michel',
hasServerError: false,
validationErrors: [],
isDisabled: false
};
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChangeNumbers = this.handleChangeNumbers.bind(this);
this.handleChangeCatalog = this.handleChangeCatalog.bind(this);
}

handleChangeNumbers(event) {
event.preventDefault();
this.setState({
numbers: 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}_numbers`,
value: this.state.numbers.split(',')
}
],
{
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.numbers) {
fieldErrors.push(...data.fieldErrors.numbers);
}

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() {
const hasValidationErrors = this.state.validationErrors.length > 0;
return (
<div className="col-sm-12 form-group">
<form className={`form-horizontal ${hasValidationErrors ? 'has-error' : ''}`} onSubmit={this.handleSubmit}>
<div
id="add-catalog-numbers-failed-msg"
className={`alert alert-danger text-center col-sm-8 col-sm-offset-2 ${this.state.hasServerError ? '' : 'hidden'}`}>
{ this.props.l10n['t_server_error'] || 'Server error' }
</div>
<div className="form-group form-group-sm">
<label className="control-label col-sm-3">
{ this.props.l10n['t_catalog'] || 'Catalog' }
</label>
<div className="col-sm-6">
<select
id="catalog-name"
name="catalogName"
className="form-control"
onChange={this.handleChangeCatalog}>
<option value="michel">
{ this.props.l10n['t_michel'] || 'Michel' }
</option>
<option value="scott">
{ this.props.l10n['t_scott'] || 'Scott' }
</option>
<option value="yvert">
{ this.props.l10n['t_yvert'] || 'Yvert et Tellier' }
</option>
<option value="gibbons">
{ this.props.l10n['t_sg'] || 'Stanley Gibbons' }
</option>
<option value="solovyov">
{ this.props.l10n['t_solovyov'] || 'Solovyov' }
</option>
<option value="zagorski">
{ this.props.l10n['t_zagorski'] || 'Zagorski' }
</option>
</select>
</div>
</div>
<div className="form-group form-group-sm">
<label className="control-label col-sm-3">
{ this.props.l10n['t_numbers'] || 'Numbers' }
</label>
<div className="row">
<div className="col-sm-6">
<input
id="catalog-numbers"
type="text"
className="form-control"
size="5"
required="required"
onChange={ this.handleChangeNumbers } />
</div>
</div>
</div>
<div className="col-sm-offset-3 col-sm-4">
<span
id="catalog-numbers.errors"
className={`help-block ${hasValidationErrors ? '' : 'hidden'}`}>
{ this.state.validationErrors.join(', ') }
</span>
<button
type="submit"
className="btn btn-primary btn-sm"
disabled={ this.state.isDisabled }>
{ this.props.l10n['t_add'] || 'Add' }
</button>
</div>
</form>
</div>
);
}
}
6 changes: 4 additions & 2 deletions src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public final class ResourceUrl {
public static final String STATIC_RESOURCES_URL = "https://stamps.filezz.ru";

// MUST be updated when any of our resources were modified
public static final String RESOURCES_VERSION = "v0.4.3.3";
public static final String RESOURCES_VERSION = "v0.4.3.4";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that you have to rebase your branch on top of master.

  1. sync master with php-coder/master
$ git checkout master
$ git fetch upstream
$ git merge upstream/master
$ git push
  1. do rebase
$ git rebase master adding-catalog-numbers-to-a-series
$ git push -f

If you encounter any errors, post them here.


// CheckStyle: ignore LineLength for next 14 lines
// CheckStyle: ignore LineLength for next 15 lines
private static final String CATALOG_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/CatalogUtils.min.js";
private static final String COLLECTION_INFO_JS = "/public/js/" + RESOURCES_VERSION + "/collection/info.min.js";
private static final String DATE_UTILS_JS = "/public/js/" + RESOURCES_VERSION + "/DateUtils.min.js";
Expand All @@ -47,6 +47,7 @@ public final class ResourceUrl {
private static final String SIMILAR_SERIES_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/SimilarSeriesForm.js";
private static final String ADD_COMMENT_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCommentForm.js";
private static final String CATALOG_PRICE_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCatalogPriceForm.js";
private static final String CATALOG_NUMBERS_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddCatalogNumbersForm.js";
private static final String RELEASE_YEAR_FORM_JS = "/public/js/" + RESOURCES_VERSION + "/components/AddReleaseYearForm.js";
private static final String BOOTSTRAP_LANGUAGE = "https://cdn.jsdelivr.net/gh/usrz/bootstrap-languages@3ac2a3d2b27ac43a471cd99e79d378a03b2c6b5f/languages.min.css";
private static final String FAVICON_ICO = "/favicon.ico";
Expand Down Expand Up @@ -85,6 +86,7 @@ public static void exposeResourcesToView(Map<String, String> resources, String h
put(resources, host, "SIMILAR_SERIES_FORM_JS", SIMILAR_SERIES_FORM_JS);
put(resources, host, "ADD_COMMENT_FORM_JS", ADD_COMMENT_FORM_JS);
put(resources, host, "CATALOG_PRICE_FORM_JS", CATALOG_PRICE_FORM_JS);
put(resources, host, "CATALOG_NUMBERS_FORM_JS", CATALOG_NUMBERS_FORM_JS);
put(resources, host, "RELEASE_YEAR_FORM_JS", RELEASE_YEAR_FORM_JS);
}

Expand Down
18 changes: 17 additions & 1 deletion src/main/webapp/WEB-INF/views/series/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ <h5 th:text="#{t_hidden_images}">Hidden images</h5>
<div id="add-release-year" sec:authorize="hasAuthority('CREATE_SERIES')"></div>

<div id="add-catalog-price" sec:authorize="hasAuthority('CREATE_SERIES')"></div>

<div id="add-catalog-numbers" sec:authorize="hasAuthority('CREATE_SERIES')"></div>

<div id="add-comment" sec:authorize="hasAuthority('ADD_COMMENTS_TO_SERIES')"></div>

Expand Down Expand Up @@ -931,7 +933,8 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
'fieldErrors': {
'comment': ['Comment error'],
'year': ['Year error'],
'price': ['Price error']
'price': ['Price error'],
'numbers': ['Numbers error']
}
}
},
Expand Down Expand Up @@ -977,6 +980,8 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
/*/-->
<script src="../../../../../../target/classes/js/components/AddReleaseYearForm.js" th:src="${RELEASE_YEAR_FORM_JS}"></script>
<script src="../../../../../../target/classes/js/components/AddCatalogPriceForm.js" th:src="${CATALOG_PRICE_FORM_JS}"></script>
<script src="../../../../../../target/classes/js/components/AddCatalogNumbersForm.js" th:src="${CATALOG_NUMBERS_FORM_JS}"></script>

<script th:inline="javascript">
/*[+
var addReleaseYearProps = {
Expand All @@ -992,6 +997,12 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
'l10n': {
}
};
var addCatalogNumbersProps = {
'csrfHeaderName': [[ ${_csrf.headerName} ]],
'csrfTokenValue': [[ ${_csrf.token} ]],
'l10n': {
}
};
+]*/

/*[- */
Expand All @@ -1005,10 +1016,15 @@ <h5 th:text="#{t_add_info_who_selling_series}">Add info about selling/buying thi
'url': '/series/100',
'l10n': {}
};
var addCatalogNumbersProps = {
'url': '/series/100',
'l10n': {}
};
/* -]*/

renderComponent(AddReleaseYearForm, addReleaseYearProps, 'add-release-year');
renderComponent(AddCatalogPriceForm, addCatalogPriceProps, 'add-catalog-price');
renderComponent(AddCatalogNumbersForm, addCatalogNumbersProps, 'add-catalog-numbers');
</script>
<!--/*/
</th:block>
Expand Down