Can edit and set location for accounts.

This commit is contained in:
James Cole 2019-12-30 12:12:08 +01:00
parent 71f2cacdbd
commit 54b049e106
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
24 changed files with 15310 additions and 785 deletions

View File

@ -79,6 +79,15 @@ class CreateController extends Controller
$subTitle = (string)trans(sprintf('firefly.make_new_%s_account', $objectType)); $subTitle = (string)trans(sprintf('firefly.make_new_%s_account', $objectType));
$roles = $this->getRoles(); $roles = $this->getRoles();
$liabilityTypes = $this->getLiabilityTypes(); $liabilityTypes = $this->getLiabilityTypes();
$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,
],
];
// interest calculation periods: // interest calculation periods:
$interestPeriods = [ $interestPeriods = [
@ -88,7 +97,6 @@ class CreateController extends Controller
]; ];
// pre fill some data // pre fill some data
$hasOldInput = null !== $request->old('_token');
$request->session()->flash( $request->session()->flash(
'preFilled', [ 'preFilled', [
'currency_id' => $defaultCurrency->id, 'currency_id' => $defaultCurrency->id,
@ -103,7 +111,7 @@ class CreateController extends Controller
$request->session()->forget('accounts.create.fromStore'); $request->session()->forget('accounts.create.fromStore');
Log::channel('audit')->info('Creating new account.'); Log::channel('audit')->info('Creating new account.');
return view('accounts.create', compact('subTitleIcon', 'objectType', 'interestPeriods', 'subTitle', 'roles', 'liabilityTypes')); return view('accounts.create', compact('subTitleIcon', 'locations', 'objectType', 'interestPeriods', 'subTitle', 'roles', 'liabilityTypes'));
} }
/** /**
@ -115,7 +123,6 @@ class CreateController extends Controller
*/ */
public function store(AccountFormRequest $request) public function store(AccountFormRequest $request)
{ {
$data = $request->getAccountData(); $data = $request->getAccountData();
$account = $this->repository->store($data); $account = $this->repository->store($data);
$request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name])); $request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name]));

View File

@ -87,6 +87,19 @@ class EditController extends Controller
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$roles = $this->getRoles(); $roles = $this->getRoles();
$liabilityTypes = $this->getLiabilityTypes(); $liabilityTypes = $this->getLiabilityTypes();
$location = $repository->getLocation($account);
$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'),
],
];
// interest calculation periods: // interest calculation periods:
$interestPeriods = [ $interestPeriods = [
@ -132,7 +145,9 @@ class EditController extends Controller
$request->session()->flash('preFilled', $preFilled); $request->session()->flash('preFilled', $preFilled);
return view( return view(
'accounts.edit', compact('account', 'currency', 'subTitle', 'subTitleIcon', 'objectType', 'roles', 'preFilled', 'liabilityTypes', 'interestPeriods') 'accounts.edit', compact(
'account', 'currency', 'subTitle', 'subTitleIcon', 'locations', 'objectType', 'roles', 'preFilled', 'liabilityTypes', 'interestPeriods'
)
); );
} }

View File

@ -155,6 +155,7 @@ class IndexController extends Controller
$account->interest = round($this->repository->getMetaValue($account, 'interest'), 6); $account->interest = round($this->repository->getMetaValue($account, 'interest'), 6);
$account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))); $account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
$account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type)); $account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));
$account->location = $this->repository->getLocation($account);
} }
); );

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(); $location = $this->repository->getLocation($account);
$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));
@ -147,6 +147,7 @@ class ShowController extends Controller
return $this->redirectAccountToAccount($account); // @codeCoverageIgnore return $this->redirectAccountToAccount($account); // @codeCoverageIgnore
} }
$location = $this->repository->getLocation($account);
$isLiability = $this->repository->isLiability($account); $isLiability = $this->repository->isLiability($account);
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); $objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
$end = new Carbon; $end = new Carbon;
@ -168,8 +169,10 @@ class ShowController extends Controller
return view( return view(
'accounts.show', 'accounts.show',
compact('account', 'showAll', 'objectType', 'isLiability', 'currency', 'today', compact(
'chartUri', 'periods', 'subTitleIcon', 'groups', 'subTitle', 'start', 'end') 'account', 'showAll', 'location', 'objectType', 'isLiability', 'currency', 'today',
'chartUri', 'periods', 'subTitleIcon', 'groups', 'subTitle', 'start', 'end'
)
); );
} }

