Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link authoring theme with superdesk selected theme #4316

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,20 @@ export function AuthoringThemesService(storage, preferencesService) {
});
};

// when the user change theme of application, the theme of editor will inherit the app's
service.syncWithApplicationTheme = (appTheme: string, themeObject: any) => {
let activeThemeObject = JSON.parse(themeObject);

if (activeThemeObject.theme === 'default' || activeThemeObject.theme === 'dark') {
let activeTheme = appTheme === 'dark-ui'
? {...activeThemeObject, theme: 'dark'}
: {...activeThemeObject, theme: 'default'};

return activeTheme;
} else {
return activeThemeObject;
}
};

return service;
}
21 changes: 10 additions & 11 deletions scripts/apps/users/directives/UserPreferencesDirective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import {applyDefault} from 'core/helpers/typescript-helpers';
* themselves.
*/
UserPreferencesDirective.$inject = ['session', 'preferencesService', 'notify', 'asset',
'metadata', 'desks', 'modal', '$timeout', '$q', 'userList', 'lodash', 'search'];
'metadata', 'desks', 'modal', '$timeout', '$q', 'userList', 'lodash', 'search', 'authThemes'];

export function UserPreferencesDirective(
session, preferencesService, notify, asset, metadata, desks, modal,
$timeout, $q, userList, _, search,
$timeout, $q, userList, _, search, authThemes,
) {
// human readable labels for server values
const LABELS = {
Expand Down Expand Up @@ -46,15 +46,6 @@ export function UserPreferencesDirective(
scope.activeNavigation = null;
scope.activeTheme = localStorage.getItem('theme');

scope.$watch('activeTheme', (val) => {
if (!val) {
return;
}

localStorage.setItem('theme', val);
body.attr('data-theme', val);
});

/*
* Set this to true after adding all the preferences to the scope. If done before, then the
* directives which depend on scope variables might fail to load properly.
Expand Down Expand Up @@ -119,6 +110,9 @@ export function UserPreferencesDirective(
if (_.get(preferences, 'desktop:notification.enabled')) {
preferencesService.desktopNotification.requestPermission();
}

localStorage.setItem('theme', scope.activeTheme);
body.attr('data-theme', scope.activeTheme);
notify.success(gettext('User preferences saved'));
scope.cancel();
}, (reason) => {
Expand Down Expand Up @@ -422,6 +416,11 @@ export function UserPreferencesDirective(

p[key] = _.extend(val, scope.preferences[key]);
});

if (orig['editor:theme'] != null) {
p['editor:theme'] = {...orig['editor:theme'], theme: JSON.stringify(authThemes.syncWithApplicationTheme(scope.activeTheme, orig['editor:theme'].theme))};
}

return p;
}
},
Expand Down
9 changes: 9 additions & 0 deletions scripts/apps/users/tests/sdUserPreferences.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ describe('sdUserPreferences directive', () => {
category: 'article_defaults',
place: '',
},
'editor:theme': {
type: 'string',
theme: JSON.stringify({
theme: 'default',
headline: 'medium',
abstract: 'medium',
body: 'medium',
}),
},
};

metadata.values = {
Expand Down