jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/365988 )
Change subject: Extract ConstraintReport{Group,List} classes ...................................................................... Extract ConstraintReport{Group,List} classes ConstraintReportGroup groups together a set of ConstraintReportPanels, and ConstraintReportList is a list of such groups. ConstraintReportList also has a static method to sort a flat list of constraint reports into groups by status. Bug: T169971 Change-Id: I6e31e84d40d4b3e8edfc7bd4359ae615a595453d --- M .eslintrc.json A modules/ui/ConstraintReportGroup.css A modules/ui/ConstraintReportGroup.js A modules/ui/ConstraintReportList.js 4 files changed, 265 insertions(+), 0 deletions(-) Approvals: Jonas Kress (WMDE): Looks good to me, approved jenkins-bot: Verified diff --git a/.eslintrc.json b/.eslintrc.json index bd8174d..fa5b64c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,6 +10,7 @@ "OO": false }, "rules": { + "dot-notation": [ "error", { "allowKeywords": true } ], "keyword-spacing": "off", "space-before-function-paren": "off", "wrap-iife": "off" diff --git a/modules/ui/ConstraintReportGroup.css b/modules/ui/ConstraintReportGroup.css new file mode 100644 index 0000000..4d68f51 --- /dev/null +++ b/modules/ui/ConstraintReportGroup.css @@ -0,0 +1,4 @@ +.wikibase-toolbar-item .mw-collapsible-toggle * { + /* wikibase CSS adds an icon, so hide the normal [expand] link */ + display: none; +} diff --git a/modules/ui/ConstraintReportGroup.js b/modules/ui/ConstraintReportGroup.js new file mode 100644 index 0000000..697e80d --- /dev/null +++ b/modules/ui/ConstraintReportGroup.js @@ -0,0 +1,97 @@ +( function( OO, wb ) { + 'use strict'; + + /** + * A panel for a group of constraint report results. + * + * @example + * var group = new wikibase.quality.constraints.ui.ConstraintReportGroup( { + * items: [ + * new wikibase.quality.constraints.ui.ConstraintReportPanel( { + * status: 'compliance', + * constraint: { + * type: 'Q1', + * typeLabel: 'my constraint', + * link: 'http://example.com/my-constraint' + * }, + * message: 'everything okay' + * } ) + * ], + * heading: 'reports that are fine', + * collapsed: true, + * expanded: false, + * framed: true + * } ); + * $( 'body' ).append( group.$element ); + * + * @class + * @extends OO.ui.StackLayout + * + * @constructor + * @param {Object} config Configuration options + * @cfg {wikibase.quality.constraints.ui.ConstraintReportPanel[]} items The individual constraint report results. + * @cfg {string} [heading] The heading of the group. + * @cfg {string} [subheading] The subheading of the group. Unlike the heading, it is part of the collapsed content if `collapsible` is `true`. + * @cfg {boolean} [collapsible=false] Whether the group can be collapsed or not. If `true`, a `heading` is recommended. + * @cfg {boolean} [collapsed=false] Whether the group is collapsed by default or not. (If `true`, implies `collapsible=true` as well.) + * @cfg {string} [status] The status of all reports in this group. Unused by this class, but assigned by `ConstraintReportList.fromPanels`. + */ + wb.quality.constraints.ui.ConstraintReportGroup = function WBQCConstraintReportGroup( config ) { + + var heading = config.heading || null, + collapsible = config.collapsible || config.collapsed || false, + collapsed = config.collapsed || false, + subheading = config.subheading || null, + status = config.status || null, + $subheadingContainer; + + // Configuration initialization + config.continuous = true; + config.classes = OO.simpleArrayUnion( + config.classes || [], + [ 'wbqc-reports' ] + ); + + // Parent constructor + wb.quality.constraints.ui.ConstraintReportGroup.parent.call( this, config ); + + // Mixin constructors + // (none) + + // Properties + this.heading = heading; + this.collapsible = collapsible; + this.collapsed = collapsed; + this.status = status; + + // Initialization + if ( collapsible ) { + this.$element.makeCollapsible( { collapsed: collapsed } ); + } + if ( heading !== null ) { + this.$element.prepend( $( '<strong>' ).text( heading ) ); + } + if ( subheading !== null ) { + $subheadingContainer = collapsible ? + this.$element.find( '.mw-collapsible-content' ) : + this.$element; + $subheadingContainer.prepend( + $( '<p>' ).append( $( '<small>' ).text( subheading ) ) + ); + } + if ( collapsible && heading === null && subheading === null ) { + // we need a spacer before the toggler, + // otherwise it's not clickable because it's on the same height as the items and behind them + this.$element.prepend( $( '<span> </span>' ) ); + } + }; + + /* Setup */ + + OO.inheritClass( wb.quality.constraints.ui.ConstraintReportGroup, OO.ui.StackLayout ); + + /* Methods */ + + // (none) + +}( OO, wikibase ) ); diff --git a/modules/ui/ConstraintReportList.js b/modules/ui/ConstraintReportList.js new file mode 100644 index 0000000..aa89bed --- /dev/null +++ b/modules/ui/ConstraintReportList.js @@ -0,0 +1,163 @@ +( function( OO, wb ) { + 'use strict'; + + /** + * A panel for a list of constraint report results grouped by status. + * + * Usually, you want to initialize the list directly from a list of constraint reports. + * Use the static method {@link wikibase.quality.constraints.ui.ConstraintReportList.fromPanels} for that: + * + * @example + * var report = new wikibase.quality.constraints.ui.ConstraintReportList.static.fromPanels( + * [ + * new wikibase.quality.constraints.ui.ConstraintReportPanel( { + * status: 'compliance', + * constraint: { + * type: 'Q1', + * typeLabel: 'my constraint', + * link: 'http://example.com/my-constraint' + * }, + * message: 'everything okay' + * } ), + * new wikibase.quality.constraints.ui.ConstraintReportPanel( { + * status: 'violation', + * constraint: { + * type: 'Q2', + * typeLabel: 'my other constraint', + * link: 'http://example.com/my-other-constraint' + * }, + * message: 'doing it wrong' + * } ) + * ], + * { + * statuses: [ + * { + * status: 'violation', + * heading: 'Violations' + * }, + * { + * status: 'bad-parameters', + * heading: 'Bad parameters', + * collapsed: true + * } + * ], + * expanded: false, + * framed: true + * } + * ); + * $( 'body' ).append( report.$element ); + * + * You can also explicitly provide the groups to the constructor: + * + * @example + * var report = new wikibase.quality.constraints.ui.ConstraintReportList( { + * items: [ + * new wikibase.quality.constraints.ui.ConstraintReportGroup( { + * items: [ + * new wikibase.quality.constraints.ui.ConstraintReportPanel( { + * status: 'compliance', + * constraint: { + * type: 'Q1', + * typeLabel: 'my constraint', + * link: 'http://example.com/my-constraint' + * }, + * message: 'everything okay' + * } ) + * ], + * heading: 'Violations' + * } ), + * new wikibase.quality.constraints.ui.ConstraintReportGroup( { + * items: [ + * new wikibase.quality.constraints.ui.ConstraintReportPanel( { + * status: 'violation', + * constraint: { + * type: 'Q2', + * typeLabel: 'my other constraint', + * link: 'http://example.com/my-other-constraint' + * }, + * message: 'doing it wrong' + * } ) + * ], + * heading: 'Bad parameters', + * collapsed: true + * } ) + * ], + * expanded: false, + * framed: true + * } ); + * $( 'body' ).append( report.$element ); + * + * @class + * @extends OO.ui.StackLayout + * + * @constructor + * @param {Object} config Configuration options + * @cfg {wikibase.quality.constraints.ui.ConstraintReportGroup[]} items The constraint report groups. + */ + wb.quality.constraints.ui.ConstraintReportList = function WBQCConstraintReportList( config ) { + + // Configuration initialization + config.continuous = true; + config.classes = OO.simpleArrayUnion( + config.classes || [], + [ 'wbqc-reports-all' ] + ); + + // Parent constructor + wb.quality.constraints.ui.ConstraintReportList.parent.call( this, config ); + + // Mixin constructors + // (none) + }; + + /* Setup */ + + OO.inheritClass( wb.quality.constraints.ui.ConstraintReportList, OO.ui.StackLayout ); + + /* Methods */ + + /** + * Sort a flat list of constraint reports into groups by status. + * + * @param {wikibase.quality.constraints.ui.ConstraintReportPanel[]} panels The individual constraint report panels. + * @param {Object} config Configuration options (all options except `statuses` are passed to the `ConstraintReportList` constructor). + * @param {Object[]} config.statuses The configuration for each group. + * The `status` member selects constraint report panels from `panels` with this status; + * all other options are passed to the `ConstraintReportGroup` constructor. + * The order of status objects in the array determines the order of groups in the list. + * @return {wikibase.quality.constraints.ui.ConstraintReportList} + * @static + */ + wb.quality.constraints.ui.ConstraintReportList.static.fromPanels = function( panels, config ) { + var panelsByStatus = {}, + items = []; + + panels.forEach( function( panel ) { + panelsByStatus[ panel.status ] = panelsByStatus[ panel.status ] || []; + panelsByStatus[ panel.status ].push( panel ); + } ); + + config.statuses.forEach( function( statusConfig ) { + var status = statusConfig.status, + statusPanels = panelsByStatus[ status ]; + + if ( statusPanels === undefined ) { + return; + } + + delete statusConfig.status; // remainder of config is for ConstraintReportGroup + statusConfig.items = statusPanels; + statusConfig.classes = OO.simpleArrayUnion( + statusConfig.classes || [], + [ 'wbqc-reports-status-' + status ] + ); + statusConfig.status = status; + items.push( new wb.quality.constraints.ui.ConstraintReportGroup( statusConfig ) ); + } ); + + delete config.statuses; // remainder of config is for ConstraintReportList + config.items = items; + return new wb.quality.constraints.ui.ConstraintReportList( config ); + }; + +}( OO, wikibase ) ); -- To view, visit https://gerrit.wikimedia.org/r/365988 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6e31e84d40d4b3e8edfc7bd4359ae615a595453d Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints Gerrit-Branch: master Gerrit-Owner: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de> Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de> Gerrit-Reviewer: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits