Skip to content

Commit

Permalink
Progress FollowMyVote#19: Implement basic sponsorship form
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielhourt committed Mar 9, 2016
1 parent 56f43b5 commit a55c209
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 47 deletions.
4 changes: 2 additions & 2 deletions VotingApp/VotingSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class VotingSystem : public QObject
*/
Q_INVOKABLE Promise* castCurrentDecision(swv::ContestWrapper* contest);

Q_INVOKABLE CoinWrapper* getCoin(quint64 id);
Q_INVOKABLE CoinWrapper* getCoin(QString name);
Q_INVOKABLE swv::CoinWrapper* getCoin(quint64 id);
Q_INVOKABLE swv::CoinWrapper* getCoin(QString name);

Q_INVOKABLE swv::data::Account* getAccount(QString name);

Expand Down
50 changes: 44 additions & 6 deletions VotingApp/qml/BasicContestForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import QtQmlTricks.UiElements 2.0
import FollowMyVote.StakeWeightedVoting 1.0

Item {
id: basicContestForm

property VotingSystem votingSystem
property var purchaseRequest
property var contestCreator

Flickable {
id: flickable
Expand All @@ -25,6 +28,8 @@ Item {
id: createContestFormColumn
width: parent.width
spacing: window.dp(8)
ExtraAnchors.topLeftCorner: parent
anchors.margins: window.dp(16)

AppTextField {
id: contestName
Expand Down Expand Up @@ -91,7 +96,7 @@ Item {
IconButton {
icon: IconType.edit
onClicked: {
var dialog = contestantDialog.createObject(createContestPage, {
var dialog = contestantDialog.createObject(basicContestForm, {
"contestantName": name,
"contestantDescription": description})

Expand Down Expand Up @@ -126,13 +131,13 @@ Item {

onClicked: {
// Create a new dialog as defined by the contestDialog component
var dialog = contestantDialog.createObject(createContestPage)
var dialog = contestantDialog.createObject(basicContestForm)

// Handle dialog accepted/canceled signals
dialog.accepted.connect(function() {
var contestant = Qt.createQmlObject("import FollowMyVote.StakeWeightedVoting." +
"ContestPurchase 1.0; Contestant{}",
createContestPage, "ContestantCreation")
basicContestForm, "ContestantCreation")
contestant.name = dialog.contestantName;
contestant.description = dialog.contestantDescription
purchaseRequest.contestants.append(contestant)
Expand All @@ -154,11 +159,11 @@ Item {
return new Date(0)

var date = new Date()
if (contestEndsTime.currentIndex === 1)
if (contestEndsTime.currentIdx === 1)
date.setDate(date.getDate() + 1)
else if (contestEndsTime.currentIndex === 2)
else if (contestEndsTime.currentIdx === 2)
date.setDate(date.getDate() + 7)
else if (contestEndsTime.currentIndex === 3)
else if (contestEndsTime.currentIdx === 3)
date.setMonth(date.getMonth() + 1)
return date
}
Expand All @@ -180,4 +185,37 @@ Item {
}
}
}

Component {
id: contestantDialog

Dialog {
title: qsTr("Edit Contestant")
contentHeight: window.dp(200)
contentWidth: window.dp(300)

property alias contestantName: contestantName.text
property alias contestantDescription: contestantDescription.text

ColumnLayout {
anchors.fill: parent
anchors.margins: window.dp(8)

AppTextField {
id: contestantName
placeholderText: qsTr("Name")
maximumLength: contestCreator.contestLimits[ContestLimits.ContestantNameLength]
Layout.fillWidth: true
KeyNavigation.tab: contestantDescription
Component.onCompleted: forceActiveFocus(Qt.Popup)
}
ScrollingTextEdit {
id: contestantDescription
Layout.fillHeight: true
Layout.fillWidth: true
textEdit.placeholderText: qsTr("Description")
}
}
}
}
}
59 changes: 25 additions & 34 deletions VotingApp/qml/CreateContestPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Page {
id: createContestPage
backgroundColor: "white"

property var contestCreator
property VotingSystem votingSystem
property var contestCreator
property var purchaseRequest: contestCreator.getPurchaseContestRequest()

SwipeView {
Expand All @@ -23,46 +23,37 @@ Page {

BasicContestForm {
votingSystem: createContestPage.votingSystem
contestCreator: createContestPage.contestCreator
purchaseRequest: createContestPage.purchaseRequest
}
SponsorshipForm {
onSponsorshipEnabledChanged: purchaseRequest.sponsorshipEnabled = sponsorshipEnabled
SwipeView.onIsCurrentItemChanged: {
if (!SwipeView.isCurrentItem && purchaseRequest.sponsorshipEnabled) {
try {
purchaseRequest.sponsorMaxVotes = maxVotes
} catch (a) {
purchaseRequest.sponsorMaxVotes = 0
}
try {
purchaseRequest.sponsorMaxRevotes = maxRevotes
} catch (a) {
purchaseRequest.sponsorMaxRevotes = 0
}
try {
purchaseRequest.sponsorIncentive = incentive * 10000
} catch (a) {
purchaseRequest.sponsorIncentive = 0
}
purchaseRequest.sponsorEndDate = endTime
}
}
}
}
PageControl {
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
pages: swiper.count
currentPage: swiper.currentIndex
}

Component {
id: contestantDialog

Dialog {
title: qsTr("Edit Contestant")
contentHeight: window.dp(200)
contentWidth: window.dp(300)

property alias contestantName: contestantName.text
property alias contestantDescription: contestantDescription.text

ColumnLayout {
anchors.fill: parent
anchors.margins: window.dp(8)

AppTextField {
id: contestantName
placeholderText: qsTr("Name")
maximumLength: contestCreator.contestLimits[ContestLimits.ContestantNameLength]
Layout.fillWidth: true
KeyNavigation.tab: contestantDescription
Component.onCompleted: forceActiveFocus(Qt.Popup)
}
ScrollingTextEdit {
id: contestantDescription
Layout.fillHeight: true
Layout.fillWidth: true
textEdit.placeholderText: qsTr("Description")
}
}
}
}
}
106 changes: 106 additions & 0 deletions VotingApp/qml/SponsorshipForm.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import QtQuick 2.5
import QtQuick.Layouts 1.1
import Qt.labs.controls 1.0
import QtQml 2.2

import VPlayApps 1.0

import QtQmlTricks.UiElements 2.0

import FollowMyVote.StakeWeightedVoting 1.0

Flickable {
property alias sponsorshipEnabled: sponsorshipEnabledSwitch.checked
property alias maxVotes: maxVotesField.text
property alias maxRevotes: maxRevotesField.text
readonly property var endTime: {
if (sponsorshipEndTime.currentIdx === 0)
return 0

var date = new Date()
if (sponsorshipEndTime.currentIdx === 1)
date.setDate(date.getDate() + 1)
else if (sponsorshipEndTime.currentIdx === 2)
date.setDate(date.getDate() + 7)
else if (sponsorshipEndTime.currentIdx === 3)
date.setMonth(date.getMonth() + 1)
return date.getTime()
}
property alias incentive: incentiveField.text


flickableDirection: Flickable.VerticalFlick

Column {
ExtraAnchors.topLeftCorner: parent
anchors.margins: window.dp(16)

Row {
AppText {
text: qsTr("Sponsor Votes")
}
AppSwitch {
id: sponsorshipEnabledSwitch
height: window.dp(30)
}
}
Column {
enabled: sponsorshipEnabledSwitch.checked

Row {
AppText {
text: qsTr("Max votes to sponsor")
}
AppTextField {
id: maxVotesField
inputMethodHints: Qt.ImhDigitsOnly
validator: IntValidator { bottom: 0 }
}
}
Row {
AppText {
text: qsTr("Max replacement votes per voter to sponsor")
}
AppTextField {
id: maxRevotesField
inputMethodHints: Qt.ImhDigitsOnly
validator: IntValidator { bottom: 0 }
}
}
Row {
spacing: window.dp(8)

Binding {
target: purchaseRequest
property: "sponsorEndDate"
value: {
}
}

AppText {
id: sponshorshipEndsLabel
text: qsTr("Sponsorship ends")
}
ComboList {
id: sponsorshipEndTime
width: window.dp(100)
model: [qsTr("never"), qsTr("in a day"), qsTr("in a week"), qsTr("in a month")]
delegate: ComboListDelegateForSimpleVar {
label.font: sponshorshipEndsLabel.font
}
Component.onCompleted: currentIdx = 0
}
}
Row {
AppText {
text: qsTr("Voter incentive in VOTE")
}
AppTextField {
id: incentiveField
inputMethodHints: Qt.ImhDigitsOnly
validator: DoubleValidator { bottom: 0; decimals: 4 }
}
}
}
}
}
12 changes: 9 additions & 3 deletions VotingApp/wrappers/PurchaseContestRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
} \
void PurchaseContestRequestWrapper::set ## upperProperty(type property) { \
if (!sponsorshipEnabled()) \
request.getRequest().initSponsorship().initOptions(); \
setSponsorshipEnabled(true); \
_SIMPLE_SETTER_IMPL(property, getSponsorship().getOptions().set ## requestField(property)) \
}

Expand Down Expand Up @@ -101,8 +101,14 @@ QVariantMap PurchaseContestRequestWrapper::submit() {
{"surchargePromise", QVariant::fromValue(qmlPromise)}};
}

void PurchaseContestRequestWrapper::disableSponsorship() {
request.getRequest().initSponsorship().setNoSponsorship();
void PurchaseContestRequestWrapper::setSponsorshipEnabled(bool enabled) {
if (enabled == sponsorshipEnabled())
return;
if (enabled)
request.getRequest().initSponsorship().initOptions();
else
request.getRequest().initSponsorship().setNoSponsorship();
emit sponsorshipEnabledChanged(enabled);
}

SPONSORSHIP_SIMPLE_GETTER_SETTER(sponsorMaxVotes, SponsorMaxVotes, qint64, MaxVotes)
Expand Down
5 changes: 3 additions & 2 deletions VotingApp/wrappers/PurchaseContestRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class PurchaseContestRequestWrapper : public QObject
Q_PROPERTY(QQmlVariantListModel* promoCodes READ promoCodes CONSTANT)
Q_PROPERTY(quint64 weightCoin READ weightCoin WRITE setWeightCoin NOTIFY weightCoinChanged)
Q_PROPERTY(qint64 expiration READ expiration WRITE setExpiration NOTIFY expirationChanged)
Q_PROPERTY(bool sponsorshipEnabled READ sponsorshipEnabled NOTIFY sponsorshipEnabledChanged STORED false)
Q_PROPERTY(bool sponsorshipEnabled READ sponsorshipEnabled WRITE setSponsorshipEnabled
NOTIFY sponsorshipEnabledChanged)
Q_PROPERTY(qint64 sponsorMaxVotes READ sponsorMaxVotes WRITE setSponsorMaxVotes NOTIFY sponsorMaxVotesChanged)
Q_PROPERTY(qint32 sponsorMaxRevotes READ sponsorMaxRevotes WRITE setSponsorMaxRevotes
NOTIFY sponsorMaxRevotesChanged)
Expand Down Expand Up @@ -102,7 +103,7 @@ public slots:
void setExpiration(qint64 expiration);
void setContestType(ContestType::Type contestType);
void setTallyAlgorithm(TallyAlgorithm::Type tallyAlgorithm);
void disableSponsorship();
void setSponsorshipEnabled(bool enabled);
void setSponsorMaxVotes(qint64 sponsorMaxVotes);
void setSponsorMaxRevotes(qint32 sponsorMaxRevotes);
void setSponsorEndDate(qint64 sponsorEndDate);
Expand Down

0 comments on commit a55c209

Please sign in to comment.