Skip to content

Commit

Permalink
v0.0.12 add Projects Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
SteakOverCooked authored and SteakOverCooked committed Feb 21, 2018
1 parent 0915b4b commit 012a49c
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 15 deletions.
7 changes: 7 additions & 0 deletions js/functions.js
Expand Up @@ -76,4 +76,11 @@ const formatReputation = function(reputation, decimal_places = 3) {
v = neg ? -v : v;
let vv = v * 9 + 25;
return +(Math.round(vv + "e+" + decimal_places) + "e-" + decimal_places);
}

// get last week
const getLastWeek = () => {
let today = new Date();
let lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
return lastWeek;
}
118 changes: 104 additions & 14 deletions js/utopian.js
Expand Up @@ -4,6 +4,31 @@
const default_node = "https://api.steemit.com";
steem.api.setOptions({ url: default_node });

// save settings
const saveSettings = (showMsg = true) => {
let id = $('input#steemit_id').val().trim();
let website = $('select#steemit_website').val();
let friends = $('textarea#friends').val();
let nodes = $('select#nodes').val();
let utopian = {};
utopian['steemit_id'] = id;
utopian['steemit_website'] = website;
utopian['friends'] = friends;
utopian['nodes'] = nodes;
utopian['top_limit'] = parseInt($('input#top_limit').val());
utopian['top_start'] = $('input#top_start').val().trim();
utopian['top_end'] = $('input#top_end').val().trim();
utopian['top_sort1'] = $('select#top_sort1').val().trim();
utopian['top_new'] = $('input#top_limit').is(':checked');
chrome.storage.sync.set({
utopian_settings: utopian
}, function() {
if (showMsg) {
alert('Settings Saved (Required: Reload Extension)');
}
});
}

