Skip to content
Snippets Groups Projects
Commit 87367ccd authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

Merge branch 'survey-creator' into 'develop'

Survey creator

See merge request !129
parents 4b35c7eb 649c51ec
No related branches found
No related tags found
1 merge request!129Survey creator
Showing with 19846 additions and 1 deletion
...@@ -37,4 +37,5 @@ node_modules ...@@ -37,4 +37,5 @@ node_modules
.env .env
# script output # script output
survey_text.* survey_text.*
\ No newline at end of file *.license
\ No newline at end of file
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"regenerator": true
}
],
"@babel/plugin-proposal-class-properties"
]
}
**/*.css
**/*.scss
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"react-hooks"
],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": "off",
"@typescript-eslint/no-unused-vars": [
"warn", { "argsIgnorePattern": "^_" }
],
"@typescript-eslint/no-empty-function": "off"
},
"settings": {
"react": {
"pragma": "React",
"version": "detect"
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{
"name": "compendium-survey-creator",
"version": "1.0.0",
"description": "Application for updating the Compendium Survey using the SurveyJS Creator tool",
"scripts": {
"start": "webpack serve --mode development --open",
"build": "webpack --mode production"
},
"devDependencies": {
"@babel/core": "~7.24",
"@babel/plugin-proposal-class-properties": "~7.18",
"@babel/plugin-transform-runtime": "~7.24",
"@babel/preset-env": "~7.24.7",
"@babel/preset-react": "~7.24",
"@babel/preset-typescript": "~7.24",
"@babel/runtime": "~7.24",
"@types/express": "^4.17.21",
"@types/react": "~18.3",
"@types/react-dom": "~18.3",
"@types/react-router-dom": "~5.3.3",
"@types/webpack": "~5.28",
"@typescript-eslint/eslint-plugin": "~6.21",
"@typescript-eslint/parser": "~6.21",
"babel-loader": "~9.1.3",
"css-loader": "~6.11.0",
"eslint": "^8.57.0",
"eslint-plugin-react": "~7.34.3",
"eslint-plugin-react-hooks": "~4.6.2",
"express": "^4.19.2",
"fork-ts-checker-webpack-plugin": "~9.0.2",
"mini-css-extract-plugin": "~2.9.0",
"sass": "~1.77.6",
"sass-loader": "~13.3.3",
"style-loader": "~3.3.4",
"ts-node": "~10.9.2",
"typescript": "~5.5.3",
"url-loader": "~4.1.1",
"webpack": "~5.92.1",
"webpack-cli": "~5.1.4",
"webpack-dev-server": "~4.15.2"
},
"dependencies": {
"react": "~18.3.1",
"react-bootstrap": "~2.10.4",
"react-dom": "~18.3.1",
"survey-creator-react": "~1.11.6",
"survey-react-ui": "~1.11.5"
},
"main": "index.tsx",
"author": "GÉANT",
"license": "ISC",
"repository": {
"type": "git",
"url": "https://gitlab.geant.org/geant-swd/compendium-v2.git"
}
}
.App {
height: 100vh;
}
\ No newline at end of file
import React, { useEffect, useState } from 'react';
import './App.css';
import { SurveyCreatorWidget } from './SurveyCreator';
import { setLicenseKey } from "survey-core";
function App() {
const [licenseKey, setKey] = useState<string | null>(null);
useEffect(() => {
async function getLicenseKey() {
const response = await fetch("/license-key");
if (response.ok) {
const licenseKey = await response.text();
return licenseKey;
}
}
getLicenseKey().catch(console.error).then((key) => {
if (key) {
setLicenseKey(key);
setKey(key);
} else {
alert('Failed to fetch license key, make sure you have survey-creator.license file alongside webpack.config.ts')
}
});
}, []);
return licenseKey ? (
<div className="App">
<SurveyCreatorWidget></SurveyCreatorWidget>
</div>
) : <div>Fetching license...</div>;
}
export default App;
\ No newline at end of file
import React, { useEffect, useState } from "react";
import { SurveyCreatorComponent, SurveyCreator } from "survey-creator-react";
import "survey-core/defaultV2.min.css";
import "survey-creator-core/survey-creator-core.min.css";
import { Serializer } from "survey-core";
Serializer.addProperty("itemvalue", "customDescription:text");
Serializer.addProperty("question", "hideCheckboxLabels:boolean");
const creatorOptions = {
showLogicTab: true,
isAutoSave: true
};
export function SurveyCreatorWidget() {
const [defaultJson, setDefaultJson] = useState({});
useEffect(() => {
async function getSurveyJson() {
const response = await fetch("/survey-json");
if (response.ok) {
const surveyJson = await response.json();
setDefaultJson(surveyJson);
}
}
getSurveyJson().catch(console.error);
}, []);
const creator = new SurveyCreator(creatorOptions);
creator.text = JSON.stringify(defaultJson);
return (
<SurveyCreatorComponent creator={creator} />
)
}
\ No newline at end of file
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from "./App";
const container = document.getElementById('root') as HTMLElement;
const root = createRoot(container);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
)
\ No newline at end of file
{
"compilerOptions": {
"target": "ES6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"declaration": true,
"declarationDir": "dist/types",
"noImplicitAny": false,
},
"include": ["src"]
}
import path from "path";
import fs from "fs";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import { Configuration as WebpackConfiguration } from "webpack";
import { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server";
interface Configuration extends WebpackConfiguration {
devServer?: WebpackDevServerConfiguration;
}
const isProduction = process.argv[process.argv.indexOf('--mode') + 1] === 'production';
console.log(isProduction ? 'Production build' : 'Development build')
const config: Configuration = {
entry: "./src/index.tsx",
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript",
],
},
},
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
isProduction ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
"sass-loader",
],
},
{
test: /\.css$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader"
],
},
{
test: /\.(png|svg|jpe?g|gif)$/,
type: 'asset/resource'
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".html", '.svg'],
},
output: {
path: path.resolve(__dirname, "..", "compendium_v2", "static"),
filename: "bundle.js",
},
devServer: {
static: path.join(__dirname, "..", "compendium_v2", "static"),
compress: true,
port: 54054,
// Allow SPA urls to work with dev-server
historyApiFallback: true,
setupMiddlewares: (middlewares, devServer) => {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}
const getLicense = (req, res) => {
const licensePath = path.resolve(__dirname, 'survey-creator.license');
if (fs.existsSync(licensePath)) {
const contents = fs.readFileSync(licensePath, 'utf8');
res.send(contents);
} else {
res.status(404).send('License key not found');
}
}
const getSurveyJson = (req, res) => {
const surveyModel = path.resolve(__dirname, 'models', 'survey_model.json');
if (fs.existsSync(surveyModel)) {
const contents = fs.readFileSync(surveyModel, 'utf8');
res.send(contents);
} else {
res.send(JSON.stringify({}));
}
}
devServer.app?.use('/license-key', getLicense);
devServer.app?.use('/survey-json', getSurveyJson);
return middlewares;
},
},
devtool: isProduction ? undefined : "inline-source-map",
plugins: [
new ForkTsCheckerWebpackPlugin({
async: false,
}),
new MiniCssExtractPlugin(
{
filename: 'bundle.css',
}
),
],
};
export default config;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment