diff --git a/etuc-voting.html b/etuc-voting.html deleted file mode 100644 index 240e93864f8e5ebaae29fc981836924235c006b6..0000000000000000000000000000000000000000 --- a/etuc-voting.html +++ /dev/null @@ -1,206 +0,0 @@ -<!DOCTYPE html> -<html> -<head> - <title></title> - <meta charset="UTF-8"> - <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> - <title>SIB Event - Demo</title> - - <script type="module" src="https://unpkg.com/@startinblox/router"></script> - <script type="module" src="https://unpkg.com/@startinblox/core@0.10"></script> - <script type="module" src="https://unpkg.com/@startinblox/component-conversation@0.3"></script> - - <link rel="stylesheet" href="/css/main.css"> - - <script type="module" src="solid-polls.js"></script> - <script type="text/javascript" src="/js/main.js"></script> - <script type="text/javascript" src="/js/polls-math.js"></script> - <script type="module" src="./solid-polls-widget.js"></script> -</head> -<body> - -<p> - <ol class="todo"> - <li>fix user id not added automatically when submitting form. Don't forget to make it mandatory again in models after</li> - </ol> - -</p> - -<div id="pollPage"> - <!--Title--> - <solid-display - id="title" - data-src="http://127.0.0.1:8000/polls/1/" - fields="title" - related-field="" - widget-title="solid-display-h1" - > - </solid-display> - - - <!-- Topline - Image & Sidebar Main info--> - <solid-display - class="topline" - data-src="http://127.0.0.1:8000/polls/1/" - fields="left(image), - right(orgLine(orgImage,hostingOrganisation),dateLine(dateImage,endDate),shortDescription,tags)" - - multiple-tags - - widget-tags="etuc-display-votetags" - - widget-image="solid-display-img" - widget-hostingOrganisation="solid-display-div" - - widget-orgImage="solid-display-div" - value-orgImage="<i class='material-icons'>language</i>" - - widget-endDate="solid-display-date" - widget-dateImage="solid-display-div" - value-dateImage="<i class='material-icons'>update</i>" - - > - </solid-display> - - - <!-- Main description--> - - <solid-display - data-src="http://127.0.0.1:8000/polls/1/" - fields="longDescription" - widget-longDescription="solid-display-div" - > - - </solid-display> - - <!-- votes & debates --> - - <section class="vote-debate-content"> - <div class="vote-debate-tabs"> - <div class="vote-tab-cta active-tab" onclick="showHideBlocks('.vote-tab-cta','.debate-tab-cta','.vote-tab-content','.debate-tab-content','flex')"> - <h2>Vote</h2> - </div> - <div class="debate-tab-cta" onclick="showHideBlocks('.debate-tab-cta','.vote-tab-cta','.debate-tab-content','.vote-tab-content','flex')"> - <h2>Debate</h2> - </div> - </div> - - <div class="border-content padded"> - <div class="vote-tab-content" style="display: flex;"> - <!-- Counter of votes --> - <div class="vote-section"> - <div class="voteCounter"> - </div> - <solid-display - id="poll-votes-values" - data-src="http://127.0.0.1:8000/polls/total_votes/1/" - fields="row1(choiceValue,name), total_votes,progressBar" - - widget-choiceValue="solid-display-div" - widget-progressBar="solid-display-div" - value-progressBar='<div style="width:100%;"><div class="progressBarValue" style="width:1%;"></div></div>' - - > - </solid-display> - - <!--Content voting tab --> - <h3>Your opinion</h3> - <solid-form - data-src="http://127.0.0.1:8000/polls/1/" - nested-field="votes" - - fields="choiceValue,chosenOption" - range-chosenOption="http://127.0.0.1:8000/polls/1/pollOptions/" - - widget-choiceValue="solid-display-div" - widget-chosenOption='solid-form-radio' - label-chosenOption="" - - submit-button="Save my vote" - - > - </solid-form> - </div> - - <div class="share-vote"> - <h3>Invite someone to vote</h3> - <p>email</p> - <p>field</p> - <p>To invite several people seperate the email with a semicolon (;).</p> - <div class="send-share"> - <i class='material-icons white'>send</i> - <input type="submit" value="SEND INVITES"> - </div> - </div> - - </div> - - <div class="debate-tab-content" style="display: none;"> - - <solid-conversation - data-src="http://127.0.0.1:8000/polls/1/" - nested-field="debate" - date-format="DD/MM/YYYY - kk:mm" - > - </solid-conversation> - - - - - </div> - </div> - </section> - <h1>test convo</h1> - <solid-conversation - data-src="http://127.0.0.1:8000/polls/7/" - nested-field="debate"> -</solid-conversation> - - - <!-- widgets --> - - - <solid-widget name="solid-display-backspaced-labelled-div"> - - <template> - ${(await value) ? '<div class="'+await name+'"><p class="label">' + label + '</p></div>':""} - - - - </template> - - </solid-widget> - - <solid-widget name="etuc-display-votetags"> - <template> - <div> - <p> - ${await value} - </p> - </div> - </template> - </solid-widget> - - - <script type="text/javascript"> - - - - </script> - - - - <solid-widget name="solid-display-h1"> - <template> - ${await value ? '<h1>'+ value +'</h1>' :""} - </template> - </solid-widget> - - -</div> - - - - -</body> -</html> \ No newline at end of file diff --git a/form.html b/form.html deleted file mode 100644 index 5a16edf71efc18221073250fc3d4ef3a0dfe23a7..0000000000000000000000000000000000000000 --- a/form.html +++ /dev/null @@ -1,113 +0,0 @@ - -<!DOCTYPE html> -<html> -<head> - <title></title> - <meta charset="UTF-8"> - <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> - <title>SIB Event - Demo</title> - - <script type="module" src="https://unpkg.com/@startinblox/router"></script> - <script type="module" src="https://unpkg.com/@startinblox/core@0.10"></script> - <script type="module" src="https://unpkg.com/@startinblox/component-conversation"></script> - - <link rel="stylesheet" href="/css/main.css"> - - <script type="module" src="solid-polls.js"></script> - <script type="text/javascript" src="./js/main.js"></script> - <script type="text/javascript" src="polls-math.js"></script> - <script type="module" src="./solid-polls-widget.js"></script> -</head> - -<body> - <div id="add-survey"> - <div class="form-intro"> - <h2>Post a new survey</h2> - <p>This form allow you to share a new survey</p> - </div> - <solid-form - data-src="http://127.0.0.1:8000/polls/" - nested-fields='pollOptions' - fields="main( - title,titleNote,hostingOrganisation,shortDescription,longDescription), - surveyOptions( - sectionOptionTitle,pollOptions), - surveyInfo( - sectionInfoTitle,dates(startDate,endDate),image,tags)" - - widget-title="solid-form-label-text" - label-title="Survey title*" - - widget-titleNote="solid-display-div" - value-titleNote="Be clear on your survey title to helps users understand what is it about" - class-titleNote="form-tips" - - widget-hostingOrganisation="solid-form-label-text" - label-hostingOrganisation="Organisation" - - widget-shortDescription="solid-form-label-text" - label-shortDescription="Short Presentation*" - - widget-longDescription="solid-form-textarea" - label-longDescription="Full Description*" - - widget-pollOptions="custom-choix" - multiple-pollOptions - label-pollOptions="" - - widget-image="solid-form-file-image" - label-image="Photo :" - upload-url-image="http://127.0.0.1:8000/upload/" - - widget-sectionOptionTitle="solid-display-div" - value-sectionOptionTitle="Vote options" - class-sectionOptionTitle="h3-like" - - widget-options="solid-display-div" - value-options="Vote options to add here" - - widget-sectionInfoTitle="solid-display-div" - value-sectionInfoTitle="Survey Information" - class-sectionInfoTitle="h3-like" - - widget-startDate="solid-form-date" - label-startDate="START DATE*" - - widget-endDate="solid-form-date" - label-endDate="END DATE*" - - widget-tags="solid-form-auto-completion" - multiple-tags='solid-multiple-select' - range-tags="http://127.0.0.1:8000/tags/" - label-tags="Tags" - - ></solid-form> - - - <solid-widget name="custom-choix"> - <template> - <solid-form - data-src="${value}" - data-holder - naked - fields="name" - label-name="New option" - ></solid-form> - </template> - </solid-widget> - - <solid-widget name="custom-tag"> - <template> - <solid-form - data-src="${value}" - data-holder - naked - fields="name" - label-name="Add keyword" - ></solid-form> - </template> - </solid-widget> - </div> - -</body> -</html> \ No newline at end of file diff --git a/js/main.js b/js/main.js index b5d0e8720b899afb51f4ba30b43eb4c2f32d24ec..5654bad99f0d2220d982adab51cc88752e550319 100644 --- a/js/main.js +++ b/js/main.js @@ -291,9 +291,13 @@ function disableVotes(){ if (comparisonStartDate > date) { let errorMessage = "This poll hasn't started yet, you can start voting on :" + startDate+"."; deactivateButton(errorMessage); - } else if(comparisonEndDate <= date) { + } else if(comparisonEndDate < date) { let errorMessage = "This poll is closed since : " + endDate+"."; deactivateButton(errorMessage); + } + else if(comparisonEndDate = date) { + let errorMessage = "Today is the last day to vote!"; + activateButton(); } else{ activateButton(); diff --git a/js/polls-math.js b/js/polls-math.js index 8026a8dd2bbc776027db3ec189aa7d36953b559d..871c1403a7f5d2cef0a7eba39569d40227199322 100644 --- a/js/polls-math.js +++ b/js/polls-math.js @@ -16,168 +16,186 @@ function firstLoad(){ let elementsLoaded = document.querySelector("solid-display"); //console.log("elements loaded are",elementsLoaded); - if (!elementsLoaded) throw "no elements yet"; - const dataSourceURI = elementsLoaded.dataset.src; - const urlComponents = new URL(dataSourceURI); - const dataSourceDomain = urlComponents.origin; - ////console.log("the data domain is",dataSourceDomain); - - ////console.log("elements are there, updating id's"); - getPollTotalInfo(dataSourceDomain); - - document.querySelector("solid-form[name=addPoll]").addEventListener("populate",()=> { - //console.log("populating add form"); - newOptionContent(); - }); + if (!elementsLoaded){ + console.log("no elements yet"); + setTimeout(() => { + firstLoad(); + }, 500); + } + else{ + const dataSourceURI = elementsLoaded.dataset.src; + const urlComponents = new URL(dataSourceURI); + const dataSourceDomain = urlComponents.origin; + ////console.log("the data domain is",dataSourceDomain); + + ////console.log("elements are there, updating id's"); + getPollTotalInfo(dataSourceDomain); + + document.querySelector("solid-form[name=addPoll]").addEventListener("populate",()=> { + //console.log("populating add form"); + newOptionContent(); + }); - /***** - Updates on navigate - */ - document.querySelector("solid-router").addEventListener("navigate",()=> { - getPollTotalInfo(dataSourceDomain); - updateFormSource(); + /***** + Updates on navigate + */ + document.querySelector("solid-router").addEventListener("navigate",()=> { + console.log("navigating"); + getPollTotalInfo(dataSourceDomain); + updateFormSource(); - }); - //refresh display of total votes on a poll - document.querySelector("#poll-votes-values").addEventListener("populate",() => { - refreshTotalVotes(); - }); + }); + //refresh display of total votes on a poll + document.querySelector("#poll-votes-values").addEventListener("populate",() => { + console.log("populating"); + refreshTotalVotes(); + }); - //refresh total votes when user votes - document.querySelector("solid-form#poll-votes-form").addEventListener("save",()=> { - refreshVoteDataSrc(); - }); + //refresh total votes when user votes + document.querySelector("solid-form#poll-votes-form").addEventListener("save",()=> { + refreshVoteDataSrc(); + }); - /********* - * Get info on the current poll - *********/ - function getPollTotalInfo(dataSourceDomain){ - //get value of data-scr linked to poll page - const pollPage = document.querySelector("#pollPage"); - const pageTitle = pollPage.querySelectorAll("solid-display[id=title]"); - ////console.log("page title is",pageTitle); - //console.log("getting total poll info for the domaine",dataSourceDomain); + /********* + * Get info on the current poll + *********/ + function getPollTotalInfo(dataSourceDomain){ + //get value of data-scr linked to poll page + const pollPage = document.querySelector("#pollPage"); + const pageTitle = pollPage.querySelectorAll("solid-display[id=title]"); + ////console.log("page title is",pageTitle); + //console.log("getting total poll info for the domaine",dataSourceDomain); - for (let i = 0; i < pageTitle.length; i++){ - //if to deal with error - if(pageTitle[i] == "" || null) continue - - //get the data src node of first sib display & extract the url - const dataSrc = pageTitle[i].dataset.src; - //extract current poll ID from the data src - const pollId = dataSrc.match(/\/([0-9]+)\/$/)[1]; - /*push to function that will take the value of ID - & - push it to the poll option data range - push it to the total polls data-src - */ - setCurrentPollOptions(dataSourceDomain,pollPage,pollId); - setTotalResultId(dataSourceDomain,pollPage,pollId); - } - } - /** - * push poll ID into data-scr url of current poll - */ - function setTotalResultId(dataSourceDomain,currentPage,currentId){ - //get the vote blocks - ////console.log("setting currnt source"); - const currentPollValues = currentPage.querySelectorAll("[id=poll-votes-values]")[0]; - //add the poll number - const currentPollSrc = dataSourceDomain + "/polls/total_votes/" + currentId + "/"; - ////console.log("the domaine here is : ", dataSourceDomain,currentPollSrc); - //push the reconstructed data src to the HTML - currentPage.querySelector("[id=poll-votes-values]").dataset.src = currentPollSrc; - } + for (let i = 0; i < pageTitle.length; i++){ + //if to deal with error + if(pageTitle[i] == "" || null || undefined){ + console.log("there's no page title"); + } + else{ + //get the data src node of first sib display & extract the url + const dataSrc = pageTitle[i].dataset.src; + console.log("data src is",dataSrc,"and title page is", pageTitle[i]); + console.log(pageTitle[i].dataset.src); + //extract current poll ID from the data src + const pollId = dataSrc.match(/\/([0-9]+)\/$/)[1]; + /*push to function that will take the value of ID + & + push it to the poll option data range + push it to the total polls data-src + */ + setCurrentPollOptions(dataSourceDomain,pollPage,pollId); + setTotalResultId(dataSourceDomain,pollPage,pollId); + } + } + } + /** + * push poll ID into data-scr url of current poll + */ + function setTotalResultId(dataSourceDomain,currentPage,currentId){ + //get the vote blocks + ////console.log("setting currnt source"); + const currentPollValues = currentPage.querySelectorAll("[id=poll-votes-values]")[0]; + //add the poll number + const currentPollSrc = dataSourceDomain + "/polls/total_votes/" + currentId + "/"; + ////console.log("the domaine here is : ", dataSourceDomain,currentPollSrc); + //push the reconstructed data src to the HTML + currentPage.querySelector("[id=poll-votes-values]").dataset.src = currentPollSrc; + } - /** - * push poll ID into data-scr url poll options - */ - function setCurrentPollOptions(dataSourceDomain,currentPage,currentId){ - //add the poll option number within the URL of the options - //get the form block - const formContent = currentPage.querySelector("[id=poll-votes-form]"); - if(formContent == null) throw "there's no formContent with the id poll-votes-form"; - //get the range for option choices - const newOptionRange = dataSourceDomain+"/polls/"+currentId+"/pollOptions/"; - //push new - formContent.setAttribute('range-chosenoption',newOptionRange); - } + /** + * push poll ID into data-scr url poll options + */ + function setCurrentPollOptions(dataSourceDomain,currentPage,currentId){ + //add the poll option number within the URL of the options + //get the form block + const formContent = currentPage.querySelector("[id=poll-votes-form]"); + if(formContent == null){ + throw "there's no formContent with the id poll-votes-form"; + } + else{ + //get the range for option choices + const newOptionRange = dataSourceDomain+"/polls/"+currentId+"/pollOptions/"; + //push new + formContent.setAttribute('range-chosenoption',newOptionRange); + } + } - /*********************************************************** - * BELOW SCRIPT TO UPDATE VALUES WITHIN A POLL - * - 1. Get the values of the displayed totals of each poll options - calculate the percentage & display them - - 2. Functions that take advantage of process done in 1 in order to - personnalise content & css within the vote tab - ***********************************************************/ - function refreshTotalVotes(){ - //get all the polls - const pollVoteValues = document.querySelectorAll("#poll-votes-values"); - for (let i = 0; i < pollVoteValues.length; i++){ - //for each poll get the totals of each option - const voteOptionResults = pollVoteValues[i].querySelectorAll("[name=total_votes]"); - let totalCount = 0; - let choiceNumber = 0; - //add option total to the global tally - for(let y = 0; y < voteOptionResults.length; y++){ - const currentValue = parseInt(voteOptionResults[y].innerHTML); - if (!Number.isNaN(currentValue)){ - totalCount = totalCount + currentValue; - } - else{ - console.log("it's Cheese NaN"); - } - } - //launch function to display the number of votes in HTML - //console.log("about to refresh dsplayed total",totalCount); - displayTotalVotes(pollVoteValues[i],totalCount); + /*********************************************************** + * BELOW SCRIPT TO UPDATE VALUES WITHIN A POLL + * + 1. Get the values of the displayed totals of each poll options + calculate the percentage & display them + + 2. Functions that take advantage of process done in 1 in order to + personnalise content & css within the vote tab + ***********************************************************/ + function refreshTotalVotes(){ + //get all the polls + const pollVoteValues = document.querySelectorAll("#poll-votes-values"); + for (let i = 0; i < pollVoteValues.length; i++){ + //for each poll get the totals of each option + const voteOptionResults = pollVoteValues[i].querySelectorAll("[name=total_votes]"); + let totalCount = 0; + let choiceNumber = 0; + //add option total to the global tally + for(let y = 0; y < voteOptionResults.length; y++){ + const currentValue = parseInt(voteOptionResults[y].innerHTML); + if (!Number.isNaN(currentValue)){ + totalCount = totalCount + currentValue; + } + else{ + console.log("it's Cheese NaN"); + } + } + //launch function to display the number of votes in HTML + //console.log("about to refresh dsplayed total",totalCount); + displayTotalVotes(pollVoteValues[i],totalCount); - /*now that we have the values & the totals we can calculate the %ge of each option - we will also take advantage of this step to launch the functions that set - the background color and the choice number*/ + /*now that we have the values & the totals we can calculate the %ge of each option + we will also take advantage of this step to launch the functions that set + the background color and the choice number*/ - for(let z = 0; z < voteOptionResults.length; z++){ - const currentValue = parseInt(voteOptionResults[z].innerHTML); + for(let z = 0; z < voteOptionResults.length; z++){ + const currentValue = parseInt(voteOptionResults[z].innerHTML); - const percentageBarField = voteOptionResults[z].nextElementSibling; + const percentageBarField = voteOptionResults[z].nextElementSibling; - if (!Number.isNaN(currentValue)) { - const percentageOfTotal = ((currentValue/totalCount)*100).toFixed(2)+"%"; - percentageBarField.querySelector(".progressBarValue").innerHTML = percentageOfTotal; - percentageBarField.querySelector(".progressBarValue").style.width = percentageOfTotal; + if (!Number.isNaN(currentValue)) { + const percentageOfTotal = ((currentValue/totalCount)*100).toFixed(2)+"%"; + percentageBarField.querySelector(".progressBarValue").innerHTML = percentageOfTotal; + percentageBarField.querySelector(".progressBarValue").style.width = percentageOfTotal; - } - else{ - const percentageOfTotal = ""; - percentageBarField.querySelector(".progressBarValue").innerHTML = "0%"; - } - setChoiceColor(percentageBarField,choiceNumber); - choiceNumber = choiceNumber + 1; - if (choiceNumber > 3 ) { - choiceNumber = 1; - } - } - //launch the function that will display the choice number - setChoiceNumber(pollVoteValues[i]); - } - } + } + else{ + const percentageOfTotal = ""; + percentageBarField.querySelector(".progressBarValue").innerHTML = "0%"; + } + setChoiceColor(percentageBarField,choiceNumber); + choiceNumber = choiceNumber + 1; + if (choiceNumber > 3 ) { + choiceNumber = 1; + } + } + //launch the function that will display the choice number + setChoiceNumber(pollVoteValues[i]); + } + } - /********************** - Refresh vote results when someone submits a vote - ***********************/ + /********************** + Refresh vote results when someone submits a vote + ***********************/ - function refreshVoteDataSrc(){ - let pollTotalVotes = document.querySelector("solid-display#poll-votes-values"); - pollTotalVotes.dataset.src = pollTotalVotes.dataset.src+"?"+Date.now(); - //math.random() to break sib cache and actually get now values - ////console.log("after the string is",pollTotalVotes.dataset.src); - getPollTotalInfo(dataSourceDomain); - refreshTotalVotes(); - } + function refreshVoteDataSrc(){ + let pollTotalVotes = document.querySelector("solid-display#poll-votes-values"); + pollTotalVotes.dataset.src = pollTotalVotes.dataset.src+"?"+Date.now(); + //math.random() to break sib cache and actually get now values + ////console.log("after the string is",pollTotalVotes.dataset.src); + getPollTotalInfo(dataSourceDomain); + refreshTotalVotes(); + } + } } function updateFormSource(){ @@ -208,12 +226,11 @@ function setChoiceColor(currentProgressBar, choiceNumber){ 'background-first-color', 'background-second-color', 'background-third-color', -] - if(colors[choiceNumber] == null) - choiceNumber = 0; - + ] + if(colors[choiceNumber] == null){ + choiceNumber = 0; + } currentProgressBar.querySelector(".progressBarValue").classList.add(colors[choiceNumber]); - } function displayTotalVotes(poll,totalCount){