diff --git a/settings.json.docker b/settings.json.docker index 6b4b32426..a52c63924 100644 --- a/settings.json.docker +++ b/settings.json.docker @@ -290,6 +290,7 @@ "cmdShiftC": "${PAD_SHORTCUTS_ENABLED_CMD_SHIFT_C:true}", /* clear authorship */ "cmdH": "${PAD_SHORTCUTS_ENABLED_CMD_H:true}", /* backspace */ "ctrlHome": "${PAD_SHORTCUTS_ENABLED_CTRL_HOME:true}", /* scroll to top of pad */ + "cmdEsc": "${PAD_SHORTCUTS_ENABLED_CMD_ESC:true}", /* Exit pad and go back to home */ "pageUp": "${PAD_SHORTCUTS_ENABLED_PAGE_UP:true}", "pageDown": "${PAD_SHORTCUTS_ENABLED_PAGE_DOWN:true}" }, @@ -643,7 +644,7 @@ "right": [ ["importexport", "timeslider", "savedrevision"], ["settings", "embed"], - ["showusers"] + ["showusers", "gohome", "logout"] ], "timeslider": [ ["timeslider_export", "timeslider_returnToPad"] diff --git a/settings.json.template b/settings.json.template index e6293d87f..9f7e9418d 100644 --- a/settings.json.template +++ b/settings.json.template @@ -275,6 +275,7 @@ "cmdShiftC": true, /* clear authorship */ "cmdH": true, /* backspace */ "ctrlHome": true, /* scroll to top of pad */ + "cmdEsc": true, /* Exit pad and go back to home */ "pageUp": true, "pageDown": true }, @@ -642,7 +643,7 @@ "right": [ ["importexport", "timeslider", "savedrevision"], ["settings", "embed"], - ["showusers"] + ["showusers", "gohome", "logout"] ], "timeslider": [ ["timeslider_export", "timeslider_returnToPad"] diff --git a/src/locales/en.json b/src/locales/en.json index 5305a7025..6428f4b92 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -54,6 +54,9 @@ "pad.toolbar.settings.title": "Settings", "pad.toolbar.embed.title": "Share and Embed this pad", "pad.toolbar.showusers.title": "Show the users on this pad", + "pad.toolbar.gohome.title": "Go Home", + "pad.toolbar.logout.title": "Logout", + "pad.colorpicker.save": "Save", "pad.colorpicker.cancel": "Cancel", diff --git a/src/node/utils/Settings.ts b/src/node/utils/Settings.ts index 4d7b421e1..c906fdf97 100644 --- a/src/node/utils/Settings.ts +++ b/src/node/utils/Settings.ts @@ -229,6 +229,7 @@ exports.padShortcutEnabled = { cmdShiftC: true, cmdH: true, ctrlHome: true, + cmdEsc: true, pageUp: true, pageDown: true, }; @@ -246,7 +247,7 @@ exports.toolbar = { right: [ ['importexport', 'timeslider', 'savedrevision'], ['settings', 'embed'], - ['showusers'], + ['showusers', 'gohome', 'logout'], ], timeslider: [ ['timeslider_export', 'timeslider_settings', 'timeslider_returnToPad'], diff --git a/src/node/utils/toolbar.ts b/src/node/utils/toolbar.ts index f0ef45479..ea48580d3 100644 --- a/src/node/utils/toolbar.ts +++ b/src/node/utils/toolbar.ts @@ -241,6 +241,18 @@ module.exports = { embed: defaultButtonAttributes('embed'), showusers: defaultButtonAttributes('showusers'), + gohome:{ + command: 'gohome', + localizationId: 'pad.toolbar.gohome.title', + class: 'buttonicon buttonicon-gohome', + }, + + logout:{ + command: 'logout', + localizationId: 'pad.toolbar.logout.title', + class: 'buttonicon buttonicon-logout', + }, + timeslider_export: { command: 'import_export', localizationId: 'timeslider.toolbar.exportlink.title', diff --git a/src/static/css/pad.css b/src/static/css/pad.css index 5ef192509..027877e23 100644 --- a/src/static/css/pad.css +++ b/src/static/css/pad.css @@ -12,6 +12,7 @@ @import url("pad/gritter.css"); @import url("pad/loadingbox.css"); @import url("pad/form.css"); +@import url("pad/home.css"); html { font-size: 15px; diff --git a/src/static/css/pad/home.css b/src/static/css/pad/home.css new file mode 100644 index 000000000..1c35ce02b --- /dev/null +++ b/src/static/css/pad/home.css @@ -0,0 +1,10 @@ +/*.homeicon-exit:before { + content: "\2302"; + margin-right: 3px; +} + +.homeicon:hover{ + background-color: grey; +} + +*/ \ No newline at end of file diff --git a/src/static/css/pad/icons.css b/src/static/css/pad/icons.css index eb1016dca..d703d9d5c 100644 --- a/src/static/css/pad/icons.css +++ b/src/static/css/pad/icons.css @@ -74,6 +74,12 @@ .buttonicon-showusers:before { content: "\e835"; } +.buttonicon-gohome:before { + content: "\e80b"; /* Assuming \e80b is the Unicode for the home icon */ +} +.buttonicon-logout:before { + content: "\e800"; /* Assuming \e800 is the Unicode for the logout icon */ +} .buttonicon-savedRevision:before { content: "\e856"; } diff --git a/src/static/js/pad_editbar.ts b/src/static/js/pad_editbar.ts index d98174fe5..b73af9710 100644 --- a/src/static/js/pad_editbar.ts +++ b/src/static/js/pad_editbar.ts @@ -387,6 +387,22 @@ exports.padeditbar = new class { $('#myusernameedit').trigger('focus'); }); + this.registerCommand('gohome', () => { + console.log('Go Home button clicked'); + window.location.href = '/'; + }); + + this.registerCommand('logout', () => { + console.log('Logout button clicked'); + // Clear session or authentication token + fetch('/logout', { method: 'POST' }) + .then(response => { + if (response.ok) { + window.location.href = '/'; // Redirect to the home page + } + }); + }); + this.registerCommand('embed', () => { this.setEmbedLinks(); this.toggleDropDown('embed'); diff --git a/src/tests/frontend-new/helper/padHelper.ts b/src/tests/frontend-new/helper/padHelper.ts index f52cd0a35..28673feed 100644 --- a/src/tests/frontend-new/helper/padHelper.ts +++ b/src/tests/frontend-new/helper/padHelper.ts @@ -20,6 +20,10 @@ export const toggleUserList = async (page: Page) => { await page.locator("button[data-l10n-id='pad.toolbar.showusers.title']").click() } +export const leavePad = async (page: Page) => { + await page.locator("button[data-l10n-id='pad.toolbar.gohome.title']").click(); +} + export const setUserName = async (page: Page, userName: string) => { await page.waitForSelector('[class="popup popup-show"]') await page.click("input[data-l10n-id='pad.userlist.entername']"); diff --git a/src/tests/frontend-new/specs/leavePadTests.ts b/src/tests/frontend-new/specs/leavePadTests.ts new file mode 100644 index 000000000..497bcdd3f --- /dev/null +++ b/src/tests/frontend-new/specs/leavePadTests.ts @@ -0,0 +1,16 @@ +import { test, expect } from '@playwright/test'; // Assuming Playwright is being used +import { leavePad } from '../helper/padHelper'; // Import the exitPad function + +test('should exit the pad and return to the homepage', async ({ page }) => { + // Open a new pad (this can use helper.newPad() if it exists) + await page.goto('http://localhost:9001/p/test-' + Date.now()); // Or use helper.newPad() + + // Ensure the page is loaded + await page.waitForLoadState('domcontentloaded'); + + // Click the exit button using the exitPad function + await leavePad(page); + + // Verify that the page has navigated to the homepage + await expect(page).toHaveURL('http://localhost:9001/'); +}); \ No newline at end of file diff --git a/src/tests/frontend/helper/ui.ts b/src/tests/frontend/helper/ui.ts index 69e6b7d40..3c35aa154 100644 --- a/src/tests/frontend/helper/ui.ts +++ b/src/tests/frontend/helper/ui.ts @@ -85,6 +85,21 @@ helper.toggleUserList = async () => { await helper.waitForPromise(() => !isVisible); }; +helper.homeButton = () => helper.padChrome$("button[data-l10n-id='pad.toolbar.gohome.title']"); + +helper.leavePad = async () => { + const button = helper.homeButton(); + button.trigger('click'); + await helper.waitForPromise(() => window.location.pathname === '/'); +}; + +helper.newPad = async (page: Page) => { + // create a new pad before each test run + const padId = "FRONTEND_TESTS"+randomUUID(); + await page.goto('http://localhost:9001/p/'+padId); + await page.waitForSelector('iframe[name="ace_outer"]'); + return padId; +} /** * Gets the user name input field * diff --git a/src/tests/frontend/specs/leavePadTest.js b/src/tests/frontend/specs/leavePadTest.js new file mode 100644 index 000000000..4d0652052 --- /dev/null +++ b/src/tests/frontend/specs/leavePadTest.js @@ -0,0 +1,10 @@ +describe("Leave Pad Functionality", function () { + beforeEach(async function () { + await helper.newPad(); // Open a new pad before each test + }); + + it("should leave the pad and go back to the homepage", async function () { + await helper.leavePad(); // Clicks the exit button + expect(window.location.pathname).toBe("/"); // Confirms we are on the homepage + }); +}); diff --git a/ui/pad.html b/ui/pad.html index e11541943..baa3a0b3f 100644 --- a/ui/pad.html +++ b/ui/pad.html @@ -77,6 +77,16 @@