@luomus/laji-form 15.0.0 → 15.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -4
- package/dist/laji-form.js +1 -1
- package/dist/styles.css +81 -90
- package/jsonconfig.json +26 -0
- package/migrate.sh +0 -1
- package/package.json +8 -8
- package/test-export/array-spec.js +204 -0
- package/test-export/bird-point-count-spec.d.ts +1 -0
- package/test-export/bird-point-count-spec.js +62 -0
- package/test-export/collection-contest-form-spec.d.ts +1 -0
- package/test-export/collection-contest-form-spec.js +38 -0
- package/test-export/dataset-form-spec.d.ts +1 -0
- package/test-export/dataset-form-spec.js +50 -0
- package/test-export/date-time-widget-spec.d.ts +1 -0
- package/test-export/date-time-widget-spec.js +188 -0
- package/test-export/geocoder-spec.d.ts +1 -0
- package/test-export/geocoder-spec.js +135 -0
- package/test-export/image-array-spec.d.ts +1 -0
- package/test-export/image-array-spec.js +94 -0
- package/test-export/inject-field-spec.d.ts +1 -0
- package/test-export/inject-field-spec.js +148 -0
- package/test-export/internal-uuids-spec.d.ts +1 -0
- package/test-export/internal-uuids-spec.js +157 -0
- package/test-export/invasive-species-eradication-np-spec.d.ts +1 -0
- package/test-export/invasive-species-eradication-np-spec.js +18 -0
- package/test-export/invasive-species-eradication-spec.d.ts +1 -0
- package/test-export/invasive-species-eradication-spec.js +25 -0
- package/test-export/line-transect-spec.d.ts +1 -0
- package/test-export/line-transect-spec.js +121 -0
- package/test-export/mobile-form-spec.d.ts +1 -0
- package/test-export/mobile-form-spec.js +84 -0
- package/test-export/nafi-spec.d.ts +1 -0
- package/test-export/nafi-spec.js +85 -0
- package/test-export/select-widget-spec.d.ts +1 -0
- package/test-export/select-widget-spec.js +68 -0
- package/test-export/single-item-array-field-spec.d.ts +1 -0
- package/test-export/single-item-array-field-spec.js +92 -0
- package/test-export/syke-butterfly-spec.d.ts +1 -0
- package/test-export/syke-butterfly-spec.js +163 -0
- package/test-export/test-utils.d.ts +150 -176
- package/test-export/test-utils.js +218 -210
- package/test-export/transaction-form-spec.d.ts +1 -0
- package/test-export/transaction-form-spec.js +63 -0
- package/test-export/trip-report-autosuggest-spec.d.ts +1 -0
- package/test-export/trip-report-autosuggest-spec.js +272 -0
- package/test-export/trip-report-spec.d.ts +1 -0
- package/test-export/trip-report-spec.js +456 -0
- package/test-export/unit-list-shorthand-array-field-spec.d.ts +1 -0
- package/test-export/unit-list-shorthand-array-field-spec.js +71 -0
- package/test-export/validation-spec.d.ts +1 -0
- package/test-export/validation-spec.js +336 -0
- package/test-export/water-bird-spec.d.ts +1 -0
- package/test-export/water-bird-spec.js +30 -0
- package/test-export/wbc-spec.d.ts +1 -0
- package/test-export/wbc-spec.js +82 -0
- package/tsconfig.test.json +1 -1
- package/xsel -b +9 -0
- package/cypress/fixtures/example.json +0 -5
- package/cypress/screenshots/nafi.cy.ts/NAFI (MHL.6) -- selecting species name with keyboard navigation -- and closes suggestion list (failed).png +0 -0
- package/cypress/screenshots/nafi.cy.ts/NAFI (MHL.6) -- selecting species name with keyboard navigation -- and is marked as suggested (failed).png +0 -0
- package/lib/ApiClient.d.ts +0 -46
- package/lib/ApiClient.js +0 -93
- package/lib/Context.d.ts +0 -8
- package/lib/Context.js +0 -18
- package/lib/ReactContext.d.ts +0 -7
- package/lib/ReactContext.js +0 -5
- package/lib/components/BaseComponent.d.ts +0 -9
- package/lib/components/BaseComponent.js +0 -29
- package/lib/components/LajiForm.d.ts +0 -221
- package/lib/components/LajiForm.js +0 -615
- package/lib/components/VirtualSchemaField.d.ts +0 -42
- package/lib/components/VirtualSchemaField.js +0 -74
- package/lib/components/components.d.ts +0 -119
- package/lib/components/components.js +0 -606
- package/lib/components/fields/AnnotationField.d.ts +0 -34
- package/lib/components/fields/AnnotationField.js +0 -242
- package/lib/components/fields/AnyToBooleanField.d.ts +0 -18
- package/lib/components/fields/AnyToBooleanField.js +0 -20
- package/lib/components/fields/ArrayBulkField.d.ts +0 -23
- package/lib/components/fields/ArrayBulkField.js +0 -82
- package/lib/components/fields/ArrayCombinerField.d.ts +0 -36
- package/lib/components/fields/ArrayCombinerField.js +0 -138
- package/lib/components/fields/ArrayField.d.ts +0 -39
- package/lib/components/fields/ArrayField.js +0 -148
- package/lib/components/fields/AudioArrayField.d.ts +0 -22
- package/lib/components/fields/AudioArrayField.js +0 -100
- package/lib/components/fields/AutoArrayField.d.ts +0 -24
- package/lib/components/fields/AutoArrayField.js +0 -56
- package/lib/components/fields/AutosuggestField.d.ts +0 -69
- package/lib/components/fields/AutosuggestField.js +0 -299
- package/lib/components/fields/CombinedValueDisplayField.d.ts +0 -41
- package/lib/components/fields/CombinedValueDisplayField.js +0 -100
- package/lib/components/fields/ConditionalOnChangeField.d.ts +0 -42
- package/lib/components/fields/ConditionalOnChangeField.js +0 -107
- package/lib/components/fields/ConditionalUiSchemaField.d.ts +0 -123
- package/lib/components/fields/ConditionalUiSchemaField.js +0 -143
- package/lib/components/fields/ContextInjectionField.d.ts +0 -24
- package/lib/components/fields/ContextInjectionField.js +0 -68
- package/lib/components/fields/DataLeakerField.d.ts +0 -40
- package/lib/components/fields/DataLeakerField.js +0 -68
- package/lib/components/fields/DefaultValueArrayField.d.ts +0 -34
- package/lib/components/fields/DefaultValueArrayField.js +0 -59
- package/lib/components/fields/DependentBooleanField.d.ts +0 -38
- package/lib/components/fields/DependentBooleanField.js +0 -87
- package/lib/components/fields/DependentDisableField.d.ts +0 -35
- package/lib/components/fields/DependentDisableField.js +0 -71
- package/lib/components/fields/EnumRangeArrayField.d.ts +0 -27
- package/lib/components/fields/EnumRangeArrayField.js +0 -115
- package/lib/components/fields/ExtraLabelRowField.d.ts +0 -38
- package/lib/components/fields/ExtraLabelRowField.js +0 -100
- package/lib/components/fields/FakePropertyField.d.ts +0 -18
- package/lib/components/fields/FakePropertyField.js +0 -48
- package/lib/components/fields/FilterArrayField.d.ts +0 -73
- package/lib/components/fields/FilterArrayField.js +0 -121
- package/lib/components/fields/FlatField.d.ts +0 -29
- package/lib/components/fields/FlatField.js +0 -171
- package/lib/components/fields/GeocoderField.d.ts +0 -47
- package/lib/components/fields/GeocoderField.js +0 -372
- package/lib/components/fields/GridLayoutField.d.ts +0 -18
- package/lib/components/fields/GridLayoutField.js +0 -32
- package/lib/components/fields/HiddenField.d.ts +0 -10
- package/lib/components/fields/HiddenField.js +0 -11
- package/lib/components/fields/ImageArrayField.d.ts +0 -172
- package/lib/components/fields/ImageArrayField.js +0 -697
- package/lib/components/fields/ImageDisplayField.d.ts +0 -18
- package/lib/components/fields/ImageDisplayField.js +0 -44
- package/lib/components/fields/InitiallyHiddenField.d.ts +0 -21
- package/lib/components/fields/InitiallyHiddenField.js +0 -58
- package/lib/components/fields/InjectDefaultValueField.d.ts +0 -37
- package/lib/components/fields/InjectDefaultValueField.js +0 -68
- package/lib/components/fields/InjectField.d.ts +0 -46
- package/lib/components/fields/InjectField.js +0 -88
- package/lib/components/fields/InputWithDefaultValueButtonField.d.ts +0 -25
- package/lib/components/fields/InputWithDefaultValueButtonField.js +0 -61
- package/lib/components/fields/LocalityField.d.ts +0 -22
- package/lib/components/fields/LocalityField.js +0 -94
- package/lib/components/fields/LocationChooserField.d.ts +0 -27
- package/lib/components/fields/LocationChooserField.js +0 -440
- package/lib/components/fields/MapArrayField.d.ts +0 -78
- package/lib/components/fields/MapArrayField.js +0 -1783
- package/lib/components/fields/MapField.d.ts +0 -48
- package/lib/components/fields/MapField.js +0 -434
- package/lib/components/fields/MultiAnyToBooleanField.d.ts +0 -25
- package/lib/components/fields/MultiAnyToBooleanField.js +0 -100
- package/lib/components/fields/MultiArrayField.d.ts +0 -53
- package/lib/components/fields/MultiArrayField.js +0 -224
- package/lib/components/fields/MultiLanguageField.d.ts +0 -13
- package/lib/components/fields/MultiLanguageField.js +0 -52
- package/lib/components/fields/MultiTagArrayField.d.ts +0 -36
- package/lib/components/fields/MultiTagArrayField.js +0 -142
- package/lib/components/fields/NamedPlaceChooserField.d.ts +0 -29
- package/lib/components/fields/NamedPlaceChooserField.js +0 -380
- package/lib/components/fields/NamedPlaceSaverField.d.ts +0 -29
- package/lib/components/fields/NamedPlaceSaverField.js +0 -237
- package/lib/components/fields/NestField.d.ts +0 -148
- package/lib/components/fields/NestField.js +0 -289
- package/lib/components/fields/ObjectField.d.ts +0 -2
- package/lib/components/fields/ObjectField.js +0 -119
- package/lib/components/fields/PdfArrayField.d.ts +0 -21
- package/lib/components/fields/PdfArrayField.js +0 -40
- package/lib/components/fields/PrefillingArrayField.d.ts +0 -22
- package/lib/components/fields/PrefillingArrayField.js +0 -65
- package/lib/components/fields/SchemaField.d.ts +0 -7
- package/lib/components/fields/SchemaField.js +0 -109
- package/lib/components/fields/ScopeField.d.ts +0 -85
- package/lib/components/fields/ScopeField.js +0 -521
- package/lib/components/fields/SectionArrayField.d.ts +0 -38
- package/lib/components/fields/SectionArrayField.js +0 -618
- package/lib/components/fields/SelectTreeField.d.ts +0 -39
- package/lib/components/fields/SelectTreeField.js +0 -143
- package/lib/components/fields/SingleActiveArrayField.d.ts +0 -49
- package/lib/components/fields/SingleActiveArrayField.js +0 -974
- package/lib/components/fields/SingleItemArrayField.d.ts +0 -15
- package/lib/components/fields/SingleItemArrayField.js +0 -60
- package/lib/components/fields/SortArrayField.d.ts +0 -73
- package/lib/components/fields/SortArrayField.js +0 -351
- package/lib/components/fields/SplitField.d.ts +0 -28
- package/lib/components/fields/SplitField.js +0 -65
- package/lib/components/fields/StringToArrayField.d.ts +0 -24
- package/lib/components/fields/StringToArrayField.js +0 -48
- package/lib/components/fields/SumField.d.ts +0 -35
- package/lib/components/fields/SumField.js +0 -83
- package/lib/components/fields/TableField.d.ts +0 -18
- package/lib/components/fields/TableField.js +0 -136
- package/lib/components/fields/TagArrayField.d.ts +0 -38
- package/lib/components/fields/TagArrayField.js +0 -128
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.d.ts +0 -26
- package/lib/components/fields/ToggleAdditionalArrayFieldsField.js +0 -81
- package/lib/components/fields/UiFieldApplierField.d.ts +0 -30
- package/lib/components/fields/UiFieldApplierField.js +0 -106
- package/lib/components/fields/UiFieldMapperArrayField.d.ts +0 -42
- package/lib/components/fields/UiFieldMapperArrayField.js +0 -121
- package/lib/components/fields/UnitCountShorthandField.d.ts +0 -22
- package/lib/components/fields/UnitCountShorthandField.js +0 -149
- package/lib/components/fields/UnitListShorthandArrayField.d.ts +0 -26
- package/lib/components/fields/UnitListShorthandArrayField.js +0 -108
- package/lib/components/fields/UnitShorthandField.d.ts +0 -32
- package/lib/components/fields/UnitShorthandField.js +0 -220
- package/lib/components/templates/ArrayFieldTemplate.d.ts +0 -85
- package/lib/components/templates/ArrayFieldTemplate.js +0 -417
- package/lib/components/templates/BaseInputTemplate.d.ts +0 -11
- package/lib/components/templates/BaseInputTemplate.js +0 -80
- package/lib/components/templates/DescriptionField.d.ts +0 -1
- package/lib/components/templates/DescriptionField.js +0 -37
- package/lib/components/templates/ErrorListTemplate.d.ts +0 -9
- package/lib/components/templates/ErrorListTemplate.js +0 -95
- package/lib/components/templates/FieldTemplate.d.ts +0 -6
- package/lib/components/templates/FieldTemplate.js +0 -112
- package/lib/components/templates/ObjectFieldTemplate.d.ts +0 -7
- package/lib/components/templates/ObjectFieldTemplate.js +0 -66
- package/lib/components/templates/TitleField.d.ts +0 -9
- package/lib/components/templates/TitleField.js +0 -51
- package/lib/components/widgets/AnyToBooleanWidget.d.ts +0 -20
- package/lib/components/widgets/AnyToBooleanWidget.js +0 -49
- package/lib/components/widgets/AutosuggestWidget.d.ts +0 -66
- package/lib/components/widgets/AutosuggestWidget.js +0 -1127
- package/lib/components/widgets/CheckboxWidget.d.ts +0 -37
- package/lib/components/widgets/CheckboxWidget.js +0 -139
- package/lib/components/widgets/DateTimeWidget.d.ts +0 -62
- package/lib/components/widgets/DateTimeWidget.js +0 -251
- package/lib/components/widgets/DateWidget.d.ts +0 -23
- package/lib/components/widgets/DateWidget.js +0 -41
- package/lib/components/widgets/HiddenWidget.d.ts +0 -15
- package/lib/components/widgets/HiddenWidget.js +0 -19
- package/lib/components/widgets/ImageSelectWidget.d.ts +0 -14
- package/lib/components/widgets/ImageSelectWidget.js +0 -57
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.d.ts +0 -43
- package/lib/components/widgets/InformalTaxonGroupChooserWidget.js +0 -237
- package/lib/components/widgets/InputGroupWidget.d.ts +0 -21
- package/lib/components/widgets/InputGroupWidget.js +0 -36
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.d.ts +0 -21
- package/lib/components/widgets/InputWithDefaultValueButtonWidget.js +0 -47
- package/lib/components/widgets/NumberWidget.d.ts +0 -13
- package/lib/components/widgets/NumberWidget.js +0 -21
- package/lib/components/widgets/PlainTextWidget.d.ts +0 -12
- package/lib/components/widgets/PlainTextWidget.js +0 -24
- package/lib/components/widgets/SelectWidget.d.ts +0 -52
- package/lib/components/widgets/SelectWidget.js +0 -158
- package/lib/components/widgets/SeparatedDateTimeWidget.d.ts +0 -19
- package/lib/components/widgets/SeparatedDateTimeWidget.js +0 -59
- package/lib/components/widgets/TaxonImageWidget.d.ts +0 -13
- package/lib/components/widgets/TaxonImageWidget.js +0 -30
- package/lib/components/widgets/TextSelectWidget.d.ts +0 -25
- package/lib/components/widgets/TextSelectWidget.js +0 -94
- package/lib/components/widgets/TextareaWidget.d.ts +0 -32
- package/lib/components/widgets/TextareaWidget.js +0 -87
- package/lib/components/widgets/TimeWidget.d.ts +0 -11
- package/lib/components/widgets/TimeWidget.js +0 -19
- package/lib/components/widgets/URLWidget.d.ts +0 -14
- package/lib/components/widgets/URLWidget.js +0 -12
- package/lib/components/widgets/UpperCaseWidget.d.ts +0 -13
- package/lib/components/widgets/UpperCaseWidget.js +0 -21
- package/lib/index.d.ts +0 -20
- package/lib/index.js +0 -50
- package/lib/services/blocker-service.d.ts +0 -11
- package/lib/services/blocker-service.js +0 -55
- package/lib/services/custom-event-service.d.ts +0 -17
- package/lib/services/custom-event-service.js +0 -35
- package/lib/services/dom-id-service.d.ts +0 -8
- package/lib/services/dom-id-service.js +0 -30
- package/lib/services/focus-service.d.ts +0 -13
- package/lib/services/focus-service.js +0 -60
- package/lib/services/id-service.d.ts +0 -22
- package/lib/services/id-service.js +0 -130
- package/lib/services/key-handler-service.d.ts +0 -56
- package/lib/services/key-handler-service.js +0 -184
- package/lib/services/root-instance-service.d.ts +0 -25
- package/lib/services/root-instance-service.js +0 -49
- package/lib/services/settings-service.d.ts +0 -34
- package/lib/services/settings-service.js +0 -154
- package/lib/services/singleton-map-service.d.ts +0 -23
- package/lib/services/singleton-map-service.js +0 -44
- package/lib/services/submit-hook-service.d.ts +0 -24
- package/lib/services/submit-hook-service.js +0 -73
- package/lib/styles.js +0 -4
- package/lib/themes/bs3.d.ts +0 -3
- package/lib/themes/bs3.js +0 -133
- package/lib/themes/bs5.d.ts +0 -3
- package/lib/themes/bs5.js +0 -111
- package/lib/themes/glyphicon-fa-mapping.d.ts +0 -3
- package/lib/themes/glyphicon-fa-mapping.js +0 -271
- package/lib/themes/stub.d.ts +0 -3
- package/lib/themes/stub.js +0 -82
- package/lib/themes/theme.d.ts +0 -233
- package/lib/themes/theme.js +0 -2
- package/lib/translations.json +0 -847
- package/lib/utils.d.ts +0 -171
- package/lib/utils.js +0 -1191
- package/lib/validation.d.ts +0 -7
- package/lib/validation.js +0 -141
- package/llol +0 -10
- package/llol.pdf +0 -10
- package/playwright-report/index.html +0 -62
- package/q +0 -196
- package/rename.sh +0 -24
- package/trip-report.spec.ts +0 -594
- /package/{lib/styles.d.ts → test-export/array-spec.d.ts} +0 -0
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
const React = require("react");
|
|
10
|
-
const react_dom_1 = require("react-dom");
|
|
11
|
-
const PropTypes = require("prop-types");
|
|
12
|
-
const utils_1 = require("../../utils");
|
|
13
|
-
const components_1 = require("../components");
|
|
14
|
-
const Spinner = require("react-spinner");
|
|
15
|
-
const Context_1 = require("../../Context");
|
|
16
|
-
const ReactContext_1 = require("../../ReactContext");
|
|
17
|
-
const BaseComponent_1 = require("../BaseComponent");
|
|
18
|
-
const MapArrayField_1 = require("./MapArrayField");
|
|
19
|
-
const globals_1 = require("@luomus/laji-map/lib/globals");
|
|
20
|
-
const SelectWidget_1 = require("../widgets/SelectWidget");
|
|
21
|
-
const PLACES_FETCH_FAIL = "PLACES_FETCH_FAIL";
|
|
22
|
-
const PLACE_USE_FAIL = "PLACE_USE_FAIL";
|
|
23
|
-
const PLACE_DELETE_FAIL = "PLACE_DELETE_FAIL";
|
|
24
|
-
/**
|
|
25
|
-
* Compatible only with gatherings array and gathering object.
|
|
26
|
-
*/
|
|
27
|
-
let NamedPlaceChooserField = class NamedPlaceChooserField extends React.Component {
|
|
28
|
-
constructor(props) {
|
|
29
|
-
super(props);
|
|
30
|
-
this.getUiSchema = (props) => {
|
|
31
|
-
if (this.buttonDefinition) {
|
|
32
|
-
this.buttonDefinition = Object.assign(Object.assign({}, this.buttonDefinition), { label: props.formContext.translations.ChooseFromNamedPlace });
|
|
33
|
-
const innerUiSchema = utils_1.getInnerUiSchema(props.uiSchema);
|
|
34
|
-
const options = utils_1.getUiOptions(innerUiSchema);
|
|
35
|
-
return Object.assign(Object.assign({}, innerUiSchema), { "ui:options": Object.assign(Object.assign({}, options), { buttons: [
|
|
36
|
-
this.buttonDefinition,
|
|
37
|
-
...(options.buttons || [])
|
|
38
|
-
] }) });
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return utils_1.getInnerUiSchema(props.uiSchema);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
this.isGatheringsArray = () => this.props.schema.type === "array";
|
|
45
|
-
this.onPlaceSelected = (place) => {
|
|
46
|
-
const getGathering = (schema) => {
|
|
47
|
-
const whitelist = ["geometry", "country", "administrativeProvince", "biologicalProvince", "municipality", "locality", "localityDescription", "habitat", "habitatDescription"];
|
|
48
|
-
let gathering = utils_1.getDefaultFormState(schema);
|
|
49
|
-
const placeGathering = place.prepopulatedDocument.gatherings[0];
|
|
50
|
-
whitelist.forEach(prop => {
|
|
51
|
-
if (prop in placeGathering && prop in schema.properties) {
|
|
52
|
-
gathering[prop] = placeGathering[prop];
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
gathering.namedPlaceID = place.id;
|
|
56
|
-
const tmpIdTree = this.props.formContext.services.ids.getRelativeTmpIdTree(this.props.idSchema.$id);
|
|
57
|
-
const [withLajiFormIds] = utils_1.addLajiFormIds(gathering, tmpIdTree, false);
|
|
58
|
-
return withLajiFormIds;
|
|
59
|
-
};
|
|
60
|
-
try {
|
|
61
|
-
let targetId, gathering, newFormData, zoomToData;
|
|
62
|
-
if (this.isGatheringsArray()) {
|
|
63
|
-
gathering = getGathering(this.props.schema.items);
|
|
64
|
-
newFormData = [
|
|
65
|
-
...(this.props.formData || []),
|
|
66
|
-
gathering
|
|
67
|
-
];
|
|
68
|
-
this.setState({ show: false });
|
|
69
|
-
targetId = this.props.idSchema.$id;
|
|
70
|
-
this.props.formContext.services.customEvents.send(targetId, "activeIdx", (this.props.formData || []).length);
|
|
71
|
-
}
|
|
72
|
-
else { // gathering object
|
|
73
|
-
gathering = getGathering(this.props.schema);
|
|
74
|
-
gathering.namedPlaceID = place.id;
|
|
75
|
-
newFormData = Object.assign(Object.assign({}, this.props.formData), gathering);
|
|
76
|
-
this.setState({ show: false });
|
|
77
|
-
const splits = this.props.idSchema.$id.split("_");
|
|
78
|
-
splits.pop();
|
|
79
|
-
targetId = splits.join("_");
|
|
80
|
-
zoomToData = true;
|
|
81
|
-
}
|
|
82
|
-
this.props.onChange(newFormData);
|
|
83
|
-
if (zoomToData)
|
|
84
|
-
this.props.formContext.services.customEvents.send(targetId, "zoomToData", undefined);
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
this.setState({ failed: PLACE_USE_FAIL });
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
this.onPlaceDeleted = (place, success) => {
|
|
91
|
-
this.apiClient.fetchRaw(`/named-places/${place.id}`, undefined, { method: "DELETE" }).then(response => {
|
|
92
|
-
if (response.status === 204) {
|
|
93
|
-
// It takes a while for API to remove the place, so we remove it locally and then invalidate again after some time.
|
|
94
|
-
this.removeIds[place.id] = true;
|
|
95
|
-
this.apiClient.invalidateCachePath("/named-places");
|
|
96
|
-
setTimeout(() => this.apiClient.invalidateCachePath("/named-places"), 2000);
|
|
97
|
-
success();
|
|
98
|
-
}
|
|
99
|
-
}).catch(() => {
|
|
100
|
-
this.setState({ failed: PLACE_DELETE_FAIL });
|
|
101
|
-
this.props.formContext.notifier.error(this.props.formContext.translations.PlaceRemovalFailed);
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
this.onButtonClick = () => () => {
|
|
105
|
-
this.setState({ show: true });
|
|
106
|
-
};
|
|
107
|
-
this.updatePlaces = () => {
|
|
108
|
-
this.buttonDefinition = undefined;
|
|
109
|
-
this.apiClient.fetchCached("/named-places", { includePublic: false, pageSize: 10000 }).then(response => {
|
|
110
|
-
if (!this.mounted)
|
|
111
|
-
return;
|
|
112
|
-
const state = { places: response.results.filter(p => !this.removeIds[p.id]).sort((a, b) => {
|
|
113
|
-
if (a.name < b.name)
|
|
114
|
-
return -1;
|
|
115
|
-
if (a.name > b.name)
|
|
116
|
-
return 1;
|
|
117
|
-
return 0;
|
|
118
|
-
}) };
|
|
119
|
-
if (response.results && response.results.length) {
|
|
120
|
-
this.buttonDefinition = {
|
|
121
|
-
fn: this.onButtonClick,
|
|
122
|
-
fnName: "addNamedPlace",
|
|
123
|
-
glyph: "map-marker",
|
|
124
|
-
label: this.props.formContext.translations.ChooseFromNamedPlace,
|
|
125
|
-
id: this.props.idSchema.$id,
|
|
126
|
-
changesFormData: true,
|
|
127
|
-
variant: "primary"
|
|
128
|
-
};
|
|
129
|
-
if (this.isGatheringsArray()) {
|
|
130
|
-
this.buttonDefinition.rules = { canAdd: true };
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
this.buttonDefinition.position = "top";
|
|
134
|
-
}
|
|
135
|
-
const uiSchema = this.getUiSchema(this.props);
|
|
136
|
-
state.uiSchema = uiSchema;
|
|
137
|
-
}
|
|
138
|
-
this.setState(state);
|
|
139
|
-
}).catch(() => {
|
|
140
|
-
this.setState({ failed: PLACES_FETCH_FAIL });
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
this.onHide = () => this.setState({ show: false });
|
|
144
|
-
this.apiClient = props.formContext.apiClient;
|
|
145
|
-
this.removeIds = {};
|
|
146
|
-
}
|
|
147
|
-
getStateFromProps(props) {
|
|
148
|
-
return { uiSchema: this.getUiSchema(props) };
|
|
149
|
-
}
|
|
150
|
-
componentDidMount() {
|
|
151
|
-
this.mounted = true;
|
|
152
|
-
this.updatePlaces();
|
|
153
|
-
this.apiClient.onCachePathInvalidation("/named-places", this.updatePlaces);
|
|
154
|
-
}
|
|
155
|
-
componentWillUnmount() {
|
|
156
|
-
this.mounted = false;
|
|
157
|
-
this.apiClient.removeOnCachePathInvalidation("/named-places", this.updatePlaces);
|
|
158
|
-
}
|
|
159
|
-
render() {
|
|
160
|
-
const { registry: { fields: { SchemaField } }, formContext } = this.props;
|
|
161
|
-
const { translations } = formContext;
|
|
162
|
-
const { failed } = this.state;
|
|
163
|
-
const { Modal, Alert } = this.context.theme;
|
|
164
|
-
return (React.createElement(React.Fragment, null,
|
|
165
|
-
React.createElement(SchemaField, Object.assign({}, this.props, { uiSchema: this.state.uiSchema })),
|
|
166
|
-
this.state.show ? (React.createElement(Modal, { dialogClassName: "laji-form map-dialog named-place-chooser-modal", show: true, onHide: this.onHide },
|
|
167
|
-
React.createElement(Modal.Header, { closeButton: true }, translations.ChooseNamedPlace),
|
|
168
|
-
React.createElement(Modal.Body, null,
|
|
169
|
-
failed === PLACE_USE_FAIL && React.createElement(Alert, { variant: "danger" }, translations.NamedPlacesUseFail),
|
|
170
|
-
failed === PLACES_FETCH_FAIL && React.createElement(Alert, { variant: "danger" }, translations.NamedPlacesFetchFail),
|
|
171
|
-
React.createElement(NamedPlaceChooser, { places: this.state.places, failed: failed === PLACES_FETCH_FAIL ? true : false, formContext: formContext, onSelected: this.onPlaceSelected, onDeleted: this.onPlaceDeleted })))) : null));
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
NamedPlaceChooserField.contextType = ReactContext_1.default;
|
|
175
|
-
NamedPlaceChooserField.propTypes = {
|
|
176
|
-
schema: PropTypes.shape({
|
|
177
|
-
type: PropTypes.oneOf(["object", "array"])
|
|
178
|
-
}).isRequired,
|
|
179
|
-
formData: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
|
|
180
|
-
};
|
|
181
|
-
NamedPlaceChooserField = __decorate([
|
|
182
|
-
BaseComponent_1.default
|
|
183
|
-
], NamedPlaceChooserField);
|
|
184
|
-
exports.default = NamedPlaceChooserField;
|
|
185
|
-
class NamedPlaceChooser extends React.Component {
|
|
186
|
-
constructor(props) {
|
|
187
|
-
super(props);
|
|
188
|
-
this.onPlaceSelected = (place) => {
|
|
189
|
-
this.props.onSelected(place);
|
|
190
|
-
};
|
|
191
|
-
this.onPlaceDeleted = (place) => {
|
|
192
|
-
const onDelete = () => {
|
|
193
|
-
if (this.popupContainerElem && this.popupElem) {
|
|
194
|
-
this.popupContainerElem.appendChild(react_dom_1.findDOMNode(this.popupElem));
|
|
195
|
-
}
|
|
196
|
-
this.mapElem.map.map.closePopup();
|
|
197
|
-
this.setState({ deleting: false, popupIdx: undefined });
|
|
198
|
-
};
|
|
199
|
-
this.setState({ deleting: true });
|
|
200
|
-
this.props.onDeleted(place, onDelete);
|
|
201
|
-
};
|
|
202
|
-
this.onSelectChange = (idx) => {
|
|
203
|
-
if (idx === undefined) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const { map } = this.mapElem;
|
|
207
|
-
const layers = this.idxToLayer[idx];
|
|
208
|
-
const [layer] = layers;
|
|
209
|
-
const bounds = map.getBoundsForLayers(layers);
|
|
210
|
-
const center = bounds.getCenter();
|
|
211
|
-
map.fitBounds(bounds, { animate: false });
|
|
212
|
-
this.props.formContext.setTimeout(() => layer.fire("click", { latlng: center }), 10);
|
|
213
|
-
};
|
|
214
|
-
this.onMapChange = (events) => {
|
|
215
|
-
events.some(({ type, idx }) => {
|
|
216
|
-
if (type === "active") {
|
|
217
|
-
this.setState({ popupIdx: idx });
|
|
218
|
-
const { map } = this.mapElem;
|
|
219
|
-
if (this.geometryCollectionData) {
|
|
220
|
-
map.setData();
|
|
221
|
-
}
|
|
222
|
-
this.geometryCollectionData = {
|
|
223
|
-
geoData: this.props.places[idx].geometry
|
|
224
|
-
};
|
|
225
|
-
map.setData(this.geometryCollectionData);
|
|
226
|
-
return true;
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
this.getFeatureStyle = (data) => {
|
|
231
|
-
const { feature = {} } = data || {};
|
|
232
|
-
function getColor(idx) {
|
|
233
|
-
const r = globals_1.NORMAL_COLOR.substring(1, 3);
|
|
234
|
-
const g = globals_1.NORMAL_COLOR.substring(3, 5);
|
|
235
|
-
const b = globals_1.NORMAL_COLOR.substring(5, 7);
|
|
236
|
-
return [r, g, b].reduce((rgb, hex) => {
|
|
237
|
-
const decimal = parseInt(hex, 16);
|
|
238
|
-
const amount = 40;
|
|
239
|
-
const _decimal = (idx % 2) ? decimal : Math.min(decimal + amount, 255);
|
|
240
|
-
return rgb + _decimal.toString(16);
|
|
241
|
-
}, "#");
|
|
242
|
-
}
|
|
243
|
-
const { idx } = feature.properties || {};
|
|
244
|
-
const color = idx === this.state.popupIdx ? globals_1.ACTIVE_COLOR : getColor(idx);
|
|
245
|
-
return { color, fillColor: color };
|
|
246
|
-
};
|
|
247
|
-
this.setPopupContainerRef = (elem) => {
|
|
248
|
-
this.popupContainerElem = elem;
|
|
249
|
-
};
|
|
250
|
-
this.state = {};
|
|
251
|
-
}
|
|
252
|
-
componentDidUpdate(prevProps, prevState) {
|
|
253
|
-
const { map } = this.mapElem;
|
|
254
|
-
this.idxToLayer = map.data.reduce((idxToLayer, item) => {
|
|
255
|
-
const layerGroup = item.group;
|
|
256
|
-
layerGroup.eachLayer(layer => {
|
|
257
|
-
if (!idxToLayer[layer.feature.properties.idx]) {
|
|
258
|
-
idxToLayer[layer.feature.properties.idx] = [];
|
|
259
|
-
}
|
|
260
|
-
idxToLayer[layer.feature.properties.idx].push(layer);
|
|
261
|
-
});
|
|
262
|
-
return idxToLayer;
|
|
263
|
-
}, {});
|
|
264
|
-
if (this.state.popupIdx !== prevState.popupIdx) {
|
|
265
|
-
const prevLayers = this.idxToLayer[prevState.popupIdx] || [];
|
|
266
|
-
const layers = this.idxToLayer[this.state.popupIdx] || [];
|
|
267
|
-
[prevLayers, layers].forEach(layers => {
|
|
268
|
-
layers.forEach(layer => {
|
|
269
|
-
if (layer) {
|
|
270
|
-
map.setLayerStyle(layer, this.getFeatureStyle({ feature: layer.feature }));
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
render() {
|
|
277
|
-
const { places, failed, formContext: { translations } } = this.props;
|
|
278
|
-
const that = this;
|
|
279
|
-
function getPopupRef(elem) {
|
|
280
|
-
that.popupElem = elem;
|
|
281
|
-
}
|
|
282
|
-
function getMapRef(elem) {
|
|
283
|
-
that.mapElem = elem;
|
|
284
|
-
}
|
|
285
|
-
function getPopup({ feature }, callback) {
|
|
286
|
-
const { idx } = feature.properties;
|
|
287
|
-
that.setState({ popupIdx: idx });
|
|
288
|
-
callback(react_dom_1.findDOMNode(that.popupElem));
|
|
289
|
-
}
|
|
290
|
-
const { Alert } = this.context.theme;
|
|
291
|
-
if (failed) {
|
|
292
|
-
return React.createElement(Alert, { variant: "danger" }, `${translations.NamedPlacesFetchFail} ${translations.TryAgainLater}`);
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
const enums = (places || []).map((place, idx) => {
|
|
296
|
-
return { value: idx, label: place.name };
|
|
297
|
-
});
|
|
298
|
-
let pointer = 1;
|
|
299
|
-
const data = (places || []).reduce((data, place, i) => {
|
|
300
|
-
const { geometry } = place;
|
|
301
|
-
let isCollection = false;
|
|
302
|
-
if (geometry.type === "GeometryCollection") {
|
|
303
|
-
isCollection = true;
|
|
304
|
-
}
|
|
305
|
-
if (isCollection) {
|
|
306
|
-
data[pointer] = {
|
|
307
|
-
geoData: { type: "FeatureCollection", features: geometry.geometries.map(geom => { return { type: "Feature", geometry: geom, properties: { idx: i } }; }) },
|
|
308
|
-
getFeatureStyle: this.getFeatureStyle,
|
|
309
|
-
getPopup,
|
|
310
|
-
highlightOnHover: true
|
|
311
|
-
};
|
|
312
|
-
pointer++;
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
if (!data[0])
|
|
316
|
-
data[0] = {
|
|
317
|
-
geoData: { type: "FeatureCollection", features: [] },
|
|
318
|
-
getFeatureStyle: this.getFeatureStyle,
|
|
319
|
-
getPopup,
|
|
320
|
-
cluster: true,
|
|
321
|
-
highlightOnHover: true
|
|
322
|
-
};
|
|
323
|
-
data[0].geoData.features.push({ type: "Feature", geometry, properties: { idx: i } });
|
|
324
|
-
}
|
|
325
|
-
return data;
|
|
326
|
-
}, []);
|
|
327
|
-
return (React.createElement("div", { style: { height: "inherit" } },
|
|
328
|
-
React.createElement(SelectWidget_1.default, { disabled: !places, options: { enumOptions: enums, placeholder: `${translations.SelectPlaceFromList}...` }, onChange: this.onSelectChange, selectOnChange: false, schema: {}, id: "named-place-chooser-select", formContext: this.props.formContext }),
|
|
329
|
-
React.createElement(MapArrayField_1.Map, { ref: getMapRef, data: data, markerPopupOffset: 45, featurePopupOffset: 5, controls: { draw: false }, lang: this.props.formContext.lang, bodyAsDialogRoot: false, formContext: this.props.formContext }),
|
|
330
|
-
(!places) ? React.createElement(Spinner, null) : null,
|
|
331
|
-
React.createElement("div", { style: { display: "none" }, ref: this.setPopupContainerRef },
|
|
332
|
-
React.createElement(Popup, { ref: getPopupRef, place: (places || [])[this.state.popupIdx], onPlaceSelected: this.onPlaceSelected, onPlaceDeleted: this.onPlaceDeleted, deleting: this.state.deleting, formContext: this.props.formContext, translations: translations }))));
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
NamedPlaceChooser.contextType = ReactContext_1.default;
|
|
337
|
-
class Popup extends React.Component {
|
|
338
|
-
constructor() {
|
|
339
|
-
super(...arguments);
|
|
340
|
-
this._onPlaceSelected = () => {
|
|
341
|
-
this.props.onPlaceSelected(this.props.place);
|
|
342
|
-
};
|
|
343
|
-
this._onPlaceDeleted = () => {
|
|
344
|
-
this.props.onPlaceDeleted(this.props.place);
|
|
345
|
-
};
|
|
346
|
-
this.getButtonRef = (elem) => {
|
|
347
|
-
this.buttonElem = elem;
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
componentDidUpdate() {
|
|
351
|
-
this.props.formContext.setTimeout(() => {
|
|
352
|
-
if (this.buttonElem)
|
|
353
|
-
react_dom_1.findDOMNode(this.buttonElem).focus();
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
render() {
|
|
357
|
-
const { place, translations, deleting } = this.props;
|
|
358
|
-
return place ? (React.createElement("div", { className: "named-place-popup" },
|
|
359
|
-
React.createElement("table", null,
|
|
360
|
-
React.createElement("tbody", null, [
|
|
361
|
-
["Name", "name"],
|
|
362
|
-
["Notes", "notes"]
|
|
363
|
-
].reduce((fieldset, [translationKey, fieldName], i) => {
|
|
364
|
-
if (!utils_1.isEmptyString(place[fieldName]))
|
|
365
|
-
fieldset.push(React.createElement("tr", { key: i },
|
|
366
|
-
React.createElement("td", null,
|
|
367
|
-
React.createElement("b", null,
|
|
368
|
-
translations[translationKey],
|
|
369
|
-
": ")),
|
|
370
|
-
React.createElement("td", null, place[fieldName])));
|
|
371
|
-
return fieldset;
|
|
372
|
-
}, []))),
|
|
373
|
-
React.createElement(components_1.Button, { block: true, ref: this.getButtonRef, onClick: this._onPlaceSelected }, translations.UseThisPlace),
|
|
374
|
-
React.createElement(components_1.DeleteButton, { block: true, onClick: this._onPlaceDeleted, disabled: deleting, glyphButton: false, confirm: true, confirmStyle: "browser", translations: translations },
|
|
375
|
-
translations.Remove,
|
|
376
|
-
" ",
|
|
377
|
-
deleting && React.createElement(Spinner, null)))) : React.createElement(Spinner, null);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
Context_1.default("SCHEMA_FIELD_WRAPPERS").NamedPlaceChooserField = true;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compatible only with gathering field.
|
|
3
|
-
*/
|
|
4
|
-
export default class NamedPlaceSaverField extends React.Component<any, any, any> {
|
|
5
|
-
static contextType: React.Context<import("../../ReactContext").ContextProps>;
|
|
6
|
-
static propTypes: {
|
|
7
|
-
schema: PropTypes.Validator<PropTypes.InferProps<{
|
|
8
|
-
type: PropTypes.Requireable<string>;
|
|
9
|
-
}>>;
|
|
10
|
-
formData: PropTypes.Requireable<object>;
|
|
11
|
-
};
|
|
12
|
-
constructor(props: any);
|
|
13
|
-
constructor(props: any, context: any);
|
|
14
|
-
getStateFromProps(props: any): {
|
|
15
|
-
uiSchema: any;
|
|
16
|
-
};
|
|
17
|
-
getButton(props: any): {
|
|
18
|
-
label: any;
|
|
19
|
-
fn: () => () => void;
|
|
20
|
-
glyph: string;
|
|
21
|
-
position: string;
|
|
22
|
-
disabled: boolean;
|
|
23
|
-
};
|
|
24
|
-
onButtonClick: () => () => void;
|
|
25
|
-
onSave: (place: any) => void;
|
|
26
|
-
onHide: () => void;
|
|
27
|
-
}
|
|
28
|
-
import * as React from "react";
|
|
29
|
-
import * as PropTypes from "prop-types";
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
9
|
-
var t = {};
|
|
10
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
11
|
-
t[p] = s[p];
|
|
12
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
13
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
14
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
15
|
-
t[p[i]] = s[p[i]];
|
|
16
|
-
}
|
|
17
|
-
return t;
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
const React = require("react");
|
|
21
|
-
const react_dom_1 = require("react-dom");
|
|
22
|
-
const PropTypes = require("prop-types");
|
|
23
|
-
const utils_1 = require("../../utils");
|
|
24
|
-
const components_1 = require("../components");
|
|
25
|
-
const Context_1 = require("../../Context");
|
|
26
|
-
const ReactContext_1 = require("../../ReactContext");
|
|
27
|
-
const BaseComponent_1 = require("../BaseComponent");
|
|
28
|
-
const Spinner = require("react-spinner");
|
|
29
|
-
const MapArrayField_1 = require("./MapArrayField");
|
|
30
|
-
const SAVE = "SAVE", FETCH = "FETCH";
|
|
31
|
-
/**
|
|
32
|
-
* Compatible only with gathering field.
|
|
33
|
-
*/
|
|
34
|
-
let NamedPlaceSaverField = class NamedPlaceSaverField extends React.Component {
|
|
35
|
-
constructor() {
|
|
36
|
-
super(...arguments);
|
|
37
|
-
this.onButtonClick = () => () => {
|
|
38
|
-
this.setState({ show: !this.state.show });
|
|
39
|
-
};
|
|
40
|
-
this.onSave = (place) => {
|
|
41
|
-
this.setState({ show: false }, () => {
|
|
42
|
-
this.props.onChange(Object.assign(Object.assign({}, (this.props.formData || {})), { namedPlaceID: place.id }));
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
this.onHide = () => this.setState({ show: false });
|
|
46
|
-
}
|
|
47
|
-
getStateFromProps(props) {
|
|
48
|
-
const innerUiSchema = utils_1.getInnerUiSchema(props.uiSchema);
|
|
49
|
-
const uiSchema = Object.assign(Object.assign({}, innerUiSchema), { "ui:options": Object.assign(Object.assign({}, utils_1.getUiOptions(innerUiSchema)), { buttons: [
|
|
50
|
-
...(utils_1.getUiOptions(innerUiSchema).buttons || []),
|
|
51
|
-
this.getButton(props)
|
|
52
|
-
] }) });
|
|
53
|
-
return { uiSchema };
|
|
54
|
-
}
|
|
55
|
-
getButton(props) {
|
|
56
|
-
return {
|
|
57
|
-
label: props.formContext.translations.SaveNamedPlace,
|
|
58
|
-
fn: this.onButtonClick,
|
|
59
|
-
glyph: "floppy-disk",
|
|
60
|
-
position: "top",
|
|
61
|
-
disabled: !MapArrayField_1.parseGeometries((props.formData || {}).geometry).length
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
componentDidUpdate(prevProps, prevState) {
|
|
65
|
-
if (prevState.show !== this.state.show)
|
|
66
|
-
this.setState(this.getStateFromProps(this.props));
|
|
67
|
-
}
|
|
68
|
-
render() {
|
|
69
|
-
const { registry: { fields: { SchemaField } }, formContext } = this.props;
|
|
70
|
-
const { uiSchema } = this.state;
|
|
71
|
-
const { Modal } = this.context.theme;
|
|
72
|
-
return (React.createElement("div", null,
|
|
73
|
-
React.createElement(SchemaField, Object.assign({}, this.props, { uiSchema: uiSchema })),
|
|
74
|
-
this.state && this.state.show
|
|
75
|
-
? (React.createElement(Modal, { dialogClassName: "laji-form", show: true, onHide: this.onHide },
|
|
76
|
-
React.createElement(Modal.Header, null,
|
|
77
|
-
React.createElement(Modal.Title, null, formContext.translations.NamedPlaces)),
|
|
78
|
-
React.createElement(Modal.Body, null,
|
|
79
|
-
React.createElement(PlaceSaverDialog, { formContext: formContext, onSave: this.onSave, gathering: this.props.formData || {} })))) : null));
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
NamedPlaceSaverField.contextType = ReactContext_1.default;
|
|
83
|
-
NamedPlaceSaverField.propTypes = {
|
|
84
|
-
schema: PropTypes.shape({
|
|
85
|
-
type: PropTypes.oneOf(["object"])
|
|
86
|
-
}).isRequired,
|
|
87
|
-
formData: PropTypes.object
|
|
88
|
-
};
|
|
89
|
-
NamedPlaceSaverField = __decorate([
|
|
90
|
-
BaseComponent_1.default
|
|
91
|
-
], NamedPlaceSaverField);
|
|
92
|
-
exports.default = NamedPlaceSaverField;
|
|
93
|
-
class PlaceSaverDialog extends React.Component {
|
|
94
|
-
constructor(props) {
|
|
95
|
-
super(props);
|
|
96
|
-
this.onInputChange = ({ target: { value } }) => {
|
|
97
|
-
this.setState({ value });
|
|
98
|
-
};
|
|
99
|
-
this.getGathering = () => {
|
|
100
|
-
return ["geometry", "country", "administrativeProvince", "biologicalProvince", "municipality", "locality", "localityDescription", "habitat", "habitatDescription", "coordinateRadius"].reduce((gathering, key) => {
|
|
101
|
-
gathering[key] = this.props.gathering[key];
|
|
102
|
-
return gathering;
|
|
103
|
-
}, {});
|
|
104
|
-
};
|
|
105
|
-
this.onSaveNew = (e) => {
|
|
106
|
-
e.preventDefault();
|
|
107
|
-
const _a = this.getGathering(), { namedPlaceID } = _a, gathering = __rest(_a, ["namedPlaceID"]); //eslint-disable-line @typescript-eslint/no-unused-vars
|
|
108
|
-
this.onSave({
|
|
109
|
-
name: this.state.value,
|
|
110
|
-
prepopulatedDocument: { gatherings: [gathering] }
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
this.onOverwriteCurrent = () => {
|
|
114
|
-
const { namedPlaceID } = this.props.gathering;
|
|
115
|
-
const gathering = this.getGathering(); //eslint-disable-line no-unused-vars
|
|
116
|
-
this.onSave(Object.assign(Object.assign({}, this.state.placeIdsToPlaces[namedPlaceID]), { name: this.state.value, prepopulatedDocument: { gatherings: [gathering] } }));
|
|
117
|
-
};
|
|
118
|
-
this.onOverwriteSelected = (place) => () => {
|
|
119
|
-
const gathering = this.getGathering(); //eslint-disable-line no-unused-vars
|
|
120
|
-
this.onSave(Object.assign(Object.assign({}, place), { name: this.state.value, prepopulatedDocument: { gatherings: [gathering] } }));
|
|
121
|
-
};
|
|
122
|
-
this.onOverwriteExisting = () => {
|
|
123
|
-
this.onOverwriteSelected(this.state.placeNamesToPlaces[this.state.value])();
|
|
124
|
-
};
|
|
125
|
-
// Hack that fixed autofocus cursor position
|
|
126
|
-
this.onFocus = (e) => {
|
|
127
|
-
var val = e.target.value;
|
|
128
|
-
e.target.value = "";
|
|
129
|
-
e.target.value = val;
|
|
130
|
-
};
|
|
131
|
-
this.onSubmit = (e) => {
|
|
132
|
-
e.preventDefault();
|
|
133
|
-
};
|
|
134
|
-
this.setInputRef = (elem) => {
|
|
135
|
-
this.inputRef = elem;
|
|
136
|
-
};
|
|
137
|
-
const { namedPlaceID, locality = "" } = props.gathering;
|
|
138
|
-
this.state = { value: locality };
|
|
139
|
-
if (namedPlaceID) {
|
|
140
|
-
this.state = { value: "", loading: true };
|
|
141
|
-
}
|
|
142
|
-
this.apiClient = props.formContext.apiClient;
|
|
143
|
-
}
|
|
144
|
-
componentWillUnmount() {
|
|
145
|
-
this.mounted = false;
|
|
146
|
-
}
|
|
147
|
-
componentDidMount() {
|
|
148
|
-
this.mounted = true;
|
|
149
|
-
this.apiClient.fetchCached("/named-places", { includePublic: false, pageSize: 10000 }).then(response => {
|
|
150
|
-
if (!this.mounted)
|
|
151
|
-
return;
|
|
152
|
-
const state = {
|
|
153
|
-
places: response.results,
|
|
154
|
-
placeIdsToPlaces: response.results.reduce((idsToPlaces, place) => {
|
|
155
|
-
idsToPlaces[place.id] = place;
|
|
156
|
-
return idsToPlaces;
|
|
157
|
-
}, {}),
|
|
158
|
-
placeNamesToPlaces: response.results.reduce((namesToPlaces, place) => {
|
|
159
|
-
if (!namesToPlaces[place.name])
|
|
160
|
-
namesToPlaces[place.name] = [];
|
|
161
|
-
namesToPlaces[place.name].push(place);
|
|
162
|
-
return namesToPlaces;
|
|
163
|
-
}, {})
|
|
164
|
-
};
|
|
165
|
-
const { namedPlaceID } = this.props.gathering;
|
|
166
|
-
if (namedPlaceID) {
|
|
167
|
-
state.value = state.placeIdsToPlaces[namedPlaceID].name;
|
|
168
|
-
state.loading = false;
|
|
169
|
-
}
|
|
170
|
-
this.setState(state, () => {
|
|
171
|
-
if (namedPlaceID) {
|
|
172
|
-
react_dom_1.findDOMNode(this.inputRef).focus();
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}).catch(() => {
|
|
176
|
-
this.setState({ failed: FETCH });
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
onSave(place) {
|
|
180
|
-
place = Object.assign(Object.assign({}, place), { geometry: place.prepopulatedDocument.gatherings[0].geometry });
|
|
181
|
-
this.props.formContext.services.blocker.push();
|
|
182
|
-
this.apiClient.fetchRaw(`/named-places${place.id ? `/${place.id}` : ""}`, undefined, {
|
|
183
|
-
method: place.id ? "PUT" : "POST",
|
|
184
|
-
headers: {
|
|
185
|
-
"accept": "application/json",
|
|
186
|
-
"content-type": "application/json"
|
|
187
|
-
},
|
|
188
|
-
body: JSON.stringify(place)
|
|
189
|
-
}).then(response => {
|
|
190
|
-
this.props.formContext.services.blocker.pop();
|
|
191
|
-
this.apiClient.invalidateCachePath("/named-places");
|
|
192
|
-
return response.json();
|
|
193
|
-
}).then(this.props.onSave)
|
|
194
|
-
.catch(() => {
|
|
195
|
-
this.props.formContext.services.blocker.pop();
|
|
196
|
-
this.setState({ failed: SAVE });
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
render() {
|
|
200
|
-
const { value, placeNamesToPlaces = {}, loading } = this.state;
|
|
201
|
-
const { translations } = this.props.formContext;
|
|
202
|
-
const existingPlaces = (placeNamesToPlaces[value] || []).filter(place => {
|
|
203
|
-
return (place.owners || []).includes(this.props.formContext.uiSchemaContext.creator);
|
|
204
|
-
});
|
|
205
|
-
const getButton = (onClick, text) => {
|
|
206
|
-
return React.createElement(components_1.Button, { small: true, onClick: onClick, disabled: loading || utils_1.isEmptyString(value) }, text);
|
|
207
|
-
};
|
|
208
|
-
const { Panel, FormGroup, FormControl, ListGroup, ListGroupItem, Alert, Form, ControlLabel } = this.context.theme;
|
|
209
|
-
return this.state.failed ? (React.createElement(Alert, { variant: "danger" }, `${translations[`NamedPlaces${this.state.failed === FETCH ? "Fetch" : "Save"}Fail`]} ${translations.TryAgainLater}`)) : (React.createElement("div", { className: "place-saver-dialog" },
|
|
210
|
-
React.createElement(Form, { inline: true, onSubmit: this.onSubmit },
|
|
211
|
-
React.createElement(FormGroup, null,
|
|
212
|
-
React.createElement(ControlLabel, null,
|
|
213
|
-
translations.Name,
|
|
214
|
-
": "),
|
|
215
|
-
" ",
|
|
216
|
-
React.createElement(FormControl, { type: "text", value: value, onChange: this.onInputChange, autoFocus: true, onFocus: this.onFocus, disabled: loading, ref: this.setInputRef }),
|
|
217
|
-
" ",
|
|
218
|
-
!existingPlaces.length ?
|
|
219
|
-
getButton(this.onSaveNew, `${translations.Save} ${translations.new}`) : null,
|
|
220
|
-
" ",
|
|
221
|
-
this.props.gathering.namedPlaceID ?
|
|
222
|
-
getButton(this.onOverwriteCurrent, translations.SaveCurrentOverwrite) : null,
|
|
223
|
-
existingPlaces.length === 1 && !this.props.gathering.namedPlaceID ?
|
|
224
|
-
getButton(this.onOverwriteExisting, translations.SaveExistingOverwrite) : null),
|
|
225
|
-
loading ? React.createElement("div", { className: "pull-right" },
|
|
226
|
-
React.createElement(Spinner, null)) : null),
|
|
227
|
-
!this.props.gathering.namedPlaceID && existingPlaces.length ?
|
|
228
|
-
React.createElement(Alert, { variant: "warning" }, `${translations.Warning}: ${translations.UsedNamedPlaceName}.${existingPlaces.length > 1 ? ` ${translations.UsedNamedPlaceNameMultiple}.` : ""}`)
|
|
229
|
-
: null,
|
|
230
|
-
existingPlaces.length > 1 ? (React.createElement(FormGroup, null,
|
|
231
|
-
React.createElement(Panel, null,
|
|
232
|
-
React.createElement(Panel.Heading, null, translations.ClickPlaceToOverwrite),
|
|
233
|
-
React.createElement(ListGroup, { fill: "fill" }, existingPlaces.map(place => React.createElement(ListGroupItem, { header: place.name, key: place.id, onClick: loading ? undefined : this.onOverwriteSelected(place), disabled: loading }, place.notes)))))) : null));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
PlaceSaverDialog.contextType = ReactContext_1.default;
|
|
237
|
-
Context_1.default("SCHEMA_FIELD_WRAPPERS").NamedPlaceSaverField = true;
|