New Projects
-
What is the project about?
steemthink is a question and answer platform based on STEEM blockchain. The existing pc-side website has just started and completed the acquisition of the homepage data.
-
Technology Stack
I used angular as my front frame.And use Interactive Steem API to get the data from the blockchain
-
Roadmap
Complete the homepage of data acquisition, I will continue to develop the content page, and complete the comment and voting functions
-
How to contribute?
[IMAGE: https://res.cloudinary.com/hpiynhbhq/image/upload/v1520261339/orte1nu6tgrmv4svoxmj.jpg]
> As can be seen from the picture, the page has been from the block chain to get the latest articles under the utopian-io directory.
Below I will share with you how this page is completed, only for the angular and steem api to share.
Use steem API to get the latest data in the utopian-io directory
var app = angular.module('myApp', []);
app.controller('siteCtrl', function($scope, $http) {
$http({
method: 'GET',
url: 'https://api.steemjs.com/get_discussions_by_created?query={"tag":"utopian-io", "limit": "10"}'
}).then(function successCallback(response) {
$scope.lists = response.data;
}, function errorCallback(response) {
});
});
Use angular's http service to get data from the blockchain,the Request URL is
https://api.steemjs.com/get_discussions_by_created?query={"tag":"utopian-io", "limit": "10"}'
the method is GET
Use angular Create a module and Add controller
var app = angular.module('myApp', []);
app.controller('siteCtrl', function($scope, $http)
Format the reputation from json , use 2 part code
for (i=0; i<$scope.lists.length; i++ ) {
var author_reputation = this.change($scope.lists[i].author_reputation);
$scope.lists[i].author_reputation = author_reputation;
}
and
function change(reputation){
if (reputation == null) return reputation;
reputation = parseInt(reputation);
let rep = String(reputation);
const neg = rep.charAt(0) === "-";
rep = neg ? rep.substring(1) : rep;
const str = rep;
const leadingDigits = parseInt(str.substring(0, 4));
const log = Math.log(leadingDigits) / Math.log(10);
const n = str.length - 1;
let out = n + (log - parseInt(log));
if (isNaN(out)) out = 0;
out = Math.max(out - 9, 0);
out = (neg ? -1 : 1) * out;
out = out * 9 + 25;
out = parseInt(out);
return out;
};
Because the field value obtained by the official api is a string that needs to be formatted for normal display.
Here need to thank @stoodkev, For the format gave me a great help.
this article is for your reference:Steem.Js for dummies #4: Users reputation
After the data is processed, we display it using angular ng-repeat
{{ x.title }}
{{ x.body|limitTo:150}} ...
this is tag
{{ x.author }}
{{x.author_reputation}}
{{ x.created | date : 'yyyy-MM-dd HH:mm:ss' }}
{{ x.pending_payout_value | limitTo:6 }}Earn
{{ x.children }}Answers
{{x.net_votes}}Upvote
Homepage File :https://github.com/steemthink/steemthink/blob/master/html/index.html
SteemThink - You Ask - We Answer - Share Knowledge
Home
About us
Login
ASK A QUESTION
Questions
18
Answer
12
©2018
Terms & Privacy
All Questions
New
Trending
Hot
{{ x.title }}
{{ x.body|limitTo:150}} ...
this is tag
{{ x.author }}
{{x.author_reputation}}
{{ x.created | date : 'yyyy-MM-dd HH:mm:ss' }}
{{ x.pending_payout_value | limitTo:6 }}Earn
{{ x.children }}Answers
{{x.net_votes}}Upvote
Witness
SteemThink is now the first Q&A platform driven STEEM Witness!
Vote
Github
SteemThink is an open source project, if you are interested in our project, please visit github download.
Download
var app = angular.module('myApp', []);
app.controller('siteCtrl', function($scope, $http) {
$http({
method: 'GET',
url: 'https://api.steemjs.com/get_discussions_by_created?query={"tag":"utopian-io", "limit": "10"}'
}).then(function successCallback(response) {
$scope.lists = response.data;
for (i=0; i<$scope.lists.length; i++ ) {
var author_reputation = this.change($scope.lists[i].author_reputation);
$scope.lists[i].author_reputation = author_reputation;
}
}, function errorCallback(response) {
});
});
function change(reputation){
if (reputation == null) return reputation;
reputation = parseInt(reputation);
let rep = String(reputation);
const neg = rep.charAt(0) === "-";
rep = neg ? rep.substring(1) : rep;
const str = rep;
const leadingDigits = parseInt(str.substring(0, 4));
const log = Math.log(leadingDigits) / Math.log(10);
const n = str.length - 1;
let out = n + (log - parseInt(log));
if (isNaN(out)) out = 0;
out = Math.max(out - 9, 0);
out = (neg ? -1 : 1) * out;
out = out * 9 + 25;
out = parseInt(out);
return out;
};
Posted on Utopian.io - Rewarding Open Source Contributors