Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DH-Center-Tuebingen/Spacialist in…
Browse files Browse the repository at this point in the history
…to release-0.11

Signed-off-by: Vinzenz Rosenkranz <[email protected]>
  • Loading branch information
v1r0x committed Dec 11, 2024
2 parents 78915a7 + 1b40090 commit b5c9e85
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 150 deletions.
18 changes: 15 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ All notable changes to this project will be documented in this file.
## 0.11
### Added
- Filter and sort functionality on _Entity Type List_

### Fixed
- Missing "Color Dots" of _Entity Type_ (colors are now handled on the Entity Type itself and do no longer rely on the _Map_ Plugin)
- 'Jumping' behavior on floating quick access controls on the _Entity Type List_ (copy, duplicate, delete)
- Attribute Dependency inverted

## 0.10.2
### Fixed
- Date Range _importFrom_ did not return a JSON string
- Richtext editor did not trigger the dirty state on entity
- Certainty warning due to _undefined_ value
- Serial and SQL attributes now have the required value (_v_) and functions (_resetFieldState_, _undirtyField_)
### Changed
- Added tests to _ApiDataImporterTest_ to check if the same columns can be used in multiple attributes
- Row error now also sends the column value, instead of just sending the column name
- Dropdowns in the _Data Importer_ are now sorted alphabetically
- The ErrorList component of the Data Importer in the Frontend now preserves text inside `{{...}}`
- Adjusted colors of Markdown modal buttons

## 0.10.1
### Added
- Option to display attributes in _Data Model Editor_ in groups
Expand All @@ -19,8 +31,8 @@ All notable changes to this project will be documented in this file.
- selects the first choice (if there is **only one choice** in the dropdown)*
- selects the exact match (**case insensitive**; e.g. "apple" + `Tab` will select the available choice "apple", but also "Apple")*
- nothing and focuses the next attribute (default)
- * Selected elements will be marked with a blue (Tab) badge
- Pressing `Delete` inside _Single Choice Dropdowns_ will clear the element
- * Selected elements will be marked with a blue (Tab) badge
- Pressing `Delete` inside _Single Choice Dropdowns_ will clear the element
- Importer now automatically removes BOM if present
- Better readable format for error message on validation
- Renamed _fromImport_ to _parseImport_ on the attribute classses. The base class now by default imports the passed string, removing redundancies on the string-based classes.
Expand Down
8 changes: 4 additions & 4 deletions app/AttributeTypes/DaterangeAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public static function parseImport(int|float|bool|string $data) : mixed {
throw InvalidDataException::requireBefore($start, $end);
}

return [
"start" => $start,
"end" => $end,
];
return json_encode([
$start,
$end,
]);
}

