<commit_before>/* eslint-disable ghost/ember/alias-model-in-controller */
import Controller from '@ember/controller';
import {computed} from '@ember/object';
import {isEmpty} from '@ember/utils';
import {isThemeValidationError} from 'ghost-admin/services/ajax';
import {notEmpty} from '@ember/object/computed';
import {inject as service} from '@ember/service';

export const MARKETPLACE_THEMES = [{
    name: 'Edition',
    category: 'Newsletter',
    url: 'https://github.com/TryGhost/Edition',
    previewUrl: 'https://ghost.org/themes/edition',
    ref: 'TryGhost/Edition',
    image: 'assets/img/themes/Edition.jpg',
    shortImage: 'assets/img/themes/Edition-cut.jpg'
}, {
    name: 'Alto',
    category: 'Blog',
    url: 'https://github.com/TryGhost/Alto',
    previewUrl: 'https://ghost.org/themes/alto',
    ref: 'TryGhost/Alto',
    image: 'assets/img/themes/Alto.jpg',
    shortImage: 'assets/img/themes/Alto-cut.jpg'
}, {
    name: 'London',
    category: 'Photography',
    url: 'https://github.com/TryGhost/London',
    previewUrl: 'https://ghost.org/themes/london',
    ref: 'TryGhost/London',
    image: 'assets/img/themes/London.jpg',
    shortImage: 'assets/img/themes/London-cut.jpg'
}, {
    name: 'Ease',
    category: 'Documentation',
    url: 'https://github.com/TryGhost/Ease',
    previewUrl: 'https://ghost.org/themes/ease',
    ref: 'TryGhost/Ease',
    image: 'assets/img/themes/Ease.jpg',
    shortImage: 'assets/img/themes/Ease-cut.jpg'
}];

export default Controller.extend({
    config: service(),
    ghostPaths: service(),
    limit: service(),
    notifications: service(),
    session: service(),
    settings: service(),
    utils: service(),

    dirtyAttributes: false,
    newNavItem: null,
    newSecondaryNavItem: null,
    themes: null,
    themeToDelete: null,
    displayUpgradeModal: false,
    limitErrorMessage: null,

    init() {
        this._super(...arguments);
        this.marketplaceThemes = MARKETPLACE_THEMES;
    },

    showDeleteThemeModal: notEmpty('themeToDelete'),

    blogUrl: computed('config.blogUrl', function () {
        let url = this.get('config.blogUrl');

        return url.slice(-1) !== '/' ? `${url}/` : url;
    }),

    actions: {
        async activateTheme(theme) {
            const isOverLimit = await this.limit.checkWouldGoOverLimit('customThemes', {value: theme.name});
            if (isOverLimit) {
                try {
                    await this.limit.limiter.errorIfWouldGoOverLimit('customThemes', {value: theme.name});
                    this.limitErrorMessage = null;
                } catch (error) {
                    if (error.errorType !== 'HostLimitError') {
                        throw error;
                    }

                    this.limitErrorMessage = error.message;
                }

                this.set('displayUpgradeModal', true);
                return;
            }
            return theme.activate().then((activatedTheme) => {
                if (!isEmpty(activatedTheme.get('warnings'))) {
                    this.set('themeWarnings', activatedTheme.get('warnings'));
                    this.set('showThemeWarningsModal', true);
                }

                if (!isEmpty(activatedTheme.get('errors'))) {
                    this.set('themeErrors', activatedTheme.get('errors'));
                    this.set('showThemeWarningsModal', true);
                }
            }).catch((error) => {<commit_msg>Removed unused blogUrl CP from theme controller<commit_after>/* eslint-disable ghost/ember/alias-model-in-controller */
import Controller from '@ember/controller';
import {isEmpty} from '@ember/utils';
import {isThemeValidationError} from 'ghost-admin/services/ajax';
import {notEmpty} from '@ember/object/computed';
import {inject as service} from '@ember/service';

export const MARKETPLACE_THEMES = [{
    name: 'Edition',
    category: 'Newsletter',
    url: 'https://github.com/TryGhost/Edition',
    previewUrl: 'https://ghost.org/themes/edition',
    ref: 'TryGhost/Edition',
    image: 'assets/img/themes/Edition.jpg',
    shortImage: 'assets/img/themes/Edition-cut.jpg'
}, {
    name: 'Alto',
    category: 'Blog',
    url: 'https://github.com/TryGhost/Alto',
    previewUrl: 'https://ghost.org/themes/alto',
    ref: 'TryGhost/Alto',
    image: 'assets/img/themes/Alto.jpg',
    shortImage: 'assets/img/themes/Alto-cut.jpg'
}, {
    name: 'London',
    category: 'Photography',
    url: 'https://github.com/TryGhost/London',
    previewUrl: 'https://ghost.org/themes/london',
    ref: 'TryGhost/London',
    image: 'assets/img/themes/London.jpg',
    shortImage: 'assets/img/themes/London-cut.jpg'
}, {
    name: 'Ease',
    category: 'Documentation',
    url: 'https://github.com/TryGhost/Ease',
    previewUrl: 'https://ghost.org/themes/ease',
    ref: 'TryGhost/Ease',
    image: 'assets/img/themes/Ease.jpg',
    shortImage: 'assets/img/themes/Ease-cut.jpg'
}];

export default Controller.extend({
    config: service(),
    ghostPaths: service(),
    limit: service(),
    notifications: service(),
    session: service(),
    settings: service(),
    utils: service(),

    dirtyAttributes: false,
    newNavItem: null,
    newSecondaryNavItem: null,
    themes: null,
    themeToDelete: null,
    displayUpgradeModal: false,
    limitErrorMessage: null,

    init() {
        this._super(...arguments);
        this.marketplaceThemes = MARKETPLACE_THEMES;
    },

    showDeleteThemeModal: notEmpty('themeToDelete'),

    actions: {
        async activateTheme(theme) {
            const isOverLimit = await this.limit.checkWouldGoOverLimit('customThemes', {value: theme.name});
            if (isOverLimit) {
                try {
                    await this.limit.limiter.errorIfWouldGoOverLimit('customThemes', {value: theme.name});
                    this.limitErrorMessage = null;
                } catch (error) {
                    if (error.errorType !== 'HostLimitError') {
                        throw error;
                    }

                    this.limitErrorMessage = error.message;
                }

                this.set('displayUpgradeModal', true);
                return;
            }
            return theme.activate().then((activatedTheme) => {
                if (!isEmpty(activatedTheme.get('warnings'))) {
                    this.set('themeWarnings', activatedTheme.get('warnings'));
                    this.set('showThemeWarningsModal', true);
                }

                if (!isEmpty(activatedTheme.get('errors'))) {
                    this.set('themeErrors', activatedTheme.get('errors'));
                    this.set('showThemeWarningsModal', true);
                }
            }).catch((error) => {
{'fraction_non_alphanumeric': 0.14761904761904762, 'fraction_numerical': 0.00014880952380952382, 'mean_word_length': 2.423841059602649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7548981', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1969, 'n_words': 352}