Get Current value of a Firebase Node? (Using AngularJS) - angularjs

Trying to update the information in a node by adding an amount to the current value. I can't find a way to reference the current value so I can add my value. How can you call the current value?
.update({total: "current-value?" + $scope.user.amount}).then(function() {
});

As it looks like you might not be able to pull the current value of a node without using a function, that is what I did:
snap.ref().child('gold/total').transaction(function(currentVal) {
return (currentVal || 0) + $scope.user.amount;
});
The current value of the node is captured with "currentVal", and then it can be passed along so that the addition can be performed.

Related

Why is my object not changing when I reassign properties in a forEach loop?

I am fetching an array of objects from an RX/JS call from an http backend. It returns an object which I am then trying to work with. I am making changes to this object using a for loop (in this example I am trying the .forEach because I have tried a number of different things and none of them seem to work.
When I run the code, I get a very weird problem. If I return the values of the properties, I get the new values (i.e. correctionQueued returns as true, etc.) but in the very next line, when I return the object, those same values are the same as the original (correctionQueued === false, etc.) HOWEVER, correctionStatus (which does not exist on the original object from http) sets just fine.
I don't understand how
array[index].correctionQueued can return true, but
array[index] returns an object with correctionQueued as false.
After the loop, the original array (checklistCopy) is identical to the object before the forEach loop, except the new property (correctionStatus) is now set, but all properties that I changed that were part of the original object remain as they were.
I have tried using a for of, for in, and .forEach. I have used the index to alter the original array, always the same result. Preexisting properties do not change, new properties are added. I have even tried working on a copy of the object in case there is something special about the object returned from rxjs, but to no avail.
checklistCopy.forEach((checklistItem, index, array) => {
if (checklistItem.crCode.isirName === correctionSetItem) {
array[index].correctionQueued = true;
array[index].correctionValue = mostRecentCorrection.correctionValue;
array[index].correctionStatus = mostRecentCorrection.status;
console.log(array[index].correctionQueued, array[index].correctionValue, array[index].correctionStatus);
console.log(array[index]);
}
}
);
I don't get an error, but I get..
Original object is:
correctionQueued: false;
correctionValue: JAAMES;
--
console.log(array[index].correctionQueued, array[index].correctionValue, array[index].correctionStatus);
true JAMES SENT
but when I print the whole object:
console.log(array[index]);
correctionQueued: false;
correctionValue: JAAMES;
correctionStatus: "SENT'; <-- This is set correctly but does not exist on original object.
console.log(array[index]) (at least in Chrome) just adds the object reference to the console. The values do not resolve until you expand it, so your console log statement is not actually capturing the values at that moment in time.
Change your console statement to: console.log(JSON.stringify(array[index])) and you should discover that the values are correct at the time the log statement runs.
The behavior you are seeing suggests that something is coming along later and changing the object properties back to the original value. Unless you show a more complete example, we can't help you find the culprit. But hopefully this answers the question about why your logs show what they show.
Your output doesn't make sense to me either but cleaning up your code may help you. Try this:
checklistCopy.forEach(checklistItem => {
checklistItem.correctionQueued = checklistItem.crCode.isirName === correctionSetItem;
if (checklistItem.correctionQueued) {
checklistItem.correctionValue = mostRecentCorrection.correctionValue;
checklistItem.correctionStatus = mostRecentCorrection.status;
console.log('checklistItem', checklistItem)
}
}
);

nginx module to set variable value for log module

I want to define an nginx variable, set its value during a request, and use the variable inside a log format.
I am currently implementing a custom module in C (not interested in LUA at the moment).
Desired flow:
1. configure new log format: log_format my_format '$my_var1'; (nginx.conf)
2. configure new access log using that format: access_log /tmp/out my_format (nginx.conf)
3. set value during request handler, function from the following type:
typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);
Current flow:
1. Set variable to an initial value: set $my_var1 'empty_value'; (nginx.conf)
2. Find variable by index with ngx_http_get_flushed_variable(r, index)
3. Change variable value by assigning to data field.
When I print my variable to the debug log, I see the variable is set correctly to the changed value. However, the log module outputs the initial variable value instead of the changed value to the custom access log.
Can someone point me to what am I missing here?
Should I use ngx_http_add_variable function or use script compile /complex ?
short snippet from the current flow described above:
ngx_http_variable_value_t *v;
v = ngx_http_get_flushed_variable(r, ale_srv_cf->output_variable_index);
// ... error handling if not found ....
v->data = new_value;
v->len = new_value_length;

Create a json object storing only value in Angularjs

I have to store an object in my AngularJS code. The values that are to be stored are variables that are passed in a function that is called when a button is clicked.
The basic structure of the object is :
"TopNode" : {
"CreateNode" : {
"ChildNode": {
"LowestNodeOne": "LowestNodeTwo"
}
}
}
All the above variables are obtained from the function parameters. But the problem here is that when I write the variables in the above object, i.e
variableTop : {
variableCreate : {
variableChild : {
variableLowOne : "Value for LowestNodeTwo"
}
}
}
But this code return the variable name itself and not the value stored in it (except for the lowest value variable).
I'm also fine with storing the object as a key-value pair, where the name of the key would also be stored along with its value. But I'm not sure exactly how would the structure of such an object would be?
Any help would be appreciated. Thanks.
Not able to understand the first version of the problem .
Will Edit this answer if i get hold of the problem.
But for your second part of the problem , you can store JSON key value pairs in Hash map like this:
[parent] = parent.child1
[parent.child1] = parent.child1.child
[parent.child1.child] = value
Algo - Traverse map till a value of a key is not a key .
Note : Hash maps and JSON have their own use cases . Usage of Hash Maps as a hierarchical object is not recommended as if the number of child nodes increase there would be a performance hit while traversing to the desired node , Better you go with JSON approach.

