Re use gr-diff-preferences inside gr-settings-view

Bug: Issue 8678
Change-Id: Ifd950bd4226407252e86610149dd8c6ba94ab967
This commit is contained in:
Paladox none
2019-02-19 22:07:54 +00:00
parent 002c7931e2
commit 7a2280c5dc
19 changed files with 554 additions and 680 deletions

View File

@@ -24,7 +24,6 @@ limitations under the License.
<link rel="import" href="../../core/gr-navigation/gr-navigation.html">
<link rel="import" href="../../core/gr-reporting/gr-reporting.html">
<link rel="import" href="../../diff/gr-comment-api/gr-comment-api.html">
<link rel="import" href="../../diff/gr-diff-preferences/gr-diff-preferences.html">
<link rel="import" href="../../edit/gr-edit-constants.html">
<link rel="import" href="../../plugins/gr-endpoint-decorator/gr-endpoint-decorator.html">
<link rel="import" href="../../plugins/gr-endpoint-param/gr-endpoint-param.html">

View File

@@ -283,7 +283,8 @@ limitations under the License.
});
test(', should open diff preferences', () => {
const stub = sandbox.stub(element.$.fileList.$.diffPreferences, 'open');
const stub = sandbox.stub(
element.$.fileList.$.diffPreferencesDialog, 'open');
MockInteractions.pressAndReleaseKeyOn(element, 188, null, ',');
assert.isTrue(stub.called);
});

View File

@@ -23,8 +23,9 @@ limitations under the License.
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../core/gr-navigation/gr-navigation.html">
<link rel="import" href="../../core/gr-reporting/gr-reporting.html">
<link rel="import" href="../../diff/gr-diff-host/gr-diff-host.html">
<link rel="import" href="../../diff/gr-diff-cursor/gr-diff-cursor.html">
<link rel="import" href="../../diff/gr-diff-host/gr-diff-host.html">
<link rel="import" href="../../diff/gr-diff-preferences-dialog/gr-diff-preferences-dialog.html">
<link rel="import" href="../../edit/gr-edit-file-controls/gr-edit-file-controls.html">
<link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-cursor-manager/gr-cursor-manager.html">
@@ -465,10 +466,11 @@ limitations under the License.
</gr-button><!--
--></gr-tooltip-content>
</div>
<gr-diff-preferences
id="diffPreferences"
prefs="{{diffPrefs}}"
local-prefs="{{_localPrefs}}"></gr-diff-preferences>
<gr-diff-preferences-dialog
id="diffPreferencesDialog"
diff-prefs="{{diffPrefs}}"
on-reload-diff-preference="_handleReloadingDiffPreference">
</gr-diff-preferences-dialog>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
<gr-storage id="storage"></gr-storage>
<gr-diff-cursor id="diffCursor"></gr-diff-cursor>

View File

@@ -125,7 +125,6 @@
},
/** @type {?} */
_userPrefs: Object,
_localPrefs: Object,
_showInlineDiffs: Boolean,
numFilesShown: {
type: Number,
@@ -269,7 +268,6 @@
});
}));
this._localPrefs = this.$.storage.getPreferences();
promises.push(this._getDiffPreferences().then(prefs => {
this.diffPrefs = prefs;
}));
@@ -297,7 +295,7 @@
},
openDiffPrefs() {
this.$.diffPreferences.open();
this.$.diffPreferencesDialog.open();
},
_calculatePatchChange(files) {
@@ -1255,5 +1253,11 @@
return 'Mark as reviewed (shortcut: r)';
},
_handleReloadingDiffPreference() {
this._getDiffPreferences().then(prefs => {
this.diffPrefs = prefs;
});
},
});
})();

View File

@@ -0,0 +1,80 @@
<!--
@license
Copyright (C) 2019 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.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-diff-preferences/gr-preferences.html">
<link rel="import" href="../../shared/gr-overlay/gr-overlay.html">
<dom-module id="gr-diff-preferences-dialog">
<template>
<style include="shared-styles">
.diffHeader,
.diffActions {
padding: 1em 1.5em;
}
.diffHeader,
.diffActions {
background-color: var(--dialog-background-color);
}
.diffHeader {
border-bottom: 1px solid var(--border-color);
font-weight: var(--font-weight-bold);
}
.diffActions {
border-top: 1px solid var(--border-color);
display: flex;
justify-content: flex-end;
}
.diffPrefsOverlay gr-button {
margin-left: 1em;
}
div.edited:after {
color: var(--deemphasized-text-color);
content: ' *';
}
#diffPreferences {
display: flex;
padding: .35em 1.5em;
}
</style>
<gr-overlay id="diffPrefsOverlay" with-backdrop>
<div class$="diffHeader [[_computeHeaderClass(_diffPrefsChanged)]]">Diff Preferences</div>
<gr-diff-preferences
id="diffPreferences"
diff-prefs="{{diffPrefs}}"
has-unsaved-changes="{{_diffPrefsChanged}}"></gr-diff-preferences>
<div class="diffActions">
<gr-button
id="cancelButton"
link
on-tap="_handleCancelDiff">
Cancel
</gr-button>
<gr-button
id="saveButton"
link primary
on-tap="_handleSaveDiffPreferences"
disabled$="[[!_diffPrefsChanged]]">
Save
</gr-button>
</div>
</gr-overlay>
</template>
<script src="gr-diff-preferences-dialog.js"></script>
</dom-module>

