Cannot implement $.data.promise - jaydata

When I am integrating 2 modules then I am getting the following error:
Not implemented!: $data.Promise.then
I spend 2 days working on it.On local server its working but on my local system this error is coming.
Here is my code:
function getSelectedGridData(viewId,filterId,groupId){
// Declaration of variables
var resultArray=[];
var viewFieldArray=[];
var headerArray=[];
var headerString="";
var groupString="";
var innerFilterString="";
var outerFilterString="";
var swapFilter="";
offlinedb.view.toArray(function (View) {
................some code...........
// Fetch data from table 'document_header' and convert entity set into array
offlinedb.document_headers.toArray(function (header){
......some code............
});
}).then(function (startGroup){
offlinedb.grouping.toArray(function (Group) {
...some code.....
}).then(function (startFilter){
offlinedb.filters.toArray(function (Filter) {
..some code............
sqlitedb.transaction(function (sqliteTransation) {
...some code.....
});
});
});
});
}
My error is :
Not implemented!: $data.Promise.then
Exception {name: "Not implemented!", message: "$data.Promise.then", data: undefined, _getStackTrace: function}
jaydata.js:1880
Guard.raise jaydata.js:1880
$data.Class.define.then jaydata.js:9239
getSelectedGridData common.js:72
(anonymous function) common.js:348
Uncaught Not implemented!: $data.Promise.then

you need a promise libraray, jquery or q

put them in the shown order, it would work
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="http://include.jaydata.org/jaydata.js"></script>

Related

How to pass a key field as variable instead of hard-coded key value to OData operation?

