0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Refactored navigation controller to Octane patterns

refs https://github.com/TryGhost/Ghost/issues/14101

- migrated to native class syntax
- removed use of jQuery that was long out of date and not necessary
This commit is contained in:
Kevin Ansfield 2022-10-06 16:51:58 +01:00
parent fab7a82185
commit ea05b30380
3 changed files with 43 additions and 41 deletions

View file

@ -955,3 +955,17 @@ remove|ember-template-lint|no-passed-in-event-handlers|20|28|20|28|1591adfb7d0db
remove|ember-template-lint|no-passed-in-event-handlers|93|28|93|28|55dadf0e7dc5e2ed57771f46ca3cb82607d1799c|1665014400000|1675386000000|1680566400000|app/components/settings/members/stripe-settings-form.hbs
remove|ember-template-lint|no-action|5|18|5|18|7c796afb78a976ab2411eab292c02c4250e429c7|1662681600000|1673053200000|1678237200000|app/components/gh-date-time-picker.hbs
add|ember-template-lint|no-action|5|18|5|18|0c80a75b2a80d404755333991c266c81c97c9cda|1665100800000|1675472400000|1680652800000|app/components/gh-date-time-picker.hbs
remove|ember-template-lint|no-action|24|45|24|45|812038f28c7626209e8ae622703ea8c4e75b7f60|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|25|48|25|48|930d7fb74c5abe804a6b02736914e835c1b25777|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|26|47|26|47|3c723798059c71aedfa95cd70507bc0308728544|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|27|49|27|49|115cc8adc4c0f98e2d93a59ff8efbee711541336|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|35|33|35|33|812038f28c7626209e8ae622703ea8c4e75b7f60|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|36|35|36|35|3c723798059c71aedfa95cd70507bc0308728544|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|37|37|37|37|115cc8adc4c0f98e2d93a59ff8efbee711541336|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|53|45|53|45|812038f28c7626209e8ae622703ea8c4e75b7f60|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|54|48|54|48|930d7fb74c5abe804a6b02736914e835c1b25777|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|55|47|55|47|3c723798059c71aedfa95cd70507bc0308728544|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|56|49|56|49|115cc8adc4c0f98e2d93a59ff8efbee711541336|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|64|33|64|33|812038f28c7626209e8ae622703ea8c4e75b7f60|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|65|35|65|35|3c723798059c71aedfa95cd70507bc0308728544|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs
remove|ember-template-lint|no-action|66|37|66|37|115cc8adc4c0f98e2d93a59ff8efbee711541336|1662681600000|1673053200000|1678237200000|app/templates/settings/navigation.hbs

View file