View File

@@ -0,0 +1,66 @@
/**
* @license
* Copyright (C) 2019 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-diff-preferences-dialog',
properties: {
/** @type {?} */
diffPrefs: Object,
_diffPrefsChanged: Boolean,
},
getFocusStops() {
return {
start: this.$.contextSelect,
end: this.$.saveButton,
};
},
resetFocus() {
this.$.contextSelect.focus();
},
_computeHeaderClass(changed) {
return changed ? 'edited' : '';
},
_handleCancelDiff(e) {
e.stopPropagation();
this.$.diffPrefsOverlay.close();
},
open() {
this.$.diffPrefsOverlay.open().then(() => {
const focusStops = this.getFocusStops();
this.$.diffPrefsOverlay.setFocusStops(focusStops);
this.resetFocus();
});
},
_handleSaveDiffPreferences() {
this.$.diffPreferences.save().then(() => {
this.fire('reload-diff-preference', null, {bubbles: false});
this.$.diffPrefsOverlay.close();
});
},
});
})();

View File

@@ -1,173 +0,0 @@
<!--
@license
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.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/iron-input/iron-input.html">
<link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-overlay/gr-overlay.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<link rel="import" href="../../shared/gr-storage/gr-storage.html">
<link rel="import" href="../../../styles/shared-styles.html">
<dom-module id="gr-diff-preferences">
<template>
<style include="shared-styles">
:host {
display: block;
}
:host([disabled]) {
opacity: .5;
pointer-events: none;
}
input,
select {
font: inherit;
}
input[type="number"] {
width: 4em;
}
.header,
.actions {
padding: 1em 1.5em;
}
.header,
.mainContainer,
.actions {
background-color: var(--dialog-background-color);
}
.header {
border-bottom: 1px solid var(--border-color);
font-weight: var(--font-weight-bold);
}
.mainContainer {
padding: 1em 0;
}
.pref {
align-items: center;
display: flex;
padding: .35em 1.5em;
width: 25em;
}
.pref:hover {
background-color: var(--hover-background-color);
}
.pref label {
cursor: pointer;
flex: 1;
}
.actions {
border-top: 1px solid var(--border-color);
display: flex;
justify-content: flex-end;
}
gr-button {
margin-left: 1em;
}
</style>
<gr-overlay id="prefsOverlay" with-backdrop>
<div class="header">
Diff View Preferences
</div>
<div class="mainContainer">
<div class="pref">
<label for="contextSelect">Context</label>
<select id="contextSelect" on-change="_handleContextSelectChange">
<option value="3">3 lines</option>
<option value="10">10 lines</option>
<option value="25">25 lines</option>
<option value="50">50 lines</option>
<option value="75">75 lines</option>
<option value="100">100 lines</option>
<option value="-1">Whole file</option>
</select>
</div>
<div class="pref">
<label for="lineWrappingInput">Fit to screen</label>
<input
is="iron-input"
type="checkbox"
id="lineWrappingInput"
on-tap="_handlelineWrappingTap">
</div>
<div class="pref" id="columnsPref">
<label for="columnsInput">Diff width</label>
<input is="iron-input" type="number" id="columnsInput"
prevent-invalid-input
allowed-pattern="[0-9]"
bind-value="{{_newPrefs.line_length}}">
</div>
<div class="pref">
<label for="tabSizeInput">Tab width</label>
<input is="iron-input" type="number" id="tabSizeInput"
prevent-invalid-input
allowed-pattern="[0-9]"
bind-value="{{_newPrefs.tab_size}}">
</div>
<div class="pref" hidden$="[[!_newPrefs.font_size]]">
<label for="fontSizeInput">Font size</label>
<input is="iron-input" type="number" id="fontSizeInput"
prevent-invalid-input
allowed-pattern="[0-9]"
bind-value="{{_newPrefs.font_size}}">
</div>
<div class="pref">
<label for="showTabsInput">Show tabs</label>
<input is="iron-input" type="checkbox" id="showTabsInput"
on-tap="_handleShowTabsTap">
</div>
<div class="pref">
<label for="showTrailingWhitespaceInput">
Show trailing whitespace</label>
<input is="iron-input" type="checkbox"
id="showTrailingWhitespaceInput"
on-tap="_handleShowTrailingWhitespaceTap">
</div>
<div class="pref">
<label for="syntaxHighlightInput">Syntax highlighting</label>
<input is="iron-input" type="checkbox" id="syntaxHighlightInput"
on-tap="_handleSyntaxHighlightTap">
</div>
<div class="pref">
<label for="automaticReviewInput">Automatically mark viewed files reviewed</label>
<input
is="iron-input"
id="automaticReviewInput"
type="checkbox"
on-tap="_handleAutomaticReviewTap">
</div>
<div class="pref">
<label for="ignoreWhitespace">Ignore Whitespace</label>
<select id="ignoreWhitespace" on-change="_handleIgnoreWhitespaceChange">
<option value="IGNORE_NONE">None</option>
<option value="IGNORE_TRAILING">Trailing</option>
<option value="IGNORE_LEADING_AND_TRAILING">Leading & trailing</option>
<option value="IGNORE_ALL">All</option>
</select>
</div>
</div>
<div class="actions">
<gr-button id="cancelButton" link on-tap="_handleCancel">
Cancel</gr-button>
<gr-button id="saveButton" link primary on-tap="_handleSave">
Save</gr-button>
</div>
</gr-overlay>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
<gr-storage id="storage"></gr-storage>
</template>
<script src="gr-diff-preferences.js"></script>
</dom-module>

