Respect "Show Change Number In Changes Table" preference

Change-Id: I5d5927343e0dcc22d5685cbd1d055fdc405822b1
Feature: Issue 3902
This commit is contained in:
Urs Wolfer 2016-04-30 14:36:04 +02:00
parent c37b69ab9b
commit c292dbea40
5 changed files with 92 additions and 2 deletions

View File

@ -68,9 +68,12 @@ limitations under the License.
<span class="cell keyboard">
<span class="positionIndicator">&#x25b6;</span>
</span>
<span class="cell star" hidden$="[[!showStar]]">
<span class="cell star" hidden$="[[!showStar]]" hidden>
<gr-change-star change="{{change}}"></gr-change-star>
</span>
<a class="cell number" href$="[[changeURL]]" hidden$="[[!showNumber]]" hidden>
[[change._number]]
</a>
<a class="cell subject" href$="[[changeURL]]">[[change.subject]]</a>
<span class="cell status">[[_computeChangeStatusString(change)]]</span>
<span class="cell owner">

View File

@ -18,6 +18,7 @@ limitations under the License.
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
<link rel="import" href="../../../styles/gr-change-list-styles.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<link rel="import" href="../gr-change-list-item/gr-change-list-item.html">
<dom-module id="gr-change-list">
@ -31,7 +32,8 @@ limitations under the License.
<style include="gr-change-list-styles"></style>
<div class="headerRow">
<span class="topHeader keyboard"></span> <!-- keyboard position indicator -->
<span class="topHeader star" hidden$="[[!showStar]]"></span>
<span class="topHeader star" hidden$="[[!showStar]]" hidden></span>
<span class="topHeader number" hidden$="[[!showNumber]]" hidden>#</span>
<span class="topHeader subject">Subject</span>
<span class="topHeader status">Status</span>
<span class="topHeader owner">Owner</span>
@ -57,10 +59,12 @@ limitations under the License.
selected$="[[_computeItemSelected(index, groupIndex, selectedIndex)]]"
needs-review="[[_computeItemNeedsReview(account, change, showReviewedState)]]"
change="[[change]]"
show-number="[[showNumber]]"
show-star="[[showStar]]"
label-names="[[labelNames]]"></gr-change-list-item>
</template>
</template>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
</template>
<script src="gr-change-list.js"></script>
</dom-module>

View File

@ -58,6 +58,7 @@
type: Number,
notify: true,
},
showNumber: Boolean, // No default value to prevent flickering.
showStar: {
type: Boolean,
value: false,
@ -77,6 +78,31 @@
Gerrit.RESTClientBehavior,
],
attached: function() {
this._loadPreferences();
},
_loadPreferences: function() {
return this._getLoggedIn().then(function(loggedIn) {
if (!loggedIn) {
this.showNumber = false;
return;
}
return this._getPreferences().then(function(preferences) {
this.showNumber = !!(preferences &&
preferences.legacycid_in_change_table);
}.bind(this));
}.bind(this));
},
_getLoggedIn: function() {
return this.$.restAPI.getLoggedIn();
},
_getPreferences: function() {
return this.$.restAPI.getPreferences();
},
_computeLabelNames: function(groups) {
if (!groups) { return []; }
var labels = [];

View File

@ -46,6 +46,60 @@ limitations under the License.
element = fixture('basic');
});
function stubRestAPI(preferences) {
var loggedInPromise = Promise.resolve(preferences !== null);
var preferencesPromise = Promise.resolve(preferences);
stub('gr-rest-api-interface', {
getLoggedIn: sinon.stub().returns(loggedInPromise),
getPreferences: sinon.stub().returns(preferencesPromise),
});
return Promise.all([loggedInPromise, preferencesPromise]);
}
suite('test show change number not logged in', function() {
setup(function(done) {
return stubRestAPI(null).then(function() {
element = fixture('basic');
element._loadPreferences().then(function() { done(); });
});
});
test('show number disabled', function() {
assert.isFalse(element.showNumber);
});
});
suite('test show change number preference enabled', function() {
setup(function(done) {
return stubRestAPI(
{legacycid_in_change_table: true, time_format: 'HHMM_12'}
).then(function() {
element = fixture('basic');
element._loadPreferences().then(function() { done(); });
});
});
test('show number enabled', function() {
assert.isTrue(element.showNumber);
});
});
suite('test show change number preference disabled', function() {
setup(function(done) {
// legacycid_in_change_table is not set when false.
return stubRestAPI(
{time_format: 'HHMM_12'}
).then(function() {
element = fixture('basic');
element._loadPreferences().then(function() { done(); });
});
});
test('show number disabled', function() {
assert.isFalse(element.showNumber);
});
});
test('computed fields', function() {
assert.equal(element._computeLabelNames(
[[{_number: 0, labels: {}}]]).length, 0);

View File

@ -44,6 +44,9 @@ limitations under the License.
.star {
padding-top: .05em;
}
.number {
width: 4em;
}
.subject {
flex-grow: 1;
flex-shrink: 1;