@ -1,14 +1,11 @@
import classic from 'ember-classic-decorator';
import {action, computed} from '@ember/object';
import {inject as service} from '@ember/service';
/* eslint-disable ghost/ember/alias-model-in-controller */
import $ from 'jquery';
import Controller from '@ember/controller';
import NavigationItem from 'ghost-admin/models/navigation-item';
import RSVP from 'rsvp';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
import {tracked} from '@glimmer/tracking';
@classic
export default class NavigationController extends Controller {
@service config;
@service ghostPaths;
@ -16,17 +13,10 @@ export default class NavigationController extends Controller {
@service session;
@service settings;
dirtyAttributes = false;
newNavItem = null;
newSecondaryNavItem = null;
@tracked dirtyAttributes = false;
@tracked newNavItem = NavigationItem.create({isNew: true});
@tracked newSecondaryNavItem = NavigationItem.create({isNew: true, isSecondary: true});
init() {
super.init(...arguments);
this.set('newNavItem', NavigationItem.create({isNew: true}));
this.set('newSecondaryNavItem', NavigationItem.create({isNew: true, isSecondary: true}));
}
@computed('config.blogUrl')
get blogUrl() {
let url = this.config.blogUrl;
@ -59,7 +49,7 @@ export default class NavigationController extends Controller {
let navItems = item.isSecondary ? this.settings.secondaryNavigation : this.settings.navigation;
navItems.removeObject(item);
this.set('dirtyAttributes', true);
this.dirtyAttributes = true;
}
@action
@ -70,7 +60,7 @@ export default class NavigationController extends Controller {
if (navItem.get('label') !== label) {
navItem.set('label', label);
this.set('dirtyAttributes', true);
this.dirtyAttributes = true;
}
}
@ -82,7 +72,7 @@ export default class NavigationController extends Controller {
if (navItem.get('url') !== url) {
navItem.set('url', url);
this.set('dirtyAttributes', true);
this.dirtyAttributes = true;
}
return url;
@ -90,8 +80,8 @@ export default class NavigationController extends Controller {
@action
reset() {
this.set('newNavItem', NavigationItem.create({isNew: true}));
this.set('newSecondaryNavItem', NavigationItem.create({isNew: true, isSecondary: true}));
this.newNavItem = NavigationItem.create({isNew: true});
this.newSecondaryNavItem = NavigationItem.create({isNew: true, isSecondary: true});
}
addNewNavItem(item) {
@ -99,14 +89,12 @@ export default class NavigationController extends Controller {
item.set('isNew', false);
navItems.pushObject(item);
this.set('dirtyAttributes', true);
this.dirtyAttributes = true;
if (item.isSecondary) {
this.set('newSecondaryNavItem', NavigationItem.create({isNew: true, isSecondary: true}));
$('.gh-blognav-container:last .gh-blognav-line:last input:first').focus();
this.newSecondaryNavItem = NavigationItem.create({isNew: true, isSecondary: true});
} else {
this.set('newNavItem', NavigationItem.create({isNew: true}));
$('.gh-blognav-container:first .gh-blognav-line:last input:first').focus();
this.newNavItem = NavigationItem.create({isNew: true});
}
}
@ -136,7 +124,7 @@ export default class NavigationController extends Controller {
try {
yield RSVP.all(validationPromises);
this.set('dirtyAttributes', false);
this.dirtyAttributes = false;
return yield this.settings.save();
} catch (error) {
if (error) {

View file

@ -27,10 +27,10 @@
<GhNavitem
@navItem={{navItem}}
@baseUrl={{this.blogUrl}}
@addItem={{action "addNavItem"}}
@deleteItem={{action "deleteNavItem"}}
@updateUrl={{action "updateUrl"}}
@updateLabel={{action "updateLabel"}}
@addItem={{this.addNavItem}}
@deleteItem={{this.deleteNavItem}}
@updateUrl={{this.updateUrl}}
@updateLabel={{this.updateLabel}}
data-test-navitem={{index}} />
</DraggableObject>
{{/each}}
@ -38,9 +38,9 @@
<GhNavitem
@navItem={{this.newNavItem}}
@baseUrl={{this.blogUrl}}
@addItem={{action "addNavItem"}}
@updateUrl={{action "updateUrl"}}
@updateLabel={{action "updateLabel"}}
@addItem={{this.addNavItem}}
@updateUrl={{this.updateUrl}}
@updateLabel={{this.updateLabel}}
data-test-navitem="new" />
</form>
</div>
@ -56,10 +56,10 @@
<GhNavitem
@navItem={{navItem}}
@baseUrl={{this.blogUrl}}
@addItem={{action "addNavItem"}}
@deleteItem={{action "deleteNavItem"}}
@updateUrl={{action "updateUrl"}}
@updateLabel={{action "updateLabel"}}
@addItem={{this.addNavItem}}
@deleteItem={{this.deleteNavItem}}
@updateUrl={{this.updateUrl}}
@updateLabel={{this.updateLabel}}
data-test-navitem={{index}} />
</DraggableObject>
{{/each}}
@ -67,9 +67,9 @@
<GhNavitem
@navItem={{this.newSecondaryNavItem}}
@baseUrl={{this.blogUrl}}
@addItem={{action "addNavItem"}}
@updateUrl={{action "updateUrl"}}
@updateLabel={{action "updateLabel"}}
@addItem={{this.addNavItem}}
@updateUrl={{this.updateUrl}}
@updateLabel={{this.updateLabel}}
data-test-navitem="new" />
</form>
</div>