mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
make sure all forms work as expected for b3.
This commit is contained in:
parent
d5ee87ddee
commit
a43bd745d1
@ -76,7 +76,7 @@ class IndexController extends Controller
|
||||
$user = auth()->user();
|
||||
$this->createDefaultRuleGroup();
|
||||
$this->createDefaultRule();
|
||||
$this->ruleGroupRepos->resetRuleGroupOrder();
|
||||
$this->ruleGroupRepos->resetOrder();
|
||||
$ruleGroups = $this->ruleGroupRepos->getRuleGroupsWithRules(null);
|
||||
|
||||
return prefixView('rules.index', compact('ruleGroups'));
|
||||
@ -96,43 +96,6 @@ class IndexController extends Controller
|
||||
return redirect($route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop action for reordering of rule actions.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function reorderRuleActions(Request $request, Rule $rule): JsonResponse
|
||||
{
|
||||
$ids = $request->get('actions');
|
||||
if (is_array($ids)) {
|
||||
$this->ruleRepos->reorderRuleActions($rule, $ids);
|
||||
}
|
||||
|
||||
return response()->json('true');
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop action for reordering of rule triggers.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function reorderRuleTriggers(Request $request, Rule $rule): JsonResponse
|
||||
{
|
||||
$ids = $request->get('triggers');
|
||||
if (is_array($ids)) {
|
||||
$this->ruleRepos->reorderRuleTriggers($rule, $ids);
|
||||
}
|
||||
|
||||
return response()->json('true');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Rule $rule
|
||||
|
@ -51,7 +51,7 @@ class EditController extends Controller
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string) trans('firefly.rules'));
|
||||
app('view')->share('title', (string)trans('firefly.rules'));
|
||||
app('view')->share('mainTitleIcon', 'fa-random');
|
||||
|
||||
$this->repository = app(RuleGroupRepositoryInterface::class);
|
||||
@ -70,7 +70,12 @@ class EditController extends Controller
|
||||
*/
|
||||
public function down(RuleGroup $ruleGroup)
|
||||
{
|
||||
$this->repository->moveDown($ruleGroup);
|
||||
$maxOrder =$this->repository->maxOrder();
|
||||
$order = (int)$ruleGroup->order;
|
||||
if ($order < $maxOrder) {
|
||||
$newOrder = $order + 1;
|
||||
$this->repository->setOrder($ruleGroup, $newOrder);
|
||||
}
|
||||
|
||||
return redirect(route('rules.index'));
|
||||
}
|
||||
@ -86,11 +91,11 @@ class EditController extends Controller
|
||||
*/
|
||||
public function edit(Request $request, RuleGroup $ruleGroup)
|
||||
{
|
||||
$subTitle = (string) trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]);
|
||||
$subTitle = (string)trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]);
|
||||
|
||||
$hasOldInput = null !== $request->old('_token');
|
||||
$preFilled = [
|
||||
'active' => $hasOldInput ? (bool) $request->old('active') : $ruleGroup->active,
|
||||
$preFilled = [
|
||||
'active' => $hasOldInput ? (bool)$request->old('active') : $ruleGroup->active,
|
||||
];
|
||||
|
||||
|
||||
@ -114,7 +119,11 @@ class EditController extends Controller
|
||||
*/
|
||||
public function up(RuleGroup $ruleGroup)
|
||||
{
|
||||
$this->repository->moveUp($ruleGroup);
|
||||
$order = (int)$ruleGroup->order;
|
||||
if ($order > 1) {
|
||||
$newOrder = $order - 1;
|
||||
$this->repository->setOrder($ruleGroup, $newOrder);
|
||||
}
|
||||
|
||||
return redirect(route('rules.index'));
|
||||
}
|
||||
@ -132,15 +141,15 @@ class EditController extends Controller
|
||||
$data = [
|
||||
'title' => $request->string('title'),
|
||||
'description' => $request->nlString('description'),
|
||||
'active' => 1 === (int) $request->input('active'),
|
||||
'active' => 1 === (int)$request->input('active'),
|
||||
];
|
||||
|
||||
$this->repository->update($ruleGroup, $data);
|
||||
|
||||
session()->flash('success', (string) trans('firefly.updated_rule_group', ['title' => $ruleGroup->title]));
|
||||
session()->flash('success', (string)trans('firefly.updated_rule_group', ['title' => $ruleGroup->title]));
|
||||
app('preferences')->mark();
|
||||
$redirect = redirect($this->getPreviousUri('rule-groups.edit.uri'));
|
||||
if (1 === (int) $request->get('return_to_edit')) {
|
||||
if (1 === (int)$request->get('return_to_edit')) {
|
||||
// @codeCoverageIgnoreStart
|
||||
session()->put('rule-groups.edit.fromUpdate', true);
|
||||
|
||||
|
@ -263,59 +263,16 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
*/
|
||||
public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule
|
||||
{
|
||||
$rule->order = $order;
|
||||
if ($rule->rule_group_id !== $ruleGroup->id) {
|
||||
$rule->rule_group_id = $ruleGroup->id;
|
||||
}
|
||||
$rule->save();
|
||||
$rule->refresh();
|
||||
$this->setOrder($rule, $order);
|
||||
|
||||
return $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $ids
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reorderRuleActions(Rule $rule, array $ids): bool
|
||||
{
|
||||
$order = 1;
|
||||
foreach ($ids as $actionId) {
|
||||
/** @var RuleTrigger $trigger */
|
||||
$action = $rule->ruleActions()->find($actionId);
|
||||
if (null !== $action) {
|
||||
$action->order = $order;
|
||||
$action->save();
|
||||
++$order;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $ids
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reorderRuleTriggers(Rule $rule, array $ids): bool
|
||||
{
|
||||
$order = 1;
|
||||
foreach ($ids as $triggerId) {
|
||||
/** @var RuleTrigger $trigger */
|
||||
$trigger = $rule->ruleTriggers()->find($triggerId);
|
||||
if (null !== $trigger) {
|
||||
$trigger->order = $order;
|
||||
$trigger->save();
|
||||
++$order;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
|
@ -132,22 +132,6 @@ interface RuleRepositoryInterface
|
||||
*/
|
||||
public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $ids
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reorderRuleActions(Rule $rule, array $ids): bool;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param array $ids
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reorderRuleTriggers(Rule $rule, array $ids): bool;
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
|
@ -274,7 +274,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
*/
|
||||
public function maxOrder(): int
|
||||
{
|
||||
return (int)$this->user->ruleGroups()->max('order');
|
||||
return (int)$this->user->ruleGroups()->where('active', 1)->max('order');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -282,10 +282,11 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
*/
|
||||
public function resetOrder(): bool
|
||||
{
|
||||
$this->user->ruleGroups()->whereNotNull('deleted_at');
|
||||
|
||||
$this->user->ruleGroups()->where('active', false)->update(['order' => 0]);
|
||||
$set = $this->user
|
||||
->ruleGroups()
|
||||
->where('active', 1)
|
||||
->whereNull('deleted_at')
|
||||
->orderBy('order', 'ASC')
|
||||
->orderBy('title', 'DESC')
|
||||
->get();
|
||||
@ -315,6 +316,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
{
|
||||
$set = $ruleGroup->rules()
|
||||
->orderBy('order', 'ASC')
|
||||
->where('active', true)
|
||||
->orderBy('title', 'DESC')
|
||||
->orderBy('updated_at', 'DESC')
|
||||
->get(['rules.*']);
|
||||
@ -370,7 +372,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
$index = 1;
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($triggers as $trigger) {
|
||||
$order = (int) $trigger->order;
|
||||
$order = (int)$trigger->order;
|
||||
if ($order !== $index) {
|
||||
$trigger->order = $index;
|
||||
$trigger->save();
|
||||
|
@ -100,6 +100,7 @@ trait AppendsLocationData
|
||||
$data['zoom_level'] = $this->string($zoomLevelKey);
|
||||
}
|
||||
|
||||
// for a PUT (api update) or POST update (UI)
|
||||
if ($isValidPUT) {
|
||||
Log::debug('Method is PUT and all fields present and not NULL.');
|
||||
$data['update_location'] = true;
|
||||
@ -164,20 +165,21 @@ trait AppendsLocationData
|
||||
if (null !== $this->get($longitudeKey) && null !== $this->get($latitudeKey) && null !== $this->get($zoomLevelKey)) {
|
||||
Log::debug('All fields present');
|
||||
// if is POST and route contains API, this is enough:
|
||||
if ('POST' === $this->method() && $this->routeIs('*.store') && $this->routeIs('api.v1.*')) {
|
||||
if ('POST' === $this->method() && $this->routeIs('api.v1.*')) {
|
||||
Log::debug('Is API location');
|
||||
|
||||
return true;
|
||||
}
|
||||
// if is POST and route does not contain API, must also have "store_location" = true
|
||||
// if is POST and route does not contain API, must also have "has_location" = true
|
||||
if ('POST' === $this->method() && $this->routeIs('*.store') && !$this->routeIs('api.v1.*') && $hasLocationKey) {
|
||||
Log::debug('Is POST + store route.');
|
||||
$hasLocation = $this->boolean($hasLocationKey);
|
||||
if (true === $hasLocation) {
|
||||
Log::debug('Is form location');
|
||||
Log::debug('Has form form location');
|
||||
|
||||
return true;
|
||||
}
|
||||
Log::debug('Is not form location');
|
||||
Log::debug('Does not have form location');
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -200,13 +202,38 @@ trait AppendsLocationData
|
||||
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
|
||||
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
|
||||
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
|
||||
$hasLocationKey = $this->getLocationKey($prefix, 'has_location');
|
||||
Log::debug('Now in isValidPUT()');
|
||||
|
||||
return (
|
||||
null !== $this->get($longitudeKey)
|
||||
&& null !== $this->get($latitudeKey)
|
||||
&& null !== $this->get($zoomLevelKey))
|
||||
&& (('PUT' === $this->method() && $this->routeIs('*.update'))
|
||||
|| ('POST' === $this->method() && $this->routeIs('*.update')));
|
||||
// all fields must be set:
|
||||
if( null !== $this->get($longitudeKey) && null !== $this->get($latitudeKey) && null !== $this->get($zoomLevelKey)) {
|
||||
Log::debug('All fields present.');
|
||||
// must be PUT and API route:
|
||||
if ('PUT' === $this->method() && $this->routeIs('api.v1.*')) {
|
||||
Log::debug('Is API location');
|
||||
return true;
|
||||
}
|
||||
// if POST and not API route, must also have "has_location"
|
||||
// if is POST and route does not contain API, must also have "has_location" = true
|
||||
if ('POST' === $this->method() && $this->routeIs('*.update') && !$this->routeIs('api.v1.*') && $hasLocationKey) {
|
||||
Log::debug('Is POST + store route.');
|
||||
$hasLocation = $this->boolean($hasLocationKey);
|
||||
if (true === $hasLocation) {
|
||||
Log::debug('Has form location data + has_location');
|
||||
|
||||
return true;
|
||||
}
|
||||
Log::debug('Does not have form location');
|
||||
|
||||
return false;
|
||||
}
|
||||
Log::debug('Is not POST API or POST form');
|
||||
|
||||
return false;
|
||||
}
|
||||
Log::debug('Fields not present');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -183,6 +183,14 @@ class RecurrenceTransformer extends AbstractTransformer
|
||||
$array['piggy_bank_name'] = $piggy->name;
|
||||
}
|
||||
break;
|
||||
case 'category_id':
|
||||
$category = $this->factory->findOrCreate((int)$transactionMeta->value, null);
|
||||
if (null !== $category) {
|
||||
$array['category_id'] = (string)$category->id;
|
||||
$array['category_name'] = $category->name;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'category_name':
|
||||
$category = $this->factory->findOrCreate(null, $transactionMeta->value);
|
||||
if (null !== $category) {
|
||||
|
@ -908,9 +908,6 @@ Route::group(
|
||||
Route::post('move-rule/{rule}/{ruleGroup}', ['uses' => 'Rule\IndexController@moveRule', 'as' => 'move-rule']);
|
||||
|
||||
|
||||
Route::post('trigger/order/{rule}', ['uses' => 'Rule\IndexController@reorderRuleTriggers', 'as' => 'reorder-triggers']);
|
||||
Route::post('action/order/{rule}', ['uses' => 'Rule\IndexController@reorderRuleActions', 'as' => 'reorder-actions']);
|
||||
|
||||
// select controller
|
||||
Route::get('test', ['uses' => 'Rule\SelectController@testTriggers', 'as' => 'test-triggers']);
|
||||
Route::get('test-rule/{rule}', ['uses' => 'Rule\SelectController@testTriggersByRule', 'as' => 'test-triggers-rule']);
|
||||
|
Loading…
Reference in New Issue
Block a user