diff --git a/TERRARIUM/assignment.html b/TERRARIUM/assignment.html new file mode 100644 index 0000000..8527c65 --- /dev/null +++ b/TERRARIUM/assignment.html @@ -0,0 +1,45 @@ + + + + Assignment + + + + + +

ALL ABOUT ME

+
+
+
+ image +
+
+ image +
+
+
+
+

A Brief Intro

+

.....................

+

.....................

+

.....................

+

.....................

+
+
+

My Educational Qualifications

+

.....................

+

.....................

+

.....................

+

.....................

+
+
+

My Achievments

+

.....................

+

.....................

+

.....................

+

.....................

+
+
+
+ + \ No newline at end of file diff --git a/TERRARIUM/images/Chrome.png b/TERRARIUM/images/Chrome.png new file mode 100644 index 0000000..1e7a719 Binary files /dev/null and b/TERRARIUM/images/Chrome.png differ diff --git a/TERRARIUM/images/Firefox.png b/TERRARIUM/images/Firefox.png new file mode 100644 index 0000000..4d9f908 Binary files /dev/null and b/TERRARIUM/images/Firefox.png differ diff --git a/TERRARIUM/images/Graphical mockup.png b/TERRARIUM/images/Graphical mockup.png new file mode 100644 index 0000000..b2667fc Binary files /dev/null and b/TERRARIUM/images/Graphical mockup.png differ diff --git a/2-terrarium/images/plant1.png b/TERRARIUM/images/plant1.png similarity index 100% rename from 2-terrarium/images/plant1.png rename to TERRARIUM/images/plant1.png diff --git a/2-terrarium/images/plant10.png b/TERRARIUM/images/plant10.png similarity index 100% rename from 2-terrarium/images/plant10.png rename to TERRARIUM/images/plant10.png diff --git a/2-terrarium/images/plant11.png b/TERRARIUM/images/plant11.png similarity index 100% rename from 2-terrarium/images/plant11.png rename to TERRARIUM/images/plant11.png diff --git a/2-terrarium/images/plant12.png b/TERRARIUM/images/plant12.png similarity index 100% rename from 2-terrarium/images/plant12.png rename to TERRARIUM/images/plant12.png diff --git a/2-terrarium/images/plant13.png b/TERRARIUM/images/plant13.png similarity index 100% rename from 2-terrarium/images/plant13.png rename to TERRARIUM/images/plant13.png diff --git a/2-terrarium/images/plant14.png b/TERRARIUM/images/plant14.png similarity index 100% rename from 2-terrarium/images/plant14.png rename to TERRARIUM/images/plant14.png diff --git a/2-terrarium/images/plant2.png b/TERRARIUM/images/plant2.png similarity index 100% rename from 2-terrarium/images/plant2.png rename to TERRARIUM/images/plant2.png diff --git a/2-terrarium/images/plant3.png b/TERRARIUM/images/plant3.png similarity index 100% rename from 2-terrarium/images/plant3.png rename to TERRARIUM/images/plant3.png diff --git a/2-terrarium/images/plant4.png b/TERRARIUM/images/plant4.png similarity index 100% rename from 2-terrarium/images/plant4.png rename to TERRARIUM/images/plant4.png diff --git a/2-terrarium/images/plant5.png b/TERRARIUM/images/plant5.png similarity index 100% rename from 2-terrarium/images/plant5.png rename to TERRARIUM/images/plant5.png diff --git a/2-terrarium/images/plant6.png b/TERRARIUM/images/plant6.png similarity index 100% rename from 2-terrarium/images/plant6.png rename to TERRARIUM/images/plant6.png diff --git a/2-terrarium/images/plant7.png b/TERRARIUM/images/plant7.png similarity index 100% rename from 2-terrarium/images/plant7.png rename to TERRARIUM/images/plant7.png diff --git a/2-terrarium/images/plant8.png b/TERRARIUM/images/plant8.png similarity index 100% rename from 2-terrarium/images/plant8.png rename to TERRARIUM/images/plant8.png diff --git a/2-terrarium/images/plant9.png b/TERRARIUM/images/plant9.png similarity index 100% rename from 2-terrarium/images/plant9.png rename to TERRARIUM/images/plant9.png diff --git a/2-terrarium/images/screenshot_gray.png b/TERRARIUM/images/screenshot_gray.png similarity index 100% rename from 2-terrarium/images/screenshot_gray.png rename to TERRARIUM/images/screenshot_gray.png diff --git a/TERRARIUM/index.html b/TERRARIUM/index.html new file mode 100644 index 0000000..4a29bfc --- /dev/null +++ b/TERRARIUM/index.html @@ -0,0 +1,71 @@ + + + + Welcome to my Virtual Terrarium + + + + + + + +

