Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
abalsh
/
Garlix
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8192635b
authored
May 09, 2019
by
Florian Shllaku
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Retriving data from API - live data finished
parent
3aa40a09
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
194 deletions
app/Http/Controllers/API.php
public/currency.json
public/js/main.js
resources/views/currency.blade.php
app/Http/Controllers/API.php
View file @
8192635b
...
...
@@ -4,13 +4,18 @@ namespace App\Http\Controllers;
use
Illuminate\Http\Request
;
use
App\CurrencyListing
;
use
function
GuzzleHttp
\json_encode
;
class
API
extends
Controller
{
public
function
index
()
{
$data
=
CurrencyListing
::
all
(
'iso'
,
'rates'
);
return
$data
;
foreach
(
$data
as
$i
=>
$item
)
{
$data
[
$i
]
=
array
(
$item
[
"iso"
]
=>
$item
[
"rates"
]);
}
$ex
=
str_replace
(
array
(
'['
,
']'
),
array
(
'{'
,
'}'
),
json_encode
(
$data
));
return
'{'
.
str_replace
(
array
(
'{'
,
'}'
),
''
,
$ex
)
.
'}'
;
}
}
public/currency.json
View file @
8192635b
{
"USD"
:
[
{
"iso"
:
"USD"
,
"rates"
:
1.12
}],
"JPY"
:
[
{
"iso"
:
"JPY"
,
"rates"
:
124.4
}],
"BGN"
:
[
{
"iso"
:
"BGN"
,
"rates"
:
1.96
}],
"CZK"
:
[
{
"iso"
:
"CZK"
,
"rates"
:
25.71
}],
"DKK"
:
[
{
"iso"
:
"DKK"
,
"rates"
:
7.47
}],
"GBP"
:
[
{
"iso"
:
"GBP"
,
"rates"
:
0.86
}],
"HUF"
:
[
{
"iso"
:
"HUF"
,
"rates"
:
323.38
}],
"PLN"
:
[
{
"iso"
:
"PLN"
,
"rates"
:
4.29
}],
"RON"
:
[
{
"iso"
:
"RON"
,
"rates"
:
4.76
}],
"SEK"
:
[
{
"iso"
:
"SEK"
,
"rates"
:
10.7
}],
"CHF"
:
[
{
"iso"
:
"CHF"
,
"rates"
:
1.1400000000000001
}],
"ISK"
:
[
{
"iso"
:
"ISK"
,
"rates"
:
136.6
}],
"NOK"
:
[
{
"iso"
:
"NOK"
,
"rates"
:
9.78
}],
"HRK"
:
[
{
"iso"
:
"HRK"
,
"rates"
:
7.41
}],
"RUB"
:
[
{
"iso"
:
"RUB"
,
"rates"
:
72.87
}],
"TRY"
:
[
{
"iso"
:
"TRY"
,
"rates"
:
6.66
}],
"AUD"
:
[
{
"iso"
:
"AUD"
,
"rates"
:
1.5899999999999999
}],
"BRL"
:
[
{
"iso"
:
"BRL"
,
"rates"
:
4.42
}],
"CAD"
:
[
{
"iso"
:
"CAD"
,
"rates"
:
1.5
}],
"CNY"
:
[
{
"iso"
:
"CNY"
,
"rates"
:
7.51
}],
"HDK"
:
[
{
"iso"
:
"HKD"
,
"rates"
:
8.75
}],
"IDR"
:
[
{
"iso"
:
"IDR"
,
"rates"
:
15901.45
}],
"ILS"
:
[
{
"iso"
:
"ILS"
,
"rates"
:
4.01
}],
"INR"
:
[
{
"iso"
:
"INR"
,
"rates"
:
77.26
}],
"KRW"
:
[
{
"iso"
:
"KRW"
,
"rates"
:
1305.08
}],
"MXN"
:
[
{
"iso"
:
"MXN"
,
"rates"
:
21.34
}],
"MYR"
:
[
{
"iso"
:
"MYR"
,
"rates"
:
4.62
}],
"NZD"
:
[
{
"iso"
:
"NZD"
,
"rates"
:
1.69
}],
"PHP"
:
[
{
"iso"
:
"PHP"
,
"rates"
:
57.86
}],
"SGD"
:
[
{
"iso"
:
"SGD"
,
"rates"
:
1.52
}],
"THB"
:
[
{
"iso"
:
"THB"
,
"rates"
:
35.72
}],
"ZAR"
:
[
{
"iso"
:
"ZAR"
,
"rates"
:
16.21
}],
"EUR"
:
[
{
"iso"
:
"EUR"
,
"rates"
:
1
}]
}
\ No newline at end of file
{
"USD"
:
1.24
,
"BGN"
:
1.96
,
"CZK"
:
25.7
,
"DKK"
:
7.47
,
"GBP"
:
0.86
,
"HUF"
:
323
,
"PLN"
:
4.29
,
"RON"
:
4.76
,
"SEK"
:
10.7
,
"CHF"
:
1.1400000000000001
,
"ISK"
:
136
,
"NOK"
:
9.78
,
"HRK"
:
7.41
,
"RUB"
:
72.8
,
"TRY"
:
6.66
,
"AUD"
:
1.5899999999999999
,
"BRL"
:
4.42
,
"CAD"
:
1.5
,
"CNY"
:
7.51
,
"HDK"
:
8.75
,
"IDR"
:
1590
,
"ILS"
:
4.01
,
"INR"
:
77.2
,
"KRW"
:
1305
,
"MXN"
:
21.3
,
"MYR"
:
4.62
,
"NZD"
:
1.69
,
"PHP"
:
57.8
,
"SGD"
:
1.52
,
"THB"
:
35.7
,
"ZAR"
:
16.2
,
"EUR"
:
1
}
public/js/main.js
View file @
8192635b
$
.
getJSON
(
"/currency.json"
,
function
(
data
)
{
$
(
"#go"
).
click
(
function
()
{
$
(
'#From'
).
attr
(
'id'
,
'To'
);
$
(
'#To'
).
attr
(
'id'
,
'From'
);
var
From
;
var
To
;
var
Amount
;
var
From_iso_value
;
var
To_iso_value
;
}
);
// $('#From').on("change",function(){
// From = $("#From option:selected").attr('value');
// return data[From][0]['rates'];
// });
$
(
'#Form'
).
on
(
"change"
,
function
(){
Amount
=
document
.
getElementById
(
"Amount"
).
value
;
From_iso_value
=
$
(
"#From option:selected"
).
attr
(
'value'
);
From
=
data
[
From_iso_value
][
0
][
'rates'
];
To_iso_value
=
$
(
"#To option:selected"
).
attr
(
'value'
);
To
=
data
[
To_iso_value
][
0
][
'rates'
];
console
.
log
((
Amount
/
From
)
*
To
);
});
});
\ No newline at end of file
$
.
ajax
({
url
:
"/api"
,
dataType
:
'json'
,
success
:
function
(
data
){
var
From
;
var
To
;
var
Amount
;
var
From_iso_value
;
var
To_iso_value
;
$
(
'#Form'
).
on
(
"change"
,
function
(){
Amount
=
document
.
getElementById
(
"Amount"
).
value
;
From_iso_value
=
$
(
"#From option:selected"
).
attr
(
'value'
);
From
=
data
[
From_iso_value
];
To_iso_value
=
$
(
"#To option:selected"
).
attr
(
'value'
);
To
=
data
[
To_iso_value
];
console
.
log
((
Amount
/
From
)
*
To
);
});
}
});
\ No newline at end of file
resources/views/currency.blade.php
View file @
8192635b
...
...
@@ -14,7 +14,7 @@
@endforeach
</select>
<br>
<input type="
button
" id="
go
"
onclick="
swapValues
()
"
value="
Swap
">
<input type="
button
" id="
go
" value="
Swap
">
<br>
<select class="
form
-
control
" id="
To
" name="
To
">
@foreach (
$currencies
as
$item
)
...
...
@@ -48,6 +48,14 @@
</div>
</div>
{{-- <script>
function swapValues(){
var tmp = document.getElementById("
From
").value;
document.getElementById("
From
").value = document.getElementById("
To
").value;
document.getElementById("
To
").value = tmp;
}
</script> --}}
{{-- <script>
function swapValues(){
var tmp = document.getElementById("
From
").value;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment