Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 13008 | Rev 13068 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 13008 Rev 13067
Línea 15... Línea 15...
15
	open: 'Abierto',
15
	open: 'Abierto',
16
	simple: 'Simple',
16
	simple: 'Simple',
17
	multiple: 'Multiple'
17
	multiple: 'Multiple'
18
}
18
}
Línea -... Línea 19...
-
 
19
 
-
 
20
const INITIAL_OPTION = {
-
 
21
	slug_section: '',
-
 
22
	slug_question: '',
-
 
23
	slug_option: '',
-
 
24
	text: '',
-
 
25
	checked: false,
-
 
26
	position: 0
-
 
27
}
19
 
28
 
20
const INITIAL_SECTION = {
29
const INITIAL_SECTION = {
21
	slug_section: '',
30
	slug_section: '',
22
	name: '',
31
	name: '',
23
	text: '',
32
	text: '',
Línea 51... Línea 60...
51
	// Section modal states
60
	// Section modal states
52
	const [isShowSection, setIsShowSectionModal] = useState(false)
61
	const [isShowSection, setIsShowSectionModal] = useState(false)
53
	const [sectionSelected, setSectionSelected] = useState(INITIAL_SECTION)
62
	const [sectionSelected, setSectionSelected] = useState(INITIAL_SECTION)
54
	const [sectionType, setSectionType] = useState('add')
63
	const [sectionType, setSectionType] = useState('add')
Línea 55... Línea 64...
55
 
64
 
56
	// Section modal states
65
	// Question modal states
57
	const [isShowQuestion, setIsShowQuestionModal] = useState(false)
66
	const [isShowQuestion, setIsShowQuestionModal] = useState(false)
58
	const [questionSelected, setQuestionSelected] = useState(INITIAL_QUESTION)
67
	const [questionSelected, setQuestionSelected] = useState(INITIAL_QUESTION)
Línea -... Línea 68...
-
 
68
	const [questionType, setQuestionType] = useState('add')
-
 
69
 
-
 
70
	// Option modal states
-
 
71
	const [isShowOption, setIsShowOptionModal] = useState(false)
-
 
72
	const [optionSelected, setOptionSelected] = useState(INITIAL_OPTION)
59
	const [questionType, setQuestionType] = useState('add')
73
	const [optionType, setOptionType] = useState('add')
60
 
74
 
61
	const [content, setContent] = useState([])
75
	const [content, setContent] = useState([])
62
	const [status, setStatus] = useState('A')
76
	const [status, setStatus] = useState('A')
63
	const [showDeleteModal, setShowDeleteModal] = useState(false)
77
	const [showDeleteModal, setShowDeleteModal] = useState(false)
64
	const [deleteType, setDeleteType] = useState('section')
78
	const [deleteType, setDeleteType] = useState('section')
65
	const deleteSlugsOptions = {
79
	const deleteSlugsOptions = {
66
		section: sectionSelected.slug_section,
80
		section: sectionSelected.slug_section,
Línea -... Línea 81...
-
 
81
		question: questionSelected.slug_question
67
		question: questionSelected.slug_question
82
	}
68
	}
83
 
69
 
84
	// Section methods
70
	const showSectionModal = (section = INITIAL_SECTION, type = 'add') => {
85
	const showSectionModal = (section = INITIAL_SECTION, type = 'add') => {
71
		setSectionSelected(section)
86
		setSectionSelected(section)
Línea 92... Línea 107...
92
			questions: [],
107
			questions: [],
93
			status: 0
108
			status: 0
94
		}])
109
		}])
95
	}
110
	}
Línea 96... Línea -...
96
 
-
 
97
	const deleteSection = (slug) => {
-
 
98
		setContent(current =>
-
 
99
			current.filter(currentSection => {
-
 
100
				return currentSection.slug_section !== slug
-
 
101
			}),
-
 
102
		)
-
 
103
	}
-
 
104
 
-
 
