mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-31 15:24:31 +03:00
Sorting: Added sort set form manager UI JS
Extracted much code to be shared with the shelf books management UI
This commit is contained in:
@ -15,21 +15,21 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class SortSet extends Model
|
||||
{
|
||||
/**
|
||||
* @return SortSetOption[]
|
||||
* @return SortSetOperation[]
|
||||
*/
|
||||
public function getOptions(): array
|
||||
public function getOperations(): array
|
||||
{
|
||||
$strOptions = explode(',', $this->sequence);
|
||||
$options = array_map(fn ($val) => SortSetOption::tryFrom($val), $strOptions);
|
||||
$options = array_map(fn ($val) => SortSetOperation::tryFrom($val), $strOptions);
|
||||
return array_filter($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SortSetOption[] $options
|
||||
* @param SortSetOperation[] $options
|
||||
*/
|
||||
public function setOptions(array $options): void
|
||||
public function setOperations(array $options): void
|
||||
{
|
||||
$values = array_map(fn (SortSetOption $opt) => $opt->value, $options);
|
||||
$values = array_map(fn (SortSetOperation $opt) => $opt->value, $options);
|
||||
$this->sequence = implode(',', $values);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace BookStack\Sorting;
|
||||
|
||||
enum SortSetOption: string
|
||||
enum SortSetOperation: string
|
||||
{
|
||||
case NameAsc = 'name_asc';
|
||||
case NameDesc = 'name_desc';
|
||||
@ -34,11 +34,11 @@ enum SortSetOption: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SortSetOption[]
|
||||
* @return SortSetOperation[]
|
||||
*/
|
||||
public static function allExcluding(array $options): array
|
||||
public static function allExcluding(array $operations): array
|
||||
{
|
||||
$all = SortSetOption::cases();
|
||||
return array_diff($all, $options);
|
||||
$all = SortSetOperation::cases();
|
||||
return array_diff($all, $operations);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user