View File

@@ -1,144 +0,0 @@
/**
* @license
* 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-diff-preferences',
properties: {
prefs: {
type: Object,
notify: true,
},
localPrefs: {
type: Object,
notify: true,
},
disabled: {
type: Boolean,
value: false,
reflectToAttribute: true,
},
/** @type {?} */
_newPrefs: Object,
_newLocalPrefs: Object,
},
observers: [
'_prefsChanged(prefs.*)',
'_localPrefsChanged(localPrefs.*)',
],
getFocusStops() {
return {
start: this.$.contextSelect,
end: this.$.saveButton,
};
},
resetFocus() {
this.$.contextSelect.focus();
},
_prefsChanged(changeRecord) {
const prefs = changeRecord.base;
// NOTE: Object.assign is NOT automatically a deep copy. If prefs adds
// an object as a value, it must be marked enumerable.
this._newPrefs = Object.assign({}, prefs);
this.$.contextSelect.value = prefs.context;
this.$.showTabsInput.checked = prefs.show_tabs;
this.$.showTrailingWhitespaceInput.checked = prefs.show_whitespace_errors;
this.$.lineWrappingInput.checked = prefs.line_wrapping;
this.$.syntaxHighlightInput.checked = prefs.syntax_highlighting;
this.$.automaticReviewInput.checked = !prefs.manual_review;
this.$.ignoreWhitespace.value = prefs.ignore_whitespace;
},
_localPrefsChanged(changeRecord) {
const localPrefs = changeRecord.base || {};
this._newLocalPrefs = Object.assign({}, localPrefs);
},
_handleContextSelectChange(e) {
const selectEl = Polymer.dom(e).rootTarget;
this.set('_newPrefs.context', parseInt(selectEl.value, 10));
},
_handleIgnoreWhitespaceChange(e) {
const selectEl = Polymer.dom(e).rootTarget;
this.set('_newPrefs.ignore_whitespace', selectEl.value);
},
_handleShowTabsTap(e) {
this.set('_newPrefs.show_tabs', Polymer.dom(e).rootTarget.checked);
},
_handleShowTrailingWhitespaceTap(e) {
this.set('_newPrefs.show_whitespace_errors',
Polymer.dom(e).rootTarget.checked);
},
_handleSyntaxHighlightTap(e) {
this.set('_newPrefs.syntax_highlighting',
Polymer.dom(e).rootTarget.checked);
},
_handlelineWrappingTap(e) {
this.set('_newPrefs.line_wrapping', Polymer.dom(e).rootTarget.checked);
},
_handleAutomaticReviewTap(e) {
this.set('_newPrefs.manual_review', !Polymer.dom(e).rootTarget.checked);
},
_handleSave(e) {
e.stopPropagation();
this.prefs = this._newPrefs;
this.localPrefs = this._newLocalPrefs;
const el = Polymer.dom(e).rootTarget;
el.disabled = true;
this.$.storage.savePreferences(this._localPrefs);
this._saveDiffPreferences().then(response => {
el.disabled = false;
if (!response.ok) { return response; }
this.$.prefsOverlay.close();
}).catch(err => {
el.disabled = false;
});
},
_handleCancel(e) {
e.stopPropagation();
this.$.prefsOverlay.close();
},
open() {
this.$.prefsOverlay.open().then(() => {
const focusStops = this.getFocusStops();
this.$.prefsOverlay.setFocusStops(focusStops);
this.resetFocus();
});
},
_saveDiffPreferences() {
return this.$.restAPI.saveDiffPreferences(this.prefs);
},
});
})();

View File

