Make sure that accounts and tags both can handle locations.

This commit is contained in:
James Cole
2019-12-30 17:43:04 +01:00
parent 7e5d0d455a
commit becab15ab8
13 changed files with 123 additions and 124 deletions

View File

@@ -92,18 +92,29 @@ class TagController extends Controller
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create()
public function create(Request $request)
{
$subTitle = (string)trans('firefly.new_tag');
$subTitleIcon = 'fa-tag';
// location info:
$hasOldInput = null !== $request->old('_token');
$locations = [
'location' => [
'latitude' => $hasOldInput ? old('location_latitude') : config('firefly.default_location.latitude'),
'longitude' => $hasOldInput ? old('location_longitude') : config('firefly.default_location.longitude'),
'zoom_level' => $hasOldInput ? old('location_zoom_level') : config('firefly.default_location.zoom_level'),
'has_location' => $hasOldInput ? 'true' === old('location_has_location') : false,
],
];
// put previous url in session if not redirect from store (not "create another").
if (true !== session('tags.create.fromStore')) {
$this->rememberPreviousUri('tags.create.uri');
}
session()->forget('tags.create.fromStore');
return view('tags.create', compact('subTitle', 'subTitleIcon'));
return view('tags.create', compact('subTitle', 'subTitleIcon', 'locations'));
}
/**
@@ -153,13 +164,27 @@ class TagController extends Controller
$subTitle = (string)trans('firefly.edit_tag', ['tag' => $tag->tag]);
$subTitleIcon = 'fa-tag';
$location = $this->repository->getLocation($tag);
$latitude = $location ? $location->latitude : config('firefly.default_location.latitude');
$longitude = $location ? $location->longitude : config('firefly.default_location.longitude');
$zoomLevel = $location ? $location->zoom_level : config('firefly.default_location.zoom_level');
$hasLocation = null !== $location;
$locations = [
'location' => [
'latitude' => old('location_latitude') ?? $latitude,
'longitude' => old('location_longitude') ?? $longitude,
'zoom_level' => old('location_zoom_level') ?? $zoomLevel,
'has_location' => $hasLocation || 'true' === old('location_has_location'),
],
];
// put previous url in session if not redirect from store (not "return_to_edit").
if (true !== session('tags.edit.fromUpdate')) {
$this->rememberPreviousUri('tags.edit.uri');
}
session()->forget('tags.edit.fromUpdate');
return view('tags.edit', compact('tag', 'subTitle', 'subTitleIcon'));
return view('tags.edit', compact('tag', 'subTitle', 'subTitleIcon','locations'));
}
/**
@@ -209,6 +234,7 @@ class TagController extends Controller
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$start = $start ?? session('start');
$end = $end ?? session('end');
$location = $this->repository->getLocation($tag);
$subTitle = trans(
'firefly.journals_in_period_for_tag', ['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat),
'end' => $end->formatLocalized($this->monthAndDayFormat),]
@@ -229,7 +255,7 @@ class TagController extends Controller
$groups->setPath($path);
$sums = $this->repository->sumsOfTag($tag, $start, $end);
return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'groups', 'start', 'end'));
return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'groups', 'start', 'end', 'location'));
}
/**
@@ -252,6 +278,7 @@ class TagController extends Controller
$start = $this->repository->firstUseDate($tag) ?? new Carbon;
$end = new Carbon;
$path = route('tags.show', [$tag->id, 'all']);
$location = $this->repository->getLocation($tag);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withAccountInformation()
@@ -260,7 +287,7 @@ class TagController extends Controller
$groups->setPath($path);
$sums = $this->repository->sumsOfTag($tag, $start, $end);
return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'groups', 'start', 'end'));
return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'groups', 'start', 'end', 'location'));
}
/**

View File

@@ -67,9 +67,10 @@ class AccountFormRequest extends Request
'interest' => $this->string('interest'),
'interest_period' => $this->string('interest_period'),
'include_net_worth' => '1',
// new: location
'longitude' => $this->float('location_longitude'),
'latitude' => $this->float('location_latitude'),
'longitude' => $this->string('location_longitude'),
'latitude' => $this->string('location_latitude'),
'zoom_level' => $this->integer('location_zoom_level'),
'has_location' => $this->boolean('location_has_location'),
];
@@ -113,6 +114,9 @@ class AccountFormRequest extends Request
'amount_currency_id_virtual_balance' => 'exists:transaction_currencies,id',
'what' => 'in:' . $types,
'interest_period' => 'in:daily,monthly,yearly',
'latitude' => 'numeric|min:-90|max:90|nullable|required_with:longitude',
'longitude' => 'numeric|min:-180|max:180|nullable|required_with:latitude',
'zoom_level' => 'numeric|min:0|max:80|nullable',
];
if ('liabilities' === $this->get('objectType')) {

View File

@@ -47,26 +47,26 @@ class TagFormRequest extends Request
*/
public function collectTagData(): array
{
$latitude = null;
$longitude = null;
$zoomLevel = null;
if ('true' === $this->get('tag_position_has_tag')) {
$latitude = $this->string('tag_position_latitude');
$longitude = $this->string('tag_position_longitude');
$zoomLevel = $this->integer('tag_position_zoomlevel');
$latitude = null;
$longitude = null;
$zoomLevel = null;
$hasLocation = false;
if (true === $this->boolean('location_has_location')) {
$latitude = $this->string('location_latitude');
$longitude = $this->string('location_longitude');
$zoomLevel = $this->integer('location_zoom_level');
$hasLocation = true;
}
$data = [
'tag' => $this->string('tag'),
'date' => $this->date('date'),
'description' => $this->string('description'),
'latitude' => $latitude,
'longitude' => $longitude,
'zoom_level' => $zoomLevel,
return [
'tag' => $this->string('tag'),
'date' => $this->date('date'),
'description' => $this->string('description'),
'latitude' => $latitude,
'longitude' => $longitude,
'zoom_level' => $zoomLevel,
'has_location' => $hasLocation,
];
return $data;
}
/**