Skip to content

Commit

Permalink
Merge pull request #1023 from rdmorganiser/small_fixes
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
jochenklar authored Jul 3, 2024
2 parents fddd019 + 30a644f commit 7208136
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 25 deletions.
4 changes: 4 additions & 0 deletions rdmo/core/static/core/css/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ h4 {
form {
margin-bottom: 20px;
}
textarea {
resize: vertical;
}

.extend {
width: 100%;
}
Expand Down
5 changes: 3 additions & 2 deletions rdmo/management/assets/js/components/common/Links.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ ExtendLink.propTypes = {
onClick: PropTypes.func.isRequired
}

const CodeLink = ({ className, uri, onClick, order }) => {
const CodeLink = ({ className, uri, href, onClick, order }) => {
return (
<>
<Link onClick={onClick}>
<Link href={href} onClick={onClick}>
<code className={className}>{uri}</code>
</Link>
{!isNil(order) ? (
Expand All @@ -214,6 +214,7 @@ const CodeLink = ({ className, uri, onClick, order }) => {
CodeLink.propTypes = {
className: PropTypes.string.isRequired,
uri: PropTypes.string.isRequired,
href: PropTypes.string,
onClick: PropTypes.func.isRequired,
order: PropTypes.number
}
Expand Down
4 changes: 2 additions & 2 deletions rdmo/management/assets/js/components/edit/EditAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ const EditAttribute = ({ config, attribute, elements, elementActions }) => {
{
parent && parent.questionset && <div className="panel-body panel-border">
<p dangerouslySetInnerHTML={{
__html:interpolate(gettext('This attribute will be added to the page <code class="code-questions">%s</code>.'), [parent.questionset.uri])
__html:interpolate(gettext('This attribute will be added to the question set <code class="code-questions">%s</code>.'), [parent.questionset.uri])
}} />
</div>
}
{
parent && parent.question && <div className="panel-body panel-border">
<p dangerouslySetInnerHTML={{
__html:interpolate(gettext('This attribute will be added to the page <code class="code-questions">%s</code>.'), [parent.question.uri])
__html:interpolate(gettext('This attribute will be added to the question <code class="code-questions">%s</code>.'), [parent.question.uri])
}} />
</div>
}
Expand Down
6 changes: 5 additions & 1 deletion rdmo/management/assets/js/components/edit/EditQuestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const EditQuestion = ({ config, question, elements, elementActions}) => {

const info = <QuestionInfo question={question} elements={elements} elementActions={elementActions} />

// for reasons unknown, the strings are not picked up by makemessages from the props
const addOptionText = gettext('Add existing optionset')
const createOptionText = gettext('Create new optionset')

return (
<div className="panel panel-default panel-edit">
<div className="panel-heading">
Expand Down Expand Up @@ -153,7 +157,7 @@ const EditQuestion = ({ config, question, elements, elementActions}) => {
</Tab>
<Tab key={1} eventKey={1} title={gettext('Option sets')}>
<MultiSelect config={config} element={question} field="optionsets" options={optionsets}
addText={gettext('Add existing optionset')} createText={gettext('Create new optionset')}
addText={addOptionText} createText={createOptionText}
onChange={updateQuestion} onCreate={createOptionSet} onEdit={editOptionSet} />
</Tab>
<Tab key={2} eventKey={2} title={gettext('Range')}>
Expand Down
2 changes: 1 addition & 1 deletion rdmo/management/assets/js/components/element/Attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Attribute = ({ config, attribute, elementActions, display='list', indent=0
<div>
<p>
<strong>{gettext('Attribute')}{': '}</strong>
<CodeLink className="code-domain" uri={attribute.uri} onClick={() => fetchEdit()} />
<CodeLink className="code-domain" uri={attribute.uri} href={editUrl} onClick={() => fetchEdit()} />
</p>
<ElementErrors element={attribute} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion rdmo/management/assets/js/components/element/Catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const Catalog = ({ config, catalog, elementActions, display='list',
</p>
{
get(config, 'display.uri.catalogs', true) &&
<CodeLink className="code-questions" uri={catalog.uri} onClick={() => fetchEdit()} />
<CodeLink className="code-questions" uri={catalog.uri} href={editUrl} onClick={() => fetchEdit()} />
}
<ElementErrors element={catalog} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion rdmo/management/assets/js/components/element/Condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Condition = ({ config, condition, elementActions, filter=false, filterEdit
<div>
<p>
<strong>{gettext('Condition')}{': '}</strong>
<CodeLink className="code-conditions" uri={condition.uri} onClick={() => fetchEdit()} />
<CodeLink className="code-conditions" uri={condition.uri} href={editUrl} onClick={() => fetchEdit()} />
</p>
<ElementErrors element={condition} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion rdmo/management/assets/js/components/element/Option.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Option = ({ config, option, elementActions, display='list', indent=0, filt
</p>
{
get(config, 'display.uri.options', true) &&
<CodeLink className="code-options" uri={option.uri} onClick={() => fetchEdit()} />
<CodeLink className="code-options" uri={option.uri} href={editUrl} onClick={() => fetchEdit()} />
}
<ElementErrors element={option} />
</div>
Expand Down
18 changes: 17 additions & 1 deletion rdmo/management/assets/js/components/element/OptionSet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import get from 'lodash/get'

import { filterElement } from '../../utils/filter'
import { buildPath } from '../../utils/location'
Expand All @@ -18,12 +19,15 @@ const OptionSet = ({ config, optionset, elementActions, display='list', filter=f
const nestedUrl = buildPath(config.baseUrl, 'optionsets', optionset.id, 'nested')
const exportUrl = buildPath(config.apiUrl, 'options', 'optionsets', optionset.id, 'export')

const getConditionUrl = (index) => buildPath(config.apiUrl, 'conditions', 'conditions', optionset.conditions[index])

const fetchEdit = () => elementActions.fetchElement('optionsets', optionset.id)
const fetchCopy = () => elementActions.fetchElement('optionsets', optionset.id, 'copy')
const fetchNested = () => elementActions.fetchElement('optionsets', optionset.id, 'nested')
const toggleLocked = () => elementActions.storeElement('optionsets', {...optionset, locked: !optionset.locked })

const createOption = () => elementActions.createElement('options', { optionset })
const fetchCondition = (index) => elementActions.fetchElement('conditions', optionset.conditions[index])

const elementNode = (
<div className="element">
Expand All @@ -41,8 +45,20 @@ const OptionSet = ({ config, optionset, elementActions, display='list', filter=f
<div>
<p>
<strong>{gettext('Option set')}{': '}</strong>
<CodeLink className="code-options" uri={optionset.uri} onClick={() => fetchEdit()} />
<CodeLink className="code-options" uri={optionset.uri} href={editUrl} onClick={() => fetchEdit()} />
</p>
{
get(config, 'display.uri.conditions', true) && optionset.condition_uris.map((uri, index) => (
<p key={index}>
<CodeLink
className="code-conditions"
uri={uri}
href={getConditionUrl(index)}
onClick={() => fetchCondition(index)}
/>
</p>
))
}
<ElementErrors element={optionset} />
</div>
</div>
Expand Down
25 changes: 22 additions & 3 deletions rdmo/management/assets/js/components/element/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const Page = ({ config, page, configActions, elementActions, display='list', ind
const copyUrl = buildPath(config.baseUrl, 'pages', page.id, 'copy')
const nestedUrl = buildPath(config.baseUrl, 'pages', page.id, 'nested')
const exportUrl = buildPath(config.apiUrl, 'questions', 'pages', page.id, 'export')
const attributeUrl = buildPath(config.apiUrl, 'domain', 'attributes', page.attribute)

const getConditionUrl = (index) => buildPath(config.apiUrl, 'conditions', 'conditions', page.conditions[index])

const fetchEdit = () => elementActions.fetchElement('pages', page.id)
const fetchCopy = () => elementActions.fetchElement('pages', page.id, 'copy')
Expand Down Expand Up @@ -58,18 +61,34 @@ const Page = ({ config, page, configActions, elementActions, display='list', ind
</p>
{
get(config, 'display.uri.pages', true) && <p>
<CodeLink className="code-questions" uri={page.uri} onClick={() => fetchEdit()} order={order} />
<CodeLink
className="code-questions"
uri={page.uri}
href={editUrl}
onClick={() => fetchEdit()}
order={order}
/>
</p>
}
{
get(config, 'display.uri.attributes', true) && page.attribute_uri && <p>
<CodeLink className="code-domain" uri={page.attribute_uri} onClick={() => fetchAttribute()} />
<CodeLink
className="code-domain"
uri={page.attribute_uri}
href={attributeUrl}
onClick={() => fetchAttribute()}
/>
</p>
}
{
get(config, 'display.uri.conditions', true) && page.condition_uris.map((uri, index) => (
<p key={index}>
<CodeLink className="code-conditions" uri={uri} onClick={() => fetchCondition(index)} />
<CodeLink
className="code-conditions"
uri={uri}
href={getConditionUrl(index)}
onClick={() => fetchCondition(index)}
/>
</p>
))
}
Expand Down
29 changes: 25 additions & 4 deletions rdmo/management/assets/js/components/element/Question.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const Question = ({ config, question, elementActions, display='list', indent=0,
const editUrl = buildPath(config.baseUrl, 'questions', question.id)
const copyUrl = buildPath(config.baseUrl, 'questions', question.id, 'copy')
const exportUrl = buildPath(config.apiUrl, 'questions', 'questions', question.id, 'export')
const attributeUrl = buildPath(config.apiUrl, 'domain', 'attributes', question.attribute)

const getConditionUrl = (index) => buildPath(config.apiUrl, 'conditions', 'conditions', question.conditions[index])
const getOptionSetUrl = (index) => buildPath(config.apiUrl, 'options', 'optionsets', question.optionsets[index])

const fetchEdit = () => elementActions.fetchElement('questions', question.id)
const fetchCopy = () => elementActions.fetchElement('questions', question.id, 'copy')
Expand Down Expand Up @@ -46,25 +50,42 @@ const Question = ({ config, question, elementActions, display='list', indent=0,
</p>
{
get(config, 'display.uri.questions', true) && <p>
<CodeLink className="code-questions" uri={question.uri} onClick={() => fetchEdit()} order={order} />
<CodeLink
className="code-questions"
uri={question.uri}
href={editUrl}
onClick={() => fetchEdit()}
order={order} />
</p>
}
{
get(config, 'display.uri.attributes', true) && question.attribute_uri && <p>
<CodeLink className="code-domain" uri={question.attribute_uri} onClick={() => fetchAttribute()} />
<CodeLink
className="code-domain"
uri={question.attribute_uri}
href={attributeUrl}
onClick={() => fetchAttribute()} />
</p>
}
{
get(config, 'display.uri.conditions', true) && question.condition_uris.map((uri, index) => (
<p key={index}>
<CodeLink className="code-conditions" uri={uri} onClick={() => fetchCondition(index)} />
<CodeLink
className="code-conditions"
uri={uri}
href={getConditionUrl(index)}
onClick={() => fetchCondition(index)} />
</p>
))
}
{
get(config, 'display.uri.optionsets', true) && question.optionset_uris.map((uri, index) => (
<p key={index}>
<CodeLink className="code-options" uri={uri} onClick={() => fetchOptionSet(index)} />
<CodeLink
className="code-options"
uri={uri}
href={getOptionSetUrl(index)}
onClick={() => fetchOptionSet(index)} />
</p>
))
}
Expand Down
25 changes: 22 additions & 3 deletions rdmo/management/assets/js/components/element/QuestionSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const QuestionSet = ({ config, questionset, configActions, elementActions, displ
const copyUrl = buildPath(config.baseUrl, 'questionsets', questionset.id, 'copy')
const nestedUrl = buildPath(config.baseUrl, 'questionsets', questionset.id, 'nested')
const exportUrl = buildPath(config.apiUrl, 'questions', 'questionsets', questionset.id, 'export')
const attributeUrl = buildPath(config.apiUrl, 'domain', 'attributes', questionset.attribute)

const getConditionUrl = (index) => buildPath(config.apiUrl, 'conditions', 'conditions', questionset.conditions[index])

const fetchEdit = () => elementActions.fetchElement('questionsets', questionset.id)
const fetchCopy = () => elementActions.fetchElement('questionsets', questionset.id, 'copy')
Expand Down Expand Up @@ -57,18 +60,34 @@ const QuestionSet = ({ config, questionset, configActions, elementActions, displ
</p>
{
get(config, 'display.uri.questionsets', true) && <p>
<CodeLink className="code-questions" uri={questionset.uri} onClick={() => fetchEdit()} order={order} />
<CodeLink
className="code-questions"
uri={questionset.uri}
href={editUrl}
onClick={() => fetchEdit()}
order={order}
/>
</p>
}
{
get(config, 'display.uri.attributes', true) && questionset.attribute_uri &&<p>
<CodeLink className="code-domain" uri={questionset.attribute_uri} onClick={() => fetchAttribute()} />
<CodeLink
className="code-domain"
uri={questionset.attribute_uri}
href={attributeUrl}
onClick={() => fetchAttribute()}
/>
</p>
}
{
get(config, 'display.uri.conditions', true) && questionset.condition_uris.map((uri, index) => (
<p key={index}>
<CodeLink className="code-conditions" uri={uri} onClick={() => fetchCondition(index)} />
<CodeLink
className="code-conditions"
uri={uri}
href={getConditionUrl(index)}
onClick={() => fetchCondition(index)}
/>
</p>
))
}
Expand Down
2 changes: 1 addition & 1 deletion rdmo/management/assets/js/components/element/Section.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const Section = ({ config, section, configActions, elementActions, display='list
</p>
{
get(config, 'display.uri.sections', true) &&
<CodeLink className="code-questions" uri={section.uri} onClick={() => fetchEdit()} order={order} />
<CodeLink className="code-questions" uri={section.uri} href={editUrl} onClick={() => fetchEdit()} order={order} />
}
<ElementErrors element={section} />
</div>
Expand Down
11 changes: 9 additions & 2 deletions rdmo/management/assets/js/components/element/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const Task = ({ config, task, elementActions, filter=false, filterSites=false, f
const copyUrl = buildPath(config.baseUrl, 'tasks', task.id, 'copy')
const exportUrl = buildPath(config.apiUrl, 'tasks', 'tasks', task.id, 'export')

const getConditionUrl = (index) => buildPath(config.apiUrl, 'conditions', 'conditions', task.conditions[index])

const fetchEdit = () => elementActions.fetchElement('tasks', task.id)
const fetchCopy = () => elementActions.fetchElement('tasks', task.id, 'copy')
const toggleAvailable = () => elementActions.storeElement('tasks', {...task, available: !task.available })
Expand Down Expand Up @@ -51,13 +53,18 @@ const Task = ({ config, task, elementActions, filter=false, filterSites=false, f
</p>
{
get(config, 'display.uri.tasks', true) && <p>
<CodeLink className="code-tasks" uri={task.uri} onClick={() => fetchEdit()} />
<CodeLink className="code-tasks" uri={task.uri} href={editUrl} onClick={() => fetchEdit()} />
</p>
}
{
get(config, 'display.uri.conditions', true) && task.condition_uris.map((uri, index) => (
<p key={index}>
<CodeLink className="code-conditions" uri={uri} onClick={() => fetchCondition(index)} />
<CodeLink
className="code-conditions"
uri={uri}
href={getConditionUrl(index)}
onClick={() => fetchCondition(index)}
/>
</p>
))
}
Expand Down
2 changes: 1 addition & 1 deletion rdmo/management/assets/js/components/element/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const View = ({ config, view, elementActions, filter=false, filterSites=false, f
<div>
<p>
<strong>{gettext('View')}{': '}</strong>
<CodeLink className="code-views" uri={view.uri} onClick={() => fetchEdit()} />
<CodeLink className="code-views" uri={view.uri} href={editUrl} onClick={() => fetchEdit()} />
</p>
<ElementErrors element={view} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion rdmo/management/assets/js/constants/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const elementTypes = {
'questions.page': 'pages',
'questions.questionset': 'questionsets',
'questions.question': 'questions',
'domain.attribute':'attributes',
'domain.attribute': 'attributes',
'options.optionset': 'optionsets',
'options.option': 'options',
'conditions.condition': 'conditions',
Expand Down
3 changes: 3 additions & 0 deletions rdmo/management/assets/js/reducers/elementsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function elementsReducer(state = initialState, action) {
elementId: null,
elementAction: null,
element: null,
parent: null,
errors: {}
}
case 'elements/fetchElementsSuccess':
Expand All @@ -46,6 +47,7 @@ export default function elementsReducer(state = initialState, action) {
elementId: action.elementId,
elementAction: action.elementAction,
element: null,
parent: null,
errors: {}
}
case 'elements/fetchElementSuccess':
Expand Down Expand Up @@ -89,6 +91,7 @@ export default function elementsReducer(state = initialState, action) {
elementId: null,
elementAction: 'create',
element: null,
parent: null,
errors: {}
}
case 'elements/createElementSuccess':
Expand Down
Loading

0 comments on commit 7208136

Please sign in to comment.