Skip to content

Commit

Permalink
feat: setPage{Url,Title}() functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
hash-bang committed May 7, 2024
1 parent c26b34a commit bc6d00f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/terafy.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default class TeraFy {

// Webpages
'setPageUrl',
'setPageTitle',

// UI
'uiAlert',
Expand Down Expand Up @@ -1017,8 +1018,15 @@ export default class TeraFy {
* @function setPageUrl
* @param {String} url The URL to restore on next refresh
*/
setPageUrl(url) {
}


/**
* Set the active page title
* This is usually called by a tool nested within the tera-tools.com embed
*
* @function setPageTitle
* @param {String} title The current page title
*/


/**
Expand Down
21 changes: 19 additions & 2 deletions lib/terafy.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,10 +1192,27 @@ export default class TeraFyServer {
* @param {String} url The URL to restore on next refresh
*/
setPageUrl(url) {
debugger; // FIXME: Untested
console.info('FIXME: Unsupported setPageUrl(', url, ')');
if (!url.startsWith('/')) throw new Error('All pageURLs must be a relative path starting with a slash');

let $routeMatched = app.service('$route').matched[0];
if (!$routeMatched?.name) throw new Error('No active route');
if (!$routeMatched?.path.endsWith('/:toolPath(.*)?')) throw new Error('No tool active');

app.router.push({
path: $routeMatched.path.replace(/\/:toolPath\(\.\*\)\?$/, url),
});
}


/**
* Set the active page title
* This is usually called by a tool nested within the tera-tools.com embed
*
* @param {String} [title] The current page title. Set to a falsy value to revert back to the default page title
*/
setPageTitle(title) {
app.root.setPageTitle(title);
}
// }}}

// Init - constructor(), init() {{{
Expand Down

0 comments on commit bc6d00f

Please sign in to comment.