How to get data from an upstream node in maya?

I have a maya node myNode, which creates a shadeNode, which inMesh attribute is connected to shapeNode.outMesh and has an attribute distance.
myNode.outMesh -> shapeNode.inMesh
myNode.distance = 10
Then i have a command, which works on the shape node, but requires the distance argument, which it does by iterating over the inMesh connections:
MPlugArray meshConnections;
MPlug inMeshPlug = depNodeFn.findPlug("inMesh");
inMeshPlug.connectedTo(meshConnections, true, false); // in connections
bool node_found = false;
for(uint i = 0; i < numConnections; i++) {
MPlug remotePlug = meshConnections[i];
myNode = remotePlug.node();
if(MFnDependencyNode(myNode ).typeName() == "myNode") {
node_found = true;
break;
}
}
MFnDependencyNode myDepNode(myNode);
MPlug distancePlug = myDepNode.findPlug("distance");
Now i get a problem, when applying another node (of another type) to myShape, because the dependency graph now looks like this:
myNode.outMesh -> myOtherNode.inMesh
myOtherNode.outMesh -> shapeNode.inMesh
myNode.distance = 10
I tried to remove the check for typeName() == "myNode", because i understood the documentation like there should be recursion to the parent node, when the next node return Mstatus::kInvalidParameter for the unknown MPlug, but i cannot reach the distance plug without implementing further graph traversion.
What is the correct way to reliably find an attribute of a parent node, even when some other nodes were added in between?
The command itself should use the distance Plug to either connect to myNode or to some plug which gets the value recursively. If possible i do not want to change myOtherNode to have a distance plug and correspondig connections for forwarding the data.
The usual Maya workflow would be to make the node operate in isolation -- it should not require any knowledge of the graph structure which surrounds it, it just reacts to changes in inputs and emits new data from its outputs. The node needs to work properly if a user manually unhooks the inputs and then manually reconnects them to other objects -- you can't know, for example, that some tool won't insert a deformer upstream of your node changing the graph layout that was there when the node was first created.
You also don't want to pass data around outside the dag graph -- if the data needs to be updated you'll want to pass it as a connection. Otherwise you won't be able to reproduce the scene from the graph alone. You want to make sure that the graph can only ever produce an unambiguous result.
When you do have to do DAG manipulations -- like setting up a network of connectiosn -- put them into an MPXCommand or a mel/python script.
I found the answer in an answer (python code) to the question how to get all nodes in the graph. My code to find the node in the MPxCommand now looks like this:
MPlugArray meshConnections;
MPlug inMeshPlug = depNodeFn.findPlug("inMesh");
MItDependencyGraph depGraphIt(inMeshPlug, MFn::kInvalid, MItDependencyGraph::Direction::kUpstream);
bool offset_mesh_node_found = false;
while(!depGraphIt.isDone()) {
myNode = depGraphIt.currentItem();
if(MFnDependencyNode(myNode).typeName() == "myNode") {
offset_mesh_node_found = true;
break;
}
depGraphIt.next();
}
The MItDependencyGraph can traverse the graph in upstream or downstream direction either starting from an object or a plug. Here i just search for the first instance of myNode, as I assume there will only be one in my use case. It then connects the distance MPlug in the graph, which still works when more mesh transforms are inserted.
The MItDependencyGraph object allows to filter for node ids, but only the numeric node ids not node names. I probably add a filter later, when I have unique maya ids assigned in all plugins.

Kendo TreeView: How to set Intermediate state Programmatically

I am trying to use Kendo TreeView with other controls. Each of the leaf node on tree opens a detail pane. When I select all the elements from detail pane, I set the state of that node as Checked
myTree.dataItem(node).set("checked", true);
and when all the items are un-selected, I set the state of node as unchecked.
myTree.dataItem(node).set("checked", false);
but if some of the items are selected, I want to show the state of node as Intermediate
how can I do that. I cant find anything in the documentation that can help me. The closest thing I found is
myTree.updateIndeterminate()
however, it is not doing the job. Apparently, it sets the state based on the state of child nodes. but in my case, there are no child nodes. I am dealing with leaf nodes here. Can I set the state of a leaf node as Intermediate ? if yes, how?
Couldn't find any help on this.
Ended up using the following approach
I am now finding the checkbox associated with that particular node and setting it's indeterminate value using jQuery.
function SetTreeNodeIndeterminate(nodeId, set) {
var uid = $("#" + nodeId).parents('li').attr('data-uid');
var node = myTree.findByUid(uid);
if (node.length == 0) return;
var checkBox = $("#_" + uid);
if (checkBox.length == 0) return;
checkBox.prop('indeterminate', set);
updateParentNodeState(node);
}
the following line makes sure that all the parents of a node are also marked as indeterminate
function updateParentNodeState(node) {
myTree.updateIndeterminate(node);
let parentNode = myTree.parent(node);
if (parentNode.length > 0)
updateParentNodeState(parentNode);
}

Resources