diff --git a/app/Entity.php b/app/Entity.php
index 2f43b978..69106014 100755
--- a/app/Entity.php
+++ b/app/Entity.php
@@ -122,6 +122,11 @@ public static function getFromPath($path, $delimiter = "\\\\"): ?int {
return null;
}
}
+
+ public function findChildren(){
+ $children = Entity::where('root_entity_id', $this->id)->get();
+ return $children;
+ }
public static function create($fields, $entityTypeId, $user, $rootEntityId = null) {
$isChild = isset($rootEntityId);
diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php
index f06d0511..18172ee9 100644
--- a/app/Http/Controllers/EntityController.php
+++ b/app/Http/Controllers/EntityController.php
@@ -15,8 +15,6 @@
use App\Exceptions\InvalidDataException;
use App\Exceptions\Structs\AttributeImportExceptionStruct;
use App\Import\EntityImporter;
-use App\Import\ImportResolution;
-use App\Import\ImportResolutionType;
use App\Reference;
use App\ThConcept;
use Exception;
@@ -40,7 +38,7 @@ public function __construct() {
public function getTopEntities() {
$user = auth()->user();
- if (!$user->can('entity_read')) {
+ if(!$user->can('entity_read')) {
return response()->json([
'error' => __('You do not have the permission to get entities'),
], 403);
@@ -52,14 +50,14 @@ public function getTopEntities() {
public function getEntity($id) {
$user = auth()->user();
- if (!$user->can('entity_read')) {
+ if(!$user->can('entity_read')) {
return response()->json([
'error' => __('You do not have the permission to get a specific entity'),
], 403);
}
try {
$entity = Entity::findOrFail($id);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This entity does not exist'),
], 400);
@@ -70,31 +68,31 @@ public function getEntity($id) {
public function getDataForEntityType(Request $request, $etid, $aid) {
$user = auth()->user();
- if (!$user->can('entity_read') || !$user->can('entity_type_read') || !$user->can('entity_data_read')) {
+ if(!$user->can('entity_read') || !$user->can('entity_type_read') || !$user->can('entity_data_read')) {
return response()->json([
'error' => __('You do not have the permission to get an entity\'s data'),
], 403);
}
try {
$entityType = EntityType::findOrFail($etid);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This entity type does not exist'),
], 400);
}
try {
Attribute::findOrFail($aid);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This attribute does not exist'),
], 400);
}
$constraints = $request->query();
$entities = Entity::where('entity_type_id', $etid);
- foreach ($constraints as $relation => $cons) {
- if ($cons == 'has') {
+ foreach($constraints as $relation => $cons) {
+ if($cons == 'has') {
$entities->has($relation);
- } else if ($cons == 'hasnot') {
+ } else if($cons == 'hasnot') {
$entities->doesntHave($relation);
}
}
@@ -107,8 +105,8 @@ public function getDataForEntityType(Request $request, $etid, $aid) {
->where('attribute_id', $aid)
->get();
$data = [];
- foreach ($values as $value) {
- switch ($value->attribute->datatype) {
+ foreach($values as $value) {
+ switch($value->attribute->datatype) {
case 'entity':
$entity = Entity::find($value->entity_val)->name;
$value->name = $entity;
@@ -130,12 +128,12 @@ public function getDataForEntityType(Request $request, $etid, $aid) {
->where('attribute_id', $aid)
->get();
- foreach ($sqls as $sql) {
+ foreach($sqls as $sql) {
// if entity_id is referenced several times
// add an incrementing counter, so the
// references are unique (required by PDO)
$cnt = substr_count($sql->attribute->text, ':entity_id');
- if ($cnt > 1) {
+ if($cnt > 1) {
$i = 0;
$text = preg_replace_callback('/:entity_id/', function ($matches) use (&$i) {
return $matches[0] . '_' . $i++;
@@ -143,10 +141,10 @@ public function getDataForEntityType(Request $request, $etid, $aid) {
} else {
$text = $sql->attribute->text;
}
- foreach ($entityIds as $eid) {
+ foreach($entityIds as $eid) {
$safes = [];
- if ($cnt > 1) {
- for ($i = 0; $i < $cnt; $i++) {
+ if($cnt > 1) {
+ for($i = 0; $i < $cnt; $i++) {
$safes[':entity_id_' . $i] = $eid;
}
} else {
@@ -160,11 +158,11 @@ public function getDataForEntityType(Request $request, $etid, $aid) {
DB::rollBack();
// Check if only one result exists
- if (count($sqlValue) === 1) {
+ if(count($sqlValue) === 1) {
// Get all column indices (keys) using the first row
$valueKeys = array_keys(get_object_vars($sqlValue[0]));
// Check if also only one key/column exists
- if (count($valueKeys) === 1) {
+ if(count($valueKeys) === 1) {
// If only one row and one column exist,
// return plain value instead of array
$firstKey = $valueKeys[0];
@@ -182,22 +180,22 @@ public function getDataForEntityType(Request $request, $etid, $aid) {
public function getData($id, $aid = null) {
$user = auth()->user();
- if (!$user->can('entity_read') || !$user->can('entity_data_read')) {
+ if(!$user->can('entity_read') || !$user->can('entity_data_read')) {
return response()->json([
'error' => __('You do not have the permission to get an entity\'s data'),
], 403);
}
try {
$entity = Entity::findOrFail($id);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This entity does not exist'),
], 400);
}
- if (isset($aid)) {
+ if(isset($aid)) {
try {
Attribute::findOrFail($aid);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This attribute does not exist'),
], 400);
@@ -219,8 +217,8 @@ public function getData($id, $aid = null) {
}
$data = [];
- foreach ($attributes as $a) {
- switch ($a->attribute->datatype) {
+ foreach($attributes as $a) {
+ switch($a->attribute->datatype) {
case 'string-sc':
$a->thesaurus_val = ThConcept::where('concept_url', $a->thesaurus_val)->first();
break;
@@ -229,7 +227,7 @@ public function getData($id, $aid = null) {
break;
case 'entity-mc':
$names = [];
- foreach (json_decode($a->json_val) as $dec) {
+ foreach(json_decode($a->json_val) as $dec) {
$names[] = Entity::find($dec)->name;
}
$a->name = $names;
@@ -238,18 +236,18 @@ public function getData($id, $aid = null) {
break;
}
$value = $a->getValue();
- if ($a->moderation_state == 'pending-delete') {
+ if($a->moderation_state == 'pending-delete') {
$a->value = [];
$a->original_value = $value;
} else {
$a->value = $value;
}
- if (isset($data[$a->attribute_id])) {
+ if(isset($data[$a->attribute_id])) {
$oldAttr = $data[$a->attribute_id];
// check if stored entry is moderated one
// if so, add current value as original value
// otherwise, set stored entry as original value
- if (isset($oldAttr->moderation_state)) {
+ if(isset($oldAttr->moderation_state)) {
$oldAttr->original_value = $value;
$a = $oldAttr;
} else {
@@ -263,19 +261,19 @@ public function getData($id, $aid = null) {
$q->where('datatype', 'sql');
})
->where('entity_type_id', $entity->entity_type_id);
- if (isset($aid)) {
+ if(isset($aid)) {
$sqls->where('attribute_id', $aid);
}
$sqls = $sqls->get();
- foreach ($sqls as $sql) {
+ foreach($sqls as $sql) {
// if entity_id is referenced several times
// add an incrementing counter, so the
// references are unique (required by PDO)
$cnt = substr_count($sql->attribute->text, ':entity_id');
- if ($cnt > 1) {
+ if($cnt > 1) {
$safes = [];
- for ($i = 0; $i < $cnt; $i++) {
+ for($i = 0; $i < $cnt; $i++) {
$safes[':entity_id_' . $i] = $id;
}
$i = 0;
@@ -294,11 +292,11 @@ public function getData($id, $aid = null) {
DB::rollBack();
// Check if only one result exists
- if (count($sqlValue) === 1) {
+ if(count($sqlValue) === 1) {
// Get all column indices (keys) using the first row
$valueKeys = array_keys(get_object_vars($sqlValue[0]));
// Check if also only one key/column exists
- if (count($valueKeys) === 1) {
+ if(count($valueKeys) === 1) {
// If only one row and one column exist,
// return plain value instead of array
$firstKey = $valueKeys[0];
@@ -309,7 +307,8 @@ public function getData($id, $aid = null) {
'value' => $sqlValue,
];
}
-
+
+ $data['tabbedChildren'] = $entity->findChildren();
return response()->json($data);
}
@@ -333,7 +332,7 @@ public function getMetadata($id) {
public function getParentIds($id) {
$user = auth()->user();
- if (!$user->can('entity_read')) {
+ if(!$user->can('entity_read')) {
return response()->json([
'error' => __('You do not have the permission to get an entity\'s parent id\'s'),
], 403);
@@ -341,7 +340,7 @@ public function getParentIds($id) {
try {
$entity = Entity::findOrFail($id);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This entity does not exist'),
], 400);
@@ -351,7 +350,7 @@ public function getParentIds($id) {
public function getEntitiesByParent($id) {
$user = auth()->user();
- if (!$user->can('entity_read')) {
+ if(!$user->can('entity_read')) {
return response()->json([
'error' => __('You do not have the permission to get an entity set'),
], 403);
@@ -364,7 +363,7 @@ public function getEntitiesByParent($id) {
public function addEntity(Request $request) {
$user = auth()->user();
- if (!$user->can('entity_create')) {
+ if(!$user->can('entity_create')) {
return response()->json([
'error' => __('You do not have the permission to add a new entity'),
], 403);
@@ -377,7 +376,7 @@ public function addEntity(Request $request) {
$res = Entity::create($fields, $etid, $user, $reid);
- if ($res['type'] === 'entity') {
+ if($res['type'] === 'entity') {
return response()->json($res['entity'], 201);
} else {
return response()->json([
@@ -388,7 +387,7 @@ public function addEntity(Request $request) {
public function duplicateEntity(Request $request, $id) {
$user = auth()->user();
- if (!$user->can('entity_create')) {
+ if(!$user->can('entity_create')) {
return response()->json([
'error' => __('You do not have the permission to duplicate an entity'),
], 403);
@@ -405,10 +404,10 @@ public function duplicateEntity(Request $request, $id) {
$duplicate = $entity->replicate();
$duplicate->created_at = Carbon::now();
- if (sp_has_plugin('Map')) {
+ if(sp_has_plugin('Map')) {
$duplicate->geodata_id = null;
}
- if (isset($duplicate->root_entity_id)) {
+ if(isset($duplicate->root_entity_id)) {
$duplicate->rank = Entity::where('root_entity_id', $duplicate->root_entity_id)->max('rank') + 1;
} else {
$duplicate->rank = Entity::whereNull('root_entity_id')->max('rank') + 1;
@@ -418,9 +417,9 @@ public function duplicateEntity(Request $request, $id) {
$duplicate->save();
// Files, bibliographies, attribute_values
- if (sp_has_plugin('File')) {
+ if(sp_has_plugin('File')) {
$fileLinks = EntityFile::where('entity_id', $entity->id)->get();
- foreach ($fileLinks as $fileLink) {
+ foreach($fileLinks as $fileLink) {
$newLink = $fileLink->replicate();
$newLink->entity_id = $duplicate->id;
$newLink->user_id = $user->id;
@@ -428,7 +427,7 @@ public function duplicateEntity(Request $request, $id) {
}
}
$refs = Reference::where('entity_id', $entity->id)->get();
- foreach ($refs as $ref) {
+ foreach($refs as $ref) {
$newLink = $ref->replicate();
$newLink->entity_id = $duplicate->id;
$newLink->user_id = $user->id;
@@ -436,7 +435,7 @@ public function duplicateEntity(Request $request, $id) {
$newLink->save();
}
$values = AttributeValue::where('entity_id', $entity->id)->get();
- foreach ($values as $val) {
+ foreach($values as $val) {
unset($val->comments_count);
$newValue = $val->replicate();
$newValue->entity_id = $duplicate->id;
@@ -450,7 +449,7 @@ public function duplicateEntity(Request $request, $id) {
private function verifyImportData(Request $request) {
$user = auth()->user();
- if (!$user->can('entity_create') || !$user->can('entity_write')) {
+ if(!$user->can('entity_create') || !$user->can('entity_write')) {
return response()->json([
'error' => __('You do not have the permission to import entity data'),
], 403);
@@ -510,27 +509,27 @@ public function importData(Request $request) {
// Getting headers
- if (($row = fgetcsv($handle, 0, $metadata['delimiter'])) !== false) {
+ if(($row = fgetcsv($handle, 0, $metadata['delimiter'])) !== false) {
$row = sp_trim_array($row);
try {
$headerRow = $row;
- for ($i = 0; $i < count($row); $i++) {
- if ($row[$i] == $nameColumn) {
+ for($i = 0; $i < count($row); $i++) {
+ if($row[$i] == $nameColumn) {
$nameIdx = $i;
- } else if (isset($parentColumn) && $row[$i] == $parentColumn) {
+ } else if(isset($parentColumn) && $row[$i] == $parentColumn) {
$parentIdx = $i;
$hasParent = true;
}
- foreach ($attributesMapping as $id => $a) {
- if ($a == $row[$i]) {
+ foreach($attributesMapping as $id => $a) {
+ if($a == $row[$i]) {
$attributeIdToColumnIdxMapping[$id] = $i;
$attributeTypes[$id] = Attribute::findOrFail($id)->datatype;
break;
}
}
}
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
DB::rollBack();
$ids = $e->getIds();
return response()->json([
@@ -541,11 +540,11 @@ public function importData(Request $request) {
}
//Processing rows
- while (($row = fgetcsv($handle, 0, $metadata['delimiter'])) !== false) {
+ while(($row = fgetcsv($handle, 0, $metadata['delimiter'])) !== false) {
$row = sp_trim_array($row);
$affectedRows++;
- if (!isset($nameIdx)) {
+ if(!isset($nameIdx)) {
throw new ImportException(
"Name column '" . $nameColumn . "' could not be found in CSV file",
400,
@@ -563,7 +562,7 @@ public function importData(Request $request) {
entry: $entityName,
);
- if ($hasParent && !empty($rootEntityPath)) {
+ if($hasParent && !empty($rootEntityPath)) {
$entityPath = implode("\\\\", [$rootEntityPath, $entityName]);
@@ -573,14 +572,14 @@ public function importData(Request $request) {
try {
$parentEntity = Entity::getFromPath($rootEntityPath);
- if (!isset($parentEntity)) {
+ if(!isset($parentEntity)) {
DB::rollBack();
return response()->json([
'error' => __('Parent entity does not exist'),
'data' => $errorResponseData
], 400);
}
- } catch (AmbiguousValueException $ave) {
+ } catch(AmbiguousValueException $ave) {
DB::rollBack();
return response()->json([
'error' => __($ave->getMessage()),
@@ -591,7 +590,7 @@ public function importData(Request $request) {
try {
$entityId = Entity::getFromPath($entityPath);
- } catch (AmbiguousValueException $ave) {
+ } catch(AmbiguousValueException $ave) {
DB::rollBack();
return response()->json([
'error' => __($ave->getMessage()),
@@ -600,11 +599,11 @@ public function importData(Request $request) {
}
try {
$user = auth()->user();
- if ($entityId == null) {
+ if($entityId == null) {
$entity = $this->createImportedEntity($entityName, $rootEntityPath, $entityTypeId, $user);
// If create entity fails, return error
- if ($entity["type"] !== "entity") {
+ if($entity["type"] !== "entity") {
DB::rollBack();
return response()->json([
'error' => $entity['msg'],
@@ -621,10 +620,10 @@ public function importData(Request $request) {
$this->setOrUpdateImportedAttributes($entityId, $row, $headerRow, $attributeIdToColumnIdxMapping, $attributeTypes, $user);
$changedEntities[] = $entityId;
- } catch (AttributeImportException $e) {
+ } catch(AttributeImportException $e) {
DB::rollBack();
return response()->json($e->toImportExceptionObject(count($changedEntities) + 1, $entityName), 400);
- } catch (ImportException $e) {
+ } catch(ImportException $e) {
DB::rollBack();
return response()->json(
[
@@ -633,7 +632,7 @@ public function importData(Request $request) {
],
400
);
- } catch (Exception $e) {
+ } catch(Exception $e) {
DB::rollBack();
return response()->json(
[
@@ -645,7 +644,7 @@ public function importData(Request $request) {
}
}
- if ($affectedRows === 0) {
+ if($affectedRows === 0) {
DB::rollBack();
return response()->json([
'error' => __('entity-importer.empty'),
@@ -660,10 +659,10 @@ public function importData(Request $request) {
function createImportedEntity($entityName, ?string $rootEntityPath, $entityTypeId, $user) {
$rootEntityId = null;
- if (isset($rootEntityPath)) {
+ if(isset($rootEntityPath)) {
try {
$rootEntityId = Entity::getFromPath($rootEntityPath);
- } catch (AmbiguousValueException $ave) {
+ } catch(AmbiguousValueException $ave) {
throw new Exception($ave->getMessage());
}
}
@@ -674,7 +673,7 @@ function createImportedEntity($entityName, ?string $rootEntityPath, $entityTypeI
}
function setOrUpdateImportedAttributes($entity_id, $row, $headerRow, $attributeIdToColumnIdxMapping, $attributeTypes, $user) {
- foreach ($attributeIdToColumnIdxMapping as $key => $colIdx) {
+ foreach($attributeIdToColumnIdxMapping as $key => $colIdx) {
$aid = intval($key);
$type = $attributeTypes[$aid];
@@ -686,7 +685,7 @@ function setOrUpdateImportedAttributes($entity_id, $row, $headerRow, $attributeI
]);
try {
$setValue = $attrVal->setValueFromRaw($row[$colIdx], $type);
- } catch (InvalidDataException $e) {
+ } catch(InvalidDataException $e) {
throw new AttributeImportException(
$e->getMessage(),
new AttributeImportExceptionStruct(
@@ -698,7 +697,7 @@ function setOrUpdateImportedAttributes($entity_id, $row, $headerRow, $attributeI
);
}
- if ($setValue === null) {
+ if($setValue === null) {
continue;
}
$attrVal->save();
@@ -709,7 +708,7 @@ function setOrUpdateImportedAttributes($entity_id, $row, $headerRow, $attributeI
public function patchAttributes($id, Request $request) {
$user = auth()->user();
- if (!$user->can('entity_data_write')) {
+ if(!$user->can('entity_data_write')) {
return response()->json([
'error' => __('You do not have the permission to modify an entity\'s data'),
], 403);
@@ -717,28 +716,28 @@ public function patchAttributes($id, Request $request) {
try {
$entity = Entity::findOrFail($id);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This entity does not exist'),
], 400);
}
$addedAttributes = [];
- foreach ($request->request as $patch) {
+ foreach($request->request as $patch) {
$op = $patch['op'];
$aid = $patch['params']['aid'];
- switch ($op) {
+ switch($op) {
case 'remove':
$attrval = AttributeValue::where([
['entity_id', '=', $id],
['attribute_id', '=', $aid],
])->first();
- if (!isset($attrval)) {
+ if(!isset($attrval)) {
return response()->json([
'error' => __('This attribute value does either not exist or is in moderation state.'),
], 400);
}
- if ($user->isModerated()) {
+ if($user->isModerated()) {
$attrval->moderate('pending-delete', true);
} else {
$attrval->delete();
@@ -749,7 +748,7 @@ public function patchAttributes($id, Request $request) {
->where('attribute_id', $aid)
->withModerated()
->exists();
- if ($alreadyAdded) {
+ if($alreadyAdded) {
return response()->json([
'error' => __('There is already a value set for this attribute or it is in moderation state.'),
], 400);
@@ -759,7 +758,7 @@ public function patchAttributes($id, Request $request) {
$attrval->entity_id = $id;
$attrval->attribute_id = $aid;
$attrval->certainty = null;
- if ($user->isModerated()) {
+ if($user->isModerated()) {
$attrval->moderate('pending', true, true);
}
break;
@@ -768,7 +767,7 @@ public function patchAttributes($id, Request $request) {
->where('attribute_id', $aid)
->onlyModerated()
->exists();
- if ($alreadyModerated) {
+ if($alreadyModerated) {
return response()->json([
'error' => __('This attribute value is in moderation state. A user with appropriate permissions has to accept or deny it first.'),
], 400);
@@ -778,7 +777,7 @@ public function patchAttributes($id, Request $request) {
['entity_id', '=', $id],
['attribute_id', '=', $aid],
])->first();
- if ($user->isModerated()) {
+ if($user->isModerated()) {
$attrval = $attrval->moderate('pending', false, true);
unset($attrval->comments_count);
}
@@ -790,14 +789,14 @@ public function patchAttributes($id, Request $request) {
}
// no further action required for deleted attribute values, continue with next patch
- if ($op == 'remove') {
+ if($op == 'remove') {
continue;
}
$attr = Attribute::find($aid);
try {
$formKeyValue = AttributeValue::getFormattedKeyValue($attr->datatype, $value);
- } catch (InvalidDataException $ide) {
+ } catch(InvalidDataException $ide) {
return response()->json([
'error' => $ide->getMessage(),
], 422);
@@ -805,7 +804,7 @@ public function patchAttributes($id, Request $request) {
$attrval->{$formKeyValue->key} = $formKeyValue->val;
$attrval->user_id = $user->id;
$attrval->save();
- if ($op == 'add') {
+ if($op == 'add') {
$addedAttributes[$aid] = $attrval;
}
}
@@ -813,7 +812,7 @@ public function patchAttributes($id, Request $request) {
// Save model if last editor changed
// Only update timestamps otherwise
$entity->user_id = $user->id;
- if ($entity->isDirty()) {
+ if($entity->isDirty()) {
$entity->save();
} else {
$entity->touch();
@@ -829,7 +828,7 @@ public function patchAttributes($id, Request $request) {
public function patchAttribute($id, $aid, Request $request) {
$user = auth()->user();
- if (!$user->can('entity_data_write')) {
+ if(!$user->can('entity_data_write')) {
return response()->json([
'error' => __('You do not have the permission to modify an entity\'s data'),
], 403);
@@ -838,14 +837,14 @@ public function patchAttribute($id, $aid, Request $request) {
try {
Entity::findOrFail($id);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This entity does not exist'),
], 400);
}
try {
Attribute::findOrFail($aid);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This attribute does not exist'),
], 400);
@@ -859,7 +858,7 @@ public function patchAttribute($id, $aid, Request $request) {
]);
// When attribute value already exists and nothing changed
// (same certainty)
- if (
+ if(
!$attrValue->wasRecentlyCreated
&&
($request->has('certainty') && $request->get('certainty') == $attrValue->certainty)
@@ -875,7 +874,7 @@ public function patchAttribute($id, $aid, Request $request) {
public function multieditAttributes(Request $request) {
$user = auth()->user();
- if (!$user->can('entity_data_write')) {
+ if(!$user->can('entity_data_write')) {
return response()->json([
'error' => __('You do not have the permission to modify an entity\'s data'),
], 403);
@@ -891,10 +890,10 @@ public function multieditAttributes(Request $request) {
DB::beginTransaction();
- foreach ($attrValues as $av) {
+ foreach($attrValues as $av) {
try {
$attr = Attribute::findOrFail($av['attribute_id']);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
DB::rollBack();
return response()->json([
'error' => __('This attribute does not exist'),
@@ -902,13 +901,13 @@ public function multieditAttributes(Request $request) {
}
try {
$formKeyValue = AttributeValue::getFormattedKeyValue($attr->datatype, $av['value']);
- } catch (InvalidDataException $ide) {
+ } catch(InvalidDataException $ide) {
DB::rollBack();
return response()->json([
'error' => $ide->getMessage(),
], 422);
}
- foreach ($entities as $eid) {
+ foreach($entities as $eid) {
AttributeValue::updateOrCreate(
['entity_id' => $eid, 'attribute_id' => $av['attribute_id']],
[
@@ -926,7 +925,7 @@ public function multieditAttributes(Request $request) {
public function handleModeration($id, $aid, Request $request) {
$user = auth()->user();
- if (!$user->can('entity_data_write') || $user->isModerated()) {
+ if(!$user->can('entity_data_write') || $user->isModerated()) {
return response()->json([
'error' => __('You do not have the permission to modify an entity\'s data'),
], 403);
@@ -940,14 +939,14 @@ public function handleModeration($id, $aid, Request $request) {
try {
Entity::findOrFail($id);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This entity does not exist'),
], 400);
}
try {
$attribute = Attribute::findOrFail($aid);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This attribute does not exist'),
], 400);
@@ -958,7 +957,7 @@ public function handleModeration($id, $aid, Request $request) {
->onlyModerated()
->first();
- if (!isset($attrValue)) {
+ if(!isset($attrValue)) {
return response()->json([
'error' => __('This attribute value does not exist'),
], 400);
@@ -967,10 +966,10 @@ public function handleModeration($id, $aid, Request $request) {
$attrValue->moderate($action);
$editedValue = $request->get('value');
- if (isset($editedValue) && $action == 'accept') {
+ if(isset($editedValue) && $action == 'accept') {
try {
$formKeyValue = AttributeValue::getFormattedKeyValue($attribute->datatype, $editedValue);
- } catch (InvalidDataException $ide) {
+ } catch(InvalidDataException $ide) {
return response()->json([
'error' => $ide->getMessage(),
], 422);
@@ -985,7 +984,7 @@ public function handleModeration($id, $aid, Request $request) {
public function patchName($id, Request $request) {
$user = auth()->user();
- if (!$user->can('entity_write')) {
+ if(!$user->can('entity_write')) {
return response()->json([
'error' => __('You do not have the permission to modify an entity\'s data'),
], 403);
@@ -996,7 +995,7 @@ public function patchName($id, Request $request) {
try {
$entity = Entity::findOrFail($id);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This entity does not exist'),
], 400);
@@ -1044,7 +1043,7 @@ public function patchMetadata($id, Request $request) {
public function moveEntity(Request $request, $id) {
$user = auth()->user();
- if (!$user->can('entity_write')) {
+ if(!$user->can('entity_write')) {
return response()->json([
'error' => __('You do not have the permission to modify an entity'),
], 403);
@@ -1057,7 +1056,7 @@ public function moveEntity(Request $request, $id) {
try {
Entity::findOrFail($id);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This entity does not exist'),
], 400);
@@ -1067,8 +1066,8 @@ public function moveEntity(Request $request, $id) {
$parent_id = $request->get('parent_id');
$addToEnd = $request->get('to_end');
- if ($addToEnd) {
- if (isset($parent_id)) {
+ if($addToEnd) {
+ if(isset($parent_id)) {
$rank = Entity::where('root_entity_id', $parent_id)->max('rank') + 1;
} else {
$rank = Entity::whereNull('root_entity_id')->max('rank') + 1;
@@ -1083,14 +1082,14 @@ public function moveEntity(Request $request, $id) {
public function deleteEntity($id) {
$user = auth()->user();
- if (!$user->can('entity_delete')) {
+ if(!$user->can('entity_delete')) {
return response()->json([
'error' => __('You do not have the permission to delete an entity'),
], 403);
}
try {
$entity = Entity::findOrFail($id);
- } catch (ModelNotFoundException $e) {
+ } catch(ModelNotFoundException $e) {
return response()->json([
'error' => __('This entity does not exist'),
], 400);
diff --git a/resources/js/bootstrap/router.js b/resources/js/bootstrap/router.js
index f0519b9e..50ab0b1c 100644
--- a/resources/js/bootstrap/router.js
+++ b/resources/js/bootstrap/router.js
@@ -8,7 +8,7 @@ import {
// Pages
import Login from '@/components/Login.vue';
import MainView from '@/components/MainView.vue';
-import EntityDetail from '@/components/EntityDetail.vue';
+import EntityDetailView from '@/components/view/EntityDetailView.vue';
import EntityReferenceModal from '@/components/modals/entity/Reference.vue';
// Tools
import Bibliography from '@/components/BibliographyTable.vue';
@@ -132,7 +132,7 @@ export const router = createRouter({
{
path: 'e/:id',
name: 'entitydetail',
- component: EntityDetail,
+ component: EntityDetailView,
children: [
{
path: 'refs/:aid',
diff --git a/resources/js/bootstrap/store.js b/resources/js/bootstrap/store.js
index b4a45f44..e7ff772b 100644
--- a/resources/js/bootstrap/store.js
+++ b/resources/js/bootstrap/store.js
@@ -745,6 +745,8 @@ export const store = createStore({
commit('setEntity', hiddenEntity);
} else {
entity.data = await getEntityData(entityId);
+
+
fillEntityData(entity.data, entity.entity_type_id);
entity.references = await getEntityReferences(entityId) || {};
for(let k in entity.data) {
@@ -756,6 +758,7 @@ export const store = createStore({
}
}
}
+
commit('setEntity', entity);
return;
}
diff --git a/resources/js/components/EntityDetail.vue b/resources/js/components/EntityDetail.vue
index 6bbfb639..fd300c31 100644
--- a/resources/js/components/EntityDetail.vue
+++ b/resources/js/components/EntityDetail.vue
@@ -232,6 +232,23 @@
+
+