Advertisement
Guest User

talent.cfg

a guest
Feb 7th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.92 KB | None | 0 0
  1. JAVASCRIPT
  2.  
  3. function applyBlackFriday(products, discount){
  4. return new Promise( (resolve, reject) => {
  5. if (isNaN(discount)) {
  6. reject(new Error('Invalid discount'));
  7. } else if (discount <= 0 || discount > 10) {
  8. reject(new Error('Discount not applicable'));
  9. }
  10.  
  11. products.forEach(product => {
  12. if (product.name && typeof product.name === 'string' && product.price && typeof product.price === 'number') {
  13. product.price = (1 - discount/100) * product.price;
  14. } else {
  15. reject(new Error('Invalid array format'));
  16. }
  17. })
  18. resolve(products);
  19. })
  20. }
  21.  
  22. function addTokens(input, tokens) {
  23. if (typeof input !== 'string') {
  24. throw new Error('Invalid input');
  25. }
  26.  
  27. if (input.length < 6) {
  28. throw new Error(`Input should have at least 6 characters`);
  29. }
  30.  
  31. tokens.forEach(tokenName => {
  32. if (typeof(tokenName) === 'string') {
  33. if (input.includes('...')) {
  34. input = input.replace('...', `${tokenName}`);
  35. }
  36. }
  37. else {
  38. throw new Error('Invalid array format');
  39. }
  40. });
  41.  
  42. return input;
  43. }
  44.  
  45.  
  46.  
  47. function applyDiscount(vehicles, discount) {
  48. return new Promise((resolve, reject) => {
  49. if (typeof discount !== 'number') {
  50. reject(new Error('Invalid discount'));
  51. }
  52.  
  53. let lowestPrice = vehicles[0].price;
  54. for (let i = 0; i < vehicles.length; i++) {
  55. if (vehicles[i].price < lowestPrice) {
  56. lowestPrice = vehicles[i].price;
  57. }
  58. }
  59. lowestPrice = lowestPrice * (50 / 100);
  60.  
  61. if (discount > lowestPrice) {
  62. reject('Discount too big');
  63. }
  64. vehicles.forEach(veh => {
  65. // if (veh && veh.name && typeof veh.name === 'string' && veh.price && typeof veh.price === 'number') {
  66. // veh.price = (1 - discount / 100) * veh.price;
  67. // }
  68. let obj = {
  69. name: ' ',
  70. price: 1
  71. }
  72.  
  73. if (veh.isPrototypeOf(obj)) {
  74. veh.price = (1 - discount / 100) * veh.price;
  75. }
  76. else {
  77. reject(new Error('Invalid array format'));
  78. }
  79.  
  80. })
  81. resolve(vehicles);
  82. });
  83. }
  84.  
  85. //textprocessor
  86. alt model din seminar
  87. String.prototype.format = function(specs){
  88. let str = this.toString()
  89. if (specs){
  90. for (let prop in specs){
  91. str = str.replace('{' + prop + '}', specs[prop])
  92. }
  93. }
  94. return str
  95. }
  96.  
  97. console.warn('i am a string with {a} and {b} params'.format({a : 'first', b : 'second'}))
  98.  
  99.  
  100. function translate(text, dictionary){
  101. if (typeof text !== 'string'){
  102. throw new Error('TypeError')
  103. }
  104. if (typeof dictionary !== 'object' || !dictionary){
  105. throw new Error('TypeError')
  106. }
  107. for (let prop in dictionary){
  108. if (typeof dictionary[prop] !== 'string'){
  109. throw new Error('TypeError')
  110. }
  111. }
  112. let result = text.split(' ')
  113. for (let prop in dictionary){
  114. let position = result.indexOf(prop)
  115. if (position !== -1){
  116. result[position] = dictionary[prop]
  117. }
  118. }
  119. return result.join(' ')
  120. }
  121.  
  122. function capitalize(text, dictionary){
  123. if (typeof text !== 'string'){
  124. throw new Error('TypeError')
  125. }
  126. if (!Array.isArray(dictionary)){
  127. throw new Error('TypeError')
  128. }
  129. if (dictionary.filter((e) => typeof e !== 'string').length){
  130. throw new Error('TypeError')
  131. }
  132. let result = text
  133. let items = result.split(' ')
  134. for (let i = 0; i < items.length; i++){
  135. if (dictionary.indexOf(items[i]) !== -1){
  136. items[i] = items[i][0].toUpperCase() + items[i].slice(1, items[i].length)
  137. }
  138. }
  139. return items.join(' ')
  140. }
  141.  
  142. /*
  143. Exista un tip obiectual definit (Bird)
  144. Să se definească tipul Penguin.
  145. Un pinguin este un tip copil pentru Bird și are în plus metoda swim(distance)
  146. Un pinguin nu poate fi creat fără un nume de tip string
  147. Un pinguin nu poate să zboare și va spune asta dacă i se cere
  148. Dacă se apelează makeNest, un pinguin va apela metoda părintelui său
  149. Vedeți testele pentru formatul exact al mesajelors
  150. */
  151.  
  152. class Bird {
  153. constructor(name){
  154. this.name = name
  155. }
  156.  
  157. fly(distance){
  158. return `${this.name} flies ${this.distance}`
  159. }
  160.  
  161. makeNest(){
  162. return `${this.name} makes a nest`
  163. }
  164. }
  165.  
  166.  
  167. class Penguin extends Bird {
  168. constructor(name){
  169. if (!name || typeof name !== 'string'){
  170. throw new Error('CreationError')
  171. }
  172. super(name)
  173. }
  174.  
  175. fly(distance){
  176. return `${this.name} is a penguin and cannot fly`
  177. }
  178.  
  179. swim(distance){
  180. return `${this.name} swims ${distance}`
  181. }
  182. }
  183.  
  184.  
  185. /*
  186. Exista un tip obiectual definit (Widget)
  187. Funcția decorate adaugă la Widget o metodă numită enhance, care crește mărimea unui widget cu "n"
  188. Dacă parametrul trimis nu este un număr, se aruncă o excepție ("InvalidType")
  189. Metoda funcționează și asupra Widget-urilor deja declarate
  190. */
  191.  
  192. class Widget {
  193. constructor(name, size){
  194. this.name = name
  195. this.size = size
  196. }
  197.  
  198. getDescription(){
  199. return `a ${this.name} of size ${this.size}`
  200. }
  201. }
  202.  
  203. function decorate(){
  204. Widget.prototype.enhance = function (n){
  205. if (typeof n !== 'number'){
  206. throw new Error("InvalidType")
  207. }
  208. this.size += n
  209. }
  210. }
  211.  
  212. /*
  213. - funcția distance primește ca parametrii două array-uri
  214. - fiecare element poate apărea cel mult o dată într-un array
  215. - distanța dintre cele 2 array-uri este numărul de elemente diferite dintre ele
  216. - dacă parametrii nu sunt array-uri se va arunca o excepție ("InvalidType")
  217. */
  218. function distance(first, second){
  219. if (!Array.isArray(first) || !Array.isArray(second)){
  220. throw new Error('InvalidType')
  221. }
  222. let me = [...new Set(first)]
  223. let other = [...new Set(second)]
  224. let diffCount = 0
  225. for (let item of me){
  226. if (other.indexOf(item) === -1){
  227. diffCount++
  228. }
  229. else{
  230. other.splice(other.indexOf(item), 1)
  231. }
  232. }
  233. diffCount += other.length
  234. return diffCount
  235. }
  236.  
  237. {
  238. "invoiceNumber": 1,
  239. "invoiceSeries": "ABCD",
  240. "invoiceItems": [{
  241. "productName": "Product 1",
  242. "quantity": 10,
  243. "productPrice": 10.00
  244. }, {
  245. "productName": "Product 2",
  246. "quantity": 10,
  247. "productPrice": 100.00
  248. }]
  249. }
  250.  
  251. {
  252. "title": "Some article title",
  253. "abstract": "Some abstract here",
  254. "keywords": ["keyword1", "keyword2", "keyword3"],
  255. "authors": [{
  256. "fullName": "Author 1",
  257. "institution": "ASE",
  258. "email": "author1@example.com"
  259. }, {
  260. "fullName": "Author 2",
  261. "institution": "ASE",
  262. "email": "author2@example.com"
  263. }]
  264. }
  265.  
  266. //SCHEMA
  267. let schema = {
  268. title: 'Article schema',
  269. type: 'object',
  270. required: ['title', 'abstract', 'keywords', 'authors'],
  271. properties: {
  272. title: {
  273. type: 'string'
  274. },
  275. abstract: {
  276. type: 'string'
  277. },
  278. keywords: {
  279. type: 'array',
  280. minItems: 3,
  281. items: {
  282. type: 'string'
  283. }
  284. },
  285. authors: {
  286. type: 'array',
  287. minItems: 2,
  288. items: {
  289. type: 'object',
  290. required: ['fullName', 'institution', 'email']
  291. }
  292. }
  293. }
  294. }
  295.  
  296. describe("JSON", () => {
  297. describe("GET /article.json", () => {
  298. it('should return a valid json', (done) => {
  299. chai.request(app)
  300. .get('/article.json')
  301. .end((err, res) => {
  302. res.should.have.status(200);
  303. res.body.should.be.a('object');
  304. chai.assert.jsonSchema(res.body, schema)
  305. done();
  306. });
  307. })
  308. })
  309. });
  310. //
  311.  
  312.  
  313. {
  314. "name": "Some name title",
  315. "description": "Some description here",
  316. "sizes": [10, 12, 14],
  317. "price": 200,
  318. "inventory": [{
  319. "supplierName": "Some name",
  320. "quantity": 10,
  321. "aquisitionPrice": 100
  322. }, {
  323. "supplierName": "Some name",
  324. "quantity": 10,
  325. "aquisitionPrice": 100
  326. }]
  327. }
  328.  
  329. {
  330. "accountHolder": "Some Name",
  331. "currentBalance": 100,
  332. "iban": "AABBSS",
  333. "currency": "RON",
  334. "transactions": [
  335. {
  336. "amount": 50,
  337. "transactionType": "IN",
  338. "beneficiaryName": "Some Name",
  339. "approved": false
  340. },
  341. {
  342. "amount": 50,
  343. "transactionType": "IN",
  344. "beneficiaryName": "Some Name",
  345. "approved": true
  346. }
  347. ]
  348. }
  349.  
  350. {
  351. "name": "Some Name",
  352. "year": 3,
  353. "credits": 100,
  354. "superpowers": ["a", "b", "c"],
  355. "grades": [{
  356. "class": "Some class",
  357. "homeworkSubmitted": true,
  358. "examGrade": 5
  359. },{
  360. "class": "Some class",
  361. "homeworkSubmitted": false,
  362. "examGrade": 5
  363. }]
  364. }
  365.  
  366.  
  367. index html
  368. <!DOCTYPE html>
  369. <html>
  370.  
  371. <head>
  372. <script>
  373. document.addEventListener('DOMContentLoaded', () => {
  374. fetch("path")
  375. .then( res => {
  376. return res.json();
  377. })
  378. .then(data => {
  379. let item = document.getElementById('myDiv');
  380. item.innerHTML = JSON.parse(data);
  381. })
  382. .catch(err => {
  383. console.warn(err);
  384. })
  385. });
  386. </script>
  387. </head>
  388.  
  389. <body>
  390. <div id="myDiv"></div>
  391. </body>
  392.  
  393. </html>
  394.  
  395.  
  396. SEQUELIZE
  397. var-0
  398. const express = require('express')
  399. const bodyParser = require('body-parser')
  400. const Sequelize = require('sequelize')
  401.  
  402. const mysql = require('mysql2/promise')
  403.  
  404. const DB_USERNAME = 'root'
  405. const DB_PASSWORD = 'welcome12#'
  406.  
  407. mysql.createConnection({
  408. user : DB_USERNAME,
  409. password : DB_PASSWORD
  410. })
  411. .then(async (connection) => {
  412. await connection.query('DROP DATABASE IF EXISTS tw_exam')
  413. await connection.query('CREATE DATABASE IF NOT EXISTS tw_exam')
  414. })
  415. .catch((err) => {
  416. console.warn(err.stack)
  417. })
  418.  
  419. const sequelize = new Sequelize('tw_exam', DB_USERNAME, DB_PASSWORD,{
  420. dialect : 'mysql',
  421. logging: false
  422. })
  423.  
  424. // let Author = sequelize.define('author', {
  425. // name : Sequelize.STRING,
  426. // email : Sequelize.STRING,
  427. // address : Sequelize.STRING,
  428. // age : Sequelize.INTEGER
  429. // })
  430.  
  431. const app = express()
  432. app.use(bodyParser.json())
  433.  
  434. app.get('/create', async (req, res) => {
  435. try{
  436. await sequelize.sync({force : true})
  437. for (let i = 0; i < 10; i++){
  438. let author = new Author({
  439. name : 'name ' + i,
  440. email : 'name' + i + '@nowhere.com',
  441. address : 'some address on ' + i + 'th street'
  442. })
  443. await author.save()
  444. }
  445. res.status(201).json({message : 'created'})
  446. }
  447. catch(err){
  448. console.warn(err.stack)
  449. res.status(500).json({message : 'server error'})
  450. }
  451. })
  452.  
  453. app.get('/authors', async (req, res) => {
  454. // should get all authors
  455. try{
  456. let authors = await Author.findAll()
  457. res.status(200).json(authors)
  458. }
  459. catch(err){
  460. // console.warn(err.stack)
  461. res.status(500).json({message : 'server error'})
  462. }
  463. })
  464.  
  465. app.post('/authors', async (req, res) => {
  466. // should add an author
  467. // author names and emails cannot be empty
  468. // author addresses can be empty
  469. // author emails have to be valid
  470. try{
  471. let author = new Author(req.body)
  472. await author.save()
  473. res.status(201).json({message : 'created'})
  474. }
  475. catch(err){
  476. // console.warn(err.stack)
  477. res.status(500).json({message : 'server error'})
  478. }
  479. })
  480.  
  481. app.listen(8080)
  482.  
  483. module.exports = app
  484.  
  485.  
  486.  
  487. ___________
  488. var-1
  489.  
  490. const express = require('express')
  491. const bodyParser = require('body-parser')
  492. const Sequelize = require('sequelize')
  493.  
  494. const mysql = require('mysql2/promise')
  495.  
  496. const DB_USERNAME = 'root'
  497. const DB_PASSWORD = 'welcome12#'
  498.  
  499. mysql.createConnection({
  500. user : DB_USERNAME,
  501. password : DB_PASSWORD
  502. })
  503. .then(async (connection) => {
  504. await connection.query('DROP DATABASE IF EXISTS tw_exam')
  505. await connection.query('CREATE DATABASE IF NOT EXISTS tw_exam')
  506. })
  507. .catch((err) => {
  508. console.warn(err.stack)
  509. })
  510.  
  511. const sequelize = new Sequelize('tw_exam', DB_USERNAME, DB_PASSWORD,{
  512. dialect : 'mysql',
  513. logging: false
  514. })
  515.  
  516. let Author = sequelize.define('author', {
  517. name : Sequelize.STRING,
  518. email : Sequelize.STRING,
  519. address : Sequelize.STRING,
  520. age : Sequelize.INTEGER
  521. },{
  522. timestamps : false
  523. })
  524.  
  525.  
  526.  
  527.  
  528. const app = express()
  529. app.use(bodyParser.json())
  530.  
  531. app.get('/create', async (req, res) => {
  532. try{
  533. await sequelize.sync({force : true})
  534. for (let i = 0; i < 10; i++){
  535. let author = new Author({
  536. name : 'name ' + i,
  537. email : 'name' + i + '@nowhere.com',
  538. address : 'some address on ' + i + 'th street',
  539. age : 30 + i
  540. })
  541. await author.save()
  542. }
  543. console.warn('CREATED')
  544. res.status(201).json({message : 'created'})
  545. }
  546. catch(err){
  547. console.warn(err.stack)
  548. res.status(500).json({message : 'server error'})
  549. }
  550. })
  551.  
  552. app.get('/authors', async (req, res) => {
  553. try{
  554. let authors = await Author.findAll()
  555. res.status(200).json(authors)
  556. }
  557. catch(err){
  558. // console.warn(err.stack)
  559. res.status(500).json({message : 'server error'})
  560. }
  561. })
  562.  
  563. app.post('/authors', async (req, res) => {
  564. try{
  565. let author = new Author(req.body)
  566. await author.save()
  567. res.status(201).json({message : 'created'})
  568. }
  569. catch(err){
  570. // console.warn(err.stack)
  571. res.status(500).json({message : 'server error'})
  572. }
  573. })
  574.  
  575. app.put('/authors/:id', async (req, res) => {
  576. // TODO: implementați funcția
  577. // adăugați o metoda pentru modificarea autorului
  578. // un autor inexistent nu poate fi modificat
  579. // numai câmpurile care sunt definite in request trebuie actualizate
  580.  
  581. // add the method to modify an author
  582. // a non existant author cannot be updated
  583. // only defined fields should be updated
  584. try{
  585. let author = await Author.findById(req.params.id)
  586. if (!author){
  587. res.status(404).json({message : 'not found'})
  588. }
  589. else{
  590. author.name = req.body.name ? req.body.name : author.name
  591. author.email = req.body.email ? req.body.email : author.email
  592. author.address = req.body.address ? req.body.address : author.address
  593. author.age = req.body.age ? req.body.age : author.age
  594. await author.save()
  595. res.status(202).json({message : 'accepted'})
  596. }
  597. }
  598. catch(err){
  599. // console.warn(err.stack)
  600. res.status(500).json({message : 'server error'})
  601. }
  602. })
  603.  
  604. app.delete('/authors/:id', async (req, res) => {
  605. // add the method to delete an author
  606. // a non existant author cannot be deleted
  607. try{
  608. let author = await Author.findById(req.params.id)
  609. if (!author){
  610. res.status(404).json({message : 'not found'})
  611. }
  612. else{
  613. await author.destroy()
  614. res.status(202).json({message : 'accepted'})
  615. }
  616. }
  617. catch(err){
  618. // console.warn(err.stack)
  619. res.status(500).json({message : 'server error'})
  620. }
  621.  
  622. })
  623.  
  624. app.listen(8080)
  625.  
  626. module.exports = app
  627.  
  628.  
  629. __________________
  630. var-2
  631.  
  632. const express = require('express')
  633. const bodyParser = require('body-parser')
  634. const Sequelize = require('sequelize')
  635.  
  636. const mysql = require('mysql2/promise')
  637.  
  638. const DB_USERNAME = 'root'
  639. const DB_PASSWORD = 'welcome12#'
  640.  
  641. mysql.createConnection({
  642. user : DB_USERNAME,
  643. password : DB_PASSWORD
  644. })
  645. .then(async (connection) => {
  646. await connection.query('DROP DATABASE IF EXISTS tw_exam')
  647. await connection.query('CREATE DATABASE IF NOT EXISTS tw_exam')
  648. })
  649. .catch((err) => {
  650. console.warn(err.stack)
  651. })
  652.  
  653. const sequelize = new Sequelize('tw_exam', DB_USERNAME, DB_PASSWORD,{
  654. dialect : 'mysql',
  655. logging: false
  656. })
  657.  
  658. let Author = sequelize.define('author', {
  659. name : Sequelize.STRING,
  660. email : Sequelize.STRING,
  661. address : Sequelize.STRING,
  662. age : Sequelize.INTEGER
  663. })
  664.  
  665. const app = express()
  666. app.use(bodyParser.json())
  667.  
  668. app.get('/create', async (req, res) => {
  669. try{
  670. await sequelize.sync({force : true})
  671. for (let i = 0; i < 10; i++){
  672. let author = new Author({
  673. name : 'name ' + i,
  674. email : 'name' + i + '@nowhere.com',
  675. address : 'some address on ' + i + 'th street'
  676. })
  677. await author.save()
  678. }
  679. res.status(201).json({message : 'created'})
  680. }
  681. catch(err){
  682. console.warn(err.stack)
  683. res.status(500).json({message : 'server error'})
  684. }
  685. })
  686.  
  687. app.get('/authors', async (req, res) => {
  688. // TODO: adăugați funcția pentru cererea listei autorilor
  689. // ar trebui să trimită clientului lista autorilor
  690. // ar trebui să permită paginare cu un număr de pagina pageNo și o mărime de pagină pageSize trimiși prin query
  691. // TODO: add the function to get all authors
  692. // should get all authors
  693. // should allow for pagination with a pageNo and a pageSize possibly sent as query parameters
  694. try{
  695. let pageSize = parseInt(req.query.pageSize)
  696. pageSize = pageSize ? parseInt(req.query.pageSize) : 5
  697. let authors
  698. let pageNo = parseInt(req.query.pageNo)
  699. if (pageNo){
  700. authors = await Author.findAll({
  701. offset : pageNo * pageSize,
  702. limit : pageSize
  703. })
  704. }
  705. else{
  706. authors = await Author.findAll()
  707. }
  708. res.status(200).json(authors)
  709. }
  710. catch(err){
  711. console.warn(err.stack)
  712. res.status(500).json({message : 'server error'})
  713. }
  714. })
  715.  
  716. app.post('/authors', async (req, res) => {
  717. try{
  718. let author = new Author(req.body)
  719. await author.save()
  720. res.status(201).json({message : 'created'})
  721. }
  722. catch(err){
  723. // console.warn(err.stack)
  724. res.status(500).json({message : 'server error'})
  725. }
  726. })
  727.  
  728. app.listen(8080)
  729.  
  730. module.exports = app
  731.  
  732. ________
  733.  
  734. var-3
  735.  
  736. const express = require('express')
  737. const bodyParser = require('body-parser')
  738. const Sequelize = require('sequelize')
  739. const Op = Sequelize.Op
  740.  
  741. const mysql = require('mysql2/promise')
  742.  
  743. const DB_USERNAME = 'root'
  744. const DB_PASSWORD = 'welcome12#'
  745.  
  746. mysql.createConnection({
  747. user : DB_USERNAME,
  748. password : DB_PASSWORD
  749. })
  750. .then(async (connection) => {
  751. await connection.query('DROP DATABASE IF EXISTS tw_exam')
  752. await connection.query('CREATE DATABASE IF NOT EXISTS tw_exam')
  753. })
  754. .catch((err) => {
  755. console.warn(err.stack)
  756. })
  757.  
  758. const sequelize = new Sequelize('tw_exam', DB_USERNAME, DB_PASSWORD,{
  759. dialect : 'mysql',
  760. logging: false
  761. })
  762.  
  763. let Author = sequelize.define('author', {
  764. name : Sequelize.STRING,
  765. email : Sequelize.STRING,
  766. address : Sequelize.STRING,
  767. age : Sequelize.INTEGER
  768. })
  769.  
  770. const app = express()
  771. app.use(bodyParser.json())
  772.  
  773. app.get('/create', async (req, res) => {
  774. try{
  775. await sequelize.sync({force : true})
  776. for (let i = 0; i < 10; i++){
  777. let author = new Author({
  778. name : 'name ' + i,
  779. email : 'name' + i + '@nowhere.com',
  780. address : 'some address on ' + i + 'th street'
  781. })
  782. await author.save()
  783. }
  784. res.status(201).json({message : 'created'})
  785. }
  786. catch(err){
  787. console.warn(err.stack)
  788. res.status(500).json({message : 'server error'})
  789. }
  790. })
  791.  
  792. app.get('/authors', async (req, res) => {
  793. // TODO: implement the function
  794. // should get all authors
  795. // should allow for filtering based on address and email (filters are called address and email and are sent as query parameters)
  796. try{
  797. let addressFilter = req.query.address
  798. let emailFilter = req.query.email
  799. let query = {where : {}}
  800. if (addressFilter){
  801. query.where.address = {
  802. [Op.like] : `%${addressFilter}%`
  803. }
  804. }
  805. if (emailFilter){
  806. query.where.email = {
  807. [Op.like] : `%${emailFilter}%`
  808. }
  809. }
  810. let authors = await Author.findAll(query)
  811. res.status(200).json(authors)
  812. }
  813. catch(err){
  814. console.warn(err.stack)
  815. res.status(500).json({message : 'server error'})
  816. }
  817. })
  818.  
  819. app.post('/authors', async (req, res) => {
  820. try{
  821. let author = new Author(req.body)
  822. await author.save()
  823. res.status(201).json({message : 'created'})
  824. }
  825. catch(err){
  826. // console.warn(err.stack)
  827. res.status(500).json({message : 'server error'})
  828. }
  829. })
  830.  
  831. app.listen(8080)
  832.  
  833. module.exports = app
  834.  
  835. var-4
  836. const express = require('express')
  837. const bodyParser = require('body-parser')
  838. const Sequelize = require('sequelize')
  839.  
  840. const mysql = require('mysql2/promise')
  841.  
  842. const DB_USERNAME = 'root'
  843. const DB_PASSWORD = 'welcome12#'
  844.  
  845. mysql.createConnection({
  846. user : DB_USERNAME,
  847. password : DB_PASSWORD
  848. })
  849. .then(async (connection) => {
  850. await connection.query('DROP DATABASE IF EXISTS tw_exam')
  851. await connection.query('CREATE DATABASE IF NOT EXISTS tw_exam')
  852. })
  853. .catch((err) => {
  854. console.warn(err.stack)
  855. })
  856.  
  857. const sequelize = new Sequelize('tw_exam', DB_USERNAME, DB_PASSWORD,{
  858. dialect : 'mysql',
  859. logging: false,
  860. define: {
  861. timestamps: false
  862. },
  863. })
  864.  
  865. let Author = sequelize.define('author', {
  866. name : Sequelize.STRING,
  867. email : Sequelize.STRING,
  868. address : Sequelize.STRING,
  869. age : Sequelize.INTEGER
  870. })
  871.  
  872. let Book = sequelize.define('book', {
  873. title : Sequelize.STRING,
  874. pages : Sequelize.INTEGER
  875. })
  876.  
  877. Author.hasMany(Book)
  878.  
  879. const app = express()
  880. app.use(bodyParser.json())
  881.  
  882. app.get('/create', async (req, res) => {
  883. try{
  884. await sequelize.sync({force : true})
  885. for (let i = 0; i < 10; i++){
  886. let author = new Author({
  887. name : 'name ' + i,
  888. email : 'name' + i + '@nowhere.com',
  889. address : 'some address on ' + i + 'th street'
  890. })
  891. await author.save()
  892. }
  893. res.status(201).json({message : 'created'})
  894. }
  895. catch(err){
  896. console.warn(err.stack)
  897. res.status(500).json({message : 'server error'})
  898. }
  899. })
  900.  
  901. app.get('/authors', async (req, res) => {
  902. // should get all authors
  903. try{
  904. let authors = await Author.findAll()
  905. res.status(200).json(authors)
  906. }
  907. catch(err){
  908. console.warn(err.stack)
  909. res.status(500).json({message : 'server error'})
  910. }
  911. })
  912.  
  913. app.post('/authors', async (req, res) => {
  914. try{
  915. let author = new Author(req.body)
  916. await author.save()
  917. res.status(201).json({message : 'created'})
  918. }
  919. catch(err){
  920. // console.warn(err.stack)
  921. res.status(500).json({message : 'server error'})
  922. }
  923. })
  924.  
  925. app.post('/authors/:id/books', async (req, res) => {
  926. // should add a book to an author
  927. try{
  928. let author = await Author.findById(req.params.id)
  929. if (author){
  930. let book = req.body
  931. book.authorId = author.id
  932. await Book.create(book)
  933. res.status(201).json({message : 'created'})
  934. }
  935. else{
  936. res.status(404).json({message : 'not found'})
  937. }
  938. }
  939. catch(e){
  940. console.warn(e)
  941. res.status(500).json({message : 'server error'})
  942. }
  943. })
  944.  
  945. app.get('/authors/:id/books', async (req, res) => {
  946. // should list all of an authors' books
  947. try{
  948. let author = await Author.findById(req.params.id, {include : [Book]})
  949. if (author){
  950. let books = author.books
  951. res.status(200).json(books)
  952. }
  953. else{
  954. res.status(404).json({message : 'not found'})
  955. }
  956. }
  957. catch(e){
  958. console.warn(e)
  959. res.status(500).json({message : 'server error'})
  960. }
  961. })
  962.  
  963.  
  964. app.listen(8080)
  965.  
  966. module.exports = app
  967.  
  968. var-9
  969. app.post('/cars', (req, res, next) => {
  970. if (req.body.constructor === Object && Object.keys(req.body).length === 0) {
  971. res.status(500).json({ message: 'Body is missing' });
  972. }
  973. else {
  974. if (req.body.make && req.body.model && req.body.price) {
  975. if (req.body.price > 0) {
  976. let doesExist = false;
  977. app.locals.cars.forEach(car => {
  978. if (car.model == req.body.model) {
  979. doesExist = true;
  980. }
  981. });
  982.  
  983. if (doesExist) {
  984. res.status(500).json({ message: 'Car already exists' });
  985.  
  986. }
  987. else {
  988. let newCar = {
  989. make: req.body.make,
  990. model: req.body.model,
  991. price: req.body.price
  992. }
  993. app.locals.cars.push(newCar);
  994. res.status(201).json({ message: 'Created' });
  995. }
  996. }
  997. else {
  998. res.status(500).json({ message: 'Price should be a positive number' });
  999. }
  1000. }
  1001. else {
  1002. res.status(500).json({ message: 'Invalid body format' });
  1003. }
  1004. }
  1005. })
  1006.  
  1007. var-0 REACT-EXAMPLE
  1008. // TODO : adăugați o componentă Robot
  1009. // afișați o componentă Robot pentru fiecare robot din stare
  1010. // o componentă robot ar trebui să afișeze un robot și să permită ștergerea lui
  1011.  
  1012. // TODO : add a Robot component
  1013. // show a Robot component for each robot in the state
  1014. // a robot component should show a robot and allow deletion of a robot
  1015.  
  1016. class Robot extends Component {
  1017. render() {
  1018. let {item} = this.props
  1019. return (
  1020. <div>
  1021. Hello, my name is {item.name}. I am a {item.type} and weigh {item.mass}
  1022. <input type="button" value="delete" onClick={() => this.props.onDelete(item.id)} />
  1023. </div>
  1024. )
  1025. }
  1026. }
  1027. export default Robot
  1028.  
  1029. class RobotList extends Component {
  1030. constructor(){
  1031. super()
  1032. this.state = {
  1033. robots : []
  1034. }
  1035. this.deleteRobot = (id) => {
  1036. this.store.deleteRobot(id)
  1037. }
  1038. }
  1039. componentDidMount(){
  1040. this.store = new RobotStore()
  1041. this.setState({
  1042. robots : this.store.getRobots()
  1043. })
  1044. this.store.emitter.addListener('UPDATE', () => {
  1045. this.setState({
  1046. robots : this.store.getRobots()
  1047. })
  1048. })
  1049. }
  1050. render() {
  1051. // a robot component should show a robot and allow deletion of a robot
  1052. return (
  1053. <div>
  1054.  
  1055. {
  1056. this.state.robots.map((e, i) =>
  1057. <Robot item={e} key={i} onDelete={this.deleteRobot} />
  1058. )
  1059. }
  1060. </div>
  1061. )
  1062. }
  1063. }
  1064. export default RobotList
  1065.  
  1066. import React, { Component } from 'react'
  1067. import RobotList from './RobotList'
  1068.  
  1069. class App extends Component {
  1070. render() {
  1071. return (
  1072. <div>
  1073. A list of robots
  1074. <RobotList />
  1075. </div>
  1076. )
  1077. }
  1078. }
  1079.  
  1080. export default App
  1081.  
  1082. __________________________________________________________________________
  1083. var-1 REACT-EXAMPLE
  1084. // TODO : adăugați o componentă RobotForm
  1085. // RobotForm ar să permită adăugarea unui robot
  1086.  
  1087. // TODO : add a RobotForm component
  1088. // RobotForm should be able to add a robot
  1089.  
  1090. class RobotForm extends Component {
  1091. constructor(props){
  1092. super(props)
  1093. this.state = {
  1094. type : '',
  1095. name : '',
  1096. mass : ''
  1097. }
  1098. this.handleChange = (evt) => {
  1099. this.setState({
  1100. [evt.target.name] : evt.target.value
  1101. })
  1102. }
  1103. }
  1104. render() {
  1105. return (
  1106. <div>
  1107. <label htmlFor="type">Type</label>
  1108. <input type="text" id="type" name="type" onChange={this.handleChange} />
  1109. <label htmlFor="name">Name</label>
  1110. <input type="name" id="name" name="name" onChange={this.handleChange} />
  1111. <label htmlFor="mass">Mass</label>
  1112. <input type="text" id="mass" name="mass" onChange={this.handleChange} />
  1113. <input type="button" value="add" onClick={() => this.props.onAdd({
  1114. name : this.state.name,
  1115. type : this.state.type,
  1116. mass : this.state.mass
  1117. })} />
  1118. </div>
  1119. )
  1120. }
  1121. }
  1122.  
  1123. import React, { Component } from 'react'
  1124. import RobotStore from '../stores/RobotStore'
  1125. import Robot from './Robot'
  1126. import RobotForm from './RobotForm'
  1127.  
  1128. class RobotList extends Component {
  1129. // add a form to allow adding robots
  1130. constructor(){
  1131. super()
  1132. this.state = {
  1133. robots : []
  1134. }
  1135. this.addRobot = (robot) => {
  1136. this.store.addRobot(robot)
  1137. }
  1138. }
  1139. componentDidMount(){
  1140. this.store = new RobotStore()
  1141. this.setState({
  1142. robots : this.store.getRobots()
  1143. })
  1144. this.store.emitter.addListener('UPDATE', () => {
  1145. this.setState({
  1146. robots : this.store.getRobots()
  1147. })
  1148. })
  1149. }
  1150. render() {
  1151. return (
  1152. <div>
  1153.  
  1154. {
  1155. this.state.robots.map((e, i) =>
  1156. <Robot item={e} key={i} />
  1157. )
  1158. }
  1159. <RobotForm onAdd={this.addRobot} />
  1160. </div>
  1161. )
  1162. }
  1163. }
  1164.  
  1165. export default RobotList
  1166.  
  1167. __________________________________________________________________________
  1168. var-2 REACT-EXAMPLE
  1169. // TODO : adăugați posibilitatea de a edita un robot
  1170. // editarea se face prin intermediul unui robot cu 2 stări, una de vizualizare și una de editare
  1171.  
  1172. // TODO : add the posibility to edit a robot
  1173. // editing is done via 2 states a view state and an edit state
  1174.  
  1175. import React, { Component } from 'react'
  1176.  
  1177. class Robot extends Component {
  1178. constructor(props){
  1179. super(props)
  1180. let {item} = this.props
  1181. this.state = {
  1182. name : item.name,
  1183. type : item.type,
  1184. mass : item.mass,
  1185. isEditing : false
  1186. }
  1187. this.handleChange = (evt) => {
  1188. this.setState({
  1189. [evt.target.name] : evt.target.value
  1190. })
  1191. }
  1192. }
  1193. render() {
  1194. let {item} = this.props
  1195. if (this.state.isEditing){
  1196. return (
  1197. <div>
  1198. Hello, my name is
  1199. <input type="text" id="type" name="type" onChange={this.handleChange} value={this.state.type} />
  1200. . I am a
  1201. <input type="text" id="name" name="name" onChange={this.handleChange} value={this.state.name} />
  1202. and weigh
  1203. <input type="text" id="mass" name="mass" onChange={this.handleChange} value={this.state.mass} />
  1204. <input type="button" value="save" onClick={() => {
  1205. this.props.onSave(item.id, {
  1206. name : this.state.name,
  1207. type : this.state.type,
  1208. mass : this.state.mass
  1209. })
  1210. this.setState({isEditing : false})
  1211. }
  1212. } />
  1213. <input type="button" value="cancel" onClick={() => this.setState({isEditing : false})} />
  1214. </div>
  1215. )
  1216. }
  1217. else{
  1218. return (
  1219. <div>
  1220. Hello, my name is {item.name}. I am a {item.type} and weigh {item.mass}
  1221. <input type="button" value="edit" onClick={() => this.setState({isEditing : true})} />
  1222. </div>
  1223. )
  1224. }
  1225. }
  1226. }
  1227.  
  1228. export default Robot
  1229.  
  1230.  
  1231. __________________________________________________________________________
  1232. var-3 REACT-EXAMPLE
  1233. // TODO : adăugați posibilitatea de a vizualiza detaliile unui robot
  1234. // RobotList are 2 stări una de detalii și una de listă
  1235. // se poate trece în starea de detalii printr-un buton pe fiecare robot
  1236. // se poate trece înapoi la listă printr-un buton de anulare
  1237. // TODO : add the posibility to view a robot's details
  1238. // RobotList has 2 states, one for details for a robot and one for the full list of robots
  1239. // passing to the details state is done with a button on each robot
  1240. // returning tothe list is done with a cancel button
  1241.  
  1242. import React, { Component } from 'react'
  1243.  
  1244. class Robot extends Component {
  1245. render() {
  1246. let {item} = this.props
  1247. return (
  1248. <div>
  1249. Hello, my name is {item.name}. I am a {item.type} and weigh {item.mass}
  1250. <input type="button" value="select" onClick={() => this.props.onSelect(item.id)} />
  1251. </div>
  1252. )
  1253. }
  1254. }
  1255.  
  1256. export default Robot
  1257.  
  1258. import React, { Component } from 'react'
  1259. import RobotStore from '../stores/RobotStore'
  1260. import Robot from './Robot'
  1261. import RobotDetails from './RobotDetails'
  1262.  
  1263. class RobotList extends Component {
  1264. constructor(){
  1265. super()
  1266. this.state = {
  1267. robots : [],
  1268. selected : null
  1269. }
  1270. this.selectRobot = (id) => {
  1271. this.store.selectRobot(id)
  1272. }
  1273. this.cancelSelection = () => {
  1274. this.setState({
  1275. selected : null
  1276. })
  1277. }
  1278. }
  1279. componentDidMount(){
  1280. this.store = new RobotStore()
  1281. this.setState({
  1282. robots : this.store.getRobots()
  1283. })
  1284. this.store.emitter.addListener('UPDATE', () => {
  1285. this.setState({
  1286. robots : this.store.getRobots(),
  1287. selected : this.store.getSelected()
  1288. })
  1289. })
  1290. }
  1291. render() {
  1292. // a robot component should show a robot and allow deletion of a robot
  1293. if (this.state.selected){
  1294. return (
  1295. <RobotDetails item={this.state.selected} onCancel={this.cancelSelection} />
  1296. )
  1297. }
  1298. else{
  1299. return (
  1300. <div>
  1301.  
  1302. {
  1303. this.state.robots.map((e, i) =>
  1304. <Robot item={e} key={i} onSelect={this.selectRobot} />
  1305. )
  1306. }
  1307. </div>
  1308. )
  1309. }
  1310. }
  1311. }
  1312.  
  1313. export default RobotList
  1314.  
  1315. import React, { Component } from 'react'
  1316.  
  1317. class RobotDetails extends Component {
  1318. render() {
  1319. let {item} = this.props
  1320. return (
  1321. <div>
  1322. Details for {item.name}
  1323. <input type="button" value="cancel" onClick={() => this.props.onCancel()} />
  1324. </div>
  1325. )
  1326. }
  1327. }
  1328.  
  1329. export default RobotDetails
  1330.  
  1331.  
  1332.  
  1333. __________________________________________________________________________
  1334. var-4 REACT-EXAMPLE
  1335. // TODO: adăugați posibilitatea de a filtra roboții după name și type
  1336. // filtrarea se face pe baza a 2 text input-uri și se produce la fiecare tastă apăsată
  1337.  
  1338. // TODO: add the possiblity to filter robots according to name and type
  1339. // filtering is done via 2 text inputs and happens whenever a key is pressed
  1340.  
  1341. import React, { Component } from 'react'
  1342. import RobotStore from '../stores/RobotStore'
  1343. import Robot from './Robot'
  1344.  
  1345. class RobotList extends Component {
  1346. constructor(){
  1347. super()
  1348. this.state = {
  1349. robots : [],
  1350. nameFilter : '',
  1351. typeFilter : ''
  1352. }
  1353. this.handleChange = (evt) => {
  1354. this.setState({
  1355. [evt.target.name] : evt.target.value
  1356. })
  1357. }
  1358. }
  1359. componentDidMount(){
  1360. this.store = new RobotStore()
  1361. this.setState({
  1362. robots : this.store.getRobots()
  1363. })
  1364. this.store.emitter.addListener('UPDATE', () => {
  1365. this.setState({
  1366. robots : this.store.getRobots()
  1367. })
  1368. })
  1369. }
  1370. render() {
  1371. // a robot component should show a robot and allow deletion of a robot
  1372. let robots = this.state.robots.filter((e) => e.name.indexOf(this.state.nameFilter) !== -1).filter((e) => e.type.indexOf(this.state.typeFilter) !== -1)
  1373. return (
  1374. <div>
  1375. <div>
  1376. <input type="text" value={this.state.filter} onChange={this.handleChange} name="nameFilter" id="nameFilter" />
  1377. <input type="text" value={this.state.filter} onChange={this.handleChange} name="typeFilter" id="typeFilter" />
  1378. </div>
  1379. {
  1380. robots.map((e, i) =>
  1381. <Robot item={e} key={i} />
  1382. )
  1383. }
  1384. </div>
  1385. )
  1386. }
  1387. }
  1388.  
  1389. export default RobotList
  1390.  
  1391.  
  1392. __________________________________________________________________________
  1393. var-9 REACT-EXAMPLE
  1394. COUPON
  1395.  
  1396. import React from 'react';
  1397.  
  1398. class AddCoupon extends React.Component {
  1399. constructor(props) {
  1400. super(props);
  1401. this.state = {
  1402. category: '',
  1403. discount: '',
  1404. availability: ''
  1405. };
  1406. }
  1407.  
  1408. addCoupon = () => {
  1409. let coupon = {
  1410. category: this.state.category,
  1411. discount: this.state.discount,
  1412. availability: this.state.availability
  1413. };
  1414. this.props.onAdd(coupon);
  1415. }
  1416.  
  1417. onChange = (e) => {
  1418. this.setState({
  1419. [e.target.name]:e.target.value
  1420. })
  1421. }
  1422.  
  1423.  
  1424.  
  1425. render() {
  1426. return (
  1427. <div>
  1428. <input type="text" id="category" name="category" placeholder="Category" value={this.state.category} onChange={this.onChange.bind(this)}/>
  1429. <input type="text" id="discount" name="discount" placeholder="Discount" value={this.state.discount} onChange={this.onChange.bind(this)}/>
  1430. <input type="text" id="availability" name="availability" placeholder="Availability" value={this.state.availability} onChange={this.onChange.bind(this)}/>
  1431. <input type="button" value="add coupon" onClick={this.addCoupon.bind(this)}/>
  1432. </div>
  1433. )
  1434. }
  1435. }
  1436.  
  1437. export default AddCoupon;
  1438.  
  1439. import React from 'react';
  1440. import AddCoupon from './AddCoupon';
  1441. class CouponList extends React.Component {
  1442. constructor(){
  1443. super();
  1444. this.state = {
  1445. coupons: []
  1446. };
  1447. }
  1448.  
  1449. onAddCoupon = (coupon) => {
  1450. let temp = this.state.coupons;
  1451. temp.push(coupon);
  1452. this.setState({
  1453. coupons: temp
  1454. });
  1455. }
  1456.  
  1457.  
  1458.  
  1459. render() {
  1460. let items = this.state.coupons.map((item, index) => {
  1461. return <li key={index}>{item.category}</li>
  1462. });
  1463.  
  1464. return (
  1465. <div>
  1466. <AddCoupon onAdd={this.onAddCoupon.bind(this)}/>
  1467. <ul>
  1468. {items}
  1469. </ul>
  1470. </div>
  1471. )
  1472. }
  1473. }
  1474.  
  1475. export default CouponList;
  1476.  
  1477. import React, { Component } from 'react';
  1478. import CouponList from './CouponList';
  1479. class App extends Component {
  1480. render() {
  1481. return (
  1482. <div>
  1483. <CouponList/>
  1484. </div>
  1485. );
  1486. }
  1487. }
  1488.  
  1489. export default App;
  1490.  
  1491. //1
  1492. <!DOCTYPE html>
  1493. <html>
  1494. <head>
  1495. <title>var - 0</title>
  1496. <link rel="stylesheet" type="text/css" href="main.css">
  1497. </head>
  1498. <body>
  1499. <div class="main">
  1500. <div class="sidebar">
  1501. <div class="sidebar-item">1</div>
  1502. <div class="sidebar-item">2</div>
  1503. <div class="sidebar-item">3</div>
  1504. <div class="sidebar-item">4</div>
  1505. </div>
  1506. <div class="view">
  1507. <div class="top">top</div>
  1508. <div class="bottom">bottom</div>
  1509. </div>
  1510. </div>
  1511. </body>
  1512. </html>
  1513.  
  1514. *{
  1515. box-sizing: border-box;
  1516. border : 1px solid black;
  1517. margin : 0px;
  1518. padding: 0px;
  1519. font-size: xx-large;
  1520. }
  1521.  
  1522. .main{
  1523. display : grid;
  1524. width: 80vw;
  1525. height: 80vh;
  1526. text-align: center;
  1527. line-height: 100%;
  1528. grid-template-columns: 20vw 60vw;
  1529. grid-template-rows: 80vh;
  1530. grid-template-areas:
  1531. "sidebar view"
  1532. ;
  1533. }
  1534.  
  1535. .sidebar{
  1536. grid-area : sidebar;
  1537. }
  1538.  
  1539. .sidebar-item{
  1540. height : 20vh;
  1541. }
  1542.  
  1543. .view{
  1544. grid-area : view;
  1545. }
  1546.  
  1547. .top{
  1548. height : 20vh;
  1549. }
  1550.  
  1551. .bottom{
  1552. height : 60vh;
  1553. }
  1554.  
  1555. //2
  1556. <!DOCTYPE html>
  1557. <html>
  1558. <head>
  1559. <title>var - 0</title>
  1560. <link rel="stylesheet" type="text/css" href="main.css">
  1561. </head>
  1562. <body>
  1563. <div class="main">
  1564. <div class="first">1</div>
  1565. <div class="second">2</div>
  1566. <div class="third">3</div>
  1567. <div class="fourth">4</div>
  1568. <div class="fifth">5</div>
  1569. <div class="sixth">6</div>
  1570. </div>
  1571. </body>
  1572. </html>
  1573.  
  1574. *{
  1575. box-sizing: border-box;
  1576. border : 1px solid black;
  1577. margin : 0px;
  1578. padding: 0px;
  1579. font-size: xx-large;
  1580. }
  1581.  
  1582. .main{
  1583. display : grid;
  1584. width: 60vw;
  1585. height: 30vh;
  1586. text-align: center;
  1587. line-height: 100%;
  1588. grid-template-columns: 10vw 10vw 10vw 10vw 10vw 10vw;
  1589. grid-template-rows: 10vh 10vh 10vh;
  1590. grid-template-areas:
  1591. ". first first second second ."
  1592. "sixth sixth . . third third"
  1593. ". fifth fifth fourth fourth ."
  1594. ;
  1595. }
  1596.  
  1597. .first{
  1598. grid-area : first;
  1599. }
  1600.  
  1601. .second{
  1602. grid-area : second;
  1603. }
  1604.  
  1605. .third{
  1606. grid-area : third;
  1607. }
  1608.  
  1609. .fourth{
  1610. grid-area : fourth;
  1611. }
  1612.  
  1613. .fifth{
  1614. grid-area : fifth;
  1615. }
  1616.  
  1617. .sixth{
  1618. grid-area : sixth;
  1619. }
  1620.  
  1621. //3
  1622.  
  1623. <!DOCTYPE html>
  1624. <html>
  1625. <head>
  1626. <title>var - 0</title>
  1627. <link rel="stylesheet" type="text/css" href="main.css">
  1628. </head>
  1629. <body>
  1630. <div class="main">
  1631. <div class="header">header</div>
  1632. <div class="column">
  1633. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  1634. </div>
  1635. <div class="column">
  1636. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  1637. </div>
  1638. <div class="column">
  1639. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  1640. </div>
  1641. </div>
  1642. </body>
  1643. </html>
  1644.  
  1645. *{
  1646. box-sizing: border-box;
  1647. border : 1px solid black;
  1648. margin : 0px;
  1649. padding: 0px;
  1650. font-size: xx-large;
  1651. }
  1652.  
  1653. .main{
  1654. display : grid;
  1655. width: 100%;
  1656. height: 100%;
  1657. grid-template-columns: 33.33% 33.33% 33.33%;
  1658. grid-template-rows: 100%;
  1659. grid-template-areas:
  1660. "first second third"
  1661. ;
  1662. }
  1663.  
  1664. .header{
  1665. height:20vh;
  1666. width:100%;
  1667. background-color: yellow;
  1668. position: fixed;
  1669. top:0px;
  1670. }
  1671.  
  1672. .column{
  1673. float:left;
  1674. }
  1675.  
  1676. //4
  1677. <!DOCTYPE html>
  1678. <html>
  1679. <head>
  1680. <title>var - 0</title>
  1681. <link rel="stylesheet" type="text/css" href="main.css">
  1682. </head>
  1683. <body>
  1684. <div class="main">
  1685.  
  1686. </div>
  1687. </body>
  1688. </html>
  1689.  
  1690. *{
  1691. box-sizing: border-box;
  1692. border : 1px solid black;
  1693. margin : 0px;
  1694. padding: 0px;
  1695. font-size: xx-large;
  1696. }
  1697.  
  1698. .main{
  1699. display : grid;
  1700. width: 80vw;
  1701. height: 80vh;
  1702. max-width:100%;
  1703. max-height:100%;
  1704. grid-template-columns: 20vw 60vw;
  1705. grid-template-rows: 80vh;
  1706. grid-template-areas:
  1707. "sidebar view"
  1708. ;
  1709. }
  1710.  
  1711. .sidebar{
  1712. grid-area : sidebar;
  1713. }
  1714.  
  1715. .sidebar-item{
  1716. height : 20vh;
  1717. }
  1718.  
  1719. .view{
  1720. grid-area : view;
  1721. }
  1722.  
  1723. .top{
  1724. height : 20vh;
  1725. }
  1726.  
  1727. .bottom{
  1728. height : 60vh;
  1729. }
  1730.  
  1731. //6
  1732. <!DOCTYPE html>
  1733. <html>
  1734. <head>
  1735. <title>var - 0</title>
  1736. <link rel="stylesheet" type="text/css" href="main.css">
  1737. </head>
  1738. <body>
  1739. <div class="main">
  1740. <div class="sidebar">
  1741. <div class="sidebar-item">1</div>
  1742. <div class="sidebar-item">2</div>
  1743. <div class="sidebar-item">3</div>
  1744. <div class="sidebar-item">4</div>
  1745. </div>
  1746. <div class="view">
  1747. <div class="top">top</div>
  1748. <div class="bottom">bottom</div>
  1749. </div>
  1750. </div>
  1751. </body>
  1752. </html>
  1753.  
  1754. *{
  1755. box-sizing: border-box;
  1756. border : 1px solid black;
  1757. margin : 0px;
  1758. padding: 0px;
  1759. font-size: xx-large;
  1760. }
  1761.  
  1762. .main{
  1763. display : grid;
  1764. width: 80vw;
  1765. height: 80vh;
  1766. max-width:100%;
  1767. max-height:100%;
  1768. grid-template-columns: 20vw 60vw;
  1769. grid-template-rows: 80vh;
  1770. grid-template-areas:
  1771. "sidebar view"
  1772. ;
  1773. }
  1774.  
  1775. .sidebar{
  1776. grid-area : sidebar;
  1777. }
  1778.  
  1779. .sidebar-item{
  1780. height : 20vh;
  1781. }
  1782.  
  1783. .view{
  1784. grid-area : view;
  1785. }
  1786.  
  1787. .top{
  1788. height : 20vh;
  1789. }
  1790.  
  1791. .bottom{
  1792. height : 60vh;
  1793. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement