2016-05-20 08:57:45 +02:00
|
|
|
<?php
|
2016-05-20 12:27:31 +02:00
|
|
|
/**
|
|
|
|
* JsonController.php
|
2017-10-21 08:40:00 +02:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-05-20 12:27:31 +02:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* This file is part of Firefly III.
|
2016-10-05 06:52:15 +02:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 14:41:58 +01:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-20 12:27:31 +02:00
|
|
|
*/
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-05-20 08:57:45 +02:00
|
|
|
namespace FireflyIII\Http\Controllers;
|
2015-02-24 22:53:38 +01:00
|
|
|
|
2017-01-22 09:15:53 +01:00
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
2017-01-20 19:50:22 +01:00
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
2015-04-28 10:36:13 +02:00
|
|
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
2016-12-28 13:02:56 +01:00
|
|
|
use Illuminate\Http\Request;
|
2015-02-24 22:53:38 +01:00
|
|
|
use Response;
|
2015-03-29 07:51:56 +02:00
|
|
|
|
2015-02-24 22:53:38 +01:00
|
|
|
/**
|
2017-11-15 12:25:49 +01:00
|
|
|
* Class JsonController.
|
2015-02-24 22:53:38 +01:00
|
|
|
*/
|
2015-03-06 08:20:27 +01:00
|
|
|
class JsonController extends Controller
|
|
|
|
{
|
2016-01-09 08:20:55 +01:00
|
|
|
/**
|
|
|
|
* JsonController constructor.
|
|
|
|
*/
|
2016-01-08 18:29:47 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
2016-01-08 20:40:48 +01:00
|
|
|
parent::__construct();
|
2016-01-08 18:29:47 +01:00
|
|
|
}
|
2015-03-06 08:20:27 +01:00
|
|
|
|
2016-01-14 16:41:15 +01:00
|
|
|
/**
|
2016-12-28 13:02:56 +01:00
|
|
|
* @param Request $request
|
|
|
|
*
|
2016-01-14 16:41:15 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2017-12-22 18:32:43 +01:00
|
|
|
*
|
2017-12-17 14:30:53 +01:00
|
|
|
* @throws \Throwable
|
2016-01-14 16:41:15 +01:00
|
|
|
*/
|
2016-12-28 13:02:56 +01:00
|
|
|
public function action(Request $request)
|
2016-01-14 16:41:15 +01:00
|
|
|
{
|
2016-12-28 13:02:56 +01:00
|
|
|
$count = intval($request->get('count')) > 0 ? intval($request->get('count')) : 1;
|
2016-04-26 21:40:15 +02:00
|
|
|
$keys = array_keys(config('firefly.rule-actions'));
|
2016-01-14 16:41:15 +01:00
|
|
|
$actions = [];
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
$actions[$key] = trans('firefly.rule_action_' . $key . '_choice');
|
|
|
|
}
|
2016-01-24 16:12:59 +01:00
|
|
|
$view = view('rules.partials.action', compact('actions', 'count'))->render();
|
2016-01-14 16:41:15 +01:00
|
|
|
|
|
|
|
return Response::json(['html' => $view]);
|
|
|
|
}
|
|
|
|
|
2017-01-22 09:15:53 +01:00
|
|
|
/**
|
|
|
|
* @param BudgetRepositoryInterface $repository
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function budgets(BudgetRepositoryInterface $repository)
|
|
|
|
{
|
|
|
|
$return = array_unique($repository->getBudgets()->pluck('name')->toArray());
|
|
|
|
sort($return);
|
|
|
|
|
|
|
|
return Response::json($return);
|
|
|
|
}
|
|
|
|
|
2015-02-24 22:53:38 +01:00
|
|
|
/**
|
|
|
|
* Returns a list of categories.
|
|
|
|
*
|
2017-01-22 09:15:53 +01:00
|
|
|
* @param CategoryRepositoryInterface $repository
|
2015-05-03 12:58:55 +02:00
|
|
|
*
|
2015-02-24 22:53:38 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
2017-01-22 09:15:53 +01:00
|
|
|
public function categories(CategoryRepositoryInterface $repository)
|
2015-02-24 22:53:38 +01:00
|
|
|
{
|
2017-01-20 19:50:22 +01:00
|
|
|
$return = array_unique($repository->getCategories()->pluck('name')->toArray());
|
|
|
|
sort($return);
|
2015-02-24 22:53:38 +01:00
|
|
|
|
|
|
|
return Response::json($return);
|
|
|
|
}
|
|
|
|
|
2015-05-05 12:57:27 +02:00
|
|
|
/**
|
|
|
|
* Returns a JSON list of all beneficiaries.
|
|
|
|
*
|
|
|
|
* @param TagRepositoryInterface $tagRepository
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function tags(TagRepositoryInterface $tagRepository)
|
|
|
|
{
|
2017-01-20 19:50:22 +01:00
|
|
|
$return = array_unique($tagRepository->get()->pluck('tag')->toArray());
|
|
|
|
sort($return);
|
2015-05-05 12:57:27 +02:00
|
|
|
|
|
|
|
return Response::json($return);
|
|
|
|
}
|
|
|
|
|
2017-01-20 19:50:22 +01:00
|
|
|
/**
|
2017-02-25 05:57:01 +01:00
|
|
|
* @param JournalRepositoryInterface $repository
|
2017-01-20 19:50:22 +01:00
|
|
|
*
|
2017-02-25 05:57:01 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2017-01-20 19:50:22 +01:00
|
|
|
*/
|
|
|
|
public function transactionTypes(JournalRepositoryInterface $repository)
|
|
|
|
{
|
|
|
|
$return = array_unique($repository->getTransactionTypes()->pluck('type')->toArray());
|
|
|
|
sort($return);
|
2015-03-10 17:26:31 +01:00
|
|
|
|
2017-01-20 19:50:22 +01:00
|
|
|
return Response::json($return);
|
2015-03-10 17:26:31 +01:00
|
|
|
}
|
|
|
|
|
2016-01-24 15:58:16 +01:00
|
|
|
/**
|
2016-12-28 13:02:56 +01:00
|
|
|
* @param Request $request
|
|
|
|
*
|
2016-01-24 15:58:16 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2017-12-22 18:32:43 +01:00
|
|
|
*
|
2017-12-17 14:30:53 +01:00
|
|
|
* @throws \Throwable
|
2016-01-24 15:58:16 +01:00
|
|
|
*/
|
2016-12-28 13:02:56 +01:00
|
|
|
public function trigger(Request $request)
|
2016-01-24 15:58:16 +01:00
|
|
|
{
|
2016-12-28 13:02:56 +01:00
|
|
|
$count = intval($request->get('count')) > 0 ? intval($request->get('count')) : 1;
|
2016-04-26 21:40:15 +02:00
|
|
|
$keys = array_keys(config('firefly.rule-triggers'));
|
2016-01-24 15:58:16 +01:00
|
|
|
$triggers = [];
|
|
|
|
foreach ($keys as $key) {
|
2017-11-15 12:25:49 +01:00
|
|
|
if ('user_action' !== $key) {
|
2016-01-24 15:58:16 +01:00
|
|
|
$triggers[$key] = trans('firefly.rule_trigger_' . $key . '_choice');
|
|
|
|
}
|
|
|
|
}
|
2017-09-03 10:16:45 +02:00
|
|
|
asort($triggers);
|
2016-01-24 15:58:16 +01:00
|
|
|
|
2016-01-24 16:12:59 +01:00
|
|
|
$view = view('rules.partials.trigger', compact('triggers', 'count'))->render();
|
2016-01-24 15:58:16 +01:00
|
|
|
|
|
|
|
return Response::json(['html' => $view]);
|
|
|
|
}
|
2015-02-24 22:53:38 +01:00
|
|
|
}
|