Skip to content

Commit

Permalink
Merge pull request #147 from c4dt/141
Browse files Browse the repository at this point in the history
Add AdditionalInfo field
  • Loading branch information
PascalinDe authored Mar 8, 2024
2 parents 7d60164 + c4ec900 commit cffd74b
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 4 deletions.
5 changes: 3 additions & 2 deletions contracts/evoting/types/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ type ShuffleInstance struct {

// Configuration contains the configuration of a new poll.
type Configuration struct {
Title Title
Scaffold []Subject
Title Title
Scaffold []Subject
AdditionalInfo string
}

// MaxBallotSize returns the maximum number of bytes required to store a ballot
Expand Down
1 change: 1 addition & 0 deletions integration/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func createFormNChunks(m txManager, title types.Title, admin string, numChunks i
}},
},
},
AdditionalInfo: "",
}

createForm := types.CreateForm{
Expand Down
1 change: 1 addition & 0 deletions internal/testing/fake/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewForm(ctx serde.Context, snapshot store.Snapshot, formID string) (types.F
De: "",
URL: "",
},
AdditionalInfo: "",
},
FormID: formID,
Status: types.Closed,
Expand Down
11 changes: 11 additions & 0 deletions web/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@tailwindcss/typography": "^0.5.2",
"ajv": "^8.11.0",
"buffer": "^6.0.3",
"dompurify": "^3.0.9",
"file-saver": "^2.0.5",
"i18next": "^21.6.10",
"i18next-browser-languagedetector": "^6.1.3",
Expand Down
1 change: 1 addition & 0 deletions web/frontend/src/language/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"subject": "Betreff",
"choices": "Auswahlmöglichkeiten",
"url": "URL",
"additionalInfo": "Weitere Informationen",
"answers": "Antworten",
"enterMaxLength": "Geben Sie die MaxLength",
"maxChoices": "Maximale Anzahl von Auswahlmöglichkeiten",
Expand Down
1 change: 1 addition & 0 deletions web/frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"subject": "Subject",
"choices": "Choices",
"url": "URL",
"additionalInfo": "Additional information",
"answers": "Answers",
"enterMaxLength": "Enter the MaxLength",
"maxChoices": "Max number of choices",
Expand Down
1 change: 1 addition & 0 deletions web/frontend/src/language/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"subject": "Sujet",
"choices": "Choix",
"url": "URL",
"additionalInfo": "Informations supplémentaires",
"answers": "Réponses",
"enterMaxLength": "Entrer la longueur max",
"maxChoices": "Max nombre de choix",
Expand Down
8 changes: 8 additions & 0 deletions web/frontend/src/pages/ballot/components/BallotDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Select from './Select';
import Text from './Text';
import { DragDropContext } from 'react-beautiful-dnd';
import { internationalize, urlizeLabel } from './../../utils';
import DOMPurify from 'dompurify';

type BallotDisplayProps = {
configuration: Configuration;
Expand Down Expand Up @@ -82,6 +83,13 @@ const BallotDisplay: FC<BallotDisplayProps> = ({
<h3 className="pb-6 break-all text-2xl text-center text-gray-700">
{urlizeLabel(internationalize(language, titles), titles.URL)}
</h3>
<div
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(configuration.AdditionalInfo, {
USE_PROFILES: { html: true },
}),
}}
/>
<div className="flex flex-col">
{configuration.Scaffold.map((subject: types.Subject) => SubjectTree(subject))}
<div className="text-red-600 text-sm pt-3 pb-1">{userErrors}</div>
Expand Down
8 changes: 8 additions & 0 deletions web/frontend/src/pages/form/Result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import IndividualResult from './IndividualResult';
import { default as i18n } from 'i18next';
import GroupedResult from './GroupedResult';
import { internationalize, urlizeLabel } from './../utils';
import DOMPurify from 'dompurify';

// Functional component that displays the result of the votes
const FormResult: FC = () => {
Expand Down Expand Up @@ -103,6 +104,13 @@ const FormResult: FC = () => {
configuration.Title.URL
)}
</h3>
<div
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(configuration.AdditionalInfo, {
USE_PROFILES: { html: true },
}),
}}
/>

