mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
85d7932e45
refs https://github.com/TryGhost/Team/issues/559
refs 054a5f15f5
- with the update of `ember-promise-modals` we started to get deprecation warnings when using `modals.open('modal-component-name')`
- upcoming Ember build updates will introduce tree shaking but using run-time lookup of modal components by name works against that because it's not statically analysable
- switched to importing components and passing the component class directly, eg. `modals.open(ModalComponent)`
- standardized modal component class names with a `MyModal` style to get better behaviour in code editors when it auto generates imports
- dropped the modal defaults from the modals service because we can now use a static `modalOptions` property on the modal components themselves when we want to override the defaults
100 lines
3.0 KiB
JavaScript
100 lines
3.0 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import ConfirmDeleteThemeModal from './modals/design/confirm-delete-theme';
|
|
import {action, get} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default class GhThemeTableComponent extends Component {
|
|
@service ghostPaths;
|
|
@service modals;
|
|
@service themeManagement;
|
|
@service utils;
|
|
|
|
activateTaskInstance = null;
|
|
confirmDeleteModal = null;
|
|
|
|
willDestroy() {
|
|
super.willDestroy(...arguments);
|
|
this.confirmDeleteModal?.close?.();
|
|
this.activateTaskInstance?.cancel();
|
|
}
|
|
|
|
get sortedThemes() {
|
|
let themes = this.args.themes.map((t) => {
|
|
let theme = {};
|
|
let themePackage = get(t, 'package');
|
|
|
|
theme.model = t;
|
|
theme.name = get(t, 'name');
|
|
theme.label = themePackage ? `${themePackage.name}` : theme.name;
|
|
theme.version = themePackage ? `${themePackage.version}` : '1.0';
|
|
theme.package = themePackage;
|
|
theme.active = get(t, 'active');
|
|
theme.isDeletable = !theme.active;
|
|
|
|
return theme;
|
|
});
|
|
let duplicateThemes = [];
|
|
|
|
themes.forEach((theme) => {
|
|
let duplicateLabels = themes.filterBy('label', theme.label);
|
|
|
|
if (duplicateLabels.length > 1) {
|
|
duplicateThemes.pushObject(theme);
|
|
}
|
|
});
|
|
|
|
duplicateThemes.forEach((theme) => {
|
|
if (theme.name !== 'casper') {
|
|
theme.label = `${theme.label} (${theme.name})`;
|
|
}
|
|
});
|
|
|
|
// "(default)" needs to be added to casper manually as it's always
|
|
// displayed and would mess up the duplicate checking if added earlier
|
|
let casper = themes.findBy('name', 'casper');
|
|
if (casper) {
|
|
casper.label = `${casper.label} (default)`;
|
|
casper.isDefault = true;
|
|
casper.isDeletable = false;
|
|
}
|
|
|
|
// sorting manually because .sortBy('label') has a different sorting
|
|
// algorithm to [...strings].sort()
|
|
return themes.sort((themeA, themeB) => {
|
|
let a = themeA.label.toLowerCase();
|
|
let b = themeB.label.toLowerCase();
|
|
|
|
if (a < b) {
|
|
return -1;
|
|
}
|
|
if (a > b) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
}
|
|
|
|
@action
|
|
downloadTheme(themeName, dropdown) {
|
|
dropdown?.actions.close();
|
|
this.utils.downloadFile(`${this.ghostPaths.apiRoot}/themes/${themeName}/download/`);
|
|
}
|
|
|
|
@action
|
|
activateTheme(theme, dropdown) {
|
|
dropdown?.actions.close();
|
|
this.activateTaskInstance = this.themeManagement.activateTask.perform(theme);
|
|
}
|
|
|
|
@action
|
|
deleteTheme(theme, dropdown) {
|
|
dropdown?.actions.close();
|
|
|
|
this.confirmDeleteModal = this.modals.open(ConfirmDeleteThemeModal, {
|
|
theme
|
|
}).finally(() => {
|
|
this.confirmDeleteModal = null;
|
|
});
|
|
}
|
|
}
|