Reset rule order on index. #3376

This commit is contained in:
James Cole 2020-05-19 11:18:58 +02:00
parent ef9714b7e0
commit 4ebb6de520
2 changed files with 10 additions and 3 deletions

View File

@ -91,6 +91,7 @@ class IndexController extends Controller
$user = auth()->user();
$this->createDefaultRuleGroup();
$this->createDefaultRule();
$this->ruleGroupRepos->resetRuleGroupOrder();
$ruleGroups = $this->ruleGroupRepos->getRuleGroupsWithRules($user);
return view('rules.index', compact('ruleGroups'));

View File

@ -56,7 +56,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
}
/**
* @param RuleGroup $ruleGroup
* @param RuleGroup $ruleGroup
* @param RuleGroup|null $moveTo
*
* @return bool
@ -98,6 +98,10 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
foreach ($set as $entry) {
$entry->order = $count;
$entry->save();
// also update rules in group.
$this->resetRulesInGroupOrder($entry);
++$count;
}
@ -114,6 +118,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
$ruleGroup->rules()->whereNotNull('deleted_at')->update(['order' => 0]);
$set = $ruleGroup->rules()
->orderBy('active','DESC')
->orderBy('order', 'ASC')
->orderBy('updated_at', 'DESC')
->get();
@ -328,7 +333,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
/**
* @param RuleGroup $ruleGroup
* @param array $data
* @param array $data
*
* @return RuleGroup
*/
@ -353,4 +358,5 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
{
return $this->user->ruleGroups()->where('title', $title)->first();
}
}
}