Pฤvฤ | Alexandru Pฤvฤloi
๐ฅ will have acquired confidence to start basic Web projects on your own
๐ will have worked on a personal project which showcases your skills
๐ will have worked with multiple colleagues and thus grow your team-work skills
OR
๐ More info here
1. Read How it feels to learn JavaScript in 2016 2. Make a team & decide on projects (top 2). If you don't like any project, than propose one 3. HTML structure of YouTube --- BONUS --- So you want Bonus work huh? Well, check the lab's website then!
Set up a Twitter and follow these people
Addy Osmani
Jake Archibald
Monica Dinculescu
Brendan Eich
Dan Abramov
CSS Tricks
Sarah Drasner
Alex Russell
Mike North
Wes Bos
freecodecamp
JavaScript Daily
Week #2
img {
border: 5px solid black;
}
property
value
selector
<p style="font-weight: bold">
A simple styled paragraph...
</p>
<style>
h1 {
text-align: center;
}
</style>
<!-- index.html -->
<link rel="stylesheet"
href="style.css" />
<!-- style.css -->
footer {
color: #000;
background-color: #fff;
}
i want to select a specific element from the page
<p id="hello">
A simple styled paragraph...
</p>
<style>
#hello {
font-weight: bold;
}
</style>
i want to select similar elements from the page
<button class="btn round">
Log In
</button>
<style>
.btn{
border-radius: 10px;
}
</style>
i want to select same-tag elements from the page
<h1>
Who is BuBu?
</h1>
<style>
h1{
font-size: 50px;
}
</style>
<!-- index.html -->
<img class="round-image" id="profile"
src="user.jpg" />
<style>
img {
border: 1px solid black;
}
.round-image {
border: 5px dotted yellow;
}
#profile {
border: 2px solid blue;
}
</style>
๐ ID
๐ Class
๐ Tag Name
๐ฅ !important
.valentines.in-love {
// both "valentines" & "in-love"
// classes
text-decoration: make-up;
}
.raining .human {
/* "human" class inside "raining"-class
elements
*/
display: hidden;
position: under-blanket;/
}
.raining.valentines .in-love {
color: red;
}
faculty.in-iasi.state-owned .b4 #gicu {
display: none;
}
<div class="card">
<p class="card__header"> Amsterdam </p>
<img class="card__image round" id="home"
src="duck.jpg"/>
</div>
<style>
.card__image { border-color: black; }
.card .card__image { border-color: red; }
.card .card__image.round {
border-color: green;
}
#home { border-color: blue; }
.card #home { border-color: white; }
.card__image#home { border-color: brown; }
</style>
Ex #1: Slider
Ex #2: Badge
Let's style our Twitter-page elements
1. Read about naming your CSS classes 2. Create an HTML & CSS Traffic-light. Details here 3. Finish styling the Twitter elements (no layout yet) --- BONUS --- So you want Bonus work huh? Well, check the lab's website then!
Week #3
๐๐ Grid
๐ Flexbox
๐ง Position
STATIC
RELATIVE
ABSOLUTE
FIXED
๐ง Position
๐ง Position Practice
#1: relative
Move all the grades closer to the Week #no
Ex #2: absolute
Move the grades in the bottom-right corner of the Week box
Ex #3: fixed
Fix the footer in the bottom-right of the screen
BLOCK
INLINE-BLOCK
INLINE
๐ง TABLE
๐ FLEXBOX
๐ GRID
๐น Display ๐น
๐ฉโ๐ป Ex ๐ฉโ๐ป
#1
#2
.profile {
display: inline-block;
}
@media (max-width: 600px) {
.profile {
display: block;
}
}
PS: check out the Official CSS resources page. It has loads of cool stuff ๐
Hyper Text Markup Language
HTML --> DOM tree
the structure of Web Pages
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Cascading Style Sheets
inline | <style> | external
#id | .class | tag
<html>
<head>
<link rel="stylesheet" type="text/css" href="style1.css" />
<link rel="stylesheet" type="text/css" href="style2.css" />
</head>
<body>
<p> what color do I have </p>
</body>
</html>
/** style1.css */
p {
color: black;
text-align: center;
}
/** style2.css */
p {
color: red;
font-size: 22px;
}
<body>
<section class="question">
<p class="question__body">
Do you even bike?
</p>
<p class="question__answer">
No
</p>
<p class="question__answer
question__answer--selected">
Yes
</p>
</section>
</body>
Write just the HTML
Move the menu outside the screen
Move the menu on-screen when a new class is added
Apply the transition property so that the movement is fluid
CSS with superpowers
.header {
color: #ff22dd;
}
.header.header--expanded {
/* ... */
}
.header .logo {
/* ... */
}
$color-primary: #ff22dd;
.header {
color: $color-primary;
&.header--expanded {
/* ... */
}
.logo {
/* ... */
}
}
Server
3rd party API's
DB
Microservices
Client
Server
Browser
GET
POST
PUT
DELETE
...
Sa se construiasca o aplicatie Web care sa-l asiste pe student in construirea proiectului la disciplina Tehnologii Web.
Aplicatia va oferi un "to-do list" detaliat ce cuprinde toate lucrurile pe care trebuie sa le aiba in vedere pentru promovare. Utilizatorii autentificati vor putea sa marcheze task'urile finalizate pentru a avea o mai buna privire de ansamblu asupra progresului, in timp ce utilizatorii ne-autentificati vor putea doar consulta lista fara a-si salva in nici un fel progresul.
Number
String
Boolean
Array
Object
NULL
<?php
$tw = NULL;
echo $tw;
$tw = 22;
$tw = 'Amu is String';
class Human {
public $name = 'Bob';
}
$tw = new Human();
echo $tw->name;
?>
if
for
while
foreach
<?php
$tw = NULL;
if($tw === NULL) {
echo "it's null";
}
if($tw == FALSE) {
echo "it's also false!!!";
}
$tw = [1,2,3];
foreach($tw as $index => $e) {
echo "at $index is $e <br/>";
}
?>
<?php
function sumMeBaby($param1, $param2) {
return $param1 + $param2;
}
class Human {
public function buyFood() { }
}
?>
Our app will have 2 pages: the login one and the home one. Both of them have the same header. Let's move the header code in a separate file and include it from there in both pages.
1. Create a header-component.php file which has a getHeader function returning the HTML for the header. 2. Include this component in index & home pages and render the header's HTML using that function
INDICATIONS
7 mins
EX #1
Let's assume only logged in users should see the home page. So, if the credentials match allow them access, if not just keep them on the login page.
1. You will have to add an action to our login form pointing towards php script. 2. To access the input values use the $_POST array. The keys are the same as the name attribute on the fields
INDICATIONS
EX #2
12 mins
3. If the credentials match redirect to the home page. If not, redirect back to login page 4. To redirect just set the Location header like this `header("Location: google.com")`
We're on the home page but it's empty ๐ Let's read some dummy todo's from a CSV and add them to the page.
1. To read the CSV you can use the file function 2. By iterating (foreach)over the result we can access each line, as a string. 3. To parse the string line into an array of values use the str_getcsv function
INDICATIONS
EX #3
15 mins
๐ฅ Instead of getting the ToDo's from a CSV file, get them from a Database.
* in case you didn't manage to implement the previous exercises, do that as well so you get the hang of PHP
The software architecture of a system depicts the systemโs organization or structure, and provides an explanation of how it behaves.
In other words, the software architecture provides a sturdy foundation on which software can be built.
[...]
renders the UI
what the users sees and interacts with
the data layer: Objects, files, Database
has functionality which stores and retrieves this data
where the s*** happens
responds to user actions by getting/storing data in the Model and showing an appropriate View
users
username
password
todos
id
topic
text
done_todos
username
todo_id
Bob
Login
Login Controller
Auth Model
Check
Credentials
store
๐ช username & pass
๐ช token
Very high level view of all the component parts (Server, Client, Database, Services, Micro Services, Libraries )of this app and the connections between them
Example:
Server
Client
SQL DB
Google Maps API
QR JS Library
GitHub Api
โ Database structure & relationships
โ Design Patterns (MVC recommended)
โ Class diagrams
โ Usecase diagrams (at least 1 flow per user category)
โ Master Diagram (see previous slide)
<?xml version="1.0" encoding="UTF-8"?>
<produse>
<produs stare="deteriorat">
<nume> Pink Uinix </nume>
<ofertant> http://www.pinfuin.info </ofertant>
</produs>
<produs>
<nume> Sosete Colorate </nume>
<ofertant> https://www.iampava.com </ofertant>
</produs>
</produse>
tag
attribute
<?xml version="1.0" encoding="UTF-8" ?>
<produse>
<produs stare="deteriorat">
<produsXML:nume> Pink Uinix </produsXML:nume>
<ofertant>
<nume> pinguini.ro </nume>
<adresa> Strada Polul Nord, 22 </adresa>
</ofertant>
</produs>
<produs>
<!-- ... -->
</produs>
</produse>
EX #0
Let's create an XML file that models the places I've spoken at ๐
1. Make sure this XML file is self-explanatory. If I (a human) read it I should be able to understand what's going on in Pava's speaking life.
You're changing towns but you're not taking your books with you. So, you take your PC and decide to create an XML file which represents your entire collection.
1. Make sure this XML file is self-explanatory for a human.
INDICATIONS
10 mins
EX #1
Solution #1
Document Object Model
Modelling HTML, SVG and XML documents as objects.
[...]
The DOM model represents a document with a logical tree.
๐ป Let's create the XML we did in the last exercise in PHP! Using DOM ๐ฅ๐ฅ๐ฅ
10 mins
EX #2
You're organizing a field-trip with a group of 100 students from the 3 biggest universities in Iasi. Let's model an XML file which details all the participants.
For each participant we care about his name, age, uni and role. (some students have additional responsibilities)
1. Make the XML self explanatory to another human.
INDICATIONS
10 mins
EX #3
Transform the TW-checklist DB from a relational one to a XML based one.
1. You may use one or more XML files. It's up to you
INDICATIONS
10 mins
EX #4
Talking about the same things but in different languages...๐
Schema.org is a collaborative, community activity with a mission to create, maintain, and promote schemas for structured data on the Internet, on web pages, in email messages, and beyond.
Founded by Google, Microsoft, Yahoo and Yandex, Schema.org vocabularies are developed by an open community process, using the public-schemaorg@w3.org mailing list and through GitHub.
...
๐ป online XML editor
๐ XML namespaces
๐ณ Document Object Model
๐ schema.org
Previous lab...
XML intro and modelling
XML serialization using DOM
Ex #1
๐ป https://github.com/iampava/tw-labs
DOM practice in JavaScript ๐ฅ
๐ป to the code
querySelector vs querySelectorAll
$x function
Ex #2
Print a table with the weekdays and their schedule!
๐ป to the code
Ex #3
Write a XML which respects the XSD๐ฅ
โญโญโญโญโญโญโญ
ratings on The Web
THE USECASE...
#1 Web Scrapping
#2 Web Services
A Web service is a software system designed to support inter-operable machine-to-machine interaction over a network.
Examples
TrendsMap
Authentication with Social Media
#2 SOAP:
Simple Object Access Protocol
messaging protocol for exchanging structured data to & from a webservice
int getSum
(int, int)
float convert
(float)
SOAP Enpelope
SOAP Header
SOAP Body
Ex #1
Write a SOAP Web Service that returns the Weather information for a particular day and use it in a "real" app.
client.html
app.php
weather-service.php
Ex #2
Build on the previous example and return data in XML format! Use the DOM to model it!
Ex #3
Set up a connection with a DB and get the data from there, before converting it to XML.
ful
REpresentational
State Transfer
The computational results are actually resource representations
each resource representation has an associated URL
clients interact with those resources via http verbs
https://demo.app/v3/users
https://demo.app/v3/users/1234
{
"users": [{
"username": "iampava",
"avatar": "https://demo.app/avatar.png"
}]
}
{
"username": "iampava",
"avatar": "https://demo.app/avatar.png"
}
๐ Accept: application/json
https://demo.app/v3/users/1234/settings
{
"theme": "light-gray",
"notifications": false
}
https://demo.app/v3/users/
{
"username": "iampava",
"avatar": "https://demo.app/avatar.png"
}
{
"username": "iampava",
"avatar": "https://demo.app/avatar.png",
"userId": 1234
}
https://demo.app/v3/users/1234
or
๐ Chuck Norris API ๐ Dog Ceo API
FrontEnd
BackEnd
API DEV #1
API DEV #2
FrontEnd AJAX
let mockReq = new XMLHttpRequest();
mockReq.open( 'POST', 'https://demo.app/v1/users');
mockReq.addEventListener('load', function onLoad() {
let jsonResp = JSON.parse(mockReq.response);
switch (mockReq.status) {
case 200:
console.log("Whoooray!");
break;
default:
break;
}
});
mockReq.addEventListener('error', () => {
console.error("Oups, something failed!");
});
let payload = {
"username": "iampava",
"avatar": "https://url.com/png"
};
mockReq.send(JSON.stringify(payload));
REST API call in PHP
$req = curl_init("https://demo.app/api/v1/users");
$headers = array(
'Content-Type:application/json',
'Accept: application/json'
);
$body = array(
"client_id" => "1234",
"client_pass" => "Secret"
);
curl_setopt($req, CURLOPT_POST, TRUE);
curl_setopt($req, CURLOPT_HTTPHEADER, $headers);
curl_setopt($req, CURLOPT_POSTFIELDS, json_encode($body));
curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
$respAsJson = json_decode(curl_exec($req));
curl_close($req);
REST listen to requests
switch ($_SERVER['REQUEST_METHOD']) {
case "POST":
if(preg_match('/\/api\/v1\/users\/?$/'
, $_SERVER['REQUEST_URI'])) {
// POST on api/v1/users
} else if(preg_match('/\/api\/v1\/users\/(.+)?$/'
, $_SERVER['REQUEST_URI'])) {
$json_str = file_get_contents('php://input');
$json_obj = json_decode($json_str);
echo $json_obj -> userId; //respond
http_response_code(200);
} else {
http_response_code(404);
}
break;
default:
break;
}
DB layer
$conn = new mysqli
( "servername", "username", "pass", "db_name");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
function getUser($username) {
global $conn;
$stmt = $conn->prepare('
SELECT * FROM users
WHERE username = ?
');
if (false === $stmt ) {
die('prepare() failed: ' . htmlspecialchars($conn->error));
}
$stmt->bind_param('s', $username);
$stmt->execute();
$result = $stmt -> get_result();
$row = $result -> fetch_assoc();
return $row["pass"];
}
[REST] API Collections
let xhr = new XMLHttpRequest();
xhr.open("POST", "https://demo.app/api/v1/users");
xhr.addEventListener("load", function loadCallback() {
switch (xhr.status) {
case 200:
console.log("Success" + xhr.response);
break;
case 404:
console.log("Oups! Not found");
break;
}
});
xhr.addEventListener("error", function errorCallback() {
console.log("Network error");
});
let payload = {
username: "iampava",
pass: "1234"
}
xhr.send(JSON.stringify(payload));
Create a client-only app with a button.
Upon clicking the button, a new Labrador image should be appended to the page.
โ fully functional solution
โ uses AJAX
โ project report in Scholarly HTML
โ instructions manual
โ demonstrative video (for M projects) ๐ additional details
Brendan Eich
1995 JS creation
1997 ECMA standard
2007 V8 project starts
2008 - 2010 Race for speed
2009 AngularJS
2013 React
2009 NodeJS
2014 VueJS
2018 > 5B devices
Desktop
Mobile
Server
Browser
Number
String
Boolean
Object
Null ๐ฒ
Undefined ๐ฒ๐ฒ
Symbol* ๐ฒ๐ฒ๐ฒ
var tw;
console.log(typeof tw);
tw = 22;
console.log(tw);
tw = 'Amu is String';
to the Code
They are First Class citizens!
BUTTON + JavaScript = ๐