We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to convert an ES5 custom adapter to an ES6 class to be used in aurelia synfusion bridge project

I am using aurelia skeleton-navigation esnext as a base.  The Aurelia Syncfusion Bridge is installed and working correctly as I have verified it using the grid remote data example.

My custom adapter is working fine in an ES5 but I am having trouble converting it to an es6 class that can be use as an import

I am using the grid remote data and replacing it with my custom adapter.  

Instantiating
this.OrdersList =  ej.DataManager({ // eslint-disable-line new-cap
url: dataurl,
adaptor: syncfusionDreamFactoryAdapter(),
});

My custom adapter is extending the your odata adapter.
Code:
var syncfusiondmSymbols = {};
syncfusiondmSymbols.operatorSymbols = {
"=": "equal",
"is not null": "notnull",
"is null": "isnull",
"is not in": "notin",
"is in": "in"
};

ej.data.fnOperators.like = function (actual, expected, ignoreCase) {
if (ignoreCase)
return (actual) && "LIKE" && (expected);

return actual > expected;
};
ej.data.fnOperators.notin = function (actual, expected, ignoreCase) {
if (ignoreCase)
return (actual) && "NOT IN " && (expected);

return actual > expected;
};

ej.data.fnOperators.in = function (actual, expected, ignoreCase) {
if (ignoreCase)
return (actual) && "IN" && (expected);

return actual > expected;
};

$.extend(ej.data.operatorSymbols, syncfusiondmSymbols.operatorSymbols);

var syncfusionDreamFactoryAdapter = new ej.ODataAdaptor().extend({
options: {
from: "table",
requestType: "json",
sortBy: "order",
select: "fields",
skip: "skip",
group: "group",
take: "limit",
search: "search",
count: "count",
where: "filter",
aggregates: "aggregates"
},
dreamFactoryodBiOperator: {
"<": " < ",
">": " > ",
"<=": " <= ",
">=": " >= ",
"==": " = ",
"=": " = ",
"!=": " != ",
"lessthan": " < ",
"lessthanorequal": " <= ",
"greaterthan": " > ",
"greaterthanorequal": " >= ",
"equal": " = ",
"notequal": " != ",
"like": " LIKE ",
"notnull": " IS NOT NULL ",
"isnull": " IS NULL",
"IS NOT NULL": " IS NOT NULL ",
"IS NULL": " IS NULL ",
"contains": " CONTAINS ",
"endswith": " ENDS WITH ",
"startswith": " STARTS WITH "
},
dreamFactoryUniOperator: {
"in": " IN ",
"notin": " NOT IN ",
"IS NOT IN": " IS NOT IN ",
"IS IN": " IS IN "
},
onPredicate: function (pred, query, requiresCast) {
// query._fromTable ="contact"
var returnValue = "",
operator, guid,
val = pred.value,
type = typeof val,
field = this._p(pred.field);
//field = field.replace(/^(|\)$/g, '');
if (val instanceof Date) {
val = "datetime'" + p.replacer(val).toJSON() + "'";
}

operator = this.dreamFactoryodBiOperator[pred.operator];
if (operator) {
returnValue += field;
returnValue += operator;
if (guid)
returnValue += guid;
return returnValue + val;
}

operator = this.dreamFactoryUniOperator[pred.operator];

if (!operator || type !== "string") return "";

returnValue += field;
returnValue += operator + "(";

if (guid) returnValue += guid;
returnValue += val + ")";

return returnValue
},
processResponse: function (data, ds, query, xhr, request, changes) {

var count = null, aggregateResult = {};

if (query && query._requiresCount) {
if (data.meta) count = data.meta.count;
}

data = data.resource;
return isNull(count) ? data : {result: data, count: count};

},
onCount: function (e) {
return e === true ? true : "";
},
beforeSend: function (dm, request, settings) {

var table = "", count = "", data = ej.parseJSON(settings.data);

if (data.table)
table = data.table;
if (data.count === true) {
delete data.count;
count = 'include_count=true';
}
settings.contentType = "application/json; charset=utf-8";
settings.url = settings.url + table + '?method=GET&' + count + '';

delete data.params;
delete data.requiresCounts;
settings.data = JSON.stringify(data)
}

});

var isNull = function (val) {
return val === undefined || val === null;
};

I have tried as a test exporting as a function your custom adapter example, but I get an error this.adaptor.processQuery is not a function

Any help is appreciated 


4 Replies

PO Prince Oliver Syncfusion Team January 6, 2017 01:41 PM UTC

Hi Dan, 

Thanks for contacting Syncfusion support. 

We tried to reconstruct your scenario with the code you shared. We are unable to reproduce the issue at our end. Kindly share an issue reproducing sample with replication step. It will help us isolate the root cause and provide you a solution. 
 
 
Regards, 
Prince 



DA dan January 6, 2017 04:17 PM UTC

Thank you for the sample.  I could not get it to run.  
First it complained about ej.signature.min.js missing

I figured this was just a mismatch in syncfusion-javascript vs aurelia-syncfusion-bridge, as I see in the latest syncfusion-javascript version you have ej.signature.min.js.
However after upgrading to the latest I get the below error.

TypeError: Cannot read property 'apply' of undefined
    at BasicUse.i [as syncfusionDreamFactoryAdapter] (http://localhost:9000/jspm_packages/github/syncfusion/JavaScript-Widgets@14.4.20/Scripts/ej/common/ej.data.min.js:10:15262)

I did update config.js packages to match the latest syncfusion-javascript version
   "common/ej.*": "jspm_packages/github/syncfusion/JavaScript-Widgets@14.4.20/Scripts/ej/common/ej.*.js",
    "datavisualization/ej.*": "jspm_packages/github/syncfusion/JavaScript-Widgets@14.4.20/Scripts/ej/datavisualization/ej.*.js",
    "ej.*": "jspm_packages/github/syncfusion/JavaScript-Widgets@14.4.20/Scripts/ej/web/ej.*.js",
    "syncfusion-javascript/*": "jspm_packages/github/syncfusion/JavaScript-Widgets@14.4.20/*"

Also I am using the latest aurelia-skeleton-navigation


PO Prince Oliver Syncfusion Team January 11, 2017 12:51 PM UTC

Hi Dan, 

Thanks for your update.  

We are unable to bind data from our demo OData service to the grid using custom adaptor with you provided. Please share us your sample along with replication steps. It will help us isolate the root cause and provide you a solution. 

Regards, 
Prince  



DA dan January 17, 2017 06:18 AM UTC

I have a test project and test server setup.  Can I send the project files to you in a private message?  The login info is for testing but I still like to keep the credentials private.

Loader.
Up arrow icon