jenkins-bot has submitted this change and it was merged.
Change subject: Add external identifier support in ui
......................................................................
Add external identifier support in ui
This patch registers the new external identifier datatype in all necessary
places. Furthermore, it enables rendering of it by passing the property id
to the formatter.
Bumps required version of WikibaseJavaScriptApi to 1.1
Bug: T124918
Change-Id: Iab6305f9ba24dbfea1aa62e2a1c30c55a4613145
---
M composer.json
M repo/resources/experts/getStore.js
M repo/resources/formatters/ApiValueFormatter.js
M repo/resources/formatters/ApiValueFormatterFactory.js
M repo/resources/parsers/getStore.js
M repo/resources/wikibase.ui.entityViewInit.js
M view/resources/jquery/wikibase/snakview/snakview.variations.Value.js
M view/resources/wikibase/wikibase.ValueFormatterFactory.js
M view/resources/wikibase/wikibase.ValueViewBuilder.js
M view/tests/qunit/wikibase/wikibase.ValueViewBuilder.tests.js
10 files changed, 65 insertions(+), 20 deletions(-)
Approvals:
Hoo man: Looks good to me, but someone else must approve
Adrian Heine: Looks good to me, approved
jenkins-bot: Verified
diff --git a/composer.json b/composer.json
index ad87c63..131372a 100644
--- a/composer.json
+++ b/composer.json
@@ -38,7 +38,7 @@
"wikibase/internal-serialization": "~2.0",
"wikibase/data-model-services": "^3.2.0",
"wikibase/data-model-javascript": "~2.0.0",
- "wikibase/javascript-api": "~1.0",
+ "wikibase/javascript-api": "~1.1",
"wikibase/serialization-javascript": "~2.0.5",
"diff/diff": "~2.0"
},
diff --git a/repo/resources/experts/getStore.js
b/repo/resources/experts/getStore.js
index 25c37ff..71f98ba 100644
--- a/repo/resources/experts/getStore.js
+++ b/repo/resources/experts/getStore.js
@@ -43,11 +43,11 @@
var dataTypeIdToExpertConstructor = {
commonsMedia: vv.experts.CommonsMediaType,
+ 'external-id': vv.experts.StringValue,
monolingualtext: vv.experts.MonolingualText,
url: vv.experts.StringValue,
'wikibase-item': wb.experts.Item,
'wikibase-property': wb.experts.Property
-
};
for ( var dataTypeId in dataTypeIdToExpertConstructor ) {
diff --git a/repo/resources/formatters/ApiValueFormatter.js
b/repo/resources/formatters/ApiValueFormatter.js
index 24b0d28..86a0477 100644
--- a/repo/resources/formatters/ApiValueFormatter.js
+++ b/repo/resources/formatters/ApiValueFormatter.js
@@ -20,15 +20,17 @@
* @param {wikibase.api.FormatValueCaller} formatValueCaller
* @param {Object} additionalOptions
* @param {string|null} dataTypeId
+ * @param {string|null} propertyId
* @param {string} outputType
*/
wb.formatters.ApiValueFormatter = util.inherit(
'WbApiValueFormatter',
PARENT,
- function( formatValueCaller, additionalOptions, dataTypeId,
outputType ) {
+ function( formatValueCaller, additionalOptions, dataTypeId,
propertyId, outputType ) {
this._formatValueCaller = formatValueCaller;
this._options = additionalOptions;
this._dataTypeId = dataTypeId;
+ this._propertyId = propertyId;
this._outputType = outputType;
},
{
@@ -41,6 +43,11 @@
* @var {string|null}
*/
_dataTypeId: null,
+
+ /**
+ * @var {string|null}
+ */
+ _propertyId: null,
/**
* @var {Object}
@@ -67,7 +74,9 @@
format: function( dataValue ) {
var deferred = $.Deferred();
- this._formatValueCaller.formatValue( dataValue,
this._dataTypeId, this._outputType, this._options )
+ this._formatValueCaller.formatValue(
+ dataValue, this._dataTypeId,
this._outputType, this._propertyId, this._options
+ )
.done( function( formattedValue ) {
deferred.resolve( formattedValue,
dataValue );
} )
diff --git a/repo/resources/formatters/ApiValueFormatterFactory.js
b/repo/resources/formatters/ApiValueFormatterFactory.js
index e6d8aa4..12044e8 100644
--- a/repo/resources/formatters/ApiValueFormatterFactory.js
+++ b/repo/resources/formatters/ApiValueFormatterFactory.js
@@ -31,18 +31,19 @@
_options: null,
/**
- * Returns a ValueFormatter instance for the given
DataType id and output type
+ * Returns a ValueFormatter instance for the given
DataType ID or Property ID and output type.
*
* @param {string|null} dataTypeId
+ * @param {string|null} propertyId
* @param {string} outputType
* @return {valueFormatters.ValueFormatter}
*/
- getFormatter: function( dataTypeId, outputType ) {
+ getFormatter: function( dataTypeId, propertyId,
outputType ) {
var options = this._options;
if ( dataTypeId === 'quantity' && outputType
=== 'text/plain' ) {
options = $.extend( { applyRounding:
false, applyUnit: false }, options );
}
- return new wb.formatters.ApiValueFormatter(
this._apiCaller, options, dataTypeId, outputType );
+ return new wb.formatters.ApiValueFormatter(
this._apiCaller, options, dataTypeId, propertyId, outputType );
}
}
);
diff --git a/repo/resources/parsers/getStore.js
b/repo/resources/parsers/getStore.js
index 8d73757..964a585 100644
--- a/repo/resources/parsers/getStore.js
+++ b/repo/resources/parsers/getStore.js
@@ -58,6 +58,14 @@
'url'
);
+ parserStore.registerDataTypeParser(
+ util.inherit(
+ ApiBasedValueParser,
+ { API_VALUE_PARSER_ID: 'external-id' }
+ ),
+ 'external-id'
+ );
+
return parserStore;
};
diff --git a/repo/resources/wikibase.ui.entityViewInit.js
b/repo/resources/wikibase.ui.entityViewInit.js
index 42cc644..db0ba21 100644
--- a/repo/resources/wikibase.ui.entityViewInit.js
+++ b/repo/resources/wikibase.ui.entityViewInit.js
@@ -106,8 +106,8 @@
userLanguages[0]
),
parserStore = getParserStore( repoApi ),
- htmlDataValueEntityIdFormatter =
formatterFactory.getFormatter( null, 'text/html' ),
- plaintextDataValueEntityIdFormatter =
formatterFactory.getFormatter( null, 'text/plain' ),
+ htmlDataValueEntityIdFormatter =
formatterFactory.getFormatter( null, null, 'text/html' ),
+ plaintextDataValueEntityIdFormatter =
formatterFactory.getFormatter( null, null, 'text/plain' ),
entityIdParser = new ( parserStore.getParser(
wb.datamodel.EntityId.TYPE ) )( { lang: userLanguages[0] } ),
viewFactory = new wikibase.view.ViewFactory(
contentLanguages,
diff --git
a/view/resources/jquery/wikibase/snakview/snakview.variations.Value.js
b/view/resources/jquery/wikibase/snakview/snakview.variations.Value.js
index 2f3182d..e08e54b 100644
--- a/view/resources/jquery/wikibase/snakview/snakview.variations.Value.js
+++ b/view/resources/jquery/wikibase/snakview/snakview.variations.Value.js
@@ -181,7 +181,9 @@
return;
}
- var dataType = _getDataType(
fetchedProperty );
+ var dataType = _getDataType(
fetchedProperty ),
+ propertyId = fetchedProperty ?
fetchedProperty.getId() : null;
+
if ( fetchedProperty && !dataType ) {
mw.log.warn(
'Found property ' +
fetchedProperty.getId() + ' in entityStore but couldn\'t find ' +
@@ -215,7 +217,7 @@
} else {
// remove old view, create a
new one or display message if unsupported data
// type or other issue which
would prevent from creating a valueview
- self._createNewValueView(
newValue, dataType );
+ self._createNewValueView(
newValue, dataType, propertyId );
}
self.$viewPort.removeClass(
@@ -341,9 +343,10 @@
* @param {dataTypes.DataType} [dataType] The `DataTypes` which
the given `DataValue` has
* been created for. Can be omitted but might result in
a less specialized
* `jQuery.valueview`.
+ * @param {string} [propertyId]
* @return {boolean} Whether a `jQuery.valueview` has actually
been instantiated.
*/
- _createNewValueView: function( dataValue, dataType ) {
+ _createNewValueView: function( dataValue, dataType, propertyId
) {
var $valueViewDom;
if ( this._valueView ) {
@@ -372,7 +375,8 @@
this._valueView = this._valueViewBuilder.initValueView(
$valueViewDom,
dataType,
- dataValue
+ dataValue,
+ propertyId
);
return true;
diff --git a/view/resources/wikibase/wikibase.ValueFormatterFactory.js
b/view/resources/wikibase/wikibase.ValueFormatterFactory.js
index d79217b..1fc3e63 100644
--- a/view/resources/wikibase/wikibase.ValueFormatterFactory.js
+++ b/view/resources/wikibase/wikibase.ValueFormatterFactory.js
@@ -6,9 +6,10 @@
};
/**
- * Returns a ValueFormatter instance for the given DataType id and output type
+ * Returns a ValueFormatter instance for the given DataType ID or Property ID
and output type.
*
* @param {string|null} dataTypeId
+ * @param {string|null} propertyId
* @param {string} outputType
* @return {valueFormatters.ValueFormatter}
*/
diff --git a/view/resources/wikibase/wikibase.ValueViewBuilder.js
b/view/resources/wikibase/wikibase.ValueViewBuilder.js
index 0d7794f..c20fad1 100644
--- a/view/resources/wikibase/wikibase.ValueViewBuilder.js
+++ b/view/resources/wikibase/wikibase.ValueViewBuilder.js
@@ -51,12 +51,13 @@
* @param {jQuery} $valueViewDom
* @param {dataTypes.DataType|null} dataType
* @param {dataValues.DataValue|null} dataValue
+ * @param {string|null} propertyId
*
* @return {jQuery.valueview}
*/
- initValueView: function( $valueViewDom, dataType, dataValue ) {
+ initValueView: function( $valueViewDom, dataType, dataValue,
propertyId ) {
var valueView,
- valueViewOptions = this._getOptions( dataType,
dataValue );
+ valueViewOptions = this._getOptions( dataType,
dataValue, propertyId );
// TODO: Use something like an 'editview' and just
change its data type rather than
// initializing this over and over again and doing the
checks.
@@ -69,14 +70,15 @@
/**
* @param {dataTypes.DataType|null} dataType
* @param {dataValues.DataValue|null} dataValue
+ * @param {string|null} propertyId
*
* @return {Object}
*/
- _getOptions: function( dataType, dataValue ) {
+ _getOptions: function( dataType, dataValue, propertyId ) {
var dataTypeId = dataType && dataType.getId();
var valueViewOptions = $.extend( {}, this._baseOptions,
{
- htmlFormatter:
this._formatterFactory.getFormatter( dataTypeId, 'text/html' ),
- plaintextFormatter:
this._formatterFactory.getFormatter( dataTypeId, 'text/plain' ),
+ htmlFormatter:
this._formatterFactory.getFormatter( dataTypeId, propertyId, 'text/html' ),
+ plaintextFormatter:
this._formatterFactory.getFormatter( dataTypeId, propertyId, 'text/plain' ),
value: dataValue
} );
diff --git a/view/tests/qunit/wikibase/wikibase.ValueViewBuilder.tests.js
b/view/tests/qunit/wikibase/wikibase.ValueViewBuilder.tests.js
index 76cb9f7..6dfc6a9 100644
--- a/view/tests/qunit/wikibase/wikibase.ValueViewBuilder.tests.js
+++ b/view/tests/qunit/wikibase/wikibase.ValueViewBuilder.tests.js
@@ -70,7 +70,7 @@
htmlFormatter = {},
plaintextFormatter = {},
formatterFactory = {
- getFormatter: function( _, outputType ) {
+ getFormatter: function( dataTypeId, propertyId,
outputType ) {
return outputType === 'text/html' ?
htmlFormatter : plaintextFormatter;
}
};
@@ -175,4 +175,24 @@
} ) );
} );
+ QUnit.test( 'initValueView passes dataTypeId & propertyId', function(
assert ) {
+ assert.expect( 1 );
+ var vvAndDom = getValueViewAndDom(),
+ $dom = vvAndDom.$dom,
+ getFormatter = sinon.spy(),
+ dataType = {
+ getId: function() { return 'datatype id'; },
+ getDataValueType: function() { return
'datavaluetype id'; }
+ };
+
+ var valueViewBuilder = new wb.ValueViewBuilder(
+ null,
+ { getFormatter: getFormatter }
+ );
+
+ valueViewBuilder.initValueView( $dom, dataType, null, 'property
id' );
+
+ sinon.assert.calledWith( getFormatter, sinon.match( 'datatype
id', 'property id' ) );
+ } );
+
}( wikibase, sinon, QUnit ) );
--
To view, visit https://gerrit.wikimedia.org/r/266761
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iab6305f9ba24dbfea1aa62e2a1c30c55a4613145
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
Gerrit-Reviewer: Adrian Heine <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits