Selecting elements from DOM - dom

On my page contents, I have multiple cards organized as a grid
__________________
| ____ ____ |
| | | | | |
| | | | | |
| |____| |____| |
| |
| ____ ____ |
| | | | | |
| | | | | |
| |____| |____| |
|__________________|
My issue is that each card container has the same class, and I want to select a distinct element inside a container. Example:
<div class="parent-container">
<div class="container">
<h2> Distinct title 1 </h2>
</div>
<div class="container">
<div class="another-container">
<button>
<span> Click Here! </span>
</button>
</div>
</div>
</div>
[repeat X times]
or using a DOM tree
. Parent div
|_ child div
| |_ <h2> Distinct title 3 </h2>
|
|_ child div
|_ grandchild div
|_ button
|_ <span> Click Here! </span>
So, supposedly I want to select an element on the third container. How would the selector query be?
Based on #lostlemon answer, my query is the following:
await t
.click(Selector('span')
.parent(3)
.child('h2')
.withExactText('Distinct title 3'));

If you always want to select the third container in this scenario, you could use nth-child or nth-of-type:
await t.click('div:nth-child(3) > span');
If you need to click on the span based on title, try this:
await t
.click(Selector('span').parent('.parent-container')
.child('h2').withExactText('Distinct title 3');
.withText() can be removed if all the <span>s have the same text
make sure your parent selector is trying to find the class and not an element if you're targeting the container class
.find() looks for an element, so it wouldn't match the distinct title text

You can just give each span a unique class.
<span class="card-1">CONTENT</span>

Related

Laravel 8 Eloquent one-to-many relationship data retrieval issue

I have been following a tutorial on the Internet about the one-to-many relationships in Eloquent (in Laravel 8). It has a simple mySQL database with two simple tables ("cars" and "car_models") that were created by using Laravel migration.
Here is the migration file:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCarsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('cars', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('founded');
$table->longText('description');
$table->timestamps();
});
Schema::create('car_models', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('car_id');
$table->string('model_name');
$table->timestamps();
$table->foreign('car_id')
->references('id')
->on('cars')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('cars');
}
}
Here is the "cars" table:
mysql> desc cars;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| founded | int | NO | | NULL | |
| description | longtext | NO | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
6 rows in set (0.34 sec)
mysql> select * from cars;
+----+------+---------+-------------------------------------+------------+------------+
| id | name | founded | description | created_at | updated_at |
+----+------+---------+-------------------------------------+------------+------------+
| 2 | Audi | 1908 | this is not the description of Audi | NULL | NULL |
+----+------+---------+-------------------------------------+------------+------------+
1 row in set (0.01 sec)
Here is the "car_models" table:
mysql> desc car_models;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int unsigned | NO | PRI | NULL | auto_increment |
| car_id | int unsigned | NO | MUL | NULL | |
| model_name | varchar(255) | NO | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
mysql> select * from car_models;
+----+--------+------------+------------+------------+
| id | car_id | model_name | created_at | updated_at |
+----+--------+------------+------------+------------+
| 5 | 2 | A1 | NULL | NULL |
| 6 | 2 | A3 | NULL | NULL |
| 7 | 2 | A5 | NULL | NULL |
+----+--------+------------+------------+------------+
3 rows in set (0.00 sec)
What the sample project does is, all the rows from the "cars" table are pulled and feeds to a view. The user can then click on any of the brand names and the project will display all the models of that brand on another view. There are two models in the project that describe the data.
Here is the "Car" model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Car extends Model
{
use HasFactory;
protected $table = 'cars';
protected $primaryKey = 'id';
// public $timestamps = true;
protected $fillable = ['name', 'founded', 'description'];
public function carModels() {
return $this -> hasMany(CarModel::class, 'id', 'car_id');
}
}
Here is the "CarModel" model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CarModel extends Model
{
use HasFactory;
protected $table = 'cars';
protected $primaryKey = 'id';
public function car() {
return $this -> belongsTo(Car::class);
}
}
When I followed the tutorial strictly in the beginning, the project would bork with a 1054 error.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'cars.car_id' in 'where clause'
That was fixed after I added in the two optional parameters "foreign key" and "local key" to the hasMany() in the "Car" model. However, the resulting webpage says "No models found" when it should display "A1 A3 A5"
screenshot of output
Here is the relevant view:
#extends('layouts.app')
#section('contents')
<div class="m-auto w-4/5 py-24">
<div class="text-center">
<h1 class="text-5xl uppercase bold">{{ $car -> name }}</h1>
</div>
<div class="w-5/6 py-10">
<div class="m-auto">
<span class="uppercase text-blue-500 fold-bold text-xs italic">Founded: {{ $car -> founded }}</span>
<h2 class="text-gray-700 text-5xl hover:text-gray-500">
{{ $car -> name }}
</h2>
<p class="text-lg text-gray-700 py-6">{{ $car -> description }}</p>
</div>
<ul>
<p class="text-lg text-gray-700 py-3">Models:</p>
#forelse ($car -> carModels as $model)
<li class="inline italic text-gray-600 px-1 py-6">
{{ $model['model_name'] }}
</li>
#empty
<p>No models found</p>
#endforelse
</ul>
<hr class="mt-4 mb-8" />
</div>
</div>
#endsection
The id is correct as dd() returned a 2.
I have been staring at this for a few hours and my brains are now frizzled. A fresh pair of eyes can assist greatly. Thank you very much.
Okay, I found out what's wrong.
In the "CarModels" model, the protected $table should be "car_models," not "cars."

Access column array and store it in a new table

