Change query() to children() - expose hassuborinates

This commit is contained in:
Deon George 2020-09-14 21:08:55 +10:00
parent 1ebdffa358
commit c549d28340
4 changed files with 13 additions and 11 deletions

View File

@ -78,16 +78,17 @@ class Server
* @param string $dn
* @return |null
*/
public function query(string $dn)
public function children(string $dn)
{
try {
return ($x=(new Entry)
->query()
->select(['dn','hassubordinates'])
->setDn($dn)
->listing()
->get()) ? $x : NULL;
// @todo Tidy up this exception
// @todo Tidy up this exception
} catch (\Exception $e) {
dd(['e'=>$e]);
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Log;
use LdapRecord\Query\Collection;
@ -35,20 +36,20 @@ class APIController extends Controller
* @param Request $request
* @return Collection
*/
public function query(Request $request): Collection
public function children(Request $request): Collection
{
$levels = $request->query('depth',1);
$dn = Crypt::decryptString($request->query('key'));
Log::debug(sprintf('%s: Query [%s] - Levels [%d]',__METHOD__,$dn,$levels));
return (new Server())
->query($dn)
->children($dn)
->transform(function($item) {
return [
'title'=>$item->getDn(),
'title'=>$item->getRdn(),
'item'=>Crypt::encryptString($item->getDn()),
'icon'=>'fa-fw fas fa-sitemap',
'lazy'=>TRUE,
'lazy'=>Arr::get($item->getAttribute('hassubordinates'),0) == 'TRUE',
'tooltip'=>$item->getDn(),
];
});

6
public/js/custom.js vendored
View File

@ -47,7 +47,7 @@ $(document).ready(function() {
source: sources,
lazyLoad: function(event,data) {
data.result = {
url: "api/query",
url: 'api/children',
data: {key: data.node.data.item,depth: 1}
};
@ -55,8 +55,8 @@ $(document).ready(function() {
},
keydown: function(event, data){
switch( $.ui.fancytree.eventToString(data.originalEvent) ) {
case "return":
case "space":
case 'return':
case 'space':
data.node.toggleExpanded();
break;
}

View File

@ -20,6 +20,6 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
});
*/
Route::group([],function() {
Route::get('/bases', 'APIController@bases');
Route::get('/query', 'APIController@query');
Route::get('/bases','APIController@bases');
Route::get('/children','APIController@children');
});