@@ -1,110 +0,0 @@
<!DOCTYPE html>
<!--
@license
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.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>gr-diff-preferences</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-diff-preferences.html">
<script>void(0);</script>
<test-fixture id="basic">
<template>
<gr-diff-preferences></gr-diff-preferences>
</template>
</test-fixture>
<script>
suite('gr-diff-preferences tests', () => {
let element;
let sandbox;
setup(() => {
sandbox = sinon.sandbox.create();
element = fixture('basic');
});
teardown(() => {
sandbox.restore();
});
test('model changes', () => {
element.prefs = {
context: 10,
font_size: 12,
line_length: 100,
show_tabs: true,
tab_size: 8,
show_whitespace_errors: true,
syntax_highlighting: true,
};
assert.deepEqual(element.prefs, element._newPrefs);
element.$.contextSelect.value = '50';
element.fire('change', {}, {node: element.$.contextSelect});
element.$.columnsInput.bindValue = 80;
element.$.fontSizeInput.bindValue = 10;
element.$.tabSizeInput.bindValue = 4;
MockInteractions.tap(element.$.showTabsInput);
MockInteractions.tap(element.$.showTrailingWhitespaceInput);
MockInteractions.tap(element.$.syntaxHighlightInput);
MockInteractions.tap(element.$.lineWrappingInput);
assert.equal(element._newPrefs.context, 50);
assert.equal(element._newPrefs.font_size, 10);
assert.equal(element._newPrefs.line_length, 80);
assert.equal(element._newPrefs.tab_size, 4);
assert.isFalse(element._newPrefs.show_tabs);
assert.isFalse(element._newPrefs.show_whitespace_errors);
assert.isTrue(element._newPrefs.line_wrapping);
assert.isFalse(element._newPrefs.syntax_highlighting);
});
test('clicking save button calls _handleSave function', () => {
const savePrefs = sinon.stub(element, '_handleSave');
MockInteractions.tap(element.$.saveButton);
flushAsynchronousOperations();
assert(savePrefs.calledOnce);
savePrefs.restore();
});
test('save button', () => {
element.prefs = {
font_size: '11',
};
element._newPrefs = {
font_size: '12',
};
const saveStub = sandbox.stub(element.$.restAPI, 'saveDiffPreferences',
() => { return Promise.resolve(); });
MockInteractions.tap(element.$$('gr-button[primary]'));
assert.deepEqual(element.prefs, element._newPrefs);
assert.deepEqual(saveStub.lastCall.args[0], element._newPrefs);
});
test('cancel button', () => {
const closeStub = sandbox.stub(element.$.prefsOverlay, 'close');
MockInteractions.tap(element.$$('gr-button:not([primary])'));
assert.isTrue(closeStub.called);
});
});
</script>

View File

@@ -34,9 +34,9 @@ limitations under the License.
<link rel="import" href="../../shared/revision-info/revision-info.html">
<link rel="import" href="../gr-comment-api/gr-comment-api.html">
<link rel="import" href="../gr-diff-cursor/gr-diff-cursor.html">
<link rel="import" href="../gr-diff-mode-selector/gr-diff-mode-selector.html">
<link rel="import" href="../gr-diff-preferences/gr-diff-preferences.html">
<link rel="import" href="../gr-diff-host/gr-diff-host.html">
<link rel="import" href="../gr-diff-mode-selector/gr-diff-mode-selector.html">
<link rel="import" href="../gr-diff-preferences-dialog/gr-diff-preferences-dialog.html">
<link rel="import" href="../gr-patch-range-select/gr-patch-range-select.html">
<dom-module id="gr-diff-view">
@@ -338,10 +338,11 @@ limitations under the License.
is-blame-loaded="{{_isBlameLoaded}}"
on-line-selected="_onLineSelected">
</gr-diff-host>
<gr-diff-preferences
id="diffPreferences"
prefs="{{_prefs}}"
local-prefs="{{_localPrefs}}"></gr-diff-preferences>
<gr-diff-preferences-dialog
id="diffPreferencesDialog"
diff-prefs="{{_prefs}}"
on-reload-diff-preference="_handleReloadingDiffPreference">
</gr-diff-preferences-dialog>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
<gr-storage id="storage"></gr-storage>
<gr-diff-cursor id="cursor"></gr-diff-cursor>

View File