I have a table like this:
| id | cars | owner |
|----|--------------------------|----------------|
| 1 | {tesla, bmw, mercedes} | Chris Houghton |
| 2 | {toyota, bmw, fiat} | Matt Quinn |
Is there a way to access the car table array DISTINCT values and store them in a new table without duplicate values?
I want this table
| brands |
|--------|
| tesla |
| bmw |
|mercedes|
| toyota |
| fiat |
I believe you are looking for this kind of statement.
SELECT
DISTINCT
table_array.array_unnest
FROM (
SELECT
UNNEST(cars)
FROM
<table>
) AS table_array(array_unnest)
see demo
This indeed works but how can I store them for example in a column
"brand" of a table Manufactures.
INSERT INTO
Manufactures
(brand)
SELECT
DISTINCT
table_array.array_unnest
FROM (
SELECT
UNNEST(cars)
FROM
<table>
) AS table_array(array_unnest)
see demo

Cross tab with a list of values instead of summation

I want a Cross tab that lists field values and counts them instead of just giving a count for the summation. I know I could make this with groups but I cant list the values vertically that way. From my research I believe I have to use a Display String Formula.
SQL Field Data
-------------------------------------------------
| Play # | Formation |Back Set | R/P | PLAY |
-------------------------------------------------
| 1 | TREY | FG | R | TRUCK |
-------------------------------------------------
| 2 | T | FG | R | RHINO |
-------------------------------------------------
| 3 | D | FG | P | 5 STEP |
-------------------------------------------------
| 4 | D | FG | P | 5 STEP |
-------------------------------------------------
| 5 | K JET | NG | R | DOG |
-------------------------------------------------
Desired report structure:
-----------------------------------------------------------
| Backet & Formation | Run | Pass |
-----------------------------------------------------------
| NG K JET | BULLA 1 | |
| | HELL 3 | |
-----------------------------------------------------------
| FG D | | 5 STEP 2 |
-----------------------------------------------------------
| NG K JET | DOG | |
-----------------------------------------------------------
| FG T | RHINO | |
-----------------------------------------------------------
Don't see why a Crosstab is necessary for this - especially if the entire body of the report is just that table.
Group your records by Bracket and Formation - If that's not
something natively configured in your table, make a new Formula field
and group on that.
Drop the 3 relevant fields into whichever section you need to display. (It might be a Footer, based on whether or not you want repeats
Write a formula to determine whether or not Run or Pass are displayed, and place it in their suppression field. (Good luck getting a Crosstab to do that for you! It tends to prefer 0s over blanks.)
If there's more to the report than just this table, you can cheat the system by placing your "table" into a subreport. And of course you can stretch Line objects across the sections and it will stretch to form the table outlines

How to present data in a tree like table in UI5

I have data which is expected to be displayed in a structured table. It is expected that the table can be opened and collapsed on two levels allowing
you to drill down in the data.
Example: Cities World Wide
When the table is loaded it should be displayed like this:
Area | Country | Name | Population | ...
--------------+----------------+-------------+-------------+----
Europe | | | |
North America | | | |
... | | | |
when I click on "Europe" the second level is shown:
Area | Country | Name | Population | ...
--------------+----------------+-------------+-------------+-----
Europe | | | |
| Germany | | |
| Czech Republic | | |
North America | | | |
... | | | |
When I now click on "Germany" the third level containing the actual city data is shown:
Area | Country | Name | Population | ...
--------------+----------------+-------------+-------------+-----
Europe | | | |
| Germany | | |
| | Berlin | 4 Million | ...
| | Leipzig | 0.5 Million | ...
| Czech Republic | | |
North America | | | |
... | | | |
How can I achieve a drill down in a tree like structure like shown in this example in UI5?
Since one of the requirement is to also to see and compare the data at once I believe a table control would be best but I don't know how to bring in this drill down behavior.
Mobile support is not required. The person using this will be a data analyst working on a big screen.
Any help appreciated.
While writing this question I came up with the search phrase "ui5 tree table" and voila:
https://experience.sap.com/fiori-design-web/ui-components/tree-table/
This is what I was looking for.

Force a section to always print on odd pages in crystal reports

I have an invoice that runs off of a crystal report and I want to tweak it, but can't seem to figure it out.
I have paper that has a sticker at the bottom (to put on boxes and such). I have a label which is a report footer on the report that always prints at the bottom of the page so that it will fit on the sticker. On the back of the invoice I print the return policy and other information so we can save on paper. The invoice has a list of items and prices and normally there is no problem. However, every once in a while there are so many items that it forces the label onto the next page (which is the back of the sticker).
--------------------------------------------------------------------
| |
| |
| |
| |
| Item 1 Price |
| Item 2 Price |
| Item 3 Price |
| Item 4 Price |
| Item 5 Price |
| Item 6 Price |
| etc. |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|-------------------------------------------------------------------|
| |
| |
| |
| Sticker |
| |
| |
| |
---------------------------------------------------------------------
Q:Is there a way to force a report footer to print only on odd pages so that the label will always be on a sticker?
Things I've tried:
On the label section I've tried the "New Page Before" if pagenumber mod 2 = 0
Creating a new report footer section above the label that's the same size as the label that prints a new page after if pagenumber mod 2 = 0 and is suppressed if pagenumber mod 2 = 1. I've tried a couple of variations of this, i.e. making the section always print on the bottom of the page, forcing the label to print of the bottom of the next page and stuff like that but none of it worked.
Perhaps I'm on the right track and missing something simple, or maybe I'm not even close. Either way any help would be much appreciated!
If I understand you right, try this solution
Move the Sticker to the Page Footer and hide it on odd pages.
Steps:
Open report desing mode
copy the sticker to page footer.
go to Section expert
Suppress [x-2] on formula and place if pagenumber mod 2 = 0
run report