View File

@ -70,8 +70,8 @@ class AccountFormRequest extends Request
// new: location // new: location
'longitude' => $this->float('location_longitude'), 'longitude' => $this->float('location_longitude'),
'latitude' => $this->float('location_latitude'), 'latitude' => $this->float('location_latitude'),
'zoom_level' => $this->integer('location_zoomlevel'), 'zoom_level' => $this->integer('location_zoom_level'),
'has_location' => $this->boolean('location_has_tag'), 'has_location' => $this->boolean('location_has_location'),
]; ];
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

@ -27,6 +27,7 @@ use FireflyIII\User;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@ -91,7 +92,18 @@ class Tag extends Model
'longitude' => 'float', 'longitude' => 'float',
]; ];
/** @var array Fields that can be filled */ /** @var array Fields that can be filled */
protected $fillable = ['user_id', 'tag', 'date', 'description', 'latitude', 'longitude', 'zoomLevel', 'tagMode']; protected $fillable = ['user_id', 'tag', 'date', 'description'];
protected $hidden = ['zoomLevel', 'latitude', 'longitude'];
/**
* @codeCoverageIgnore
* @return MorphMany
*/
public function locations(): MorphMany
{
return $this->morphMany(Location::class, 'locatable');
}
/** /**
* Route binder. Converts the key in the URL to the specified object (or throw 404). * Route binder. Converts the key in the URL to the specified object (or throw 404).

View File

@ -28,6 +28,7 @@ use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Location;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
@ -634,4 +635,12 @@ class AccountRepository implements AccountRepositoryInterface
return $query->get(['accounts.*']); return $query->get(['accounts.*']);
} }
/**
* @inheritDoc
*/
public function getLocation(Account $account): ?Location
{
return $account->locations()->first();
}
} }

View File

@ -25,6 +25,7 @@ namespace FireflyIII\Repositories\Account;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Location;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
@ -46,6 +47,15 @@ interface AccountRepositoryInterface
*/ */
public function count(array $types): int; public function count(array $types): int;
/**
* Get account location, if any.
*
* @param Account $account
*
* @return Location|null
*/
public function getLocation(Account $account): ?Location;
/** /**
* Moved here from account CRUD. * Moved here from account CRUD.
* *

View File

@ -25,6 +25,7 @@ namespace FireflyIII\Services\Internal\Update;
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;
@ -99,6 +100,23 @@ class AccountUpdateService
// update all meta data: // update all meta data:
$this->updateMetaData($account, $data); $this->updateMetaData($account, $data);
// update, delete or create location:
$hasLocation = $data['has_location'] ?? false;
if (false === $hasLocation) {
$account->locations()->delete();
}
if (true === $hasLocation) {
$location = $this->accountRepository->getLocation($account);
if (null === $location) {
$location = new Location;
$location->locatable()->associate($account);
}
$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();
}
// has valid initial balance (IB) data? // has valid initial balance (IB) data?
$type = $account->accountType; $type = $account->accountType;
// if it can have a virtual balance, it can also have an opening balance. // if it can have a virtual balance, it can also have an opening balance.

View File

@ -157,6 +157,11 @@ return [
'login_provider' => envNonEmpty('LOGIN_PROVIDER', 'eloquent'), 'login_provider' => envNonEmpty('LOGIN_PROVIDER', 'eloquent'),
'cer_provider' => envNonEmpty('CER_PROVIDER', 'fixer'), 'cer_provider' => envNonEmpty('CER_PROVIDER', 'fixer'),
'update_endpoint' => 'https://version.firefly-iii.org/index.json', 'update_endpoint' => 'https://version.firefly-iii.org/index.json',
'default_location' => [
'longitude' => env('MAP_DEFAULT_LONG', '5.916667'),
'latitude' => env('MAP_DEFAULT_LAT', '51.983333'),
'zoom_level' => env('MAP_DEFAULT_ZOOM', '6'),
],
'allowedMimes' => [ 'allowedMimes' => [
/* plain files */ /* plain files */
'text/plain', 'text/plain',

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