public static function unserialize(mixed $data) : mixed {
Expand Down
29 changes: 16 additions & 13 deletions app/Import/EntityImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EntityImporter {

private $metadata;
private array $attributesMap;
private array $attributeAttributeMap = [];
private array $attributeIdToAttributeValue = [];
private int $entityTypeId;
private string $nameColumn;
private ?string $parentColumn = null;
Expand Down Expand Up @@ -147,7 +147,7 @@ private function verifyEntityType($entityTypeId): bool {
private function verifyAttributeMapping($headers): bool {
$nameErrors = [];
$indexErrors = [];
foreach($this->attributesMap as $attribute => $column) {
foreach($this->attributesMap as $attributeId => $column) {
$column = trim($column);
if($column == "") {
continue;
Expand All @@ -157,27 +157,26 @@ private function verifyAttributeMapping($headers): bool {
array_push($nameErrors, $column);
}

$attr = Attribute::find($attribute);
$attr = Attribute::find($attributeId);
if(!$attr) {
array_push($indexErrors, $attribute);
array_push($indexErrors, $attributeId);
} else {
$this->attributeAttributeMap[$column] = $attr;
$this->attributeIdToAttributeValue[$attributeId] = $attr;
}
}

$valid = true;
if(count($indexErrors) > 0) {
$this->resolver->conflict(__("entity-importer.attribute-id-does-not-exist", ["attributes" => implode(", ", $indexErrors)]));
$valid = false;
}

if(count($nameErrors) > 0) {
$this->resolver->conflict(__("entity-importer.attribute-column-does-not-exist", ["columns" => implode(", ", $nameErrors)]));
$valid = false;
}

if(count($indexErrors) > 0 || count($nameErrors) > 0) {
return false;
} else {
return true;
}
return $valid;
}

private function validateName($row, $rowIndex): bool {
Expand Down Expand Up @@ -233,18 +232,22 @@ private function validateLocation($row, $rowIndex): bool {

private function validateAttributesInRow($row, $index): bool {
$errors = [];
foreach($this->attributeAttributeMap as $column => $attribute) {
foreach($this->attributeIdToAttributeValue as $attributeId => $attribute) {
try {
$column = $this->attributesMap[$attributeId];
$datatype = $attribute->datatype;
$attrClass = AttributeBase::getMatchingClass($datatype);
$attrClass::fromImport($row[$column]);
} catch(Exception $e) {
array_push($errors, $column);
array_push($errors, ["column" => $column, "value" => $row[$column]]);
}
}

if(count($errors) > 0) {
$this->rowConflict($index, "entity-importer.attribute-could-not-be-imported", ["attribute" => implode(", ", $errors)]);
$errorStrings = array_map(function ($error) {
return "{{" . $error['column'] . "}}" . " => " . "{{" . $error['value'] . "}}";
}, $errors);
$this->rowConflict($index, "entity-importer.attribute-could-not-be-imported", ["attributeErrors" => implode(", ", $errorStrings)]);
}
return count($errors) == 0;
}
Expand Down
10 changes: 10 additions & 0 deletions database/seeders/Demo/EntityAttributesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ public function run()
'position' => 6,
'depends_on' => NULL,
),
23 =>
array (
'id' => 26,
'entity_type_id' => 3, // Fundstelle
'attribute_id' => 19, // Aufbewahrung [string]
'created_at' => '2017-12-20 17:00:43',
'updated_at' => '2017-12-20 17:01:58',
'position' => 3,
'depends_on' => NULL,
),
));
}
}
4 changes: 3 additions & 1 deletion lang/de/entity-importer.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

<?php

return [
'empty' => 'Keine Zeilen für den Import gefunden',
'file-not-found' => 'Datei konnte nicht gelesen werden.',
'missing-data' => 'Benötigte Spalte fehlt: :column',
'invalid-data' => 'Ungültige Daten: [:column] => :value',
'attribute-could-not-be-imported' => 'Attribut konnte nicht importiert werden: :attributeErrors',
'attribute-id-does-not-exist' => 'Die Attribut-ID existiert nicht: :attributes',
'attribute-column-does-not-exist' => 'Die Attribut-Spalten existieren nicht: :columns',
'name-column-does-not-exist' => 'Die Spalte für den Namen existiert nicht: :column',
'parent-column-does-non-exist' => 'Die Spalte für die Eltern-Entität existiert nicht: :column',
'parent-entity-does-not-exist' => 'Die Eltern-Entität existiert nicht: :entity',
Expand Down
2 changes: 1 addition & 1 deletion lang/en/entity-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'file-not-found' => 'File could not be read.',
'missing-data' => 'Required column is missing: :column',
'invalid-data' => 'Invalid data: [:column] => :value',
'attribute-could-not-be-imported' => 'Attribute could not be imported: :attribute',
'attribute-could-not-be-imported' => 'Attribute could not be imported: :attributeErrors',
'attribute-id-does-not-exist' => 'The attribute id does not exist: :attributes',
'attribute-column-does-not-exist' => 'The attribute columns do not exist: :columns',
'name-column-does-not-exist' => 'The column for the name does not exist: :column',
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/AttributeList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@
};
const certainty = attribute => {
return state.attributeValues?.[attribute.id]?.certainty;
return state.attributeValues?.[attribute.id]?.certainty ?? null;
};
const hasComment = attribute => {
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/attribute/Attribute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

<serial-attribute
v-else-if="data.datatype == 'serial'"
:ref="el => setRef(el)"
:disabled="state.disabled"
:name="`attr-${data.id}`"
:value="state.value"
Expand Down Expand Up @@ -223,6 +224,7 @@

<sql-attribute
v-else-if="data.datatype == 'sql'"
:ref="el => setRef(el)"
:disabled="state.disabled"
:name="`attr-${data.id}`"
:value="state.value"
Expand Down
19 changes: 10 additions & 9 deletions resources/js/components/attribute/Daterange.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<template>
<date-picker
:id="name"
Expand Down Expand Up @@ -46,6 +45,9 @@
},
value: {
type: Array,
validator: arr => {
return !arr || arr.length === 2;
},
required: true,
},
},
Expand All @@ -56,15 +58,15 @@
disabled,
value,
} = toRefs(props);
// FETCH
// FUNCTIONS
const strToDate = str => {
return new Date(str);
// FETCH
const fixValue = _ => {
return value.value?.map(dt => new Date(dt));
};
const resetFieldState = _ => {
v.resetField({
value: value.value?.map(dt => strToDate(dt)),
value: fixValue(),
});
};
const undirtyField = _ => {
Expand All @@ -78,7 +80,7 @@
return new Date(date.getTime() - (date.getTimezoneOffset()*60*1000));
});
v.handleChange(correctValue);
}
};
// DATA
const {
Expand All @@ -87,7 +89,7 @@
meta,
resetField,
} = useField(`daterange_${name.value}`, yup.array(), {
initialValue: value.value?.map(dt => strToDate(dt)),
initialValue: fixValue(),
});
const state = reactive({
Expand All @@ -99,7 +101,6 @@
resetField,
});
watch(_ => value, (newValue, oldValue) => {
resetFieldState();
});
Expand Down
43 changes: 17 additions & 26 deletions resources/js/components/attribute/Richtext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
@mouseleave="state.hovered = false"
>
<md-viewer
v-if="current"
v-if="v.value"
:id="name"
:classes="state.classes"
:source="current"
:source="v.value"
/>
<div
v-else
Expand Down Expand Up @@ -42,7 +42,6 @@
import {
computed,
reactive,
ref,
toRefs,
watch,
} from 'vue';
Expand Down Expand Up @@ -77,33 +76,32 @@
} = toRefs(props);
const handleInput = text => {
current.value = text || '';
meta.dirty = true;
meta.valid = true;
v.value = text || '';
v.meta.dirty = true;
v.meta.valid = true;
context.emit('change', {
dirty: meta.dirty,
valid: meta.valid,
value: current.value,
dirty: v.meta.dirty,
valid: v.meta.valid,
value: v.value,
});
};
const resetFieldState = _ => {
current.value = initial.value || '';
v.value = initial.value || '';
undirtyField();
};
const undirtyField = _ => {
meta.dirty = false;
v.meta.dirty = false;
};
watch(initial, _ => {
resetFieldState();
});
const openMdEditor = _ => {
showMarkdownEditor(current.value, text => {
showMarkdownEditor(v.value, text => {
handleInput(text);
});
};
Expand All @@ -119,24 +117,18 @@
}
}),
});
const current = ref(initial.value || '');
const meta = reactive({
dirty: false,
valid: true,
});
/**
* v is required as the attr-list fetches
* the values of the attributes via every
* attribute's v.value.
*/
const v = computed(_ => {
return {
value: current.value,
meta: {
...meta
}
};
const v = reactive({
value: initial.value || '',
meta: {
dirty: false,
valid: true,
}
});
// RETURN
Expand All @@ -147,7 +139,6 @@
undirtyField,
openMdEditor,
// STATE
current,
state,
v,
};
Expand Down
Loading

0 comments on commit b5c9e85

Please sign in to comment.