lift template and snippet returning slick query result - lift

Please excuse if this is a very basic question, I'm learning. :(
I have this class:
class X {
def do_something {
db withSession {
val qresult = for {
(d, o) <- TABLE1 innerJoin TABLE2 on (_.TB1ID === _.TB2ID)
} yield(d, o)
}
}
}
and I would like to build a HTML table out of this, something like:
(record1) d.TB1ID d.F1VALUE d.F2VALUE o.F1VALUE o.F2VALUE o.TB2ID
(record2) d.TB1ID d.F1VALUE d.F2VALUE o.F1VALUE o.F2VALUE o.TB2ID
....
would anyone be kind enough to give me a pointer where to look? I've found plenty of examples but I have trouble connecting the qresult value to something I can bind in my template.
I am using Lift and Slick 1.0.1.

Assuming you have a table in your HTML template that looks like this:
<table>
<tr>
<td class="TB1ID"></td>
<td class="dF1VALUE"></td>
<td class="dF2VALUE"></td>
<td class="oF1VALUE"></td>
<td class="oF2VALUE"></td>
<td class="TB2ID"></td>
</tr>
</table>
Then, you should be able to have your CSS Transform look like:
"tr" #> qresult.map { case (d, o) =>
".TB1ID *" #> d.TB1ID &
".dF1VALUE *" #> d.F1VALUE &
".dF2VALUE *" #> d.F2VALUE &
".oF1VALUE *" #> o.F1VALUE &
".oF1VALUE *" #> o.F2VALUE &
".TB2ID *" #> o.TB2ID
}
That will key on the TR and repeat it for every row in your qresult list. Then, for each of the columns (represented above by their class attribute), it will output the value you want associated with it. Note that the * in the selector will append the value on the right as a child of the TD instead of replacing it with the value on the right.
You can find more information on CSS Selectors and outputting HTML here:
http://simply.liftweb.net/index-7.10.html
https://www.assembla.com/wiki/show/liftweb/binding_via_css_selectors

Related

How to select specific data in dynamic table using protractor?

