mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 09:51:09 +03:00
Add PUT support for models
This commit is contained in:
parent
add48f3f14
commit
09ac71518e
@ -5,6 +5,8 @@ function AddCredentialsController (models, $state) {
|
|||||||
let credential = models.credential;
|
let credential = models.credential;
|
||||||
let credentialType = models.credentialType;
|
let credentialType = models.credentialType;
|
||||||
|
|
||||||
|
vm.panelTitle = 'New Credential';
|
||||||
|
|
||||||
vm.form = credential.createFormSchema('post', {
|
vm.form = credential.createFormSchema('post', {
|
||||||
omit: ['user', 'team', 'inputs']
|
omit: ['user', 'team', 'inputs']
|
||||||
});
|
});
|
||||||
@ -24,13 +26,13 @@ function AddCredentialsController (models, $state) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
vm.form.save = data => {
|
vm.form.save = data => {
|
||||||
data.user = me.get('results[0].id');
|
data.user = me.getSelf().id;
|
||||||
|
|
||||||
return credential.request('post', data);
|
return credential.request('post', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.form.onSaveSuccess = res => {
|
vm.form.onSaveSuccess = res => {
|
||||||
$state.go('credentials.edit', { credential: res.data });
|
$state.go('credentials.edit', { id: res.data.id }, { reload: true });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<at-panel>
|
<at-panel>
|
||||||
<at-panel-heading>New Credential</at-panel-heading>
|
<at-panel-heading>{{ vm.panelTitle }}</at-panel-heading>
|
||||||
|
|
||||||
<at-tab-group>
|
<at-tab-group>
|
||||||
<at-tab to="details">Details</at-tab>
|
<at-tab to="details">Details</at-tab>
|
||||||
|
@ -4,35 +4,43 @@ function EditCredentialsController (models, $state) {
|
|||||||
let me = models.me;
|
let me = models.me;
|
||||||
let credential = models.credential;
|
let credential = models.credential;
|
||||||
let credentialType = models.credentialType;
|
let credentialType = models.credentialType;
|
||||||
let credentialOptions = models.credentialOptions;
|
|
||||||
|
|
||||||
vm.form = credentialOptions.createFormSchema('put', {
|
vm.panelTitle = credential.get('name');
|
||||||
omit: ['user', 'team', 'inputs'],
|
|
||||||
models
|
vm.form = credential.createFormSchema('put', {
|
||||||
|
omit: ['user', 'team', 'inputs']
|
||||||
});
|
});
|
||||||
|
|
||||||
vm.form.credential_type._data = credentialType.get('results');
|
vm.form.credential_type._data = credentialType.get('results');
|
||||||
vm.form.credential_type._placeholder = 'SELECT A TYPE';
|
|
||||||
vm.form.credential_type._format = 'grouped-object';
|
vm.form.credential_type._format = 'grouped-object';
|
||||||
vm.form.credential_type._display = 'name';
|
vm.form.credential_type._display = 'name';
|
||||||
vm.form.credential_type._key = 'id';
|
vm.form.credential_type._key = 'id';
|
||||||
vm.form.credential_type._exp = 'type as type.name group by type.kind for type in state._data';
|
vm.form.credential_type._exp = 'type as type.name group by type.kind for type in state._data';
|
||||||
|
vm.form.credential_type._value = credentialType.getById(credential.get('credential_type'));
|
||||||
|
|
||||||
vm.form.inputs = {
|
vm.form.inputs = {
|
||||||
_get: credentialType.mergeInputProperties,
|
_get (type) {
|
||||||
|
let inputs = credentialType.mergeInputProperties(type);
|
||||||
|
|
||||||
|
if (type.id === credential.get('credential_type')) {
|
||||||
|
inputs = credential.assignInputGroupValues(inputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputs;
|
||||||
|
},
|
||||||
_source: vm.form.credential_type,
|
_source: vm.form.credential_type,
|
||||||
_reference: 'vm.form.inputs',
|
_reference: 'vm.form.inputs',
|
||||||
_key: 'inputs'
|
_key: 'inputs'
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.form.save = data => {
|
vm.form.save = data => {
|
||||||
data.user = me.get('results[0].id');
|
data.user = me.getSelf().id;
|
||||||
|
|
||||||
return credential.request('post', data);
|
return credential.request('put', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.form.onSaveSuccess = res => {
|
vm.form.onSaveSuccess = res => {
|
||||||
$state.go('credentials.edit', { credential: res.data });
|
$state.go('credentials', { reload: true });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,21 +41,21 @@ function config ($stateExtenderProvider, pathServiceProvider) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function CredentialsResolve ($q, params, Me, Credential, CredentialType) {
|
function CredentialsResolve ($q, $stateParams, Me, Credential, CredentialType) {
|
||||||
|
let id = $stateParams.id;
|
||||||
|
|
||||||
let promises = {
|
let promises = {
|
||||||
me: new Me('get')
|
me: new Me('get'),
|
||||||
|
credentialType: new CredentialType('get')
|
||||||
};
|
};
|
||||||
|
|
||||||
if (params.credential) {
|
if (id) {
|
||||||
promises.credential = new Credential('get', params.credential);
|
promises.credential = new Credential(['get', 'options'], [id, id]);
|
||||||
promises.credentialOptions = new Credential('options');
|
|
||||||
promises.credentialType = new CredentialType('get', params.credential.credential_type);
|
|
||||||
} else {
|
} else {
|
||||||
promises.credential = new Credential('options');
|
promises.credential = new Credential('options');
|
||||||
promises.credentialType = new CredentialType('get');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $q.all(promises).then(models => models);
|
return $q.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
CredentialsResolve.$inject = [
|
CredentialsResolve.$inject = [
|
||||||
@ -86,7 +86,7 @@ function config ($stateExtenderProvider, pathServiceProvider) {
|
|||||||
|
|
||||||
stateExtender.addState({
|
stateExtender.addState({
|
||||||
name: 'credentials.edit',
|
name: 'credentials.edit',
|
||||||
route: '/edit/:credential',
|
route: '/edit/:id',
|
||||||
ncyBreadcrumb: {
|
ncyBreadcrumb: {
|
||||||
label: N_('EDIT')
|
label: N_('EDIT')
|
||||||
},
|
},
|
||||||
|
@ -18,13 +18,45 @@ function AtInputSecretController (baseInputController) {
|
|||||||
baseInputController.call(vm, 'input', _scope_, element, form);
|
baseInputController.call(vm, 'input', _scope_, element, form);
|
||||||
|
|
||||||
scope = _scope_;
|
scope = _scope_;
|
||||||
scope.type = 'password';
|
|
||||||
scope.buttonText = 'SHOW';
|
if (!scope.state._value) {
|
||||||
|
scope.type = 'password';
|
||||||
|
scope.buttonText = 'SHOW';
|
||||||
|
|
||||||
|
vm.toggle = vm.toggleAddState;
|
||||||
|
} else {
|
||||||
|
scope.type = 'password';
|
||||||
|
scope.edit = true;
|
||||||
|
scope.replace = false;
|
||||||
|
scope.buttonText = 'REPLACE';
|
||||||
|
|
||||||
|
vm.toggle = vm.toggleEditState;
|
||||||
|
}
|
||||||
|
|
||||||
vm.check();
|
vm.check();
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.toggle = () => {
|
vm.updateModel = value => {
|
||||||
|
if (!scope.edit || scope.replace) {
|
||||||
|
scope.state._value = scope.displayModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
vm.check();
|
||||||
|
};
|
||||||
|
|
||||||
|
vm.toggleEditState = () => {
|
||||||
|
scope.displayModel = '';
|
||||||
|
|
||||||
|
if (scope.replace) {
|
||||||
|
scope.buttonText = 'REPLACE';
|
||||||
|
} else {
|
||||||
|
scope.buttonText = 'REVERT';
|
||||||
|
}
|
||||||
|
|
||||||
|
scope.replace = !scope.replace;
|
||||||
|
};
|
||||||
|
|
||||||
|
vm.toggleAddState = () => {
|
||||||
if (scope.type === 'password') {
|
if (scope.type === 'password') {
|
||||||
scope.type = 'text';
|
scope.type = 'text';
|
||||||
scope.buttonText = 'HIDE';
|
scope.buttonText = 'HIDE';
|
||||||
|
@ -12,13 +12,13 @@
|
|||||||
</span>
|
</span>
|
||||||
<input type="{{ type }}"
|
<input type="{{ type }}"
|
||||||
class="form-control at-Input"
|
class="form-control at-Input"
|
||||||
ng-model="state._value"
|
ng-model="displayModel"
|
||||||
ng-class="{ 'at-Input--rejected': state._rejected }"
|
ng-class="{ 'at-Input--rejected': state._rejected }"
|
||||||
ng-attr-maxlength="{{ state.max_length || undefined }}"
|
ng-attr-maxlength="{{ state.max_length || undefined }}"
|
||||||
ng-attr-tabindex="{{ tab || undefined }}"
|
ng-attr-tabindex="{{ tab || undefined }}"
|
||||||
ng-attr-placeholder="{{::state._placeholder || undefined }}"
|
ng-attr-placeholder="{{::state._placeholder || undefined }}"
|
||||||
ng-change="vm.check()"
|
ng-change="vm.updateModel()"
|
||||||
ng-disabled="state._disabled || form.disabled" />
|
ng-disabled="(state._disabled || form.disabled) || (state._encrypted && !replace)" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<at-input-message></at-input-message>
|
<at-input-message></at-input-message>
|
||||||
|
@ -27,6 +27,10 @@ function AtInputSelectController (baseInputController, eventService) {
|
|||||||
|
|
||||||
vm.setListeners();
|
vm.setListeners();
|
||||||
vm.check();
|
vm.check();
|
||||||
|
|
||||||
|
if (scope.state._value) {
|
||||||
|
vm.updateDisplayModel();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.setListeners = () => {
|
vm.setListeners = () => {
|
||||||
|
@ -26,64 +26,78 @@ function AtInputTextareaSecretController (baseInputController, eventService) {
|
|||||||
textarea = element.find('textarea')[0];
|
textarea = element.find('textarea')[0];
|
||||||
container = element[0];
|
container = element[0];
|
||||||
|
|
||||||
scope.pre = {};
|
|
||||||
scope.state._edit = true;
|
|
||||||
|
|
||||||
if (scope.state.format === 'ssh_private_key') {
|
if (scope.state.format === 'ssh_private_key') {
|
||||||
scope.ssh = true;
|
scope.ssh = true;
|
||||||
scope.state._hint = scope.state._hint || DEFAULT_HINT;
|
|
||||||
input = element.find('input')[0];
|
input = element.find('input')[0];
|
||||||
vm.setFileListeners(textarea, input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scope.state._edit) {
|
if (scope.state._value) {
|
||||||
scope.edit = true;
|
scope.edit = true;
|
||||||
scope.isShown = true;
|
scope.replace = false;
|
||||||
scope.buttonText = 'REPLACE';
|
scope.buttonText = 'REPLACE';
|
||||||
|
} else {
|
||||||
|
scope.state._hint = scope.state._hint || DEFAULT_HINT;
|
||||||
|
vm.listeners = vm.setFileListeners(textarea, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vm.updateModel();
|
||||||
|
};
|
||||||
|
|
||||||
|
vm.updateModel = (value) => {
|
||||||
|
if (!scope.edit || scope.replace) {
|
||||||
|
scope.state._value = scope.displayModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
vm.check();
|
vm.check();
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.setFileListeners = (textarea, input) => {
|
vm.setFileListeners = (textarea, input) => {
|
||||||
eventService.addListener(textarea, 'dragenter', event => {
|
return eventService.addListeners([
|
||||||
event.stopPropagation();
|
[textarea, 'dragenter', event => {
|
||||||
event.preventDefault();
|
event.stopPropagation();
|
||||||
scope.$apply(() => scope.drag = true);
|
event.preventDefault();
|
||||||
});
|
scope.$apply(() => scope.drag = true);
|
||||||
|
}],
|
||||||
|
|
||||||
eventService.addListener(input, 'dragleave', event => {
|
[input, 'dragleave', event => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
scope.$apply(() => scope.drag = false);
|
scope.$apply(() => scope.drag = false);
|
||||||
});
|
}],
|
||||||
|
|
||||||
eventService.addListener(input, 'change', event => {
|
[input, 'change', event => {
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
|
|
||||||
reader.onload = () => vm.readFile(reader, event);
|
reader.onload = () => vm.readFile(reader, event);
|
||||||
reader.readAsText(input.files[0]);
|
reader.readAsText(input.files[0]);
|
||||||
});
|
}]
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.readFile = (reader, event) => {
|
vm.readFile = (reader, event) => {
|
||||||
scope.$apply(() => {
|
scope.$apply(() => {
|
||||||
scope.state._value = reader.result;
|
scope.displayModel = reader.result;
|
||||||
|
vm.updateModel();
|
||||||
scope.drag = false
|
scope.drag = false
|
||||||
|
input.value = '';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.toggle = () => {
|
vm.toggle = () => {
|
||||||
if (scope.isShown) {
|
scope.displayModel = undefined;
|
||||||
scope.buttonText = 'REVERT';
|
|
||||||
scope.pre.value = scope.state._value;
|
if (scope.replace) {
|
||||||
scope.state._value = undefined;
|
|
||||||
} else {
|
|
||||||
scope.state._value = scope.pre.value;
|
|
||||||
scope.buttonText = 'REPLACE';
|
scope.buttonText = 'REPLACE';
|
||||||
|
scope.state._hint = '';
|
||||||
|
eventService.remove(vm.listeners);
|
||||||
|
} else {
|
||||||
|
scope.buttonText = 'REVERT';
|
||||||
|
scope.state._hint = scope.state._hint || DEFAULT_HINT;
|
||||||
|
vm.listeners = vm.setFileListeners(textarea, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.isShown = !scope.isShown;
|
scope.replace = !scope.replace;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
type="file"
|
type="file"
|
||||||
name="files" />
|
name="files" />
|
||||||
<textarea class="form-control at-Input at-Textarea"
|
<textarea class="form-control at-Input at-Textarea"
|
||||||
ng-model="state._value"
|
ng-model="displayModel"
|
||||||
ng-class="{ 'at-Input--rejected': state._rejected }"
|
ng-class="{ 'at-Input--rejected': state._rejected }"
|
||||||
ng-attr-maxlength="{{ state.max_length || undefined }}"
|
ng-attr-maxlength="{{ state.max_length || undefined }}"
|
||||||
ng-attr-tabindex="{{ tab || undefined }}"
|
ng-attr-tabindex="{{ tab || undefined }}"
|
||||||
ng-attr-placeholder="{{::state._placeholder || undefined }}"
|
ng-attr-placeholder="{{::state._placeholder || undefined }}"
|
||||||
ng-change="vm.check()"
|
ng-change="vm.updateModel()"
|
||||||
ng-disabled="state._disabled || form.disabled" />
|
ng-disabled="(state._disabled || form.disabled) || (state._encrypted && !replace)" />
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,40 +1,33 @@
|
|||||||
let $http;
|
let $http;
|
||||||
let $q;
|
let $q;
|
||||||
|
|
||||||
function request (method, ...args) {
|
function request (method, resource) {
|
||||||
this.method = method.toUpperCase();
|
if (Array.isArray(method) && Array.isArray(resource)) {
|
||||||
|
let promises = method.map((value, i) => this.http[value](resource[i]));
|
||||||
|
|
||||||
if (typeof args[0] === 'object') {
|
return $q.all(promises);
|
||||||
this.res = null;
|
|
||||||
this.model = args[0];
|
|
||||||
|
|
||||||
return $q.resolve();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (this.method) {
|
return this.http[method](resource);
|
||||||
case 'OPTIONS':
|
|
||||||
return this.httpOptions(...args);
|
|
||||||
case 'GET':
|
|
||||||
return this.httpGet(...args);
|
|
||||||
case 'POST':
|
|
||||||
return this.httpPost(...args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function httpGet (id) {
|
function httpGet (resource) {
|
||||||
let req = {
|
let req = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: this.path
|
url: this.path
|
||||||
};
|
};
|
||||||
|
|
||||||
if (id) {
|
if (typeof resource === 'object') {
|
||||||
req.url = `${this.path}/${id}`;
|
this.model[this.method] = resource;
|
||||||
|
|
||||||
|
return $q.resolve();
|
||||||
|
} else if (resource) {
|
||||||
|
req.url = `${this.path}/${resource}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $http(req)
|
return $http(req)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.res = res;
|
this.model.GET = res.data;
|
||||||
this.model = res.data;
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
@ -47,33 +40,56 @@ function httpPost (data) {
|
|||||||
data
|
data
|
||||||
};
|
};
|
||||||
|
|
||||||
return $http(req)
|
return $http(req).then(res => res);
|
||||||
.then(res => {
|
|
||||||
this.res = res;
|
|
||||||
this.model = res.data;
|
|
||||||
|
|
||||||
return res;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function httpOptions () {
|
function httpPut (changes) {
|
||||||
|
let model = Object.assign(this.get(), changes);
|
||||||
|
|
||||||
|
let req = {
|
||||||
|
method: 'PUT',
|
||||||
|
url: `${this.path}${model.id}/`,
|
||||||
|
data: model
|
||||||
|
};
|
||||||
|
|
||||||
|
return $http(req).then(res => res);
|
||||||
|
}
|
||||||
|
|
||||||
|
function httpOptions (resource) {
|
||||||
let req = {
|
let req = {
|
||||||
method: 'OPTIONS',
|
method: 'OPTIONS',
|
||||||
url: this.path
|
url: this.path
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (resource) {
|
||||||
|
req.url = `${this.path}/${resource}`;
|
||||||
|
}
|
||||||
|
|
||||||
return $http(req)
|
return $http(req)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.res = res;
|
this.model.OPTIONS = res.data;
|
||||||
this.model = res.data;
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function get (_keys_) {
|
function get (method, keys) {
|
||||||
let keys = _keys_.split('.');
|
let model;
|
||||||
let value = this.model;
|
|
||||||
|
if (keys) {
|
||||||
|
model = this.model[method.toUpperCase()];
|
||||||
|
} else {
|
||||||
|
model = this.model.GET;
|
||||||
|
keys = method;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!keys) {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
keys = keys.split('.');
|
||||||
|
|
||||||
|
let value = model;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
keys.forEach(key => {
|
keys.forEach(key => {
|
||||||
@ -109,14 +125,17 @@ function normalizePath (resource) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function BaseModel (path) {
|
function BaseModel (path) {
|
||||||
|
this.model = {};
|
||||||
this.get = get;
|
this.get = get;
|
||||||
this.httpGet = httpGet;
|
|
||||||
this.httpOptions = httpOptions;
|
|
||||||
this.httpPost = httpPost;
|
|
||||||
this.normalizePath = normalizePath;
|
this.normalizePath = normalizePath;
|
||||||
this.request = request;
|
this.request = request;
|
||||||
|
this.http = {
|
||||||
|
get: httpGet.bind(this),
|
||||||
|
options: httpOptions.bind(this),
|
||||||
|
post: httpPost.bind(this),
|
||||||
|
put: httpPut.bind(this)
|
||||||
|
};
|
||||||
|
|
||||||
this.model = {};
|
|
||||||
this.path = this.normalizePath(path);
|
this.path = this.normalizePath(path);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
const ENCRYPTED_VALUE = '$encrypted$';
|
||||||
|
|
||||||
let BaseModel;
|
let BaseModel;
|
||||||
|
|
||||||
function createFormSchema (method, config) {
|
function createFormSchema (method, config) {
|
||||||
method = method.toUpperCase();
|
let schema = Object.assign({}, this.get('options', `actions.${method.toUpperCase()}`));
|
||||||
|
|
||||||
let schema = Object.assign({}, this.get(`actions.${method}`));
|
|
||||||
|
|
||||||
if (config && config.omit) {
|
if (config && config.omit) {
|
||||||
config.omit.forEach(key => {
|
config.omit.forEach(key => {
|
||||||
@ -13,17 +13,33 @@ function createFormSchema (method, config) {
|
|||||||
|
|
||||||
for (let key in schema) {
|
for (let key in schema) {
|
||||||
schema[key].id = key;
|
schema[key].id = key;
|
||||||
|
|
||||||
|
if (method === 'put') {
|
||||||
|
schema[key]._value = this.get(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
function CredentialModel (method, id) {
|
function assignInputGroupValues (inputs) {
|
||||||
|
return inputs.map(input => {
|
||||||
|
let value = this.get(`inputs.${input.id}`);
|
||||||
|
|
||||||
|
input._value = value;
|
||||||
|
input._encrypted = value === ENCRYPTED_VALUE;
|
||||||
|
|
||||||
|
return input;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function CredentialModel (method, resource) {
|
||||||
BaseModel.call(this, 'credentials');
|
BaseModel.call(this, 'credentials');
|
||||||
|
|
||||||
this.createFormSchema = createFormSchema.bind(this);
|
this.createFormSchema = createFormSchema.bind(this);
|
||||||
|
this.assignInputGroupValues = assignInputGroupValues.bind(this);
|
||||||
|
|
||||||
return this.request(method, id)
|
return this.request(method, resource)
|
||||||
.then(() => this);
|
.then(() => this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,11 +26,18 @@ function mergeInputProperties (type) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getById (id) {
|
||||||
|
let type = this.get('results').filter(type => type.id === id);
|
||||||
|
|
||||||
|
return type ? type[0] : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function CredentialTypeModel (method, id) {
|
function CredentialTypeModel (method, id) {
|
||||||
BaseModel.call(this, 'credential_types');
|
BaseModel.call(this, 'credential_types');
|
||||||
|
|
||||||
this.categorizeByKind = categorizeByKind.bind(this);
|
this.categorizeByKind = categorizeByKind.bind(this);
|
||||||
this.mergeInputProperties = mergeInputProperties.bind(this);
|
this.mergeInputProperties = mergeInputProperties.bind(this);
|
||||||
|
this.getById = getById.bind(this);
|
||||||
|
|
||||||
return this.request(method, id)
|
return this.request(method, id)
|
||||||
.then(() => this);
|
.then(() => this);
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
let BaseModel;
|
let BaseModel;
|
||||||
|
|
||||||
|
function getSelf () {
|
||||||
|
return this.get('results[0]');
|
||||||
|
}
|
||||||
|
|
||||||
function MeModel (method) {
|
function MeModel (method) {
|
||||||
BaseModel.call(this, 'me');
|
BaseModel.call(this, 'me');
|
||||||
|
|
||||||
|
this.getSelf = getSelf.bind(this);
|
||||||
|
|
||||||
return this.request(method)
|
return this.request(method)
|
||||||
.then(() => this);
|
.then(() => this);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user