Browse Source

new versions, WIP

integrate_codes_to_fields
anghenfil 3 years ago
parent
commit
ada9d8a5de
  1. 435
      .idea/workspace.xml
  2. 5
      Cargo.toml
  3. 2
      Rocket.toml
  4. 4
      src/database/mod.rs
  5. 4
      src/main.rs
  6. 41
      src/utils/poll_generator.rs
  7. 35
      src/webserver/delivery.rs
  8. 3
      src/webserver/mod.rs
  9. 8
      src/webserver/session_manager.rs
  10. 170
      src/webserver/sites.rs
  11. 25
      src/webserver/styles.rs
  12. 0
      src/webserver/templates.rs
  13. 4
      style/global.css
  14. 16
      style/poll.css
  15. 11
      style/poll.js

435
.idea/workspace.xml

@ -10,16 +10,23 @@
</component>
<component name="ChangeListManager">
<list default="true" id="77587fc1-3757-4042-86e1-b4a4e81ff6db" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/database/code_management.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/webserver/templates.rs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/style/poll.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Rocket.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Rocket.toml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0.html" beforeDir="false" afterPath="$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-1.html" beforeDir="false" afterPath="$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-1.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/polls/poll-1/poll.json" beforeDir="false" afterPath="$PROJECT_DIR$/data/polls/poll-1/poll.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/polls/poll-1/result.csv" beforeDir="false" afterPath="$PROJECT_DIR$/data/polls/poll-1/result.csv" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/database/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/database/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/filecache/cache.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/filecache/cache.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils/poll_generator.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/poll_generator.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/webserver/delivery.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/webserver/delivery.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/webserver/mod.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/webserver/mod.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/webserver/session_manager.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/webserver/session_manager.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/webserver/sites.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/webserver/sites.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/style/dashboard.css" beforeDir="false" afterPath="$PROJECT_DIR$/style/dashboard.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/webserver/styles.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/webserver/styles.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/style/global.css" beforeDir="false" afterPath="$PROJECT_DIR$/style/global.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/style/poll.css" beforeDir="false" afterPath="$PROJECT_DIR$/style/poll.css" afterDir="false" />
</list>
@ -33,11 +40,12 @@
<session id="-2001885257">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="17" />
<entry key="project.closed" value="23" />
<entry key="project.open.time.3" value="1" />
<entry key="project.open.time.30" value="1" />
<entry key="project.open.time.31" value="2" />
<entry key="project.open.time.33" value="2" />
<entry key="project.open.time.31" value="3" />
<entry key="project.open.time.32" value="1" />
<entry key="project.open.time.33" value="4" />
<entry key="project.open.time.34" value="2" />
<entry key="project.open.time.35" value="1" />
<entry key="project.open.time.36" value="1" />
@ -46,60 +54,66 @@
<entry key="project.open.time.4" value="1" />
<entry key="project.open.time.42" value="2" />
<entry key="project.open.time.44" value="1" />
<entry key="project.open.time.46" value="2" />
<entry key="project.open.time.46" value="3" />
<entry key="project.open.time.47" value="1" />
<entry key="project.open.time.51" value="1" />
<entry key="project.open.time.66" value="1" />
<entry key="project.open.time.86" value="1" />
<entry key="project.opened" value="22" />
<entry key="project.open.time.94" value="1" />
<entry key="project.opened" value="28" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="blockinfo" value="2" />
<entry key="css" value="15" />
<entry key="csv" value="8" />
<entry key="html" value="9" />
<entry key="css" value="20" />
<entry key="csv" value="12" />
<entry key="html" value="12" />
<entry key="iml" value="1" />
<entry key="json" value="10" />
<entry key="js" value="1" />
<entry key="json" value="15" />
<entry key="lock" value="1" />
<entry key="pollinfo" value="1" />
<entry key="q1" value="1" />
<entry key="question-1" value="1" />
<entry key="rs" value="137" />
<entry key="toml" value="14" />
<entry key="rs" value="169" />
<entry key="toml" value="24" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="CSS" value="15" />
<entry key="HTML" value="9" />
<entry key="CSS" value="20" />
<entry key="HTML" value="12" />
<entry key="IDEA_MODULE" value="1" />
<entry key="JSON" value="10" />
<entry key="PLAIN_TEXT" value="28" />
<entry key="Rust" value="136" />
<entry key="JSON" value="15" />
<entry key="JavaScript" value="1" />
<entry key="PLAIN_TEXT" value="43" />
<entry key="Rust" value="168" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="blockinfo" value="81" />
<entry key="css" value="355" />
<entry key="csv" value="4" />
<entry key="css" value="573" />
<entry key="csv" value="5" />
<entry key="html" value="47" />
<entry key="json" value="344" />
<entry key="js" value="393" />
<entry key="json" value="2281" />
<entry key="pollinfo" value="270" />
<entry key="question-1" value="15" />
<entry key="rs" value="27356" />
<entry key="toml" value="180" />
<entry key="txt" value="97" />
<entry key="rs" value="30652" />
<entry key="toml" value="288" />
<entry key="txt" value="111" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="CSS" value="355" />
<entry key="CSS" value="573" />
<entry key="HTML" value="47" />
<entry key="JSON" value="344" />
<entry key="PLAIN_TEXT" value="647" />
<entry key="Rust" value="27356" />
<entry key="JSON" value="2281" />
<entry key="JavaScript" value="393" />
<entry key="PLAIN_TEXT" value="770" />
<entry key="Rust" value="30652" />
</counts>
</usages-collector>
</session>
@ -109,64 +123,24 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/webserver/sites.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="175">
<caret line="198" column="44" selection-start-line="198" selection-start-column="44" selection-end-line="198" selection-end-column="44" />
<state relative-caret-position="617">
<caret line="97" lean-forward="true" selection-start-line="97" selection-end-line="97" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/database/mod.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="1" column="16" lean-forward="true" selection-start-line="1" selection-start-column="16" selection-end-line="1" selection-end-column="16" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/utils/poll_generator.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="646">
<caret line="38" column="70" selection-start-line="38" selection-start-column="70" selection-end-line="38" selection-end-column="70" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/webserver/delivery.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="45" column="9" lean-forward="true" selection-start-line="45" selection-start-column="9" selection-end-line="45" selection-end-column="9" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/poll.json">
<entry file="file://$PROJECT_DIR$/src/webserver/mod.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85">
<caret line="5" column="26" lean-forward="true" selection-start-line="5" selection-start-column="26" selection-end-line="5" selection-end-column="26" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/database/code_management.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="1" column="30" selection-start-line="1" selection-start-column="30" selection-end-line="1" selection-end-column="30" />
<caret line="5" column="4" lean-forward="true" selection-start-line="5" selection-start-column="4" selection-end-line="5" selection-end-column="4" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/webserver/session_manager.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" selection-start-line="2" selection-end-line="2" selection-end-column="30" />
</state>
</provider>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/webserver/templates.rs">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
</leaf>
@ -177,21 +151,42 @@
<option value="Rust File" />
<option value="CSS File" />
<option value="HTML File" />
<option value="JavaScript File" />
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>cache2</find>
<find>submit</find>
<find>parts[1</find>
<find>json</find>
<find>SESSIONS</find>
<find>read</find>
<find>unsafe</find>
<find>pr</find>
<find>/q</find>
<find>complete</find>
<find>Digip</find>
<find>Digi</find>
<find>poll-1</find>
<find>format</find>
<find>logo</find>
<find>form</find>
<find>onsubmit</find>
<find>on_submit</find>
<find>continu</find>
<find>script</find>
<find>button</find>
<find>style</find>
<find>Continue</find>
<find>Continu</find>
<find>unwrap</find>
<find>submitted</find>
<find>temp.</find>
<find>status::Cu</find>
<find>data.fields</find>
<find>data</find>
<find>data_fields</find>
<find>temp</find>
<find>write</find>
<find>completed</find>
<find>if(comp</find>
<find>session</find>
<find>result</find>
</findStrings>
</component>
<component name="Git.Settings">
@ -216,25 +211,27 @@
<option value="$PROJECT_DIR$/data/polls/poll-1/questionblocks/block-1/block-1.html" />
<option value="$PROJECT_DIR$/src/utils/filesystem.rs" />
<option value="$PROJECT_DIR$/src/utils/mod.rs" />
<option value="$PROJECT_DIR$/Rocket.toml" />
<option value="$PROJECT_DIR$/Cargo.toml" />
<option value="$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0/q2.html" />
<option value="$PROJECT_DIR$/src/main.rs" />
<option value="$PROJECT_DIR$/src/webserver/styles.rs" />
<option value="$PROJECT_DIR$/src/filecache/cache.rs" />
<option value="$PROJECT_DIR$/src/webserver/session_manager.rs" />
<option value="$PROJECT_DIR$/data/polls/poll-1/poll.json" />
<option value="$PROJECT_DIR$/data/polls/poll-1/result.csv" />
<option value="$PROJECT_DIR$/src/webserver/formdata.rs" />
<option value="$PROJECT_DIR$/style/global.css" />
<option value="$PROJECT_DIR$/style/dashboard.css" />
<option value="$PROJECT_DIR$/style/poll.css" />
<option value="$PROJECT_DIR$/src/webserver/mod.rs" />
<option value="$PROJECT_DIR$/src/database/code_management.rs" />
<option value="$PROJECT_DIR$/data/polls/poll-1/result.csv" />
<option value="$PROJECT_DIR$/Rocket.toml" />
<option value="$PROJECT_DIR$/style/global.css" />
<option value="$PROJECT_DIR$/src/webserver/images.rs" />
<option value="$PROJECT_DIR$/src/main.rs" />
<option value="$PROJECT_DIR$/src/database/mod.rs" />
<option value="$PROJECT_DIR$/src/utils/poll_generator.rs" />
<option value="$PROJECT_DIR$/style/poll.js" />
<option value="$PROJECT_DIR$/src/webserver/delivery.rs" />
<option value="$PROJECT_DIR$/src/database/code_management.rs" />
<option value="$PROJECT_DIR$/src/webserver/styles.rs" />
<option value="$PROJECT_DIR$/style/poll.css" />
<option value="$PROJECT_DIR$/src/utils/poll_generator.rs" />
<option value="$PROJECT_DIR$/src/webserver/session_manager.rs" />
<option value="$PROJECT_DIR$/data/polls/poll-1/poll.json" />
<option value="$PROJECT_DIR$/src/webserver/sites.rs" />
<option value="$PROJECT_DIR$/Cargo.toml" />
<option value="$PROJECT_DIR$/src/webserver/mod.rs" />
</list>
</option>
</component>
@ -245,17 +242,14 @@
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="110" />
<option name="y" value="12" />
<option name="width" value="1221" />
<option name="height" value="756" />
<option name="width" value="842" />
<option name="height" value="768" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
@ -268,19 +262,6 @@
<item name="DigiPoll" type="462c0819:PsiDirectoryNode" />
<item name="data" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="DigiPoll" type="b2602c69:ProjectViewProjectNode" />
<item name="DigiPoll" type="462c0819:PsiDirectoryNode" />
<item name="data" type="462c0819:PsiDirectoryNode" />
<item name="polls" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="DigiPoll" type="b2602c69:ProjectViewProjectNode" />
<item name="DigiPoll" type="462c0819:PsiDirectoryNode" />
<item name="data" type="462c0819:PsiDirectoryNode" />
<item name="polls" type="462c0819:PsiDirectoryNode" />
<item name="poll-1" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="DigiPoll" type="b2602c69:ProjectViewProjectNode" />
<item name="DigiPoll" type="462c0819:PsiDirectoryNode" />
@ -315,16 +296,23 @@
<item name="DigiPoll" type="462c0819:PsiDirectoryNode" />
<item name="style" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="DigiPoll" type="b2602c69:ProjectViewProjectNode" />
<item name="DigiPoll" type="462c0819:PsiDirectoryNode" />
<item name="style" type="462c0819:PsiDirectoryNode" />
<item name="js" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
<pane id="PackagesPane" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="DefaultHtmlFileTemplate" value="HTML File" />
<property name="SearchEverywhereHistoryKey" value="commit&#9;ACTION&#9;CheckinProject&#10;Commit&#9;ACTION&#9;CheckinProject&#10;reformat&#9;ACTION&#9;ReformatCode&#10;ref&#9;ACTION&#9;IncomingChanges.Refresh&#10;Reformat&#9;ACTION&#9;ReformatCode&#10;format&#9;ACTION&#9;ReformatCode&#10;plugin&#9;ACTION&#9;WelcomeScreen.Plugins&#10;Plugin&#9;ACTION&#9;WelcomeScreen.Plugins&#10;push&#9;ACTION&#9;Vcs.Push" />
<property name="SearchEverywhereHistoryKey" value="Commit&#9;ACTION&#9;CheckinProject&#10;reformat code&#9;ACTION&#9;ReformatCode&#10;Reformat&#9;ACTION&#9;ReformatCode&#10;commit&#9;ACTION&#9;CheckinProject&#10;reformat&#9;ACTION&#9;ReformatCode&#10;ref&#9;ACTION&#9;IncomingChanges.Refresh&#10;format&#9;ACTION&#9;ReformatCode&#10;plugin&#9;ACTION&#9;WelcomeScreen.Plugins&#10;Plugin&#9;ACTION&#9;WelcomeScreen.Plugins&#10;push&#9;ACTION&#9;Vcs.Push" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1549401259949" />
@ -336,15 +324,16 @@
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/utils" />
<recent name="$PROJECT_DIR$/src/webserver" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/webserver" />
<recent name="$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0" />
<recent name="$PROJECT_DIR$/src/utils" />
<recent name="$PROJECT_DIR$/src/database" />
<recent name="$PROJECT_DIR$/src/filecache" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/data/logos" />
<recent name="$PROJECT_DIR$/src/utils" />
<recent name="$PROJECT_DIR$/src/webserver" />
</key>
</component>
@ -403,7 +392,13 @@
<workItem from="1550841378832" duration="23027000" />
<workItem from="1551026115070" duration="19923000" />
<workItem from="1551082519467" duration="11639000" />
<workItem from="1551132275468" duration="17491000" />
<workItem from="1551132275468" duration="17594000" />
<workItem from="1551184788684" duration="8845000" />
<workItem from="1551208673752" duration="14794000" />
<workItem from="1551255138385" duration="12428000" />
<workItem from="1551394261806" duration="32000" />
<workItem from="1551648633689" duration="310000" />
<workItem from="1551654833472" duration="217000" />
</task>
<task id="LOCAL-00001" summary="New project structure">
<created>1547901316778</created>
@ -426,11 +421,18 @@
<option name="project" value="LOCAL" />
<updated>1551086888389</updated>
</task>
<option name="localTasksCounter" value="4" />
<task id="LOCAL-00004" summary="progress">
<created>1551151990528</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1551151990529</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="161446000" />
<option name="totallyTimeSpent" value="198175000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
@ -445,7 +447,7 @@
<frame x="0" y="0" width="1366" height="768" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.26359516" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.28247735" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" />
@ -454,16 +456,16 @@
<window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.328594" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.49773413" visible="true" weight="0.3270142" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.49773413" weight="0.30805686" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39968404" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" weight="0.328594" />
<window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Terminal" order="8" sideWeight="0.49848944" weight="0.328594" />
<window_info anchor="bottom" id="Terminal" order="8" sideWeight="0.49848944" weight="0.3280757" />
<window_info anchor="bottom" id="Event Log" order="9" sideWeight="0.50151056" side_tool="true" weight="0.328594" />
<window_info anchor="bottom" id="Version Control" order="10" />
<window_info anchor="bottom" id="Messages" order="11" weight="0.328594" />
<window_info active="true" anchor="bottom" id="Messages" order="11" visible="true" weight="0.328594" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@ -520,7 +522,8 @@
<MESSAGE value="Update" />
<MESSAGE value="Added example json, added html generator" />
<MESSAGE value="Refactored" />
<option name="LAST_COMMIT_MESSAGE" value="Refactored" />
<MESSAGE value="progress" />
<option name="LAST_COMMIT_MESSAGE" value="progress" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/Generator.iml">
@ -531,13 +534,6 @@
<entry file="file://$PROJECT_DIR$/src/webserver/src/lib/sites.rs" />
<entry file="file://$PROJECT_DIR$/src/webserver/src/lib/lib.rs" />
<entry file="file://$PROJECT_DIR$/src/webserver/lib/delivery.rs" />
<entry file="file://$PROJECT_DIR$/src/filecache/mod.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="2" column="20" lean-forward="true" selection-start-line="2" selection-start-column="20" selection-end-line="2" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/data/polls/poll-1-old/pollinfo">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="75">
@ -577,176 +573,197 @@
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0/block.html" />
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0/q1" />
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0/q1.html" />
<entry file="file://$PROJECT_DIR$/Rocket.toml">
<entry file="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/rocket-0.4.0/src/response/status.rs">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0/q2.html" />
<entry file="file://$PROJECT_DIR$/src/filecache/cache_error.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="1" column="18" selection-start-line="1" selection-start-column="18" selection-end-line="1" selection-end-column="18" />
<state relative-caret-position="238">
<caret line="14" column="33" selection-start-line="14" selection-start-column="33" selection-end-line="14" selection-end-column="33" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/rocket-0.4.0/src/response/status.rs">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/Cargo.toml">
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="170">
<caret line="10" column="14" selection-start-line="10" selection-start-column="14" selection-end-line="10" selection-end-column="14" />
<state relative-caret-position="478">
<caret line="35" column="28" lean-forward="true" selection-start-line="35" selection-start-column="28" selection-end-line="35" selection-end-column="28" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0/q2.html" />
<entry file="file://$PROJECT_DIR$/src/main.rs">
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-1.html">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/utils/mod.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="136">
<caret line="8" column="18" selection-start-line="8" selection-start-column="18" selection-end-line="8" selection-end-column="18" />
<state relative-caret-position="17">
<caret line="1" column="8" selection-start-line="1" selection-start-column="8" selection-end-line="1" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/filecache/cache_error.rs">
<entry file="file://$PROJECT_DIR$/style/dashboard.css">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="14" column="33" selection-start-line="14" selection-start-column="33" selection-end-line="14" selection-end-column="33" />
<state relative-caret-position="-647">
<caret line="1" column="30" selection-start-line="1" selection-start-column="30" selection-end-line="1" selection-end-column="30" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/webserver/styles.rs">
<entry file="file://$PROJECT_DIR$/src/webserver/formdata.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="155">
<caret line="10" column="27" selection-start-line="10" selection-start-column="27" selection-end-line="10" selection-end-column="27" />
<state relative-caret-position="-18">
<caret line="5" column="24" lean-forward="true" selection-start-line="5" selection-start-column="24" selection-end-line="5" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-0.html">
<entry file="file://$PROJECT_DIR$/src/filecache/cached_file.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="478">
<caret line="35" column="28" lean-forward="true" selection-start-line="35" selection-start-column="28" selection-end-line="35" selection-end-column="28" />
<state relative-caret-position="363">
<caret line="35" column="89" selection-start-line="35" selection-start-column="89" selection-end-line="35" selection-end-column="89" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-1.html">
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-5.html">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/database/database.rs">
<entry file="file://$PROJECT_DIR$/Rocket.toml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="15" column="12" selection-start-line="15" selection-start-column="11" selection-end-line="15" selection-end-column="12" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/cache/questionblock-2.html">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/utils/mod.rs">
<entry file="file://$PROJECT_DIR$/style/global.css">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="1" column="8" selection-start-line="1" selection-start-column="8" selection-end-line="1" selection-end-column="8" />
<state relative-caret-position="204">
<caret line="12" column="1" selection-start-line="12" selection-start-column="1" selection-end-line="12" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/result.csv">
<entry file="file://$PROJECT_DIR$/src/filecache/mod.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="9" lean-forward="true" selection-start-line="9" selection-end-line="9" />
<state relative-caret-position="34">
<caret line="2" column="20" lean-forward="true" selection-start-line="2" selection-start-column="20" selection-end-line="2" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/style/global.css">
<entry file="file://$PROJECT_DIR$/src/filecache/cache.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="14" column="1" lean-forward="true" selection-start-line="14" selection-start-column="1" selection-end-line="14" selection-end-column="1" />
<state relative-caret-position="311">
<caret line="21" column="45" selection-start-line="21" selection-start-column="45" selection-end-line="21" selection-end-column="45" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/style/dashboard.css">
<entry file="file://$PROJECT_DIR$/src/webserver/images.rs" />
<entry file="file://$PROJECT_DIR$/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-647">
<caret line="1" column="30" selection-start-line="1" selection-start-column="30" selection-end-line="1" selection-end-column="30" />
<state relative-caret-position="102">
<caret line="6" column="28" selection-start-line="6" selection-start-column="28" selection-end-line="6" selection-end-column="28" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/style/poll.css">
<entry file="file://$PROJECT_DIR$/style/poll.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="308">
<caret line="28" column="16" selection-start-line="28" selection-start-column="16" selection-end-line="28" selection-end-column="16" />
<state>
<caret column="21" selection-start-column="21" selection-end-column="21" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/webserver/formdata.rs">
<entry file="file://$PROJECT_DIR$/src/webserver/delivery.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-18">
<caret line="5" column="24" lean-forward="true" selection-start-line="5" selection-start-column="24" selection-end-line="5" selection-end-column="24" />
<state relative-caret-position="263">
<caret line="35" column="41" selection-start-line="35" selection-start-column="41" selection-end-line="35" selection-end-column="41" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/webserver/mod.rs">
<entry file="file://$PROJECT_DIR$/src/webserver/styles.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" column="9" lean-forward="true" selection-start-line="2" selection-start-column="9" selection-end-line="2" selection-end-column="9" />
<state relative-caret-position="340">
<caret line="20" column="52" selection-start-line="20" selection-start-column="52" selection-end-line="20" selection-end-column="52" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/database/mod.rs">
<entry file="file://$PROJECT_DIR$/style/poll.css">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="1" column="16" lean-forward="true" selection-start-line="1" selection-start-column="16" selection-end-line="1" selection-end-column="16" />
<state relative-caret-position="86">
<caret line="24" column="7" selection-start-line="24" selection-start-column="7" selection-end-line="24" selection-end-column="7" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/utils/poll_generator.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="646">
<caret line="38" column="70" selection-start-line="38" selection-start-column="70" selection-end-line="38" selection-end-column="70" />
<state relative-caret-position="-221">
<caret line="80" column="30" selection-start-line="80" selection-start-column="30" selection-end-line="80" selection-end-column="30" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/filecache/cached_file.rs">
<entry file="file://$PROJECT_DIR$/src/webserver/session_manager.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="363">
<caret line="35" column="89" selection-start-line="35" selection-start-column="89" selection-end-line="35" selection-end-column="89" />
<state relative-caret-position="498">
<caret line="49" column="16" selection-start-line="49" selection-start-column="12" selection-end-line="49" selection-end-column="16" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/filecache/cache.rs">
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/result.csv">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="223">
<caret line="58" column="42" selection-start-line="58" selection-start-column="42" selection-end-line="58" selection-end-column="42" />
<folding>
<element signature="e#1578#1579#0" expanded="true" />
<element signature="e#1622#1623#0" expanded="true" />
<element signature="e#1678#1679#0" expanded="true" />
<element signature="e#1728#1729#0" expanded="true" />
</folding>
<state relative-caret-position="249">
<caret line="42" column="15" selection-start-line="42" selection-start-column="15" selection-end-line="42" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/webserver/session_manager.rs">
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/poll.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" selection-start-line="2" selection-end-line="2" selection-end-column="30" />
<state relative-caret-position="221">
<caret line="202" column="19" lean-forward="true" selection-start-line="202" selection-start-column="19" selection-end-line="202" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/database/code_management.rs">
<entry file="file://$PROJECT_DIR$/Cargo.lock">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/Cargo.toml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17">
<caret line="1" column="30" selection-start-line="1" selection-start-column="30" selection-end-line="1" selection-end-column="30" />
<state relative-caret-position="136">
<caret line="8" column="4" selection-start-line="8" selection-start-column="4" selection-end-line="8" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/webserver/sites.rs">
<entry file="file://$PROJECT_DIR$/src/database/mod.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="175">
<caret line="198" column="44" selection-start-line="198" selection-start-column="44" selection-end-line="198" selection-end-column="44" />
<state relative-caret-position="340">
<caret line="20" column="21" lean-forward="true" selection-start-line="20" selection-start-column="21" selection-end-line="20" selection-end-column="21" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/webserver/delivery.rs">
<entry file="file://$PROJECT_DIR$/src/database/code_management.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="45" column="9" lean-forward="true" selection-start-line="45" selection-start-column="9" selection-end-line="45" selection-end-column="9" />
<state relative-caret-position="17">
<caret line="1" column="30" selection-start-line="1" selection-start-column="30" selection-end-line="1" selection-end-column="30" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/data/polls/poll-1/poll.json">
<entry file="file://$PROJECT_DIR$/src/database/database.rs">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/webserver/sites.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="617">
<caret line="97" lean-forward="true" selection-start-line="97" selection-end-line="97" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/webserver/mod.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85">
<caret line="5" column="26" lean-forward="true" selection-start-line="5" selection-start-column="26" selection-end-line="5" selection-end-column="26" />
<caret line="5" column="4" lean-forward="true" selection-start-line="5" selection-start-column="4" selection-end-line="5" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/webserver/templates.rs">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</component>
<component name="masterDetails">
<states>

5
Cargo.toml

@ -1,10 +1,11 @@
[package]
name = "DigiPoll"
version = "0.1.0"
name = "Surveyz"
version = "0.6.3"
authors = ["anghenfil <ares@anghenfil.de>"]
[dependencies]
rocket = "0.4.0"
rocket_contrib = "0.4.0"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
lazy_static = "1.2.0"

2
Rocket.toml

@ -14,7 +14,7 @@ limits = { forms = 32768 }
[production]
address = "0.0.0.0"
port = 8000
port = 8060
keep_alive = 5
log = "critical"
limits = { forms = 32768 }

4
src/database/mod.rs

@ -17,7 +17,9 @@ pub struct Question{
pub identifier : String,
pub question : String,
pub optional : bool,
pub questiontype : i8
pub questiontype : i8,
#[serde(default)]
pub selection_options : Vec<String>
}
#[derive(Debug, Serialize, Deserialize)]

4
src/main.rs

@ -4,6 +4,7 @@
extern crate lazy_static;
#[macro_use]
extern crate rocket;
extern crate rocket_contrib;
extern crate serde_json;
extern crate serde;
extern crate rand;
@ -13,6 +14,9 @@ mod filecache;
mod database;
mod utils;
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
fn main(){
println!("Starting Surveyz version {}", VERSION);
webserver::delivery::deliver();
}

41
src/utils/poll_generator.rs

@ -49,16 +49,24 @@ pub fn generate_questionblock(questionblock : &database::QuestionBlock, pollid :
}
pub fn generate_question(question : &database::Question, last_question_type : i8) -> String{
let required = if ! question.optional {
"required"
}else{
""
};
if question.questiontype == 10{
let mut temp = String::new();
if(last_question_type != 10){
temp = String::from("<div class=\"group d-flex\">
temp = String::from("<div class=\"group\
\">
<div class=\"ml-auto\">
<span class=\"test\">++</span>
<span class=\"test\">+</span>
<span class=\"test\">-</span>
<span class=\"test\">--</span>
<span class=\"test\">N/A</span>
<span class=\"legend\">++</span>
<span class=\"legend\">+</span>
<span class=\"legend\">-</span>
<span class=\"legend\">--</span>
<span class=\"legend\">N/A</span>
</div>
</div>");
}
@ -69,11 +77,11 @@ pub fn generate_question(question : &database::Question, last_question_type : i8
<div class=\"checkboxes ml-auto\">
<input type=\"hidden\" name=\"q{}\" />
<label class=\"checkbox form-group\">
<input type=\"radio\" name=\"q{}\" value=\"4\">
<input type=\"radio\" name=\"q{}\" value=\"N/A\" oninvalid=\"report_missing()\"{}>
<span class=\"default\"></span>
</label>
<label class=\"checkbox form-group\">
<input type=\"radio\" name=\"q{}\" value=\"3\">
<input type=\"radio\" name=\"q{}\" value=\"1\">
<span class=\"default\"></span>
</label>
<label class=\"checkbox form-group\">
@ -81,24 +89,31 @@ pub fn generate_question(question : &database::Question, last_question_type : i8
<span class=\"default\"></span>
</label>
<label class=\"checkbox form-group\">
<input type=\"radio\" name=\"q{}\" value=\"1\">
<input type=\"radio\" name=\"q{}\" value=\"3\">
<span class=\"default\"></span>
</label>
<label class=\"checkbox form-group\">
<input type=\"radio\" name=\"q{}\" value=\"N/A\">
<input type=\"radio\" name=\"q{}\" value=\"4\">
<span class=\"default\"></span>
</label>
</div>
</div>
", temp, question.question, question.identifier, question.identifier, question.identifier, question.identifier, question.identifier, question.identifier)
", temp, question.question, question.identifier, question.identifier, required, question.identifier, question.identifier, question.identifier, question.identifier)
}else if question.questiontype == 20 {
return format!("
<div>
<p>{}</p>
<div class=\"textfield\">
<textarea class=\"textfield\" name=\"q{}\" rows=\"5\"></textarea>
<textarea class=\"textfield\" name=\"q{}\" rows=\"5\" {}></textarea>
</div>
</div>", question.question, question.identifier);
</div>", question.question, question.identifier, required);
}else if question.questiontype == 30 {
let options : String = question.selection_options.iter().map(|option|{
format!("<option value=\"{}\">{}</option>", option, option)
}).collect();
return format!("<div><p>{}</p><select name=\"q{}\" {}>
{}
</select></div>", question.question, question.identifier, required, options);
}else{
return String::from("<p>Error: Unkown Qustiontype.");
}

35
src/webserver/delivery.rs

@ -11,6 +11,7 @@ use webserver::session_manager;
use std::collections::HashMap;
use std::sync::RwLock;
use database::code_management;
use rocket_contrib::serve::StaticFiles;
lazy_static! {
pub static ref CACHE: RwLock<Cache> = RwLock::new(Cache{
@ -19,32 +20,22 @@ lazy_static! {
});
}
pub fn deliver(){
unsafe {
CACHE.write().unwrap().add(String::from("global.css"), String::from("style/global.css"), 0);
CACHE.write().unwrap().add(String::from("poll.css"), String::from("style/poll.css"), 0);
CACHE.write().unwrap().add(String::from("dashboard.css"), String::from("style/dashboard.css"), 0);
CACHE.write().unwrap().add(String::from("bootstrap.css"), String::from("style/bootstrap/bootstrap.min.css"), 0);
}
pub fn deliver() {
CACHE.write().unwrap().add(String::from("global.css"), String::from("style/global.css"), 0);
CACHE.write().unwrap().add(String::from("poll.css"), String::from("style/poll.css"), 0);
CACHE.write().unwrap().add(String::from("dashboard.css"), String::from("style/dashboard.css"), 0);
CACHE.write().unwrap().add(String::from("bootstrap.css"), String::from("style/bootstrap/bootstrap.min.css"), 0);
CACHE.write().unwrap().add(String::from("poll.js"), String::from("style/poll.js"), 0);
//load_polls();
generate_poll(String::from("poll-1"));
code_management::CODE_MANAGER.write().unwrap().insert(String::from("FLADF"), String::from("poll-1"));
rocket::ignite()
.mount("/", routes![sites::index])
.mount("/", routes![styles::getcss])
.mount("/", routes![sites::poll])
.mount("/", routes![sites::index])
.mount("/", routes![styles::getcss])
.mount("/", routes![styles::getjs])
.mount("/", routes![sites::poll])
.mount("/", routes![sites::poll_post])
.launch();
}
fn load_polls(){
if check_poll(String::from("poll-1-old")){
unsafe {
CACHE.write().unwrap().add(String::from("poll-1-old-block-1"), String::from("data/polls/poll-1-old/questionblocks/block-1/block-1.html"), 0)
}
}else{
eprintln!("Missing files for poll-1-old!");
}
.mount("/images/", StaticFiles::from("data/logos"))
.launch();
}

3
src/webserver/mod.rs

@ -2,4 +2,5 @@ pub mod delivery;
mod sites;
mod styles;
mod session_manager;
mod formdata;
mod formdata;
mod templates;

8
src/webserver/session_manager.rs

@ -13,7 +13,7 @@ pub struct Session{
pub step : String,
pub complete : bool,
pub poll : String,
pub data : Vec<(String, String)>,
pub data : HashMap<String, String>,
}
lazy_static! {
@ -47,7 +47,7 @@ pub fn session_handling(sessionid : Option<&RawStr>, code : &RawStr) -> Result<S
step: String::from("0"),
complete: false,
poll: code.to_string(),
data: Vec::new()
data: HashMap::new()
});
}else {
sessionid2 = sessionid.unwrap().to_string();
@ -63,7 +63,7 @@ pub fn session_handling(sessionid : Option<&RawStr>, code : &RawStr) -> Result<S
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">
<title>DigiPoll</title>
<title>Surveyz</title>
<link href=\"https://fonts.googleapis.com/css?family=Lato\" rel=\"stylesheet\">
<link rel=\"stylesheet\" href=\"style/bootstrap.css\">
<link rel=\"stylesheet\" href=\"style/global.css\">
@ -75,7 +75,7 @@ pub fn session_handling(sessionid : Option<&RawStr>, code : &RawStr) -> Result<S
<p>Invalid session. But you can <a href=\"/poll?code={}\">start over.</a></p>
</div>
<div class=\"footer\">
<p>Powered by DigiPoll - Project created by Keanu Dölle</p>
<p>Powered by Surveyz - Project created by Keanu Dölle</p>
</div>
</body>
</html>", code))));

170
src/webserver/sites.rs

@ -12,9 +12,11 @@ use webserver::formdata::FormData;
use std::fs::OpenOptions;
use std::io::Write;
use database::code_management;
use std::path::Path;
#[post("/poll?<code>&<sessionid>", data = "<data>")]
pub fn poll_post(code: &RawStr, data: Form<FormData>, sessionid: Option<&RawStr>) -> Result<content::Html<String>, status::Custom<content::Html<String>>> {
let mut data_fields = data.fields.clone();
let sessionid: String = match session_manager::session_handling(sessionid, code) { //obtain valid session id or return error
Ok(sessionid) => sessionid,
@ -23,15 +25,15 @@ pub fn poll_post(code: &RawStr, data: Form<FormData>, sessionid: Option<&RawStr>
let codetemp = code.to_string().clone();
let poll : String = if code_management::CODE_MANAGER.read().unwrap().contains_key(&codetemp) {
let poll: String = if code_management::CODE_MANAGER.read().unwrap().contains_key(&codetemp) {
code_management::CODE_MANAGER.read().unwrap().get(&codetemp).unwrap().clone()
}else{
} else {
return Err(status::Custom(Status::NotFound, content::Html(String::from("<!DOCTYPE html>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">
<title>DigiPoll</title>
<title>Surveyz</title>
<link href=\"https://fonts.googleapis.com/css?family=Lato\" rel=\"stylesheet\">
<link rel=\"stylesheet\" href=\"style/bootstrap.css\">
<link rel=\"stylesheet\" href=\"style/global.css\">
@ -43,7 +45,7 @@ pub fn poll_post(code: &RawStr, data: Form<FormData>, sessionid: Option<&RawStr>
<p>The Code you entered is invalid.</p>
</div>
<div class=\"footer\">
<p>Powered by DigiPoll - Project created by Keanu Dölle</p>
<p>Powered by Surveyz - Project created by Keanu Dölle</p>
</div>
</body>
</html>
@ -54,50 +56,99 @@ pub fn poll_post(code: &RawStr, data: Form<FormData>, sessionid: Option<&RawStr>
//TODO: handling if survey completed
let mut step = session_manager::SESSIONS.read().unwrap().get(&sessionid).unwrap().step.clone();
if(step == "0"){ //First step, change step to first questionblock
if (step == "0") { //First step, change step to first questionblock
step = String::from("questionblock-0"); //TODO: Check if at least one questionblock exists
}else{ //Step should look like "questionblock-x"
} else { //Step should look like "questionblock-x"
if !webserver::delivery::CACHE.read().unwrap().check_file(&format!("{}/{}", &poll, &step)) {
//Questionblock unkown (not in cache)
//TODO: Server error
}
}
//Check sent data
let mut submitted: String;
let temp = data_fields.get("submit").cloned();
if temp.is_none() {
return Err(status::Custom(Status::BadRequest, content::Html(String::from("<!DOCTYPE html>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">
<title>Surveyz</title>
<link href=\"https://fonts.googleapis.com/css?family=Lato\" rel=\"stylesheet\">
<link rel=\"stylesheet\" href=\"style/bootstrap.css\">
<link rel=\"stylesheet\" href=\"style/global.css\">
<link rel=\"stylesheet\" href=\"style/poll.css\">
</head>
<body class=\"centered\">
<div class=\"mainframe text-center align-middle\">
<br><br><br><h1>Error 400.</h1>
<p>Submitted data were invalid.</p>
</div>
<div class=\"footer\">
<p>Powered by Surveyz - Project created by Keanu Dölle</p>
</div>
</body>
</html>
"))));
} else {
submitted = temp.unwrap();
}
data_fields.remove("submit");
let temp1 = step.clone();
let parts : Vec<&str>= temp1.split("-").collect();
let mut num1 : i32 = parts.last().unwrap().parse().unwrap(); //TODO: replace unwrap with error handling
let temp2 = submitted.clone();
let parts : Vec<&str>= temp2.split("-").collect();
let num2 : i32 = parts.last().unwrap().parse().unwrap(); //TODO: replace unwrap with error handling
let mut error = false;
for item in &data.fields{
println!("{}:{}", item.0, item.1);
if item.1 == "" {
if webserver::delivery::CACHE.read().unwrap().get_value(&format!("{}/{}-optional", &poll, item.0)).unwrap() == "false" { //TODO error handling instead of unwrap
//non optional field is empty!
error = true;
}
if submitted.clone() != step{ //user submitted wrong step
if num2 > num1 { //Example: User submitted step 6 but should submit step 4
//do not accept step and display expected step (in example step 4)
error = true;
}else if num2 < num1{ //Example: user submitted step 3 again, but should be at step 5
//accept step and display next step (in example step 4)
num1 = num2;
}
}
for item in &data_fields {
if item.1 == "" {
if webserver::delivery::CACHE.read().unwrap().get_value(&format!("{}/{}-optional", &poll, item.0)).unwrap() == "false" { //TODO error handling instead of unwrap
//non optional field is empty!
error = true;
}
}
}
if(!error){
println!("Hm. Values are there.");
//save data:
let data2 : Vec<(String, String)> = data.fields.iter().map(|item| (item.0.clone(), item.1.clone())).collect();
let data2 : Vec<(String, String)> = data_fields.iter().map(|item| (item.0.clone(), item.1.clone())).collect();
for item in data2.iter().rev() {
session_manager::SESSIONS.write().unwrap().get_mut(&sessionid).unwrap().data.push((item.0.clone(), item.1.clone()));
session_manager::SESSIONS.write().unwrap().get_mut(&sessionid).unwrap().data.insert(item.0.clone(), item.1.clone());
//session_manager::SESSIONS.write().unwrap().get_mut(&sessionid).unwrap().data.push((item.0.clone(), item.1.clone()));
}
//increase step:
let temp = step.clone();
let parts : Vec<&str>= temp.split("-").collect();
let num : i32 = parts.last().unwrap().parse().unwrap(); //TODO: replace unwrap with error handling
//increase step
if webserver::delivery::CACHE.read().unwrap().check_file(&format!("{}/questionblock-{}", &poll, num+1)){
step = format!("questionblock-{}", num+1);
if webserver::delivery::CACHE.read().unwrap().check_file(&format!("{}/questionblock-{}", &poll, num1+1)){
step = format!("questionblock-{}", num1+1);
session_manager::SESSIONS.write().unwrap().get_mut(&sessionid).unwrap().step = step.clone();
}else{
//TODO: handle completion
session_manager::SESSIONS.write().unwrap().get_mut(&sessionid).unwrap().complete = true;
let data_string : String = session_manager::SESSIONS.read().unwrap().get(&sessionid).unwrap().data.iter().map(|item| format!("\"{}\",",item.1)).collect();
for item in session_manager::SESSION.read().unwrap().get(&sessionid).unwrap().data.iter() {
}
let data_string : String = session_manager::SESSIONS.read().unwrap().get(&sessionid).unwrap().data.iter().map(|item| format!("\"{}={}\",",item.0, item.1)).collect();
let mut buffer = OpenOptions::new().append(true).open(format!("data/polls/{}/result.csv", &poll)).unwrap();
buffer.write(format!("{}\n", data_string).as_bytes());
@ -105,37 +156,42 @@ pub fn poll_post(code: &RawStr, data: Form<FormData>, sessionid: Option<&RawStr>
}
}else{
//TODO: Error reporting
println!("Error: missing values");
//TODO: Error reporting if values missing
}
let mut logo = String::new();
if Path::new(&format!("data/logos/{}.png", &poll)).exists(){
logo = format!("<img class=\"logo\" src=\"/images/{}.png\" alt=\"logo\">", &poll);
}
if session_manager::SESSIONS.read().unwrap().get(&sessionid).unwrap().complete {
return Ok(content::Html(String::from("<!DOCTYPE html>
return Ok(content::Html(format!("<!DOCTYPE html>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">
<title>DigiPoll</title>
<title>Surveyz</title>
<link href=\"https://fonts.googleapis.com/css?family=Lato\" rel=\"stylesheet\">
<link rel=\"stylesheet\" href=\"style/bootstrap.css\">
<link rel=\"stylesheet\" href=\"style/global.css\">
<link rel=\"stylesheet\" href=\"style/poll.css\">
</head>
<body class=\"centered\">
{}
<div class=\"mainframe text-center align-middle\">
<h1>Completed!</h1>
<p>Thank you for your participation!</p>
</div>
<div class=\"footer\">
<p>Powered by DigiPoll - Project created by Keanu Dölle</p>
<p>Powered by Surveyz - Project created by Keanu Dölle</p>
</div>
</body>
</html>
")));
", logo)));
}
let cache = webserver::delivery::CACHE.read().unwrap();
let content = cache.get_file(format!("poll-1/{}", step));
let content = cache.get_file(format!("{}/{}", &poll, step));
if content.is_ok() {
return Ok(content::Html(format!("<!DOCTYPE html>
@ -143,32 +199,34 @@ pub fn poll_post(code: &RawStr, data: Form<FormData>, sessionid: Option<&RawStr>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">
<title>DigiPoll</title>
<title>Surveyz</title>
<link href=\"https://fonts.googleapis.com/css?family=Lato\" rel=\"stylesheet\">
<link rel=\"stylesheet\" href=\"style/bootstrap.css\">
<link rel=\"stylesheet\" href=\"style/global.css\">
<link rel=\"stylesheet\" href=\"style/poll.css\">
</head>
<body class=\"centered\">
{}
<div class=\"mainframe text-center align-middle\">
<form action=\"/poll?code={}&sessionid={}\" method=\"post\">
{}
<button type=\"submit\">Continue</button>
<button type=\"submit\" name=\"submit\" value=\"{}\" onclick=\"on_submit()\">Continue</button>
</form>
</div>
<div class=\"footer\">
<p>Powered by DigiPoll - Project created by Keanu Dölle</p>
<p>Powered by Surveyz - Project created by Keanu Dölle</p>
</div>
<script src=\"script/poll.js\"></script>
</body>
</html>
", code, sessionid, content.unwrap().content)));
", logo, code, sessionid, content.unwrap().content, step)));
} else {
return Err(status::Custom(Status::NotFound, content::Html(String::from("<!DOCTYPE html>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">
<title>DigiPoll</title>
<title>Surveyz</title>
<link href=\"https://fonts.googleapis.com/css?family=Lato\" rel=\"stylesheet\">
<link rel=\"stylesheet\" href=\"style/bootstrap.css\">
<link rel=\"stylesheet\" href=\"style/global.css\">
@ -180,7 +238,7 @@ pub fn poll_post(code: &RawStr, data: Form<FormData>, sessionid: Option<&RawStr>
<p>Couldn't found the requested poll</p>
</div>
<div class=\"footer\">
<p>Powered by DigiPoll - Project created by Keanu Dölle</p>
<p>Powered by Surveyz - Project created by Keanu Dölle</p>
</div>
</body>
</html>
@ -206,7 +264,7 @@ pub fn poll(code: &RawStr, sessionid: Option<&RawStr>) -> Result<content::Html<S
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">
<title>DigiPoll</title>
<title>Surveyz</title>
<link href=\"https://fonts.googleapis.com/css?family=Lato\" rel=\"stylesheet\">
<link rel=\"stylesheet\" href=\"style/bootstrap.css\">
<link rel=\"stylesheet\" href=\"style/global.css\">
@ -218,13 +276,18 @@ pub fn poll(code: &RawStr, sessionid: Option<&RawStr>) -> Result<content::Html<S
<p>The Code you entered is invalid.</p>
</div>
<div class=\"footer\">
<p>Powered by DigiPoll - Project created by Keanu Dölle</p>
<p>Powered by Surveyz - Project created by Keanu Dölle</p>
</div>
</body>
</html>
"))));
};
let mut logo = String::new();
if Path::new(&format!("data/logos/{}.png", &poll)).exists(){
logo =