Angularfire $save array - angularjs

I'm trying to save a collection of data after i have updated an entry in the array.
// Edit a post
$scope.editMe = function(message) {
if($scope.textBoxMessage = "What good did you do today?"){
$scope.textBoxMessage = "Here you can edit your post by entering a new message and pressing edit on the affected post" + "\n \n" + "Your post:" + "\n" + message.post;
}
else{
$scope.message.post="hello"; //$scope.newMessage
$scope.messages.$save(2);
}
}
Ones a user have entered some text in a textfield i want to replace that with the already stored data. This by overwriting message.data with sometext. Since i read in data like this:
var list = fbutil.syncArray('posts/'+user.uid);
i also tried to simply say:
message.post = $scope.newMessage;
list.$save()
Neither of these two methods work but i'm sure it's a minor mistake.
ED:
According to angularFire api, visit: https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-firebasearray-save-recordorindex
list[2].post = "hello";
list.$save(2);
should work but i have had no luck.

Okay here is how i solved it:
The problem had more to do with the if else statement then with the server code itself. The $scope.textBoxMessage is always true no matter what and this is what bothered me. Even if i say if($scope.textBoxMessage = "hi") it will be true.
I'm not sure why this is the case but feel free to comment if you have any suggestions.
This is how i solved it:
// Edit a post
$scope.editMe = function(message) {
if($scope.newMessage == null){
$scope.textBoxMessage = "Here you can edit your post by entering a new message and pressing edit on the affected post" + "\n \n" + "Your post:" + "\n" + message.post;
}
else{
message.post = $scope.newMessage;
list.$save(message);
$scope.textBoxMessage = chatmessage;
$scope.newMessage = null;
}
}

Related

How to prevent dataprovider from printing the sensitive data such as login credentials on to the console?

whenever we use dataprovider in our tests , the test data which is being used will also gets print on the console, how can we disable this functionality ? Can anyone pls help me on this ?
eg:
#Test(dataProvider = "data-provider", dataProviderClass = DataProviderClass.class)
public void testMethod(String data)
{
System.out.println("Data is: " + data);
}
#DataProvider(name = "data-provider")
public static Object[][] dataProviderMethod()
{
return new Object[][] { { "data one" }, { "data two" } };
}
o/p:Data is: data one
Data is: data two
PASSED: testMethod(“data one”)
PASSED: testMethod(“data two”)
here the testdata which is being used is also getting printed ,how can we disable this functionality?
A data provider has no functionality of printing anything. Its your print statement inside the Test method that is printing the data. If you don't want to print anything to the console, remove the
System.out.println("Data is: " + data);
from the test method definition.
I'm pretty sure your issue is something else as the problem statement is quite obvious. Feel free to update the question.

Bugzilla's "Request System": do other issue tracking tools have it?

