few fixes and updates
parent
0137d31e46
commit
c478fa1636
|
|
@ -24,24 +24,6 @@ class ObjectsController extends Controller {
|
|||
$query = $this->model->query();
|
||||
$service = FiltersService::getService('objects');
|
||||
$service->applyFilters($query, $filters);
|
||||
/*
|
||||
if (($val = $request->get('type')) && ($type = ObjectType::query()->where(['name' => $val])->first())) {
|
||||
$query->whereHas('type', function ($query) use ($val) {
|
||||
$query->where('name', $val)->orWhereHas('parent', function ($query) use ($val) {
|
||||
$query->where('name', $val);
|
||||
});
|
||||
});
|
||||
if (in_array('product', [$type->name, $type->parent->name ?? null]) && ($field = Field::byUuidOrName('specification-holder')->first())) {
|
||||
$field->applyFilter($query, $request->user()->companies->pluck('uuid')->all());
|
||||
}
|
||||
}
|
||||
$filters = collect($request->has('filters') ? json_decode($request->get('filters'), true) : []);
|
||||
$filters->each(function($value, $prop) use($query) {
|
||||
if ($prop === 'search') $this->model->applySearchFilter($query, $value);
|
||||
elseif ($field = Field::byUuidOrName($prop)->first()) $field->applyFilter($query, $value);
|
||||
});
|
||||
$query->orderBy('created_at', 'desc');
|
||||
*/
|
||||
$paginator = $query->paginate(config('app.pagination_limit'));
|
||||
return fractal($paginator, new ObjectTransformer())->respond();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class NirObject extends Model {
|
|||
}
|
||||
|
||||
public function objects(): MorphToMany {
|
||||
return $this->morphToMany(NirObject::class, 'objectable');
|
||||
return $this->morphToMany(NirObject::class, 'objectable')->withPivot(['ord', 'group']);
|
||||
}
|
||||
|
||||
public function objectables($related): MorphToMany {
|
||||
|
|
|
|||
|
|
@ -38,9 +38,10 @@ trait HasObjectsTrait {
|
|||
}
|
||||
|
||||
public function attachObject(NirObject $object, $ord = null, $group = null) {
|
||||
$group = $group ?? 'default';
|
||||
$ord = ($ord === null) ? $this->getMaxObjectOrd($group) : $ord;
|
||||
$this->moveObjectsSet('forward', $ord, null, $group);
|
||||
$this->objects()->attach($object->id, ['ord' => $ord ?? 0, 'group' => $group ?? 'default']);
|
||||
$this->objects()->attach($object->id, ['ord' => $ord ?? 0, 'group' => $group]);
|
||||
}
|
||||
|
||||
public function getMaxObjectOrd($group = null): int {
|
||||
|
|
@ -71,7 +72,7 @@ trait HasObjectsTrait {
|
|||
|
||||
public function trimIndexes($groups) {
|
||||
collect(is_array($groups) ? $groups : [$groups])->unique()->each(function($group) {
|
||||
$this->objectsByGroup($group)->each(function($object, $index) {
|
||||
$this->objectsByGroup($group)->orderByPivot('ord')->each(function($object, $index) {
|
||||
if ($object->pivot->ord !== $index) $this->objects()->updateExistingPivot($object, ['ord' => $index]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class ObjectTransformer extends TransformerAbstract {
|
|||
}
|
||||
|
||||
public function includeObjects(NirObject $model): Collection {
|
||||
return $this->collection($model->objects, new ObjectTransformer());
|
||||
return $this->collection($model->objects()->orderByPivot('ord')->get(), new ObjectTransformer());
|
||||
}
|
||||
|
||||
public function includePermissions(NirObject $model): Primitive {
|
||||
|
|
|
|||
Loading…
Reference in New Issue