<div>
<Tab.Group>
Expand Down
8 changes: 8 additions & 0 deletions web/frontend/src/pages/form/Show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import DKGStatusTable from './components/DKGStatusTable';
import LoadingButton from './components/LoadingButton';
import { internationalize, urlizeLabel } from './../utils';
import { default as i18n } from 'i18next';
import DOMPurify from 'dompurify';

const FormShow: FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -225,6 +226,13 @@ const FormShow: FC = () => {
<div className="pt-8 text-2xl font-bold leading-7 text-gray-900 sm:text-3xl sm:truncate">
{urlizeLabel(internationalize(i18n.language, titles), titles.URL)}
</div>
<div
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(configObj.AdditionalInfo, {
USE_PROFILES: { html: true },
}),
}}
/>

<div className="pt-2 break-all">Form ID : {formId}</div>
{status >= Status.Open &&
Expand Down
21 changes: 20 additions & 1 deletion web/frontend/src/pages/form/components/FormForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { FlashContext, FlashLevel } from 'index';
import { availableLanguages } from 'language/Configuration';
import LanguageButtons from 'language/LanguageButtons';
import { default as i18n } from 'i18next';
import DOMPurify from 'dompurify';

// notifyParent must be used by the child to tell the parent if the subject's
// schema changed.
Expand All @@ -55,7 +56,7 @@ const FormForm: FC<FormFormProps> = () => {
const [marshalledConf, setMarshalledConf] = useState<any>(marshalConfig(conf));
const { configuration: previewConf, answers, setAnswers } = useConfiguration(marshalledConf);

const { Title, Scaffold } = conf;
const { Title, Scaffold, AdditionalInfo } = conf;

const [language, setLanguage] = useState(i18n.language);
const regexPattern = /[^a-zA-Z0-9]/g;
Expand Down Expand Up @@ -229,6 +230,19 @@ const FormForm: FC<FormFormProps> = () => {
placeholder={t('url')}
className="m-3 px-1 w-100 text-lg border rounded-md"
/>
<input
value={AdditionalInfo}
onChange={(e) =>
setConf({
...conf,
AdditionalInfo: e.target.value,
})
}
name="AdditionalInfo"
type="text"
placeholder={t('additionalInfo')}
className="m-3 px-1 w-100 text-lg border rounded-md"
/>
<div className="ml-1">
<button
className={`border p-1 rounded-md ${
Expand All @@ -247,6 +261,11 @@ const FormForm: FC<FormFormProps> = () => {
onClick={() => setTitleChanging(true)}>
{urlizeLabel(internationalize(language, Title), Title.URL)}
</div>
<div
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(AdditionalInfo, { USE_PROFILES: { html: true } }),
}}
/>
<div className="ml-1">
<button
className="hover:text-[#ff0000] p-1 rounded-md"
Expand Down
7 changes: 6 additions & 1 deletion web/frontend/src/types/JSONparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const unmarshalConfig = (json: any): types.Configuration => {
const conf = {
Title: json.Title,
Scaffold: [],
AdditionalInfo: json.AdditionalInfo,
};
for (const subject of json.Scaffold) {
conf.Scaffold.push(unmarshalSubject(subject));
Expand Down Expand Up @@ -222,7 +223,11 @@ const marshalSubject = (subject: types.Subject): any => {
};

const marshalConfig = (configuration: types.Configuration): any => {
const conf = { Title: configuration.Title, Scaffold: [] };
const conf = {
Title: configuration.Title,
Scaffold: [],
AdditionalInfo: configuration.AdditionalInfo,
};
for (const subject of configuration.Scaffold) {
conf.Scaffold.push(marshalSubject(subject));
}
Expand Down
1 change: 1 addition & 0 deletions web/frontend/src/types/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ interface Subject extends SubjectElement {
interface Configuration {
Title: Title;
Scaffold: Subject[];
AdditionalInfo: string;
}

// Answers describes the current answers for each type of question
Expand Down
1 change: 1 addition & 0 deletions web/frontend/src/types/getObjectType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const emptyConfiguration = (): types.Configuration => {
URL: '',
},
Scaffold: [],
AdditionalInfo: '',
};
};

Expand Down

0 comments on commit cffd74b

Please sign in to comment.