move currency to config file; change units to their own group in settings

This commit is contained in:
Nabeel Shahzad
2018-02-26 20:23:48 -06:00
parent 920b92c096
commit d61ade4482
15 changed files with 154 additions and 39 deletions

View File

@@ -2,6 +2,7 @@
use App\Models\Migrations\Migration; use App\Models\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Money\Currencies\CurrencyList;
class CreateSettingsTable extends Migration class CreateSettingsTable extends Migration
{ {
@@ -22,7 +23,7 @@ class CreateSettingsTable extends Migration
$table->string('default')->nullable(); $table->string('default')->nullable();
$table->string('group')->nullable(); $table->string('group')->nullable();
$table->string('type')->nullable(); $table->string('type')->nullable();
$table->string('options')->nullable(); $table->text('options')->nullable();
$table->string('description')->nullable(); $table->string('description')->nullable();
$table->primary('id'); $table->primary('id');
@@ -50,58 +51,67 @@ class CreateSettingsTable extends Migration
'description' => 'Email where notices, etc are sent', 'description' => 'Email where notices, etc are sent',
]); ]);
$this->addSetting('general.currency', [ /*$this->addSetting('general.currency', [
'name' => 'Currency to Use', 'name' => 'Currency to Use',
'group' => 'general', 'group' => 'general',
'value' => 'dollar', 'value' => 'USD',
'type' => 'select', 'type' => 'select',
'options' => 'dollar,euro,gbp,yen,jpy,rupee,ruble', 'options' => 'USD,EUR,GBP,JPY,RUB',
'description' => 'Currency to show in the interface', 'description' => 'Currency to use. NOTE: If you change this, then current amounts won\'t be converted',
]); ]);*/
$this->addSetting('general.distance_unit', [ $this->addSetting('units.distance', [
'name' => 'Distance Units', 'name' => 'Distance Units',
'group' => 'general', 'group' => 'units',
'value' => 'NM', 'value' => 'NM',
'type' => 'select', 'type' => 'select',
'options' => 'km,mi,NM', 'options' => 'km=kilometers,mi=miles,NM=nautical miles',
'description' => 'The distance unit to show', 'description' => 'The distance unit for display',
]); ]);
$this->addSetting('general.weight_unit', [ $this->addSetting('units.weight', [
'name' => 'Weight Units', 'name' => 'Weight Units',
'group' => 'general', 'group' => 'units',
'value' => 'lbs', 'value' => 'lbs',
'type' => 'select', 'type' => 'select',
'options' => 'lbs,kg', 'options' => 'lbs,kg',
'description' => 'The weight unit', 'description' => 'The weight unit for display',
]); ]);
$this->addSetting('general.speed_unit', [ $this->addSetting('units.speed', [
'name' => 'Speed Units', 'name' => 'Speed Units',
'group' => 'general', 'group' => 'units',
'value' => 'knot', 'value' => 'knot',
'type' => 'select', 'type' => 'select',
'options' => 'km/h,knot', 'options' => 'km/h,knot',
'description' => 'The speed unit', 'description' => 'The speed unit for display',
]); ]);
$this->addSetting('general.altitude_unit', [ $this->addSetting('units.altitude', [
'name' => 'Altitude Units', 'name' => 'Altitude Units',
'group' => 'general', 'group' => 'units',
'value' => 'ft', 'value' => 'ft',
'type' => 'select', 'type' => 'select',
'options' => 'ft,m', 'options' => 'ft=feet,m=meters',
'description' => 'The altitude units', 'description' => 'The altitude unit for display',
]); ]);
$this->addSetting('general.fuel_unit', [ $this->addSetting('units.fuel', [
'name' => 'Fuel Units', 'name' => 'Fuel Units',
'group' => 'general', 'group' => 'units',
'value' => 'lbs', 'value' => 'lbs',
'type' => 'select', 'type' => 'select',
'options' => 'lbs,kg', 'options' => 'lbs,kg',
'description' => 'The units for fuel', 'description' => 'The units for fuel for display',
]);
$this->addSetting('units.volume', [
'name' => 'Volume Units',
'group' => 'units',
'value' => 'gallons',
'type' => 'select',
'options' => 'gallons,l=liters',
'description' => 'The units for fuel for display',
]); ]);
/** /**

View File

@@ -15,7 +15,7 @@ class Altitude extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arr
*/ */
public function __toString() public function __toString()
{ {
$unit = setting('general.altitude_unit'); $unit = setting('units.altitude');
$value = $this->toUnit($unit); $value = $this->toUnit($unit);
return (string) round($value, 2); return (string) round($value, 2);
} }

View File

@@ -15,7 +15,7 @@ class Distance extends \PhpUnitsOfMeasure\PhysicalQuantity\Length implements Arr
*/ */
public function __toString() public function __toString()
{ {
$unit = setting('general.distance_unit'); $unit = setting('units.distance');
$value = $this->toUnit($unit); $value = $this->toUnit($unit);
return (string) round($value, 2); return (string) round($value, 2);
} }

View File

@@ -15,7 +15,7 @@ class Fuel extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass implements Arrayable
*/ */
public function __toString() public function __toString()
{ {
$unit = setting('general.fuel_unit'); $unit = setting('units.fuel');
$value = $this->toUnit($unit); $value = $this->toUnit($unit);
return (string) round($value, 2); return (string) round($value, 2);
} }

View File

@@ -15,7 +15,7 @@ class Mass extends \PhpUnitsOfMeasure\PhysicalQuantity\Mass implements Arrayable
*/ */
public function __toString() public function __toString()
{ {
$unit = setting('general.weight_unit'); $unit = setting('units.weight');
$value = $this->toUnit($unit); $value = $this->toUnit($unit);
return (string) round($value, 2); return (string) round($value, 2);
} }

View File

@@ -15,7 +15,7 @@ class Velocity extends \PhpUnitsOfMeasure\PhysicalQuantity\Velocity implements A
*/ */
public function __toString() public function __toString()
{ {
$unit = setting('general.speed_unit'); $unit = setting('units.speed');
$value = $this->toUnit($unit); $value = $this->toUnit($unit);
return (string) round($value, 2); return (string) round($value, 2);
} }

View File

@@ -15,7 +15,7 @@ class Volume extends \PhpUnitsOfMeasure\PhysicalQuantity\Volume implements Array
*/ */
public function __toString() public function __toString()
{ {
$unit = setting('general.liquid_unit'); $unit = setting('units.volume');
$value = $this->toUnit($unit); $value = $this->toUnit($unit);
return (string) round($value, 2); return (string) round($value, 2);
} }

View File

@@ -43,7 +43,13 @@ if(!function_exists('list_to_assoc')) {
{ {
$ret = []; $ret = [];
foreach($list as $item) { foreach($list as $item) {
$ret[$item] = $item; if(substr_count($item, '=')) {
[$item, $title] = explode('=', $item);
} else {
$title = $item;
}
$ret[$item] = $title;
} }
return $ret; return $ret;

View File

@@ -36,7 +36,8 @@
"irazasyed/laravel-gamp": "1.3.x", "irazasyed/laravel-gamp": "1.3.x",
"vierbergenlars/php-semver": "3.0.x", "vierbergenlars/php-semver": "3.0.x",
"php-units-of-measure/php-units-of-measure": "2.1.x", "php-units-of-measure/php-units-of-measure": "2.1.x",
"markrogoyski/math-php": "^0.38.0" "markrogoyski/math-php": "^0.38.0",
"moneyphp/money": "^3.1"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~7.0", "phpunit/phpunit": "~7.0",

82
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "dbfae0d2bcd1653a30a90bb2e244308c", "content-hash": "4d004ed24ecf6bf961fc610d54213848",
"packages": [ "packages": [
{ {
"name": "arrilot/laravel-widgets", "name": "arrilot/laravel-widgets",
@@ -1861,6 +1861,86 @@
], ],
"time": "2017-12-11T05:05:12+00:00" "time": "2017-12-11T05:05:12+00:00"
}, },
{
"name": "moneyphp/money",
"version": "v3.1.3",
"source": {
"type": "git",
"url": "https://github.com/moneyphp/money.git",
"reference": "5e6a3c98ba2cb190d48d35656967eacf30716034"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/moneyphp/money/zipball/5e6a3c98ba2cb190d48d35656967eacf30716034",
"reference": "5e6a3c98ba2cb190d48d35656967eacf30716034",
"shasum": ""
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"cache/taggable-cache": "^0.4.0",
"doctrine/instantiator": "^1.0.5",
"ext-bcmath": "*",
"ext-gmp": "*",
"ext-intl": "*",
"florianv/swap": "^3.0",
"leanphp/phpspec-code-coverage": "^3.0 || ^4.0",
"moneyphp/iso-currencies": "^3.0",
"php-http/message": "^1.4",
"php-http/mock-client": "^0.3.3",
"phpspec/phpspec": "^3.0",
"phpunit/phpunit": "^5",
"psr/cache": "^1.0",
"sllh/php-cs-fixer-styleci-bridge": "^2.1",
"symfony/phpunit-bridge": "^4"
},
"suggest": {
"ext-bcmath": "Calculate without integer limits",
"ext-gmp": "Calculate without integer limits",
"ext-intl": "Format Money objects with intl",
"florianv/swap": "Exchange rates library for PHP",
"psr/cache-implementation": "Used for Currency caching"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"Money\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mathias Verraes",
"email": "mathias@verraes.net",
"homepage": "http://verraes.net"
},
{
"name": "Frederik Bosch",
"email": "f.bosch@genkgo.nl"
},
{
"name": "Márk Sági-Kazár",
"email": "mark.sagi-kazar@gmail.com"
}
],
"description": "PHP implementation of Fowler's Money pattern",
"homepage": "http://verraes.net/2011/04/fowler-money-pattern-in-php/",
"keywords": [
"Value Object",
"money",
"vo"
],
"time": "2018-02-16T11:04:16+00:00"
},
{ {
"name": "monolog/monolog", "name": "monolog/monolog",
"version": "1.23.0", "version": "1.23.0",

View File

@@ -21,6 +21,15 @@ return [
*/ */
'skin' => env('APP_SKIN', 'default'), 'skin' => env('APP_SKIN', 'default'),
/**
* The ISO "Currency Code" to use
* http://www.xe.com/iso4217.php
*
* Note, do not change this after you've set it, unless you don't
* care that the currencies aren't "exchanged" into the new format
*/
'currency' => 'USD',
/** /**
* Your vaCentral API key * Your vaCentral API key
*/ */

View File

@@ -21,6 +21,15 @@ return [
'phpvms' => [ 'phpvms' => [
'skin' => 'default', 'skin' => 'default',
'vacentral_api_key' => '', 'vacentral_api_key' => '',
/**
* The ISO "Currency Code" to use
* http://www.xe.com/iso4217.php
*
* Note, do not change this after you've set it, unless you don't
* care that the currencies aren't "exchanged" into the new format
*/
'currency' => 'USD',
], ],
# overrides cache.php # overrides cache.php

View File

@@ -161,7 +161,7 @@ $(document).ready(function () {
const caret = $("a." + id + " b"); const caret = $("a." + id + " b");
caret.addClass("pe-7s-angle-down"); caret.addClass("pe-7s-angle-down");
caret.removeClass("pe-7s-angle-up"); caret.removeClass("pe-7s-angle-right");
} }
$(".collapse").on("hide.bs.collapse", function () { $(".collapse").on("hide.bs.collapse", function () {
@@ -169,7 +169,7 @@ $(document).ready(function () {
const id = $(this).attr('id'); const id = $(this).attr('id');
const elem = $("a." + id + " b"); const elem = $("a." + id + " b");
elem.removeClass("pe-7s-angle-down"); elem.removeClass("pe-7s-angle-down");
elem.addClass("pe-7s-angle-up"); elem.addClass("pe-7s-angle-right");
removeItem(storage.menu, id); removeItem(storage.menu, id);
saveStorage("phpvms.admin", storage); saveStorage("phpvms.admin", storage);
@@ -180,7 +180,7 @@ $(document).ready(function () {
const id = $(this).attr('id'); const id = $(this).attr('id');
const caret = $("a." + id + " b"); const caret = $("a." + id + " b");
caret.addClass("pe-7s-angle-down"); caret.addClass("pe-7s-angle-down");
caret.removeClass("pe-7s-angle-up"); caret.removeClass("pe-7s-angle-right");
addItem(storage.menu, id); addItem(storage.menu, id);
saveStorage("phpvms.admin", storage); saveStorage("phpvms.admin", storage);

View File

@@ -5,7 +5,7 @@
<li> <li>
<a data-toggle="collapse" href="#operations_menu" class="menu operations_menu" aria-expanded="true"> <a data-toggle="collapse" href="#operations_menu" class="menu operations_menu" aria-expanded="true">
<h5>operations&nbsp;<b class="pe-7s-angle-up"></b></h5> <h5>operations&nbsp;<b class="pe-7s-angle-right"></b></h5>
</a> </a>
<div class="collapse" id="operations_menu" aria-expanded="true"> <div class="collapse" id="operations_menu" aria-expanded="true">
@@ -24,7 +24,7 @@
<li> <li>
<a data-toggle="collapse" href="#config_menu" class="menu config_menu" aria-expanded="true"> <a data-toggle="collapse" href="#config_menu" class="menu config_menu" aria-expanded="true">
<h5>config&nbsp;<b class="pe-7s-angle-up"></b></h5> <h5>config&nbsp;<b class="pe-7s-angle-right"></b></h5>
</a> </a>
<div class="collapse" id="config_menu" aria-expanded="true"> <div class="collapse" id="config_menu" aria-expanded="true">
@@ -43,7 +43,7 @@
<li> <li>
<a data-toggle="collapse" href="#addons_menu" class="menu addons_menu" aria-expanded="true"> <a data-toggle="collapse" href="#addons_menu" class="menu addons_menu" aria-expanded="true">
<h5>addons&nbsp;<b class="pe-7s-angle-up"></b></h5> <h5>addons&nbsp;<b class="pe-7s-angle-right"></b></h5>
</a> </a>
<div class="collapse" id="addons_menu" aria-expanded="true"> <div class="collapse" id="addons_menu" aria-expanded="true">

View File

@@ -1,6 +1,6 @@
{!! Form::model($grouped_settings, ['route' => ['admin.settings.update'], 'method' => 'post']) !!} {!! Form::model($grouped_settings, ['route' => ['admin.settings.update'], 'method' => 'post']) !!}
@foreach($grouped_settings as $group => $settings) @foreach($grouped_settings as $group => $settings)
<div class="card"> <div class="card border-blue-bottom">
<div class="content table-responsive table-full-width"> <div class="content table-responsive table-full-width">
<table class="table table-hover" id="flights-table"> <table class="table table-hover" id="flights-table">
<thead> <thead>