mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 03:42:27 +03:00
[chore] runs native classes codemod for app/adapters (#2239)
no issue * ran native classes codemod for app/adapters * migrated slug-url mixin to a utility
This commit is contained in:
parent
5e7c98fb46
commit
fdc24103cc
@ -1,10 +1,11 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend({
|
||||
|
||||
@classic
|
||||
export default class ApiKey extends ApplicationAdapter {
|
||||
queryRecord(store, type, query) {
|
||||
if (!query || query.id !== 'me') {
|
||||
return this._super(...arguments);
|
||||
return super.queryRecord(...arguments);
|
||||
}
|
||||
|
||||
let url = `${this.buildURL('users', 'me')}token/`;
|
||||
@ -12,5 +13,4 @@ export default ApplicationAdapter.extend({
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import EmbeddedRelationAdapter from 'ghost-admin/adapters/embedded-relation-adapter';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default EmbeddedRelationAdapter.extend({
|
||||
|
||||
@classic
|
||||
export default class Application extends EmbeddedRelationAdapter {
|
||||
shouldBackgroundReloadRecord() {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend({
|
||||
|
||||
@classic
|
||||
export default class Email extends ApplicationAdapter {
|
||||
retry(model) {
|
||||
let url = `${this.buildURL('email', model.get('id'))}retry/`;
|
||||
|
||||
@ -10,5 +11,4 @@ export default ApplicationAdapter.extend({
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import BaseAdapter from 'ghost-admin/adapters/base';
|
||||
import classic from 'ember-classic-decorator';
|
||||
import {get} from '@ember/object';
|
||||
import {isNone} from '@ember/utils';
|
||||
import {underscore} from '@ember/string';
|
||||
@ -13,14 +14,15 @@ import {underscore} from '@ember/string';
|
||||
// If a model has an embedded hasMany relation, the related type will be included:
|
||||
// roles: DS.hasMany('role', { embedded: 'always' }) => ?include=roles
|
||||
|
||||
export default BaseAdapter.extend({
|
||||
@classic
|
||||
export default class EmbeddedRelationAdapter extends BaseAdapter {
|
||||
find(store, type, id, snapshot) {
|
||||
return this.ajax(this.buildIncludeURL(store, type.modelName, id, snapshot, 'find'), 'GET');
|
||||
},
|
||||
}
|
||||
|
||||
findRecord(store, type, id, snapshot) {
|
||||
return this.ajax(this.buildIncludeURL(store, type.modelName, id, snapshot, 'findRecord'), 'GET');
|
||||
},
|
||||
}
|
||||
|
||||
findAll(store, type, sinceToken) {
|
||||
let query, url;
|
||||
@ -32,19 +34,19 @@ export default BaseAdapter.extend({
|
||||
url = this.buildIncludeURL(store, type.modelName, null, null, 'findAll');
|
||||
|
||||
return this.ajax(url, 'GET', {data: query});
|
||||
},
|
||||
}
|
||||
|
||||
query(store, type, query) {
|
||||
return this._super(store, type, this.buildQuery(store, type.modelName, query));
|
||||
},
|
||||
return super.query(store, type, this.buildQuery(store, type.modelName, query));
|
||||
}
|
||||
|
||||
queryRecord(store, type, query) {
|
||||
return this._super(store, type, this.buildQuery(store, type.modelName, query));
|
||||
},
|
||||
return super.queryRecord(store, type, this.buildQuery(store, type.modelName, query));
|
||||
}
|
||||
|
||||
createRecord(store, type, snapshot) {
|
||||
return this.saveRecord(store, type, snapshot, {method: 'POST'}, 'createRecord');
|
||||
},
|
||||
}
|
||||
|
||||
updateRecord(store, type, snapshot) {
|
||||
let options = {
|
||||
@ -53,7 +55,7 @@ export default BaseAdapter.extend({
|
||||
};
|
||||
|
||||
return this.saveRecord(store, type, snapshot, options, 'updateRecord');
|
||||
},
|
||||
}
|
||||
|
||||
saveRecord(store, type, snapshot, options, requestType) {
|
||||
let _options = options || {};
|
||||
@ -61,7 +63,7 @@ export default BaseAdapter.extend({
|
||||
let payload = this.preparePayload(store, type, snapshot);
|
||||
|
||||
return this.ajax(url, _options.method, payload);
|
||||
},
|
||||
}
|
||||
|
||||
preparePayload(store, type, snapshot) {
|
||||
let serializer = store.serializerFor(type.modelName);
|
||||
@ -70,7 +72,7 @@ export default BaseAdapter.extend({
|
||||
serializer.serializeIntoHash(payload, type, snapshot);
|
||||
|
||||
return {data: payload};
|
||||
},
|
||||
}
|
||||
|
||||
buildIncludeURL(store, modelName, id, snapshot, requestType, query) {
|
||||
let includes = this.getEmbeddedRelations(store, modelName);
|
||||
@ -82,7 +84,7 @@ export default BaseAdapter.extend({
|
||||
}
|
||||
|
||||
return parsedUrl.toString();
|
||||
},
|
||||
}
|
||||
|
||||
buildQuery(store, modelName, options) {
|
||||
let deDupe = {};
|
||||
@ -112,7 +114,7 @@ export default BaseAdapter.extend({
|
||||
}
|
||||
|
||||
return query;
|
||||
},
|
||||
}
|
||||
|
||||
getEmbeddedRelations(store, modelName) {
|
||||
let model = store.modelFor(modelName);
|
||||
@ -140,4 +142,4 @@ export default BaseAdapter.extend({
|
||||
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,4 +1,12 @@
|
||||
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
||||
import SlugUrl from 'ghost-admin/mixins/slug-url';
|
||||
import SlugUrl from 'ghost-admin/utils/slug-url';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend(SlugUrl);
|
||||
@classic
|
||||
export default class Label extends ApplicationAdapter {
|
||||
buildURL(_modelName, _id, _snapshot, _requestType, query) {
|
||||
let url = super.buildURL(...arguments);
|
||||
|
||||
return SlugUrl(url, query);
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend({
|
||||
@classic
|
||||
export default class Member extends ApplicationAdapter {
|
||||
queryRecord(store, type, query) {
|
||||
if (query && query.id) {
|
||||
let {id} = query;
|
||||
@ -9,11 +11,11 @@ export default ApplicationAdapter.extend({
|
||||
return this.ajax(url, 'GET', {data: query});
|
||||
}
|
||||
|
||||
return this._super(...arguments);
|
||||
},
|
||||
return super.queryRecord(...arguments);
|
||||
}
|
||||
|
||||
urlForDeleteRecord(id, modelName, snapshot) {
|
||||
let url = this._super(...arguments);
|
||||
let url = super.urlForDeleteRecord(...arguments);
|
||||
let parsedUrl = new URL(url);
|
||||
|
||||
if (snapshot && snapshot.adapterOptions && snapshot.adapterOptions.cancel) {
|
||||
@ -22,4 +24,4 @@ export default ApplicationAdapter.extend({
|
||||
|
||||
return parsedUrl.toString();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend({
|
||||
@classic
|
||||
export default class Offer extends ApplicationAdapter {
|
||||
queryRecord(store, type, query) {
|
||||
if (query && query.id) {
|
||||
let {id} = query;
|
||||
@ -9,13 +11,13 @@ export default ApplicationAdapter.extend({
|
||||
return this.ajax(url, 'GET', {data: query});
|
||||
}
|
||||
|
||||
return this._super(...arguments);
|
||||
},
|
||||
return super.queryRecord(...arguments);
|
||||
}
|
||||
|
||||
urlForDeleteRecord() {
|
||||
let url = this._super(...arguments);
|
||||
let url = super.urlForDeleteRecord(...arguments);
|
||||
let parsedUrl = new URL(url);
|
||||
|
||||
return parsedUrl.toString();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend({
|
||||
@classic
|
||||
export default class Page extends ApplicationAdapter {
|
||||
// posts and pages now include everything by default
|
||||
buildIncludeURL(store, modelName, id, snapshot, requestType, query) {
|
||||
return this.buildURL(modelName, id, snapshot, requestType, query);
|
||||
},
|
||||
}
|
||||
|
||||
buildQuery(store, modelName, options) {
|
||||
return options;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend({
|
||||
@classic
|
||||
export default class Post extends ApplicationAdapter {
|
||||
// posts and pages now include everything by default
|
||||
buildIncludeURL(store, modelName, id, snapshot, requestType, query) {
|
||||
let url = this.buildURL(modelName, id, snapshot, requestType, query);
|
||||
@ -17,9 +19,9 @@ export default ApplicationAdapter.extend({
|
||||
}
|
||||
|
||||
return parsedUrl.toString();
|
||||
},
|
||||
}
|
||||
|
||||
buildQuery(store, modelName, options) {
|
||||
return options;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend({
|
||||
@classic
|
||||
export default class Product extends ApplicationAdapter {
|
||||
queryRecord(store, type, query) {
|
||||
if (query && query.id) {
|
||||
let {id} = query;
|
||||
@ -9,13 +11,13 @@ export default ApplicationAdapter.extend({
|
||||
return this.ajax(url, 'GET', {data: query});
|
||||
}
|
||||
|
||||
return this._super(...arguments);
|
||||
},
|
||||
return super.queryRecord(...arguments);
|
||||
}
|
||||
|
||||
urlForDeleteRecord() {
|
||||
let url = this._super(...arguments);
|
||||
let url = super.urlForDeleteRecord(...arguments);
|
||||
let parsedUrl = new URL(url);
|
||||
|
||||
return parsedUrl.toString();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend({
|
||||
@classic
|
||||
export default class Setting extends ApplicationAdapter {
|
||||
updateRecord(store, type, record) {
|
||||
let data = {};
|
||||
let serializer = store.serializerFor(type.modelName);
|
||||
@ -16,4 +18,4 @@ export default ApplicationAdapter.extend({
|
||||
// pass in an id.
|
||||
return this.ajax(this.buildURL(type.modelName), 'PUT', {data});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,4 +1,12 @@
|
||||
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
||||
import SlugUrl from 'ghost-admin/mixins/slug-url';
|
||||
import SlugUrl from 'ghost-admin/utils/slug-url';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend(SlugUrl);
|
||||
@classic
|
||||
export default class Tag extends ApplicationAdapter {
|
||||
buildURL(_modelName, _id, _snapshot, _requestType, query) {
|
||||
let url = super.buildURL(...arguments);
|
||||
|
||||
return SlugUrl(url, query);
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
export default ApplicationAdapter.extend({
|
||||
|
||||
@classic
|
||||
export default class Theme extends ApplicationAdapter {
|
||||
activate(model) {
|
||||
let url = `${this.buildURL('theme', model.get('id'))}activate/`;
|
||||
|
||||
@ -10,5 +11,4 @@ export default ApplicationAdapter.extend({
|
||||
return model;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -1,14 +1,22 @@
|
||||
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
||||
import SlugUrl from 'ghost-admin/mixins/slug-url';
|
||||
import SlugUrl from 'ghost-admin/utils/slug-url';
|
||||
import classic from 'ember-classic-decorator';
|
||||
|
||||
@classic
|
||||
export default class User extends ApplicationAdapter {
|
||||
buildURL(_modelName, _id, _snapshot, _requestType, query) {
|
||||
let url = super.buildURL(...arguments);
|
||||
|
||||
return SlugUrl(url, query);
|
||||
}
|
||||
|
||||
export default ApplicationAdapter.extend(SlugUrl, {
|
||||
queryRecord(store, type, query) {
|
||||
if (!query || query.id !== 'me') {
|
||||
return this._super(...arguments);
|
||||
return super.queryRecord(...arguments);
|
||||
}
|
||||
|
||||
let url = this.buildURL(type.modelName, 'me', null, 'findRecord');
|
||||
|
||||
return this.ajax(url, 'GET', {data: {include: 'roles'}});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
import Mixin from '@ember/object/mixin';
|
||||
import {isBlank} from '@ember/utils';
|
||||
|
||||
export default Mixin.create({
|
||||
buildURL(_modelName, _id, _snapshot, _requestType, query) {
|
||||
let url = this._super(...arguments);
|
||||
|
||||
if (query && !isBlank(query.slug)) {
|
||||
url += `slug/${query.slug}/`;
|
||||
delete query.slug;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
});
|
10
ghost/admin/app/utils/slug-url.js
Normal file
10
ghost/admin/app/utils/slug-url.js
Normal file
@ -0,0 +1,10 @@
|
||||
import {isBlank} from '@ember/utils';
|
||||
|
||||
export default function SlugUrl(url, query) {
|
||||
if (query && !isBlank(query.slug)) {
|
||||
url += `slug/${query.slug}/`;
|
||||
delete query.slug;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
Loading…
Reference in New Issue
Block a user