use the return value of function in protactor - promise

How Do I user the row value to pass UI Input?
I am trying to retrieve data from DB and using in UI. By using following, getting row but want make function and function return value will be use as input
Please need help on this.
function (done) {
//var query= "SELECT name FROM partstatus where rand() limit 1";
var query = "select part from parttable order by RAND() limit 1;"
conn.result(query).then(function(rows){
// This function get called, when success
console.log("Looks:",rows);
done();
},function(error){
// This function get called, when error
console.log(error);
done.fail(error);
});
}

You need to first select the input element of your HTML and then send the text that you fetch from database, using something like:
element(by.model('greeting')).sendKeys('Hello, E2E Tests');
This will get the HTML element bound to model 'greeting' and then put the text passed to sendkeys() to the HTML element.

Related

Dump within map function in Laravel

Within a map function i would like to use dd(); dump but i only get the first object.
When i use print_r(); within a map function i get all objects
$valeurCategorieCible = $CategoriesItineraires->map(function ($item) {
return $item->ciblesParCategorie->map(function ($ciblesParCategorie) {
return $ciblesParCategorie->cibles->map(function ($items) {
print_r($items); // Return all objects
dd($items); // Return only the first object then stop !
});
});
});
According to the documentation for dd() it "dumps the given variables and ends execution of the script" - the important part is "ends execution of the script"!
If you don't want to end execution use dump() instead of dd()

Updating a collection and returning it

I want to update a collection before looping through it.
Is there a way to set the sent value of the emails collection to true and return the collection before actually looping through it.
$emails = Email::where('sent', false);
$emails->update(array("sent" => true));
foreach ($emails as $email) {
//send email
}
I want to be able to call ->get() somewhere but I cant do it on the update or the initial query
Don't forget to call get on the Email::where('sent', false) that is an Illuminate\Eloquent\Builder instance.
You can use something like this:
tap(Email::where('sent', false)->get(), function ($emails){
Email::whereIn('id', $emails->pluck('id')->all())->update(['sent' => true]);
})->each(function($email){
// Send email
});
The tap function accepts two arguments, first one is a value that you want to run the second argument(which is a callback) on it, then the tap function returns you that first passed value and here you can easily loop through.
See Here for tap

how to load different data tables in different tabs?

i am using laravel data tables to generate different data table on different tabs. but it runs only query of first data table rendered to the page.i already have attached scope to data table to generate different results for different condition
i have attached ajax() method to the data table that are not displayed in the beginning of the page
controller file
public function index(UpcomingReservationDataTable $UpcomingReservationDataTable)
{
return $UpcomingReservationDataTable->render('admin.reservations.index');
}
public function getAllReservationTable(ReservationDataTable $ReservationDataTable){
return $ReservationDataTable->render('admin.reservations.index');
}
public function getPastReservationDataTable(PastReservationDataTable $PastReservationDataTable){
return $PastReservationDataTable->addScope(new PastReservationScope)->render('admin.reservations.index');
}
pastreservationdatatable query
public function query(Reservation $model)
{
return $model->newQuery()->where('pickup_date','<',date('Y-m-d'))->orderBy('id','desc')->with('customer','package','vehicle');
}
You can show first table in load tab and next change it by ajax.
You must write a function in javascript. This function should take a value. This value contains your query information. When this is clicked on any tab, this function must be executed with that value. The function of this function is to send information to the server, receive and display. Did you do these things?
The next issue is when the Ajax data is sent, if the server path is wrong, you will encounter an error. To view errors on your browser, press the combination keys CTR + Shift + i and in the menu at the top of the window, select the console to display the errors.

How can i pass other data in other function in my controller to view using CI

how can i pass a value from my query to the same view in CI. I am having a situation of like this:
public function index() {
$myinfo = $this->Myprofile_model->mydata();
$data['myinfo'] = $myinfo
$this->load->view('header');
$this->load->view('myprofile',$data);
$this->load->view('footer');
}
public function getResults($id) {
$fetchdata = $this->Myprofile_model->fetchresult($id);
$data['userselect'] = $fetchdata;
$this->load->view('myprofile',$data);
}
i already load my wholepage in index. and now i want to make another function to my button which is the getResults($id) function in my controller, and i want to display my another data from database to the same page. When i do the top code, my view is duplicating, because i loaded the $this->load->view('myprofile',$data); twice.
1: Create helper function and use that function on view page.
OR
If you want records for single id then merge both function in one.
If there is many ids and you want to fetch records on click for each id then you can use ajax.
$( document ).ready(function() {
$('.class_name').click(function(){
// place your code here to fetch records.
// on success you can display the result on same page
})
});
I am Not getting clearly but here is the controller to load multiple data on view:
public function index($id) {
$myinfo = $this->Myprofile_model->mydata();
$fetchdata = $this->Myprofile_model->fetchresult($id);
$this->load->view('header');
$this->load->view('myprofile',['myinfo'=>$myinfo,'fetchdata'=>$fetchdata]);
$this->load->view('footer');
}
You can use
$this->load->view('myprofile',['myinfo'=>$myinfo,'fetchdata'=>$fetchdata,'third_data'=>$third_data.. as many as you like]);
Here in your code you are passing an id to the getResults function so if you would like to load the data form this function you can do the same with this function. or pass the id to the same index function to get the result.

setCallbackHandler function with multiple inputs

I am sure there is a simple answer to this one, I'm just too new to Ajax to see it.
I am using CF 9 and i am trying to setup the callbackfuntion to take multiple inputs, however, I don't know the default name of the results from the ajax call.
here is what works:
var mySSN = document.getElementById("SSN");
var cfc = new myajax();
cfc.setCallbackHandler(UpdateValidationNotes);
cfc.ValidateSSN(mySSN.value);
And here is what i am trying to do:
var mySSN = document.getElementById("SSN");
var cfc = new myajax();
cfc.setCallbackHandler(UpdateValidationNotes(MyField, AjaxResults);
cfc.ValidateSSN(mySSN.value);
However, i don't know how to reference the ajax results since the callback handler is doing it automagically. Can anyone help out the lose newbie?
Thanks
Give a try like this,
var mySSN = document.getElementById("SSN");
var cfc = new myajax();
cfc.setCallbackHandler(function(AjaxResults) {UpdateValidationNotes(MyField, AjaxResults);});
cfc.ValidateSSN(mySSN.value);
The callback handler function can only take one argument, which will be passed to your handler function automagically. This will be the return value from the CFC that the proxy has deserialized from JSON to a JavaScript representation.(see CFAjaxProxy docmentation)
When you call setCallbackHandler, you just pass the function with no arguments.
It looks like you are trying to determine which field you just validated to possibly display a notice if it doesn't validate. In such cases, what I do is submit the field name to the server and have the server return it back in the response.

Resources