i am sending a query with expand to the server
var query = breeze.EntityQuery.from("Incidents")
.expand("IncidentComments")
.where("IncidentID", "eq", incidentId);
and in the http i an getting results which are ok, the entity with the related entity
how ever i cannot see the data when i return from the query in breeze
the IncidentComments has no comments
function getSucceeded(data) {
$scope.incident = data;
$scope.incidentComments = data.IncidentComments;
}
Assuming that "IncidentComments" is a property of "Incident", then the comments will be returned as such. So:
var query = breeze.EntityQuery.from("Incidents")
.expand("IncidentComments")
.where("IncidentID", "eq", incidentId);
var myEntityManager.executeQuery(query).then(function (data) {
var incidents = data.results;
var incident = incidents[0]; // because you are only returning one incident;
var incidentComments = incident.incidentComments;
});
Related
CommentCollection
{
"_id":"5b63f0f23846b70011330889",
"CommentType":"task",
"EntityReferenceId":"6082ef25-6f9a-4874-a832-f72e0f693409",
"Threads":[
{
"_id":"69bcef71-3695-4340-bdec-4a6e4c58c490",
"CommentType":"task",
"UserId":ObjectId("52ffc4a5d85242602e000000"),
"CommentByUserType":"Admin",
"EntityReferenceId":"6082ef25-6f9a-4874-a832-f72e0f693409",
"Content":"fdffd",
},
{
"_id":"69bcef71-3695-4340-bdec-4a6e4c58c490",
"CommentType":"task",
"UserId":ObjectId("52ffc4a5d85242602e000000"),
"CommentByUserType":"Admin",
"EntityReferenceId":"6082ef25-6f9a-4874-a832-f72e0f693409",
"Content":"fdffd",
}
]
}
Here I have to write a Mongodb filter query from asp.net core based on two conditions,
first I want to get CommentCollection by EntityReferenceId, then want to find the specific thread by id from the first result.
Any help will be appreciated.
I got the answer,I have wrote my method like below
public async Task<bool> UpdateCommentAsync(Threads thread)
{
var builder = Builders<Comments>.Filter;
var filter = builder.Empty;
var update = Builders<Comments>.Update.Set("Threads.$[i].Content", thread.Content);
var arrayFilters = new List<ArrayFilterDefinition> { new JsonArrayFilterDefinition<Threads>("{'i._id': '" + thread.Id + "'}") };
var updateOptions = new UpdateOptions { ArrayFilters = arrayFilters };
var result = await _context.Comments.UpdateManyAsync(filter, update, updateOptions);
return result.ModifiedCount > 0;
}
I"m binding my tile container in xml view as
<TileContainer id="idsolutionContainer" tiles="{ path: 'dlCourses>/DLES_COURSE_CONTENT' }">
<tiles>
<dles:DLESScoreTile name="{dlCourses>LJ_TITLE}" topicId="{dlesScore>ID}" topic="{dlCourses>LJ_SOLUTION}" dles="{dlCourses>DLES}" id="tileDLESCourse" press=".handleCourseClick"></dles:DLESScoreTile>
</tiles>
</TileContainer>`
and on the backend on inint fucntion I'm trying to filter by LJ_SOLUTION but it doesn't work. it gives me all the courses. I'm getting LJ_SOLUTION from query string that's why i'm not filtring on front end.
the code is as
var coursePath = "/DLES_COURSE_CONTENT";
var filterByName = new sap.ui.model.Filter('LJ_SOLUTION', 'EQ', 'Analytics')
//sPath = "/DLES_SOLUTION_CONTENT?$filter=LJ_SOLUTION eq '" + sId + "')";
var courses = oView.getModel("dlCourses");
var courseData = oModel.getData(coursePath);
oView.bindElement({
path: coursePath,
filters: [ new sap.ui.model.Filter("LJ_SOLUTION",sap.ui.model.FilterOperator.EQ, "Analytics") ],
model: "dlCourses",
events: {
dataRequested: function() {
oView.setBusy(true);
},
dataReceived: function() {
oView.setBusy(false);
}
}
});
The network tab...
there is another request batch I don't understand completely but the request query is as
var oView = this.getView();
var oSolutionJourneyList = oView.byId("idsolutionContainer");
var oBinding = oSolutionJourneyList.getBinding("tiles");
if (oBinding) {
var oFilter = new sap.ui.model.Filter("LJ_SOLUTION", 'EQ', 'Analytics');
oBinding.filter([oFilter]);
}
Please remove the code “var courseData = oModel.getData(coursePath);”
because this loads the entire model. The bindElement will also create a request to load the required data only. Then, check the request which is created by bindElement to see if the path for “LJ_Solution” is correct.
I'm using Q Promises to retrieve data from my redis repository. The problem I'm having, is that through each iteration, the array object (localEncounter) I'm using to store data returned from the chained functions is never updated at each iteration. Previously, I tried to solve this with a foreach loop and spread but the results were the same.
How should I correct this so that localEncounter is updated at each iteration, and ultimately localEncounters contains correct data when returned? Thank you.
var localEncounters = [];
var localEncounter = {};
Promise.all(ids.map(function(id) {
return localEncounter, getEncounter(id, client)
.then(function (encounter) {
encounterObject = encounter;
//set the fields for the return object
localEncounter['encounterid'] = encounterObject[f_id];
localEncounter['screeningid'] = encounterObject[f_screening_id];
localEncounter['assessmentid'] = encounterObject[f_clinical_assessment_id];
localEncounter['psychevalid'] = encounterObject[f_psych_eval_id];
//get screening
return getScreening(encounterObject[f_screening_id], client);
})
.then(function (screening) {
//set the fields for the return object
localEncounter['screeningbegintime'] = screening[f_begin_time];
//get assessment
return getAssessment(localEncounter['assessmentid'], client);
})
.then(function (assessment) {
//set the fields for the return object
localEncounter['assessmentbegintime'] = assessment[f_begin_time];
//get psycheval
//localEncounters.push(assessment);
return getPsychEval(localEncounter['psychevalid'], client);
})
.then(function (psychEval) {
//set the fields for the return object
localEncounter['assessmentbegintime'] = psychEval[f_begin_time];
localEncounters.push(localEncounter);
}
, function (reason) {
console.log(reason); // display reason why the call failed;
reject(reason, 'Something went wrong creating the encounter!');
})
})).then(function(results) {
// results is an array of names
console.log('done ');
resolve(localEncounters);
})
Solution: I only needed to move the declaration of localEncounter inside the map iterator
before:
var localEncounter = {};
Promise.all(ids.map(function(id) {
after:
Promise.all(ids.map(function(id) {
var localEncounter = {};
This now allows that each id iteration gets its own localEncounter object.
I'm new to breeze and I can't begin to imagine what's causing this to happen. This is a two part question:
1) My function is very simple. I'm querying with two predicates:
var getUserHealthMetricFromId = function (userId, healthMetricId, forceRemote) {
var p1 = new Predicate('userId', '==', userId);
var p2 = new Predicate('healthMetricId', '==', healthMetricId);
var query = EntityQuery.from('UserHealthMetrics').select('lowerValue', 'upperValue')
.where(p1.and(p2));
if (!forceRemote) {
//results = getUserHealthMetricFromLocal(userId, healthMetricId);
var query = query.using(breeze.FetchStrategy.FromLocalCache);
}
var promise = manager.executeQuery(query);
return promise;
};
While I'm debugging (Chrome) the first predicate declaration line, calling the Predicate ctor causes execution to jump to the following finally clause in Knockout-3.0.0.debug.js (line 1483):
finally {
ko.dependencyDetection.end();
_isBeingEvaluated = false;
}
When I execute the "_isBeingEvaluated = false" statement,
an exception is inexplicably thrown landing me here (line 2607):
} catch (ex) {
ex.message = "Unable to process binding \"" + bindingKey + ": " + bindings[bindingKey] + "\"\nMessage: " + ex.message;
throw ex;
}
Thinking this might have more to do with Knockout than with Breeze, I tested by altering the code by hardcoding the Id's so that the parameter variables (which are observables) aren't involved in calling the ctor anymore:
var p1 = new Predicate('userId', '==', 1);
var p2 = new Predicate('healthMetricId', '==', 4);
No dice. The same thing happens. When I try to step into Predicate() the same thing happens. I just throws me over to the knockout debug file.
2) In the same function, the variables I'm passing in are showing up as dependentObservables() in the debug window. These values are the product of another breeze call to the server. Why would breeze render these as dependentObservables instead of plain observables (I do not declare any computeds anywhere in the code)? Here's a quick overview of my code:
In the view model:
var latestEntriesObservable = ko.observableArray(null);
function activate() {
$('#rangeDialog').hide();
var promise = Q.all([datacontext.getLatestEntries(latestEntriesObservable, currentUserId, false),
datacontext.getUserHealthMetrics(userHealthMetricsObservable, currentUserId, false),
datacontext.getUserHealthMetricNames(userHealthMetricNamesObservable, currentUserId, false)]);
return promise;
}
var getLatestEntries = function (latestEntriesObservable, userId, forceRemote) {
var lastEntryQuery = EntityQuery.from('LatestEntries').withParameters({ id: 1 });
if (!forceRemote) {
var e = getLocal('HealthMetricValues', 'healthMetricId');
if (e.length > 0) {
latestEntriesObservable(e);
return Q.resolve();
}
}
return manager.executeQuery(lastEntryQuery)
.then(querySucceeded)
.fail(queryFailed);
// handle the ajax callback
function querySucceeded(data) {
if (latestEntriesObservable) {
latestEntriesObservable(data.results);
//latestEntriesObservable(model.toProtectedObservableItemArray(data.results));
}
log('Retrieved latest entries.', data, true);
}
};
function getLocal(resource, orderBy) {
var query = EntityQuery.from(resource).orderBy(orderBy).withParameters({ id: 1 });
return manager.executeQueryLocally(query);
}
If I haven't provided enough code to help make a diagnosis I'll be happy to provide more upon request.
Any suggestions would be much appreciated!
Ok, I think the issue is that the class is actually breeze.Predicate. In order to save typing we often assign a local variable like this.
var Predicate = breeze.Predicate;
var p1 = new Predicate('userId', '==', 1);
or you can explicitly do this via
var p1 = new breeze.Predicate('userId', '==', 1);
or
var p1 = breeze.Predicate.create('userId', '==', 1);
Presumably, you are doing the same thing with EntityQuery, i.e.
var EntityQuery = breeze.EntityQuery;
I'm trying to create a loading spinner that will be displayed when breeze is communicating with the server. Is there some property in Breeze that is 'true' only when breeze is sending data to the server, receiving data, or waiting for a response (e.g. after an async call has been made but no response yet)? I thought of binding this data to a knockout observable and binding the spinner to this observable,
Thanks,
Elior
Use spin.js
http://fgnass.github.io/spin.js/
Its so simple..make it visible before you execute the query and disable it after the query succeeds or fails.
I don't see any property that is set or observable while Breeze is querying, but if you are using a datacontext, or some JavaScript module for your data calls, this is what you can do -
EDIT
Taking John's comments into account, I added a token'd way of tracking each query.
var activeQueries = ko.observableArray();
var isQuerying = ko.computed(function () {
return activeQueries().length !== 0;
});
var toggleQuery = function (token) {
if (activeQueries.indexOf(token) === -1)
{ activeQueries.push(token); }
else { activeQueries.remove(token); }
};
var getProducts = function (productsObservable, forceRemote) {
// Don't toggle if you aren't getting it remotely since this is synchronous
if (!forceRemote) {
var p = getLocal('Products', 'Product','product_id');
if (p.length > 0) {
productsObservable(p);
return Q.resolve();
}
}
// Create a token and toggle it
var token = 'products' + new Date().getTime();
toggleQuery(token);
var query = breeze.EntityQuery
.from("Products");
return manager.executeQuery(query).then(querySucceeded).fail(queryFailed);
function querySucceeded(data) {
var s = data.results;
log('Retrieved [Products] from remote data source', s, true);
// Toggle it off
toggleQuery(token);
return productsObservable(s);
}
};
You will need to make sure all of your fail logic toggles the query as well.
Then in your view where you want to place the spinner
var spinnerState = ko.computed(function () {
datacontext.isQuerying();
};