ui: Update project blueprints for native classes (#9775)

This commit is contained in:
John Cowen 2021-02-24 09:03:18 +00:00 committed by GitHub
parent 26d41f076b
commit e81eea229b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 24 deletions

View File

@ -1,14 +1,16 @@
import Adapter from './application'; import Adapter from './application';
export default Adapter.extend({ export default class <%= classifiedModuleName %>Adapter extends Adapter {
requestForQuery: function(request, { dc, index }) {
requestForQuery(request, { ns, dc, index }) {
return request` return request`
GET /v1/<%= dasherizedModuleName %>?${{ dc }} GET /v1/<%= dasherizedModuleName %>?${{ dc }}
${{ index }} ${{ index }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, index, id }) {
requestForQueryRecord(request, { ns, dc, index, id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -17,5 +19,6 @@ export default Adapter.extend({
${{ index }} ${{ index }}
`; `;
}, }
});
};

View File

@ -1,10 +1,18 @@
import Model from 'ember-data/model'; import Model from 'ember-data/model';
import attr from 'ember-data/attr'; import attr from 'ember-data/attr';
//import { nullValue } from 'consul-ui/decorators/replace';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ID'; export const SLUG_KEY = 'ID';
export default Model.extend({ export default class <%= classifiedModuleName %>Model extends Model {
[PRIMARY_KEY]: attr('string'), @attr('string') uid;
[SLUG_KEY]: attr('string'), @attr('string') ID;
Datacenter: attr('string'), @attr('string') Datacenter;
});
// @attr('string') Namespace; // Does this Model support namespaces?
// @nullValue([]) @attr({ defaultValue: () => [] }) MaybeNull; // Does a property sometimes return null?
// @attr('number') SyncTime; // Does this Model support blocking queries?
// @attr() meta; // {} // Does this Model support blocking queries?
};

View File

@ -1,8 +1,29 @@
import RepositoryService from 'consul-ui/services/repository'; import RepositoryService from 'consul-ui/services/repository';
import dataSource from 'consul-ui/decorators/data-source';
const modelName = '<%= dasherizedModuleName %>'; const MODEL_NAME = '<%= dasherizedModuleName %>';
export default RepositoryService.extend({ const PRIMARY_KEY = 'uid';
getModelName: function() { const SLUG_KEY = 'ID';
return modelName; export default class <%= classifiedModuleName %>Repository extends RepositoryService {
}, getModelName() {
}); return MODEL_NAME;
}
getPrimaryKey() {
return PRIMARY_KEY;
}
getSlugKey() {
return SLUG_KEY;
}
@dataSource('/:ns/:dc/<%= dasherizedModuleName %>')
async findAllByDatacenter() {
return super.findAllByDatacenter(...arguments);
}
@dataSource('/:ns/:dc/<%= dasherizedModuleName %>/:id')
async findBySlug() {
return super.findBySlug(...arguments);
}
};

View File

@ -1,11 +1,12 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/<%= dasherizedModuleName %>'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/<%= dasherizedModuleName %>';
export default Serializer.extend({ export default class <%= classifiedModuleName %>Serializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
// respondForQueryRecord: function(respond, query) {
// return this._super( // respondForQueryRecord(respond, query) {
// return super.respondForQueryRecord(
// function(cb) { // function(cb) {
// return respond( // return respond(
// function(headers, body) { // function(headers, body) {
@ -20,5 +21,5 @@ export default Serializer.extend({
// }, // },
// query // query
// ); // );
// }, // }
}); };