I've used Bugzilla for many years and one of my favourite features is the "request system" (http://www.bugzilla.org/features/#rs), also known as "flags". The issue can flagged (?) to a user; the user can then accept the request (+) or deny it (-).
I am in the process of re-evaluating our issue tracking tools and I can't seem to find anything other than Bugzilla that has this feature.
So I am wondering:
Does any other product offer similar functionality?
And if not, then is there a way to mimic it (using labels or custom fields or something)?
Your advice is appreciated (FYI: I am currently leaning towards YouTrack).
Alex V. asked for more details about Bugzilla's request system functionality. Here's an example:
An arbitrary list of flags can be created in the admin interface. When editing an issue, they are listed in a row, here's an example:
Next, someone can set the flag and ask for a followup. The screen shot shows me (dcherk) setting the DJiNNInput flag for john#doe.com:
Note that the same flag can be requested multiple times (not shown).
Later, john#doe.com might act on the flag in some way and mark the request as accepted:
Alternatively, john#doe.com might not be able to accept the request. In that case, he would deny it:
Needless to say, all these changes are tracked in the issue history, and can be searched and reported on.
In YouTrack there's no such functionality. What you can do, however, is you can Star the issue for a user as if the if the user did it themselves. They will then receive a notification about it and can either leave the star on the issue, or remove it.
Don't know exactly how those flags work in Bugzilla, so it's is probably not a complete replacement of that feature. If you elaborate on the desired behaviour, I'll let you know how (if possible) to completely mimic it.
FYI:
This is what we ended up doing in YouTrack:
Created two user[*] fields:
Input Requesting (i.e. the person requesting input)
Input Requested (i.e. the user whose input is needed)
The users can always set these fields manually, but we also added the following workflow rules to speed things up:
Rule 1, relates changes to the two field:
rule Input Requested
when Input Requested.changed {
if (Input Requested.isEmpty) {
Input Requesting.clear;
} else {
Input Requesting.add(loggedInUser);
}
}
Rule 2, closed issues do not need any more input:
rule Clear Input Requests When Issue Becomes Closed
when State.becomes({Closed}) {
Input Requested.clear;
Input Requesting.clear;
}
Rule 3, #mentioning sets the fields; replying clears the fields:
rule Input Requested via #mention
when comments.added.isNotEmpty {
var separators = " `!#%^&*()=[]{}:;'\"\\|,<>/?\n\r\t";
var mentionedUsers = "";
var myComment = comments.added.first;
var originalText = myComment.text;
var text = " " + originalText.lowerCase + " ";
var username = "";
var user = loggedInUser;
var index = -1;
index = text.indexOf("#", opts);
while (index != -1) {
index = index + 1;
username = "";
var nextSymbol = text.substring(index, index + 1);
while (!separators.contains(nextSymbol, opts)) {
username = username + nextSymbol;
index = index + 1;
nextSymbol = text.substring(index, index + 1);
}
if (username.endsWith(".", opts)) {
username = username.substringOfLength(username.length - 1, opts);
}
debug("Extracted #username: |" + username + "|");
if (username.isNotEmpty) {
user = project.getUser(username);
if (user != null && !mentionedUsers.contains("#" + user.login + ",", ignoreCase) && (user.isInGroup(permittedGroup.name) || permittedGroup == null || user == reporter) && (myComment.permittedGroup == null || user.isInGroup(myComment.permittedGroup.name))) {
if (Input Requesting.contains(user)) {
Input Requested.remove(loggedInUser);
if (Input Requested.isEmpty) {
Input Requesting.clear;
}
} else {
Input Requested.add(user);
Input Requesting.add(loggedInUser);
}
mentionedUsers = mentionedUsers + "#" + user.login + ",";
}
}
text = text.substringRelative("#" + username, pos: after);
index = text.indexOf("#", opts);
}
}
Hope that helps anyone along the way.

Arrays and if statements. How to check if value is in array? *javascript*

So I have a program that sends emails. The user has a list of emails that cannot be sent to. These are in arrays and I need to use a if statement to determine if what the user entered in is in the array of emails. I tried the in function which didnt work but Im probably just using it wrong. I tried for loops and if statements inside. But that didnt work either. Here is a snapshot of the code Im using to help you get the idea of what im trying to do.
function test2(){
var safe = [1]
safe[1] = "lol"
safe[2] = "yay"
var entry = "lol"
Logger.log("entry: " + entry)
for(i = 0; i < safe.length; i++){
if(entry == safe[i]){
Logger.log("positive")
}else{
Logger.log("negative")
}
}
}
Here is what I tried with the in function to show you if I did it wrong
function test(){
var safe = [1]
safe[1] = "lol"
safe[2] = "yay"
var entry = "losl"
Logger.log("entry: " + entry)
if(entry in safe){
Logger.log("came positive")
}else{
Logger.log("came negative")
}
Logger.log(safe)
}
array.indexOf(element) > -1 usually does the trick for these situations!
To expand upon this:
if (array.indexOf(emailToSendTo) < 0) {
// send
}
Alternatively, check this cool thing out:
emailsToSend = emailsToSend.filter(function(x) {
// basically, this returns "yes" if it's not found in that other array.
return arrayOfBadEmails.indexOf(x) < 0;
})
What this does is it filters the list of emailsToSend, making sure that it's not a bad email. There's probably an even more elegant solution, but this is neat.

in the dark about ajax instructions on arrays inside Autocomplete widget