105
	const deleteQuestion = (slug) => {
-
 
106
		setContent(current =>
-
 
107
			current.map(currentSection => {
-
 
108
				if (currentSection.slug_section === sectionSelected.slug_section) {
-
 
109
					return {
-
 
110
						...currentSection,
-
 
111
						questions: currentSection.questions.filter((currentQuestion) => currentQuestion.slug_question !== slug)
-
 
112
					}
-
 
113
				}
-
 
114
				return currentSection
-
 
115
			}),
-
 
116
		)
-
 
117
	}
-
 
118
 
-
 
119
	const deleteHandler = (type, slug) => {
-
 
120
		if (type === 'section') {
-
 
121
			return deleteSection(slug)
-
 
122
		}
-
 
123
		if (type === 'question') {
-
 
124
			return deleteQuestion(slug)
-
 
125
		}
-
 
126
	}
-
 
127
 
111
 
128
	const editSection = (name, text, slug) => {
112
	const editSection = (name, text, slug) => {
129
		setContent(current =>
113
		setContent(current =>
130
			current.map(currentSection => {
114
			current.map(currentSection => {
131
				if (currentSection.slug_section === slug) {
115
				if (currentSection.slug_section === slug) {
Línea 135... Línea 119...
135
				return currentSection
119
				return currentSection
136
			})
120
			})
137
		)
121
		)
138
	}
122
	}
Línea -... Línea 123...
-
 
123
 
-
 
124
	const deleteSection = (slug) => {
-
 
125
		setContent(current =>
-
 
126
			current.filter(currentSection => {
-
 
127
				return currentSection.slug_section !== slug
-
 
128
			}),
-
 
129
		)
-
 
130
	}
-
 
131
 
139
 
132
	// Question methods
140
	const showQuestionModal = (question = INITIAL_QUESTION, type = 'add') => {
133
	const showQuestionModal = (question = INITIAL_QUESTION, type = 'add') => {
141
		setIsShowQuestionModal(true)
134
		setIsShowQuestionModal(true)
142
		setQuestionType(type)
135
		setQuestionType(type)
143
		setQuestionSelected(question)
136
		setQuestionSelected(question)
Línea 191... Línea 184...
191
				return currentSection
184
				return currentSection
192
			})
185
			})
193
		)
186
		)
194
	}
187
	}
Línea -... Línea 188...
-
 
188
 
-
 
189
	const deleteQuestion = (slug) => {
-
 
190
		setContent(current =>
-
 
191
			current.map(currentSection => {
-
 
192
				if (currentSection.slug_section === sectionSelected.slug_section) {
-
 
193
					return {
-
 
194
						...currentSection,
-
 
195
						questions: currentSection.questions.filter((currentQuestion) => currentQuestion.slug_question !== slug)
-
 
196
					}
-
 
197
				}
-
 
198
				return currentSection
-
 
199
			}),
-
 
200
		)
-
 
201
	}
-
 
202
 
-
 
203
	// Option methods
-
 
204
	const showOptionModal = (option = INITIAL_OPTION, type = 'add') => {
-
 
205
		setIsShowOptionModal(true)
-
 
206
		setOptionType(type)
-
 
207
		setOptionSelected(option)
-
 
208
	}
-
 
209
 
-
 
210
	const addOption = (option) => {
-
 
211
		const uuid = new Date().getTime()
-
 
212
 
-
 
213
		setContent(current =>
-
 
214
			current.map(currentSection => {
-
 
215
				if (currentSection.slug_section === sectionSelected.slug_section) {
-
 
216
 
-
 
217
					currentSection.questions.map(currentQuestion => {
-
 
218
						if (currentQuestion.slug_question === questionSelected.slug_question) {
-
 
219
							return {
-
 
220
								...currentQuestion,
-
 
221
								options: [
-
 
222
									...currentQuestion.options,
-
 
223
									{
-
 
224
										...option,
-
 
225
										slug_question: questionSelected.slug_question,
-
 
226
										slug_section: sectionSelected.slug_section,
-
 
227
										slug_option: `option${uuid}`
-
 
228
									}
-
 
229
								]
-
 
230
							}
-
 
231
						}
-
 
232
 
-
 
233
						return currentQuestion
-
 
234
					})
-
 
235
				}
-
 
236
 
-
 
237
				return currentSection
-
 
238
			})
-
 
239
		)
-
 
240
	}
