summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/shared
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/shared')
-rw-r--r--polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.html163
-rw-r--r--polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.js78
-rw-r--r--polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences_test.html123
3 files changed, 364 insertions, 0 deletions
diff --git a/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.html b/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.html
new file mode 100644
index 0000000000..d7bc704cce
--- /dev/null
+++ b/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.html
@@ -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>
diff --git a/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.js b/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.js
new file mode 100644
index 0000000000..e2278c2680
--- /dev/null
+++ b/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.js
@@ -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;
+ });
+ },
+ });
+})();
diff --git a/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences_test.html b/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences_test.html
new file mode 100644
index 0000000000..511737fcd8
--- /dev/null
+++ b/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences_test.html
@@ -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>