I have an Autocomplete working with geonames.org cities in the source: option and want to manipulate some of the arrays in the results. I have a "hard coded" test version running, but am having trouble manipulating the array variables to turn it into something useful.
A short statement of the problem is I can't get the alert statements to output readable strings. I get [object, Object] types of output. I need readable strings in the arrays for other code (not shown) to work. But other problems are: the Firebug Console output does not occur, and the Console gives me the following error statement - Error: Permission denied to access property 'item.autocomplete' - from line 2 of jQuery. This does not happen with the hard coded test. This is my first time using .grep and I'm not comfortable with .map, so I'm pretty sure the problems are array manipulations in those 3 sections.
Here's some relevant code. All the variables are declared, but I don't show all the declarations below.
citiesWithBoroughs = //a global array variable, populated in a prior select: option
source: function (request, response){
$.ajax({
success: function ( data ){
var geonamesResponse=$.map(data.geonames, function (item){
return {
label: item.name //and others
}
}
alert(citiesWithBoroughs + "," + citiesWithBoroughs.length + "|cWB2" ); //displays correct info
var noBoroughs=$.grep( geonamesResponse, function ( item, i ) {
for (var i=0; i < citiesWithBoroughs.length; i++ )
if( item.label === citiesWithBoroughs[i] ){ //compare geonamesResponse to each citiesWithBoroughs
console.log(citiesWithBoroughs[i]); //nothing in Console
return false; //drop any matches out of the geonamesResponse array
}
noBoroughs = $.map( data.geonames, function (item){ return item.label; });
console.log(noBoroughs); //nothing appears in Console
return true;
});
alert(noBoroughs.length + "," + citiesWithBoroughs.length + "," + geonamesResponse.length + "|3lengths" ); //correct info
alert(noBoroughs + "|nB" ); //in test, shows correct number of [object,Object] but no data
if( noBoroughs.length != geonamesResponse.length ){
var dropdownsCityWithBoroughs = $.grep( geonamesResponse, function ( item, i ) {
for (var i=0; i<citiesWithBoroughs.length; i++ )
if(item.label === citiesWithBoroughs[i]){return false;}
return true;
}, true )//true inverts grep to return the has-Boroughs city in the dropdown
alert(dropdownsCityWithBoroughs + "|dCWB"); //contains object, Object, but shows no data
}
}
}
}
I'm a novice so please give specific comments and code. I don't follow general instructions well.
The short statement of my problem was I could not read the output of my alerts, which contain arrays. Turns out JSON.stringify() fixes that. Other problems, like the Console.log statements not showing continue, but I can deal with that mysterious problem when the alerts work.

data comparision fails even though the value is same

I am working on a code for a quiz test, here
function run($id){
//Is this the first question ?
if($this->data){
$question_no = $this->Session->read('Test.qno'); //0
$last_answer = $this->Session->read('Test.last_answer');
$question_no = $question_no + 1; //1
$this->Session->write('Test.qno',$question_no); //Test.qno = 1
$this->Session->setFlash('last_answer'.$this->data['Test']['answer']);
$this->redirect($this->referer());
if($this->data['Test']['answer']==$last_answer){
$score = $this->Session->read('Test.score');
$score = $score + 1 ;
$this->Session->write('Test.score',$score);
$this->Session->setFlash('Correct answer');
}
}
$question_no = $this->Session->read('Test.qno'); //question_no =
if(!$question_no){
$question_no = 0;
$this->Session->write('Test.qno',$question_no);
$this->Session->write('Test.score',0);
}
$question = $this->Test->Question->find('first',array('conditions'=>array('Question.test_id ='=>$id),'offset'=>$question_no));
$answer = $question['Question']['answer'];
$this->Session->write('Test.last_answer',$answer);
if(empty($question)){
$score = $this->Session->read('Test.score');
$this->Session->setFlash('Your Score is '.$score);
$this->Session->write('Test.qno',0);
$this->redirect(array('controller'=>'States','action'=>'index'));
}
else{
$this->set(compact('question'));
}
}
here data comparison fails even though they both hold the same value can some one tell me why,here $last_answer is retrieved from session and holds a number.
$this->data['Test']['answer'] is taken from a form with radio button's
Add
debug( '"'.$this->data['Test']['answer'].'"' );
debug( '"'.$last_answer.'"' );
to confirm they really are the same.
Also make sure it's not a problem with sessions (i.e. the condition is true, but the code inside doesn't do anything): add debug( "true" ); inside the if block and confirm that you see the message.
UPDATE after seeing the whole code:
You have a $this->redirect() right before the if block! Of course the code you initially posted doesn't do anything because you redirect the user to another page before the execution even reaches it.

Resources