How to present data in a tree like table in UI5 - sapui5

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.

Related

How to split a big table into multiple related tables?

Am new to Postgres SQL.
I have a big table that can be splitted to multiple table
ID_Student | Name_Student | Departement_Student | is_Student_works | job_title | Work_Departement | Location|
=============================================================================================================
1 | Rolf | Software Eng | Yes | intern SE | data Studio
| london |
2 | Silvya | Accounting | Yes | Accounter | TORnivo
| New York |
I want to split it into 3 tables ( student, departement, work) :
STUDENT TABLE
ID_Student | Name_Student | is_Student_works | Location|
========================================================
1 | Rolf | yes | london |
2 | Silvya | Yes | New York|
DEPARTEMENT TABLE
ID_DEPARTEMENT | Name_DEPARTEMENT |
===================================
1 | Software Eng |
2 | Accounting |
WORK TABLE
ID_WORK | Name_WORK |
===================================
1 | intern SE |
2 | Accounter |
I need Only the Query that Split the table into multiple tables, THE CREATION OF TABLES ARE NOT NEEDED.

Flatten Postgers left join query result with dynamic values into one row

I have two tables products and product_attributs. One Product can have one or many attributs and these are filled by a dynamic web form (name and value inputs) added by the user as needed. For example for a drill the user could decide to add two attributs : color=blue and power=100 watts. For another product it could be 3 or more different attribus and for another it could have no special attributs.
products
| id | name | identifier | identifier_type | active
| ----------|--------------|-------------|------------------|---
| 1 | Drill | AD44 | barcode | true
| 2 | Polisher | AP211C | barcode | true
| 3 | Jackhammer | AJ2133 | barcode | false
| 4 | Screwdriver | AS4778 | RFID | true
product_attributs
|id | name | value | product_id
|----------|--------------|-------------|----------
|1 | color | blue | 1
|2 | power | 100 watts | 1
|3 | size | 40 cm | 2
|4 | energy | electrical | 3
|4 | price | 35€ | 3
so attributs could be anything which are set dynamically by the user. My need is to generate a report on CSV which contain all products with their attributs. Without a good experience in SQL I generated the following basic request :
SELECT pr.name, pr.identifier_type, pr.identifier, pr.active, att.name, att.value
FROM products as pr
LEFT JOIN product_attributs att ON pr.id = att.product_id
as you know the result will contain for the same product as many rows as attributs it has and this is not ideal for reporting. The ideal would be this :
|name | identifier_type | identifier | active | name | value | name | value
|-----------|-----------------|------------|--------|--------|-------|------ |------
|Drill | barcode | AD44 | true | color | blue | power | 100 w
|Polisher | barcode | AP211C | true | size | 40 cm | null | null
|Jackhammer | barcode | AJ2133 | true | energy | elect | price | 35 €
|Screwdriver| barcode | AS4778 | true | null | null | null | null
here I only showed a max of two attributes per product but it could be more if needed. Well I did some research and came across the pivot with crosstab function on Postgres but the problem it requests static values but this does not match my need.
thanks lot for your help and sorry for duplicates if any.
Thanks Laurenz Albe for your help. array_agg solved my problem. Here is the query if someone may be interested in :
SELECT
pr.name, pr.description, pr.identifier_type, pr.identifier,
pr.internal_identifier, pr.active,
ARRAY_TO_STRING(ARRAY_AGG (oa.name || ' = ' || oa.value),', ') attributs
FROM
products pr
LEFT JOIN product_attributs oa ON pr.id = oa.product_id
GROUP BY
pr.name, pr.description, pr.identifier_type, pr.identifier,
pr.internal_identifier, pr.active
ORDER BY
pr.name;

How to convert text-based table to image from terminal in the same structure?

I'm trying to convert text-based table to the image, but the structure is broken after convertation.
I have file with the next structure:
+-----------+------+------------+-----------------+
| City name | Area | Population | Annual Rainfall |
+-----------+------+------------+-----------------+
| Adelaide | 1295 | 1158259 | 600.5 |
| Brisbane | 5905 | 1857594 | 1146.4 |
| Darwin | 112 | 120900 | 1714.7 |
| Hobart | 1357 | 205556 | 619.5 |
| Sydney | 2058 | 4336374 | 1214.8 |
| Melbourne | 1566 | 3806092 | 646.9 |
| Perth | 5386 | 1554769 | 869.4 |
+-----------+------+------------+-----------------+%
after a conversation with ImageMagick and command below:
convert label:"$(cat test.txt)" result1.png
I have next image:
As you can see, the structure of the columns is broken.
Do you have an idea of how can such an issue be solved?
Regards,
Ihor
You need to set the TypeFace to something monospace to match the terminal.
convert -font "Liberation-Mono" label:#test.txt result1.png
You can identify which fonts on the system by running
identify -list font | grep Mono