I am calling the GetEntity OData read method from the SAP UI5 view controller and passing a key value in the request URL. I am getting the proper response from the back-end when I hardcode the key value.
However, when I try to pass the key value dynamically in a variable by appending it to the URL, it doesn't work. I get the following error
HTTP request failed 404
In below code, sGrant is the variable and it doesn't work. But if I replace the variable name with its value hard-coded in below code, for example, in the read method like this: "/GrantMasterSet('TY560003')", then it works:
var sGrant = this.byId("grantNbr").getValue();
var oMod = this.getOwnerComponent().getModel();
oMod.read("/GrantMasterSet('sGrant')", {
success: function(oData) {
var oJsonModel = new JSONModel();
oJsonModel.setData(oData);
this.getView().setModel(oJsonModel);
}.bind(this),
error: function(oError) {
MessageToast.show("Read Failed");
}
});
UI5 has a method to generate the right URI for you, no matter what is the data type of the key of your entity type.
The method is createKey of the sap.ui.model.odata.v2.ODataModel class. See its documentation
Inside your controller, use the following source code.
onInit: function () {
var oRouter = this.getOwnerComponent().getRouter();
oRouter.getRoute("routeName").attachPatternMatched( this.onPatternMatched , this );
},
onPatternMatched: function(oEvent){
var oParameters = oEvent.getParameters();
var oArguments = oParameters.arguments; // is not a function - without ()
var sKey = oArguments.id; // route parameter passed when using navTo
var oDataModel = this.getView().getModel(); // v2.ODataModel
oDataModel.metadataLoaded().then(function() {
var sPath = oDataModel.createKey("EntitySet", { Key: sKey });
this.getView().bindElement("/" + sPath);
}.bind(this)
);
}
Usually this is necessary in details pages, in order to apply element binding to a page. As the createKey method relies on the $metadata of your service, you must make sure that it is already loaded in your app. This can be achieved by using method metadataLoaded, provided in the snippet as well.
You should concatenate the variable to the rest of the string, like this:
oMod.read("/GrantMasterSet('" + sGrant + "')", {
Or, you can use a template literal, which comes down to the same thing (notice the backtics):
oMod.read(`/GrantMasterSet('${sGrant}')`, {
You should escape 'sGrant' so it can be evaluated.
It should be something like that :
var sGrant = this.byId("grantNbr").getValue();
var oMod = this.getOwnerComponent().getModel();
oMod.read("/GrantMasterSet("+sGrant+")", {
success: function(oData) {
var oJsonModel = new sap.ui.model.json.JSONModel();
oJsonModel.setData(oData);
this.getView().setModel(oJsonModel);
}.bind(this),
error: function(oError) {
MessageToast.show("Read Failed");
}
});

Protractor - "Failed: each key must be a number of string; got undefined"

this program is to retrieve the value from other .js file using Protractor.
FirstConnectDatabase.js - establish the DB connection and Query.
spec.js - retrieve the result from the above .js file.
getting the below Error
Failed: each key must be a number of string; got undefined
Can anyone help me on this.
**spec.js**
var dbConnect = require('./FirstConnectDatabase.js');
var AptNbr = new dbConnect;
var readAptNbr = AptNbr.Apts;
console.log('Enter the order #'+readAptNbr);
**FirstConnectDatabase.js**
var retrieveAptNbr = function mySQLDatabase()
{
var mysql = require('../../node_modules/mysql');
var Aptnumber="";
var connection = mysql.createConnection({
host: 'local',
user :'user',
password :'password',
database:'DB'
});
connection.connect(function(err){
if(err){
console.log("Error"+err)
}else{
console.log('DB is connected');
}
});
connection.query("select * from XXXX",function(err,rows) {
if (!err)
{
console.log("result is :", rows[0].AptNo);
var Apts = (function() {
var on = rows[0].Aptnumber;
return parseInt(on);
}());
}else{
console.log("Error"+err)
}
});
};
module.exports=retrieveAptNbr;
This error comes when we are fetching a string value from other JS file, where string is not present or may be our fetching statement is incorrect. In your case you also fetching value in 'on' variable, check if it is getting some string value or not.

Cannot read property 'sPath' of undefined error while performing .read() method

I am confused with the error I get while trying to do .read() method of the odata model.
Here is my model definition:
var oModel = new sap.ui.model.odata.ODataModel("/destination/sap/opu/odata/sap/ODataServer");
this.getView().setModel(oModel, "odata");
Here is the relevant method:
_read: function(aFilters) {
var oModel = this.getView().getModel("odata");
console.log("oModel",oModel);
oModel.read("/myEntitySet", {
filters: aFilters,
success: function(oData) {
console.log("oData",oData);
},
error: function(oError) {
console.log("oError",oError);
}
});
}
The model is defined and is displayed in console.
In the line where the .read() method is, I get the following error:
Uncaught TypeError: Cannot read property 'sPath' of undefined
I have never seen such behavior before. What do I do wrong?
I had an error in my aFilters array. Well,the problem was that aFilters wasn't array at all. After fixing this issue, the .read() method worked fine.

Unable to loadDatabase with lokiJs

I have trying to create a database with a collection added to this database and the changes saved to a IndexedDB.
Below is my code
Two controllers SaveController and LoadController.
myApp.controller('SaveController', ['$scope', 'Loki', function ($scope, Loki) {
// SAVE : will save App/Key/Val as 'finance'/'test'/{serializedDb}
// if appContect ('finance' in this example) is omitted, 'loki' will be used
var idbAdapter = new LokiIndexedAdapter('finance');
var db = new loki('ProjectDb', { adapter: idbAdapter });
var coll = db.addCollection('SampleCollection');
coll.insert({ SampleId: 'Sample text.....' });
db.saveDatabase(); // could pass callback if needed for async complete
}]);
and then in my LoadController i use the
myApp.controller('LoadController', ['$scope', 'Loki', function ($scope, Loki) {
var idbAdapter = new LokiIndexedAdapter('finance');
var db = new loki('ProjectDb', { adapter: idbAdapter, autoload: true });
db.loadDatabase({}, function (result) {
console.log(result);
});
alert(db.getCollection("SampleCollection"));
}]);
I get a null when i alert "alert(db.getCollection("SampleCollection"));" . It never enters the call back of the "loadDatabase" method.
Is there something that i am missing ?
IndexedDB in Browser
Here the page html
Edit for default localstorage implementation
I use the default implementation for loki js and i try to load the offline db is shows result as null every time even though the db exist
var offlineDb = new loki('DbOfflineNew');
offlineDb.loadDatabase({},function (result) {
console.log(result);
if (result == null) {
alert('loading for first time..');
}
else {
alert('existing load..');
}
});
Every time the alert "loading for first time.. " is fired.. Any thing i am missing here..?
Basically all your logic needs to be in the loadDatabase callback. If you try to console.log the collection before it's loaded it will be null. Many people fall in this trap.
In other words:
myApp.controller('LoadController', ['$scope', 'Loki', function ($scope, Loki) {
var idbAdapter = new LokiIndexedAdapter('finance');
var db = new loki('ProjectDb', { adapter: idbAdapter, autoload: true });
db.loadDatabase({}, function (result) {
console.log(result);
// put your log call here.
alert(db.getCollection("SampleCollection"));
});
}]);
Hope this helps.

How to get Meteor.Call to return value for template?

I've tried to understand this post regarding this concept, however, I'm failing to get it. I have the following simple setup:
/server/test.js
Meteor.methods({
abc: function() {
var result = {};
result.foo = "Hello ";
result.bar = "World!";
return result;
}
});
/client/myapp.js
var q = Meteor.call('abc');
console.log(q);
This structure returns to the console undefined.
If I change the myapp.js file to:
Meteor.call('abc', function(err, data) {
!err ? console.log(data) : console.log(err);
}
I receive the Object in my console.
Ideally this is what I'd like to be able to do, but it doesn't work, stating in the console: Cannot read property 'greeting' of undefined
/client/myapp.js
var q = Meteor.call('abc');
Template.hello.greeting = function() {
return q.foo;
}
Any help in passing the data from the server object into the template would be greatly appreciated. I'm still learning JavaScript & Meteor.
Thanks!
From the Meteor.call documentation:
On the client, if you do not pass a callback and you are not inside a stub, call will return undefined, and you will have no way to get the return value of the method. That is because the client doesn't have fibers, so there is not actually any way it can block on the remote execution of a method.
So, you'll want to do it like this:
Meteor.call('abc', function(err, data) {
if (err)
console.log(err);
Session.set('q', data);
});
Template.hello.greeting = function() {
return Session.get('q').foo;
};
This will reactively update the template once the data is available.
This happens because Npm.require has Async behavior. That's the reason that you have to write a callback for Meteor.call.
But there is a solution, just use install(mrt add npm) and you'll get a function named Meteor.sync(//...) with this you can do both games: sync and async in your Meteor.call().
Reference: http://www.sitepoint.com/create-a-meteor-app-using-npm-module/
You can get the return value of a Meteor method for use in a template by using a reactive variable. Check out the working demonstration on Meteorpad
I went for a ghetto solution. But, it works for me, which is what matters, to me. Below is my code, which, in concept, I think, solves OP's problem.
In the client's main.js:
Meteor.setInterval(function() {
confirmLogin();
}, 5000);
This runs the confirmLogin() function every five seconds.
The confirmLogin function (in the client's main.js):
function confirmLogin() {
Meteor.call('loggedIn', function (error, result) {
Session.set("loggedIn", result);
});
}
The loggedIn method (in the server's main.js):
loggedIn: function () {
var toReturn = false;
var userDetails = Meteor.user();
if (typeof userDetails["services"] !== "undefined") {
if (typeof userDetails["services"]["facebook"] != "undefined") {
toReturn = true;
}
}
return toReturn;
},
The relevant helper:
loggedIn: function () {
return Session.get("loggedIn");
}