Skip to content

Commit

Permalink
Added hide value ability & Standardized directory structure
Browse files Browse the repository at this point in the history
- Standardized the directory structure.
- Added ability to hide value.
- Changes settings styles.
- Added exception handling when reading and writing settings.
  • Loading branch information
XjSv committed Feb 4, 2018
1 parent 0492b00 commit 8dc08ae
Show file tree
Hide file tree
Showing 22 changed files with 197 additions and 191 deletions.
1 change: 0 additions & 1 deletion docs/_config.yml

This file was deleted.

File renamed without changes
4 changes: 3 additions & 1 deletion css/index.css → en-US/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ body {
#meta-container {
color: #cbcbcb;
float: right;
text-align: right;
font-size: 0.6em;
margin-right: 5px;
height: 10px;
display: inline-block;
width: 395px;
}
#out-of-date {
width: 100px;
Expand All @@ -42,7 +44,7 @@ body {
table {
margin: 0;
padding: 0;
width: 25em;
width: 400px;
border-collapse: collapse;
}

Expand Down
9 changes: 4 additions & 5 deletions css/settings.css → en-US/css/settings.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
body {
width: 300px;
height: 400px;
height: 350px;
margin: 0;
padding: 0;
}
#main {
height: 400px;
overflow: auto;
height: 350px;
overflow-y: auto;
}
#inputCurrList {
height: 250px;
height: 150px;
}
#currency-holdings {
height: 250px;
display: block;
}
File renamed without changes
File renamed without changes
28 changes: 28 additions & 0 deletions en-US/gadget.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<gadget>
<name>Cryptocurrencies Price Tracker</name>
<namespace>microsoft.windows</namespace>
<version>1.2.0</version>
<author name="Armand Tresova">
<info url="https://www.armandtresova.com/" text="www.armandtresova.com"/>
<logo src="logo.png" />
</author>
<copyright>© 2018 ArmandTresova.com</copyright>
<description>
Cryptocurrencies Price Tracker is a Windows Sidebar Gadget that displays snapshot prices from CoinMarketCap using their API, as well as a personal portfolio value.
<br /><br />
A free utility provided by Armand Tresova.
</description>
<icons>
<icon height="64" width="64" src="icon.png"/>
</icons>
<hosts>
<host name="sidebar">
<base type="HTML" apiVersion="1.0.0" src="index.html" />
<autoscaleDPI>true</autoscaleDPI>
<permissions>Full</permissions>
<platform minPlatformVersion="1.0" />
<defaultImage src="drag.png" />
</host>
</hosts>
</gadget>
16 changes: 9 additions & 7 deletions index.html → en-US/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=Unicode"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Cryptocurrencies Price Tracker</title>
<link href="css/index.css" rel="stylesheet" type="text/css">
<script src="js/jquery-1.12.4.min.js" type="text/javascript"></script>
<script src="js/common.js" type="text/javascript"></script>
<script src="js/index.js" type="text/javascript"></script>
<script src="js/jquery-1.12.4.min.js" type="text/javascript" language="javascript"></script>
<script src="js/common.js" type="text/javascript" language="javascript"></script>
<script src="js/index.js" type="text/javascript" language="javascript"></script>
</head>
<body onload="init();">
<div id="main">
Expand All @@ -20,9 +20,11 @@
</table>
<span id="meta-container">
<span id="out-of-date"></span>
Refreshed: <span id="last-refreshed"></span>
Updated: <span id="last-updated"></span>
Refresh every: <span id="refresh-frequency"></span> min
<span id="meta-data">
Refreshed: <span id="last-refreshed"></span>
Updated: <span id="last-updated"></span>
Refresh every: <span id="refresh-frequency"></span> min
</span>
</span>
</div>
</body>
Expand Down
52 changes: 44 additions & 8 deletions js/index.js → en-US/js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cryptoCurrencyMapping = {};
currencySymbolMapping = {
var configCurr;
var configFreq;
var configCurrList;
var cryptoCurrencyMapping = {};
var currencySymbolMapping = {
'USD': '$',
'AUD': '$',
'EUR': '€',
Expand Down Expand Up @@ -38,19 +41,41 @@ function init() {
System.Gadget.settingsUI = 'settings.html';
System.Gadget.onSettingsClosed = init;

configCurr = (System.Gadget.Settings.readString('configCurr') || 'USD');
configFreq = (System.Gadget.Settings.readString('configFreq') || 20);
configCurrList = (System.Gadget.Settings.readString('configCurrList') || 'BTC,BCH,LTC,ETH').split(',');
configDisplayValue = readSetting('configDisplayValue', 'true');
configCurr = readSetting('configCurr', 'USD');
configFreq = readSetting('configFreq', '20');
configCurrList = readSetting('configCurrList', 'BTC,BCH,LTC,ETH').split(',');

createTableBody();

var tableHeight = $('#main-table').outerHeight();
var offset = 30;

document.body.style.width = 405;
document.body.style.height = (tableHeight + offset);
document.body.style.margin = 0;

if (configDisplayValue == 'false') {
document.body.style.width = 305;
$('#main').css('width', '300px');
$('#main-table').css('width', '300px');
$('#meta-container').css('width', '295px');

if (!isUpToDateResults) {
$('#out-of-date').css('text-align', 'right');
$('#meta-data').hide();
} else {
$('#out-of-date').css('width', '0');
}
} else {
document.body.style.width = 405;
$('#main').css('width', '400px');
$('#main-table').css('width', '400px');
$('#meta-container').css('width', '395px');
$('#out-of-date').css('width', '100px');
$('#out-of-date').css('text-align', 'left');
$('#meta-data').show();
}

$('#main').css('height', (tableHeight + offset) + 'px');
$('.currency-label').html('(' + configCurr + ')');
$('#refresh-frequency').html(configFreq);
Expand Down Expand Up @@ -78,7 +103,7 @@ function getPrice(code) {
if (code) {
$.getJSON('https://api.coinmarketcap.com/v1/ticker/' + cryptoCurrencyMapping[code] + '/?convert=' + configCurr, function(data) {
var changeDirection = (data[0].percent_change_1h < 0) ? 'decrease' : 'increase';
var configHoldingValue = ((System.Gadget.Settings.readString('inputHoldList-' + code) || 0) * 1);
var configHoldingValue = (readSetting('configHoldList-' + code, '0') * 1);
var price = (data[0]['price_' + configCurr.toLowerCase()] * 1);
var priceFormatted = formatCurrency(data[0]['price_' + configCurr.toLowerCase()]);
var holdingsValueFormatted = formatCurrency(price * configHoldingValue);
Expand Down Expand Up @@ -116,9 +141,16 @@ function altRows() {
}

function createTableBody() {
var tableHeaders = document.getElementById('main-table').getElementsByTagName('th');
var tableBody = document.getElementById('main-table').getElementsByTagName('tbody')[0];
var rows = tableBody.rows;

if (configDisplayValue == 'false') {
tableHeaders[3].style.display = 'none';
} else {
tableHeaders[3].style.display = 'block';
}

// Delete all rows first before inserting new ones.
while (tableBody.rows.length > 0) {
tableBody.deleteRow(0);
Expand Down Expand Up @@ -146,6 +178,10 @@ function createTableBody() {
var cell5 = row.insertCell(3);
cell5.className = 'portfolio';
cell5.id = configCurrList[i] + '-port';

if (configDisplayValue == 'false') {
cell5.style.display = 'none';
}
}

altRows();
Expand All @@ -163,4 +199,4 @@ function getTimeNow() {

function formatCurrency(number) {
return currencySymbolMapping[configCurr] + (number * 1).toLocaleString(undefined, { style: 'currency', currency: configCurr });
}
}
File renamed without changes.
40 changes: 31 additions & 9 deletions js/settings.js → en-US/js/settings.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
currencies = {};

function init() {
var configCurr = (System.Gadget.Settings.readString('configCurr') || 'USD');
var configFreq = (System.Gadget.Settings.readString('configFreq') || 20);
var configCurrList = (System.Gadget.Settings.readString('configCurrList') || 'BTC,BCH,LTC,ETH');
var configDisplayValue = readSetting('configDisplayValue', 'true');
var configCurr = readSetting('configCurr', 'USD');
var configFreq = readSetting('configFreq', '20');
var configCurrList = readSetting('configCurrList', 'BTC,BCH,LTC,ETH');

if (configDisplayValue == 'true') {
$('#inputDisplayValue').attr('checked', true);
} else {
$('#inputDisplayValue').removeAttr('checked');
$('#current-holdings').hide();
}

$('#inputCurr').val(configCurr);
$('#inputFreq').val(configFreq);
Expand All @@ -14,6 +22,14 @@ function init() {
generateHoldingsInputs($(this).val());
});

$('#inputDisplayValue').change(function() {
if ($(this).is(':checked')) {
$('#current-holdings').show();
} else {
$('#current-holdings').hide();
}
});

$('#currency-holdings').on('keyup', '.inputHoldList', function() {
this.value = this.value.replace(/[^0-9\.]/g, '');
});
Expand All @@ -23,12 +39,19 @@ function init() {

function saveSettings(event) {
if (event.closeAction == event.Action.commit) {
System.Gadget.Settings.writeString('configCurr', $('#inputCurr').val());
System.Gadget.Settings.writeString('configFreq', $('#inputFreq').val());
System.Gadget.Settings.writeString('configCurrList', $('#inputCurrList').val());

if ($('#inputDisplayValue').is(":checked")) {
saveSetting('configDisplayValue', 'true');
} else {
saveSetting('configDisplayValue', 'false');
}

saveSetting('configCurr', $('#inputCurr').val());
saveSetting('configFreq', $('#inputFreq').val());
saveSetting('configCurrList', $('#inputCurrList').val());

$('.inputHoldList').each(function() {
System.Gadget.Settings.writeString('inputHoldList-' + $(this).attr('id'), ($(this).val() * 1));
saveSetting('configHoldList-' + $(this).attr('id'), ($(this).val() * 1));
});

event.cancel = false;
Expand All @@ -38,10 +61,9 @@ function saveSettings(event) {
function generateHoldingsInputs(selectedOptions) {
var holdingsInputs = '';
$.each(selectedOptions, function(key, val) {
var elementValue = (System.Gadget.Settings.readString('inputHoldList-' + val) || '0');
var elementValue = readSetting('configHoldList-' + val, '0');
holdingsInputs += val + ': <input name="inputHoldList-' + val + '" id="' + val + '" class="inputHoldList" type="text" size="3" value="' + elementValue + '" align="right" /><br />';
});

$('#currency-holdings').html(holdingsInputs);
}

Expand Down
76 changes: 76 additions & 0 deletions en-US/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Cryptocurrencies Price Tracker - Settings</title>
<link href="css/settings.css" rel="stylesheet" type="text/css">
<script src="js/jquery-1.12.4.min.js" type="text/javascript" language="javascript"></script>
<script src="js/common.js" type="text/javascript" language="javascript"></script>
<script src="js/settings.js" type="text/javascript" language="javascript"></script>
</head>
<body onload="init();">
<div id="main">
<div><b>Display Value</b><input id="inputDisplayValue" name="inputDisplayValue" type="checkbox" checked="true"></div>
<div>
<b>Currency</b>
<select id="inputCurr" name="inputCurr">
<option value="USD" selected="selected">USD</option>
<option value="AUD">AUD</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="BRL">BRL</option>
<option value="CAD">CAD</option>
<option value="CHF">CHF</option>
<option value="CLP">CLP</option>
<option value="CNY">CNY</option>
<option value="CZK">CZK</option>
<option value="DKK">DKK</option>
<option value="HKD">HKD</option>
<option value="HUF">HUF</option>
<option value="IDR">IDR</option>
<option value="ILS">ILS</option>
<option value="INR">INR</option>
<option value="JPY">JPY</option>
<option value="KRW">KRW</option>
<option value="MXN">MXN</option>
<option value="MYR">MYR</option>
<option value="NOK">NOK</option>
<option value="NZD">NZD</option>
<option value="PHP">PHP</option>
<option value="PKR">PKR</option>
<option value="PLN">PLN</option>
<option value="RUB">RUB</option>
<option value="SEK">SEK</option>
<option value="SGD">SGD</option>
<option value="THB">THB</option>
<option value="TRY">TRY</option>
<option value="TWD">TWD</option>
<option value="ZAR">ZAR</option>
</select>
</div>
<div>
<b>Refresh Frequency (minutes)</b>
<select id="inputFreq" name="inputFreq">
<option value="1">1</option>
<option value="5" selected="selected">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="45">45</option>
<option value="60">60</option>
</select>
</div>
<div>
<b>Currenies</b> <br />
<select multiple="multiple" id="inputCurrList" name="inputCurrList"></select>
</div>
<div id="current-holdings">
<b>Current Holdings</b>
<div id="currency-holdings"></div>
</div>
</div>
</body>
</html>


File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions en-US/tools/build-gadget.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Compress-Archive -Path '..\..\*' -CompressionLevel NoCompression -DestinationPath '..\..\CryptocurrenciesPriceTrackerGadget.zip'
Rename-Item '..\..\CryptocurrenciesPriceTrackerGadget.zip' 'CryptocurrenciesPriceTracker.gadget'
File renamed without changes.
24 changes: 0 additions & 24 deletions gadget.xml

This file was deleted.

Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8dc08ae

Please sign in to comment.