From 88a0c439b208dfbdd6f5afc30fcdf02aeb5c7dcb Mon Sep 17 00:00:00 2001 From: Koumori97 Date: Tue, 12 Apr 2022 12:00:58 +0200 Subject: [PATCH 01/44] final push --- app.ts | 367 ++++++++++++++++++++++++++++++++++++++++++++++ index.html | 14 +- package-lock.json | 28 ++++ package.json | 26 ++++ style.css | 125 ++++++++++++++++ 5 files changed, 559 insertions(+), 1 deletion(-) create mode 100644 app.ts create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 style.css diff --git a/app.ts b/app.ts new file mode 100644 index 00000000..aef03ab4 --- /dev/null +++ b/app.ts @@ -0,0 +1,367 @@ +let paramOne = 0 +let paramTwo = 9 +let contentNeeded: any = []; +let headings: any = document.querySelector("#Headings"); +let content_cols: any = document.querySelector("#Content"); +let pageStats: any = document.getElementById('pageStats') +let clear = ""; +let prevButton: any = document.querySelector('#prev') +let nextButton: any = document.querySelector('#next') + +// Fetch requests + +//// Heading Row(The Columns) + +function getColumns() { + fetch("http://localhost:2050/columns", { + method: "GET", + headers: { "Content-Type": "application/json" }, +}) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let colList = data; + // console.log(colList); + for (let i = 0; i < colList.length; i++) { + // console.log(colList[i]); + colHeading(colList[i]); + } + }); +} + +//// Table Content + +function getTable() { + fetch("http://localhost:2050/records?from=" + paramOne + "&to=" + paramTwo, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let contentList = data; + for (let i = 0; i < contentList.length; i++) { + contentNeeded.push(contentList[i]) + cols(contentList[i]) + } + }); +} + +// Targets heading div to creating the 1st row(Column names) + +function colHeading(heading: string) { + if (heading == "ID") { + // console.log("heading", ); + let headingCol = `
${heading}
`; + headings.innerHTML += headingCol; + } + else { + let headingCol = `
${heading}
`; + headings.innerHTML += headingCol; + } +} + +// Display the current shown results + +function stats() { + fetch("http://localhost:2050/recordCount", { + method: "GET", + headers: { "Content-Type": "application/json" }, +}) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let count = data; + let currentStats = "Showing results from " + paramOne + " to " + paramTwo + " out of " + count + " results."; + pageStats.innerHTML = currentStats; + }) +} + +// Load all intial fields/data + +window.onload = function() { + stats() + getColumns() + getTable() +} + +// Targets content div to create the actual table and fill with data + +function cols(content: string) { + let content_col = `
+
${content[0]}
+
${content[1]}
+
${content[2]}
+
${content[3]}
+
${content[4]}
+
${content[5]}
+
${content[6]}
+
${content[7]}
+
${content[8]}
+
${content[9]}
+
${content[10]}
+
`; + content_cols.innerHTML += content_col +} + +// Nav Buttons + +//// Next Function + +function next() { + if (paramTwo < 999999) { + disableNext() + paramOne = paramOne + 10 + paramTwo = paramTwo + 10 + stats() + clearTable() + fetch("http://localhost:2050/records?from=" + paramOne + "&to=" + paramTwo, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let contentList = data; + for (let i = 0; i < contentList.length; i++) { + contentNeeded.push(contentList[i]) + cols(contentList[i]) + } + }); + setTimeout(enableNext, 500) + } else { + alert("There are no more records") + } +} + +//// Prev Function + +function prev() { + if (paramOne >= 10) { + disablePrev() + paramOne = paramOne - 10 + paramTwo = paramTwo - 10 + stats() + clearTable() + fetch("http://localhost:2050/records?from=" + paramOne + "&to=" + paramTwo, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let contentList = data; + // console.log(contentList); + for (let i = 0; i < contentList.length; i++) { + // console.log(contentList[i]); + contentNeeded.push(contentList[i]) + cols(contentList[i]) + } + }); + setTimeout(enablePrev, 500) + } else { + alert("No previous records") + } +} + +// To disable button +function disablePrev() { + prevButton.disabled = true; +} +function disableNext() { + nextButton.disabled = true; +} + +// To Enable Buttons +function enablePrev() { + prevButton.disabled = false; +} +function enableNext() { + nextButton.disabled = false; +} + +// Clear Table (content div) + +function clearTable() { + content_cols.innerHTML = clear +} + +// ID Search + +window.addEventListener("keydown", (e) => { + let key = e.key; + // console.log(key); + + if (key === "Enter") { + let search: any = document.querySelector('#idInput'); + // console.log("searched for", search.value); + clearTable() + if (search.value != "" && search.value < 1000000) { + pageStats.innerHTML = clear + let searchStats = "Showing result with ID of " + search.value; + pageStats.innerHTML = searchStats; + fetch("http://localhost:2050/records?from=" + search.value + "&to=" + search.value, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let contentList = data; + // console.log(contentList); + for (let i = 0; i < contentList.length; i++) { + contentNeeded.push(contentList[i]) + cols(contentList[i]) + } + }); + } else { + alert("There are no results with that ID!") + stats() + getTable() + } + search.value = clear + } +}) + +// Jump to ID + +// window.addEventListener("keydown", (e) => { +// let key = e.key; +// if (key === "Alt") { +// let search: any = document.querySelector('#idJump'); +// let searchOne = search.value +// let convert = parseInt(searchOne) + 9 +// let searchTwo = convert.toString() + +// if (searchOne != "" && searchOne <= 999990) { +// clearTable() +// fetch("http://localhost:2050/records?from=" + searchOne + "&to=" + searchTwo, { +// method: "GET", +// headers: { "Content-Type": "application/json" }, +// }) +// .then((res) => res.text()) +// .then((data) => { +// data = JSON.parse(data); +// let contentList = data; +// // console.log(contentList); +// for (let i = 0; i < contentList.length; i++) { +// contentNeeded.push(contentList[i]) +// cols(contentList[i]) +// } +// }); +// fetch("http://localhost:2050/recordCount", { +// method: "GET", +// headers: { "Content-Type": "application/json" }, +// }) +// .then((res) => res.text()) +// .then((data) => { +// data = JSON.parse(data); +// let count = data; +// let currentStats = "Showing results from ID " + searchOne + " to " + searchTwo + " out of " + count + " results."; +// pageStats.innerHTML = currentStats; +// }) +// } else if (searchOne > 999990 && searchOne < 1000000) { +// clearTable() +// fetch("http://localhost:2050/records?from=" + searchOne + "&to=" + 999999, { +// method: "GET", +// headers: { "Content-Type": "application/json" }, +// }) +// .then((res) => res.text()) +// .then((data) => { +// data = JSON.parse(data); +// let contentList = data; +// // console.log(contentList); +// for (let i = 0; i < contentList.length; i++) { +// contentNeeded.push(contentList[i]) +// cols(contentList[i]) +// } +// }); +// fetch("http://localhost:2050/recordCount", { +// method: "GET", +// headers: { "Content-Type": "application/json" }, +// }) +// .then((res) => res.text()) +// .then((data) => { +// data = JSON.parse(data); +// let count = data; +// let currentStats = "Showing results from ID " + searchOne + " to " + 999999 + " out of " + count + " results."; +// pageStats.innerHTML = currentStats; +// }) +// } else { +// alert("There are no records with that ID!") +// clearTable() +// stats() +// getTable() +// } +// search.value = clear +// } +// }) + +function idJump() { + let search: any = document.querySelector('#idJump'); + let searchOne = search.value + let convert = parseInt(searchOne) + 9 + let searchTwo = convert.toString() + + if (searchOne != "" && searchOne <= 999990) { + clearTable() + fetch("http://localhost:2050/records?from=" + searchOne + "&to=" + searchTwo, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let contentList = data; + // console.log(contentList); + for (let i = 0; i < contentList.length; i++) { + contentNeeded.push(contentList[i]) + cols(contentList[i]) + } + }); + fetch("http://localhost:2050/recordCount", { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let count = data; + let currentStats = "Showing results from ID " + searchOne + " to " + searchTwo + " out of " + count + " results."; + pageStats.innerHTML = currentStats; + }) + } else if (searchOne > 999990 && searchOne < 1000000) { + clearTable() + fetch("http://localhost:2050/records?from=" + searchOne + "&to=" + 999999, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let contentList = data; + // console.log(contentList); + for (let i = 0; i < contentList.length; i++) { + contentNeeded.push(contentList[i]) + cols(contentList[i]) + } + }); + fetch("http://localhost:2050/recordCount", { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let count = data; + let currentStats = "Showing results from ID " + searchOne + " to " + 999999 + " out of " + count + " results."; + pageStats.innerHTML = currentStats; + }) + } else { + alert("There are no records with that ID!") + clearTable() + stats() + getTable() + } + search.value = clear +} \ No newline at end of file diff --git a/index.html b/index.html index add5e736..a21875ec 100644 --- a/index.html +++ b/index.html @@ -3,10 +3,22 @@ JS Onboard Project + -

Hello

+ +
+
+ + diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..57a8346d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,28 @@ +{ + "name": "onboard-javascript", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/jquery": { + "version": "3.5.14", + "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.5.14.tgz", + "integrity": "sha512-X1gtMRMbziVQkErhTQmSe2jFwwENA/Zr+PprCkF63vFq+Yt5PZ4AlKqgmeNlwgn7dhsXEK888eIW2520EpC+xg==", + "dev": true, + "requires": { + "@types/sizzle": "*" + } + }, + "@types/sizzle": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.3.tgz", + "integrity": "sha512-JYM8x9EGF163bEyhdJBpR2QX1R5naCJHC8ucJylJ3w9/CVBaskdQ8WqBf8MmQrd1kRvp/a4TS8HJ+bxzR7ZJYQ==", + "dev": true + }, + "typescript": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", + "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..5f167012 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "onboard-javascript", + "version": "1.0.0", + "description": "This is a JavaScript project for all new developers to complete before venturing into our web frontend codebase.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build": "tsc --build" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Koumori97/onboard-javascript.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/Koumori97/onboard-javascript/issues" + }, + "homepage": "https://github.com/Koumori97/onboard-javascript#readme", + "dependencies": { + "typescript": "^4.6.3" + }, + "devDependencies": { + "@types/jquery": "^3.5.14" + } +} diff --git a/style.css b/style.css new file mode 100644 index 00000000..2a7768df --- /dev/null +++ b/style.css @@ -0,0 +1,125 @@ +* { + padding: 0; + margin: 0; + box-sizing: border-box; + overflow-y: hidden; +} + +body { + height: 100vh; + width: 100%; +} + +#Headings { + display: flex; + flex-direction: row; + min-width: 100%; +} + +#col_heading { + border: 1px solid black; + width: 100%; + height: 10vh; + display: grid; + place-items: center; + font-size: 2em; +} + +#col_heading input { + overflow-x: hidden; + width: 90%; + padding: 5px; + font-size: 0.9rem; + text-align: center; +} + +#Content { + display: flex; + flex-direction: column; + min-width: 100%; + height: calc(100vh - 15vh); +} + +#content_col { + display: flex; + width: 100%; + max-height: 20vh; +} + +.info { + border: 1px solid black; + width: 100%; + min-height: 10vh; + display: grid; + place-items: center; +} + +#info_id { + font-size: 2em; +} + +.nav { + height: 5vh; + display: grid; + place-items: center; + background-color: #000; +} + +#pageStats { + color: #fff; + font-size:1.1em; + padding: 5px; + position: absolute; + left: 1%; +} + + +#jumpID { + color: #fff; + font-size: 1.1em; + padding: 5px; + display: flex; + flex-direction: row; + text-align: center; + gap: 20px; +} +#jumpID input { + text-align: center; + padding: 3px; +} +#jumpID button { + padding: 5px; + cursor: pointer; + border-radius: 50px; + border: 1px solid black; + width: 120px; + margin: 0 25px; + font-weight: bold; + text-transform: capitalize; + transition: ease-in 0.3s; +} +#jumpID button:hover { + letter-spacing: 2px; +} + +.btns { + color: #fff; + padding: 5px; + position: absolute; + right: 1%; +} + +.btns button { + padding: 5px; + cursor: pointer; + border-radius: 50px; + border: 1px solid black; + width: 80px; + margin: 0 25px; + font-weight: bold; + text-transform: uppercase; + transition: ease-in 0.3s; +} +.btns button:hover { + letter-spacing: 3px; +} From 69a305f0e460bdb83a3859c0970855cd2ba6ce32 Mon Sep 17 00:00:00 2001 From: Koumori97 Date: Tue, 12 Apr 2022 12:17:57 +0200 Subject: [PATCH 02/44] final push --- app.ts | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/app.ts b/app.ts index aef03ab4..96494c50 100644 --- a/app.ts +++ b/app.ts @@ -130,7 +130,25 @@ function next() { }); setTimeout(enableNext, 500) } else { - alert("There are no more records") + disableNext() + paramOne = 0 + paramTwo = 9 + stats() + clearTable() + fetch("http://localhost:2050/records?from=" + paramOne + "&to=" + paramTwo, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let contentList = data; + for (let i = 0; i < contentList.length; i++) { + contentNeeded.push(contentList[i]) + cols(contentList[i]) + } + }); + setTimeout(enableNext, 500) } } @@ -160,7 +178,27 @@ function prev() { }); setTimeout(enablePrev, 500) } else { - alert("No previous records") + disablePrev() + paramOne = 999990 + paramTwo = 999999 + stats() + clearTable() + fetch("http://localhost:2050/records?from=" + paramOne + "&to=" + paramTwo, { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((res) => res.text()) + .then((data) => { + data = JSON.parse(data); + let contentList = data; + // console.log(contentList); + for (let i = 0; i < contentList.length; i++) { + // console.log(contentList[i]); + contentNeeded.push(contentList[i]) + cols(contentList[i]) + } + }); + setTimeout(enablePrev, 500) } } From 95cabc669c6fe98e3c6912648df6818b86b782af Mon Sep 17 00:00:00 2001 From: Koumori97 Date: Tue, 12 Apr 2022 12:26:11 +0200 Subject: [PATCH 03/44] final push --- app.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app.ts b/app.ts index 96494c50..6ffd9935 100644 --- a/app.ts +++ b/app.ts @@ -21,9 +21,7 @@ function getColumns() { .then((data) => { data = JSON.parse(data); let colList = data; - // console.log(colList); for (let i = 0; i < colList.length; i++) { - // console.log(colList[i]); colHeading(colList[i]); } }); @@ -51,7 +49,6 @@ function getTable() { function colHeading(heading: string) { if (heading == "ID") { - // console.log("heading", ); let headingCol = `
${heading}
`; headings.innerHTML += headingCol; } @@ -169,9 +166,7 @@ function prev() { .then((data) => { data = JSON.parse(data); let contentList = data; - // console.log(contentList); for (let i = 0; i < contentList.length; i++) { - // console.log(contentList[i]); contentNeeded.push(contentList[i]) cols(contentList[i]) } @@ -191,9 +186,7 @@ function prev() { .then((data) => { data = JSON.parse(data); let contentList = data; - // console.log(contentList); for (let i = 0; i < contentList.length; i++) { - // console.log(contentList[i]); contentNeeded.push(contentList[i]) cols(contentList[i]) } @@ -228,11 +221,9 @@ function clearTable() { window.addEventListener("keydown", (e) => { let key = e.key; - // console.log(key); if (key === "Enter") { let search: any = document.querySelector('#idInput'); - // console.log("searched for", search.value); clearTable() if (search.value != "" && search.value < 1000000) { pageStats.innerHTML = clear @@ -246,7 +237,6 @@ window.addEventListener("keydown", (e) => { .then((data) => { data = JSON.parse(data); let contentList = data; - // console.log(contentList); for (let i = 0; i < contentList.length; i++) { contentNeeded.push(contentList[i]) cols(contentList[i]) @@ -351,7 +341,6 @@ function idJump() { .then((data) => { data = JSON.parse(data); let contentList = data; - // console.log(contentList); for (let i = 0; i < contentList.length; i++) { contentNeeded.push(contentList[i]) cols(contentList[i]) @@ -378,7 +367,6 @@ function idJump() { .then((data) => { data = JSON.parse(data); let contentList = data; - // console.log(contentList); for (let i = 0; i < contentList.length; i++) { contentNeeded.push(contentList[i]) cols(contentList[i]) From 5f812147fafb8fe9e7fdcd4ba16e3addc3e86e9e Mon Sep 17 00:00:00 2001 From: Koumori97 Date: Tue, 12 Apr 2022 13:26:14 +0200 Subject: [PATCH 04/44] final push --- app.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app.ts b/app.ts index 6ffd9935..e056829d 100644 --- a/app.ts +++ b/app.ts @@ -1,5 +1,5 @@ -let paramOne = 0 -let paramTwo = 9 +let paramOne: any = 0 +let paramTwo: any = 9 let contentNeeded: any = []; let headings: any = document.querySelector("#Headings"); let content_cols: any = document.querySelector("#Content"); @@ -108,8 +108,12 @@ function cols(content: string) { function next() { if (paramTwo < 999999) { disableNext() - paramOne = paramOne + 10 - paramTwo = paramTwo + 10 + + let intOne = parseInt(paramOne) + 10 + let intTwo = parseInt(paramTwo) + 10 + paramOne = intOne.toString() + paramTwo = intTwo.toString() + stats() clearTable() fetch("http://localhost:2050/records?from=" + paramOne + "&to=" + paramTwo, { @@ -154,8 +158,12 @@ function next() { function prev() { if (paramOne >= 10) { disablePrev() - paramOne = paramOne - 10 - paramTwo = paramTwo - 10 + + let intOne = parseInt(paramOne) - 10 + let intTwo = parseInt(paramTwo) - 10 + paramOne = intOne.toString() + paramTwo = intTwo.toString() + stats() clearTable() fetch("http://localhost:2050/records?from=" + paramOne + "&to=" + paramTwo, { @@ -330,10 +338,12 @@ function idJump() { let searchOne = search.value let convert = parseInt(searchOne) + 9 let searchTwo = convert.toString() + paramOne = searchOne + paramTwo = searchTwo if (searchOne != "" && searchOne <= 999990) { clearTable() - fetch("http://localhost:2050/records?from=" + searchOne + "&to=" + searchTwo, { + fetch("http://localhost:2050/records?from=" + paramOne + "&to=" + paramTwo, { method: "GET", headers: { "Content-Type": "application/json" }, }) @@ -346,17 +356,7 @@ function idJump() { cols(contentList[i]) } }); - fetch("http://localhost:2050/recordCount", { - method: "GET", - headers: { "Content-Type": "application/json" }, - }) - .then((res) => res.text()) - .then((data) => { - data = JSON.parse(data); - let count = data; - let currentStats = "Showing results from ID " + searchOne + " to " + searchTwo + " out of " + count + " results."; - pageStats.innerHTML = currentStats; - }) + stats() } else if (searchOne > 999990 && searchOne < 1000000) { clearTable() fetch("http://localhost:2050/records?from=" + searchOne + "&to=" + 999999, { From 75bff11c8ade4d26be5de3ea3a5fdbd6c209e5cd Mon Sep 17 00:00:00 2001 From: Koumori97 Date: Tue, 12 Apr 2022 13:57:38 +0200 Subject: [PATCH 05/44] final push --- app.ts | 10 ++++++---- index.html | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app.ts b/app.ts index e056829d..d54c5f34 100644 --- a/app.ts +++ b/app.ts @@ -233,7 +233,7 @@ window.addEventListener("keydown", (e) => { if (key === "Enter") { let search: any = document.querySelector('#idInput'); clearTable() - if (search.value != "" && search.value < 1000000) { + if (search.value != "" && search.value < 1000000 && search.value >= 0) { pageStats.innerHTML = clear let searchStats = "Showing result with ID of " + search.value; pageStats.innerHTML = searchStats; @@ -341,7 +341,7 @@ function idJump() { paramOne = searchOne paramTwo = searchTwo - if (searchOne != "" && searchOne <= 999990) { + if (searchOne !== "" && searchOne <= 999990 && searchOne >= 0 && searchOne !== 'e') { clearTable() fetch("http://localhost:2050/records?from=" + paramOne + "&to=" + paramTwo, { method: "GET", @@ -357,7 +357,7 @@ function idJump() { } }); stats() - } else if (searchOne > 999990 && searchOne < 1000000) { + } else if (searchOne > 999990 && searchOne < 1000000 && searchOne >= 0 && searchOne !== 'e') { clearTable() fetch("http://localhost:2050/records?from=" + searchOne + "&to=" + 999999, { method: "GET", @@ -384,8 +384,10 @@ function idJump() { pageStats.innerHTML = currentStats; }) } else { - alert("There are no records with that ID!") + alert("There are no records with that ID! Please check that your input does not exceed 999 999 and is not a negative amount.") clearTable() + paramOne = 0 + paramTwo = 9 stats() getTable() } diff --git a/index.html b/index.html index a21875ec..fef0db91 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@