Swift & Firebase - Split data for user info?

I currently coding a fitness app that permits to record all the personal records for a user.
I'm really new with Cloud Firestore from Firebase, so I really don't know how I could structure the database.
In my mind, I have two options:
OPTION 1
Users
|
+--UserID
| |
| +--Name
| +--Phone
| +--etc..
|
|
Users-records
|
+--UserID
| |
| +--RecordName
| | |
| | +--recordValue
| | +--recordType
| |
| +--RecordName
| | +--recordValue
| | +--recordType
OPTION 2
Users
|
+--UserID
| |
| +--Name
| +--Phone
| +--etc..
| +--Records
| | |
| | +--RecordName
| | | |
| | | +--recordValue
| | | +--recordType
| | +--RecordName
| | | |
| | | +--recordValue
| | | +--recordType
The questions are: Do I have to split the collection for the user?
Do you think this architecture is well designed for the purpose (ie record personal records from users)?
Thank you very much
Your database structure really depends on how you are going to use it. Keep in mind that whenever you observe a node, you are also observing all of the children nodes.
So I'd probably go with something closer to Option two, maybe like this:
Users
|
+--UserID
| |
| +--UserInfo
| | |
| | +--Name
| | +--Phone
| | +--etc..
| |
| +--Records
| | |
| | +--RecordName
| | | |
| | | +--recordValue
| | | +--recordType
| | +--RecordName
| | | |
| | | +--recordValue
| | | +--recordType
I'd choose this, because I'd image you'd want to get all of the UserInfo at once, So we can observe that "UserInfo" node and get all of the children: name, phone, etc....
Then I'd think you'd also want to get all of the records at once, so we can observe that "Records" node and get all of that data.
Additionally, if you wanted, you could get everything at once by observing the UserID!
However, if you were maybe going to be getting a list of all the users, then you definitely don't want all this data in one spot and this design wouldn't work, because that is a lot of data to observe just to get all the users.
In summary: Choose an option which makes it easiest for you to get what you need, without getting extra data you don't want!

What SQL Statements Will Normalize and Cleanse this table

