mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
make sure all forms work as expected for b3.
This commit is contained in:
@@ -76,7 +76,7 @@ class IndexController extends Controller
|
|||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$this->createDefaultRuleGroup();
|
$this->createDefaultRuleGroup();
|
||||||
$this->createDefaultRule();
|
$this->createDefaultRule();
|
||||||
$this->ruleGroupRepos->resetRuleGroupOrder();
|
$this->ruleGroupRepos->resetOrder();
|
||||||
$ruleGroups = $this->ruleGroupRepos->getRuleGroupsWithRules(null);
|
$ruleGroups = $this->ruleGroupRepos->getRuleGroupsWithRules(null);
|
||||||
|
|
||||||
return prefixView('rules.index', compact('ruleGroups'));
|
return prefixView('rules.index', compact('ruleGroups'));
|
||||||
@@ -96,43 +96,6 @@ class IndexController extends Controller
|
|||||||
return redirect($route);
|
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 Request $request
|
||||||
* @param Rule $rule
|
* @param Rule $rule
|
||||||
|
@@ -51,7 +51,7 @@ class EditController extends Controller
|
|||||||
|
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
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');
|
app('view')->share('mainTitleIcon', 'fa-random');
|
||||||
|
|
||||||
$this->repository = app(RuleGroupRepositoryInterface::class);
|
$this->repository = app(RuleGroupRepositoryInterface::class);
|
||||||
@@ -70,7 +70,12 @@ class EditController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function down(RuleGroup $ruleGroup)
|
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'));
|
return redirect(route('rules.index'));
|
||||||
}
|
}
|
||||||
@@ -86,11 +91,11 @@ class EditController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(Request $request, RuleGroup $ruleGroup)
|
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');
|
$hasOldInput = null !== $request->old('_token');
|
||||||
$preFilled = [
|
$preFilled = [
|
||||||
'active' => $hasOldInput ? (bool) $request->old('active') : $ruleGroup->active,
|
'active' => $hasOldInput ? (bool)$request->old('active') : $ruleGroup->active,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@@ -114,7 +119,11 @@ class EditController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function up(RuleGroup $ruleGroup)
|
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'));
|
return redirect(route('rules.index'));
|
||||||
}
|
}
|
||||||
@@ -132,15 +141,15 @@ class EditController extends Controller
|
|||||||
$data = [
|
$data = [
|
||||||
'title' => $request->string('title'),
|
'title' => $request->string('title'),
|
||||||
'description' => $request->nlString('description'),
|
'description' => $request->nlString('description'),
|
||||||
'active' => 1 === (int) $request->input('active'),
|
'active' => 1 === (int)$request->input('active'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->repository->update($ruleGroup, $data);
|
$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();
|
app('preferences')->mark();
|
||||||
$redirect = redirect($this->getPreviousUri('rule-groups.edit.uri'));
|
$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
|
// @codeCoverageIgnoreStart
|
||||||
session()->put('rule-groups.edit.fromUpdate', true);
|
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
|
public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule
|
||||||
{
|
{
|
||||||
$rule->order = $order;
|
|
||||||
if ($rule->rule_group_id !== $ruleGroup->id) {
|
if ($rule->rule_group_id !== $ruleGroup->id) {
|
||||||
$rule->rule_group_id = $ruleGroup->id;
|
$rule->rule_group_id = $ruleGroup->id;
|
||||||
}
|
}
|
||||||
$rule->save();
|
$rule->save();
|
||||||
|
$rule->refresh();
|
||||||
|
$this->setOrder($rule, $order);
|
||||||
|
|
||||||
return $rule;
|
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
|
* @param RuleGroup $ruleGroup
|
||||||
*
|
*
|
||||||
|
@@ -132,22 +132,6 @@ interface RuleRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule;
|
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
|
* @param RuleGroup $ruleGroup
|
||||||
*
|
*
|
||||||
|
@@ -274,7 +274,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function maxOrder(): int
|
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
|
public function resetOrder(): bool
|
||||||
{
|
{
|
||||||
$this->user->ruleGroups()->whereNotNull('deleted_at');
|
$this->user->ruleGroups()->where('active', false)->update(['order' => 0]);
|
||||||
|
|
||||||
$set = $this->user
|
$set = $this->user
|
||||||
->ruleGroups()
|
->ruleGroups()
|
||||||
|
->where('active', 1)
|
||||||
|
->whereNull('deleted_at')
|
||||||
->orderBy('order', 'ASC')
|
->orderBy('order', 'ASC')
|
||||||
->orderBy('title', 'DESC')
|
->orderBy('title', 'DESC')
|
||||||
->get();
|
->get();
|
||||||
@@ -315,6 +316,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
|||||||
{
|
{
|
||||||
$set = $ruleGroup->rules()
|
$set = $ruleGroup->rules()
|
||||||
->orderBy('order', 'ASC')
|
->orderBy('order', 'ASC')
|
||||||
|
->where('active', true)
|
||||||
->orderBy('title', 'DESC')
|
->orderBy('title', 'DESC')
|
||||||
->orderBy('updated_at', 'DESC')
|
->orderBy('updated_at', 'DESC')
|
||||||
->get(['rules.*']);
|
->get(['rules.*']);
|
||||||
@@ -370,7 +372,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
|||||||
$index = 1;
|
$index = 1;
|
||||||
/** @var RuleTrigger $trigger */
|
/** @var RuleTrigger $trigger */
|
||||||
foreach ($triggers as $trigger) {
|
foreach ($triggers as $trigger) {
|
||||||
$order = (int) $trigger->order;
|
$order = (int)$trigger->order;
|
||||||
if ($order !== $index) {
|
if ($order !== $index) {
|
||||||
$trigger->order = $index;
|
$trigger->order = $index;
|
||||||
$trigger->save();
|
$trigger->save();
|
||||||
|
@@ -100,6 +100,7 @@ trait AppendsLocationData
|
|||||||
$data['zoom_level'] = $this->string($zoomLevelKey);
|
$data['zoom_level'] = $this->string($zoomLevelKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for a PUT (api update) or POST update (UI)
|
||||||
if ($isValidPUT) {
|
if ($isValidPUT) {
|
||||||
Log::debug('Method is PUT and all fields present and not NULL.');
|
Log::debug('Method is PUT and all fields present and not NULL.');
|
||||||
$data['update_location'] = true;
|
$data['update_location'] = true;
|
||||||
@@ -164,20 +165,21 @@ trait AppendsLocationData
|
|||||||
if (null !== $this->get($longitudeKey) && null !== $this->get($latitudeKey) && null !== $this->get($zoomLevelKey)) {
|
if (null !== $this->get($longitudeKey) && null !== $this->get($latitudeKey) && null !== $this->get($zoomLevelKey)) {
|
||||||
Log::debug('All fields present');
|
Log::debug('All fields present');
|
||||||
// if is POST and route contains API, this is enough:
|
// 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');
|
Log::debug('Is API location');
|
||||||
|
|
||||||
return true;
|
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) {
|
if ('POST' === $this->method() && $this->routeIs('*.store') && !$this->routeIs('api.v1.*') && $hasLocationKey) {
|
||||||
|
Log::debug('Is POST + store route.');
|
||||||
$hasLocation = $this->boolean($hasLocationKey);
|
$hasLocation = $this->boolean($hasLocationKey);
|
||||||
if (true === $hasLocation) {
|
if (true === $hasLocation) {
|
||||||
Log::debug('Is form location');
|
Log::debug('Has form form location');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Log::debug('Is not form location');
|
Log::debug('Does not have form location');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -200,13 +202,38 @@ trait AppendsLocationData
|
|||||||
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
|
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
|
||||||
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
|
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
|
||||||
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
|
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
|
||||||
|
$hasLocationKey = $this->getLocationKey($prefix, 'has_location');
|
||||||
|
Log::debug('Now in isValidPUT()');
|
||||||
|
|
||||||
return (
|
// all fields must be set:
|
||||||
null !== $this->get($longitudeKey)
|
if( null !== $this->get($longitudeKey) && null !== $this->get($latitudeKey) && null !== $this->get($zoomLevelKey)) {
|
||||||
&& null !== $this->get($latitudeKey)
|
Log::debug('All fields present.');
|
||||||
&& null !== $this->get($zoomLevelKey))
|
// must be PUT and API route:
|
||||||
&& (('PUT' === $this->method() && $this->routeIs('*.update'))
|
if ('PUT' === $this->method() && $this->routeIs('api.v1.*')) {
|
||||||
|| ('POST' === $this->method() && $this->routeIs('*.update')));
|
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;
|
$array['piggy_bank_name'] = $piggy->name;
|
||||||
}
|
}
|
||||||
break;
|
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':
|
case 'category_name':
|
||||||
$category = $this->factory->findOrCreate(null, $transactionMeta->value);
|
$category = $this->factory->findOrCreate(null, $transactionMeta->value);
|
||||||
if (null !== $category) {
|
if (null !== $category) {
|
||||||
|
@@ -908,9 +908,6 @@ Route::group(
|
|||||||
Route::post('move-rule/{rule}/{ruleGroup}', ['uses' => 'Rule\IndexController@moveRule', 'as' => 'move-rule']);
|
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
|
// select controller
|
||||||
Route::get('test', ['uses' => 'Rule\SelectController@testTriggers', 'as' => 'test-triggers']);
|
Route::get('test', ['uses' => 'Rule\SelectController@testTriggers', 'as' => 'test-triggers']);
|
||||||
Route::get('test-rule/{rule}', ['uses' => 'Rule\SelectController@testTriggersByRule', 'as' => 'test-triggers-rule']);
|
Route::get('test-rule/{rule}', ['uses' => 'Rule\SelectController@testTriggersByRule', 'as' => 'test-triggers-rule']);
|
||||||
|
Reference in New Issue
Block a user