My Terrarium

+
+
+
+ plant +
+
+ plant +
+
+ plant +
+
+ plant +
+
+ plant +
+
+ plant +
+
+ plant +
+
+
+
+ plant +
+
+ plant +
+
+ plant +
+
+ plant +
+
+ plant +
+
+ plant +
+
+ plant +
+
+
+
+
+
+
+
+
+
+
+
+ + diff --git a/TERRARIUM/script.js b/TERRARIUM/script.js new file mode 100644 index 0000000..6a83ec6 --- /dev/null +++ b/TERRARIUM/script.js @@ -0,0 +1,78 @@ +dragElement(document.getElementById('plant1')); +dragElement(document.getElementById('plant2')); +dragElement(document.getElementById('plant3')); +dragElement(document.getElementById('plant4')); +dragElement(document.getElementById('plant5')); +dragElement(document.getElementById('plant6')); +dragElement(document.getElementById('plant7')); +dragElement(document.getElementById('plant8')); +dragElement(document.getElementById('plant9')); +dragElement(document.getElementById('plant10')); +dragElement(document.getElementById('plant11')); +dragElement(document.getElementById('plant12')); +dragElement(document.getElementById('plant13')); +dragElement(document.getElementById('plant14')); + +function dragElement(terrariumElement) { + //set 4 positions for positioning on the screen + let pos1 = 0, + pos2 = 0, + pos3 = 0, + pos4 = 0; + terrariumElement.onpointerdown = pointerDrag; + function pointerDrag(e) { + e.preventDefault(); + console.log(e); + pos3 = e.clientX; + pos4 = e.clientY; + document.onpointermove = elementDrag; + document.onpointerup = stopElementDrag; + + } + function elementDrag(e) { + pos1 = pos3 - e.clientX; + pos2 = pos4 - e.clientY; + pos3 = e.clientX; + pos4 = e.clientY; + console.log(pos1, pos2, pos3, pos4); + terrariumElement.style.top = terrariumElement.offsetTop - pos2 + 'px'; + terrariumElement.style.left = terrariumElement.offsetLeft - pos1 + 'px'; + } + function stopElementDrag() { + document.onpointerup = null; + document.onpointermove = null; + } + + terrariumElement.addEventListener("dblclick", doSomething ) + + function doSomething(){ + if(terrariumElement==document.getElementById('plant1')) + alert("plant1"); + if(terrariumElement==document.getElementById('plant2')) + alert("plant2"); + if(terrariumElement==document.getElementById('plant3')) + alert("plant3"); + if(terrariumElement==document.getElementById('plant4')) + alert("plant4"); + if(terrariumElement==document.getElementById('plant5')) + alert("plant5"); + if(terrariumElement==document.getElementById('plant6')) + alert("plant6"); + if(terrariumElement==document.getElementById('plant7')) + alert("plant7"); + if(terrariumElement==document.getElementById('plant8')) + alert("plant8"); + if(terrariumElement==document.getElementById('plant9')) + alert("plant9"); + if(terrariumElement==document.getElementById('plant10')) + alert("plant10"); + if(terrariumElement==document.getElementById('plant11')) + alert("plant11"); + if(terrariumElement==document.getElementById('plant12')) + alert("plant12"); + if(terrariumElement==document.getElementById('plant13')) + alert("plant13"); + if(terrariumElement==document.getElementById('plant14')) + alert("plant14"); + } +} diff --git a/TERRARIUM/style.css b/TERRARIUM/style.css new file mode 100644 index 0000000..fc8cbc5 --- /dev/null +++ b/TERRARIUM/style.css @@ -0,0 +1,109 @@ +body { + font-family: helvetica, arial, sans-serif; +} + +h1 { + color: #3a241d; + text-align: center; +} +#left-container { + background-color: #eee; + width: 15%; + left: 0px; + top: 0px; + position: absolute; + height: 100%; + padding: 10px; +} + +#right-container { + background-color: #eee; + display: flex; + flex-direction: column; + width: 15%; + right: 0px; + top: 0px; + position: absolute; + height: 100%; + padding: 10px; +} + + +.plant-holder { + position: relative; + height: 13%; + left: -10px; +} + +.plant { + display: flex; + justify-content: space-between ; + position: absolute; + max-width: 150%; + max-height: 150%; + z-index: 2; +} +.jar-walls { + display: flex; + -ms-flex-align: center; + height: 80%; + width: 60%; + background: #d1e1df; + border-radius: 1rem; + position: absolute; + bottom: 0.5%; + left: 20%; + opacity: 0.5; + z-index: 1; +} + +.jar-top { + width: 50%; + height: 5%; + background: #d1e1df; + position: absolute; + bottom: 80.5%; + left: 25%; + opacity: 0.7; + z-index: 1; +} + +.jar-bottom { + width: 50%; + height: 1%; + background: #d1e1df; + position: absolute; + bottom: 0%; + left: 25%; + opacity: 0.7; +} + +.dirt { + width: 60%; + height: 5%; + background: #3a241d; + position: absolute; + border-radius: 0 0 1rem 1rem; + bottom: 1%; + left: 20%; + opacity: 0.7; + z-index: -1; +} +.jar-glossy-long{ + width: 4%; + height:25%; + background-color: #e6fcfa; + position: absolute; + border-radius: 1rem 1rem 1rem 1rem; + bottom: 20%; + left : 5% +} +.jar-glossy-short{ + width: 4%; + height:5%; + background-color: #e6fcfa; + position: absolute; + border-radius: 1rem 1rem 1rem 1rem; + bottom: 50%; + left : 5% +} diff --git a/bank-solution/Images/Dashboard.png b/bank-solution/Images/Dashboard.png new file mode 100644 index 0000000..efe98db Binary files /dev/null and b/bank-solution/Images/Dashboard.png differ diff --git a/bank-solution/Images/Login.png b/bank-solution/Images/Login.png new file mode 100644 index 0000000..ce330b5 Binary files /dev/null and b/bank-solution/Images/Login.png differ diff --git a/bank-solution/Images/dailogbox.png b/bank-solution/Images/dailogbox.png new file mode 100644 index 0000000..54781cb Binary files /dev/null and b/bank-solution/Images/dailogbox.png differ diff --git a/bank-solution/Solution.md b/bank-solution/Solution.md new file mode 100644 index 0000000..7b93430 --- /dev/null +++ b/bank-solution/Solution.md @@ -0,0 +1,77 @@ +# 4-bank-project +## 1-template-route +### Assignment +This assignment was to add title for each template and print 'Dashboard is shown' in console when dashboard page is displayed. Did the above task by adding title in routes function as shown below +``` +const routes = { + '/login': { templateId: 'login' , title: 'Login' }, + '/dashboard': { templateId: 'dashboard', init: updateDashboard , init:refresh , title: 'Dashboard'}, + '/credit' : {templateId: 'credit', title:'Credit'}, + }; +``` +and console.log for the printing 'Dashboard is shown'. +``` +if (path =='/dashboard'){ + console.log("Dashboard is shown"); + } +``` +### Challenge +Created a new template and route for the third page of the app that shows the credits. +``` + +``` +And also added the below code in const routes +``` +'/credit' : {templateId: 'credit', title:'Credit'} +``` + +## 2-forms +### Assignment +Done with styling the app both the login page and the dashboard page with giving a unique background colour. + +![Login](https://github.com/Harshith-2208/div-it-up/blob/bank-project/bank-solution/Images/Login.png) + +![Dashboard](https://github.com/Harshith-2208/div-it-up/blob/bank-project/bank-solution/Images/Dashboard.png) + +### Challenge +Did the printing of error message in HTML using div tag with role as alert as shown +``` + +``` +and check if the account already exists using js and print it in red colour. +``` +if (result.error) { + return updateElement('registerError', result.error); + } +``` + +## 3-data +### Assignment +Done with adding comments to the code . +### Challenge +I have added the media queries for the table in styles.css +``` +@media (orientation: portrait) { + #table { + display: block; + width: 250px; + background-color: #fff; + padding: 40px 40px; + } + } +``` + +## 4- state-management +### Assignment +I have added the ADD TRANSACTION dialog box in the dashboard page by adding a dailog in html adding some functions in js and stying it by css. + +![dailogbox](https://github.com/Harshith-2208/div-it-up/blob/bank-project/bank-solution/Images/dailogbox.png) diff --git a/bank-solution/app.js b/bank-solution/app.js new file mode 100644 index 0000000..1087b1c --- /dev/null +++ b/bank-solution/app.js @@ -0,0 +1,227 @@ +// Server API base URL - http://localhost:5000/api + +// Constants +let user=""; + +let state = Object.freeze({ + account: null +}); + +const storageKey = 'savedAccount'; + +const routes = { + '/login': { templateId: 'login' , title: 'Login' }, + '/dashboard': { templateId: 'dashboard', init: updateDashboard , init:refresh , title: 'Dashboard'}, + '/credit' : {templateId: 'credit', title:'Credit'}, + }; + + // Function for updating the route when pressed on a link +function updateRoute(templateId) { + const path = window.location.pathname; + const route = routes[path]; + if (!route) { + console.log("HERE"); + return navigate('/dashboard'); + + } + if (path =='/dashboard'){ + console.log("Dashboard is shown"); + } + document.title=route.title; + const template = document.getElementById(route.templateId); + const view = template.content.cloneNode(true); + const app = document.getElementById('app'); + app.innerHTML = ''; + app.appendChild(view); + if (typeof route.init === 'function') { + route.init(); + } + } + // Function which navigates to the required path + function navigate(path) { + window.history.pushState({}, path, path, path); + updateRoute(); + } + + function onLinkClick(event) { + event.preventDefault(); + navigate(event.target.href); + } + + window.onpopstate = () => updateRoute(); + updateRoute(); + + // Function for defining all the activities of register form + async function register() { + const registerForm = document.getElementById('registerForm'); + const formData = new FormData(registerForm); + const jsonData = JSON.stringify(Object.fromEntries(formData)); + const result = await createAccount(jsonData); + + if (result.error) { + return updateElement('registerError', result.error); + } + console.log('Account created!', result); + + updateState('account', result); + navigate('/dashboard'); + } + //This function will create a new acc. by the inputs given by user + async function createAccount(account) { + try { + const response = await fetch('//localhost:5000/api/accounts', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: account + }); + return await response.json(); + } catch (error) { + return { error: error.message || 'Unknown error' }; + } + } + // Function for defining all the activities of login form + async function login() { + const loginForm = document.getElementById('loginForm') + const user = loginForm.user.value; + const data = await getAccount(user); + + if (data.error) { + return updateElement('loginError', data.error); + } + + updateState('account', data); + navigate('/dashboard'); + } + + // Function used for fetch the data from API + async function getAccount(user) { + try { + const response = await fetch('//localhost:5000/api/accounts/' + encodeURIComponent(user)); + return await response.json(); + } catch (error) { + return { error: error.message || 'Unknown error' }; + } + } + + // This function updates the Dashboard page of the site + function updateDashboard() { + const account = state.account; + if (!account) { + return navigate('/login'); + } + updateElement('description', account.description); + updateElement('balance', account.balance.toFixed(2)); + updateElement('currency', account.currency); + + const transactionsRows = document.createDocumentFragment(); + for (const transaction of account.transactions) { + const transactionRow = createTransactionRow(transaction); + transactionsRows.appendChild(transactionRow); + } + updateElement('transactions', transactionsRows); + } + + // Here in this Function we take the input transation + async function transactIn(){ + const form=document.getElementById('transactionform'); + const data=new FormData(form); + const jsonData = JSON.stringify(Object.fromEntries(data)); + const response = await displayTransaction(jsonData); + const account = state.account; + user = state.account.user; + updateState('account', response); + console.log(user); + updateDashboard(); + } + //This function to display the transaction + async function displayTransaction(data){ + const fetchData= await fetch(` http://localhost:5000/api/accounts/test/transactions`,{ + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: data + }); + } + + // This function creates a transaction row + function createTransactionRow(transaction) { + const template = document.getElementById('transaction'); + const transactionRow = template.content.cloneNode(true); + const tr = transactionRow.querySelector('tr'); + tr.children[0].textContent = transaction.date; + tr.children[1].textContent = transaction.object; + tr.children[2].textContent = transaction.amount.toFixed(2); + return transactionRow; + } + + // Function declaring button + function button(){ + const box = document.getElementById('dialogue'); + document.getElementById('tranbutton').addEventListener("click", () => { + box.removeAttribute("hidden"); + }); + } + + function dailRemove(){ + const box=document.getElementById('dialogue'); + document.getElementById('backward').addEventListener("click", () => { + box.setAttribute("hidden", "hidden"); + }); + } + + // This function updates the value of according to the changes. + function updateElement(id, textOrNode) { + console.log(id, textOrNode) + const element = document.getElementById(id); + element.textContent = ''; // Removes all children + element.append(textOrNode); + } + + function updateState(property, newData) { + state = Object.freeze({ + ...state, + [property]: newData + }); + localStorage.setItem(storageKey, JSON.stringify(state.account)); + } + // This is the initialising function + function init() { + const savedAccount = localStorage.getItem(storageKey); + if (savedAccount) { + updateState('account', JSON.parse(savedAccount)); + } + + // Our previous initialization code + window.onpopstate = () => updateRoute(); + updateRoute(); + } + + // This function to get back to the login page + function logout() { + updateState('account', null); + navigate('/login'); + } + + async function updateAccountData() { + const account = state.account; + if (!account) { + return logout(); + } + + const data = await getAccount(account.user); + if (data.error) { + return logout(); + } + + updateState('account', data); + } + // Whe refreshed the dashboard gets updated. + async function refresh() { + await updateAccountData(); + updateDashboard(); + } + + init(); + + + + diff --git a/bank-solution/index.html b/bank-solution/index.html new file mode 100644 index 0000000..aa270d0 --- /dev/null +++ b/bank-solution/index.html @@ -0,0 +1,113 @@ + + + + + + Bank App + + + + +
Loading...
+
+ + +
+
+ +
+ + + + \ No newline at end of file diff --git a/bank-solution/styles.css b/bank-solution/styles.css new file mode 100644 index 0000000..83dd339 --- /dev/null +++ b/bank-solution/styles.css @@ -0,0 +1,69 @@ +body{ + display: flex; + background-color: lightblue; + justify-content: center; +} + + +h1{ + display: flex; + flex-direction: column; + -ms-flex-align: center; + align-items: center; +} + +.login-content{ + display: flex; + background-color: aliceblue; + flex-direction: column; + align-items: center; + padding-right: 80px; + padding-left: 80px; +} + +.login-container{ + display: flex; + background-color: aliceblue; + flex-direction: column; + align-items: center; + justify-content: center; +} + +.dashboard-cont{ + display: flex; + background-color: aliceblue; + flex-direction: column; + align-items: center; + justify-content: center; + +} +.link{ + display: flex; + flex-direction: column; + align-items: flex-end; + justify-content: space-between; +} + + +@media (orientation: portrait) { + #table { + display: block; + width: 250px; + background-color: #fff; + padding: 40px 40px; + } + } + + .dialogue{ + background-color: #fff; + border-radius: 10px; + width:40%; + min-width: 300px; + + } + .transactionb{ + height:45px; + border-color: black; + background-color: #0076CE; + border-radius: 5px; + } \ No newline at end of file