Skip to content

Commit

Permalink
[NF] - doc store
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrobin committed Feb 13, 2020
1 parent 3f9e930 commit 3b6622c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/Docstore/DirectoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function create( Request $request )

return view( 'docstore/dir/create', [
'dir' => false,
'dirs' => DocstoreDirectory::getListingForDropdown( null, $request->user() ),
'dirs' => DocstoreDirectory::getListingForDropdown( DocstoreDirectory::getListing( null, $request->user() ) ),
'parent_dir' => $request->input( 'parent_dir', false )
] );
}
Expand All @@ -118,7 +118,7 @@ public function edit( Request $request , DocstoreDirectory $dir ): View

return view( 'docstore/dir/create', [
'dir' => $dir,
'dirs' => DocstoreDirectory::getListingForDropdown( null, $request->user(), $dir->id ),
'dirs' => DocstoreDirectory::getListingForDropdown( DocstoreDirectory::getListing( null, $request->user() ) ),
'parent_dir' => $dir->parent_dir_id
] );
}
Expand Down
23 changes: 4 additions & 19 deletions app/Models/DocstoreDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,6 @@ public static function getListing( ?DocstoreDirectory $dir, ?UserEntity $user )
}


/**
* Gets a listing of directories and Sub folder
*
* @param DocstoreDirectory|null $dir
* @param UserEntity|null $user
* @param int|null $excluded directory to exclude
*
* @return array
*/
public static function getListingForDropdown( ?DocstoreDirectory $dir, ?UserEntity $user, ?int $excluded = null )
{
return self::structureDirectories( self::getListing( $dir, $user ), $excluded , 5 );
}

/**
* Create an array of directories keeping the hierarchy root/subfolder
*
Expand Down Expand Up @@ -162,28 +148,27 @@ public static function getListingForDropdown( ?DocstoreDirectory $dir, ?UserEnti
*
* @return array
*/
private static function structureDirectories( $dirs, $dirExcluded, $depth )
public static function getListingForDropdown( $dirs, $depth = 5 )
{
$data[] = [
'id' => '',
'name' => 'Root Directory'
];

foreach( $dirs as $dir ) {
if( $dir->id === $dirExcluded ) {
continue;
}

$data[] = [
'id' => $dir->id,
'name' => str_repeat( ' ', $depth ) . '- ' . $dir->name
];

foreach( self::structureDirectories( $dir->subDirectories, $dirExcluded, $depth + 5 ) as $sub ){
foreach( self::getListingForDropdown( $dir->subDirectories, $depth + 5 ) as $sub ) {
$data[] = $sub;
}
}

return $data;

}

}
8 changes: 7 additions & 1 deletion resources/views/docstore/dir/create.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<?= Former::select( 'parent_dir' )
->label( 'Root Directory' )
->fromQuery( $t->dirs, 'name' )
->placeholder( 'Choose a root directory' )
->addClass( 'chzn-select' );
?>

Expand Down Expand Up @@ -90,5 +89,12 @@

<?php $this->section( 'scripts' ) ?>
<script>

<?php if( $t->dir ): ?>
$(document).ready(function() {
$("#parent_dir option[value=" + <?= $t->dir->id ?> +"]").attr('disabled','disabled');
});
<?php endif; ?>

</script>
<?php $this->append() ?>
1 change: 1 addition & 0 deletions resources/views/docstore/dir/js/list.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ className: 'btn-danger',
}
});
});

})
</script>

0 comments on commit 3b6622c

Please sign in to comment.