diff --git a/boranga/components/occurrence/serializers.py b/boranga/components/occurrence/serializers.py index 93ab1a07..6eef388d 100644 --- a/boranga/components/occurrence/serializers.py +++ b/boranga/components/occurrence/serializers.py @@ -3925,7 +3925,9 @@ class Meta: class OccurrenceReportBulkImportSchemaSerializer(serializers.ModelSerializer): - columns = OccurrenceReportBulkImportSchemaColumnSerializer(many=True) + columns = OccurrenceReportBulkImportSchemaColumnSerializer( + many=True, allow_null=True, required=False + ) group_type_display = serializers.CharField(source="group_type.name", read_only=True) version = serializers.CharField(read_only=True) @@ -3935,7 +3937,11 @@ class Meta: read_only_fields = ("id",) def update(self, instance, validated_data): - columns_data = validated_data.pop("columns") + columns_data = validated_data.pop("columns", None) + + if not columns_data: + return super().update(instance, validated_data) + # Delete any columns that are not in the new data instance.columns.exclude( id__in=[ diff --git a/boranga/frontend/boranga/src/components/internal/occurrence/bulk_import_schema.vue b/boranga/frontend/boranga/src/components/internal/occurrence/bulk_import_schema.vue index d123533d..27db521a 100644 --- a/boranga/frontend/boranga/src/components/internal/occurrence/bulk_import_schema.vue +++ b/boranga/frontend/boranga/src/components/internal/occurrence/bulk_import_schema.vue @@ -23,7 +23,7 @@ }}
- {{ column.xlsx_column_header_name }} + * + style="width:10%"> - - Add Another Column + + Add Column @@ -74,7 +77,7 @@
-
+
@@ -240,24 +243,25 @@ data-bs-trigger="hover focus" data-bs-content="Basic validations embedded in the .xlsx file" data-bs-placement="top"> -
+
Allow + id="allow-blank-label">Allow Blank - +
Max Length @@ -394,6 +398,7 @@ export default { schema: null, djangoContentTypes: null, selectedColumn: null, + selectedColumnIndex: null, selectedContentType: null, selectedField: null, addEditMode: false, @@ -488,6 +493,7 @@ export default { this.enablePopovers(); if (!this.selectedColumn.id) { this.selectedColumn.xlsx_column_header_name = this.selectedField.display_name + this.selectedColumn.xlsx_data_validation_allow_blank = this.selectedField.allow_null } this.$refs['column-name'].focus() }) @@ -499,23 +505,27 @@ export default { django_import_content_type: '', django_import_field_name: '', xlsx_column_header_name: '', + xlsx_data_validation_allow_blank: true, import_validations: [] } }, addNewColumn() { this.newColumn = Object.assign({}, this.getNewColumnData()) this.schema.columns.push(this.newColumn) + this.selectedContentType = null; + this.selectedField = null; this.selectedColumn = this.newColumn + this.selectedColumnIndex = this.schema.columns.indexOf(this.newColumn) this.addEditMode = true - // this.removeAlreadySelectedFields(); this.$nextTick(() => { this.enablePopovers(); this.$refs['django-import-model'].focus() }) }, selectColumn(column) { - this.addEditMode = true this.selectedColumn = column + this.selectedColumnIndex = this.schema.columns.indexOf(column) + this.addEditMode = true this.$nextTick(() => { this.enablePopovers(); if (this.selectedColumn.django_import_content_type) { @@ -534,6 +544,7 @@ export default { cancelAddingColumn(column) { this.schema.columns = this.schema.columns.filter(col => col !== column) this.selectedColumn = null + this.selectedColumnIndex = null this.addEditMode = false }, removeColumn(column) { @@ -567,12 +578,28 @@ export default { } }) }, + validateSchema() { + swal.fire({ + title: 'Validate Schema', + text: 'Not yet implemented', + icon: 'warning', + showCancelButton: false, + cancelButtonText: 'Cancel', + customClass: { + confirmButton: 'btn btn-primary', + cancelButton: 'btn btn-secondary me-2' + }, + }) + }, save() { this.saving = true; this.$http.put(`${api_endpoints.occurrence_report_bulk_import_schemas}${this.schema.id}/`, this.schema) .then(response => { this.saving = false; - this.schema = response.data + this.schema = Object.assign({}, response.data) + if (this.addEditMode) { + this.selectedColumn = this.schema.columns[this.selectedColumnIndex] + } }) .catch(error => { this.saving = false;