2021-10-11 19:14:18 +03:00
|
|
|
import Controller from '@ember/controller';
|
2021-10-12 12:18:55 +03:00
|
|
|
import {action} from '@ember/object';
|
2021-10-11 21:30:58 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2021-10-12 12:18:55 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2021-10-11 19:14:18 +03:00
|
|
|
|
|
|
|
export default class ChangeThemeController extends Controller {
|
2021-10-19 21:43:36 +03:00
|
|
|
@service router;
|
2021-10-12 12:18:55 +03:00
|
|
|
@service store;
|
2021-10-11 21:30:58 +03:00
|
|
|
@service themeManagement;
|
|
|
|
|
2021-10-12 12:18:55 +03:00
|
|
|
@tracked showAdvanced = false;
|
2021-10-19 21:43:36 +03:00
|
|
|
|
|
|
|
themes = this.store.peekAll('theme');
|
2021-10-12 12:18:55 +03:00
|
|
|
|
2021-10-18 15:02:28 +03:00
|
|
|
officialThemes = [{
|
2021-10-18 14:32:31 +03:00
|
|
|
name: 'Casper',
|
|
|
|
category: 'Blog',
|
|
|
|
previewUrl: 'https://casper.ghost.io/',
|
|
|
|
ref: 'default',
|
|
|
|
image: 'assets/img/themes/Casper.jpg'
|
|
|
|
}, {
|
2021-10-13 18:36:26 +03:00
|
|
|
name: 'Journal',
|
|
|
|
category: 'Newsletter',
|
|
|
|
url: 'https://github.com/TryGhost/Journal',
|
|
|
|
previewUrl: 'https://journal.ghost.io/',
|
|
|
|
ref: 'TryGhost/Journal',
|
|
|
|
image: 'assets/img/themes/Journal.png'
|
|
|
|
}, {
|
2021-10-11 19:14:18 +03:00
|
|
|
name: 'Edition',
|
|
|
|
category: 'Newsletter',
|
|
|
|
url: 'https://github.com/TryGhost/Edition',
|
2021-10-12 16:27:51 +03:00
|
|
|
previewUrl: 'https://edition.ghost.io/',
|
2021-10-11 19:14:18 +03:00
|
|
|
ref: 'TryGhost/Edition',
|
2021-10-13 18:36:26 +03:00
|
|
|
image: 'assets/img/themes/Edition.png'
|
|
|
|
}, {
|
|
|
|
name: 'Digest',
|
|
|
|
category: 'Newsletter',
|
|
|
|
url: 'https://github.com/TryGhost/Digest',
|
|
|
|
previewUrl: 'https://digest.ghost.io/',
|
|
|
|
ref: 'TryGhost/Digest',
|
|
|
|
image: 'assets/img/themes/Digest.png'
|
|
|
|
}, {
|
|
|
|
name: 'Bulletin',
|
|
|
|
category: 'Newsletter',
|
|
|
|
url: 'https://github.com/TryGhost/Bulletin',
|
|
|
|
previewUrl: 'https://bulletin.ghost.io/',
|
|
|
|
ref: 'TryGhost/Bulletin',
|
|
|
|
image: 'assets/img/themes/Bulletin.png'
|
|
|
|
}, {
|
|
|
|
name: 'Dawn',
|
|
|
|
category: 'Newsletter',
|
|
|
|
url: 'https://github.com/TryGhost/Dawn',
|
|
|
|
previewUrl: 'https://dawn.ghost.io/',
|
|
|
|
ref: 'TryGhost/Dawn',
|
|
|
|
image: 'assets/img/themes/Dawn.png'
|
2021-10-11 19:14:18 +03:00
|
|
|
}, {
|
|
|
|
name: 'Alto',
|
|
|
|
category: 'Blog',
|
|
|
|
url: 'https://github.com/TryGhost/Alto',
|
2021-10-12 16:27:51 +03:00
|
|
|
previewUrl: 'https://alto.ghost.io',
|
2021-10-11 19:14:18 +03:00
|
|
|
ref: 'TryGhost/Alto',
|
2021-10-13 18:36:26 +03:00
|
|
|
image: 'assets/img/themes/Alto.png'
|
2021-10-11 19:14:18 +03:00
|
|
|
}, {
|
2021-10-13 18:36:26 +03:00
|
|
|
name: 'Edge',
|
2021-10-11 19:14:18 +03:00
|
|
|
category: 'Photography',
|
2021-10-13 18:36:26 +03:00
|
|
|
url: 'https://github.com/TryGhost/Edge',
|
|
|
|
previewUrl: 'https://edge.ghost.io',
|
|
|
|
ref: 'TryGhost/Edge',
|
|
|
|
image: 'assets/img/themes/Edge.png'
|
2021-10-11 19:14:18 +03:00
|
|
|
}, {
|
|
|
|
name: 'Ease',
|
|
|
|
category: 'Documentation',
|
|
|
|
url: 'https://github.com/TryGhost/Ease',
|
2021-10-12 16:27:51 +03:00
|
|
|
previewUrl: 'https://ease.ghost.io',
|
2021-10-11 19:14:18 +03:00
|
|
|
ref: 'TryGhost/Ease',
|
2021-10-13 18:36:26 +03:00
|
|
|
image: 'assets/img/themes/Ease.png'
|
|
|
|
}, {
|
|
|
|
name: 'Ruby',
|
|
|
|
category: 'Magazine',
|
|
|
|
url: 'https://github.com/TryGhost/Ruby',
|
|
|
|
previewUrl: 'https://ruby.ghost.io',
|
|
|
|
ref: 'TryGhost/Ruby',
|
|
|
|
image: 'assets/img/themes/Ruby.png'
|
|
|
|
}, {
|
|
|
|
name: 'Dope',
|
|
|
|
category: 'Magazine',
|
|
|
|
url: 'https://github.com/TryGhost/Dope',
|
|
|
|
previewUrl: 'https://dope.ghost.io',
|
|
|
|
ref: 'TryGhost/Dope',
|
|
|
|
image: 'assets/img/themes/Dope.png'
|
|
|
|
}, {
|
|
|
|
name: 'Wave',
|
|
|
|
category: 'Podcast',
|
|
|
|
url: 'https://github.com/TryGhost/Wave',
|
|
|
|
previewUrl: 'https://wave.ghost.io',
|
|
|
|
ref: 'TryGhost/Wave',
|
|
|
|
image: 'assets/img/themes/Wave.png'
|
|
|
|
}, {
|
|
|
|
name: 'London',
|
|
|
|
category: 'Photography',
|
|
|
|
url: 'https://github.com/TryGhost/London',
|
|
|
|
previewUrl: 'https://london.ghost.io',
|
|
|
|
ref: 'TryGhost/London',
|
|
|
|
image: 'assets/img/themes/London.jpg'
|
2021-10-11 19:14:18 +03:00
|
|
|
}]
|
2021-10-12 12:18:55 +03:00
|
|
|
|
2021-10-18 15:02:28 +03:00
|
|
|
get themesList() {
|
|
|
|
const activeTheme = this.themes.findBy('active', true);
|
|
|
|
|
|
|
|
// decorate themes based on current usage
|
|
|
|
let themesList = this.officialThemes.map((theme) => {
|
|
|
|
const decoratedTheme = Object.assign({}, theme);
|
|
|
|
|
|
|
|
if (theme.ref === 'default') {
|
|
|
|
decoratedTheme.isDefault = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (theme.name.toLowerCase() === activeTheme.name) {
|
|
|
|
decoratedTheme.isActive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return decoratedTheme;
|
|
|
|
});
|
|
|
|
|
|
|
|
// move default themes to the beginning of the list
|
|
|
|
themesList.sort((a, b) => {
|
|
|
|
if (b.isDefault) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
// ensure active theme is always first
|
|
|
|
const activeThemeInList = themesList.find(theme => theme.isActive);
|
|
|
|
const activeThemeIndex = themesList.indexOf(activeThemeInList);
|
|
|
|
if (activeThemeIndex > 0) {
|
|
|
|
themesList.splice(activeThemeIndex, 1);
|
|
|
|
themesList.unshift(activeThemeInList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return themesList;
|
|
|
|
}
|
|
|
|
|
2021-10-19 21:43:36 +03:00
|
|
|
@action
|
|
|
|
startThemeUpload(event) {
|
|
|
|
event?.preventDefault();
|
|
|
|
|
|
|
|
this.themeManagement.upload({
|
|
|
|
onActivationSuccess: () => {
|
|
|
|
this.router.transitionTo('settings.design');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-12 12:18:55 +03:00
|
|
|
@action
|
2021-10-18 15:19:30 +03:00
|
|
|
toggleAdvanced(event) {
|
2021-10-12 12:18:55 +03:00
|
|
|
this.showAdvanced = !this.showAdvanced;
|
2021-10-18 15:19:30 +03:00
|
|
|
|
|
|
|
if (this.showAdvanced) {
|
|
|
|
const mainContainer = event?.target.closest('.gh-main');
|
|
|
|
|
|
|
|
if (mainContainer) {
|
|
|
|
mainContainer.scrollTop = 0;
|
|
|
|
}
|
|
|
|
}
|
2021-10-12 12:18:55 +03:00
|
|
|
}
|
2021-10-20 22:54:05 +03:00
|
|
|
|
|
|
|
reset() {
|
|
|
|
this.showAdvanced = false;
|
|
|
|
}
|
2021-10-11 19:14:18 +03:00
|
|
|
}
|