13986
public/v1/lib/leaflet/leaflet-src.esm.js vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -25,6 +25,10 @@
user-select: none; user-select: none;
-webkit-user-drag: none; -webkit-user-drag: none;
} }
/* Prevents IE11 from highlighting tiles in blue */
.leaflet-tile::selection {
background: transparent;
}
/* Safari renders non-retina tile on retina better with this, but Chrome is worse */ /* Safari renders non-retina tile on retina better with this, but Chrome is worse */
.leaflet-safari .leaflet-tile { .leaflet-safari .leaflet-tile {
image-rendering: -webkit-optimize-contrast; image-rendering: -webkit-optimize-contrast;
@ -45,8 +49,10 @@
.leaflet-container .leaflet-marker-pane img, .leaflet-container .leaflet-marker-pane img,
.leaflet-container .leaflet-shadow-pane img, .leaflet-container .leaflet-shadow-pane img,
.leaflet-container .leaflet-tile-pane img, .leaflet-container .leaflet-tile-pane img,
.leaflet-container img.leaflet-image-layer { .leaflet-container img.leaflet-image-layer,
.leaflet-container .leaflet-tile {
max-width: none !important; max-width: none !important;
max-height: none !important;
} }
.leaflet-container.leaflet-touch-zoom { .leaflet-container.leaflet-touch-zoom {
@ -55,7 +61,10 @@
} }
.leaflet-container.leaflet-touch-drag { .leaflet-container.leaflet-touch-drag {
-ms-touch-action: pinch-zoom; -ms-touch-action: pinch-zoom;
} /* Fallback for FF which doesn't support pinch-zoom */
touch-action: none;
touch-action: pinch-zoom;
}
.leaflet-container.leaflet-touch-drag.leaflet-touch-zoom { .leaflet-container.leaflet-touch-drag.leaflet-touch-zoom {
-ms-touch-action: none; -ms-touch-action: none;
touch-action: none; touch-action: none;
@ -164,7 +173,6 @@
opacity: 0; opacity: 0;
-webkit-transition: opacity 0.2s linear; -webkit-transition: opacity 0.2s linear;
-moz-transition: opacity 0.2s linear; -moz-transition: opacity 0.2s linear;
-o-transition: opacity 0.2s linear;
transition: opacity 0.2s linear; transition: opacity 0.2s linear;
} }
.leaflet-fade-anim .leaflet-map-pane .leaflet-popup { .leaflet-fade-anim .leaflet-map-pane .leaflet-popup {
@ -181,14 +189,12 @@
.leaflet-zoom-anim .leaflet-zoom-animated { .leaflet-zoom-anim .leaflet-zoom-animated {
-webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1); -webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1);
-moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1); -moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1);
-o-transition: -o-transform 0.25s cubic-bezier(0,0,0.25,1);
transition: transform 0.25s cubic-bezier(0,0,0.25,1); transition: transform 0.25s cubic-bezier(0,0,0.25,1);
} }
.leaflet-zoom-anim .leaflet-tile, .leaflet-zoom-anim .leaflet-tile,
.leaflet-pan-anim .leaflet-tile { .leaflet-pan-anim .leaflet-tile {
-webkit-transition: none; -webkit-transition: none;
-moz-transition: none; -moz-transition: none;
-o-transition: none;
transition: none; transition: none;
} }
@ -205,6 +211,7 @@
.leaflet-grab { .leaflet-grab {
cursor: -webkit-grab; cursor: -webkit-grab;
cursor: -moz-grab; cursor: -moz-grab;
cursor: grab;
} }
.leaflet-crosshair, .leaflet-crosshair,
.leaflet-crosshair .leaflet-interactive { .leaflet-crosshair .leaflet-interactive {
@ -220,6 +227,7 @@
cursor: move; cursor: move;
cursor: -webkit-grabbing; cursor: -webkit-grabbing;
cursor: -moz-grabbing; cursor: -moz-grabbing;
cursor: grabbing;
} }
/* marker & overlays interactivity */ /* marker & overlays interactivity */
@ -233,7 +241,8 @@
.leaflet-marker-icon.leaflet-interactive, .leaflet-marker-icon.leaflet-interactive,
.leaflet-image-layer.leaflet-interactive, .leaflet-image-layer.leaflet-interactive,
.leaflet-pane > svg path.leaflet-interactive { .leaflet-pane > svg path.leaflet-interactive,
svg.leaflet-image-layer.leaflet-interactive path {
pointer-events: visiblePainted; /* IE 9-10 doesn't have auto */ pointer-events: visiblePainted; /* IE 9-10 doesn't have auto */
pointer-events: auto; pointer-events: auto;
} }
@ -490,7 +499,6 @@
-webkit-transform: rotate(45deg); -webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg); -moz-transform: rotate(45deg);
-ms-transform: rotate(45deg); -ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg); transform: rotate(45deg);
} }
.leaflet-popup-content-wrapper, .leaflet-popup-content-wrapper,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -503,7 +503,7 @@ return [
'result' => 'Result', 'result' => 'Result',
'sums_apply_to_range' => 'All sums apply to the selected range', 'sums_apply_to_range' => 'All sums apply to the selected range',
'mapbox_api_key' => 'To use map, get an API key from <a href="https://www.mapbox.com/">Mapbox</a>. Open your <code>.env</code> file and enter this code after <code>MAPBOX_API_KEY=</code>.', 'mapbox_api_key' => 'To use map, get an API key from <a href="https://www.mapbox.com/">Mapbox</a>. Open your <code>.env</code> file and enter this code after <code>MAPBOX_API_KEY=</code>.',
'press_tag_location' => 'Right click or long press to set the tag\'s location.', 'press_object_location' => 'Right click or long press to set the object\'s location.',
'clear_location' => 'Clear location', 'clear_location' => 'Clear location',
'delete_all_selected_tags' => 'Delete all selected tags', 'delete_all_selected_tags' => 'Delete all selected tags',
'select_tags_to_delete' => 'Don\'t forget to select some tags.', 'select_tags_to_delete' => 'Don\'t forget to select some tags.',

View File

@ -3,6 +3,11 @@
{{ Breadcrumbs.render(Route.getCurrentRoute.getName, objectType) }} {{ Breadcrumbs.render(Route.getCurrentRoute.getName, objectType) }}
{% endblock %} {% endblock %}
{% block content %} {% 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 action="{{ route('accounts.store') }}" method="post" id="store" class="form-horizontal"> <form action="{{ route('accounts.store') }}" method="post" id="store" class="form-horizontal">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/> <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
@ -53,7 +58,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') }} {{ ExpandedForm.location('location', null, {locations:locations}) }}
</div> </div>
</div> </div>
@ -77,43 +82,7 @@
</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 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>

View File

@ -5,6 +5,12 @@
{% endblock %} {% endblock %}
{% block content %} {% 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(account, {'class' : 'form-horizontal','id' : 'update','url' : route('accounts.update',account.id) } ) }} {{ Form.model(account, {'class' : 'form-horizontal','id' : 'update','url' : route('accounts.update',account.id) } ) }}
<input type="hidden" name="id" value="{{ account.id }}"/> <input type="hidden" name="id" value="{{ account.id }}"/>
@ -57,14 +63,13 @@
{{ ExpandedForm.amountNoCurrency('virtual_balance',null) }} {{ ExpandedForm.amountNoCurrency('virtual_balance',null) }}
{% endif %} {% endif %}
{{ ExpandedForm.checkbox('include_net_worth', 1) }}
{{ ExpandedForm.textarea('notes',preFilled.notes,{helpText: trans('firefly.field_supports_markdown')}) }} {{ ExpandedForm.textarea('notes',preFilled.notes,{helpText: trans('firefly.field_supports_markdown')}) }}
{# only correct way to do active checkbox #} {# only correct way to do active checkbox #}
{{ ExpandedForm.checkbox('active', 1) }} {{ ExpandedForm.checkbox('active', 1) }}
{# only correct way to do active checkbox #} {# only correct way to do active checkbox #}
{{ ExpandedForm.checkbox('include_net_worth', 1) }}
{{ ExpandedForm.location('location', null, {locations: locations}) }}
</div> </div>
</div> </div>
@ -100,6 +105,7 @@
{{ Form.close|raw }} {{ Form.close|raw }}
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<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/edit.js?v={{ FF_VERSION }}"></script> <script type="text/javascript" src="v1/js/ff/accounts/edit.js?v={{ FF_VERSION }}"></script>
@ -108,4 +114,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

@ -156,13 +156,6 @@
{% block scripts %} {% block scripts %}
<script type="text/javascript"> <script type="text/javascript">
var showAll = true;
currencySymbol = "{{ currency.symbol }}";
var accountID = {{ account.id }};
var chartUri = '{{ chartUri }}';
{% if not showAll %}
showAll = false;
// location stuff // location stuff
{% if location %} {% if location %}
var latitude = {{ location.latitude|default("52.3167") }}; var latitude = {{ location.latitude|default("52.3167") }};
@ -173,6 +166,15 @@
var mapboxToken = "{{ config('firefly.mapbox_api_key') }}"; var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";
{% endif %} {% endif %}
var showAll = true;
currencySymbol = "{{ currency.symbol }}";
var accountID = {{ account.id }};
var chartUri = '{{ chartUri }}';
{% if not showAll %}
showAll = false;
// 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')]) }}';

View File

@ -1,3 +1,19 @@
<!--
<pre>
Some debug
name: {{ name }}
lat: {{ name~'_latitude' }}
long: {{ name~'_longitude' }}
zoom:{{ name~'_zoom_level' }}
old lat: {{ old(name~'_latitude') }}
old long: {{ old(name~'_longitude') }}
old zoom: {{ old(name~'_zoom_level') }}
default lat: {{ 'location.'~name~'.latitude' }}: {{ options.locations[name].latitude|default(config('firefly.default_location.latitude')) }} (with default)
default long: {{ 'location.'~name~'.longitude' }}: {{ options.locations[name].longitude|default(config('firefly.default_location.longitude')) }} (with default)
default zoom: {{ 'location.'~name~'.zoom_level' }}: {{ options.locations[name].zoom_level|default(config('firefly.default_location.zoom_level')) }} (with default)
</pre>
-->
<div class="{{ classes }}" id="{{ name }}_holder"> <div class="{{ classes }}" id="{{ name }}_holder">
<label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label> <label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label>
<div class="col-sm-8"> <div class="col-sm-8">
@ -7,36 +23,22 @@
</p> </p>
{% else %} {% else %}
<div id="{{ name }}_map" style="width:100%;height:300px;"></div> <div id="{{ name }}_map" style="width:100%;height:300px;"></div>
<div id="map-canvas"></div> <div id="{{ name }}_map_canvas"></div>
<p class="help-block"> <p class="help-block">
{{ 'press_tag_location'|_ }} {{ 'press_object_location'|_ }}
<a href="#" id="{{ name }}_clear_location">{{ 'clear_location'|_ }}</a> <button class="btn btn-default btn-xs" type="button" id="{{ name }}_clear_location">{{ 'clear_location'|_ }}</button>
</p> </p>
{# latitude #} {# latitude #}
{% if old(name~'_latitude') %} <input type="hidden" name="{{ name }}_latitude" value="{{ options.locations[name].latitude|default('52.3167') }}"/>
<input type="hidden" name="{{ name }}_latitude" value="{{ old('tag_position_latitude') }}"/>
{% else %}
<input type="hidden" name="{{ name }}_latitude" value="{{ tag.latitude }}"/>
{% endif %}
{# longitude #} {# longitude #}
{% if old('tag_position_longitude') %} <input type="hidden" name="{{ name }}_longitude" value="{{ options.locations[name].longitude|default('5.5500') }}"/>
<input type="hidden" name="{{ name }}_longitude" value="{{ old('tag_position_longitude') }}"/>
{% else %}
<input type="hidden" name="{{ name }}_longitude" value="{{ tag.longitude }}"/>
{% endif %}
{# zoomlevel #} {# zoomlevel #}
{% if old('tag_position_zoomlevel') %} <input type="hidden" name="{{ name }}_zoom_level" value="{{ options.locations[name].zoom_level|default('6') }}"/>
<input type="hidden" name="{{ name }}_zoomlevel" value="{{ old('tag_position_zoomlevel') }}"/>
{% else %} {# has location set? #}
<input type="hidden" name="{{ name }}_zoomlevel" value="{{ tag.zoomLevel }}"/> <input type="hidden" name="{{ name }}_has_location" value="{{ options.locations[name].has_location|default('false') }}"/>
{% endif %}
{% if tag.zoomLevel and tag.longitude and tag.latitude %}
<input type="hidden" name="{{ name }}_has_tag" value="true"/>
{% else %}
<input type="hidden" name="{{ name }}_has_tag" value="false"/>
{% endif %}
{% include 'form/feedback' %} {% include 'form/feedback' %}
{% endif %} {% endif %}
</div> </div>
@ -45,62 +47,57 @@
{% if config('firefly.mapbox_api_key') != '' %} {% if config('firefly.mapbox_api_key') != '' %}
{% set latitudevar = name~'_latitude' %} {% set latitudevar = name~'_latitude' %}
{% set longitudevar = name~'_longitude' %} {% set longitudevar = name~'_longitude' %}
{% set zoomlevelvar = name~'_zoomlevel' %} {% set zoomlevelvar = name~'_zoom_level' %}
{% set hastagvar = name~'_has_tag' %} {% set haslocationvar = name~'_has_location' %}
{% set settagvar = name~'_set_tag' %}
{% set clearvar = name~'_clear_location' %} {% set clearvar = name~'_clear_location' %}
<script type="text/javascript"> <script type="text/javascript">
var mymap; var mymap;
var marker; var marker;
if (typeof {{ latitudevar }} === "undefined") { if (typeof locations.{{ name }}.latitude === 'undefined') {
var {{ latitudevar }} = locations.{{ name }}.latitude = '52.3167';
"52.3167";
} }
if (typeof {{ longitudevar }} === "undefined") { if (typeof locations.{{ name }}.longitude === 'undefined') {
var {{ longitudevar }} = locations.{{ name }}.longitude = '5.5500';
"5.5500";
} }
if (typeof {{ zoomlevelvar }} === "undefined") { if (typeof locations.{{ name }}.zoom_level === 'undefined') {
var {{ zoomlevelvar }} = locations.{{ name }}.zoom_level = '6';
"6";
} }
if (typeof mapboxToken === 'undefined') { if (typeof mapboxToken === 'undefined') {
var mapboxToken = 'invalid'; var mapboxToken = 'invalid';
} }
// window.onload = function () {
document.getElementById('{{ clearvar }}').addEventListener('click', function () { document.getElementById('{{ clearvar }}').addEventListener('click', function () {
if (typeof marker !== 'undefined') { if (typeof marker !== 'undefined') {
marker.remove(); marker.remove();
$('input[name="{{ hastagvar }}"]').val('false'); $('input[name="{{ haslocationvar }}"]').val('false');
} }
return false;
}); });
};
// set location thing: // set location thing:
function setTagLocation(e) { function setObjectLocation(e) {
console.log('Set object location: lat(' + e.latlng.lat + '), long(' + e.latlng.lng + '), zoom (' + mymap.getZoom() + ')');
$('input[name="{{ latitudevar }}"]').val(e.latlng.lat); $('input[name="{{ latitudevar }}"]').val(e.latlng.lat);
$('input[name="{{ longitudevar }}"]').val(e.latlng.lng); $('input[name="{{ longitudevar }}"]').val(e.latlng.lng);
$('input[name="{{ zoomlevelvar }}"]').val(mymap.getZoom()); $('input[name="{{ zoomlevelvar }}"]').val(mymap.getZoom());
$('input[name="{{ hastagvar }}"]').val('true'); $('input[name="{{ haslocationvar }}"]').val('true');
// remove existing marker: // remove existing marker:
if (typeof marker !== 'undefined') { if (typeof marker !== 'undefined') {
marker.remove(); marker.remove();
} }
// new marker // new marker
marker = L.marker([e.latlng.lat, e.latlng.lng]).addTo(mymap); marker = L.marker({lat: e.latlng.lat, lng: e.latlng.lng}).addTo(mymap);
} }
console.log({{ longitudevar }});
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
"use strict"; "use strict";
// make map: // make map:
mymap = L.map('{{ name }}_map').setView([{{ latitudevar }}, {{ longitudevar }}], {{ zoomlevelvar }}); mymap = L.map('{{ name }}_map').setView({lat: locations.{{ name }}.latitude, lng: locations.{{ name }}.longitude}, locations.{{ name }}.zoom_level);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', { 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>', 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>',
@ -109,13 +106,12 @@
accessToken: mapboxToken accessToken: mapboxToken
}).addTo(mymap); }).addTo(mymap);
mymap.on('contextmenu', setTagLocation); mymap.on('contextmenu', setObjectLocation);
// add marker // add marker
if (typeof {{ settagvar }} !== 'undefined' && {{ settagvar }} === true) { if (typeof locations.{{ name }}.has_location !== 'undefined' && locations.{{ name }}.has_location === true) {
marker = L.marker([{{ latitudevar }}, {{ longitudevar }}]).addTo(mymap); marker = L.marker({lat: locations.{{ name }}.latitude, lng: locations.{{ name }}.longitude}).addTo(mymap);
} }
}); });
</script> </script>
{% endif %} {% endif %}

View File

@ -37,7 +37,12 @@
href="{{ route('accounts.delete',account.id) }}"><i href="{{ route('accounts.delete',account.id) }}"><i
class="fa fa-fw fa-trash-o"></i></a></div> class="fa fa-fw fa-trash-o"></i></a></div>
</td> </td>
<td data-value="{{ account.name }}"><a href="{{ route('accounts.show',account.id) }}">{{ account.name }}</a></td> <td data-value="{{ account.name }}">
<a href="{{ route('accounts.show',account.id) }}">{{ account.name }}</a>
{% if account.location %}
<i class="fa fa-fw fa-map-marker"></i>
{% endif %}
</td>
{% if objectType == "asset" %} {% if objectType == "asset" %}
<td class="hidden-sm hidden-xs hidden-md"> <td class="hidden-sm hidden-xs hidden-md">
{% for entry in account.accountmeta %} {% for entry in account.accountmeta %}