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;
...
@@ -4,13 +4,18 @@ namespace App\Http\Controllers;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
App\CurrencyListing
;
use
App\CurrencyListing
;
use
function
GuzzleHttp
\json_encode
;
class
API
extends
Controller
class
API
extends
Controller
{
{
public
function
index
()
public
function
index
()
{
{
$data
=
CurrencyListing
::
all
(
'iso'
,
'rates'
);
$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"
:
[
"USD"
:
1.24
,
{
"iso"
:
"USD"
,
"BGN"
:
1.96
,
"rates"
:
1.12
}],
"CZK"
:
25.7
,
"JPY"
:
[
{
"DKK"
:
7.47
,
"iso"
:
"JPY"
,
"rates"
:
124.4
"GBP"
:
0.86
,
}],
"BGN"
:
[
"HUF"
:
323
,
{
"iso"
:
"BGN"
,
"PLN"
:
4.29
,
"rates"
:
1.96
}],
"RON"
:
4.76
,
"CZK"
:
[
{
"SEK"
:
10.7
,
"iso"
:
"CZK"
,
"rates"
:
25.71
"CHF"
:
1.1400000000000001
,
}],
"DKK"
:
[
"ISK"
:
136
,
{
"iso"
:
"DKK"
,
"NOK"
:
9.78
,
"rates"
:
7.47
}],
"HRK"
:
7.41
,
"GBP"
:
[
{
"RUB"
:
72.8
,
"iso"
:
"GBP"
,
"rates"
:
0.86
"TRY"
:
6.66
,
}],
"HUF"
:
[
"AUD"
:
1.5899999999999999
,
{
"iso"
:
"HUF"
,
"BRL"
:
4.42
,
"rates"
:
323.38
}],
"CAD"
:
1.5
,
"PLN"
:
[
{
"CNY"
:
7.51
,
"iso"
:
"PLN"
,
"rates"
:
4.29
"HDK"
:
8.75
,
}],
"RON"
:
[
"IDR"
:
1590
,
{
"iso"
:
"RON"
,
"ILS"
:
4.01
,
"rates"
:
4.76
}],
"INR"
:
77.2
,
"SEK"
:
[
{
"KRW"
:
1305
,
"iso"
:
"SEK"
,
"rates"
:
10.7
"MXN"
:
21.3
,
}],
"CHF"
:
[
"MYR"
:
4.62
,
{
"iso"
:
"CHF"
,
"NZD"
:
1.69
,
"rates"
:
1.1400000000000001
}],
"PHP"
:
57.8
,
"ISK"
:
[
{
"SGD"
:
1.52
,
"iso"
:
"ISK"
,
"rates"
:
136.6
"THB"
:
35.7
,
}],
"NOK"
:
[
"ZAR"
:
16.2
,
{
"iso"
:
"NOK"
,
"EUR"
:
1
"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
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(){
$
.
ajax
({
// From = $("#From option:selected").attr('value');
url
:
"/api"
,
// return data[From][0]['rates'];
dataType
:
'json'
,
// });
success
:
function
(
data
){
var
From
;
$
(
'#Form'
).
on
(
"change"
,
function
(){
var
To
;
Amount
=
document
.
getElementById
(
"Amount"
).
value
;
var
Amount
;
From_iso_value
=
$
(
"#From option:selected"
).
attr
(
'value'
);
var
From_iso_value
;
From
=
data
[
From_iso_value
][
0
][
'rates'
];
var
To_iso_value
;
To_iso_value
=
$
(
"#To option:selected"
).
attr
(
'value'
);
$
(
'#Form'
).
on
(
"change"
,
function
(){
To
=
data
[
To_iso_value
][
0
][
'rates'
];
console
.
log
((
Amount
/
From
)
*
To
);
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
];
\ No newline at end of file
console
.
log
((
Amount
/
From
)
*
To
);
});
}
});
\ No newline at end of file
resources/views/currency.blade.php
View file @
8192635b
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
@endforeach
@endforeach
</select>
</select>
<br>
<br>
<input type="
button
" id="
go
"
onclick="
swapValues
()
"
value="
Swap
">
<input type="
button
" id="
go
" value="
Swap
">
<br>
<br>
<select class="
form
-
control
" id="
To
" name="
To
">
<select class="
form
-
control
" id="
To
" name="
To
">
@foreach (
$currencies
as
$item
)
@foreach (
$currencies
as
$item
)
...
@@ -48,6 +48,14 @@
...
@@ -48,6 +48,14 @@
</div>
</div>
</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>
{{-- <script>
function swapValues(){
function swapValues(){
var tmp = document.getElementById("
From
").value;
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