Add location to account.

This commit is contained in:
James Cole
2019-12-28 19:49:33 +01:00
parent 950b706e7c
commit 021d421c6f
7 changed files with 155 additions and 42 deletions

View File

@@ -27,6 +27,7 @@ namespace FireflyIII\Factory;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Location;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Support\AccountServiceTrait; use FireflyIII\Services\Internal\Support\AccountServiceTrait;
use FireflyIII\User; use FireflyIII\User;
@@ -131,6 +132,17 @@ class AccountFactory
} }
} }
$this->updateNote($return, $data['notes'] ?? ''); $this->updateNote($return, $data['notes'] ?? '');
// store location
if (true === ($data['has_location'] ?? true) && null !== $return) {
$location = new Location;
$location->latitude = $data['latitude'] ?? 52.3167;
$location->longitude = $data['longitude'] ?? 5.55;
$location->zoom_level = $data['zoom_level'] ?? 6;
$location->locatable()->associate($return);
$location->save();
}
} }
return $return; return $return;

View File

@@ -99,7 +99,7 @@ class ShowController extends Controller
if ($end < $start) { if ($end < $start) {
[$start, $end] = [$end, $start]; // @codeCoverageIgnore [$start, $end] = [$end, $start]; // @codeCoverageIgnore
} }
$location = $account->locations()->first();
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); $objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
$today = new Carbon; $today = new Carbon;
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
@@ -128,7 +128,7 @@ class ShowController extends Controller
'accounts.show', 'accounts.show',
compact( compact(
'account', 'showAll', 'objectType', 'currency', 'today', 'periods', 'subTitleIcon', 'groups', 'subTitle', 'start', 'end', 'account', 'showAll', 'objectType', 'currency', 'today', 'periods', 'subTitleIcon', 'groups', 'subTitle', 'start', 'end',
'chartUri' 'chartUri', 'location'
) )
); );
} }

View File

@@ -67,6 +67,11 @@ class AccountFormRequest extends Request
'interest' => $this->string('interest'), 'interest' => $this->string('interest'),
'interest_period' => $this->string('interest_period'), 'interest_period' => $this->string('interest_period'),
'include_net_worth' => '1', 'include_net_worth' => '1',
// new: location
'longitude' => $this->float('location_longitude'),
'latitude' => $this->float('location_latitude'),
'zoom_level' => $this->integer('location_zoomlevel'),
'has_location' => $this->boolean('location_has_tag'),
]; ];
if (false === $this->boolean('include_net_worth')) { if (false === $this->boolean('include_net_worth')) {
$data['include_net_worth'] = '0'; $data['include_net_worth'] = '0';

View File

@@ -69,6 +69,30 @@ $(function () {
); );
} }
if (doPlaceMarker === true) {
/*
Create new map:
*/
// make map:
var mymap = L.map('location_map', {
zoomControl: false,
touchZoom: false,
doubleClickZoom: false,
scrollWheelZoom: false,
boxZoom: false,
dragging: false
}).setView([latitude, longitude], zoomLevel);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: mapboxToken
}).addTo(mymap);
L.marker([latitude, longitude]).addTo(mymap);
}
}); });
function sortStop(event, ui) { function sortStop(event, ui) {

View File

@@ -38,6 +38,7 @@ return [
'match' => 'Matches on', 'match' => 'Matches on',
'strict' => 'Strict mode', 'strict' => 'Strict mode',
'repeat_freq' => 'Repeats', 'repeat_freq' => 'Repeats',
'location' => 'Location',
'update_channel' => 'Update channel', 'update_channel' => 'Update channel',
'journal_currency_id' => 'Currency', 'journal_currency_id' => 'Currency',
'currency_id' => 'Currency', 'currency_id' => 'Currency',

View File

@@ -53,7 +53,7 @@
{# only correct way to do active checkbox #} {# only correct way to do active checkbox #}
{{ ExpandedForm.checkbox('include_net_worth', 1) }} {{ ExpandedForm.checkbox('include_net_worth', 1) }}
{{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }} {{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }}
{{ ExpandedForm.location('location') }}
</div> </div>
</div> </div>
@@ -77,6 +77,43 @@
</form> </form>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<!-- location script -->
<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/modernizr-custom.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="v1/js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script> <script type="text/javascript" src="v1/js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="v1/js/ff/accounts/create.js?v={{ FF_VERSION }}"></script> <script type="text/javascript" src="v1/js/ff/accounts/create.js?v={{ FF_VERSION }}"></script>
@@ -85,4 +122,5 @@
{% block styles %} {% block styles %}
<link href="v1/css/jquery-ui/jquery-ui.structure.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all"> <link href="v1/css/jquery-ui/jquery-ui.structure.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all">
<link href="v1/css/jquery-ui/jquery-ui.theme.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all"> <link href="v1/css/jquery-ui/jquery-ui.theme.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all">
<link rel="stylesheet" href="v1/lib/leaflet/leaflet.css?v={{ FF_VERSION }}"/>
{% endblock %} {% endblock %}

View File

@@ -85,9 +85,22 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% if account.notes.count == 1 %}
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'location'|_ }}</h3>
</div>
<div class="box-body">
{% if(location) %}
<div id="location_map" style="width:100%;height:300px;"></div>
{% endif %}
</div>
</div>
</div>
{% if account.notes.count == 1 %}
<div class="col-lg-6">
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'notes'|_ }}</h3> <h3 class="box-title">{{ 'notes'|_ }}</h3>
@@ -97,8 +110,8 @@
</div> </div>
</div> </div>
</div> </div>
</div>
{% endif %} {% endif %}
</div>
<div class="row"> <div class="row">
<div class="{% if periods|length > 0 %}col-lg-10 col-md-8 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% endif %}"> <div class="{% if periods|length > 0 %}col-lg-10 col-md-8 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% endif %}">
@@ -149,6 +162,17 @@
var chartUri = '{{ chartUri }}'; var chartUri = '{{ chartUri }}';
{% if not showAll %} {% if not showAll %}
showAll = false; showAll = 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 %}
// uri's for charts: // uri's for charts:
var incomeCategoryUri = '{{ route('chart.account.income-category', [account.id, start.format('Ymd'), end.format('Ymd')]) }}'; var incomeCategoryUri = '{{ route('chart.account.income-category', [account.id, start.format('Ymd'), end.format('Ymd')]) }}';
@@ -162,6 +186,9 @@
{% endif %} {% endif %}
</script> </script>
{% if location %}
<script src="v1/lib/leaflet/leaflet.js?v={{ FF_VERSION }}"></script>
{% endif %}
<script type="text/javascript" src="v1/js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}"></script> <script type="text/javascript" src="v1/js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="v1/js/lib/chartjs-plugin-annotation.min.js?v={{ FF_VERSION }}"></script> <script type="text/javascript" src="v1/js/lib/chartjs-plugin-annotation.min.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="v1/js/ff/charts.defaults.js?v={{ FF_VERSION }}"></script> <script type="text/javascript" src="v1/js/ff/charts.defaults.js?v={{ FF_VERSION }}"></script>
@@ -173,3 +200,9 @@
{# required for groups.twig #} {# required for groups.twig #}
<script type="text/javascript" src="v1/js/ff/list/groups.js?v={{ FF_VERSION }}"></script> <script type="text/javascript" src="v1/js/ff/list/groups.js?v={{ FF_VERSION }}"></script>
{% endblock %} {% endblock %}
{% block styles %}
{% if location %}
<link rel="stylesheet" href="v1/lib/leaflet/leaflet.css?v={{ FF_VERSION }}"/>
{% endif %}
{% endblock %}