From e7b740ba5fa171d39a3555e1cd1a791daf8271c7 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 21 Mar 2019 17:55:58 +0000 Subject: [PATCH] Added reset-to-homepage behaviour when clicking "view site" link no issue - return a basic "guid" from the site's `model` hook so that we have some data which changes on each refresh - add an action to the wrapper element of the "view site" link which will cause the route to refresh when clicked if we're already on the route - move the site iframe into a component so that it can watch an @uuid property and force a reset of the iframe's `src` when it detects a change --- ghost/admin/app/components/gh-nav-menu.js | 14 ++++++++++++- ghost/admin/app/components/gh-site-iframe.js | 20 +++++++++++++++++++ ghost/admin/app/controllers/site.js | 6 ++++++ ghost/admin/app/routes/site.js | 6 +++++- .../app/templates/components/gh-nav-menu.hbs | 4 +++- .../templates/components/gh-site-iframe.hbs | 15 ++++++++++++++ ghost/admin/app/templates/site.hbs | 16 +-------------- 7 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 ghost/admin/app/components/gh-site-iframe.js create mode 100644 ghost/admin/app/controllers/site.js create mode 100644 ghost/admin/app/templates/components/gh-site-iframe.hbs diff --git a/ghost/admin/app/components/gh-nav-menu.js b/ghost/admin/app/components/gh-nav-menu.js index ac3a0e3135..34d6358f87 100644 --- a/ghost/admin/app/components/gh-nav-menu.js +++ b/ghost/admin/app/components/gh-nav-menu.js @@ -1,6 +1,7 @@ import Component from '@ember/component'; import calculatePosition from 'ember-basic-dropdown/utils/calculate-position'; import {computed} from '@ember/object'; +import {getOwner} from '@ember/application'; import {htmlSafe} from '@ember/string'; import {inject as service} from '@ember/service'; @@ -8,7 +9,7 @@ export default Component.extend({ config: service(), feature: service(), ghostPaths: service(), - router: service('router'), + router: service(), session: service(), ui: service(), @@ -42,6 +43,17 @@ export default Component.extend({ this._setIconStyle(); }, + actions: { + transitionToOrRefreshSite() { + let {currentRouteName} = this.router; + if (currentRouteName === 'site') { + getOwner(this).lookup(`route:${currentRouteName}`).refresh(); + } else { + this.router.transitionTo('site'); + } + } + }, + // equivalent to "left: auto; right: -20px" userDropdownPosition(trigger, dropdown) { let {horizontalPosition, verticalPosition, style} = calculatePosition(...arguments); diff --git a/ghost/admin/app/components/gh-site-iframe.js b/ghost/admin/app/components/gh-site-iframe.js new file mode 100644 index 0000000000..0acf8c7083 --- /dev/null +++ b/ghost/admin/app/components/gh-site-iframe.js @@ -0,0 +1,20 @@ +import Component from '@ember/component'; +import {inject as service} from '@ember/service'; + +export default Component.extend({ + config: service(), + + tagName: '', + + didReceiveAttrs() { + // reset the src attribute each time the guid changes - allows for + // a click on the navigation item to reset back to the homepage + if (this.guid !== this._lastGuid) { + let iframe = document.querySelector('#site-frame'); + if (iframe) { + iframe.src = `${this.config.get('blogUrl')}/`; + } + } + this._lastGuid = this.guid; + } +}); diff --git a/ghost/admin/app/controllers/site.js b/ghost/admin/app/controllers/site.js new file mode 100644 index 0000000000..dc003e80a9 --- /dev/null +++ b/ghost/admin/app/controllers/site.js @@ -0,0 +1,6 @@ +import Controller from '@ember/controller'; +import {alias} from '@ember/object/computed'; + +export default Controller.extend({ + guid: alias('model') +}); diff --git a/ghost/admin/app/routes/site.js b/ghost/admin/app/routes/site.js index e3aa40c331..77050b4ccc 100644 --- a/ghost/admin/app/routes/site.js +++ b/ghost/admin/app/routes/site.js @@ -4,5 +4,9 @@ import styleBody from 'ghost-admin/mixins/style-body'; export default AuthenticatedRoute.extend(styleBody, { titleToken: 'Site', - classNames: ['view-site'] + classNames: ['view-site'], + + model() { + return (new Date()).valueOf(); + } }); diff --git a/ghost/admin/app/templates/components/gh-nav-menu.hbs b/ghost/admin/app/templates/components/gh-nav-menu.hbs index 37662c2aaa..cfcb0063a5 100644 --- a/ghost/admin/app/templates/components/gh-nav-menu.hbs +++ b/ghost/admin/app/templates/components/gh-nav-menu.hbs @@ -42,7 +42,9 @@ {{gh-search-input class="gh-nav-search-input"}}