Skip to content

Commit

Permalink
[conflict_resolver] Add description field (#8845)
Browse files Browse the repository at this point in the history
This adds a 'Description' field to the Conflict Resolver module (both Resolved and Unresolved tabs), which corresponds to the description of the 'Question' with the conflict. It uses /dictionary/module/instruments to get the description of the fields. Since some fields don't have descriptions (e.g. some _status variables), the empty string is used as default.

Changes have been made to the Instrument_LINST file such that numeric and date elements are added to the dictionary, even if they are not in the top page (inspired by the change in #8869).
  • Loading branch information
charlottesce authored Aug 29, 2023
1 parent e1df7cb commit b0a24a9
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 21 deletions.
39 changes: 37 additions & 2 deletions modules/conflict_resolver/jsx/resolved_filterabledatatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ class ResolvedFilterableDataTable extends Component {

this.state = {
data: {},
fieldsMeta: {},
isLoaded: false,
};

this.fetchFieldsMeta = this.fetchFieldsMeta.bind(this);
this.fetchData = this.fetchData.bind(this);
this.formatColumn = this.formatColumn.bind(this);
}
Expand All @@ -27,7 +29,8 @@ class ResolvedFilterableDataTable extends Component {
* Fetch data upon component mount
*/
componentDidMount() {
this.fetchData()
this.fetchFieldsMeta()
.then(() => this.fetchData())
.then(() => this.setState({isLoaded: true}));
}

Expand All @@ -45,6 +48,26 @@ class ResolvedFilterableDataTable extends Component {
<td>{cell}</td>
);
}

/**
* Retrieve all the field metadata
*
* @return {object}
*/
fetchFieldsMeta() {
const url = loris.BaseURL.concat('/dictionary/module/instruments');
return fetch(url, {credentials: 'same-origin'})
.then((resp) => resp.json())
.then((json) => {
if (json.error) {
throw new Error(json.error);
}
this.setState({fieldsMeta: json});
})
.catch((error) => {
this.setState({error});
});
}
/**
* Retrieve data from the provided URL and save it in state
*
Expand All @@ -62,7 +85,15 @@ class ResolvedFilterableDataTable extends Component {
}
const data = {
fieldOptions: json.fieldOptions,
data: json.data.map((e) => Object.values(e)),
data: json.data.map((e) => {
const fieldInfo = this.state.fieldsMeta[e['Instrument']][
e['Instrument']
+ '_'
+ e['Question']
];
e['Description'] = fieldInfo ? fieldInfo['description'] : '';
return Object.values(e);
}),
};
this.setState({data});
})
Expand Down Expand Up @@ -129,6 +160,10 @@ class ResolvedFilterableDataTable extends Component {
name: 'Question',
type: 'text',
}},
{label: 'Description', show: true, filter: {
name: 'Description',
type: 'text',
}},
{label: 'Value 1', show: true, filter: {
name: 'Value1',
type: 'text',
Expand Down
39 changes: 37 additions & 2 deletions modules/conflict_resolver/jsx/unresolved_filterabledatatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ class UnresolvedFilterableDataTable extends Component {

this.state = {
data: {},
fieldsMeta: {},
isLoaded: false,
};

this.fetchFieldsMeta = this.fetchFieldsMeta.bind(this);
this.fetchData = this.fetchData.bind(this);
this.formatColumn = this.formatColumn.bind(this);
}
Expand All @@ -28,7 +30,8 @@ class UnresolvedFilterableDataTable extends Component {
* Fetches data upon component mount.
*/
componentDidMount() {
this.fetchData()
this.fetchFieldsMeta()
.then(() => this.fetchData())
.then(() => this.setState({isLoaded: true}));
}

Expand Down Expand Up @@ -59,6 +62,26 @@ class UnresolvedFilterableDataTable extends Component {
<td>{cell}</td>
);
}

/**
* Retrieve all the field metadata
*
* @return {object}
*/
fetchFieldsMeta() {
const url = loris.BaseURL.concat('/dictionary/module/instruments');
return fetch(url, {credentials: 'same-origin'})
.then((resp) => resp.json())
.then((json) => {
if (json.error) {
throw new Error(json.error);
}
this.setState({fieldsMeta: json});
})
.catch((error) => {
this.setState({error});
});
}
/**
* Retrieve data from the provided URL and save it in state
*
Expand All @@ -74,7 +97,15 @@ class UnresolvedFilterableDataTable extends Component {
}
const data = {
fieldOptions: json.fieldOptions,
data: json.data.map((e) => Object.values(e)),
data: json.data.map((e) => {
const fieldInfo = this.state.fieldsMeta[e['Instrument']][
e['Instrument']
+ '_'
+ e['Question']
];
e['Description'] = fieldInfo ? fieldInfo['description'] : '';
return Object.values(e);
}),
};
this.setState({data});
})
Expand Down Expand Up @@ -141,6 +172,10 @@ class UnresolvedFilterableDataTable extends Component {
name: 'Question',
type: 'text',
}},
{label: 'Description', show: true, filter: {
name: 'Description',
type: 'text',
}},
{label: 'Value 1', show: false},
{label: 'Value 2', show: false},
{label: 'Correct Answer', show: true},
Expand Down
2 changes: 2 additions & 0 deletions modules/conflict_resolver/php/models/resolveddto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ResolvedDTO implements DataInstance, SiteHaver
protected $visitlabel;
protected $instrument;
protected $question;
protected $description;
protected $value1;
protected $value2;
protected $correctanswer;
Expand All @@ -67,6 +68,7 @@ class ResolvedDTO implements DataInstance, SiteHaver
'Visit Label' => $this->visitlabel,
'Instrument' => $this->instrument,
'Question' => $this->question,
'Description' => "",
'Value 1' => $this->value1,
'Value 2' => $this->value2,
'Correct Answer' => $this->correctanswer,
Expand Down
2 changes: 2 additions & 0 deletions modules/conflict_resolver/php/models/unresolveddto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class UnresolvedDTO implements DataInstance, SiteHaver
protected $visitlabel;
protected $instrument;
protected $question;
protected $description;
protected $value1;
protected $value2;

Expand All @@ -62,6 +63,7 @@ class UnresolvedDTO implements DataInstance, SiteHaver
'Visit Label' => $this->visitlabel,
'Instrument' => $this->instrument,
'Question' => $this->question,
'Description' => "",
'Value 1' => $this->value1,
'Value 2' => $this->value2,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UnresolvedProvisioner extends \LORIS\Data\Provisioners\DBObjectProvisioner
session.CenterID as centerid,
Project.ProjectID as projectid
FROM
conflicts_unresolved
conflicts_unresolved
LEFT JOIN flag ON (conflicts_unresolved.CommentId1=flag.CommentID)
LEFT JOIN session ON (flag.SessionID=session.ID)
LEFT JOIN candidate ON (candidate.CandID=session.CandID)
Expand Down
32 changes: 16 additions & 16 deletions php/libraries/NDB_BVL_Instrument_LINST.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,6 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
];
}

$this->dictionary[] = new DictionaryItem(
$this->testName."_".$pieces[1],
$pieces[2],
$scope,
new DateType(),
new Cardinality(Cardinality::SINGLE),
$pieces[1],
);
// Set date format
$dateFormat = isset($pieces[5]) ? trim($pieces[5]) : "";

Expand Down Expand Up @@ -742,6 +734,14 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
);
}
}
$this->dictionary[] = new DictionaryItem(
$this->testName."_".$pieces[1],
$pieces[2],
$scope,
new DateType(),
new Cardinality(Cardinality::SINGLE),
$pieces[1],
);
if ($firstFieldOfPage) {
$this->_requiredElements[] = $fieldname;
$firstFieldOfPage = false;
Expand All @@ -750,15 +750,15 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
case 'numeric':
if ($addElements) {
$this->addNumericElement($pieces[1], $pieces[2]);
$this->dictionary[] = new DictionaryItem(
$this->testName."_".$pieces[1],
$pieces[2],
$scope,
new IntegerType(),
new Cardinality(Cardinality::SINGLE),
$pieces[1],
);
}
$this->dictionary[] = new DictionaryItem(
$this->testName."_".$pieces[1],
$pieces[2],
$scope,
new IntegerType(),
new Cardinality(Cardinality::SINGLE),
$pieces[1],
);
if ($firstFieldOfPage) {
$this->_requiredElements[] = $fieldname;
$firstFieldOfPage = false;
Expand Down

0 comments on commit b0a24a9

Please sign in to comment.