-
 
241
 
-
 
242
	const deleteOption = (slug) => {
-
 
243
		setContent(current =>
-
 
244
			current.map(currentSection => {
-
 
245
				if (currentSection.slug_section === sectionSelected.slug_section) {
-
 
246
 
-
 
247
					currentSection.questions.map(question => {
-
 
248
 
-
 
249
						if (question.slug_question === questionSelected.slug_question) {
-
 
250
							return {
-
 
251
								...question,
-
 
252
								options: question.options.filter(option => option.slug_option !== slug)
-
 
253
							}
-
 
254
						}
-
 
255
 
-
 
256
						return question
-
 
257
					})
-
 
258
				}
-
 
259
 
-
 
260
				return currentSection
-
 
261
			}),
-
 
262
		)
-
 
263
	}
-
 
264
 
-
 
265
	// General methods
-
 
266
	const deleteHandler = (type, slug) => {
-
 
267
		if (type === 'section') {
-
 
268
			return deleteSection(slug)
-
 
269
		}
-
 
270
		if (type === 'question') {
-
 
271
			return deleteQuestion(slug)
-
 
272
		}
-
 
273
		if (type === 'option') {
-
 
274
			return deleteOption(slug)
-
 
275
		}
-
 
276
	}
195
 
277
 
196
	const onSubmit = () => {
278
	const onSubmit = () => {
197
		const submitData = new FormData()
279
		const submitData = new FormData()
198
		submitData.append('name', watch('name'))
280
		submitData.append('name', watch('name'))
199
		submitData.append('description', watch('description'))
281
		submitData.append('description', watch('description'))
Línea 358... Línea 440...
358
																								</button>
440
																								</button>
359
																							</td>
441
																							</td>
360
																						</tr>
442
																						</tr>
361
																						{
443
																						{
362
																							section.questions.map((question) => (
444
																							section.questions.map((question) => (
-
 
445
																								<>
363
																								<tr key={question.slug_question} className="tr-question">
446
																									<tr key={question.slug_question} className="tr-question">
364
																									<td className="text-left">Pregunta</td>
447
																										<td className="text-left">Pregunta</td>
365
																									<td className="text-left">
448
																										<td className="text-left">
366
																										{parse(question.text)}
449
																											{parse(question.text)}
367
																									</td>
450
																										</td>
368
																									<td className="text-capitalize">
451
																										<td className="text-capitalize">
369
																										{sectionTypeOptions[question.type]}
452
																											{sectionTypeOptions[question.type]}
370
																									</td>
453
																										</td>
371
																									<td>
454
																										<td>
372
																										<button className="btn btn-default btn-edit-question" onClick={() => {
455
																											<button className="btn btn-default" onClick={() => {
373
																											setSectionSelected(section)
456
																												setSectionSelected(section)
374
																											showQuestionModal(question, 'edit')
457
																												showQuestionModal(question, 'edit')
375
																										}}>
458
																											}}>
376
																											<i className="fa fa-edit" /> Editar Pregunta
459
																												<i className="fa fa-edit" /> Editar Pregunta
377
																										</button>
-
 
378
																										<button className="btn btn-default btn-delete-question" onClick={() => {
-
 
379
																											setQuestionSelected(question)
-
 
380
																											setDeleteType('question')
-
 
381
																											setShowDeleteModal(true)
-
 
382
																										}}>
-
 
383
																											<i className="fa fa-ban" /> Borrar Pregunta
-
 
384
																										</button>
-
 
385
																										{
-
 
386
																											question.type !== 'open'
-
 
387
																											&&
-
 
388
																											<button className="btn btn-default btn-delete-question">
-
 
389
																												<i className="fa fa-plus" /> Agregar opción
-
 
390
																											</button>
460
																											</button>
-
 
461
																											<button className="btn btn-default" onClick={() => {
-
 
462
																												setQuestionSelected(question)
-
 
463
																												setDeleteType('question')
-
 
464
																												setShowDeleteModal(true)
-
 
465
																											}}>
-
 
466
																												<i className="fa fa-ban" /> Borrar Pregunta
-
 
467
																											</button>
-
 
468
																											{
-
 
469
																												question.type !== 'open'
-
 
470
																												&&
-
 
471
																												<button className="btn btn-default">
-
 
472
																													<i className="fa fa-plus" /> Agregar opción
-
 
473
																												</button>
391
																										}
474
																											}
392
																									</td>
475
																										</td>
393
																								</tr>
476
																									</tr>
-
 
477
																									{
-
 
478
																										question.options.map(option => (
-
 
479
																											<tr key={option.slug_question} className="tr-option">
-
 
480
																												<td className="text-left">Pregunta</td>
-
 
481
																												<td className="text-left">
-
 
482
																													{parse(option.text)}
-
 
483
																												</td>
-
 
484
																												<td />
-
 
485
																												<td>
-
 
486
																													<button className="btn btn-default" onClick={() => {
-
 
487
																														setSectionSelected(section)
-
 
488
																														setQuestionSelected(question)
-
 
489
																														showOptionModal(option, 'edit')
-
 
490
																													}}>
-
 
491
																														<i className="fa fa-edit" /> Editar opción
-
 
492
																													</button>
-
 
493
																													<button className="btn btn-default" onClick={() => {
-
 
494
																														setOptionSelected(option)
-
 
495
																														setQuestionSelected(question)
-
 
496
																														setDeleteType('option')
-
 
497
																														setShowDeleteModal(true)
-
 
498
																													}}>
-
 
499
																														<i className="fa fa-ban" /> Borrar opción
-
 
500
																													</button>
-
 
501
																												</td>
-
 
502
																											</tr>
-
 
503
																										))
-
 
504
																									}
-
 
505
																								</>
394
																							))
506
																							))
395
																						}
507
																						}
-
 
508
 
396
																					</tbody>
509
																					</tbody>
397
																				</table>
510
																				</table>
398
																			</div>
511
																			</div>
399
																		</div>
512
																		</div>
400
																	</div>
513
																	</div>
Línea 429... Línea 542...
429
				questionType={questionType}
542
				questionType={questionType}
430
				question={questionSelected}
543
				question={questionSelected}
431
				closeModal={closeQuestionModal}
544
				closeModal={closeQuestionModal}
432
				onSubmit={questionType === 'add' ? addQuestion : editQuestion}
545
				onSubmit={questionType === 'add' ? addQuestion : editQuestion}
433
			/>
546
			/>
-
 
547
			<OptionModal
-
 
548
				show={isShowOption}
-
 
549
				questionType={optionType}
-
 
550
				question={optionSelected}
-
 
551
				closeModal={closeOptionModal}
-
 
552
				onSubmit={optionType === 'add' ? addOption : editQuestion}
-
 
553
			/>
434
			<DeleteModal
554
			<DeleteModal
435
				isOpen={showDeleteModal}
555
				isOpen={showDeleteModal}
436
				closeModal={() => setShowDeleteModal(false)}
556
				closeModal={() => setShowDeleteModal(false)}
437
				onComplete={() => deleteHandler(deleteType, deleteSlugsOptions[deleteType])}
557
				onComplete={() => deleteHandler(deleteType, deleteSlugsOptions[deleteType])}
438
				message="Registro eliminado"
558
				message="Registro eliminado"