diff --git a/addon/services/current-user.js b/addon/services/current-user.js index 726b603..804c02b 100644 --- a/addon/services/current-user.js +++ b/addon/services/current-user.js @@ -88,14 +88,26 @@ export default class CurrentUserService extends Service.extend(Evented) { this.set('user', user); this.trigger('user.loaded', user); + console.log(user); + // Set permissions this.permissions = this.getUserPermissions(user); // Set environment from user option this.theme.setEnvironment(); - // Load user preferces - await this.loadPreferences(); + // Set locale + if (user.locale) { + this.setLocale(user.locale); + } else { + await this.loadLocale(); + } + + // Load user whois data + await this.loadWhois(); + + // Load user organizations + await this.loadOrganizations(); // Optional callback if (typeof options?.onUserResolved === 'function') { @@ -118,9 +130,7 @@ export default class CurrentUserService extends Service.extend(Evented) { async loadLocale() { try { const { locale } = await this.fetch.get('users/locale'); - this.setOption('locale', locale); - this.intl.setLocale(locale); - this.locale = locale; + this.setLocale(locale); return locale; } catch (error) { @@ -207,6 +217,14 @@ export default class CurrentUserService extends Service.extend(Evented) { return this.getWhoisProperty(key); } + setLocale(locale) { + this.setOption('locale', locale); + this.intl.setLocale(locale); + this.locale = locale; + + return this; + } + setOption(key, value) { key = `${this.optionsPrefix}${dasherize(key)}`; diff --git a/addon/services/fetch.js b/addon/services/fetch.js index 79fbcb6..0e0ee84 100644 --- a/addon/services/fetch.js +++ b/addon/services/fetch.js @@ -360,6 +360,7 @@ export default class FetchService extends Service { const pathKeyVersion = new Date().toISOString(); const request = () => { + delete options.fromCache; return this.get(path, query, options).then((response) => { // cache the response this.localCache.set(pathKey, response); diff --git a/addon/utils/register-component.js b/addon/utils/register-component.js new file mode 100644 index 0000000..1c6df1c --- /dev/null +++ b/addon/utils/register-component.js @@ -0,0 +1,8 @@ +import { dasherize } from '@ember/string'; + +export default function registerComponent(owner, componentClass, options = {}) { + const registrationName = options && options.as ? `component:${options.as}` : `component:${dasherize(componentClass.name).replace('-component', '')}`; + if (!owner.hasRegistration(registrationName)) { + owner.register(registrationName, componentClass); + } +} diff --git a/addon/utils/register-helper.js b/addon/utils/register-helper.js new file mode 100644 index 0000000..396a64f --- /dev/null +++ b/addon/utils/register-helper.js @@ -0,0 +1,8 @@ +import { dasherize } from '@ember/string'; + +export default function registerHelper(owner, name, helperFn) { + const registrationName = `helper:${dasherize(name)}`; + if (!owner.hasRegistration(registrationName)) { + owner.register(registrationName, helperFn); + } +} diff --git a/app/utils/register-component.js b/app/utils/register-component.js new file mode 100644 index 0000000..af6623f --- /dev/null +++ b/app/utils/register-component.js @@ -0,0 +1 @@ +export { default } from '@fleetbase/ember-core/utils/register-component'; diff --git a/app/utils/register-helper.js b/app/utils/register-helper.js new file mode 100644 index 0000000..2f651db --- /dev/null +++ b/app/utils/register-helper.js @@ -0,0 +1 @@ +export { default } from '@fleetbase/ember-core/utils/register-helper'; diff --git a/package.json b/package.json index 7553690..923dbed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/ember-core", - "version": "0.2.18", + "version": "0.2.19", "description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.", "keywords": [ "fleetbase-core", diff --git a/tests/unit/utils/register-component-test.js b/tests/unit/utils/register-component-test.js new file mode 100644 index 0000000..ec3f9f5 --- /dev/null +++ b/tests/unit/utils/register-component-test.js @@ -0,0 +1,10 @@ +import registerComponent from 'dummy/utils/register-component'; +import { module, test } from 'qunit'; + +module('Unit | Utility | register-component', function () { + // TODO: Replace this with your real tests. + test('it works', function (assert) { + let result = registerComponent(); + assert.ok(result); + }); +}); diff --git a/tests/unit/utils/register-helper-test.js b/tests/unit/utils/register-helper-test.js new file mode 100644 index 0000000..57b49c1 --- /dev/null +++ b/tests/unit/utils/register-helper-test.js @@ -0,0 +1,10 @@ +import registerHelper from 'dummy/utils/register-helper'; +import { module, test } from 'qunit'; + +module('Unit | Utility | register-helper', function () { + // TODO: Replace this with your real tests. + test('it works', function (assert) { + let result = registerHelper(); + assert.ok(result); + }); +});