mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-26 16:26:35 -06:00
Make sure that accounts and tags both can handle locations.
This commit is contained in:
parent
7e5d0d455a
commit
becab15ab8
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Factory;
|
||||
|
||||
use FireflyIII\Models\Location;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
@ -66,11 +67,22 @@ class TagFactory
|
||||
'tagMode' => 'nothing',
|
||||
'date' => $data['date'],
|
||||
'description' => $data['description'],
|
||||
'latitude' => $latitude,
|
||||
'longitude' => $longitude,
|
||||
'zoomLevel' => $zoomLevel,
|
||||
'latitude' => null,
|
||||
'longitude' => null,
|
||||
'zoomLevel' => null,
|
||||
];
|
||||
return Tag::create($array);
|
||||
$tag = Tag::create($array);
|
||||
if (null !== $tag && null !== $latitude && null !== $longitude) {
|
||||
// create location object.
|
||||
$location = new Location;
|
||||
$location->latitude = $latitude;
|
||||
$location->longitude = $longitude;
|
||||
$location->zoom_level = $zoomLevel;
|
||||
$location->locatable()->associate($tag);
|
||||
$location->save();
|
||||
}
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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')) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,7 +92,7 @@ class Tag extends Model
|
||||
'longitude' => 'float',
|
||||
];
|
||||
/** @var array Fields that can be filled */
|
||||
protected $fillable = ['user_id', 'tag', 'date', 'description'];
|
||||
protected $fillable = ['user_id', 'tag', 'date', 'description','tagMode'];
|
||||
|
||||
protected $hidden = ['zoomLevel', 'latitude', 'longitude'];
|
||||
|
||||
|
@ -404,6 +404,23 @@ class TagRepository implements TagRepositoryInterface
|
||||
$tag->zoomLevel = $data['zoom_level'];
|
||||
$tag->save();
|
||||
|
||||
// update, delete or create location:
|
||||
$hasLocation = $data['has_location'] ?? false;
|
||||
if (false === $hasLocation) {
|
||||
$tag->locations()->delete();
|
||||
}
|
||||
if (true === $hasLocation) {
|
||||
$location = $this->getLocation($tag);
|
||||
if (null === $location) {
|
||||
$location = new Location;
|
||||
$location->locatable()->associate($tag);
|
||||
}
|
||||
$location->latitude = $data['latitude'] ?? config('firefly.default_location.latitude');
|
||||
$location->longitude = $data['longitude'] ?? config('firefly.default_location.longitude');
|
||||
$location->zoom_level = $data['zoom_level'] ?? config('firefly.default_location.zoom_level');
|
||||
$location->save();
|
||||
}
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* create-edit.js
|
||||
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||
*
|
||||
|
@ -31,7 +31,7 @@ $(function () {
|
||||
*/
|
||||
|
||||
// make map:
|
||||
var mymap = L.map('tag_location_map', {
|
||||
var mymap = L.map('location_map', {
|
||||
zoomControl: false,
|
||||
touchZoom: false,
|
||||
doubleClickZoom: false,
|
||||
@ -46,9 +46,7 @@ $(function () {
|
||||
id: 'mapbox.streets',
|
||||
accessToken: mapboxToken
|
||||
}).addTo(mymap);
|
||||
|
||||
if (doPlaceMarker) {
|
||||
L.marker([latitude, longitude]).addTo(mymap);
|
||||
}
|
||||
L.marker([latitude, longitude]).addTo(mymap);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -58,7 +58,7 @@
|
||||
{# only correct way to do active checkbox #}
|
||||
{{ ExpandedForm.checkbox('include_net_worth', 1) }}
|
||||
{{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }}
|
||||
{{ ExpandedForm.location('location', null, {locations:locations}) }}
|
||||
{{ ExpandedForm.location('location', null, {locations: locations}) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -160,12 +160,12 @@
|
||||
|
||||
// location stuff
|
||||
{% if location %}
|
||||
var latitude = {{ location.latitude|default("52.3167") }};
|
||||
var longitude = {{ location.longitude|default("5.5500") }};
|
||||
var zoomLevel = {{ location.zoom_level|default("6") }};
|
||||
var doPlaceMarker = true;
|
||||
// token for Mapbox:
|
||||
var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";
|
||||
var latitude = {{ location.latitude|default("52.3167") }};
|
||||
var longitude = {{ location.longitude|default("5.5500") }};
|
||||
var zoomLevel = {{ location.zoom_level|default("6") }};
|
||||
var doPlaceMarker = true;
|
||||
// token for Mapbox:
|
||||
var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";
|
||||
{% endif %}
|
||||
|
||||
var showAll = true;
|
||||
|
@ -5,6 +5,11 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<!-- set location data high up -->
|
||||
<script type="text/javascript">
|
||||
var locations = {{ locations|json_encode|raw }};
|
||||
var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";
|
||||
</script>
|
||||
<form method="POST" action="{{ route('tags.store') }}" accept-charset="UTF-8" class="form-horizontal" id="store">
|
||||
<input name="_token" type="hidden" value="{{ csrf_token() }}">
|
||||
<div class="row">
|
||||
@ -28,7 +33,7 @@
|
||||
<div class="box-body">
|
||||
{{ ExpandedForm.date('date') }}
|
||||
{{ ExpandedForm.textarea('description') }}
|
||||
{{ ExpandedForm.location('tag_position') }}
|
||||
{{ ExpandedForm.location('location', null, {locations: locations}) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -52,39 +57,6 @@
|
||||
</form>
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<script type="text/javascript">
|
||||
// pre-set latitude:
|
||||
{% if old('tag_position_latitude') %}
|
||||
var tag_position_latitude = "{{ old('tag_position_latitude') }}";
|
||||
{% else %}
|
||||
var tag_position_latitude = "52.3167";
|
||||
{% endif %}
|
||||
|
||||
// pre-set longitude
|
||||
{% if old('tag_position_longitude') %}
|
||||
var tag_position_longitude = "{{ old('tag_position_longitude') }}";
|
||||
{% else %}
|
||||
var tag_position_longitude = "5.5500";
|
||||
{% endif %}
|
||||
|
||||
// pre-set zoom level
|
||||
{% if old('tag_position_zoomlevel') %}
|
||||
var tag_position_zoomlevel = "{{ old('tag_position_zoomlevel') }}";
|
||||
{% else %}
|
||||
var tag_position_zoomlevel = "6";
|
||||
{% endif %}
|
||||
|
||||
// must draw a tag?
|
||||
{% if old('tag_position_latitude') and old('tag_position_longitude') and old('tag_position_zoomlevel') %}
|
||||
var tag_position_set_tag = true;
|
||||
{% else %}
|
||||
var tag_position_set_tag = false;
|
||||
{% endif %}
|
||||
|
||||
// token for Mapbox:
|
||||
var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";
|
||||
|
||||
</script>
|
||||
<script src="v1/lib/leaflet/leaflet.js?v={{ FF_VERSION }}"></script>
|
||||
<script type="text/javascript" src="v1/js/lib/modernizr-custom.js?v={{ FF_VERSION }}"></script>
|
||||
<script type="text/javascript" src="v1/js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
|
||||
|
@ -5,6 +5,12 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<!-- set location data high up -->
|
||||
<script type="text/javascript">
|
||||
var locations = {{ locations|json_encode|raw }};
|
||||
var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";
|
||||
</script>
|
||||
|
||||
{{ Form.model(tag, {'class' : 'form-horizontal','id' : 'update','url' : route('tags.update',tag.id)}) }}
|
||||
|
||||
<input type="hidden" name="id" value="{{ tag.id }}"/>
|
||||
@ -30,7 +36,7 @@
|
||||
<div class="box-body">
|
||||
{{ ExpandedForm.date('date', tag.date.format('Y-m-d')) }}
|
||||
{{ ExpandedForm.textarea('description', tag.description) }}
|
||||
{{ ExpandedForm.location('tag_position') }}
|
||||
{{ ExpandedForm.location('location', null, {locations: locations}) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -56,39 +62,6 @@
|
||||
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<script type="text/javascript">
|
||||
// pre-set latitude:
|
||||
{% if old('tag_position_latitude') %}
|
||||
var tag_position_latitude = "{{ old('tag_position_latitude') }}";
|
||||
{% else %}
|
||||
var tag_position_latitude = {{ tag.latitude|default("52.3167") }};
|
||||
{% endif %}
|
||||
|
||||
// pre-set longitude
|
||||
{% if old('tag_position_longitude') %}
|
||||
var tag_position_longitude = "{{ old('tag_position_longitude') }}";
|
||||
{% else %}
|
||||
var tag_position_longitude = {{ tag.longitude|default("5.5500") }};
|
||||
{% endif %}
|
||||
|
||||
// pre-set zoom level
|
||||
{% if old('tag_position_zoomlevel') %}
|
||||
var tag_position_zoomlevel = "{{ old('tag_position_zoomlevel') }}";
|
||||
{% else %}
|
||||
var tag_position_zoomlevel = {{ tag.zoomLevel|default("6") }};
|
||||
{% endif %}
|
||||
|
||||
{% if tag.zoomLevel and tag.longitude and tag.latitude %}
|
||||
var tag_position_set_tag = true;
|
||||
{% else %}
|
||||
var tag_position_set_tag = false;
|
||||
{% endif %}
|
||||
|
||||
|
||||
// token for Mapbox:
|
||||
var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";
|
||||
|
||||
</script>
|
||||
<script src="v1/lib/leaflet/leaflet.js?v={{ FF_VERSION }}"></script>
|
||||
<script type="text/javascript" src="v1/js/lib/modernizr-custom.js?v={{ FF_VERSION }}"></script>
|
||||
<script type="text/javascript" src="v1/js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
|
||||
|
@ -102,8 +102,8 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{% if tag.latitude and tag.longitude and tag.zoomLevel %}
|
||||
<div id="tag_location_map" style="width:100%;height:300px;"></div>
|
||||
{% if(location) %}
|
||||
<div id="location_map" style="width:100%;height:300px;"></div>
|
||||
{% else %}
|
||||
<p>{{ 'no_location_set'|_ }}</p>
|
||||
{% endif %}
|
||||
@ -178,19 +178,15 @@
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<script type="text/javascript">
|
||||
var latitude = {{ tag.latitude|default("52.3167") }};
|
||||
var longitude = {{ tag.longitude|default("5.5500") }};
|
||||
var zoomLevel = {{ tag.zoomLevel|default("6") }};
|
||||
|
||||
{% if tag.latitude and tag.longitude and tag.zoomLevel %}
|
||||
var doPlaceMarker = true;
|
||||
{% else %}
|
||||
var doPlaceMarker = false;
|
||||
// location stuff
|
||||
{% if location %}
|
||||
var latitude = {{ location.latitude|default("52.3167") }};
|
||||
var longitude = {{ location.longitude|default("5.5500") }};
|
||||
var zoomLevel = {{ location.zoom_level|default("6") }};
|
||||
var doPlaceMarker = true;
|
||||
// token for Mapbox:
|
||||
var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";
|
||||
{% endif %}
|
||||
|
||||
// token for Mapbox:
|
||||
var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";
|
||||
|
||||
</script>
|
||||
<script src="v1/lib/leaflet/leaflet.js?v={{ FF_VERSION }}"></script>
|
||||
<script src="v1/js/ff/tags/show.js?v={{ FF_VERSION }}"></script>
|
||||
|
Loading…
Reference in New Issue
Block a user