Lucas Werkmeister (WMDE) has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/373323 )
Change subject: Refactor gadget.js
......................................................................
Refactor gadget.js
In preparation for T168532, several functions are split out of
addReportsToStatement:
- buildReportList builds the ConstraintReportList and checks if it
should be displayed.
- extractResultsForStatement extracts the results for one statement from
the API response. It supports both output format versions of the API,
and will later also extract qualifier and reference snak results.
- addResultsToSnak appends the ConstraintReportList to a snak’s DOM.
addReportsToStatement’s $statement argument is also changed to hold the
general .wikibase-statementview element; selecting its mainsnak snakview
value is done in addReportsToStatement and addResultsToSnak.
Change-Id: I99379a96cda50c9ed21b743dbff5c1ae6288bd7d
---
M modules/gadget.js
1 file changed, 75 insertions(+), 23 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
refs/changes/23/373323/1
diff --git a/modules/gadget.js b/modules/gadget.js
index afbafb1..8a1b000 100644
--- a/modules/gadget.js
+++ b/modules/gadget.js
@@ -48,26 +48,8 @@
} );
}
- function addReportsToStatement( entityData, $statement ) {
- var match = $statement.parents( '.wikibase-statementview' )[ 0
].className.match(
- /\bwikibase-statement-([^\s$]+\$[\dA-F-]+)\b/i
- ),
- statementId = match && match[ 1 ],
- propertyId = $statement.parents(
'.wikibase-statementgroupview' )[ 0 ].id,
- results,
- reports,
- list,
- $target,
- haveMandatoryViolations;
-
- if ( !( propertyId in entityData && statementId in entityData[
propertyId ] ) ) {
- return;
- }
-
- results = entityData[ propertyId ][ statementId ];
- reports = results.map( buildReport );
-
- list =
wikibase.quality.constraints.ui.ConstraintReportList.static.fromPanels(
+ function buildReportList( reports ) {
+ var list =
wikibase.quality.constraints.ui.ConstraintReportList.static.fromPanels(
reports,
{
statuses: [
@@ -95,11 +77,59 @@
// ...and doesn't only contain collapsed items either
list.items[ 0 ].status !== 'bad-parameters'
) {
+ return list;
+ } else {
+ return null;
+ }
+ }
+
+ function extractResultsForStatement( entityData, propertyId,
statementId ) {
+ var statements, index, statement, results = {}, qualifierPID;
+ if ( 'claims' in entityData ) {
+ // API v2 format
+ statements = entityData.claims[ propertyId ];
+ if ( statements === undefined ) {
+ return null;
+ }
+ for ( index in statements ) {
+ if ( statements[ index ].id === statementId ) {
+ statement = statements[ index ];
+ break;
+ }
+ }
+ if ( statement === undefined ) {
+ return null;
+ }
+
+ results.mainsnak = statement.mainsnak.results;
+
+ // TODO also extract qualifier and reference snaks
+
+ return results;
+ } else {
+ // API v1 format
+ if ( propertyId in entityData && statementId in
entityData[ propertyId ] ) {
+ return {
+ mainsnak: entityData[ propertyId ][
statementId ]
+ };
+ } else {
+ return null;
+ }
+ }
+ }
+
+ function addResultsToSnak( results, $snak ) {
+ var reports = results.map( buildReport ),
+ list = buildReportList( reports ),
+ haveMandatoryViolations,
+ $target;
+
+ if ( list !== null ) {
haveMandatoryViolations = list.items[ 0 ].status ===
'violation';
- $target = $statement.find( '.valueview-instaticmode' );
+ $target = $snak.find( '.wikibase-snakview-value
.valueview-instaticmode' );
if ( $target.length === 0 ) {
- $target = $statement;
+ $target = $snak.find(
'.wikibase-snakview-value' );
}
$target.append( buildPopup(
list.$element,
@@ -107,6 +137,28 @@
haveMandatoryViolations ? 'wbqc-problems-long'
: 'wbqc-potentialissues-long'
).$element );
}
+ }
+
+ function addReportsToStatement( entityData, $statement ) {
+ var match = $statement[ 0 ].className.match(
+ /\bwikibase-statement-([^\s$]+\$[\dA-F-]+)\b/i
+ ),
+ statementId = match && match[ 1 ],
+ propertyId = $statement.parents(
'.wikibase-statementgroupview' )[ 0 ].id,
+ results = extractResultsForStatement( entityData,
propertyId, statementId ),
+ index,
+ qualifier;
+
+ if ( results === null ) {
+ return;
+ }
+
+ addResultsToSnak(
+ results.mainsnak,
+ $statement.find( '.wikibase-statementview-mainsnak' )
+ );
+
+ // TODO also add qualifier and reference results to snak
}
function addParameterReports( parameterReports ) {
@@ -170,7 +222,7 @@
uselang: lang,
id: entityId
} ).then( function( data ) {
- $( '.wikibase-statementgroupview
.wikibase-statementview-mainsnak .wikibase-snakview-value' )
+ $( '.wikibase-statementgroupview
.wikibase-statementview' )
.each( function () { addReportsToStatement(
data.wbcheckconstraints[ entityId ], $( this ) ); } );
} );
--
To view, visit https://gerrit.wikimedia.org/r/373323
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I99379a96cda50c9ed21b743dbff5c1ae6288bd7d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits