Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.9.3 #174

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
# Changelog
All notable changes to this project will be documented in this file.

## 0.9.3
### Added
- Made language list searchable
- Add _Project Name_ to browser tab title
### Fixed
- More dropdowns in modals
- Show link to Spacialist if set in preferences
- Broken avatar if is part of Spacialist
- Tree export
- Toggling concepts in sandbox tree no longer show descendants on top level
- Removing a narrower relation in _Detail View_ of a narrower with only one broader left only removed the relation, but the narrower concept still existed without any broaders
### Changed
- No longer show user profile item in dropdown, if is part of Spacialist
- Auto select user (or first available) language in _Create Concept_ modal

## 0.9.2
### Fixed
- Updated language files
- Closing modal on adding concept
- Search did not work if no concept was selected
- Node dropdown not closed on outside click
- Added missing delete functionality
- Dropdowns in modals did not overlap modal boundaries

## 0.9.1
### Added
Expand Down Expand Up @@ -46,6 +62,7 @@ All notable changes to this project will be documented in this file.
- Ignore uppercase/lowercase letters in login form user names
- Several problems with removing concepts
- Adding new top level concept not visible
- Deleting concept with strategy _Delete & Level Up_ led to orphaned descendant concepts

## 0.6.2
### Changed
Expand Down
11 changes: 0 additions & 11 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ class Controller extends BaseController
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

public function __construct() {
// $preferences = Preference::all();
// $preferenceValues = [];
// foreach($preferences as $p) {
// $preferenceValues[$p->label] = Preference::decodePreference($p->label, json_decode($p->default_value));
// }

$preferenceValues = [
'prefs.project-name' => 'Demo'
];

View::share('p', $preferenceValues);
}