I am trying to automate some scenarios using protractor where we need to verify whether the data is updating in dynamic table.
Please find below
HTML Code:
enter image description here
Table in page:
enter image description here
It can be done by verifying that element is present in the DOM with the added Group ID or Group Name.
For Group ID:
element(by.xpath("*//table//tbody//tr//td[1]//p[text()='Amanda Test
Group']")).isDisplayed()
For Group name:
element(by.xpath("*//table//tbody//tr//td[2]//p[text()='Amanda
Group']")).isDisplayed()
I'm assuming you're using Angular2+, yes?
In your HTML Template, you are probably using an *ngFor directive to populate the table dynamically. Add an index to the *ngFor (it's best practices for updating the DOM) in order to add a dynamic id to each element:
<tr *ngFor="let user of user; index as u" id="user-{{u + 1}}">
<td id="userName-{{u + 1}}">
{{user.firstName}} {{user.userName}}<br />
{{user.userName}}
</td>
<td id="userRoles-{{ u + 1 }}">
<span id="role-{{u + 1}}-{{ r + 1 }}" *ngFor="let role of user.roles; index as r">
{{ role.toUpperCase() + ', '}}
</span>
</td>
<!- Omitted code -->
</tr>
In your Page Object:
// Get first user on the table
get firstUser() {
return element(by.id('user-1');
}
// Get a specific user by id
public getUser(index: number) {
return element(by.id(`user-${index}`);
}
// Get all of the attributes for a single user by id
get userAttributes(index: number) {
return element.all(by.id(`user-${index}`);
}
I am not a fan of xpath selectors. Yes, they are faster. But in code that is dynamic or changes frequently, they are the most fragile of selectors. There is no reason your dynamic data cannot have a dynamic ID that clearly identifies each portion of the code you need.
Good luck!

how to retrieve select options from my database

I'm trying to retrieve my select option from 3 databases located in a connection that's not my defaut connection.
but I'm getting an error : Undefined variable: marqs (View: C:\wamp64\www\projetSovac\resources\views\home.blade.php)
Here's my controller code
public function index()
{
$marques= DB::connection('sqlsrv2')->table('marque')->get();
$modeles = DB::connection('sqlsrv2')->table('Modele')->select( DB::raw('CodeModele'))->get();
$finitions = DB::connection('sqlsrv2')->table('finition')->select( DB::raw('CodeFinition'))->get();
$marqs = $marques->all(['marque']);
$models = $modeles->all(['CodeModele']);
$Finitions = $finitions->all(['CodeModele']);
return View::make('home')
->with(compact($marqs))
->with(compact($models))
->with(compact($Finitions));
return View('home');
}
and my home.blade.php code
<tr class="filters">
<th><input type="text" class="form-control daterangepicker-field" placeholder="PĂ©riode d'analyse" disabled ></th>
<th><select class="form-control " disabled>
{!! Form::Label('marque', 'marque:') !!}
#foreach($marqs as $marque)
<option value="{{$marque->codeMarque}}">{{$marque->codeMarque}}</option>
#endforeach
</select>
</th>
Can you help identify the problem?
Thanks
compact($marqs) wants to have a string divining the variable you want to pass to the view. Use: compact('marqs') you can also combine your variables like compact('marqs', 'models', ....etc )
Also you are returning something 2 times now in the function this is not possible.
I would rewrite your function to be like this:
$marques= DB::connection('sqlsrv2')->table('marque')->get();
$modeles = DB::connection('sqlsrv2')->table('Modele')->select( DB::raw('CodeModele'))->get();
$finitions = DB::connection('sqlsrv2')->table('finition')->select( DB::raw('CodeFinition'))->get();
$marqs = $marques->all(['marque']);
$models = $modeles->all(['CodeModele']);
$Finitions = $finitions->all(['CodeModele']);
return View::make('home')->with(compact('marqs', 'models', 'Finitions'));
Assuming the first 6 lines get you the actual data all i changed was the return.
You might want to read up on how to use laravel models
https://laravel.com/docs/5.7/eloquent
I am not sure if u have defined any but it could make your code allot simpler.

Capybara assert element is empty

Looking for the best way to determine if an element is really empty.
<table id="foo">
<tr>
<td>Cell One</td>
<td></td>
</tr>
</table>
But both of these return true:
find("#foo td:nth-child(1)").should have_content('')
find("#foo td:nth-child(2)").should have_content('')
So I used this:
find("#foo td:nth-child(1)").text.should == 'Cell One'
find("#foo td:nth-child(2)").text.should == ''
Which seems to work, but doesn't check to see if the element may contain other elements. For example it may contain an image, link, or span.
I can check for each one of those individually(image, link, or span), but it seems like there should be better way.
Is there a way to test to see if the element is empty?
You can do the following to check that the element does not have any text and has no child elements (ie is actually empty):
# Has no child elements
find("#foo td:nth-child(2)").all('*').length.should == 0
# Has no text
find("#foo td:nth-child(2)").text.should==''

How to select "a.my" as jquery in lift?

I want to select all <a> with class myin liftweb, and set its text to ???:
val x = <div>
<a><span class="my">xxx</span></a>
<a class="my">yyy</a>
</div>
I tried:
"a .my *" #> "???"
and
"a" #> (".my *" #> "???")
But neither works, because both of them convert the x to:
<div>
<a><span class="my">???</span></a>
<a class="my">???</a>
</div>
Which are incorrect, they should only convert the second <a>.
What's the correct code?
As far as I know, there is no direct way to do that using Lift 2.5 and earlier. I believe they will be adding support for that more robust type of binding to Lift 3, but since it is not here yet you will need to work around it.
Since you can work directly with the NodeSeq on the right of the CssSelector, something like this should allow you to accomplish what you are looking to do:
"a" #> { ns:NodeSeq =>
if((ns \ "#class").text == "my")
("* *" #> "???").apply(ns)
else
ns
}
When I was fighting for another problem, I read this again(https://www.assembla.com/wiki/show/liftweb/binding_via_css_selectors) and I found a solution.
just use
".my" #> ("a *" #> "???")
instead of
"a" #> (".my *" #> "???")
then everything goes well

PHP Undefined Index Notice / Error

A page I have in my app will not display the required text so I checked my Apache error log and I found the following notice/error.
PHP Notice: Undefined index: PetManager_Model_Groomprocedures display.phtml on line 34
It is due to the fact that I'm trying to display a result from a query and it can't seem to obtain this item from my result array.
The situation is I'm querying a booking table that is related to a services table (theses elements display fine) the services table is in turn related to a procedures table(this is the element that will not display).
Can someone tell me where I'm going wrong i.e. my Query or my display code and how can I get this to work.
Query Code from my Display Action
if ($input->isValid()) {
$q = Doctrine_Query::create()
->from('PetManager_Model_Kennelbooking k')
->leftJoin('k.PetManager_Model_Kennelservices s')
->leftJoin('s.PetManager_Model_Groomprocedures g')
->leftJoin('k.PetManager_Model_Clients c')
->leftJoin('k.PetManager_Model_Kennels l')
->where('k.kennelbookingID = ?', $input->id);
if('k.groomingIncluded'==1)
{$q->addWhere('s.groomingGiven=g.groomProceduresID');
}
$result = $q->fetchArray();
if (count($result) == 1) {
$this -> view -> booking = $result[0];
The display code from my phtml file
<td class="key">Grooming Procedure </td>
</tr>
<tr>
<?php if($this->booking['PetManager_Model_Kennelservices']['groomingGiven']==NULL)
echo '<td>'.'There is no grooming procedure associated for this booking'.'</td>';
else echo '<td>'.$this->escape($this->booking['PetManager_Model_Groomprocedures']['groomprocedure']).'</td>';
;?>
</tr>
Many thanks in advance,
Graham
As you can see the index PetManager_Model_Groomprocedures is not defined in the booking-variable.
To see which keys are available do the following in your controller to get a debug output.
echo '<pre>';print_r($result[0]);echo '</pre>';exit;
You will see which keys are available in this array. I guess you are not selecting the wanted row explicitly. You will modify your query this way, that you also do select the wanted row.