Skip to content

Commit

Permalink
fix: favicon called repeatedly (#1246)
Browse files Browse the repository at this point in the history
- also refactors use of app-static-config where needed
  • Loading branch information
jaredgalanis authored Jan 12, 2024
1 parent ee68a04 commit dda5d74
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 110 deletions.
3 changes: 1 addition & 2 deletions app/components/found-manuscripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export default class FoundManuscriptsComponent extends Component {

@task
getAppConfig = function* () {
let config = yield this.appStaticConfig.getStaticConfig();
this.contactUrl = config.branding.pages.contactUrl;
this.contactUrl = yield this.appStaticConfig.config?.branding?.pages?.contactUrl;
};

@task
Expand Down
4 changes: 2 additions & 2 deletions app/components/nav-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export default class NavBar extends Component {

@task
_setupAppStaticConfig = function* () {
let config = yield this.appStaticConfig.getStaticConfig();
if (config.branding.showPagesNavBar) {
let config = yield this.appStaticConfig.config;
if (config && config.branding.showPagesNavBar) {
this.aboutUrl = config.branding.pages.aboutUrl;
this.contactUrl = config.branding.pages.contactUrl;
this.faqUrl = config.branding.pages.faqUrl;
Expand Down
8 changes: 5 additions & 3 deletions app/components/notice-banner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export default class NoticeBanner extends Component {

@task
_setupAppStaticConfig = function* () {
let config = yield this.appStaticConfig.getStaticConfig();
this.contactUrl = config.branding.pages.contactUrl;
this.instructionsUrl = config.branding.pages.instructionsUrl;
let config = yield this.appStaticConfig.config;
if (config) {
this.contactUrl = config.branding.pages.contactUrl;
this.instructionsUrl = config.branding.pages.instructionsUrl;
}
};
}
3 changes: 1 addition & 2 deletions app/components/workflow-basics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ export default class WorkflowBasics extends Component {
}

async setupConfig() {
let config = await this.appStaticConfig.getStaticConfig();
this.contactUrl = config.branding.pages.contactUrl;
this.contactUrl = this.appStaticConfig?.config?.branding?.pages?.contactUrl;
}

setPreparers() {
Expand Down
3 changes: 1 addition & 2 deletions app/components/workflow-grants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ export default class WorkflowGrants extends Component {

@task
setup = function* () {
let config = yield this.appStaticConfig.getStaticConfig();
this.contactUrl = config.branding.pages.contactUrl;
this.contactUrl = this.appStaticConfig?.config?.branding?.pages?.contactUrl;

if (get(this, 'args.submission.submitter.id')) {
yield this.updateGrants.perform();
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/grants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { grantsIndexGrantQuery, grantsIndexSubmissionQuery } from '../../util/pa

export default class GrantsIndexController extends Controller {
@service currentUser;
@service('app-static-config') configurator;
@service('app-static-config') staticConfig;
@service('emt-themes/bootstrap4') themeInstance;
@service router;
@service store;

constructor() {
super(...arguments);

this.configurator.getStaticConfig().then((config) => this.set('faqUrl', config.branding.pages.faqUrl));
this.faqUrl = this.staticConfig.config.branding.pages.faqUrl;
}

// TODO Reduce duplication in column definitions
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/submissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { submissionsIndexQuery } from '../../util/paginated-query';

export default class SubmissionsIndex extends Controller {
@service currentUser;
@service('app-static-config') configurator;
@service('app-static-config') staticConfig;
@service('emt-themes/bootstrap4') themeInstance;
@service router;
@service store;
Expand Down Expand Up @@ -38,7 +38,7 @@ export default class SubmissionsIndex extends Controller {
constructor() {
super(...arguments);

this.configurator.getStaticConfig().then((config) => this.set('faqUrl', config.branding.pages.faqUrl));
this.faqUrl = this.staticConfig.config.branding.pages.faqUrl;
}

// Columns displayed depend on the user role
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/thanks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { inject as service } from '@ember/service';
export default class ThanksController extends Controller {
queryParams = ['submission'];

@service('app-static-config')
configurator;
@service('app-static-config') staticConfig;

@tracked submission = null;
@tracked faqUrl = null;

constructor() {
super(...arguments);
this.configurator.getStaticConfig().then((config) => this.set('faqUrl', config.branding.pages.faqUrl));

this.faqUrl = this.staticConfig.config.branding.pages.faqUrl;
}
}
27 changes: 3 additions & 24 deletions app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,17 @@ export default class ApplicationRoute extends CheckSessionRoute {
}
}

async model() {
const config = await this.staticConfig.getStaticConfig();

return {
staticConfig: config,
};
}

/**
* Add styling from static branding. TODO: Should this be moved to an initializer or something?
*/
afterModel(model, transition) {
async afterModel(model, transition) {
const loader = document.getElementById('initial-loader');
if (loader) {
loader.style.display = 'none';
}

if (model.staticConfig) {
if (model.staticConfig.branding.stylesheet) {
const stylesheet = `${model.staticConfig.branding.stylesheet}`;
this.staticConfig.addCSS(stylesheet);
} else {
console.log('%cNo branding stylesheet was configured', 'color:red');
}
if (model.staticConfig.branding.overrides) {
const overrides = `${model.staticConfig.branding.overrides}`;
this.staticConfig.addCSS(overrides);
}
if (model.staticConfig.branding.favicon) {
const favicon = `${model.staticConfig.branding.favicon}`;
this.staticConfig.addFavicon(favicon);
}
if (!this.staticConfig.config) {
await this.staticConfig.setupStaticConfig();
}
}
}
2 changes: 1 addition & 1 deletion app/routes/not-found-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class NotFoundErrorRoute extends CheckSessionRoute {

model() {
return RSVP.hash({
config: this.staticConfig.getStaticConfig(),
config: this.staticConfig.config,
});
}
}
24 changes: 24 additions & 0 deletions app/services/app-static-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@ export default class AppStaticConfigService extends Service {
this.configUrl = ENV.APP.staticConfigUri;
}

get config() {
return this._config;
}

async setupStaticConfig() {
await this.getStaticConfig();
if (this._config) {
if (this._config.branding.stylesheet) {
const stylesheet = `${this._config.branding.stylesheet}`;
this.addCSS(stylesheet);
} else {
console.log('%cNo branding stylesheet was configured', 'color:red');
}
if (this._config.branding.overrides) {
const overrides = `${this._config.branding.overrides}`;
this.addCSS(overrides);
}
if (this._config.branding.favicon) {
const favicon = `${this._config.branding.favicon}`;
this.addFavicon(favicon);
}
}
}

/**
* Get the static configuration for PASS -- from ENV vars
*
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/components/nav-bar-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable ember/avoid-leaking-state-in-ember-objects */
/* eslint-disable ember/no-classic-classes */
import Service from '@ember/service';
import { setupRenderingTest } from 'ember-qunit';
Expand All @@ -10,17 +11,16 @@ module('Integration | Component | nav bar', (hooks) => {

test('it renders', async function (assert) {
const mockStaticConfig = Service.extend({
getStaticConfig: () =>
Promise.resolve({
branding: {
stylesheet: '',
pages: {
aboutUrl: '',
contactUrl: '',
faqUrl: '',
},
config: {
branding: {
stylesheet: '',
pages: {
aboutUrl: '',
contactUrl: '',
faqUrl: '',
},
}),
},
},
addCss: () => {},
});

Expand Down
18 changes: 9 additions & 9 deletions tests/integration/components/notice-banner-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable ember/avoid-leaking-state-in-ember-objects */
/* eslint-disable ember/no-classic-classes */
import Service from '@ember/service';
import { setupRenderingTest } from 'ember-qunit';
Expand All @@ -10,16 +11,15 @@ module('Integration | Component | notice-banner', (hooks) => {

test('it renders', async function (assert) {
const mockStaticConfig = Service.extend({
getStaticConfig: () =>
Promise.resolve({
branding: {
stylesheet: '',
pages: {
contactUrl: 'http://test-contact/',
instructionsUrl: 'http://test-instructions/',
},
config: {
branding: {
stylesheet: '',
pages: {
contactUrl: 'http://test-contact/',
instructionsUrl: 'http://test-instructions/',
},
}),
},
},
addCss: () => {},
});

Expand Down
1 change: 0 additions & 1 deletion tests/integration/helpers/format-date-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { module, test } from 'qunit';
module('Integration | Helper | format date', (hooks) => {
setupRenderingTest(hooks);

// Replace this with your real tests.
test('it renders', async function (assert) {
// eslint-disable-line
this.set('inputValue', 'August 19, 1975 23:15:30');
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/controllers/grants/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

class MockConfigService extends Service {
getStaticConfig() {
return Promise.resolve({ branding: { stylesheet: '', pages: { faqUrl: '' } } });
get config() {
return { branding: { stylesheet: '', pages: { faqUrl: '' } } };
}
addCss() {}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/controllers/submissions/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

class MockConfigService extends Service {
getStaticConfig() {
return Promise.resolve({ branding: { stylesheet: '', pages: { faqUrl: '' } } });
get config() {
return { branding: { stylesheet: '', pages: { faqUrl: '' } } };
}
addCss() {}
}
Expand Down
31 changes: 0 additions & 31 deletions tests/unit/controllers/thanks-test.js

This file was deleted.

12 changes: 0 additions & 12 deletions tests/unit/routes/thanks-test.js

This file was deleted.

0 comments on commit dda5d74

Please sign in to comment.