-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add viz/votes, update viz/custom-generater menu item, hive/post, stee…
…m/post, cyber/explorer menu items
- Loading branch information
1 parent
1ed935a
commit b4e923a
Showing
21 changed files
with
346 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"title": "Блок-эксплорер для Cyber", | ||
"description": "block explorer (просмотр блоков) в Cyber", | ||
"in_menu": "Блок-эксплорер", | ||
"in_menu": "Explorer", | ||
"category": "no_category" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"title": "Публикация постов", | ||
"description": "Сервис публикации постов в блокчейне Golos", | ||
"in_menu": "Добавить пост", | ||
"in_menu": "Редактор", | ||
"category": "no_category" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"title": "Публикация постов", | ||
"description": "Сервис публикации постов в блокчейне Golos", | ||
"in_menu": "Добавить пост", | ||
"in_menu": "Редактор", | ||
"category": "no_category" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"title": "Генератор custom операций", | ||
"description": "Сервис генерации custom операций для блокчейна Viz.", | ||
"in_menu": "custom генератор", | ||
"in_menu": "JSON-генератор", | ||
"category": "tools" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"title": "Опросы в Viz", | ||
"description": "Страница опросов Viz", | ||
"in_menu": "Опросы", | ||
"category": "tools" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php if (!defined('NOTLOAD')) exit('No direct script access allowed'); | ||
return '<h2>Меню</h2> | ||
<ul><li><a href="'.$conf['siteUrl'].'viz/polls/create">Создать новый</a></li> | ||
<li><a href="'.$conf['siteUrl'].'viz/polls/list">Список</a></li></ul> | ||
'; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php if (!defined('NOTLOAD')) exit('No direct script access allowed'); | ||
require_once 'functions.php'; | ||
function generateAppPages($blockchain_snippet) { | ||
$type = pageUrl()[2]; | ||
if (is_dir(__DIR__.'/pages/'.$type)) { | ||
$page_config = configs(__DIR__.'/pages/'.$type.'/config.json'); | ||
$data = []; | ||
$content_file = require_once(__DIR__.'/pages/'.$type.'/content.php'); | ||
$data['content'] = $blockchain_snippet; | ||
$data['content'] .= $content_file['content']; | ||
if ($type == 'results' || $type == 'voteing') { | ||
$data['title'] = $page_config['title'].$content_file['title']; | ||
$data['description'] = $page_config['description'].$content_file['description']; | ||
} else { | ||
$data['title'] = $page_config['title']; | ||
$data['description'] = $page_config['description']; | ||
} | ||
} | ||
return $data; | ||
} | ||
$data = generateAppPages($blockchain_snippet); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"title": "Создание опроса в Viz", | ||
"description": "Страница создания опросов в Viz" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php if (!defined('NOTLOAD')) exit('No direct script access allowed'); | ||
global $conf; | ||
$page = []; | ||
$page['content'] = '<script src="'.$conf['siteUrl'].'blockchains/viz/apps/polls/pages/create/page.js"></script> | ||
<p><span align="left">Создание опроса</span> <span align="right"><a href="'.$conf['siteUrl'].'viz/polls/list">Список</a></span></p> | ||
<form class="form"> | ||
<p><label for="login">Логин создателя опроса:</label> | ||
<input type="text" name="login" id="sender" value="" placeholder="Введите логин создателя опроса"></p> | ||
<p><label for="q">Вопрос:</label> | ||
<input type="text" name="q" id="question" value="" placeholder="Вопрос"></p> | ||
<p><lable for="a">Варианты ответа:</label> | ||
<input name="a" id="answer" placeholder="Введите ответ" type="text" ></p> | ||
<p><button type="button" onclick="add()">Добавить</button></p> | ||
<div id="out"></div> | ||
<p><label for="end_date">Дата и время окончания опроса:</label> | ||
<input type="datetime-local" name="end_date" id="datetime" placeholder="Дата и времяокончания опроса"></p> | ||
<p><label for="consider">Учитывать при расчёте результатов соц. капитал: </label> | ||
<select name="consider" id="vote_consider" placeholder="Учитывать при расчёте результатов СГ"> | ||
<option value="0">Личный</option> | ||
<option value="1">Личный + прокси</option> | ||
<option value="2">Как при награждении</option> | ||
</select></p> | ||
<p><label for="service">При помощи чего создавать опрос. Если вы авторизованы <a href="'.$conf['siteUrl'].'viz/accounts" target="_blank">здесь</a> с указанием активного ключа, будет выбран вариант dpos.space (создание опроса при помощи данного сайта): </label> | ||
<select name="service" id="clients" placeholder="При помощи чего создать опрос"> | ||
<option value="sign">Писарь</option> | ||
</select></p> | ||
<p><button type="button" onclick="submitPoll(this.form.login.value, this.form.q.value, this.form.end_date.value, this.form.consider.value, this.form.service.value)">Создать</button></p> | ||
</form>'; | ||
return $page; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
$(document).ready(function() { | ||
if (active_key) { | ||
var objSel = document.getElementById("clients"); | ||
console.log(JSON.stringify(objSel)); | ||
//Создаем новый объект Option и заносим его в коллекцию options | ||
objSel.options[0] = new Option("Dpos.space", "dpos.space", false, true); | ||
} | ||
|
||
}); | ||
|
||
var answers = []; | ||
function updateText() { | ||
let result = ''; | ||
for (let answer of answers) { | ||
result += `<li>${answer}</li>`; | ||
} | ||
document.getElementById('out').innerHTML = '<p>Итоговый список:</p><ol>' + result + '</ol>'; | ||
} | ||
|
||
function add() { | ||
var a = document.getElementById('answer').value; | ||
if (!a) { | ||
return alert('Не ввели вариант ответа'); | ||
} | ||
if (answers.indexOf(a) > -1) { | ||
return alert('Такой вариант ответа уже есть.'); | ||
} | ||
answers.push(a); | ||
|
||
updateText() | ||
} | ||
|
||
updateText(); | ||
|
||
function sendData(operations) { | ||
var q = window.confirm('Вы действительно хотите создать опрос? Операция платная: стоит 100 VIZ'); | ||
if (q === true) { | ||
viz.broadcast.send({extensions: [], operations}, [active_key], function(err, res) { | ||
if (!err) { | ||
window.alert('Опрос успешно создан.'); | ||
} else { | ||
window.alert('Ошибка: ' + JSON.stringify(err)); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function submitPoll(sender, q, end_date, consider, clients) { | ||
if (end_date) { | ||
let endDate = parseInt(new Date(end_date).getTime()/1000); | ||
let memo_array = {}; | ||
memo_array.contractName = "viz-votes"; | ||
memo_array.contractAction = "createVote"; | ||
memo_array.contractPayload = {}; | ||
memo_array.contractPayload.question = q; | ||
memo_array.contractPayload.answers = answers; | ||
memo_array.contractPayload.end_date = endDate; | ||
memo_array.contractPayload.consider = parseFloat(consider); | ||
let memo = JSON.stringify(memo_array); | ||
let data_url = []; | ||
data_url.push(["transfer",{"from":sender,"to":"committee","amount":"100.000 VIZ","memo":memo}]); | ||
let str_data_url = JSON.stringify(data_url); | ||
if (answers.length > 0) { | ||
if (clients === "sign") { | ||
window.open("https://viz.dpos.space/viz-sign/?user=" + sender + "&tr=" + str_data_url); | ||
} else if (clients === 'dpos.space') { | ||
sendData(data_url); | ||
} | ||
} else { | ||
window.alert('Нет добавленных вариантов ответа.'); | ||
} | ||
} else { | ||
window.alert('Вы не указали дату и время окончания опроса.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"title": "Список опросов в Viz", | ||
"description": "Страница со списком опросов в блокчейне Viz." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php if (!defined('NOTLOAD')) exit('No direct script access allowed'); | ||
global $conf; | ||
$page = []; | ||
$page['content'] = '<p><span align="left">Список опросов</span> <span align="right"><a href="'.$conf['siteUrl'].'viz/polls/create">Создание нового опроса</a></span></p>'; | ||
$html = file_get_contents('http://138.201.91.11:3100/viz-api?service=votes&type=list'); | ||
$table = json_decode($html, true); | ||
$page['content'] .= '<ul>'; | ||
foreach ($table as $poll) { | ||
$page['content'] .= '<li><a href="'.$conf['siteUrl'].'viz/polls/voteing/'.$poll['permlink'].'" target="_blank">'.$poll['question'].'</a></li> | ||
'; | ||
} | ||
$page['content'] .= '</ul>'; | ||
return $page; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"title": "Результаты опроса ", | ||
"description": "Страница с результатами опроса. Вопрос: " | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php if (!defined('NOTLOAD')) exit('No direct script access allowed'); | ||
if (isset(pageUrl()[3])) { | ||
require __DIR__.'/get_dynamic_global_properties.php'; | ||
$res3 = $command3->execute($commandQuery3); | ||
$mass3 = $res3['result']; | ||
$tvsh = (float)$mass3['total_vesting_shares']; | ||
global $conf; | ||
$page = []; | ||
$page['content'] = '<p><span align="left">Результаты</span> <span align="center"><a href="'.$conf['siteUrl'].'viz/polls/voteing/'.pageUrl()[3].'">голосование</a></span> <span align="right"><a href="'.$conf['siteUrl'].'viz/polls/list">Список опросов</a></span></p>'; | ||
$html = file_get_contents('http://138.201.91.11:3100/viz-api?service=votes&type=vote&permlink='.pageUrl()[3]); | ||
if (pageUrl()[3] && $html) { | ||
$table = json_decode($html, true); | ||
$d = new DateTime(); | ||
$d->setTimestamp($table['end_date']); | ||
// или createFromFormat с форматом U | ||
$d = DateTime::createFromFormat('U', $table['end_date']); | ||
$sp = $table['all_shares']; | ||
$sp = round($sp, 3); | ||
$page['content'] .= '<hr> | ||
<h2>Вопрос: '.$table['question'].'</h2> | ||
<h3>Дата и время завершения: '.$d->format('d.m.Y H:i:s').' GMT</h3> | ||
<p><br></p> | ||
<p align="left"><strong>'.$table['type'].'. Всего проголосовало '.$sp.' соц. капитала ('.round(($table['all_shares']/$tvsh*100), 2).'% от всех SHARES).</strong></p> | ||
<br> | ||
<table align="center"><thead><tr><th>Вариант ответа</th><th>Процент</th><th>Процент от общего соц. капитала по варианту</th></tr></thead><tbody> | ||
'; | ||
$voters_str = '<h2>Топ 100 пользователей по соц. капиталу (каждый вариант, за который есть голоса)</h2>'; | ||
foreach ($table['variants'] as $answer) { | ||
$answer_gests_percent = round(($answer['shares'] / $tvsh)*100, 2); | ||
$page['content'] .= '<tr><td>'.$answer['answer'].'</td> | ||
<td>'.$answer['percent'].'%</td> | ||
<td>'.$answer_gests_percent.'%</td></tr>'; | ||
$voters_str .= '<h3>За вариант "'.$answer['answer'].'" проголосовали:</h2> | ||
<p>'.$answer['voters'].'</p> | ||
'; | ||
} | ||
$page['content'] .= '</tbody></table> | ||
<br>'.$voters_str; | ||
} else { | ||
$page['content'] .= '<p>Такого опроса нет.</p>'; | ||
} | ||
$page['title'] = $table['question']; | ||
$page['description'] = $table['question']; | ||
return $page; | ||
} | ||
?> |
18 changes: 18 additions & 0 deletions
18
blockchains/viz/apps/polls/pages/results/get_dynamic_global_properties.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php if (!defined('NOTLOAD')) exit('No direct script access allowed'); | ||
require $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php'; | ||
require_once $_SERVER['DOCUMENT_ROOT'] . '/helpers.php'; | ||
|
||
use GrapheneNodeClient\Commands\CommandQueryData; | ||
use GrapheneNodeClient\Commands\Single\GetDynamicGlobalPropertiesCommand; | ||
$connector_class = CONNECTORS_MAP['viz']; | ||
|
||
$commandQuery3 = new CommandQueryData(); | ||
|
||
$data3 = []; | ||
|
||
$commandQuery3->setParams($data3); | ||
|
||
$connector = new $connector_class(); | ||
|
||
$command3 = new GetDynamicGlobalPropertiesCommand($connector); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"title": "Голосование по опросу ", | ||
"description": "Страница голосования по опросу в Viz. Вопрос: " | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php if (!defined('NOTLOAD')) exit('No direct script access allowed'); | ||
if (isset(pageUrl()[3])) { | ||
global $conf; | ||
$page = []; | ||
$page['content'] = '<script src="'.$conf['siteUrl'].'blockchains/viz/apps/polls/pages/voteing/page.js"></script> | ||
<p><span align="left">Голосование</span> <span align="center"><a href="'.$conf['siteUrl'].'viz/polls/results/'.pageUrl()[3].'">Предварительные или окончательные результаты</a></span> <span align="right"><a href="'.$conf['siteUrl'].'viz/polls/list">Список опросов</a></span></p>'; | ||
$html = file_get_contents('http://138.201.91.11:3100/viz-api?service=votes&type=voteing&permlink='.pageUrl()[3]); | ||
if (pageUrl()[3] && $html) { | ||
$table = json_decode($html, true); | ||
$answers = $table['answers']; | ||
if ($answers && $table['end_date'] > gmmktime()) { | ||
$d = new DateTime(); | ||
$d->setTimestamp($table['end_date']); | ||
|
||
// или createFromFormat с форматом U | ||
$d = DateTime::createFromFormat('U', $table['end_date']); | ||
$page['content'] .= '<hr> | ||
<h2>Вопрос: '.$table['question'].'</h2> | ||
<h3>Дата и время завершения: '.$d->format('d.m.Y H:i:s').' GMT</h3> | ||
<p><strong>Если вы авторизовались <a href="'.$conf['siteUrl'].'viz/accounts" target="_blank">здесь</a> с указанием логина и постинг ключа, сможете проголосовать, не выходя с этого сайта.</strong></p> | ||
<form class="form"> | ||
<p><label for="sender">Голосующий:</label></p> | ||
<p><input type="text" name="sender" value="" placeholder="логин голосующего"></p> | ||
<hr> | ||
<p><label for="answers">Выберите вариант ответа:</label></p> | ||
<hr>'; | ||
foreach ($answers as $num => $answer) { | ||
$page['content'] .= '<p><input type="radio" name="answers" id="voteing" value="'.$num.'" placeholder="'.$answer.'"> '.$answer.'</p>'; | ||
} | ||
$page['content'] .= '</p> | ||
<hr> | ||
<p><button type="button" onclick="submitVoteing(`'.pageUrl()[3].'`, this.form.sender.value, this.form.answers.value)">Голосовать</button></p> | ||
</form>'; | ||
} else if ($table['end_date'] <= gmmktime()) { | ||
$page['content'] .= '<p>Опрос закончен.</p>'; | ||
} | ||
} else { | ||
$page['content'] .= '<p>Такого опроса нет.</p>'; | ||
} | ||
$page['title'] = $table['question']; | ||
$page['description'] = $table['question']; | ||
return $page; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
$(document).ready(function() { | ||
if (viz_login) { | ||
$('input[name=sender]').val(viz_login); | ||
} | ||
}); | ||
|
||
function sendData(operations, variant) { | ||
variant = parseInt(variant) + 1; | ||
var q = window.confirm('Вы действительно хотите проголосовать за вариант №' + variant + '?'); | ||
if (q === true) { | ||
viz.broadcast.send({extensions: [], operations}, [active_key], function(err, res) { | ||
if (!err) { | ||
window.alert('Вы успешно проголосовали.'); | ||
} else { | ||
window.alert('Ошибка: ' + JSON.stringify(err)); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function submitVoteing(permlink, sender, answer) { | ||
let memo_array = {}; | ||
memo_array.contractName = "viz-votes"; | ||
memo_array.contractAction = "voteing"; | ||
memo_array.contractPayload = {}; | ||
memo_array.contractPayload.votePermlink = permlink; | ||
memo_array.contractPayload.answerId = answer; | ||
let memo = JSON.stringify(memo_array); | ||
let data_url = []; | ||
data_url.push(["custom",{"required_auths":[], "required_regular_auths": [sender],"id":"viz-votes","json":memo}]); | ||
let str_data_url = JSON.stringify(data_url); | ||
if (sender && answer) { | ||
if (viz_login && posting_key) { | ||
sendData(data_url, answer); | ||
} else { | ||
window.open("https://viz.dpos.space/viz-sign/?user=" + sender + "&tr=" + str_data_url); | ||
} | ||
} else if (!sender) { | ||
window.alert('Вы не ввели логин'); | ||
} else if (!answer) { | ||
window.alert('Вы не добавили ответы'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.