// get Node
const getNode = () => {
return $('select#nodes').val();
Expand Down Expand Up @@ -270,6 +295,7 @@ function updateModerators(api) {
let row = arr[i];
if (row["account"] == id) {
s += "<h3>Hello " + id + "!</h3>";
s += "<img style='float:right' src='https://api.utopian.io/api/users/" + id + "/avatar?size=96&round=true'>";
s + "<ul>";
if ((row["supermoderator"]) || (row["referrer"] == undefined)) {
s += "<li>You are a Supervisor.</li>";
Expand Down Expand Up @@ -779,25 +805,38 @@ document.addEventListener('DOMContentLoaded', function() {
}
}
}
if (utopian['top_limit']) {
$('input#top_limit').val(parseInt(utopian['top_limit']));
}
if (utopian['top_start']) {
$('input#top_start').val(utopian['top_start']);
}
if (utopian['top_end']) {
$('input#top_end').val(utopian['top_end']);
}
if (utopian['top_sort1']) {
$('select#top_sort1').val(utopian['top_sort1']);
}
if (utopian['top_new']) {
$('select#top_new').prop("checked", utopian['top_new']);
}
// get node infor
$('select#nodes').val(utopian['nodes']);
}
if ($('input#top_limit').val().trim() == '') {
$('input#top_limit').val(10);
}
// default 7 days ago
if ($('input#top_start').val().trim() == '') {
$('input#top_start').val(getLastWeek().toISOString().substr(0, 10));
}
// default today
if ($('input#top_end').val().trim() == '') {
$('input#top_end').val(new Date().toISOString().substr(0, 10));
}
});
$('button#save_id_btn').click(function() {
let id = $('input#steemit_id').val().trim();
let website = $('select#steemit_website').val();
let friends = $('textarea#friends').val();
let nodes = $('select#nodes').val();
let utopian = {};
utopian['steemit_id'] = id;
utopian['steemit_website'] = website;
utopian['friends'] = friends;
utopian['nodes'] = nodes;
chrome.storage.sync.set({
utopian_settings: utopian
}, function() {
alert('Settings Saved (Required: Reload Extension)');
});
saveSettings();
});
// utopian-io
getVP("utopian-io", $("div#account_utopian_vp"), getNode());
Expand Down Expand Up @@ -868,4 +907,55 @@ document.addEventListener('DOMContentLoaded', function() {
});
// get sponsor api
getSponsors("https://api.utopian.io/api/sponsors", $("div#sponsors"));
// top projects and contributions
$('button#btn_top').click(function() {
$('div#top_result').html("<img id='loading' src='images/loading.gif' />");
let limit = parseInt($('input#top_limit').val());
let start = $('input#top_start').val().trim();
let end = $('input#top_end').val().trim();
let sort1 = $('select#top_sort1').val().trim();
let sort2 = "projects";
let only_new = $('input#top_new').is(":checked") ? "true" : "false";
let api = "https://api.utopian.io/api/posts/top?limit=" + limit + "&start_date=" + start + "&end_date=" + end + "&sort_by=" + sort1 + "&retrieve_by=" + sort2 + "&only_new=" + only_new;
logit("calling " + api);
saveSettings(false);
$.ajax({
type: "GET",
url: api,
success: function(result) {
let s = "<table style='width:100%'>";
s += "<thead>";
s += "<tr><th>Project Name</th><th>Description</th><th>Count<th>Rewards</th><th>License</th></tr>";
s += "</thead>";
let len = result.length;
for (let i = 0; i < len; ++ i) {
s += "<tr>";
let github = result[i].github;
let lic = github.license;
let home_url = github.home_url;
let project_name = github['name'];
let description = github['description'];
let count = result[i]['count'];
let rewards = result[i]['rewards'];
let license = lic ? lic['name'] : '';
s += "<td><a target=_blank href='" + home_url + "'>" + project_name + "</a></td>";
s += "<td>" + description + "</td>";
s += "<td>" + count + "</td>";
s += "<td>" + rewards.toFixed(3) + "</td>";
s += "<td>" + license + "</td>";
s += "</tr>";
}
s += "</table>";
$('div#top_result').html(s);
},
error: function(request, status, error) {
logit('Response: ' + request.responseText);
logit('Error: ' + error );
logit('Status: ' + status);
},
complete: function(data) {
logit("API Finished: " + api);
}
});
});
}, false);
2 changes: 1 addition & 1 deletion manifest.json
Expand Up @@ -3,7 +3,7 @@
"name": "Utopian Moderator & Supervisor",
"short_name": "Utopian-IO",
"default_locale": "en",
"version": "0.0.11",
"version": "0.0.12",
"browser_action": {
"default_icon": "icon.png",
"default_title": "Utopian Moderator & Supervisor",
Expand Down
16 changes: 16 additions & 0 deletions utopian-ext-main.html
Expand Up @@ -45,6 +45,7 @@
<li><a href="#tabs-stats">Statistics</a></li>
<li><a href="#tabs-setting">Settings</a></li>
<li><a href="#tabs-tools">Tools</a></li>
<li><a href="#tabs-top">Projects</a></li>
<li><a href="#tabs-log">Log</a></li>
</ul>
<div id="tabs-general">
Expand Down Expand Up @@ -149,6 +150,21 @@ <h4>Steem Nodes Ping Tests<h4>
<p><button class='form-control' style='width: 110px' id='btn_ping'>Test</button></p>
<div id='ping_result'> </div>
</div>
<div id="tabs-top">
<h4>Top Projects</h4>
<form class='form-inline'>
<input class='form-control' placeholder='Number of Posts to return' type='number' step=1 value='10' id=top_limit>
<input class='form-control' placeholder='Start Date e.g. 2018-01-01' type='text' value='' id=top_start>
<input class='form-control' placeholder='End Date e.g. 2018-01-01' type='text' value='' id=top_end>
<select class='form-control' id='top_sort1'>
<option value='contributions'>Sort By Contributions</option>
<option value='rewards'>Sort By Rewards</option>
</select>
<label><input type='checkbox' class='form-control' id=top_new>Only New</label>
<button type='button' class='form-control' style='width: 110px' id='btn_top'>Query</button>
</form>
<div id='top_result'> </div>
</div>
<div id="tabs-log">
<h4>Proudly brought to you by <a target=_blank href="https://steemit.com/@justyy">@justyy</a></h4>
<textarea readonly class='form-control' rows=15 id='about'>
Expand Down

0 comments on commit 012a49c

Please sign in to comment.