Merge "Add reset button to my menu in settings"

This commit is contained in:
Paladox none 2018-04-06 18:46:44 +00:00 committed by Gerrit Code Review
commit e137acc455
4 changed files with 58 additions and 5 deletions

View File

@ -334,11 +334,16 @@ limitations under the License.
</fieldset> </fieldset>
<h2 id="Menu" class$="[[_computeHeaderClass(_menuChanged)]]">Menu</h2> <h2 id="Menu" class$="[[_computeHeaderClass(_menuChanged)]]">Menu</h2>
<fieldset id="menu"> <fieldset id="menu">
<gr-menu-editor menu-items="{{_localMenu}}"></gr-menu-editor> <gr-menu-editor
menu-items="{{_localMenu}}"></gr-menu-editor>
<gr-button <gr-button
id="saveMenu" id="saveMenu"
on-tap="_handleSaveMenu" on-tap="_handleSaveMenu"
disabled="[[!_menuChanged]]">Save changes</gr-button> disabled="[[!_menuChanged]]">Save changes</gr-button>
<gr-button
id="resetMenu"
link
on-tap="_handleResetMenuButton">Reset</gr-button>
</fieldset> </fieldset>
<h2 id="ChangeTableColumns" <h2 id="ChangeTableColumns"
class$="[[_computeHeaderClass(_changeTableChanged)]]"> class$="[[_computeHeaderClass(_changeTableChanged)]]">

View File

@ -162,7 +162,7 @@
this.prefs = prefs; this.prefs = prefs;
this._showNumber = !!prefs.legacycid_in_change_table; this._showNumber = !!prefs.legacycid_in_change_table;
this._copyPrefs('_localPrefs', 'prefs'); this._copyPrefs('_localPrefs', 'prefs');
this._cloneMenu(); this._cloneMenu(prefs.my);
this._cloneChangeTableColumns(); this._cloneChangeTableColumns();
})); }));
@ -226,9 +226,9 @@
} }
}, },
_cloneMenu() { _cloneMenu(prefs) {
const menu = []; const menu = [];
for (const item of this.prefs.my) { for (const item of prefs) {
menu.push({ menu.push({
name: item.name, name: item.name,
url: item.url, url: item.url,
@ -343,12 +343,20 @@
_handleSaveMenu() { _handleSaveMenu() {
this.set('prefs.my', this._localMenu); this.set('prefs.my', this._localMenu);
this._cloneMenu(); this._cloneMenu(this.prefs.my);
return this.$.restAPI.savePreferences(this.prefs).then(() => { return this.$.restAPI.savePreferences(this.prefs).then(() => {
this._menuChanged = false; this._menuChanged = false;
}); });
}, },
_handleResetMenuButton() {
return this.$.restAPI.getDefaultPreferences().then(data => {
if (data && data.my) {
this._cloneMenu(data.my);
}
});
},
_handleSaveWatchedProjects() { _handleSaveWatchedProjects() {
this.$.watchedProjectsEditor.save(); this.$.watchedProjectsEditor.save();
}, },

View File

@ -407,6 +407,42 @@ limitations under the License.
assert.isTrue(element.prefs.legacycid_in_change_table); assert.isTrue(element.prefs.legacycid_in_change_table);
}); });
test('reset menu item back to default', done => {
const originalMenu = {
my: [
{url: '/first/url', name: 'first name', target: '_blank'},
{url: '/second/url', name: 'second name', target: '_blank'},
{url: '/third/url', name: 'third name', target: '_blank'},
],
};
stub('gr-rest-api-interface', {
getDefaultPreferences() { return Promise.resolve(originalMenu); },
});
const updatedMenu = [
{url: '/first/url', name: 'first name', target: '_blank'},
{url: '/second/url', name: 'second name', target: '_blank'},
{url: '/third/url', name: 'third name', target: '_blank'},
{url: '/fourth/url', name: 'fourth name', target: '_blank'},
];
element.set('_localMenu', updatedMenu);
element._handleResetMenuButton().then(() => {
assertMenusEqual(element._localMenu, originalMenu.my);
done();
});
});
test('test that reset button is called', () => {
const overlayOpen = sandbox.stub(element, '_handleResetMenuButton');
MockInteractions.tap(element.$.resetMenu);
assert.isTrue(overlayOpen.called);
});
suite('_getFilterDocsLink', () => { suite('_getFilterDocsLink', () => {
test('with http: docs base URL', () => { test('with http: docs base URL', () => {
const base = 'http://example.com/'; const base = 'http://example.com/';

View File

@ -757,6 +757,10 @@
}); });
}, },
getDefaultPreferences() {
return this._fetchSharedCacheURL('/config/server/preferences');
},
getPreferences() { getPreferences() {
return this.getLoggedIn().then(loggedIn => { return this.getLoggedIn().then(loggedIn => {
if (loggedIn) { if (loggedIn) {