Skip to content
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

added ability to provide fetch service params and options view the cr… #22

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
use get() for getting modelName from options
roncodes committed Nov 15, 2023
commit 0684ca5ce0d41a8c515dfd5c5c1af22419310972
8 changes: 4 additions & 4 deletions addon/services/crud.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Service from '@ember/service';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { action, get } from '@ember/object';
import { isArray } from '@ember/array';
import { dasherize } from '@ember/string';
import { later } from '@ember/runloop';
@@ -48,7 +48,7 @@ export default class CrudService extends Service {
* @void
*/
@action delete(model, options = {}) {
const modelName = getModelName(model, getWithDefault(options, 'modelName'), { humanize: true, capitalizeWords: true });
const modelName = getModelName(model, get(options, 'modelName'), { humanize: true, capitalizeWords: true });

this.modalsManager.confirm({
title: `Are you sure to delete this ${modelName}?`,
@@ -99,7 +99,7 @@ export default class CrudService extends Service {
}

const firstModel = first(selected);
const modelName = getModelName(firstModel, getWithDefault(options, 'modelName'), { humanize: true, capitalizeWords: true });
const modelName = getModelName(firstModel, get(options, 'modelName'), { humanize: true, capitalizeWords: true });

// make sure all are the same type
selected = selected.filter((m) => getModelName(m) === getModelName(firstModel));
@@ -127,7 +127,7 @@ export default class CrudService extends Service {
}

const firstModel = first(selected);
const modelName = getModelName(firstModel, getWithDefault(options, 'modelName'), { humanize: true, capitalizeWords: true });
const modelName = getModelName(firstModel, get(options, 'modelName'), { humanize: true, capitalizeWords: true });
const count = selected.length;
const actionMethod = (typeof options.actionMethod === 'string' ? options.actionMethod : `POST`).toLowerCase();
const fetchParams = getWithDefault(options, 'fetchParams', {});