Skip to content

Commit

Permalink
[0.11] Handle colors on entity types (#541)
Browse files Browse the repository at this point in the history
* also handle colors on entity types
* Redesign properties and added dirty state
* Fixed de-/select buttons
* fix tests
* Ensure sub_entity_types is initialized in entityType state
* Refactor EntityTypeList component for improved styling and absolute hover effect
* added search and sort

---------

Signed-off-by: Vinzenz Rosenkranz <[email protected]>
Co-authored-by: Severino <[email protected]>
  • Loading branch information
v1r0x and Severino authored Dec 9, 2024
1 parent 0720820 commit 78915a7
Show file tree
Hide file tree
Showing 14 changed files with 445 additions and 168 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
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.1
Expand Down
3 changes: 2 additions & 1 deletion app/EntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public function getActivitylogOptions() : LogOptions
->logOnlyDirty();
}

public function setRelationInfo($isRoot = false, $subTypes = []) {
public function setRelationInfo($color, $isRoot = false, $subTypes = []) {
$this->is_root = $isRoot;
$this->color = $color;
EntityTypeRelation::where('parent_id', $this->id)->delete();
foreach($subTypes as $type) {
$relation = new EntityTypeRelation();
Expand Down
19 changes: 11 additions & 8 deletions app/Http/Controllers/EditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ public function addEntityType(Request $request) {

$curl = $request->get('concept_url');
$is_root = sp_parse_boolean($request->get('is_root'));
$cType = new EntityType();
$cType->thesaurus_url = $curl;
$cType->is_root = $is_root;
$cType->save();
$cType = EntityType::find($cType->id);
$entityType = new EntityType();
$entityType->thesaurus_url = $curl;
$entityType->is_root = $is_root;
$entityType->color = sprintf('#%06X', mt_rand(0, 0xFFFFFF));
$entityType->save();
$entityType = EntityType::find($entityType->id);

// TODO:: Reimplement in plugin [SO]
//
Expand All @@ -167,7 +168,7 @@ public function addEntityType(Request $request) {

// $cType->load('layer');

return response()->json($cType, 201);
return response()->json($entityType, 201);
}

public function setRelationInfo(Request $request, $id) {
Expand All @@ -179,7 +180,8 @@ public function setRelationInfo(Request $request, $id) {
}
$this->validate($request, [
'is_root' => 'boolean_string',
'sub_entity_types' => 'array'
'sub_entity_types' => 'array',
'color' => 'color',
]);
try {
$entityType = EntityType::findOrFail($id);
Expand All @@ -190,7 +192,8 @@ public function setRelationInfo(Request $request, $id) {
}
$is_root = $request->get('is_root');
$subs = $request->get('sub_entity_types');
$entityType->setRelationInfo($is_root, $subs);
$color = $request->get('color');
$entityType->setRelationInfo($color, $is_root, $subs);
return response()->json(null, 204);
}

Expand Down
61 changes: 61 additions & 0 deletions database/migrations/2024_12_02_132705_move_entity_type_color.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

use App\AvailableLayer;
use App\EntityType;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
activity()->disableLogging();

Schema::table('entity_types', function (Blueprint $table) {
$table->text('color')->nullable();
});

// migrate existing colors from map plugin table
if(Schema::hasTable('available_layers')) {
$entityTypeLayers = AvailableLayer::has('entity_type')->get();

foreach($entityTypeLayers as $entityTypeLayer) {
$color = $entityTypeLayer->color;
$entityTypeLayer->color = null;
$entityTypeLayer->saveQuietly();
$entityType = EntityType::find($entityTypeLayer->entity_type_id);
$entityType->color = $color;
$entityType->saveQuietly();
}
}

activity()->enableLogging();
}

/**
* Reverse the migrations.
*/
public function down(): void
{
activity()->disableLogging();

if(Schema::hasTable('available_layers')) {
$entityTypeLayers = AvailableLayer::has('entity_type')->get();

foreach($entityTypeLayers as $entityTypeLayer) {
$entityTypeLayer->color = $entityTypeLayer->entity_type->color;
$entityTypeLayer->saveQuietly();
}
}

Schema::table('entity_types', function (Blueprint $table) {
$table->dropColumn('color');
});

activity()->enableLogging();
}
};
5 changes: 5 additions & 0 deletions database/seeders/Demo/EntityTypesTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function run()
'created_at' => '2017-12-20 10:03:06',
'updated_at' => '2017-12-20 10:03:06',
'is_root' => true,
'color' => '#FF0000',
),
1 =>
array (
Expand All @@ -30,6 +31,7 @@ public function run()
'created_at' => '2017-12-20 10:03:15',
'updated_at' => '2017-12-20 10:03:15',
'is_root' => false,
'color' => '#FFFF00',
),
2 =>
array (
Expand All @@ -38,6 +40,7 @@ public function run()
'created_at' => '2017-12-20 10:03:23',
'updated_at' => '2017-12-20 10:03:23',
'is_root' => false,
'color' => '#00FF00',
),
3 =>
array (
Expand All @@ -46,6 +49,7 @@ public function run()
'created_at' => '2017-12-20 10:03:30',
'updated_at' => '2017-12-20 10:03:30',
'is_root' => false,
'color' => '#00FFFF',
),
4 =>
array (
Expand All @@ -54,6 +58,7 @@ public function run()
'created_at' => '2017-12-20 16:57:41',
'updated_at' => '2017-12-20 16:57:41',
'is_root' => true,
'color' => '#0000FF',
),
));
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export async function confirmUserPassword(uid, password = null) {
}

export async function updateEntityTypeRelation(etid, values) {
const data = only(values, ['is_root', 'sub_entity_types']);
const data = only(values, ['is_root', 'sub_entity_types', 'color']);
const apiData = { ...data };
if(data.sub_entity_types) {
apiData.sub_entity_types = data.sub_entity_types.map(t => t.id);
Expand Down
11 changes: 8 additions & 3 deletions resources/js/bootstrap/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@/helpers/tree.js';
import {
can,
calculateEntityColors,
fillEntityData,
only,
slugify,
Expand Down Expand Up @@ -159,10 +160,14 @@ export const store = createStore({
},
updateEntityType(state, data) {
const entityType = state.entityTypes[data.id];
const values = only(data, ['thesaurus_url', 'updated_at', 'is_root', 'sub_entity_types']);
const values = only(data, ['thesaurus_url', 'updated_at', 'is_root', 'sub_entity_types', 'color']);
for(let k in values) {
entityType[k] = values[k];
}
if(data.color) {
const colors = calculateEntityColors(data.id);
state.entityTypeColors[data.id] = colors;
}
},
moveEntity(state, data) {
const entity = state.entities[data.entity_id];
Expand Down Expand Up @@ -282,8 +287,8 @@ export const store = createStore({
}
}

// Remove the data from the entity.
// We need to do this as the 'replace', 'add' 'remove'
// Remove the data from the entity.
// We need to do this as the 'replace', 'add' 'remove'
// operations are calculated based on this value.
for(const attributeId in data.removed_data) {
if(entity.data[attributeId]) {
Expand Down
Loading

0 comments on commit 78915a7

Please sign in to comment.