<commit_before>import Ember from 'ember';
import AuthenticatedRoute from 'ghost/routes/authenticated';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
import PaginationRoute from 'ghost/mixins/pagination-route';

export default AuthenticatedRoute.extend(CurrentUserSettings, PaginationRoute, ShortcutsRoute, {
    titleToken: 'Settings - Tags',

    paginationModel: 'tag',
    paginationSettings: {
        include: 'count.posts',
        limit: 15
    },

    shortcuts: {
        'up, k': 'moveUp',
        'down, j': 'moveDown',
        left: 'focusList',
        right: 'focusContent',
        c: 'newTag'
    },

    beforeModel() {
        this._super(...arguments);

        return this.get('session.user')
            .then(this.transitionAuthor());
    },

    model() {
        this.store.unloadAll('tag');

        return this.loadFirstPage().then(() => {
            return this.store.filter('tag', (tag) => {
                return !tag.get('isNew');
            });
        });
    },

    deactivate() {
        this._super(...arguments);
        this.send('resetPagination');
    },

    stepThroughTags(step) {
        let currentTag = this.modelFor('settings.tags.tag');
        let tags = this.get('controller.tags');
        let length = tags.get('length');

        if (currentTag && length) {
            let newPosition = tags.indexOf(currentTag) + step;

            if (newPosition >= length) {
                return;
            } else if (newPosition < 0) {
                return;
            }

            this.transitionTo('settings.tags.tag', tags.objectAt(newPosition));
        }
    },

    scrollContent(amount) {
        let content = Ember.$('.tag-settings-pane');
        let scrolled = content.scrollTop();

        content.scrollTop(scrolled + 50 * amount);
    },

    actions: {
        moveUp() {
            if (this.controller.get('tagContentFocused')) {
                this.scrollContent(-1);
            } else {
                this.stepThroughTags(-1);
            }
        },

        moveDown() {
            if (this.controller.get('tagContentFocused')) {
                this.scrollContent(1);
            } else {
                this.stepThroughTags(1);
            }
        },

        focusList() {
            this.set('controller.keyboardFocus', 'tagList');
        },

        focusContent() {
            this.set('controller.keyboardFocus', 'tagContent');
        },

        newTag() {
            this.transitionTo('settings.tags.new');
        }
    }
});<commit_msg>Reset shortcuts scope when leaving tags route<commit_after>/* global key */
import Ember from 'ember';
import AuthenticatedRoute from 'ghost/routes/authenticated';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
import PaginationRoute from 'ghost/mixins/pagination-route';

export default AuthenticatedRoute.extend(CurrentUserSettings, PaginationRoute, ShortcutsRoute, {
    titleToken: 'Settings - Tags',

    paginationModel: 'tag',
    paginationSettings: {
        include: 'count.posts',
        limit: 15
    },

    shortcuts: {
        'up, k': 'moveUp',
        'down, j': 'moveDown',
        left: 'focusList',
        right: 'focusContent',
        c: 'newTag'
    },

    beforeModel() {
        this._super(...arguments);

        return this.get('session.user')
            .then(this.transitionAuthor());
    },

    model() {
        this.store.unloadAll('tag');

        return this.loadFirstPage().then(() => {
            return this.store.filter('tag', (tag) => {
                return !tag.get('isNew');
            });
        });
    },

    deactivate() {
        this._super(...arguments);
        this.send('resetShortcutsScope');
        this.send('resetPagination');
    },

    stepThroughTags(step) {
        let currentTag = this.modelFor('settings.tags.tag');
        let tags = this.get('controller.tags');
        let length = tags.get('length');

        if (currentTag && length) {
            let newPosition = tags.indexOf(currentTag) + step;

            if (newPosition >= length) {
                return;
            } else if (newPosition < 0) {
                return;
            }

            this.transitionTo('settings.tags.tag', tags.objectAt(newPosition));
        }
    },

    scrollContent(amount) {
        let content = Ember.$('.tag-settings-pane');
        let scrolled = content.scrollTop();

        content.scrollTop(scrolled + 50 * amount);
    },

    actions: {
        moveUp() {
            if (this.controller.get('tagContentFocused')) {
                this.scrollContent(-1);
            } else {
                this.stepThroughTags(-1);
            }
        },

        moveDown() {
            if (this.controller.get('tagContentFocused')) {
                this.scrollContent(1);
            } else {
                this.stepThroughTags(1);
            }
        },

        focusList() {
            this.set('controller.keyboardFocus', 'tagList');
        },

        focusContent() {
            this.set('controller.keyboardFocus', 'tagContent');
        },

        newTag() {
            this.transitionTo('settings.tags.new');
        },

        resetShortcutsScope() {
            key.setScope('default');
        }
    }
});
{'fraction_non_alphanumeric': 0.13918669131238448, 'fraction_numerical': 0.0033271719038817007, 'mean_word_length': 1.864478560084701, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '1773408', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1479, 'n_words': 260}