diff --git a/samples/apps/forum/README.md b/samples/apps/forum/README.md index c211f7efd..833c17153 100644 --- a/samples/apps/forum/README.md +++ b/samples/apps/forum/README.md @@ -14,11 +14,9 @@ npm start Open your browser at https://127.0.0.1:8000/app/site -Create polls by copy-pasting test/demo/polls.csv. - Generate opinions, user identities and submit: ```sh -python test/demo/generate-opinions.py test/demo/polls.csv 9 +python3.8 test/demo/generate-opinions.py test/demo/polls.csv 9 npm run ts test/demo/generate-jwts.ts . 9 npm run ts test/demo/submit-opinions.ts . ``` diff --git a/samples/apps/forum/src/controllers/poll.ts b/samples/apps/forum/src/controllers/poll.ts index 824f2bca6..2e4d91d5f 100644 --- a/samples/apps/forum/src/controllers/poll.ts +++ b/samples/apps/forum/src/controllers/poll.ts @@ -266,7 +266,6 @@ export class PollController extends Controller { const opinionCountAboveThreshold = Object.keys(poll.opinions).length >= MINIMUM_OPINION_THRESHOLD const response: GetPollResponse = { type: poll.type } - // TODO can repetition be avoided while maintaining type checking? if (poll.type == "string") { response.opinion = poll.opinions[user] if (opinionCountAboveThreshold) { diff --git a/samples/apps/forum/src/controllers/site.ts b/samples/apps/forum/src/controllers/site.ts index 610f55184..bfb7245ba 100644 --- a/samples/apps/forum/src/controllers/site.ts +++ b/samples/apps/forum/src/controllers/site.ts @@ -152,7 +152,7 @@ function isLoggedIn() { method: method, headers: { 'content-type': 'application/json', - 'authorization': 'Bearer ' + jwt, + 'authorization': 'Bearer ' + window.jwt, }, body: body ? JSON.stringify(body) : undefined }) @@ -288,7 +288,9 @@ function isLoggedIn() { xaxis: { zeroline: false, showgrid: false, - tickvals: xtickvals + tickvals: xtickvals, + tickangle: 45, + tickformat: ".1f", }, yaxis: { visible: false, @@ -315,6 +317,7 @@ function isLoggedIn() { title: topic, margin: margin, yaxis: { + visible: false, showgrid: false, }, }, {displayModeBar: false}) @@ -383,24 +386,64 @@ ${HEADER_HTML}

Confidential Forum

-

Blabla
Blablabla.

+

+ This is a simple example application written in TypeScript for the Confidential Consortium Framework. +

+
    +
  1. + Create Polls by providing a list of Name, Type, where Type is one of number, string. +
  2. +
  3. + Submit Opinions as a list of Topic Name, Value. +
  4. +
  5. + Once enough users have posted opinions about a topic, compare your opinion to the consensus. +
  6. +
${FOOTER_HTML} ` +const SAMPLE_POLLS = `\`"Topic","Opinion Type" + +"Contoso, Ltd - Country of Risk",string +"Woodgrove Bank - Country of Risk",string +"Proseware - Country of Risk",string +"Fabrikam - Country of Risk",string + +"Contoso, Ltd - 1Y CDS Spread",number +"Woodgrove Bank - 1Y CDS Spread",number +"Proseware - 1Y CDS Spread",number +"Fabrikam - 1Y CDS Spread",number + +"Contoso, Ltd - 3Y CDS Spread",number +"Woodgrove Bank - 3Y CDS Spread",number +"Proseware - 3Y CDS Spread",number +"Fabrikam - 3Y CDS Spread",number +\`` + const CREATE_POLLS_HTML = ` ${HEADER_HTML}
- +
+ Polls created successfully. + +
+ +
+
@@ -417,25 +460,53 @@ $('#create-polls-btn').addEventListener('click', async () => { window.alert(e) return } - window.alert('Successfully created polls.') + $('.alert').classList.add("show"); $('#input-polls').value = '' }) +$('#sample-polls-btn').addEventListener('click', async () => { + $('#input-polls').value = ${SAMPLE_POLLS} +}) ${FOOTER_HTML} ` +const SAMPLE_OPINIONS = `\`"Topic","Opinion" + +"Contoso, Ltd - Country of Risk",Freedonia +"Woodgrove Bank - Country of Risk",Freedonia +"Proseware - Country of Risk",Freedonia +"Fabrikam - Country of Risk",Snowdonia +"Contoso, Ltd - 1Y CDS Spread",145 +Woodgrove Bank - 1Y CDS Spread,148 +Proseware - 1Y CDS Spread,144 +Fabrikam - 1Y CDS Spread,270 +"Contoso, Ltd - 3Y CDS Spread",153 +Woodgrove Bank - 3Y CDS Spread,159 +Proseware - 3Y CDS Spread,156 +Fabrikam - 3Y CDS Spread,380 +\`` + const SUBMIT_OPINIONS_HTML = ` ${HEADER_HTML}
- +
+ Opinions submitted successfully. + +
+ +
+
@@ -456,10 +527,14 @@ $('#submit-opinions-btn').addEventListener('click', async () => { window.alert(e) return } - window.alert('Successfully submitted opinions.') + $('.alert').classList.add("show"); $('#input-opinions').value = '' }) +$('#sample-opinions-btn').addEventListener('click', async () => { + $('#input-opinions').value = ${SAMPLE_OPINIONS} +}) + ${FOOTER_HTML} ` @@ -469,7 +544,7 @@ ${HEADER_HTML} @@ -480,6 +555,7 @@ ${HEADER_HTML}