From f9b0e50ca07c1856466d1f6b49e52272356aaccf Mon Sep 17 00:00:00 2001 From: John Cowen Date: Wed, 24 Feb 2021 09:03:18 +0000 Subject: [PATCH] ui: Update project blueprints for native classes (#9775) --- .../files/__root__/__path__/__name__.js | 15 +++++---- .../model/files/__root__/__path__/__name__.js | 18 +++++++--- .../files/__root__/__path__/__name__.js | 33 +++++++++++++++---- .../files/__root__/__path__/__name__.js | 15 +++++---- 4 files changed, 57 insertions(+), 24 deletions(-) diff --git a/ui/packages/consul-ui/blueprints/adapter/files/__root__/__path__/__name__.js b/ui/packages/consul-ui/blueprints/adapter/files/__root__/__path__/__name__.js index 26f49543e1..73f3a3a8a5 100644 --- a/ui/packages/consul-ui/blueprints/adapter/files/__root__/__path__/__name__.js +++ b/ui/packages/consul-ui/blueprints/adapter/files/__root__/__path__/__name__.js @@ -1,14 +1,16 @@ import Adapter from './application'; -export default Adapter.extend({ - requestForQuery: function(request, { dc, index }) { +export default class <%= classifiedModuleName %>Adapter extends Adapter { + + requestForQuery(request, { ns, dc, index }) { return request` GET /v1/<%= dasherizedModuleName %>?${{ dc }} ${{ index }} `; - }, - requestForQueryRecord: function(request, { dc, index, id }) { + } + + requestForQueryRecord(request, { ns, dc, index, id }) { if (typeof id === 'undefined') { throw new Error('You must specify an id'); } @@ -17,5 +19,6 @@ export default Adapter.extend({ ${{ index }} `; - }, -}); + } + +}; diff --git a/ui/packages/consul-ui/blueprints/model/files/__root__/__path__/__name__.js b/ui/packages/consul-ui/blueprints/model/files/__root__/__path__/__name__.js index aa6b37b1e1..e82d67a654 100644 --- a/ui/packages/consul-ui/blueprints/model/files/__root__/__path__/__name__.js +++ b/ui/packages/consul-ui/blueprints/model/files/__root__/__path__/__name__.js @@ -1,10 +1,18 @@ import Model from 'ember-data/model'; import attr from 'ember-data/attr'; +//import { nullValue } from 'consul-ui/decorators/replace'; export const PRIMARY_KEY = 'uid'; export const SLUG_KEY = 'ID'; -export default Model.extend({ - [PRIMARY_KEY]: attr('string'), - [SLUG_KEY]: attr('string'), - Datacenter: attr('string'), -}); +export default class <%= classifiedModuleName %>Model extends Model { + @attr('string') uid; + @attr('string') ID; + @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? +}; diff --git a/ui/packages/consul-ui/blueprints/repository/files/__root__/__path__/__name__.js b/ui/packages/consul-ui/blueprints/repository/files/__root__/__path__/__name__.js index fedb6c7b19..7b069e08cb 100644 --- a/ui/packages/consul-ui/blueprints/repository/files/__root__/__path__/__name__.js +++ b/ui/packages/consul-ui/blueprints/repository/files/__root__/__path__/__name__.js @@ -1,8 +1,29 @@ import RepositoryService from 'consul-ui/services/repository'; +import dataSource from 'consul-ui/decorators/data-source'; -const modelName = '<%= dasherizedModuleName %>'; -export default RepositoryService.extend({ - getModelName: function() { - return modelName; - }, -}); +const MODEL_NAME = '<%= dasherizedModuleName %>'; +const PRIMARY_KEY = 'uid'; +const SLUG_KEY = 'ID'; +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); + } +}; diff --git a/ui/packages/consul-ui/blueprints/serializer/files/__root__/__path__/__name__.js b/ui/packages/consul-ui/blueprints/serializer/files/__root__/__path__/__name__.js index 20b4a0f1f4..beed907377 100644 --- a/ui/packages/consul-ui/blueprints/serializer/files/__root__/__path__/__name__.js +++ b/ui/packages/consul-ui/blueprints/serializer/files/__root__/__path__/__name__.js @@ -1,11 +1,12 @@ import Serializer from './application'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/<%= dasherizedModuleName %>'; -export default Serializer.extend({ - primaryKey: PRIMARY_KEY, - slugKey: SLUG_KEY, - // respondForQueryRecord: function(respond, query) { - // return this._super( +export default class <%= classifiedModuleName %>Serializer extends Serializer { + primaryKey = PRIMARY_KEY; + slugKey = SLUG_KEY; + + // respondForQueryRecord(respond, query) { + // return super.respondForQueryRecord( // function(cb) { // return respond( // function(headers, body) { @@ -20,5 +21,5 @@ export default Serializer.extend({ // }, // query // ); - // }, -}); + // } +};