public function hasInput(Request $request) {
Expand Down
4 changes: 0 additions & 4 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Preference;
use App\ThConcept;
use App\User;
use Illuminate\Support\Facades\App;

class HomeController extends Controller
{
Expand Down
49 changes: 27 additions & 22 deletions app/Http/Controllers/TreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,10 @@ public function addBroader(Request $request, $id, $bid) {
try {
if($treeName === 'sandbox') {
$concept = ThConceptSandbox::findOrFail($id);
$broaderTable = (new ThBroaderSandbox())->getTable();
} else {
$concept = ThConcept::findOrFail($id);
$broaderTable = (new ThBroader())->getTable();
}
} catch(ModelNotFoundException $e) {
return response()->json([
Expand Down Expand Up @@ -647,7 +649,7 @@ public function addBroader(Request $request, $id, $bid) {
}

// check circles
$circles = th_detect_circles();
$circles = th_detect_circles($broaderTable);

if(count($circles) > 0) {
DB::rollBack();
Expand Down Expand Up @@ -725,8 +727,8 @@ public function removeBroader(Request $request, $id, $bid) {
}

$query->where('broader_id', $bid)
->where('narrower_id', $id)
->delete();
->where('narrower_id', $id)
->delete();
} else {
$concept->is_top_concept = false;
$concept->save();
Expand Down Expand Up @@ -765,11 +767,8 @@ public function deleteConcept(Request $request, $id) {
// 'rerelate' => add concept given by query param 'p' as parent for descendants
$action = $request->query('a', 'cascade');

$conceptTable = th_tree_builder($treeName);
$broaderTable = th_broader_builder($treeName);

$broaders = $broaderTable->where('narrower_id', $id)->pluck('broader_id')->toArray();
$narrowers = $broaderTable->where('broader_id', $id)->pluck('narrower_id')->toArray();
$broaders = th_broader_builder($treeName)->where('narrower_id', $id)->pluck('broader_id')->toArray();
$narrowers = th_broader_builder($treeName)->where('broader_id', $id)->pluck('narrower_id')->toArray();

switch($action) {
case 'cascade':
Expand All @@ -778,15 +777,14 @@ public function deleteConcept(Request $request, $id) {
break;
case 'level':
if($concept->is_top_concept) {
$conceptTable
th_tree_builder($treeName)
->whereIn('id', $narrowers)
->update(['is_top_concept' => true]);
}
$concept->delete();
foreach($broaders as $broaderId) {
foreach($narrowers as $narrowerId) {
$broaderTable = th_broader_builder($treeName);
$exists = $broaderTable
$exists = th_broader_builder($treeName)
->where('broader_id', $broaderId)
->where('narrower_id', $narrowerId)
->exists();
Expand All @@ -806,7 +804,7 @@ public function deleteConcept(Request $request, $id) {
break;
case 'top':
$concept->delete();
$conceptTable
th_tree_builder($treeName)
->whereIn('id', $narrowers)
->update(['is_top_concept' => true]);
break;
Expand All @@ -832,8 +830,7 @@ public function deleteConcept(Request $request, $id) {
}
$concept->delete();
foreach($narrowers as $narrowerId) {
$broaderTable = th_broader_builder($treeName);
$exists = $broaderTable
$exists = th_broader_builder($treeName)
->where('broader_id', $newParentId)
->where('narrower_id', $narrowerId)
->exists();
Expand All @@ -858,6 +855,8 @@ public function deleteConcept(Request $request, $id) {
}

private static function deleteOrphanedConcepts($descs, $tree) {
if(count($descs) == 0) return;

$conceptTable = th_tree_builder($tree);
$uniqueDescs = $conceptTable
->whereIn('id', $descs)
Expand Down Expand Up @@ -1158,7 +1157,7 @@ public function import(Request $request) {
}

// check circles
$circles = th_detect_circles();
$circles = th_detect_circles($thBroader);

if(count($circles) > 0) {
$circleList = '';
Expand Down Expand Up @@ -1587,14 +1586,20 @@ private static function cloneConceptTree($srcId, $tgtBroaderId, $srcTree, $tgtTr
$clonedConcept->save();

if(!$clonedConcept->is_top_concept) {
if($srcTree === 'sandbox') {
$relation = new ThBroader();
} else {
$relation = new ThBroaderSandbox();
$exists = th_broader_builder($tgtTree)
->where('broader_id', $tgtBroaderId)
->where('narrower_id', $clonedConcept->id)
->exists();
if(!$exists) {
if($srcTree === 'sandbox') {
$relation = new ThBroader();
} else {
$relation = new ThBroaderSandbox();
}
$relation->broader_id = $tgtBroaderId;
$relation->narrower_id = $clonedConcept->id;
$relation->save();
}
$relation->broader_id = $tgtBroaderId;
$relation->narrower_id = $clonedConcept->id;
$relation->save();
}

$srcLabels = $srcConcept->labels;
Expand Down
12 changes: 12 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace App\Providers;

use App\Preference;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -14,6 +16,16 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
View::composer('*', function($view) {
$preferences = Preference::all();
$preferenceValues = [];
foreach($preferences as $p) {
$preferenceValues[$p->label] = Preference::decodePreference($p->label, json_decode($p->default_value));
}

$view->with('p', $preferenceValues);
});

Validator::extend('boolean_string', function ($attribute, $value, $parameters, $validator) {
$acceptable = [true, false, 0, 1, '0', '1', 'true', 'false', 'TRUE', 'FALSE'];
return in_array($value, $acceptable, true);
Expand Down
66 changes: 9 additions & 57 deletions app/ThConcept.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class ThConcept extends Model
class ThConcept extends ThConceptBase
{
protected $table = 'th_concept';
protected $broader = ThBroader::class;
protected $appends = ['broaders_count'];

/**
* The attributes that are assignable.
*
Expand All @@ -16,11 +18,10 @@ class ThConcept extends Model
protected $fillable = [
'concept_url',
'concept_scheme',
'is_top_concept',
'user_id',
];

// protected $appends = ['parents', 'path'];

public static function getMap() {
$lang = 'de'; // TODO
$concepts = DB::select(DB::raw("
Expand Down Expand Up @@ -78,6 +79,10 @@ public static function getChildren($url, $recursive = true) {
return DB::select($query);
}

public function getBroadersCountAttribute() {
return $this->broaders()->count();
}

public function labels() {
return $this->hasMany('App\ThConceptLabel', 'concept_id');
}
Expand All @@ -93,57 +98,4 @@ public function narrowers() {
public function broaders() {
return $this->belongsToMany('App\ThConcept', 'th_broaders', 'narrower_id', 'broader_id');
}

public function parentIds() {
$parents = [];

// add empty path for root concepts
if($this->is_top_concept) {
$parents[] = [];
}

$broaders = ThBroader::select('broader_id')
->where('narrower_id', $this->id)
->get();

foreach($broaders as $broader) {
$parentBroaders = ThConcept::find($broader->broader_id)->parentIds();
foreach($parentBroaders as $pB) {
$parents[] = array_merge($pB, [$broader->broader_id]);
}
}

return $parents;
}

public function getParentsAttribute() {
$user = auth()->user();
$langCode = $user->getLanguage();

$parents = [];
foreach($this->parentIds() as $paths) {
$path = [];
foreach($paths as $pid) {
$parent = ThConcept::with(['labels.language' => function($query) use($langCode) {
$query->orderByRaw("short_name != '$langCode'");
}])
->where('id', $pid)
->first();
$path[] = $parent;
}
$parents[] = $path;
}

return $parents;
}

public function getPathAttribute() {
$paths = [];
foreach($this->parentIds() as $idPath) {
$idPath[] = $this->id;
$paths[] = array_reverse($idPath);
}

return $paths;
}
}
76 changes: 76 additions & 0 deletions app/ThConceptBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class ThConceptBase extends Model
{
protected $table;
protected $broader;

/**
* The attributes that are assignable.
*
* @var array
*/
protected $fillable = [
'concept_url',
'concept_scheme',
'is_top_concept',
'user_id',
];

public function parentIds() {
$parents = [];

// add empty path for root concepts
if($this->is_top_concept) {
$parents[] = [];
}

$broaders = $this->broader::select('broader_id')
->where('narrower_id', $this->id)
->get();

foreach($broaders as $broader) {
$parentBroaders = self::find($broader->broader_id)->parentIds();
foreach($parentBroaders as $pB) {
$parents[] = array_merge($pB, [$broader->broader_id]);
}
}

return $parents;
}

public function getParentsAttribute() {
$user = auth()->user();
$langCode = $user->getLanguage();

$parents = [];
foreach($this->parentIds() as $paths) {
$path = [];
foreach($paths as $pid) {
$parent = self::with(['labels.language' => function($query) use($langCode) {
$query->orderByRaw("short_name != '$langCode'");
}])
->where('id', $pid)
->first();
$path[] = $parent;
}
$parents[] = $path;
}

return $parents;
}

public function getPathAttribute() {
$paths = [];
foreach($this->parentIds() as $idPath) {
$idPath[] = $this->id;
$paths[] = array_reverse($idPath);
}

return $paths;
}
}
Loading