- {isNewSubj ? (
-
{
- setForm({
- ...form,
- subj: event.target.value,
- })
- }}
- />
- ) : (
-
{
- setForm({
- ...form,
- subj: subjects[event.target.value],
- })
- }}
- >
-
- Válassz egy tárgyat...
-
- {subjects.map((subjName, i) => {
- return (
-
- {subjName}
-
- )
- })}
-
- )}
-
{
- setIsNewSubj(!isNewSubj)
- }}
- >
-
{isNewSubj ? 'Létező tárgy ...' : 'Új tárgy ...'}
+
+
+ {renderUsage()}
+ {subjects ? (
+ <>
+
+ {renderSubjSelector()}
+ {renderStuff()}
+ >
+ ) : null}
-
)
- }
-
- if (!data) {
- return null
- }
-
- return (
-
-
- {renderUsage()}
- {subjects ? (
- <>
-
- {renderSubjSelector()}
- {renderStuff()}
- >
- ) : null}
-
- )
}
diff --git a/src/components/questionView.js b/src/components/questionView.js
index e409cec..423dcea 100644
--- a/src/components/questionView.js
+++ b/src/components/questionView.js
@@ -4,206 +4,211 @@ import LoadingIndicator from '../components/LoadingIndicator.js'
import QuestionSearchResult from '../components/QuestionSearchResult.js'
import SearchBar from '../components/searchBar'
-import constants from '../constants.json'
+import constants from '../constants.js'
// import styles from './questionView.module.css'
const updateQuestion = (e, selectedDb) => {
- return new Promise((resolve) => {
- fetch(constants.apiUrl + 'updateQuestion', {
- method: 'POST',
- credentials: 'include',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- ...e,
- selectedDb: selectedDb,
- }),
+ return new Promise((resolve) => {
+ fetch(constants.apiUrl + 'updateQuestion', {
+ method: 'POST',
+ credentials: 'include',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ ...e,
+ selectedDb: selectedDb,
+ }),
+ })
+ .then((res) => {
+ return res.json()
+ })
+ .then((res) => {
+ resolve(res)
+ })
})
- .then((res) => {
- return res.json()
- })
- .then((res) => {
- resolve(res)
- })
- })
}
const rmQuestion = (e, selectedDb) => {
- return new Promise((resolve) => {
- fetch(constants.apiUrl + 'updateQuestion', {
- method: 'POST',
- credentials: 'include',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- ...e,
- selectedDb: selectedDb,
- }),
+ return new Promise((resolve) => {
+ fetch(constants.apiUrl + 'updateQuestion', {
+ method: 'POST',
+ credentials: 'include',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ ...e,
+ selectedDb: selectedDb,
+ }),
+ })
+ .then((res) => {
+ return res.json()
+ })
+ .then((res) => {
+ resolve(res)
+ })
})
- .then((res) => {
- return res.json()
- })
- .then((res) => {
- resolve(res)
- })
- })
}
export default function questionView(props) {
- const { selectedDb } = props
- const [data, setData] = useState(props.data)
- const [searchTerm, setSearchTerm] = useState('')
- const [edits, setEdits] = useState([])
+ const { selectedDb } = props
+ const [data, setData] = useState(props.data)
+ const [searchTerm, setSearchTerm] = useState('')
+ const [edits, setEdits] = useState([])
- useEffect(() => {
- setData(props.data)
- }, [props.data])
+ useEffect(() => {
+ setData(props.data)
+ }, [props.data])
- const updateEdits = (e) => {
- setEdits(
- edits.map((edit) => {
- if (edit.index === e.index) {
- return e
- } else {
- return edit
- }
- })
- )
- }
-
- const removeFromEdits = (e) => {
- setEdits(
- edits.filter((edit, i) => {
- return i !== e.index
- })
- )
- }
-
- const onChange = (e) => {
- const editIndex = edits.findIndex((edit) => {
- return edit.subjName === e.subjName && edit.index === e.index
- })
- if (editIndex === -1) {
- if (e.type === 'edit') {
- if (editIndex === -1) {
- setEdits([...edits, e])
- }
- }
- if (e.type === 'delete') {
- rmQuestion(e, selectedDb).then((res) => {
- if (res.success) {
- alert('Sikeres törlés')
- } else {
- alert('Hiba mentés közben :/')
- }
-
- setData(
- data.map((subj) => {
- if (subj.Name !== e.subjName) {
- return subj
- } else {
- return {
- ...subj,
- Questions: subj.Questions.filter((question, i) => {
- return i !== e.index
- }),
- }
- }
- })
- )
- })
- }
- } else {
- if (e.type === 'reset') {
- // edits -> saves -> resets? => should do nothing, no reset after saving
- removeFromEdits(e)
- setData(
- data.map((subj) => {
- if (subj.Name !== e.subjName) {
- return subj
- } else {
- return {
- ...subj,
- Questions: subj.Questions.map((question, i) => {
- if (i !== e.index) {
- return question
- } else {
- const ps = props.data.find((subj) => {
- return subj.Name === e.subjName
- })
- if (ps) {
- return ps.Questions[i]
- }
- }
- }),
- }
- }
- })
- )
- }
- if (e.type === 'save') {
- updateQuestion(
- edits.find((edit) => {
- return edit.index === e.index
- }),
- selectedDb
- ).then((res) => {
- if (res.success) {
- alert('Sikeres mentés')
- } else {
- alert('Hiba mentés közben :/')
- }
-
- removeFromEdits(e)
- })
- }
- if (e.type === 'edit') {
- updateEdits(e)
- }
- }
-
- if (e.type === 'edit') {
- setData(
- data.map((subj) => {
- if (subj.Name !== e.subjName) {
- return subj
- } else {
- return {
- ...subj,
- Questions: subj.Questions.map((question, i) => {
- if (i !== e.index) {
- return question
+ const updateEdits = (e) => {
+ setEdits(
+ edits.map((edit) => {
+ if (edit.index === e.index) {
+ return e
} else {
- return e.newVal
+ return edit
}
- }),
- }
- }
- })
- )
+ })
+ )
}
- }
- if (data) {
- return (
-
-
setSearchTerm(e)} />
-
-
-
-
-
- )
- } else {
- return
- }
+ const removeFromEdits = (e) => {
+ setEdits(
+ edits.filter((edit, i) => {
+ return i !== e.index
+ })
+ )
+ }
+
+ const onChange = (e) => {
+ const editIndex = edits.findIndex((edit) => {
+ return edit.subjName === e.subjName && edit.index === e.index
+ })
+ if (editIndex === -1) {
+ if (e.type === 'edit') {
+ if (editIndex === -1) {
+ setEdits([...edits, e])
+ }
+ }
+ if (e.type === 'delete') {
+ rmQuestion(e, selectedDb).then((res) => {
+ if (res.success) {
+ alert('Sikeres törlés')
+ } else {
+ alert('Hiba mentés közben :/')
+ }
+
+ setData(
+ data.map((subj) => {
+ if (subj.Name !== e.subjName) {
+ return subj
+ } else {
+ return {
+ ...subj,
+ Questions: subj.Questions.filter(
+ (question, i) => {
+ return i !== e.index
+ }
+ ),
+ }
+ }
+ })
+ )
+ })
+ }
+ } else {
+ if (e.type === 'reset') {
+ // edits -> saves -> resets? => should do nothing, no reset after saving
+ removeFromEdits(e)
+ setData(
+ data.map((subj) => {
+ if (subj.Name !== e.subjName) {
+ return subj
+ } else {
+ return {
+ ...subj,
+ Questions: subj.Questions.map((question, i) => {
+ if (i !== e.index) {
+ return question
+ } else {
+ const ps = props.data.find((subj) => {
+ return subj.Name === e.subjName
+ })
+ if (ps) {
+ return ps.Questions[i]
+ }
+ }
+ }),
+ }
+ }
+ })
+ )
+ }
+ if (e.type === 'save') {
+ updateQuestion(
+ edits.find((edit) => {
+ return edit.index === e.index
+ }),
+ selectedDb
+ ).then((res) => {
+ if (res.success) {
+ alert('Sikeres mentés')
+ } else {
+ alert('Hiba mentés közben :/')
+ }
+
+ removeFromEdits(e)
+ })
+ }
+ if (e.type === 'edit') {
+ updateEdits(e)
+ }
+ }
+
+ if (e.type === 'edit') {
+ setData(
+ data.map((subj) => {
+ if (subj.Name !== e.subjName) {
+ return subj
+ } else {
+ return {
+ ...subj,
+ Questions: subj.Questions.map((question, i) => {
+ if (i !== e.index) {
+ return question
+ } else {
+ return e.newVal
+ }
+ }),
+ }
+ }
+ })
+ )
+ }
+ }
+
+ if (data) {
+ return (
+
+
setSearchTerm(e)}
+ />
+
+
+
+
+
+ )
+ } else {
+ return
+ }
}
diff --git a/src/components/subjectView.js b/src/components/subjectView.js
index 0424934..7792e8a 100644
--- a/src/components/subjectView.js
+++ b/src/components/subjectView.js
@@ -5,221 +5,224 @@ import Subject from '../components/Subject.js'
import SubjectSelector from '../components/SubjectSelector.js'
import SearchBar from '../components/searchBar'
-import constants from '../constants.json'
+import constants from '../constants.js'
// import styles from './subjectView.module.css'
import commonStyles from '../commonStyles.module.css'
const onSave = (subjName, changedQuestions, deletedQuestions, selectedDb) => {
- return new Promise((resolve) => {
- fetch(constants.apiUrl + 'updateQuestion', {
- method: 'POST',
- credentials: 'include',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- subjName: subjName,
- changedQuestions: changedQuestions,
- deletedQuestions: deletedQuestions,
- type: 'subjEdit',
- selectedDb: selectedDb,
- }),
+ return new Promise((resolve) => {
+ fetch(constants.apiUrl + 'updateQuestion', {
+ method: 'POST',
+ credentials: 'include',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ subjName: subjName,
+ changedQuestions: changedQuestions,
+ deletedQuestions: deletedQuestions,
+ type: 'subjEdit',
+ selectedDb: selectedDb,
+ }),
+ })
+ .then((res) => {
+ return res.json()
+ })
+ .then((res) => {
+ resolve(res)
+ })
})
- .then((res) => {
- return res.json()
- })
- .then((res) => {
- resolve(res)
- })
- })
}
export default function SubjectView(props) {
- const { data, selectedDb } = props
- const [activeSubjName, setActiveSubjName] = useState('')
- const [searchTerm, setSearchTerm] = useState('')
+ const { data, selectedDb } = props
+ const [activeSubjName, setActiveSubjName] = useState('')
+ const [searchTerm, setSearchTerm] = useState('')
- const [unsavedIndexes, setUnsavedIndexes] = useState([])
- const [editedIndexes, setEditedIndexes] = useState([])
- const [deletedIndexes, setDeletedIndexes] = useState([])
- const [subj, setSubj] = useState(null)
+ const [unsavedIndexes, setUnsavedIndexes] = useState([])
+ const [editedIndexes, setEditedIndexes] = useState([])
+ const [deletedIndexes, setDeletedIndexes] = useState([])
+ const [subj, setSubj] = useState(null)
- const hasChange = editedIndexes.length > 0 || deletedIndexes.length > 0
+ const hasChange = editedIndexes.length > 0 || deletedIndexes.length > 0
- useEffect(() => {
- let currSubj = data.find((subj) => {
- return subj.Name === activeSubjName
- })
- setSubj(currSubj)
- }, [activeSubjName])
-
- const resetQuestion = (i) => {
- if (deletedIndexes.includes(i)) {
- setDeletedIndexes(
- deletedIndexes.filter((ind) => {
- return ind !== i
+ useEffect(() => {
+ let currSubj = data.find((subj) => {
+ return subj.Name === activeSubjName
})
- )
- }
+ setSubj(currSubj)
+ }, [activeSubjName])
- if (editedIndexes.includes(i)) {
- setEditedIndexes(
- editedIndexes.filter((ind) => {
- return ind !== i
- })
- )
- }
-
- if (unsavedIndexes.includes(i)) {
- setUnsavedIndexes(
- unsavedIndexes.filter((ind) => {
- return ind !== i
- })
- )
- }
-
- let currSubj = data.find((subj) => {
- return subj.Name === activeSubjName
- })
-
- setSubj({
- ...subj,
- Questions: subj.Questions.map((q, j) => {
- if (i === j) {
- return currSubj.Questions[i]
- } else {
- return q
- }
- }),
- })
- }
-
- const handleQuestionChange = (newq, i) => {
- if (!unsavedIndexes.includes(i)) {
- setUnsavedIndexes([...unsavedIndexes, i])
- }
-
- if (editedIndexes.includes(i)) {
- setEditedIndexes(
- editedIndexes.filter((ind) => {
- return ind !== i
- })
- )
- }
-
- setSubj({
- ...subj,
- Questions: subj.Questions.map((q, j) => {
- if (i !== j) {
- return q
- } else {
- return newq
- }
- }),
- })
- }
-
- const saveQuestion = (i) => {
- setUnsavedIndexes(
- unsavedIndexes.filter((ind) => {
- return ind !== i
- })
- )
- setEditedIndexes([...editedIndexes, i])
- }
-
- const deleteQuestion = (i) => {
- setDeletedIndexes([...deletedIndexes, i])
- }
-
- const handleSave = () => {
- if (unsavedIndexes.length > 0) {
- alert(
- 'Mentetlen módosításaid vannak, kérek mentsd, vagy állítsd vissza azokat'
- )
- return
- }
- if (editedIndexes.length === 0 && deletedIndexes.length === 0) {
- alert('Nem módosítottál még semmit')
- return
- }
- const changedQuestions = editedIndexes.map((ei) => {
- return {
- index: ei,
- value: subj.Questions[ei],
- }
- })
- const deletedQuestions = deletedIndexes
- onSave(subj.Name, changedQuestions, deletedQuestions, selectedDb).then(
- (res) => {
- if (res.success) {
- alert('Sikeres mentés')
- } else {
- alert('Hiba mentés közben :/')
+ const resetQuestion = (i) => {
+ if (deletedIndexes.includes(i)) {
+ setDeletedIndexes(
+ deletedIndexes.filter((ind) => {
+ return ind !== i
+ })
+ )
}
- setUnsavedIndexes([])
- setEditedIndexes([])
- setDeletedIndexes([])
- }
- )
- }
+ if (editedIndexes.includes(i)) {
+ setEditedIndexes(
+ editedIndexes.filter((ind) => {
+ return ind !== i
+ })
+ )
+ }
- if (data) {
- return (
-
-
setSearchTerm(e)} />
-
- {
- if (
- !hasChange ||
- confirm(
- 'Mentetlen módosításaid vannak a tárgynál, biztos bezárod?'
- )
- ) {
- setActiveSubjName(subjName)
- setUnsavedIndexes([])
- setEditedIndexes([])
- setDeletedIndexes([])
- } else {
- console.log('canceld')
+ if (unsavedIndexes.includes(i)) {
+ setUnsavedIndexes(
+ unsavedIndexes.filter((ind) => {
+ return ind !== i
+ })
+ )
+ }
+
+ let currSubj = data.find((subj) => {
+ return subj.Name === activeSubjName
+ })
+
+ setSubj({
+ ...subj,
+ Questions: subj.Questions.map((q, j) => {
+ if (i === j) {
+ return currSubj.Questions[i]
+ } else {
+ return q
+ }
+ }),
+ })
+ }
+
+ const handleQuestionChange = (newq, i) => {
+ if (!unsavedIndexes.includes(i)) {
+ setUnsavedIndexes([...unsavedIndexes, i])
+ }
+
+ if (editedIndexes.includes(i)) {
+ setEditedIndexes(
+ editedIndexes.filter((ind) => {
+ return ind !== i
+ })
+ )
+ }
+
+ setSubj({
+ ...subj,
+ Questions: subj.Questions.map((q, j) => {
+ if (i !== j) {
+ return q
+ } else {
+ return newq
+ }
+ }),
+ })
+ }
+
+ const saveQuestion = (i) => {
+ setUnsavedIndexes(
+ unsavedIndexes.filter((ind) => {
+ return ind !== i
+ })
+ )
+ setEditedIndexes([...editedIndexes, i])
+ }
+
+ const deleteQuestion = (i) => {
+ setDeletedIndexes([...deletedIndexes, i])
+ }
+
+ const handleSave = () => {
+ if (unsavedIndexes.length > 0) {
+ alert(
+ 'Mentetlen módosításaid vannak, kérek mentsd, vagy állítsd vissza azokat'
+ )
+ return
+ }
+ if (editedIndexes.length === 0 && deletedIndexes.length === 0) {
+ alert('Nem módosítottál még semmit')
+ return
+ }
+ const changedQuestions = editedIndexes.map((ei) => {
+ return {
+ index: ei,
+ value: subj.Questions[ei],
}
- }}
- />
-
-
- {subj && (
-
{
- handleSave()
- }}
- >
- Tárgy módosításainak mentése
+ })
+ const deletedQuestions = deletedIndexes
+ onSave(subj.Name, changedQuestions, deletedQuestions, selectedDb).then(
+ (res) => {
+ if (res.success) {
+ alert('Sikeres mentés')
+ } else {
+ alert('Hiba mentés közben :/')
+ }
+
+ setUnsavedIndexes([])
+ setEditedIndexes([])
+ setDeletedIndexes([])
+ }
+ )
+ }
+
+ if (data) {
+ return (
+
+
setSearchTerm(e)}
+ />
+
+ {
+ if (
+ !hasChange ||
+ confirm(
+ 'Mentetlen módosításaid vannak a tárgynál, biztos bezárod?'
+ )
+ ) {
+ setActiveSubjName(subjName)
+ setUnsavedIndexes([])
+ setEditedIndexes([])
+ setDeletedIndexes([])
+ } else {
+ console.log('canceld')
+ }
+ }}
+ />
+
+
+ {subj && (
+
{
+ handleSave()
+ }}
+ >
+ Tárgy módosításainak mentése
+
+ )}
+
+
+ {subj && (
+
+ )}
+
- )}
-
-
- {subj && (
-
- )}
-
-
- )
- } else {
- return
- }
+ )
+ } else {
+ return
+ }
}
diff --git a/src/components/testView.js b/src/components/testView.js
index 77cbc3f..6ec1f20 100644
--- a/src/components/testView.js
+++ b/src/components/testView.js
@@ -2,188 +2,199 @@ import React, { useState } from 'react'
import Question from '../components/Question'
-import constants from '../constants.json'
+import constants from '../constants.js'
import styles from './testView.module.css'
import commonStyles from '../commonStyles.module.css'
const rmTest = (subjName, testName) => {
- return new Promise((resolve) => {
- fetch(constants.apiUrl + 'rmPossibleAnswer', {
- method: 'POST',
- credentials: 'include',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- subj: subjName,
- file: testName,
- }),
+ return new Promise((resolve) => {
+ fetch(constants.apiUrl + 'rmPossibleAnswer', {
+ method: 'POST',
+ credentials: 'include',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ subj: subjName,
+ file: testName,
+ }),
+ })
+ .then((res) => {
+ return res.json()
+ })
+ .then((res) => {
+ resolve(res)
+ })
})
- .then((res) => {
- return res.json()
- })
- .then((res) => {
- resolve(res)
- })
- })
}
export default function TestView(props) {
- const { subjName, testName, router, onDelete } = props
- const [test, setTest] = useState(props.test)
+ const { subjName, testName, router, onDelete } = props
+ const [test, setTest] = useState(props.test)
- const renderActions = () => {
- return (
-
-
{
- if (confirm('Biztos véglegesen törlöd ezt az egész tesztet?')) {
- rmTest(subjName, testName).then((res) => {
- if (res.res === 'ok') {
- // alert('sikeres törlés')
- router.back()
- onDelete()
- } else {
- alert('hiba törlés közben!')
- }
- })
- }
- }}
- >
- Teszt törlése
-
-
{
- if (
- confirm(
- 'Biztos beküldöd? Beküldés után törlődik a teszt, de a Kérdések/Tárgyak nézetnél megtalálhatóak lesznek'
- )
- ) {
- const questions = test.questions.map((q) => {
- return {
- Q: q.Q,
- A: q.A,
- data: {
- ...q.data,
- ...(q.possibleAnswers && {
- possibleAnswers: q.possibleAnswers,
- }),
- },
- }
- })
- const toSend = {
- id: 'WEBSITE',
- version: 'WEBSITE',
- location: `https://${test.testUrl}`,
- subj: test.subj,
- quiz: questions,
- }
-
- fetch(constants.apiUrl + 'isAdding', {
- method: 'POST',
- credentials: 'include',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(toSend),
- })
- .then((res) => {
- return res.json()
- })
- .then((res) => {
- if (res.success) {
- alert(
- `Sikeres beküldés, ${res.totalNewQuestions} új kérdés`
- )
- rmTest(subjName, testName).then((res) => {
- if (res.res === 'ok') {
- router.back()
- onDelete()
- }
- })
- } else {
- alert('Hiba beküldés közben :/')
- }
- })
- }
- }}
- >
- Teszt mentése
-
-
- )
- }
-
- return (
-
-
-
-
Tárgy neve
-
{test.subj}
-
-
-
Teszt URL
-
{test.testUrl}
-
-
-
Beküldő felhasználó ID
-
{test.userid}
{' '}
-
-
-
Beküldés ideje
-
{new Date(test.date).toLocaleString()}
{' '}
-
-
-
- {renderActions()}
-
- {test.questions.map((question, i) => {
- return (
-
-
-
-
{
- setTest({
- ...test,
- questions: test.questions.map((q, j) => {
- if (j === i) {
- return newQ
- }
- return q
- }),
- })
- }}
- question={question}
- />
-
-
{
+ return (
+
+
{
- setTest({
- ...test,
- questions: test.questions.filter((q, j) => {
- return j !== i
- }),
- })
+ if (
+ confirm(
+ 'Biztos véglegesen törlöd ezt az egész tesztet?'
+ )
+ ) {
+ rmTest(subjName, testName).then((res) => {
+ if (res.res === 'ok') {
+ // alert('sikeres törlés')
+ router.back()
+ onDelete()
+ } else {
+ alert('hiba törlés közben!')
+ }
+ })
+ }
}}
- >
- Kérdés törlése
-
+ >
+ Teszt törlése
-
-
- )
- })}
-
- {test.questions.length > 2 ? (
- <>
-
- {renderActions()}
- >
- ) : null}
-
- )
+ {
+ if (
+ confirm(
+ 'Biztos beküldöd? Beküldés után törlődik a teszt, de a Kérdések/Tárgyak nézetnél megtalálhatóak lesznek'
+ )
+ ) {
+ const questions = test.questions.map((q) => {
+ return {
+ Q: q.Q,
+ A: q.A,
+ data: {
+ ...q.data,
+ ...(q.possibleAnswers && {
+ possibleAnswers: q.possibleAnswers,
+ }),
+ },
+ }
+ })
+ const toSend = {
+ id: 'WEBSITE',
+ version: 'WEBSITE',
+ location: `https://${test.testUrl}`,
+ subj: test.subj,
+ quiz: questions,
+ }
+
+ fetch(constants.apiUrl + 'isAdding', {
+ method: 'POST',
+ credentials: 'include',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(toSend),
+ })
+ .then((res) => {
+ return res.json()
+ })
+ .then((res) => {
+ if (res.success) {
+ alert(
+ `Sikeres beküldés, ${res.totalNewQuestions} új kérdés`
+ )
+ rmTest(subjName, testName).then(
+ (res) => {
+ if (res.res === 'ok') {
+ router.back()
+ onDelete()
+ }
+ }
+ )
+ } else {
+ alert('Hiba beküldés közben :/')
+ }
+ })
+ }
+ }}
+ >
+ Teszt mentése
+
+
+ )
+ }
+
+ return (
+
+
+
+
Tárgy neve
+
{test.subj}
+
+
+
Teszt URL
+
{test.testUrl}
+
+
+
Beküldő felhasználó ID
+
{test.userid}
{' '}
+
+
+
Beküldés ideje
+
{new Date(test.date).toLocaleString()}
{' '}
+
+
+
+ {renderActions()}
+
+ {test.questions.map((question, i) => {
+ return (
+
+
+
+
{
+ setTest({
+ ...test,
+ questions: test.questions.map(
+ (q, j) => {
+ if (j === i) {
+ return newQ
+ }
+ return q
+ }
+ ),
+ })
+ }}
+ question={question}
+ />
+
+
{
+ setTest({
+ ...test,
+ questions:
+ test.questions.filter(
+ (q, j) => {
+ return j !== i
+ }
+ ),
+ })
+ }}
+ >
+ Kérdés törlése
+
+
+
+
+ )
+ })}
+
+ {test.questions.length > 2 ? (
+ <>
+
+ {renderActions()}
+ >
+ ) : null}
+
+ )
}
diff --git a/src/constants.js b/src/constants.js
new file mode 100644
index 0000000..2b785de
--- /dev/null
+++ b/src/constants.js
@@ -0,0 +1,19 @@
+// eslint-disable-next-line no-undef
+const useLocalhost = process && process.env.NODE_ENV === 'development'
+// eslint-disable-next-line no-undef
+const domain = process && process.env.DOMAIN
+
+if (!domain && !useLocalhost) {
+ throw new Error('Domain is not defined! Please set DOMAIN env variable!')
+}
+
+const constants = {
+ domain: domain || 'localhost',
+ siteUrl: useLocalhost ? 'http://localhost:8080/' : `https://${domain}/`,
+ apiUrl: useLocalhost
+ ? 'http://localhost:8080/api/'
+ : `https://${domain}/api/`,
+ maxQuestionsToRender: 250,
+}
+
+export default constants
diff --git a/src/constants.json b/src/constants.json
deleted file mode 100644
index fd35ff2..0000000
--- a/src/constants.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "siteUrl": "https://qmining.frylabs.net/",
- "apiUrl": "https://api.frylabs.net/",
- "maxQuestionsToRender": 250
-}
diff --git a/src/pages/index.js b/src/pages/index.js
index b150fb4..6306c61 100644
--- a/src/pages/index.js
+++ b/src/pages/index.js
@@ -11,302 +11,328 @@ import LoadingIndicator from '../components/LoadingIndicator'
import styles from './index.module.css'
import commonStyles from '../commonStyles.module.css'
-import constants from '../constants.json'
+import constants from '../constants.js'
const Infos = ({ onClick, renderOKButton }) => {
- return (
-
-
Kérdés szerkesztő
-
- Ezen az oldalon az éles adatbázisban levő kérdéseket tudod szerkeszteni,
- vagy azokhoz tudsz adni.{' '}
-
- A törléshez és módosításokhoz nem kér megerősítést, ezek azonnal
- megtörténnek, és nem visszavonhatóak.
-
-
-
-
Néhány dolog, amit kérlek tarts be szerkesztés közben:
-
-
-
- Ne rontsd el a kérdéseket sok törléssel / rossz válasz
- megadásával. Sok más felhasználónak lesz rossz, és visszakereshető
- / tiltható a módosító
-
-
- Arra is vigyázz, hogy véletlen se történjen ilyesmi, vagy ha mégis
- valami baj történt, akkor azt{' '}
- jelezd . Van sok biztonsági
- mentés
-
-
- Ahhoz, hogy a script megtalálja a helyes választ a kérdés
- szövegének pontosan olyannak kell lennie, mint a teszt
- közben (elírásokkal, .... -okkal, meg mindennel)
-
-
+ return (
+
+
Kérdés szerkesztő
+
+ Ezen az oldalon az éles adatbázisban levő kérdéseket tudod
+ szerkeszteni, vagy azokhoz tudsz adni.{' '}
+
+ A törléshez és módosításokhoz nem kér megerősítést, ezek
+ azonnal megtörténnek, és nem visszavonhatóak.
+
+
+
+
Néhány dolog, amit kérlek tarts be szerkesztés közben:
+
+
+
+ Ne rontsd el a kérdéseket sok törléssel / rossz
+ válasz megadásával. Sok más felhasználónak lesz
+ rossz, és visszakereshető / tiltható a módosító
+
+
+ Arra is vigyázz, hogy véletlen se történjen ilyesmi,
+ vagy ha mégis valami baj történt, akkor azt{' '}
+ jelezd . Van
+ sok biztonsági mentés
+
+
+ Ahhoz, hogy a script megtalálja a helyes választ a
+ kérdés szövegének pontosan olyannak kell
+ lennie, mint a teszt közben (elírásokkal, ....
+ -okkal, meg mindennel)
+
+
+
+
+
+ {renderOKButton && (
+
+ OK
+
+ )}
-
-
- {renderOKButton && (
-
- OK
-
- )}
-
- )
+ )
}
const fetchDbs = () => {
- return new Promise((resolve) => {
- fetch(`${constants.apiUrl}getDbs`, {
- credentials: 'include',
+ return new Promise((resolve) => {
+ fetch(`${constants.apiUrl}getDbs`, {
+ credentials: 'include',
+ })
+ .then((resp) => {
+ return resp.json()
+ })
+ .then((resp) => {
+ resolve(resp)
+ })
})
- .then((resp) => {
- return resp.json()
- })
- .then((resp) => {
- resolve(resp)
- })
- })
}
const fetchData = (selectedDb) => {
- return new Promise((resolve) => {
- const toFetch = `${constants.apiUrl}${selectedDb.path}`
- fetch(toFetch, {
- credentials: 'include',
+ return new Promise((resolve) => {
+ const toFetch = `${constants.apiUrl}${selectedDb.path}`
+ fetch(toFetch, {
+ credentials: 'include',
+ })
+ .then((resp) => {
+ return resp.json()
+ })
+ .then((resp) => {
+ resolve(resp)
+ })
})
- .then((resp) => {
- return resp.json()
- })
- .then((resp) => {
- resolve(resp)
- })
- })
}
const views = {
- welcome: 'w',
- subject: 's',
- question: 'q',
- questionAdder: 'qa',
- possibleAnswers: 'pa',
+ welcome: 'w',
+ subject: 's',
+ question: 'q',
+ questionAdder: 'qa',
+ possibleAnswers: 'pa',
}
export default function Index({ router }) {
- const [infoRead, setInfoRead] = useState(false)
- const [data, setData] = useState(null)
- const [qdbs, setQdbs] = useState(null)
- const [selectedDb, setSelectedDb] = useState(null)
- const [view, setView] = useState(views.welcome)
+ const [infoRead, setInfoRead] = useState(false)
+ const [data, setData] = useState(null)
+ const [qdbs, setQdbs] = useState(null)
+ const [selectedDb, setSelectedDb] = useState(null)
+ const [view, setView] = useState(views.welcome)
- const [error, setError] = useState(null)
+ const [error, setError] = useState(null)
- useEffect(() => {
- if (selectedDb) {
- loadData()
- } else {
- setData(null)
- }
- }, [selectedDb])
+ useEffect(() => {
+ if (selectedDb) {
+ loadData()
+ } else {
+ setData(null)
+ }
+ }, [selectedDb])
- useEffect(() => {
- fetchDbs().then((resp) => {
- setQdbs(resp)
+ useEffect(() => {
+ fetchDbs().then((resp) => {
+ setQdbs(resp)
- const view = router.query.v
- ? decodeURIComponent(router.query.v)
- : views.welcome
- setView(view)
- })
- }, [])
+ const view = router.query.v
+ ? decodeURIComponent(router.query.v)
+ : views.welcome
+ setView(view)
+ })
+ }, [])
- const loadData = () => {
- setData(null)
- if (!selectedDb) {
- alert('Válassz egy adatbázist!')
- return
- }
+ const loadData = () => {
+ setData(null)
+ if (!selectedDb) {
+ alert('Válassz egy adatbázist!')
+ return
+ }
- fetchData(selectedDb)
- .then((resp) => {
- setData(resp)
- })
- .catch((error) => {
- console.error(error)
- console.error('Error while fetching data')
- setError('Error while fetching data')
- })
- }
-
- const refetchDbs = () => {
- if (selectedDb) {
- fetchData(selectedDb).then((resp) => {
- setData(resp)
- })
- }
- fetchDbs().then((resp) => {
- setQdbs(resp)
- })
- }
-
- const renderView = () => {
- if (view === views.subject) {
- return (
- <>
-
-
Tárgyak - Data Editor | Frylabs.net
-
-
- {data &&
}
- >
- )
- } else if (view === views.question) {
- return (
- <>
-
-
Kérdések - Data Editor | Frylabs.net
-
-
- {data &&
}
- >
- )
- } else if (view === views.questionAdder) {
- return (
- <>
-
-
Kérdés beküldés - Data Editor | Frylabs.net
-
-
-
- >
- )
- } else if (view === views.possibleAnswers) {
- return (
- <>
-
-
Kitöltetlen tesztek - Data Editor | Frylabs.net
-
-
- >
- )
- } else if (view === views.welcome) {
- return
- } else {
- return
No view!
- }
- }
-
- function renderViewSelector() {
- return (
-
-
{
- router.replace(
- `${router.pathname}?v=${views.question}`,
- undefined,
- { shallow: true }
- )
- setView(views.question)
- }}
- >
- Kérdések
-
-
{
- router.replace(`${router.pathname}?v=${views.subject}`, undefined, {
- shallow: true,
+ fetchData(selectedDb)
+ .then((resp) => {
+ setData(resp)
})
- setView(views.subject)
- }}
- >
- Tárgyak
-
-
{
- router.replace(
- `${router.pathname}?v=${views.questionAdder}`,
- undefined,
- { shallow: true }
+ .catch((error) => {
+ console.error(error)
+ console.error('Error while fetching data')
+ setError('Error while fetching data')
+ })
+ }
+
+ const refetchDbs = () => {
+ if (selectedDb) {
+ fetchData(selectedDb).then((resp) => {
+ setData(resp)
+ })
+ }
+ fetchDbs().then((resp) => {
+ setQdbs(resp)
+ })
+ }
+
+ const renderView = () => {
+ if (view === views.subject) {
+ return (
+ <>
+
+
+ Tárgyak - Data Editor | {constants.domain}
+
+
+
+ {data && (
+
+ )}
+ >
)
- setView(views.questionAdder)
- setSelectedDb(null)
- }}
- >
- Kérdés beküldés
-
-
{
- router.replace(
- `${router.pathname}?v=${views.possibleAnswers}`,
- undefined,
- { shallow: true }
+ } else if (view === views.question) {
+ return (
+ <>
+
+
+ Kérdések - Data Editor | {constants.domain}
+
+
+
+ {data && (
+
+ )}
+ >
)
- setView(views.possibleAnswers)
- }}
- >
- Kitöltetlen tesztek
+ } else if (view === views.questionAdder) {
+ return (
+ <>
+
+
+ Kérdés beküldés - Data Editor | {constants.domain}
+
+
+
+
+ >
+ )
+ } else if (view === views.possibleAnswers) {
+ return (
+ <>
+
+
+ Kitöltetlen tesztek - Data Editor |{' '}
+ {constants.domain}
+
+
+
+ >
+ )
+ } else if (view === views.welcome) {
+ return
+ } else {
+ return
No view!
+ }
+ }
+
+ function renderViewSelector() {
+ return (
+
+
{
+ router.replace(
+ `${router.pathname}?v=${views.question}`,
+ undefined,
+ { shallow: true }
+ )
+ setView(views.question)
+ }}
+ >
+ Kérdések
+
+
{
+ router.replace(
+ `${router.pathname}?v=${views.subject}`,
+ undefined,
+ {
+ shallow: true,
+ }
+ )
+ setView(views.subject)
+ }}
+ >
+ Tárgyak
+
+
{
+ router.replace(
+ `${router.pathname}?v=${views.questionAdder}`,
+ undefined,
+ { shallow: true }
+ )
+ setView(views.questionAdder)
+ setSelectedDb(null)
+ }}
+ >
+ Kérdés beküldés
+
+
{
+ router.replace(
+ `${router.pathname}?v=${views.possibleAnswers}`,
+ undefined,
+ { shallow: true }
+ )
+ setView(views.possibleAnswers)
+ }}
+ >
+ Kitöltetlen tesztek
+
+
+ )
+ }
+
+ if (error) {
+ return
{error}
+ }
+
+ if (!infoRead) {
+ return
setInfoRead(true)} renderOKButton />
+ }
+
+ if (!qdbs) {
+ return
+ }
+
+ return (
+
+ {renderViewSelector()}
+ {renderView()}
-
)
- }
-
- if (error) {
- return
{error}
- }
-
- if (!infoRead) {
- return
setInfoRead(true)} renderOKButton />
- }
-
- if (!qdbs) {
- return
- }
-
- return (
-
- {renderViewSelector()}
- {renderView()}
-
- )
}