From 8c57c82caa9d2db6068874e84e09c47a4690bd20 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 2 Dec 2020 16:19:28 -0500 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20apply=20autofocus=20?= =?UTF-8?q?to=20origin=20and=20auth=20forms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/desktop/app/templates/origin.hbs | 3 ++- .../app/templates/scopes/scope/authenticate/method.hbs | 3 ++- ui/desktop/package.json | 1 + yarn.lock | 10 +++++++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ui/desktop/app/templates/origin.hbs b/ui/desktop/app/templates/origin.hbs index 1421af91d..8fbae5380 100644 --- a/ui/desktop/app/templates/origin.hbs +++ b/ui/desktop/app/templates/origin.hbs @@ -15,7 +15,8 @@ @type="text" @value={{this.origin}} @label={{t "form.origin.label"}} - @helperText={{t "form.origin.description"}} /> + @helperText={{t "form.origin.description"}} + {{autofocus}} /> diff --git a/ui/desktop/app/templates/scopes/scope/authenticate/method.hbs b/ui/desktop/app/templates/scopes/scope/authenticate/method.hbs index 709c1f491..8cdf94c64 100644 --- a/ui/desktop/app/templates/scopes/scope/authenticate/method.hbs +++ b/ui/desktop/app/templates/scopes/scope/authenticate/method.hbs @@ -13,7 +13,8 @@ @name="identification" @type="text" @value={{this.identification}} - @label={{t "form.login_name.label"}} /> + @label={{t "form.login_name.label"}} + {{autofocus}} /> Date: Wed, 2 Dec 2020 16:41:20 -0500 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20autopopulate=20origi?= =?UTF-8?q?n=20field=20in=20development?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/desktop/app/routes/origin.js | 23 ++++++++++++++++++++++- ui/desktop/config/environment.js | 5 +++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ui/desktop/app/routes/origin.js b/ui/desktop/app/routes/origin.js index 9d3704e92..9e3df0ace 100644 --- a/ui/desktop/app/routes/origin.js +++ b/ui/desktop/app/routes/origin.js @@ -1,7 +1,9 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; +import { getOwner } from '@ember/application'; import { action } from '@ember/object'; import loading from 'ember-loading/decorator'; +import config from '../config/environment'; export default class OriginRoute extends Route { // =services @@ -20,6 +22,17 @@ export default class OriginRoute extends Route { return this.store.adapterFor('application'); } + /** + * Looks up the window object indirectly. + * @type {Window} + */ + get window() { + // The Ember way of accessing globals... + const document = getOwner(this).lookup('service:-document').documentElement; + // defaultView === window, but without using globals directly + return document.parentNode.defaultView; + } + // =methods /** @@ -36,7 +49,15 @@ export default class OriginRoute extends Route { */ setupController(controller) { super.setupController(...arguments); - const origin = this.origin.rendererOrigin; + let origin = this.origin.rendererOrigin; + // If origin is unset and this is a development environment, + // autoset the origin field of the UI for better DX. + // The controller URL is almost always the same as the current window when + // using mocks, and this makes development more rapid since developers + // do not need to fill an origin on every session. + if (!origin && config.autoOrigin) { + origin = this.window.location.origin; + } controller.setProperties({ origin }); } diff --git a/ui/desktop/config/environment.js b/ui/desktop/config/environment.js index d549aba56..e4b94e3fc 100644 --- a/ui/desktop/config/environment.js +++ b/ui/desktop/config/environment.js @@ -50,6 +50,11 @@ module.exports = function (environment) { // ENV.APP.LOG_TRANSITIONS = true; // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; // ENV.APP.LOG_VIEW_LOOKUPS = true; + + // This flag tells the origin route to autoset the controller origin field + // of the UI, which only makes sense in development where the origin is + // usually the same as the application origin. + ENV.autoOrigin = true; } if (environment === 'test') {