Files
gerrit/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item.js
Becky Siegel 1a44b34247 Add setting to Show/Hide change table columns in settings
This change adds a widget to adjust change table columns in the user's
settings. If no change table columns are adjusted, the server returns an
empty array and the client determines the default columns, stored in the
gr-change-table-behavior.

Columns can get removed/re-ordered by the user but they are limited to
those specified in gr-change-table-behavior. Column preferences persist
across all gr-change-list items (dashboards, searches, etc).

Feature: Issue 4753
Change-Id: I47d5b9f53a95c0c010b04c4495094f188d85e67e
2016-12-20 10:04:34 -08:00

125 lines
3.3 KiB
JavaScript

// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
(function() {
'use strict';
Polymer({
is: 'gr-change-list-item',
properties: {
visibleChangeTableColumns: Array,
selected: {
type: Boolean,
value: false,
reflectToAttribute: true,
},
needsReview: {
type: Boolean,
value: false,
reflectToAttribute: true,
},
labelNames: {
type: Array,
},
change: Object,
changeURL: {
type: String,
computed: '_computeChangeURL(change._number)',
},
showStar: {
type: Boolean,
value: false,
},
},
behaviors: [
Gerrit.ChangeTableBehavior,
Gerrit.RESTClientBehavior,
Gerrit.URLEncodingBehavior,
],
_computeChangeURL: function(changeNum) {
if (!changeNum) { return ''; }
return '/c/' + changeNum + '/';
},
_computeLabelTitle: function(change, labelName) {
var label = change.labels[labelName];
if (!label) { return 'Label not applicable'; }
var significantLabel = label.rejected || label.approved ||
label.disliked || label.recommended;
if (significantLabel && significantLabel.name) {
return labelName + '\nby ' + significantLabel.name;
}
return labelName;
},
_computeLabelClass: function(change, labelName) {
var label = change.labels[labelName];
// Mimic a Set.
var classes = {
'cell': true,
'label': true,
};
if (label) {
if (label.approved) {
classes['u-green'] = true;
}
if (label.value == 1) {
classes['u-monospace'] = true;
classes['u-green'] = true;
} else if (label.value == -1) {
classes['u-monospace'] = true;
classes['u-red'] = true;
}
if (label.rejected) {
classes['u-red'] = true;
}
} else {
classes['u-gray-background'] = true;
}
return Object.keys(classes).sort().join(' ');
},
_computeLabelValue: function(change, labelName) {
var label = change.labels[labelName];
if (!label) { return ''; }
if (label.approved) {
return '✓';
}
if (label.rejected) {
return '✕';
}
if (label.value > 0) {
return '+' + label.value;
}
if (label.value < 0) {
return label.value;
}
return '';
},
_computeProjectURL: function(project) {
return '/q/status:open+project:' +
this.encodeURL(project, false);
},
_computeProjectBranchURL: function(project, branch) {
// @see Issue 4255.
return this._computeProjectURL(project) +
'+branch:' + this.encodeURL(branch, false);
},
});
})();