-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenAPI CRUD views #6702
OpenAPI CRUD views #6702
Changes from 22 commits
f032067
82d072e
ae8bb90
34e2c1d
4f68001
5e4a4af
8603ab3
83e905d
4bbf98a
97b0112
36b7ff4
190640c
73f7865
b684338
8172468
61589f6
79ecf47
676ee89
0682a89
51c1489
9cc9c1e
5e50388
ce6ecdf
9ee259f
325559b
469dfde
5d9eb50
081dda0
7e28fa9
417e4b7
177109a
f523cde
caf9e05
c3f1aaa
5fcb5bd
b40623c
56f0704
2d7795f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { assign } from '@ember/polyfills'; | ||
import ApplicationAdapter from './application'; | ||
|
||
export default ApplicationAdapter.extend({ | ||
namespace: 'v1', | ||
urlForItem() {}, | ||
optionsForQuery(id) { | ||
let data = {}; | ||
if (!id) { | ||
data['list'] = true; | ||
} | ||
return { data }; | ||
}, | ||
|
||
fetchByQuery(store, query) { | ||
const { id, method, type } = query; | ||
return this.ajax(this.urlForItem(method, id, type), 'GET', this.optionsForQuery(id)).then(resp => { | ||
const data = { | ||
id, | ||
name: id, | ||
method, | ||
}; | ||
|
||
return assign({}, resp, data); | ||
}); | ||
}, | ||
|
||
query(store, type, query) { | ||
return this.fetchByQuery(store, query); | ||
}, | ||
|
||
queryRecord(store, type, query) { | ||
return this.fetchByQuery(store, query); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { inject as service } from '@ember/service'; | ||
import Component from '@ember/component'; | ||
import { computed } from '@ember/object'; | ||
import { task } from 'ember-concurrency'; | ||
import DS from 'ember-data'; | ||
|
||
/** | ||
* @module GeneratedItem | ||
* The `GeneratedItem` is the form to configure generated items related to mounts (e.g. groups, roles, users) | ||
* | ||
* @example | ||
* ```js | ||
* <GeneratedItem @model={{model}} @mode={{mode}} @itemType={{itemType/> | ||
* ``` | ||
* | ||
* @property model=null {DS.Model} - The corresponding item model that is being configured. | ||
* @property mode {String} - which config mode to use. either `show`, `edit`, or `create` | ||
* @property itemType {String} - the type of item displayed | ||
* | ||
*/ | ||
|
||
export default Component.extend({ | ||
model: null, | ||
itemType: null, | ||
flashMessages: service(), | ||
router: service(), | ||
props: computed(function() { | ||
return this.model.serialize(); | ||
}), | ||
saveModel: task(function*() { | ||
try { | ||
yield this.model.save(); | ||
} catch (err) { | ||
// AdapterErrors are handled by the error-message component | ||
// in the form | ||
if (err instanceof DS.AdapterError === false) { | ||
throw err; | ||
} | ||
return; | ||
} | ||
this.router.transitionTo('vault.cluster.access.method.item.list').followRedirects(); | ||
this.flashMessages.success(`The ${this.itemType} configuration was saved successfully.`); | ||
}).withTestWaiter(), | ||
actions: { | ||
deleteItem() { | ||
this.model.destroyRecord().then(() => { | ||
this.router.transitionTo('vault.cluster.access.method.item.list').followRedirects(); | ||
this.flashMessages.success(`${this.model.id} ${this.itemType} was deleted successfully.`); | ||
}); | ||
}, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Controller from '@ember/controller'; | ||
import ListController from 'vault/mixins/list-controller'; | ||
|
||
export default Controller.extend(ListController, {}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { set } from '@ember/object'; | ||
import Route from '@ember/routing/route'; | ||
import DS from 'ember-data'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default Route.extend({ | ||
pathHelp: service('path-help'), | ||
model(params) { | ||
// eslint-disable-line rule | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be removed. |
||
const { path } = params; | ||
return this.store.findAll('auth-method').then(modelArray => { | ||
const model = modelArray.findBy('id', path); | ||
|
@@ -12,6 +15,12 @@ export default Route.extend({ | |
set(error, 'httpStatus', 404); | ||
throw error; | ||
} | ||
if (model.type === 'ldap') { | ||
return this.pathHelp.getPaths(model.apiPath, path).then(paths => { | ||
model.set('paths', paths); | ||
return model; | ||
}); | ||
} | ||
return model; | ||
}); | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { inject as service } from '@ember/service'; | ||
import Route from '@ember/routing/route'; | ||
import { getOwner } from '@ember/application'; | ||
import { singularize } from 'ember-inflector'; | ||
|
||
export default Route.extend({ | ||
wizard: service(), | ||
pathHelp: service('path-help'), | ||
|
||
beforeModel() { | ||
const { item_type: itemType } = this.paramsFor(this.routeName); | ||
const { path: method } = this.paramsFor('vault.cluster.access.method'); | ||
let methodModel = this.modelFor('vault.cluster.access.method'); | ||
let { apiPath, type } = methodModel; | ||
let modelType = `generated-${singularize(itemType)}-${type}`; | ||
madalynrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return this.pathHelp.getNewModel(modelType, getOwner(this), method, apiPath, itemType); | ||
}, | ||
|
||
setupController(controller) { | ||
this._super(...arguments); | ||
const { item_type: itemType } = this.paramsFor(this.routeName); | ||
const { path } = this.paramsFor('vault.cluster.access.method'); | ||
const { apiPath } = this.modelFor('vault.cluster.access.method'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could wrap these into a helper method to use in both places. |
||
controller.set('itemType', itemType); | ||
controller.set('method', path); | ||
this.pathHelp.getPaths(apiPath, path, itemType).then(paths => { | ||
controller.set('paths', Array.from(paths.list, pathInfo => pathInfo.path)); | ||
}); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Route from '@ember/routing/route'; | ||
import UnloadModelRoute from 'vault/mixins/unload-model-route'; | ||
import UnsavedModelRoute from 'vault/mixins/unsaved-model-route'; | ||
import { singularize } from 'ember-inflector'; | ||
|
||
export default Route.extend(UnloadModelRoute, UnsavedModelRoute, { | ||
model() { | ||
const { item_type: itemType } = this.paramsFor('vault.cluster.access.method.item'); | ||
const methodModel = this.modelFor('vault.cluster.access.method'); | ||
const { type } = methodModel; | ||
const { path: method } = this.paramsFor('vault.cluster.access.method'); | ||
const modelType = `generated-${singularize(itemType)}-${type}`; | ||
return this.store.createRecord(modelType, { | ||
itemType, | ||
method, | ||
adapterOptions: { path: `${method}/${itemType}` }, | ||
}); | ||
}, | ||
|
||
setupController(controller) { | ||
this._super(...arguments); | ||
const { item_type: itemType } = this.paramsFor('vault.cluster.access.method.item'); | ||
const { path: method } = this.paramsFor('vault.cluster.access.method'); | ||
controller.set('itemType', singularize(itemType)); | ||
controller.set('mode', 'create'); | ||
controller.set('method', method); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Route from '@ember/routing/route'; | ||
import UnloadModelRoute from 'vault/mixins/unload-model-route'; | ||
import UnsavedModelRoute from 'vault/mixins/unsaved-model-route'; | ||
import { singularize } from 'ember-inflector'; | ||
|
||
export default Route.extend(UnloadModelRoute, UnsavedModelRoute, { | ||
model(params) { | ||
const methodModel = this.modelFor('vault.cluster.access.method'); | ||
const { type } = methodModel; | ||
const { item_type: itemType } = this.paramsFor('vault.cluster.access.method.item'); | ||
let modelType = `generated-${singularize(itemType)}-${type}`; | ||
return this.store.findRecord(modelType, params.item_id); | ||
}, | ||
|
||
setupController(controller) { | ||
this._super(...arguments); | ||
const { item_type: itemType } = this.paramsFor('vault.cluster.access.method.item'); | ||
const { path: method } = this.paramsFor('vault.cluster.access.method'); | ||
const { item_id: itemName } = this.paramsFor(this.routeName); | ||
controller.set('itemType', singularize(itemType)); | ||
controller.set('mode', 'edit'); | ||
controller.set('method', method); | ||
controller.set('itemName', itemName); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { inject as service } from '@ember/service'; | ||
import Route from '@ember/routing/route'; | ||
import { singularize } from 'ember-inflector'; | ||
import ListRoute from 'vault/mixins/list-route'; | ||
|
||
export default Route.extend(ListRoute, { | ||
wizard: service(), | ||
pathHelp: service('path-help'), | ||
model() { | ||
const { item_type: itemType } = this.paramsFor('vault.cluster.access.method.item'); | ||
const { page, pageFilter } = this.paramsFor(this.routeName); | ||
const methodModel = this.modelFor('vault.cluster.access.method'); | ||
const { type } = methodModel; | ||
let modelType = `generated-${singularize(itemType)}-${type}`; | ||
const { path: method } = this.paramsFor('vault.cluster.access.method'); | ||
|
||
return this.store | ||
.lazyPaginatedQuery(modelType, { | ||
responsePath: 'data.keys', | ||
page: page, | ||
pageFilter: pageFilter, | ||
type: itemType, | ||
method: method, | ||
}) | ||
.catch(err => { | ||
if (err.httpStatus === 404) { | ||
return []; | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
}, | ||
|
||
setupController(controller) { | ||
this._super(...arguments); | ||
const { item_type: itemType } = this.paramsFor('vault.cluster.access.method.item'); | ||
let { path } = this.paramsFor('vault.cluster.access.method'); | ||
controller.set('itemType', singularize(itemType)); | ||
controller.set('method', path); | ||
const { apiPath } = this.modelFor('vault.cluster.access.method'); | ||
this.pathHelp.getPaths(apiPath, path, itemType).then(paths => { | ||
madalynrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
controller.set('paths', Array.from(paths.list, pathInfo => pathInfo.path)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the type of |
||
}); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { singularize } from 'ember-inflector'; | ||
import { inject as service } from '@ember/service'; | ||
import Route from '@ember/routing/route'; | ||
|
||
export default Route.extend({ | ||
pathHelp: service('path-help'), | ||
model() { | ||
const { item_id: itemName } = this.paramsFor(this.routeName); | ||
const { item_type: itemType } = this.paramsFor('vault.cluster.access.method.item'); | ||
const { path: method } = this.paramsFor('vault.cluster.access.method'); | ||
const methodModel = this.modelFor('vault.cluster.access.method'); | ||
const { type } = methodModel; | ||
const modelType = `generated-${singularize(itemType)}-${type}`; | ||
return this.store.findRecord(modelType, itemName, { | ||
adapterOptions: { path: `${method}/${itemType}` }, | ||
}); | ||
}, | ||
|
||
setupController(controller) { | ||
this._super(...arguments); | ||
const { item_type: itemType } = this.paramsFor('vault.cluster.access.method.item'); | ||
controller.set('itemType', singularize(itemType)); | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note here that positionParams are going away in Glimmer components, so we'll eventually want to move away from this.