What we are trying to achieve is some level of cleansing on the table. This is what we currently have (this a subset of the table please)
+-----------+------------+-----------+------------+--------+-----------+------------+-------+
| STUDENTNO | LASTNAME | FIRSTNAME | PREFERNAME | GENDER | COURSE | YEAR | MAJOR |
+-----------+------------+-----------+------------+--------+-----------+------------+-------+
| auaw64 | Drury | Janet | Jane | f | DIPLOMA | 29/10/2011 | NO |
| auaw64 | Drury | Janet | Jane | f | BACHELORS | 29/09/2013 | YES |
| auqn70 | Givens | Jason | | m | DIPLOMA | 29/10/2011 | NO |
| auqn70 | Givens | Jason | | m | BACHELORS | 10/10/2012 | YES |
| mrpd90 | Blackstock | Williams | Bill | m | DIPLOMA | 29/10/2011 | NO |
| mrpd90 | Blackstock | Williams | Bill | m | BACHELORS | 29/09/2013 | YES |
| pyts84 | Peters | Theresa | | f | BACHELORS | 29/09/2013 | YES |
| qjgp97 | Aaron | Felina | | f | DIPLOMA | 29/10/2013 | NO |
| qzhs28 | Gyeong | Ma | | f | DIPLOMA | 29/10/2011 | NO |
| qzhs28 | Gyeong | Ma | | f | BACHELORS | 29/09/2013 | YES |
| uwnv95 | Anholt | Wilhemina | | f | MASTERS | 29/10/2011 | NO |
| uwnv95 | Anholt | Wilhemina | | f | BACHELORS | 10/10/2012 | YES |
| jaiw67 | Muguruza | David | Dave | m | MASTERS | 28/09/2014 | YES |
+-----------+------------+-----------+------------+--------+-----------+------------+-------+
But we need to reorder this table with the 'studentno' as the new primary key and then perform an update/upsert (which is where the new columns have now emerged)
+-----------+------------+-----------+------------+--------+--------------+------------+--------------+------------+
| STUDENTNO | LASTNAME | FIRSTNAME | PREFERNAME | GENDER | MAJOR_COURSE | MAJOR_YEAR | MINOR_COURSE | MINOR_YEAR |
+-----------+------------+-----------+------------+--------+--------------+------------+--------------+------------+
| auaw64 | Drury | Janet | Jane | f | BACHELORS | 29/09/2013 | DIPLOMA | 29/10/2011 |
| auqn70 | Givens | Jason | | m | BACHELORS | 10/10/2012 | DIPLOMA | 29/10/2011 |
| mrpd90 | Blackstock | Williams | Bill | m | BACHELORS | 29/09/2013 | DIPLOMA | 29/10/2011 |
| pyts84 | Peters | Theresa | | f | BACHELORS | 29/09/2013 | null | null |
| qjgp97 | Aaron | Felina | | f | DIPLOMA | 29/10/2013 | null | null |
| qzhs28 | Gyeong | Ma | | f | BACHELORS | 29/09/2013 | DIPLOMA | 29/10/2011 |
| uwnv95 | Anholt | Wilhemina | | f | BACHELORS | 29/09/2013 | DIPLOMA | 29/10/2011 |
| jaiw67 | Muguruza | David | Dave | m | MASTERS | 28/09/2014 | null | null |
+-----------+------------+-----------+------------+--------+--------------+------------+--------------+------------+
Essentially we want to take the first table and convert to the second but doing this using the functionalities inside PostgreSQL and also turning the 'studentno' into the unique key. We can then write the new table into another for another app to read or make use of but the new key will now offer a proper query handle unlike we have in the original table.
First create the course table
CREATE TABLE Courses (
id SERIAL,
course varchar);
Then insert all courses into the new table
insert into Courses(course)
select course from Participants GROUP BY course
Then create the n-n relation table
CREATE TABLE Participants_Courses (
id SERIAL,
studentno varchar,
course integer,
year date,
major boolean);
Then insert the values from Participants into the n-n table
INSERT INTO Participants_Courses AS PC (studentno, course, year,major)
VALUES (SELECT STUDENTNO, (SELECT id FROM Courses AS C where PC.course = C.course), YEAR, MAJOR);
Finally drop the unnecessary columns from the Participants table
ALTER TABLE Participants DROP COLUMN course;
ALTER TABLE Participants DROP COLUMN year;
ALTER TABLE Participants DROP COLUMN major;
This is normalized, I would not recommend to insert two courses into the same column of the table, because it would limit you. With this, a person could have many courses.
This is the Third normal form, see https://en.wikipedia.org/wiki/Third_normal_form
I did not test the SQL's so there may be syntax errors ;)
Disclaimer:
Doing this is completely backwards and wrong. It's doubling down on a bad table design by making it into a worse one. Do not use wide, denormalized tables as your primary data store.
Read:
https://en.wikipedia.org/wiki/Normalization
https://en.wikipedia.org/wiki/Third_normal_form
and get familiar with using joins.
If you use this solution then I am sorry to whoever has to maintain the code later. You appear to be determined to do it, and there are legitimate reasons you might want to make this transformation for things like a view or report, so here's how.
Use a self-left-join, treating studentno as the key. Something like:
select
l."STUDENTNO", l."LASTNAME", l."FIRSTNAME", l."PREFERNAME", l."GENDER",
l."COURSE" AS "MAJOR_COURSE", l."YEAR" AS "MAJOR_YEAR",
r."COURSE" AS "MINOR_COURSE", r."YEAR" AS "MINOR_YEAR"
FROM table1 l
LEFT OUTER JOIN table1 r
ON (l."STUDENTNO" = r."STUDENTNO"
AND (l."COURSE", l."YEAR") <> (r."COURSE", r."YEAR"))
WHERE (l."COURSE", l."YEAR") < (r."COURSE", r."YEAR")
OR r."COURSE" IS NULL;
A proper solution wouldn't rely on the lexical sort of BACHELORS before DIPLOMA and would instead use a CASE statement or a function to produce proper ordering, but since we're already piling wrong on top of wrong, it doesn't matter much.
SQLfiddle: http://sqlfiddle.com/#!15/2f49f/1
Now. Delete this, and go do it properly. Create a STUDENT table and COURSE table, and a STUDENT_COURSE table that joins them and records which students took which courses in which years. It's relational databases 101.