Compare commits
8 Commits
4ed9c834eb
...
059b31dc74
Author | SHA1 | Date | |
---|---|---|---|
059b31dc74 | |||
9c5f6aa815 | |||
8834689abf | |||
53a519ffbd | |||
845077d2a0 | |||
0c8cb81ef3 | |||
99c18cb871 | |||
ec44b0281e |
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,3 +5,6 @@
|
||||
.env
|
||||
|
||||
**/logs/
|
||||
|
||||
# PyCharm
|
||||
**/.idea/
|
||||
|
@ -115,4 +115,62 @@ class Currencies {
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function latestValue(Request $request, Response $response, ModelFactory $factory, $currency_id): Response {
|
||||
$currency = $factory->find(Currency::class)->one($currency_id);
|
||||
$output = [
|
||||
'get_data' => compact('currency_id'),
|
||||
'currency' => null,
|
||||
'value' => null
|
||||
];
|
||||
if ($currency) {
|
||||
$output['currency'] = $currency->asArray();
|
||||
if ($currency->latest()) {
|
||||
$output['value'] = $currency->latest()->asArray();
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function getSources(Request $request, Response $response, ModelFactory $factory, $currency_id): Response {
|
||||
$currency = $factory->find(Currency::class)->one($currency_id);
|
||||
$output = [
|
||||
'get_data' => compact('currency_id'),
|
||||
'currency' => null,
|
||||
'sources' => []
|
||||
];
|
||||
if ($currency) {
|
||||
$output['currency'] = $currency->asArray();
|
||||
if ($currency->sources()) {
|
||||
$output['sources'] = array_map(function($item) {
|
||||
return $item->asArray();
|
||||
}, $currency->sources());
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function addSources(Request $request, Response $response, ModelFactory $factory, $currency_id): Response {
|
||||
$currency = $factory->find(Currency::class)->one($currency_id);
|
||||
$post = json_decode($request->getBody()->getContents());
|
||||
$output = [
|
||||
'get_data' => compact('currency_id'),
|
||||
'post_data' => $post,
|
||||
'currency' => null,
|
||||
'sources' => []
|
||||
];
|
||||
if ($currency) {
|
||||
$output['currency'] = $currency->asArray();
|
||||
$sources = [];
|
||||
if (is_array($post)) {
|
||||
foreach ($post as $obj) {
|
||||
if (!is_object($obj)) {
|
||||
continue;
|
||||
}
|
||||
$sources []= $currency->addSource($obj);
|
||||
}
|
||||
} else {
|
||||
$sources []= $currency->addSource($post);
|
||||
}
|
||||
$output['sources'] = $sources;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
73
app/common/Controller/Sources.php
Normal file
73
app/common/Controller/Sources.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace ProVM\Money\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use ProVM\Common\Factory\Model as ModelFactory;
|
||||
use ProVM\Common\Define\Controller\Json;
|
||||
use ProVM\Money\Source;
|
||||
|
||||
class Sources {
|
||||
use Json;
|
||||
|
||||
public function __invoke(Request $request, Response $response, ModelFactory $factory): Response {
|
||||
$sources = $factory->find(Source::class)->array();
|
||||
$output = compact('sources');
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function get(Request $request, Response $response, ModelFactory $factory, $currency_id, $url): Response {
|
||||
$source = $factory->find(Source::class)->where([['currency_id', $currency_id], ['url', $url]])->one();
|
||||
$output = [
|
||||
'get_data' => compact('currency_id', 'url'),
|
||||
'source' => null
|
||||
];
|
||||
if ($source) {
|
||||
$output['source'] = $source->asArray();
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(Request $request, Response $response, ModelFactory $factory): Response {
|
||||
$post = json_decode($request->getBody()->getContents());
|
||||
$sources = [];
|
||||
if (is_array($post)) {
|
||||
foreach ($post as $obj) {
|
||||
if (!is_object($obj)) {
|
||||
continue;
|
||||
}
|
||||
$sources []= Source::add($factory, $obj);
|
||||
}
|
||||
} else {
|
||||
$sources []= Source::add($factory, $post);
|
||||
}
|
||||
$output = [
|
||||
'post_data' => $post,
|
||||
'sources' => $sources
|
||||
];
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(Request $request, Response $response, ModelFactory $factory, $currency_id, $url) {
|
||||
$post = json_decode($request->getBody()->getContents());
|
||||
$output = [
|
||||
'get_data' => compact('currency_id', 'url'),
|
||||
'post_data' => $post
|
||||
];
|
||||
$source = $factory->find(Source::class)->where([['currency_id', $currency_id], ['url', $url]])->one();
|
||||
$edited = false;
|
||||
if ($source) {
|
||||
$edited = $source->edit($post);
|
||||
$output['source'] = $source->asArray();
|
||||
$output['edited'] = $edited;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, ModelFactory $factory, $currency_id, $url): Response {
|
||||
$source = $factory->find(Source::class)->where([['currency_id', $currency_id], ['url', $url]])->one();
|
||||
$output = ['get_data' => compact('currency_id', 'url'), 'source' => null, 'deleted' => false];
|
||||
if ($source) {
|
||||
$output['source'] = $source->asArray();
|
||||
$status = $source->delete();
|
||||
$output['deleted'] = $status;
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -89,10 +89,10 @@ class Values {
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, ModelFactory $factory, $currency_id, $base_id, $date_time = null): Response {
|
||||
$output = ['get_data' => compact('currency_id', 'date_time', 'base_id')];
|
||||
$output = ['get_data' => compact('currency_id', 'date_time', 'base_id'), 'value' => null, 'deleted' => false];
|
||||
if ($date_time !== null) {
|
||||
$value = $factory->find(Value::class)->where([['currency_id', $currency_id], ['base_id', $base_id], ['date_time', $date_time]])->one();
|
||||
if ($currency) {
|
||||
if ($value) {
|
||||
$output['value'] = $value->asArray();
|
||||
$status = $value->delete();
|
||||
$output['deleted'] = $status;
|
||||
|
@ -50,6 +50,8 @@ server {
|
||||
}
|
||||
|
||||
add_header 'Access-Control-Allow-Origin' 'http://localhost:8080';
|
||||
add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,OPTIONS';
|
||||
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
|
||||
|
||||
location ~ \.php {
|
||||
try_files $uri =404;
|
||||
|
@ -3,6 +3,7 @@ use ProVM\Money\Common\Controller\API;
|
||||
|
||||
include_once 'currencies.php';
|
||||
include_once 'values.php';
|
||||
include_once 'sources.php';
|
||||
|
||||
$app->get('/', API::class);
|
||||
|
||||
|
@ -14,12 +14,20 @@ $app->group('/currency/{currency_id}', function($app) {
|
||||
$app->put('/edit[/]', [Currencies::class, 'edit']);
|
||||
$app->delete('/delete[/]', [Currencies::class, 'delete']);
|
||||
$app->group('/values', function($app) {
|
||||
$app->get('/latest[/]', [Currencies::class, 'latestValue']);
|
||||
$app->post('/add[/]', [Currencies::class, 'addValues']);
|
||||
$app->get('[/]', [Currencies::class, 'getValues']);
|
||||
$app->options('[/]', function (Request $request, Response $response): Response {
|
||||
return $response;
|
||||
});
|
||||
});
|
||||
$app->group('/sources', function($app) {
|
||||
$app->post('/add[/]', [Currencies::class, 'addSources']);
|
||||
$app->get('[/]', [Currencies::class, 'getSources']);
|
||||
$app->options('[/]', function (Request $request, Response $response): Response {
|
||||
return $response;
|
||||
});
|
||||
});
|
||||
$app->get('[/]', [Currencies::class, 'get']);
|
||||
$app->options('[/]', function (Request $request, Response $response): Response {
|
||||
return $response;
|
||||
|
13
app/resources/routes/sources.php
Normal file
13
app/resources/routes/sources.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
use ProVM\Money\Common\Controller\Sources;
|
||||
|
||||
$app->group('/sources', function($app) {
|
||||
$app->post('/add[/]', [Sources::class, 'add']);
|
||||
$app->get('[/]', Sources::class);
|
||||
});
|
||||
|
||||
$app->group('/source/{currency_id}/{url}', function($app) {
|
||||
$app->put('/edit[/]', [Sources::class, 'edit']);
|
||||
$app->delete('/delete[/]', [Sources::class, 'delete']);
|
||||
$app->get('[/]', [Sources::class, 'get']);
|
||||
});
|
@ -1,7 +1,15 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
if (file_exists(implode(DIRECTORY_SEPARATOR, [dirname(__DIR__, 2), '.env']))) {
|
||||
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 2));
|
||||
$dotenv->load();
|
||||
}
|
||||
|
||||
return [
|
||||
'base_path' => $_ENV['BASE_PATH'] ?? null,
|
||||
'base_url' => $_ENV['BASE_URL'] ?? null,
|
||||
'locations' => DI\decorate(function($prev, Container $container) {
|
||||
$arr = (array) $prev;
|
||||
$arr['base'] = dirname(__DIR__, 2);
|
||||
|
@ -44,7 +44,7 @@ $container = $builder->build();
|
||||
$app = Bridge::create($container);
|
||||
include_once 'databases.php';
|
||||
|
||||
if ($container->has('base_url')) {
|
||||
if ($container->has('base_url') and $container->get('base_path') !== null) {
|
||||
$app->setBasePath($container->get('base_url'));
|
||||
}
|
||||
$app->add(new ProVM\Money\Common\Middleware\Cors());
|
||||
|
@ -43,7 +43,7 @@ class CreateValues extends Phinx\Migration\AbstractMigration
|
||||
'unique' => false,
|
||||
])
|
||||
->create();
|
||||
$this->table('currencies', [
|
||||
/*$this->table('currencies', [
|
||||
'id' => false,
|
||||
'primary_key' => ['id'],
|
||||
'engine' => 'InnoDB',
|
||||
@ -72,6 +72,6 @@ class CreateValues extends Phinx\Migration\AbstractMigration
|
||||
'encoding' => 'utf8mb4',
|
||||
'after' => 'code',
|
||||
])
|
||||
->create();
|
||||
->create();*/
|
||||
}
|
||||
}
|
||||
|
52
db/migrations/20210320020631_create_sources.php
Normal file
52
db/migrations/20210320020631_create_sources.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateSources extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$this->table('sources', [
|
||||
'id' => false,
|
||||
'primary_key' => ['currency_id', 'url'],
|
||||
'engine' => 'InnoDB',
|
||||
'encoding' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_general_ci',
|
||||
'comment' => '',
|
||||
'row_format' => 'DYNAMIC',
|
||||
])
|
||||
->addColumn('currency_id', 'integer', [
|
||||
'null' => false,
|
||||
'limit' => '10',
|
||||
'signed' => false,
|
||||
'after' => 'id',
|
||||
])
|
||||
->addColumn('url', 'string', [
|
||||
'null' => false,
|
||||
'limit' => 255,
|
||||
'collation' => 'utf8mb4_general_ci',
|
||||
'encoding' => 'utf8mb4',
|
||||
'after' => 'currency_id',
|
||||
])
|
||||
->addColumn('frecuency', 'string', [
|
||||
'null' => false,
|
||||
'limit' => 100,
|
||||
'collation' => 'utf8mb4_general_ci',
|
||||
'encoding' => 'utf8mb4',
|
||||
'after' => 'url',
|
||||
])
|
||||
->create();
|
||||
}
|
||||
}
|
@ -9,6 +9,8 @@ services:
|
||||
volumes:
|
||||
- .:/code
|
||||
- ./app/docker/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
depends_on:
|
||||
- app-php
|
||||
|
||||
app-php:
|
||||
container_name: money_app_php
|
||||
@ -28,6 +30,8 @@ services:
|
||||
volumes:
|
||||
- .:/code
|
||||
- ./ui/docker/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
depends_on:
|
||||
- ui-php
|
||||
|
||||
ui-php:
|
||||
container_name: money_ui_php
|
||||
@ -39,14 +43,6 @@ services:
|
||||
ports:
|
||||
- 9124:9000
|
||||
|
||||
ui-gulp:
|
||||
container_name: money_ui_gulp
|
||||
build:
|
||||
context: ./ui/docker
|
||||
dockerfile: GULP.Dockerfile
|
||||
volumes:
|
||||
- ./ui:/app
|
||||
|
||||
db:
|
||||
container_name: money_db
|
||||
image: mariadb:latest
|
||||
|
@ -16,9 +16,28 @@ class Currency extends Model {
|
||||
public function values(): ?array {
|
||||
if ($this->values === null) {
|
||||
$this->values = $this->parentOf(Value::class, [Model::CHILD_KEY => 'currency_id']);
|
||||
if ($this->values) {
|
||||
usort($this->values, function($a, $b) {
|
||||
return $b->dateTime()->timestamp - $a->dateTime()->timestamp;
|
||||
});
|
||||
}
|
||||
}
|
||||
return $this->values;
|
||||
}
|
||||
protected $latest;
|
||||
public function latest(): ?Value {
|
||||
if ($this->latest === null) {
|
||||
$this->latest = $this->values()[0];
|
||||
}
|
||||
return $this->latest;
|
||||
}
|
||||
protected $sources;
|
||||
public function sources(): ?array {
|
||||
if ($this->sources === null) {
|
||||
$this->sources = $this->parentOf(Source::class, [Model::CHILD_KEY => 'currency_id']);
|
||||
}
|
||||
return $this->sources;
|
||||
}
|
||||
|
||||
protected static $fields = ['code', 'name'];
|
||||
public static function add(ModelFactory $factory, $info) {
|
||||
@ -37,7 +56,7 @@ class Currency extends Model {
|
||||
protected function checkCode(string $code): bool {
|
||||
return ($this->find(Currency::class)->where([['code', $code]])->one()) ? true : false;
|
||||
}
|
||||
public function edit($info) {
|
||||
public function edit($info): bool {
|
||||
$data = array_intersect_key((array) $info, array_combine(self::$fields, self::$fields));
|
||||
$edited = false;
|
||||
foreach ($data as $field => $value) {
|
||||
@ -60,4 +79,10 @@ class Currency extends Model {
|
||||
$result = Value::add($this->factory, $arr);
|
||||
return $result;
|
||||
}
|
||||
public function addSource($info) {
|
||||
$arr = (array) $info;
|
||||
$arr['currency_id'] = (int) $this->id;
|
||||
$result = Source::add($this->factory, $arr);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
67
src/Source.php
Normal file
67
src/Source.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace ProVM\Money;
|
||||
|
||||
use Carbon\CarbonInterval;
|
||||
use ProVM\Common\Alias\Model;
|
||||
|
||||
/**
|
||||
* @property Currency $currency_id
|
||||
* @property string $url
|
||||
* @property \DateInterval $frecuency
|
||||
*/
|
||||
class Source extends Model {
|
||||
public static $_table = 'sources';
|
||||
public static $_id_column = ['currency_id', 'url'];
|
||||
|
||||
protected $currency;
|
||||
public function currency(): ?Currency {
|
||||
if ($this->currency === null) {
|
||||
$this->currency = $this->childOf(Currency::class, [Model::SELF_KEY => 'currency_id']);
|
||||
}
|
||||
return $this->currency;
|
||||
}
|
||||
public function frecuency(\DateInterval $frecuency = null) {
|
||||
if ($frecuency == null) {
|
||||
return new \CarbonInterval($this->fecuency);
|
||||
}
|
||||
$this->frecuency = CarbonInterval::getDateIntervalSpec($frecuency);
|
||||
}
|
||||
|
||||
protected static $fields = ['currency_id', 'url', 'frecuency'];
|
||||
public static function add(ModelFactory $factory, $info) {
|
||||
$input = array_intersect_key((array) $info, array_combine(self::$fields, self::$fields));
|
||||
$source = $factory->find(Source::class)->where([['currency_id', $input['currency_id']], ['url', $input['url']]])->one();
|
||||
$created = false;
|
||||
$result = (object) compact('input', 'source', 'created');
|
||||
if (!$value) {
|
||||
$source = $factory->create(Source::class, $input);
|
||||
$created = $source->save();
|
||||
$result->created = $created;
|
||||
}
|
||||
$result->value = $source->asArray();
|
||||
return $result;
|
||||
}
|
||||
public function edit($info): bool {
|
||||
$data = array_intersect_key((array) $info, array_combine(self::$fields, self::$fields));
|
||||
$edited = false;
|
||||
foreach ($data as $field => $value) {
|
||||
if ($this->{$field} != $value) {
|
||||
if ($field == 'currency_id' or $field == 'url') {
|
||||
continue;
|
||||
}
|
||||
$this->{$field} = $value;
|
||||
$edited = true;
|
||||
}
|
||||
}
|
||||
if ($edited) {
|
||||
$edited = $this->save();
|
||||
}
|
||||
return $edited;
|
||||
}
|
||||
public function asArray(): array {
|
||||
$output = parent::asArray();
|
||||
$output['currency'] = $this->currency()->asArray();
|
||||
$output['frecuency'] = $this->frecuency()->format('Y-m-d H:i:s');
|
||||
return $output;
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ class Value extends Model {
|
||||
$result->value = $value->asArray();
|
||||
return $result;
|
||||
}
|
||||
public function edit($info) {
|
||||
public function edit($info): bool {
|
||||
$data = array_intersect_key((array) $info, array_combine(self::$fields, self::$fields));
|
||||
$edited = false;
|
||||
foreach ($data as $field => $value) {
|
||||
|
@ -18,16 +18,16 @@ let output_dir = './public/assets'
|
||||
|
||||
function js(done) {
|
||||
return src(path.join(source_dir, 'js', '**', '*.js'))
|
||||
.pipe(bro())
|
||||
//.pipe(bro())
|
||||
.pipe(concat('main.js'))
|
||||
.pipe(dest(path.join(output_dir, 'scripts')))
|
||||
.pipe(sourcemaps.init({loadMaps: true}))
|
||||
.pipe(babel({
|
||||
presets: ['@babel/preset-env']
|
||||
}))
|
||||
.pipe(sourcemaps.init({loadMaps: true}))
|
||||
.pipe(uglify())
|
||||
.pipe(sourcemaps.write('./maps'))
|
||||
.pipe(rename('main.min.js'))
|
||||
.pipe(sourcemaps.write('./maps'))
|
||||
.pipe(dest(path.join(output_dir, 'scripts')))
|
||||
}
|
||||
|
||||
@ -58,6 +58,6 @@ function css(done) {
|
||||
.pipe(dest(path.join(output_dir, 'images')))
|
||||
}*/
|
||||
|
||||
exports.watch = watch(source_dir, parallel(js, css/*, html*/))
|
||||
//exports.watch = watch(source_dir, parallel(js, css/*, html*/))
|
||||
|
||||
exports.default = parallel(js, css/*, html*/)
|
||||
|
File diff suppressed because it is too large
Load Diff
4
ui/public/assets/scripts/main.min.js
vendored
4
ui/public/assets/scripts/main.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["main.js"],"names":["$","require"],"mappings":"aAAA,IAAMA,EAAIC,QAAQ,UAClBA,QAAQ","file":"../main.min.js","sourcesContent":["const $ = require(\"jquery\")\r\nrequire(\"semantic-ui\")\r\n"]}
|
1
ui/public/assets/scripts/maps/main.min.js.map
Normal file
1
ui/public/assets/scripts/maps/main.min.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"../main.min.js","sources":["main.js"],"sourcesContent":["\"use strict\";\n\nfunction formatValue(value, base) {\n return new Intl.NumberFormat('es-CL', {\n style: 'currency',\n currency: base,\n minimumSignificantDigits: 2\n }).format(value);\n}\n\nfunction formatDate(date) {\n return new Intl.DateTimeFormat('es-CL', {\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit'\n }).format(date);\n}\n\nfunction readyDate(date) {\n return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();\n}"],"names":["formatValue","value","base","Intl","NumberFormat","style","currency","minimumSignificantDigits","format","formatDate","date","DateTimeFormat","year","month","day","hour","minute","second","readyDate","getFullYear","getMonth","getDate","getHours","getMinutes","getSeconds"],"mappings":"aAEA,SAASA,YAAYC,EAAOC,GAC1B,OAAO,IAAIC,KAAKC,aAAa,QAAS,CACpCC,MAAO,WACPC,SAAUJ,EACVK,yBAA0B,IACzBC,OAAOP,GAGZ,SAASQ,WAAWC,GAClB,OAAO,IAAIP,KAAKQ,eAAe,QAAS,CACtCC,KAAM,UACNC,MAAO,UACPC,IAAK,UACLC,KAAM,UACNC,OAAQ,UACRC,OAAQ,YACPT,OAAOE,GAGZ,SAASQ,UAAUR,GACjB,OAAOA,EAAKS,cAAgB,KAAOT,EAAKU,WAAa,GAAK,IAAMV,EAAKW,UAAY,IAAMX,EAAKY,WAAa,IAAMZ,EAAKa,aAAe,IAAMb,EAAKc"}
|
@ -1,4 +1,14 @@
|
||||
global.$ = global.jQuery = require("jquery")
|
||||
// Loads all Semantic javascripts
|
||||
//= require semantic-ui
|
||||
require('fomantic-ui-sass')
|
||||
function formatValue(value, base) {
|
||||
return (new Intl.NumberFormat('es-CL', {style: 'currency', currency: base, minimumSignificantDigits: 2})).format(value)
|
||||
}
|
||||
function formatDate(date) {
|
||||
return (new Intl.DateTimeFormat('es-CL', {year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit'})).format(date)
|
||||
}
|
||||
function readyDate(date) {
|
||||
return date.getFullYear()
|
||||
+ '-' + (date.getMonth() + 1)
|
||||
+ '-' + date.getDate()
|
||||
+ ' ' + date.getHours()
|
||||
+ ':' + date.getMinutes()
|
||||
+ ':' + date.getSeconds()
|
||||
}
|
||||
|
24
ui/resources/views/currencies/base.blade.php
Normal file
24
ui/resources/views/currencies/base.blade.php
Normal file
@ -0,0 +1,24 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_content')
|
||||
<h2 class="ui header">
|
||||
@yield('title')
|
||||
</h2>
|
||||
@yield('content')
|
||||
<div class="ui basic modal" id="loading">
|
||||
<div class="ui active dimmer">
|
||||
<div class="ui elastic loader"></div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
$(document).ready(() => {
|
||||
$('#loading').modal({
|
||||
blurring: true
|
||||
}).modal('show')
|
||||
.find('.dimmer').css('background-color', 'transparent')
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -1,10 +1,34 @@
|
||||
@extends('layout.base')
|
||||
@extends('currencies.base')
|
||||
|
||||
@section('page_content')
|
||||
<h2 class="ui header">
|
||||
Monedas
|
||||
</h2>
|
||||
<div class="ui link list" id="currencies">
|
||||
@section('title')
|
||||
Monedas
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<table class="ui collapsing table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Código</td>
|
||||
<th>Moneda</td>
|
||||
<th id="add_currency"><i class="plus icon"></i></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="currencies"></tbody>
|
||||
</table>
|
||||
<div class="ui modal" id="add_modal">
|
||||
<div class="content">
|
||||
<form class="ui form">
|
||||
<div class="inline field">
|
||||
<label>Código</label>
|
||||
<input type="text" name="code" />
|
||||
</div>
|
||||
<div class="inline field">
|
||||
<label>Nombre</label>
|
||||
<input type="text" name="name" />
|
||||
</div>
|
||||
<button class="ui button">Agregar</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@ -12,10 +36,18 @@
|
||||
<script type="text/javascript">
|
||||
let currencies = {
|
||||
id: '#currencies',
|
||||
loading: '#loading',
|
||||
add_button: '#add_currency',
|
||||
add_modal: '#add_modal',
|
||||
items: [],
|
||||
setup: function() {
|
||||
$(this.add_modal).modal()
|
||||
$(this.add_button).css('cursor', 'pointer').click((e) => {
|
||||
this.add()
|
||||
})
|
||||
this.load().then((data) => {
|
||||
this.build(data)
|
||||
$(this.loading).modal('hide')
|
||||
})
|
||||
},
|
||||
load: function() {
|
||||
@ -27,10 +59,68 @@
|
||||
build: function() {
|
||||
$(this.id).html('')
|
||||
$.each(this.items, (i, el) => {
|
||||
let item = $('<a></a>').attr('class', 'item').attr('href', '{{$urls->base}}/currency/' + el.id)
|
||||
.html(el.name)
|
||||
let item = $('<tr></tr>').append(
|
||||
$('<td></td>').append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/currency/' + el.id)
|
||||
.html(el.code)
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/currency/' + el.id)
|
||||
.html(el.name)
|
||||
)
|
||||
).append(
|
||||
$('<td></td>').attr('class', 'remove_currency').attr('data-id', el.id).append(
|
||||
$('<i></i>').attr('class', 'small minus icon')
|
||||
).css('cursor', 'pointer').click((e) => {
|
||||
this.remove($(e.currentTarget).attr('data-id'))
|
||||
})
|
||||
)
|
||||
$(this.id).append(item)
|
||||
})
|
||||
},
|
||||
add: function() {
|
||||
$(this.add_modal).find('form').trigger('reset').submit((e) => {
|
||||
e.preventDefault()
|
||||
this.doAdd()
|
||||
return false
|
||||
})
|
||||
$(this.add_modal).modal('show')
|
||||
},
|
||||
doAdd: function() {
|
||||
let url = '{{$urls->api}}/currencies/add'
|
||||
let form = $(this.add_modal).find('form')
|
||||
let info = {
|
||||
code: form.find("[name='code']").val(),
|
||||
name: form.find("[name='name']").val()
|
||||
}
|
||||
$(this.add_modal).modal('hide')
|
||||
$(this.loading).modal('show')
|
||||
$.post(url, JSON.stringify(info), (data) => {
|
||||
if (data.currencies[0].created) {
|
||||
this.load().then((data) => {
|
||||
this.build(data)
|
||||
$(this.loading).modal('hide')
|
||||
})
|
||||
}
|
||||
}, 'json')
|
||||
},
|
||||
remove: function(currency_id) {
|
||||
let url = '{{$urls->api}}/currency/' + currency_id + '/delete'
|
||||
$(this.loading).modal('show')
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'DELETE',
|
||||
dataType: 'json',
|
||||
success: (data) => {
|
||||
if (data.deleted) {
|
||||
this.load().then((data) => {
|
||||
this.build(data)
|
||||
$(this.loading).modal('hide')
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
|
@ -1,8 +1,11 @@
|
||||
@extends('layout.base')
|
||||
@extends('currencies.base')
|
||||
|
||||
@section('page_content')
|
||||
<h2 class="ui header">Moneda - <span class="name"></span></h2>
|
||||
<h3 class="ui header" class="code"></h3>
|
||||
@section('title')
|
||||
Moneda - <span class="c_name"></span>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<h3 class="ui header c_code"></h3>
|
||||
<table class="ui table">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -17,7 +20,7 @@
|
||||
</table>
|
||||
<div class="ui modal" id="add_modal">
|
||||
<div class="header">
|
||||
Agregar Valor para <span class="name"></span>
|
||||
Agregar Valor para <span class="c_name"></span>
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form">
|
||||
@ -53,12 +56,6 @@
|
||||
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
function formatDate(date) {
|
||||
return (new Intl.DateTimeFormat('es-CL', {year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit'})).format(date)
|
||||
}
|
||||
function formatValue(value, base) {
|
||||
return (new Intl.NumberFormat('es-CL', {style: 'currency', currency: base, minimumSignificantDigits: 2})).format(value)
|
||||
}
|
||||
let currency = {
|
||||
id: {{$currency_id}},
|
||||
data: {
|
||||
@ -67,33 +64,36 @@
|
||||
code: ''
|
||||
},
|
||||
map: {
|
||||
name: '.name',
|
||||
code: '.code'
|
||||
name: '.c_name',
|
||||
code: '.c_code'
|
||||
},
|
||||
values_id: '#values',
|
||||
values: [],
|
||||
add_button: '#add_value',
|
||||
modal: '#add_modal',
|
||||
add_modal: '#add_modal',
|
||||
loading: '#loading',
|
||||
setup: function() {
|
||||
$(this.values_id).parent().hide()
|
||||
$(this.values_id).hide()
|
||||
this.buildModal()
|
||||
$(this.add_button).css('cursor', 'pointer').click((e) => {
|
||||
this.addValue()
|
||||
})
|
||||
this.getData().then(() => {
|
||||
this.getValues()
|
||||
this.getValues().then(() => {
|
||||
$(this.loading).modal('hide')
|
||||
})
|
||||
})
|
||||
},
|
||||
buildModal: function() {
|
||||
this.getCurrencies()
|
||||
$(this.modal).modal()
|
||||
$(this.modal).find('.ui.calendar').calendar()
|
||||
$(this.modal).find('form').submit((e) => {
|
||||
$(this.add_modal).modal()
|
||||
$(this.add_modal).find('.ui.calendar').calendar()
|
||||
$(this.add_modal).find('form').submit((e) => {
|
||||
e.preventDefault()
|
||||
this.doAddValue()
|
||||
return false
|
||||
})
|
||||
$(this.modal).find('.ui.dropdown').dropdown()
|
||||
$(this.add_modal).find('.ui.dropdown').dropdown()
|
||||
},
|
||||
getData: function() {
|
||||
let url = '{{$urls->api}}/currency/' + this.id
|
||||
@ -119,20 +119,24 @@
|
||||
$(this.values_id).html('')
|
||||
$.each(this.values, (i, el) => {
|
||||
let row = $('<tr></tr>').append(
|
||||
$('<td></td>').html(formatDate(el.fecha))
|
||||
$('<td></td>').html(formatDate(new Date(el.date_time)))
|
||||
).append(
|
||||
$('<td></td>').html(formatValue(el.value, el.base.code))
|
||||
).append(
|
||||
$('<td></td>')
|
||||
$('<td></td>').attr('class', 'remove_value').attr('data-base', el.base.id).attr('data-date_time', el.date_time).append(
|
||||
$('<i></i>').attr('class', 'minus icon')
|
||||
).css('cursor', 'pointer').click((e) => {
|
||||
this.removeValue($(e.currentTarget).attr('data-base'), $(e.currentTarget).attr('data-date_time'))
|
||||
})
|
||||
)
|
||||
$(this.values_id).append(row)
|
||||
})
|
||||
$(this.values_id).parent().show()
|
||||
$(this.values_id).show()
|
||||
},
|
||||
getCurrencies: function() {
|
||||
let url = '{{$urls->api}}/currencies'
|
||||
$.getJSON(url, (data) => {
|
||||
let dp = $(this.modal).find('.ui.dropdown')
|
||||
let dp = $(this.add_modal).find('.ui.dropdown')
|
||||
values = []
|
||||
$.each(data.currencies, (i, el) => {
|
||||
values.push({name: el.name, value: el.id, text: el.name})
|
||||
@ -141,25 +145,42 @@
|
||||
})
|
||||
},
|
||||
addValue: function() {
|
||||
$(this.modal).find('form').trigger('reset')
|
||||
$(this.modal).modal('show')
|
||||
$(this.add_modal).find('form').trigger('reset')
|
||||
$(this.add_modal).modal('show')
|
||||
},
|
||||
doAddValue: function() {
|
||||
let form = $(this.modal).find('form')
|
||||
info = {
|
||||
date_time: (new Date(form.find('.ui.calendar').calendar('get date'))),
|
||||
let form = $(this.add_modal).find('form')
|
||||
let info = {
|
||||
date_time: readyDate(new Date(form.find('.ui.calendar').calendar('get date'))),
|
||||
value: form.find("[name='valor']").val(),
|
||||
base_id: form.find('.ui.dropdown').dropdown('get value')
|
||||
}
|
||||
let url = '{{$urls->api}}/currency/' + this.data.id + '/values/add'
|
||||
$.post(url, info, (data) => {
|
||||
console.debug(data)
|
||||
$(this.add_modal).modal('hide')
|
||||
$(this.loading).modal('show')
|
||||
$.post(url, JSON.stringify(info), (data) => {
|
||||
if (data.values[0].created) {
|
||||
window.location.reload()
|
||||
return false
|
||||
this.getValues()
|
||||
}
|
||||
}, 'json').then(() => {
|
||||
$(this.loading).modal('hide')
|
||||
})
|
||||
},
|
||||
removeValue: function(base_id, date_time) {
|
||||
let url = '{{$urls->api}}/value/' + this.data.id + '/' + base_id + '/' + encodeURI(date_time) + '/delete'
|
||||
$(this.loading).modal('show')
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'DELETE',
|
||||
dataType: 'json',
|
||||
success: (data) => {
|
||||
if (data.deleted) {
|
||||
this.getValues().then(() => {
|
||||
$(this.loading).modal('hide')
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
$(this.modal).modal('hide')
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
|
@ -2,6 +2,79 @@
|
||||
|
||||
@section('page_content')
|
||||
<h2 class="ui header">
|
||||
Inicio
|
||||
Monedas
|
||||
</h2>
|
||||
<div class="ui cards" id="cards">
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
let cards = {
|
||||
id: '#cards',
|
||||
setup: function() {
|
||||
this.getCurrencies()
|
||||
},
|
||||
data: [],
|
||||
getCurrencies: function() {
|
||||
let url = '{{$urls->api}}/currencies'
|
||||
return $.getJSON(url, (data) => {
|
||||
let promises = []
|
||||
$.each(data.currencies, (i, el) => {
|
||||
this.data[el.id] = {'currency': el, 'value': null}
|
||||
promises.push(this.getValue(el.id))
|
||||
})
|
||||
Promise.all(promises).then(() => {
|
||||
this.buildCards()
|
||||
})
|
||||
})
|
||||
},
|
||||
getValue: function(currency_id) {
|
||||
let url = '{{$urls->api}}/currency/' + currency_id + '/values/latest'
|
||||
return $.getJSON(url, (data) => {
|
||||
if (data.value == null) {
|
||||
this.data = this.data.filter(function(item) {
|
||||
return item.currency.id != data.currency.id
|
||||
})
|
||||
return
|
||||
}
|
||||
idx = this.data.findIndex((item, i, arr) => item.currency.id == data.currency.id)
|
||||
if (idx < 0) {
|
||||
return
|
||||
}
|
||||
this.data[idx].value = data.value
|
||||
}).fail(() => {
|
||||
this.data = this.data.filter(function(item) {
|
||||
return item.currency.id == currency_id
|
||||
})
|
||||
})
|
||||
},
|
||||
buildCards: function() {
|
||||
$.each(this.data, (i, el) => {
|
||||
$(this.id).append(
|
||||
this.buildCard(el)
|
||||
)
|
||||
})
|
||||
},
|
||||
buildCard: function(currency) {
|
||||
let card = $('<div></div>').attr('class', 'card').append(
|
||||
$('<div></div>').attr('class', 'content').append(
|
||||
$('<a></a>').attr('class', 'center aligned header').attr('href', '{{$urls->base}}/value/' + currency.currency.id + '/' + currency.value.base.id + '/' + encodeURI(readyDate(new Date(currency.value.date_time))))
|
||||
.html(formatValue(currency.value.value, currency.value.base.code))
|
||||
).append(
|
||||
$('<div></div>').attr('class', 'center aligned description').append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/value/' + currency.currency.id + '/' + currency.value.base.id + '/' + encodeURI(readyDate(new Date(currency.value.date_time))))
|
||||
.html(formatDate(new Date(currency.value.date_time)))
|
||||
)
|
||||
)
|
||||
).append(
|
||||
$('<a></a>').attr('class', 'center aligned extra content').attr('href', '{{$urls->base}}/currency/' + currency.currency.id).html(currency.currency.name)
|
||||
)
|
||||
return card
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
cards.setup()
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -1,3 +1,4 @@
|
||||
<script type="text/javascript" src="{{$urls->scripts}}/main.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/semantic.min.js" integrity="sha512-1Nyd5H4Aad+OyvVfUOkO/jWPCrEvYIsQENdnVXt1+Jjc4NoJw28nyRdrpOCyFH4uvR3JmH/5WmfX1MJk2ZlhgQ==" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="{{$urls->scripts}}/main.min.js"></script>
|
||||
@stack('scripts')
|
||||
|
@ -44,8 +44,8 @@ $container = $builder->build();
|
||||
$app = Bridge::create($container);
|
||||
include_once 'databases.php';
|
||||
|
||||
if ($container->has('base_url')) {
|
||||
$app->setBasePath($container->get('base_url'));
|
||||
if ($container->has('base_path') and $container->get('base_path') !== null) {
|
||||
$app->setBasePath($container->get('base_path'));
|
||||
}
|
||||
$app->addRoutingMiddleware();
|
||||
|
||||
|
@ -1,7 +1,15 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
if (file_exists(implode(DIRECTORY_SEPARATOR, [dirname(__DIR__, 2), '.env']))) {
|
||||
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 2));
|
||||
$dotenv->load();
|
||||
}
|
||||
|
||||
return [
|
||||
'base_path' => $_ENV['BASE_PATH'] ?? null,
|
||||
'base_url' => $_ENV['BASE_URL'] ?? null,
|
||||
'locations' => DI\decorate(function($prev, Container $container) {
|
||||
$arr = (array) $prev;
|
||||
$arr['base'] = dirname(__DIR__, 2);
|
||||
|
Reference in New Issue
Block a user