@@ -258,7 +258,9 @@
},
_getDiffPreferences() {
return this.$.restAPI.getDiffPreferences();
return this.$.restAPI.getDiffPreferences().then(prefs => {
this._prefs = prefs;
});
},
_getPreferences() {
@@ -457,7 +459,7 @@
this.modifierPressed(e)) { return; }
e.preventDefault();
this.$.diffPreferences.open();
this.$.diffPreferencesDialog.open();
},
_handleToggleDiffMode(e) {
@@ -608,10 +610,7 @@
const promises = [];
this._localPrefs = this.$.storage.getPreferences();
promises.push(this._getDiffPreferences().then(prefs => {
this._prefs = prefs;
}));
promises.push(this._getDiffPreferences());
promises.push(this._getPreferences().then(prefs => {
this._userPrefs = prefs;
@@ -837,22 +836,7 @@
_handlePrefsTap(e) {
e.preventDefault();
this.$.diffPreferences.open();
},
_handlePrefsSave(e) {
e.stopPropagation();
const el = Polymer.dom(e).rootTarget;
el.disabled = true;
this.$.storage.savePreferences(this._localPrefs);
this._saveDiffPreferences().then(response => {
el.disabled = false;
if (!response.ok) { return response; }
this.$.prefsOverlay.close();
}).catch(err => {
el.disabled = false;
});
this.$.diffPreferencesDialog.open();
},
/**
@@ -1036,5 +1020,9 @@
(file === this._path || !this._reviewedFiles.has(file)));
this._navToFile(this._path, unreviewedFiles, 1);
},
_handleReloadingDiffPreference() {
this._getDiffPreferences();
},
});
})();

View File

@@ -172,7 +172,7 @@ limitations under the License.
assert.isTrue(element._loading);
const showPrefsStub =
sandbox.stub(element.$.diffPreferences.$.prefsOverlay, 'open',
sandbox.stub(element.$.diffPreferencesDialog, 'open',
() => Promise.resolve());
MockInteractions.pressAndReleaseKeyOn(element, 188, null, ',');
@@ -365,7 +365,7 @@ limitations under the License.
test('prefsButton opens gr-diff-preferences', () => {
const handlePrefsTapSpy = sandbox.spy(element, '_handlePrefsTap');
const overlayOpenStub = sandbox.stub(element.$.diffPreferences,
const overlayOpenStub = sandbox.stub(element.$.diffPreferencesDialog,
'open');
const prefsButton =
Polymer.dom(element.root).querySelector('.prefsButton');

View File

@@ -27,6 +27,7 @@ limitations under the License.
<link rel="import" href="../../settings/gr-change-table-editor/gr-change-table-editor.html">
<link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-date-formatter/gr-date-formatter.html">
<link rel="import" href="../../shared/gr-diff-preferences/gr-diff-preferences.html">
<link rel="import" href="../../shared/gr-page-nav/gr-page-nav.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<link rel="import" href="../../shared/gr-select/gr-select.html">
@@ -259,110 +260,9 @@ limitations under the License.
Diff Preferences
</h2>
<fieldset id="diffPreferences">
<section>
<span class="title">Context</span>
<span class="value">
<gr-select bind-value="{{_diffPrefs.context}}">
<select>
<option value="3">3 lines</option>
<option value="10">10 lines</option>
<option value="25">25 lines</option>
<option value="50">50 lines</option>
<option value="75">75 lines</option>
<option value="100">100 lines</option>
<option value="-1">Whole file</option>
</select>
</gr-select>
</span>
</section>
<section>
<span class="title">Fit to screen</span>
<span class="value">
<input
id="diffLineWrapping"
type="checkbox"
checked$="[[_diffPrefs.line_wrapping]]"
on-change="_handleDiffLineWrappingChanged">
</span>
</section>
<section id="columnsPref" hidden$="[[_diffPrefs.line_wrapping]]">
<span class="title">Diff width</span>
<span class="value">
<input
is="iron-input"
type="number"
prevent-invalid-input
allowed-pattern="[0-9]"
bind-value="{{_diffPrefs.line_length}}">
</span>
</section>
<section>
<span class="title">Tab width</span>
<span class="value">
<input
is="iron-input"
type="number"
prevent-invalid-input
allowed-pattern="[0-9]"
bind-value="{{_diffPrefs.tab_size}}">
</span>
</section>
<section hidden$="[[!_diffPrefs.font_size]]">
<span class="title">Font size</span>
<span class="value">
<input
is="iron-input"
type="number"
prevent-invalid-input
allowed-pattern="[0-9]"
bind-value="{{_diffPrefs.font_size}}">
</span>
</section>
<section>
<span class="title">Show tabs</span>
<span class="value">
<input
id="diffShowTabs"
type="checkbox"
checked$="[[_diffPrefs.show_tabs]]"
on-change="_handleDiffShowTabsChanged">
</span>
</section>
<section>
<span class="title">Show trailing whitespace</span>
<span class="value">
<input
id="showTrailingWhitespace"
type="checkbox"
checked$="[[_diffPrefs.show_whitespace_errors]]"
on-change="_handleShowTrailingWhitespaceChanged">
</span>
</section>
<section>
<span class="title">Syntax highlighting</span>
<span class="value">
<input
id="diffSyntaxHighlighting"
type="checkbox"
checked$="[[_diffPrefs.syntax_highlighting]]"
on-change="_handleDiffSyntaxHighlightingChanged">
</span>
</section>
<section>
<div class="pref">
<span class="title">Ignore Whitespace</span>
<span class="value">
<gr-select bind-value="{{_diffPrefs.ignore_whitespace}}">
<select>
<option value="IGNORE_NONE">None</option>
<option value="IGNORE_TRAILING">Trailing</option>
<option value="IGNORE_LEADING_AND_TRAILING">Leading & trailing</option>
<option value="IGNORE_ALL">All</option>
</select>
</gr-select>
</span>
</div>
</section>
<gr-diff-preferences
id="diffPrefs"
has-unsaved-changes="{{_diffPrefsChanged}}"></gr-diff-preferences>
<gr-button
id="saveDiffPrefs"
on-tap="_handleSaveDiffPreferences"

View File

@@ -64,8 +64,6 @@
},
_accountNameMutable: Boolean,
_accountInfoChanged: Boolean,
/** @type {?} */
_diffPrefs: Object,
_changeTableColumnsNotDisplayed: Array,
/** @type {?} */
_localPrefs: {
@@ -92,10 +90,8 @@
type: Boolean,
value: false,
},
_diffPrefsChanged: {
type: Boolean,
value: false,
},
/** @type {?} */
_diffPrefsChanged: Boolean,
/** @type {?} */
_editPrefsChanged: Boolean,
_menuChanged: {
@@ -149,7 +145,6 @@
observers: [
'_handlePrefsChanged(_localPrefs.*)',
'_handleDiffPrefsChanged(_diffPrefs.*)',
'_handleMenuChanged(_localMenu.splices)',
'_handleChangeTableChanged(_localChangeTableColumns, _showNumber)',
],
@@ -166,6 +161,7 @@
this.$.httpPass.loadData(),
this.$.identities.loadData(),
this.$.editPrefs.loadData(),
this.$.diffPrefs.loadData(),
];
promises.push(this.$.restAPI.getPreferences().then(prefs => {
@@ -176,10 +172,6 @@
this._cloneChangeTableColumns();
}));
promises.push(this.$.restAPI.getDiffPreferences().then(prefs => {
this._diffPrefs = prefs;
}));
promises.push(this.$.restAPI.getConfig().then(config => {
this._serverConfig = config;
const configPromises = [];
@@ -277,11 +269,6 @@
this._prefsChanged = true;
},
_handleDiffPrefsChanged() {
if (this._isLoading()) { return; }
this._diffPrefsChanged = true;
},
_handleShowSizeBarsInFileListChanged() {
this.set('_localPrefs.size_bar_in_change_table',
this.$.showSizeBarsInFileList.checked);
@@ -318,24 +305,6 @@
});
},
_handleDiffLineWrappingChanged() {
this.set('_diffPrefs.line_wrapping', this.$.diffLineWrapping.checked);
},
_handleDiffShowTabsChanged() {
this.set('_diffPrefs.show_tabs', this.$.diffShowTabs.checked);
},
_handleShowTrailingWhitespaceChanged() {
this.set('_diffPrefs.show_whitespace_errors',
this.$.showTrailingWhitespace.checked);
},
_handleDiffSyntaxHighlightingChanged() {
this.set('_diffPrefs.syntax_highlighting',
this.$.diffSyntaxHighlighting.checked);
},
_handleSaveChangeTable() {
this.set('prefs.change_table', this._localChangeTableColumns);
this.set('prefs.legacycid_in_change_table', this._showNumber);
@@ -346,10 +315,7 @@
},
_handleSaveDiffPreferences() {
return this.$.restAPI.saveDiffPreferences(this._diffPrefs)
.then(() => {
this._diffPrefsChanged = false;
});
this.$.diffPrefs.save();
},
_handleSaveEditPreferences() {

View File

@@ -43,7 +43,6 @@ limitations under the License.
let element;
let account;
let preferences;
let diffPreferences;
let config;
let sandbox;
@@ -96,31 +95,12 @@ limitations under the License.
],
change_table: [],
};
diffPreferences = {
context: 10,
tab_size: 8,
font_size: 12,
line_length: 100,
cursor_blink_rate: 0,
line_wrapping: false,
intraline_difference: true,
show_line_endings: true,
show_tabs: true,
show_whitespace_errors: true,
syntax_highlighting: true,
auto_hide_diff_table_header: true,
theme: 'DEFAULT',
ignore_whitespace: 'IGNORE_NONE',
};
config = {auth: {editable_account_fields: []}};
stub('gr-rest-api-interface', {
getLoggedIn() { return Promise.resolve(true); },
getAccount() { return Promise.resolve(account); },
getPreferences() { return Promise.resolve(preferences); },
getDiffPreferences() {
return Promise.resolve(diffPreferences);
},
getWatchedProjects() {
return Promise.resolve([]);
},
@@ -261,56 +241,6 @@ limitations under the License.
});
});
test('diff preferences', done => {
// Rendered with the expected preferences selected.
assert.equal(valueOf('Context', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.context);
assert.equal(valueOf('Diff width', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.line_length);
assert.equal(valueOf('Tab width', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.tab_size);
assert.equal(valueOf('Font size', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.font_size);
assert.equal(valueOf('Show tabs', 'diffPreferences')
.firstElementChild.checked, diffPreferences.show_tabs);
assert.equal(valueOf('Show trailing whitespace', 'diffPreferences')
.firstElementChild.checked, diffPreferences.show_whitespace_errors);
assert.equal(valueOf('Fit to screen', 'diffPreferences')
.firstElementChild.checked, diffPreferences.line_wrapping);
assert.isFalse(element._diffPrefsChanged);
const showTabsCheckbox = valueOf('Show tabs', 'diffPreferences')
.firstElementChild;
showTabsCheckbox.checked = false;
element._handleDiffShowTabsChanged();
assert.isTrue(element._diffPrefsChanged);
stub('gr-rest-api-interface', {
saveDiffPreferences(prefs) {
assert.equal(prefs.show_tabs, false);
return Promise.resolve();
},
});
// Save the change.
element._handleSaveDiffPreferences().then(() => {
assert.isFalse(element._diffPrefsChanged);
done();
});
});
test('columns input is hidden with fit to scsreen is selected', () => {
assert.isFalse(element.$.columnsPref.hidden);
MockInteractions.tap(element.$.diffLineWrapping);
assert.isTrue(element.$.columnsPref.hidden);
MockInteractions.tap(element.$.diffLineWrapping);
assert.isFalse(element.$.columnsPref.hidden);
});
test('menu', done => {
assert.isFalse(element._menuChanged);
assert.isFalse(element._prefsChanged);

View File

@@ -0,0 +1,163 @@
<!--
@license
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.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/iron-input/iron-input.html">
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../gr-button/gr-button.html">
<link rel="import" href="../gr-rest-api-interface/gr-rest-api-interface.html">
<link rel="import" href="../gr-select/gr-select.html">
<dom-module id="gr-diff-preferences">
<template>
<style include="shared-styles"></style>
<style include="gr-form-styles"></style>
<div id="diffPreferences" class="gr-form-styles">
<section>
<span class="title">Context</span>
<span class="value">
<gr-select
id="contextSelect"
bind-value="{{diffPrefs.context}}">
<select
on-keypress="_handleDiffPrefsChanged"
on-change="_handleDiffPrefsChanged">
<option value="3">3 lines</option>
<option value="10">10 lines</option>
<option value="25">25 lines</option>
<option value="50">50 lines</option>
<option value="75">75 lines</option>
<option value="100">100 lines</option>
<option value="-1">Whole file</option>
</select>
</gr-select>
</span>
</section>
<section>
<span class="title">Fit to screen</span>
<span class="value">
<input
id="lineWrappingInput"
type="checkbox"
checked$="[[diffPrefs.line_wrapping]]"
on-change="_handleLineWrappingTap">
</span>
</section>
<section>
<span class="title">Diff width</span>
<span class="value">
<input
is="iron-input"
type="number"
id="columnsInput"
prevent-invalid-input
allowed-pattern="[0-9]"
bind-value="{{diffPrefs.line_length}}"
on-keypress="_handleDiffPrefsChanged"
on-change="_handleDiffPrefsChanged">
</span>
</section>
<section>
<span class="title">Tab width</span>
<span class="value">
<input
is="iron-input"
type="number"
id="tabSizeInput"
prevent-invalid-input
allowed-pattern="[0-9]"
bind-value="{{diffPrefs.tab_size}}"
on-keypress="_handleDiffPrefsChanged"
on-change="_handleDiffPrefsChanged">
</span>
</section>
<section hidden$="[[!diffPrefs.font_size]]">
<span class="title">Font size</span>
<span class="value">
<input
is="iron-input"
type="number"
id="fontSizeInput"
prevent-invalid-input
allowed-pattern="[0-9]"
bind-value="{{diffPrefs.font_size}}"
on-keypress="_handleDiffPrefsChanged"
on-change="_handleDiffPrefsChanged">
</span>
</section>
<section>
<span class="title">Show tabs</span>
<span class="value">
<input
id="showTabsInput"
type="checkbox"
checked$="[[diffPrefs.show_tabs]]"
on-change="_handleShowTabsTap">
</span>
</section>
<section>
<span class="title">Show trailing whitespace</span>
<span class="value">
<input
id="showTrailingWhitespaceInput"
type="checkbox"
checked$="[[diffPrefs.show_whitespace_errors]]"
on-change="_handleShowTrailingWhitespaceTap">
</span>
</section>
<section>
<span class="title">Syntax highlighting</span>
<span class="value">
<input
id="syntaxHighlightInput"
type="checkbox"
checked$="[[diffPrefs.syntax_highlighting]]"
on-change="_handleSyntaxHighlightTap">
</span>
</section>
<section>
<span class="title">Automatically mark viewed files reviewed</span>
<span class="value">
<input
id="automaticReviewInput"
type="checkbox"
checked$="[[diffPrefs.manual_review]]"
on-change="_handleAutomaticReviewTap">
</span>
</section>
<section>
<div class="pref">
<span class="title">Ignore Whitespace</span>
<span class="value">
<gr-select bind-value="{{diffPrefs.ignore_whitespace}}">
<select
on-keypress="_handleDiffPrefsChanged"
on-change="_handleDiffPrefsChanged">
<option value="IGNORE_NONE">None</option>
<option value="IGNORE_TRAILING">Trailing</option>
<option value="IGNORE_LEADING_AND_TRAILING">Leading & trailing</option>
<option value="IGNORE_ALL">All</option>
</select>
</gr-select>
</span>
</div>
</section>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
</template>
<script src="gr-diff-preferences.js"></script>
</dom-module>

View File

@@ -0,0 +1,78 @@
/**
* @license
* 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-diff-preferences',
properties: {
hasUnsavedChanges: {
type: Boolean,
notify: true,
value: false,
},
/** @type {?} */
diffPrefs: Object,
},
loadData() {
return this.$.restAPI.getDiffPreferences().then(prefs => {
this.diffPrefs = prefs;
});
},
_handleDiffPrefsChanged() {
this.hasUnsavedChanges = true;
},
_handleLineWrappingTap() {
this.set('diffPrefs.line_wrapping', this.$.lineWrappingInput.checked);
this._handleDiffPrefsChanged();
},
_handleShowTabsTap() {
this.set('diffPrefs.show_tabs', this.$.showTabsInput.checked);
this._handleDiffPrefsChanged();
},
_handleShowTrailingWhitespaceTap() {
this.set('diffPrefs.show_whitespace_errors',
this.$.showTrailingWhitespaceInput.checked);
this._handleDiffPrefsChanged();
},
_handleSyntaxHighlightTap() {
this.set('diffPrefs.syntax_highlighting',
this.$.syntaxHighlightInput.checked);
this._handleDiffPrefsChanged();
},
_handleAutomaticReviewTap() {
this.set('diffPrefs.manual_review',
this.$.automaticReviewInput.checked);
this._handleDiffPrefsChanged();
},
save() {
return this.$.restAPI.saveDiffPreferences(this.diffPrefs).then(res => {
this.hasUnsavedChanges = false;
});
},
});
})();

View File

@@ -0,0 +1,123 @@
<!DOCTYPE html>
<!--
@license
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.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>gr-diff-preferences</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-diff-preferences.html">
<script>void(0);</script>
<test-fixture id="basic">
<template>
<gr-diff-preferences></gr-diff-preferences>
</template>
</test-fixture>
<script>
suite('gr-diff-preferences tests', () => {
let element;
let sandbox;
let diffPreferences;
function valueOf(title, fieldsetid) {
const sections = element.$[fieldsetid].querySelectorAll('section');
let titleEl;
for (let i = 0; i < sections.length; i++) {
titleEl = sections[i].querySelector('.title');
if (titleEl.textContent.trim() === title) {
return sections[i].querySelector('.value');
}
}
}
setup(() => {
diffPreferences = {
context: 10,
line_wrapping: false,
line_length: 100,
tab_size: 8,
font_size: 12,
show_tabs: true,
show_whitespace_errors: true,
syntax_highlighting: true,
manual_review: false,
ignore_whitespace: 'IGNORE_NONE',
};
stub('gr-rest-api-interface', {
getDiffPreferences() {
return Promise.resolve(diffPreferences);
},
});
element = fixture('basic');
sandbox = sinon.sandbox.create();
return element.loadData();
});
teardown(() => { sandbox.restore(); });
test('renders', () => {
// Rendered with the expected preferences selected.
assert.equal(valueOf('Context', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.context);
assert.equal(valueOf('Fit to screen', 'diffPreferences')
.firstElementChild.checked, diffPreferences.line_wrapping);
assert.equal(valueOf('Diff width', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.line_length);
assert.equal(valueOf('Tab width', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.tab_size);
assert.equal(valueOf('Font size', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.font_size);
assert.equal(valueOf('Show tabs', 'diffPreferences')
.firstElementChild.checked, diffPreferences.show_tabs);
assert.equal(valueOf('Show trailing whitespace', 'diffPreferences')
.firstElementChild.checked, diffPreferences.show_whitespace_errors);
assert.equal(valueOf('Syntax highlighting', 'diffPreferences')
.firstElementChild.checked, diffPreferences.syntax_highlighting);
assert.equal(
valueOf('Automatically mark viewed files reviewed', 'diffPreferences')
.firstElementChild.checked, diffPreferences.manual_review);
assert.equal(valueOf('Ignore Whitespace', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.ignore_whitespace);
assert.isFalse(element.hasUnsavedChanges);
});
test('save changes', () => {
sandbox.stub(element.$.restAPI, 'saveDiffPreferences')
.returns(Promise.resolve());
const showTrailingWhitespaceCheckbox =
valueOf('Show trailing whitespace', 'diffPreferences')
.firstElementChild;
showTrailingWhitespaceCheckbox.checked = false;
element._handleShowTrailingWhitespaceTap();
assert.isTrue(element.hasUnsavedChanges);
// Save the change.
return element.save().then(() => {
assert.isFalse(element.hasUnsavedChanges);
});
});
});
</script>

View File

@@ -110,7 +110,6 @@ limitations under the License.
'diff/gr-diff-highlight/gr-annotation_test.html',
'diff/gr-diff-highlight/gr-diff-highlight_test.html',
'diff/gr-diff-mode-selector/gr-diff-mode-selector_test.html',
'diff/gr-diff-preferences/gr-diff-preferences_test.html',
'diff/gr-diff-processor/gr-diff-processor_test.html',
'diff/gr-diff-selection/gr-diff-selection_test.html',
'diff/gr-diff-view/gr-diff-view_test.html',
@@ -162,6 +161,7 @@ limitations under the License.
'shared/gr-cursor-manager/gr-cursor-manager_test.html',
'shared/gr-date-formatter/gr-date-formatter_test.html',
'shared/gr-dialog/gr-dialog_test.html',
'shared/gr-diff-preferences/gr-diff-preferences_test.html',
'shared/gr-download-commands/gr-download-commands_test.html',
'shared/gr-dropdown-list/gr-dropdown-list_test.html',
'shared/gr-editable-content/gr-editable-content_test.html',