From 3d767489702522632fbae84a20ba90104651c0af Mon Sep 17 00:00:00 2001 From: AshtonMar Date: Tue, 12 Apr 2022 12:00:40 +0200 Subject: [PATCH 01/30] first commit --- app.ts | 662 +++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 26 +- package.json | 23 ++ server/main.go | 4 +- style.css | 135 ++++++++++ 5 files changed, 838 insertions(+), 12 deletions(-) create mode 100644 app.ts create mode 100644 package.json create mode 100644 style.css diff --git a/app.ts b/app.ts new file mode 100644 index 00000000..f2abb4c1 --- /dev/null +++ b/app.ts @@ -0,0 +1,662 @@ +// Column variables created in html that allows the other content to be added to the page. +let recordNav: any = document.querySelector("#record-navigation"); +let headingColumns: any = document.querySelector("#column-headings"); +let infoColumns: any = document.querySelector("#info-columns"); +// + +function createSelect() { + recordNav.innerHTML = ` + + + `; +} + +// Functions that shows the info when the page loads at first. +// Function that creates the columns that contain the headings of the information. +function columnHeading(heading: string) { + let headingColumn = `
${heading}
`; + headingColumns.innerHTML += headingColumn; +} +// Function that creates the columns and rows +// that contain the information. +function columns(info: string) { + let infoColumns: any = document.querySelector("#info-columns"); + let infoRow = ` +
+
${info[0]}
+
${info[1]}
+
${info[2]}
+
${info[3]}
+
${info[4]}
+
${info[5]}
+
${info[6]}
+
${info[7]}
+
${info[8]}
+
${info[9]}
+
${info[10]}
+
`; + infoColumns.innerHTML += infoRow; +} +// + +// Functions that shows the info when a user search for a single record. +// Function that shows only one heading depending on what is being searched. +function singleColumnHeading(heading: string) { + console.log(heading); + + let headingColumn = ` +
ID
+
${heading}
+ `; + headingColumns.innerHTML = ""; + headingColumns.innerHTML += headingColumn; +} +// Function that creates a single column and/or row +// that contain the information. +function singleColumns(info: string, contentColumn: any, heading: any) { + let contentNumber: any; + let headingArrayNumber: any; + + if (contentColumn === "a") { + contentNumber = 1; + headingArrayNumber = 1; + } else if (contentColumn === "b") { + contentNumber = 2; + headingArrayNumber = 2; + } else if (contentColumn === "c") { + contentNumber = 3; + headingArrayNumber = 3; + } else if (contentColumn === "d") { + contentNumber = 4; + headingArrayNumber = 4; + } else if (contentColumn === "e") { + contentNumber = 5; + headingArrayNumber = 5; + } else if (contentColumn === "f") { + contentNumber = 6; + headingArrayNumber = 6; + } else if (contentColumn === "g") { + contentNumber = 7; + headingArrayNumber = 7; + } else if (contentColumn === "h") { + contentNumber = 8; + headingArrayNumber = 8; + } else if (contentColumn === "i") { + contentNumber = 9; + headingArrayNumber = 9; + } else if (contentColumn === "j") { + contentNumber = 10; + headingArrayNumber = 10; + } else { + alert("Sorry the data you have entered is incorrect. Please try again."); + } + + let columnHead = heading[headingArrayNumber]; + singleColumnHeading(columnHead); + + let infoRow = ` +
+
${info[0]}
+
${info[contentNumber]}
+
`; + infoColumns.innerHTML += infoRow; +} +// + +// Fetch request that gets the headings as well as the information and then runs +// the functions that create the rows and columns as well as add the info to them. +// Fetching headings +function fetchData() { + fetch("http://localhost:2050/columns", { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((response) => response.text()) + .then((data) => { + let headingDataList = JSON.parse(data); + + for (let i = 0; i < headingDataList.length; i++) { + columnHeading(headingDataList[i]); + } + + // Fetching information + fetch("http://localhost:2050/records?from=0&to=16", { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + + for (let i = 0; i < columnDataList.length; i++) { + columns(columnDataList[i]); + } + }); + }); + createSelect(); +} + +fetchData(); +// + +function multipleSingularColumns( + info: string, + columnPostion: string, + idPostion: string +) { + let infoColumns: any = document.querySelector("#info-columns"); + let infoRows = ` +
+
${info[0]}
+
${info[1]}
+
${info[2]}
+
${info[3]}
+
${info[4]}
+
${info[5]}
+
${info[6]}
+
${info[7]}
+
${info[8]}
+
${info[9]}
+
${info[10]}
+
`; + + infoColumns.innerHTML += infoRows; + + if (columnPostion === "a" && info[0] === idPostion) { + let infoColumnTargeted: any = document.querySelector("#one.info-column"); + console.log(infoColumnTargeted); + infoColumnTargeted.style.color = "red"; + } else if (columnPostion === "b" && info[0] === idPostion) { + let infoColumnTargeted: any = document.querySelector("#two.info-column"); + infoColumnTargeted.style.color = "red"; + } else if (columnPostion === "c" && info[0] === idPostion) { + let infoColumnTargeted: any = document.querySelector("#three.info-column"); + infoColumnTargeted.style.color = "red"; + } else if (columnPostion === "d" && info[0] === idPostion) { + let infoColumnTargeted: any = document.querySelector("#four.info-column"); + infoColumnTargeted.style.color = "red"; + } else if (columnPostion === "e" && info[0] === idPostion) { + let infoColumnTargeted: any = document.querySelector("#five.info-column"); + infoColumnTargeted.style.color = "red"; + } else if (columnPostion === "f" && info[0] === idPostion) { + let infoColumnTargeted: any = document.querySelector("#six.info-column"); + infoColumnTargeted.style.color = "red"; + } else if (columnPostion === "g" && info[0] === idPostion) { + let infoColumnTargeted: any = document.querySelector("#seven.info-column"); + infoColumnTargeted.style.color = "red"; + } else if (columnPostion === "h" && info[0] === idPostion) { + let infoColumnTargeted: any = document.querySelector("#eight.info-column"); + infoColumnTargeted.style.color = "red"; + } else if (columnPostion === "i" && info[0] === idPostion) { + let infoColumnTargeted: any = document.querySelector("#nine.info-column"); + infoColumnTargeted.style.color = "red"; + } else if (columnPostion === "j" && info[0] === idPostion) { + let infoColumnTargeted: any = document.querySelector("#ten.info-column"); + infoColumnTargeted.style.color = "red"; + } else { + alert("Error"); + } +} +// Function that allows the user to filter between looking fo a specific record or multiple records +function recordSelection() { + // let confirmationBtn: any = document.querySelector("#select-confirmation-btn") runs the function in the html (onclick); + let selectionArea: any = document.querySelector("#record-navigation"); + let recordSelector: any = document.querySelector("#record-selection"); + let recordSelectionValue: string = recordSelector.value; + let records: any = []; + + if ( + recordSelectionValue === "single" || + recordSelectionValue === "multiple" || + recordSelectionValue === "multiple-single" + ) { + if (recordSelectionValue === "single") { + let singleRecordSelection = ` + +
+ + +
+ + `; + selectionArea.innerHTML = ""; + selectionArea.innerHTML = singleRecordSelection; + let returnBtn: any = document.querySelector( + "#single-return-btn.return-btn" + ); + returnBtn.addEventListener("click", () => { + headingColumns.innerHTML = ""; + infoColumns.innerHTML = ""; + fetchData(); + createSelect(); + }); + let singleSubmitBtn: any = document.querySelector( + "#single-submit-btn.submit-btn" + ); + + singleSubmitBtn.addEventListener("click", () => { + let recordId: any = document.querySelector("#record-id"); + let recordIdValue = recordId.value; + + let recordContent: any = document.querySelector("#record-content"); + let recordContentValue = recordContent.value; + + if ( + (recordIdValue !== null && + recordContentValue === null && + recordIdValue !== "" && + recordContentValue === "") || + recordContentValue === "none" + ) { + fetch("http://localhost:2050/columns", { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((response) => response.text()) + .then((data) => { + let headingDataList = JSON.parse(data); + headingColumns.innerHTML = ""; + + for (let i = 0; i < headingDataList.length; i++) { + columnHeading(headingDataList[i]); + } + // Fetching information + fetch( + "http://localhost:2050/records?from=" + + recordIdValue + + "&to=" + + recordIdValue, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + } + ) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + + for (let i = 0; i < columnDataList.length; i++) { + let infoColumns: any = + document.querySelector("#info-columns"); + infoColumns.innerHTML = ""; + columns(columnDataList[i]); + } + }); + }); + } else if ( + recordIdValue !== null || + (recordContentValue !== null && recordIdValue !== "") || + recordContentValue !== "" || + recordContentValue !== "none" + ) { + // Fetching headings + let headingsList: any = []; + fetch("http://localhost:2050/columns", { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((response) => response.text()) + .then((data) => { + let headingDataList = JSON.parse(data); + + for (let i = 0; i < headingDataList.length; i++) { + headingsList.push(headingDataList[i]); + } + // Fetching information + fetch( + "http://localhost:2050/records?from=" + + recordIdValue + + "&to=" + + recordIdValue, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + } + ) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + + for (let i = 0; i < columnDataList.length; i++) { + let infoColumns: any = + document.querySelector("#info-columns"); + infoColumns.innerHTML = ""; + console.log(headingsList); + + singleColumns( + columnDataList[i], + recordContentValue, + headingsList + ); + } + }); + }); + } else { + alert("Sorry there has been a problem. Can you please try again."); + let confirmation = confirm("Try again?"); + if (confirmation === true) { + recordIdValue.value = ""; + recordContentValue.value = ""; + } else { + window.location.reload(); + } + } + }); + } else if (recordSelectionValue === "multiple") { + let multipleRecordSelection = ` + +
+ +
+ + `; + selectionArea.innerHTML = ""; + selectionArea.innerHTML = multipleRecordSelection; + + let returnBtn: any = document.querySelector( + "#multiple-return-btn.return-btn" + ); + returnBtn.addEventListener("click", () => { + records = []; + headingColumns.innerHTML = ""; + infoColumns.innerHTML = ""; + fetchData(); + createSelect(); + createSelect(); + }); + let multipleSubmitBtn: any = document.querySelector( + "#multiple-submit-btn.submit-btn" + ); + multipleSubmitBtn.addEventListener("click", () => { + let fromIdSelection: any = document.querySelector( + "#from-record-id.navigation-input" + ); + let toIdSelection: any = document.querySelector( + "#to-record-id.navigation-input" + ); + + let fromIdValue = fromIdSelection.value; + let toIdValue = toIdSelection.value; + + if ( + (fromIdValue !== null && toIdValue !== null) || + (fromIdValue !== "" && toIdValue !== "") + ) { + const totalRecordsAllowed = 16; + let recordCount: number = Number(toIdValue) - Number(fromIdValue) + 1; + if ( + recordCount > totalRecordsAllowed || + typeof recordCount !== "number" + ) { + let excessRecords = recordCount - totalRecordsAllowed; + toIdValue = toIdValue - excessRecords; + alert( + "The data you entered is incorrect or you trying to access to much records only " + + totalRecordsAllowed + + " records can be accessed at a time. You have " + + excessRecords + + " excess records" + ); + // Fetching information + fetch( + "http://localhost:2050/records?from=" + + fromIdValue + + "&to=" + + toIdValue, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + } + ) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + + infoColumns.innerHTML = ""; + for (let i = 0; i < columnDataList.length; i++) { + columns(columnDataList[i]); + } + }); + } else if (recordCount <= 16 || typeof recordCount === "number") { + // Fetching information + fetch( + "http://localhost:2050/records?from=" + + fromIdValue + + "&to=" + + toIdValue, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + } + ) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + + infoColumns.innerHTML = ""; + for (let i = 0; i < columnDataList.length; i++) { + columns(columnDataList[i]); + } + }); + } + } else { + alert( + "Sorry there has been a problem. Please check your inputs make sure you have both filled." + ); + } + }); + } else if (recordSelectionValue === "multiple-single") { + let multipleSingleRecordSelection = ` + +
+ +
+ + `; + selectionArea.innerHTML = ""; + selectionArea.innerHTML = multipleSingleRecordSelection; + let returnBtn: any = document.querySelector( + "#multiple-single-return-btn.return-btn" + ); + returnBtn.addEventListener("click", () => { + alert("Records you have viewed " + records); + headingColumns.innerHTML = ""; + infoColumns.innerHTML = ""; + fetchData(); + createSelect(); + createSelect(); + }); + let addMulitpleSingularRecords: any = document.querySelector( + "#add-records-btn.add-btn" + ); + + addMulitpleSingularRecords.addEventListener("click", () => { + // Inputs and selects + let IdSelection: any = document.querySelector( + "#record-id.navigation-input" + ); + + let letterValueSelection: any = + document.querySelector("#record-content"); + + //Values Needed + let IdValue = IdSelection.value; + let letterValue = letterValueSelection.value; + let numberCheck: number = 12 - Number(IdValue); + const recordAmount: number = 16; + let amountOfRecords = records.length; + console.log(amountOfRecords); + + if (amountOfRecords > recordAmount) { + alert("That is the total amount of records that can be added"); + } else if (amountOfRecords === 0) { + infoColumns.innerHTML = ""; + } else { + //pass + } + + if ( + typeof numberCheck === "number" && + typeof letterValue === "string" + ) { + let record = { + Id: IdValue, + letterId: letterValue, + }; + let arrayRecord = JSON.stringify(record); + let isInArray = records.includes(arrayRecord); + console.log(isInArray); + + if (isInArray === false) { + // Fetching information + fetch( + "http://localhost:2050/records?from=" + + IdValue + + "&to=" + + IdValue, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + } + ) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + + infoColumns.innerHTML += ""; + for (let i = 0; i < columnDataList.length; i++) { + multipleSingularColumns( + columnDataList[i], + letterValue, + IdValue + ); + } + }); + records.push(arrayRecord); + console.log(records); + + for (let i = 0; i < records.length; i++) { + JSON.parse(records[i]); + console.log(records[i]); + } + } else { + alert("The record was already added"); + console.log(records); + } + } else { + alert("Enter apropriate inputs please"); + } + }); + records = records; + } else { + alert( + "Sorry there has been a problem. The page will reload can you please try again." + ); + window.location.reload(); + } + } else { + alert( + "Sorry there has been a problem. The page will reload can you please try again." + ); + window.location.reload(); + } +} +// diff --git a/index.html b/index.html index add5e736..7b16eea4 100644 --- a/index.html +++ b/index.html @@ -1,13 +1,19 @@ - - JS Onboard Project - - - - -

Hello

- - + + JS Onboard Project + + + + +
+
+
+ + + - diff --git a/package.json b/package.json new file mode 100644 index 00000000..99313e35 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "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/AshtonMar/onboard-javascript.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/AshtonMar/onboard-javascript/issues" + }, + "homepage": "https://github.com/AshtonMar/onboard-javascript#readme", + "dependencies": { + "@types/jquery": "^3.5.14" + } +} diff --git a/server/main.go b/server/main.go index eba62f8c..de0930b4 100644 --- a/server/main.go +++ b/server/main.go @@ -13,11 +13,11 @@ import ( "time" ) +var columns = [11]string{"ID", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"} const recordCount = 1000000 -const columnCount = 11 +const columnCount = len(columns); const delayResponse = 500 * time.Millisecond -var columns = [columnCount]string{"ID", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"} var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") func main() { diff --git a/style.css b/style.css new file mode 100644 index 00000000..9d94a604 --- /dev/null +++ b/style.css @@ -0,0 +1,135 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; + font-family: sans-serif; + overflow-y: hidden; + overflow-x: hidden; +} + +/*Removing Browser scrollbar*/ +::-webkit-scrollbar { + display: none; +} +/* */ + +select, +button, +input { + text-align: center; + width: 250px; + height: 50px; + font-size: 18px; + border: 2px solid black; + border-radius: 5px; + background-color: transparent; + transition: all 0.5s; + transition-timing-function: ease-in-out; +} + +select:hover, +button:hover, +input:hover { + transform: scale(1.1); + color: white; + border-color: white; + background-color: black; +} + +/* Selection tabs */ +#record-navigation { + display: flex; + align-items: center; + justify-content: space-evenly; + flex-direction: row; + padding: 10px; + height: 10vh; +} + +#user-input-data { + display: flex; + align-items: center; + justify-content: space-between; + flex-direction: row; + height: 100%; +} + +.navigation-input-area { + display: flex; + align-items: center; + flex-direction: row; + padding: 10px; +} + +#from-id, +#to-id, +.navigation-input-area-id { + display: flex; + align-items: center; + flex-direction: row; + margin-left: 20px; + height: 100%; +} + +.record-labels { + padding: 5px 10px 0px 0px; +} + +.navigation-input { + padding: 5px; +} +/* */ + +/*Styling for the column headings*/ +#column-headings { + display: flex; + justify-content: space-between; + align-items: center; + flex-direction: row; + height: 10vh; + width: 100%; + border-block: 2px solid black; + font-size: 30px; +} + +.column-heading { + display: flex; + justify-content: center; + align-items: center; + border-left: 1px solid black; + border-right: 1px solid black; + width: 100%; + height: 100%; +} +/* */ + +/*Styling for the columns*/ +#info-columns { + display: flex; + flex-wrap: wrap; + width: 100%; + height: calc(100vh -15vh); +} + +.info-row { + display: flex; + justify-content: center; + align-items: center; + height: 5vh; + width: 100%; + border-bottom: 2px solid black; + font-size: 20px; + transition: all 0.5s; + transition-timing-function: ease-in-out; +} + +.info-column { + display: flex; + justify-content: center; + align-items: center; + border-left: 1px solid black; + border-right: 1px solid black; + width: 100%; + height: 100%; +} +/* */ From fc17d7670f11bd049d808e58efe03f5989915d18 Mon Sep 17 00:00:00 2001 From: AshtonMar Date: Tue, 12 Apr 2022 14:08:15 +0200 Subject: [PATCH 02/30] multiple-singular-select-functionality --- app.ts | 200 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 114 insertions(+), 86 deletions(-) diff --git a/app.ts b/app.ts index f2abb4c1..9d12d828 100644 --- a/app.ts +++ b/app.ts @@ -4,6 +4,43 @@ let headingColumns: any = document.querySelector("#column-headings"); let infoColumns: any = document.querySelector("#info-columns"); // +// Fetch request that gets the headings as well as the information and then runs +// the functions that create the rows and columns as well as add the info to them. +function fetchData() { + // Fetches the heading data + fetch("http://localhost:2050/columns", { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((response) => response.text()) + .then((data) => { + let headingDataList = JSON.parse(data); + + for (let i = 0; i < headingDataList.length; i++) { + columnHeading(headingDataList[i]); + } + + // Fetching information + fetch("http://localhost:2050/records?from=0&to=16", { + method: "GET", + headers: { "Content-Type": "application/json" }, + }) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + + for (let i = 0; i < columnDataList.length; i++) { + columns(columnDataList[i]); + } + }); + }); + createSelect(); +} +fetchData(); +// + +// Functions that shows the info when the page loads at first. +// Function that creates the select that appears on the page as itloads. function createSelect() { recordNav.innerHTML = ` + + + + + + `; +} + +function createGrid(headingList: any, rowList: string) { + let amountOfHeadingColumns: number = headingList.length; + let amountOfDataColumns: number = rowList.length; + // console.log(rowList[0], amountOfDataColumns); + + for (let i = 0; i < amountOfHeadingColumns; i++) { + let headingColumn: any = `

${headingList[i]}

`; + headingColumns.innerHTML += headingColumn; + } + + for (let i = 0, x = 0; i < 15 && x < amountOfDataColumns; i++ && x++) { + console.log(rowList[i]); + console.log(rowList[i][x]); + let id = rowList[i]; + + console.log(rowList); + + // let infoRow: any = ` + //
+ // ${rowList[i][x]} + //
`; + // infoColumns.innerHTML += infoRow; + break; + } +} -// Fetch request that gets the headings as well as the information and then runs -// the functions that create the rows and columns as well as add the info to them. function fetchData() { - // Fetches the heading data + // Gets headings array fetch("http://localhost:2050/columns", { method: "GET", headers: { "Content-Type": "application/json" }, @@ -16,10 +62,6 @@ function fetchData() { .then((data) => { let headingDataList = JSON.parse(data); - for (let i = 0; i < headingDataList.length; i++) { - columnHeading(headingDataList[i]); - } - // Fetching information fetch("http://localhost:2050/records?from=0&to=16", { method: "GET", @@ -28,693 +70,454 @@ function fetchData() { .then((response) => response.text()) .then((data) => { let columnDataList = JSON.parse(data); - - for (let i = 0; i < columnDataList.length; i++) { - columns(columnDataList[i]); - } + createGrid(headingDataList, columnDataList); }); }); - createSelect(); + createNavigation(); } + fetchData(); -// -// Functions that shows the info when the page loads at first. -// Function that creates the select that appears on the page as itloads. -function createSelect() { - recordNav.innerHTML = ` - - - `; -} -// Function that creates the columns that contain the headings of the information. -function columnHeading(heading: string) { - let headingColumn = `
${heading}
`; - headingColumns.innerHTML += headingColumn; -} -// Function that creates the columns and rows that contain the information. -function columns(info: string) { - let infoColumns: any = document.querySelector("#info-columns"); - let infoRow = ` -
-
${info[0]}
-
${info[1]}
-
${info[2]}
-
${info[3]}
-
${info[4]}
-
${info[5]}
-
${info[6]}
-
${info[7]}
-
${info[8]}
-
${info[9]}
-
${info[10]}
-
`; - infoColumns.innerHTML += infoRow; -} -// +function nextPrevious(firstId: any, finalId: any) { + let nextBtn: any = document.querySelector(".next-records-btn"); + let previousBtn: any = document.querySelector(".previous-records-btn"); + let currentPage: any = document.querySelector(".current-page"); -// Functions that shows the info when a user search for a single record. -// Function that shows only one heading depending on what is being searched. -function singleColumnHeading(heading: string) { - let headingColumn = ` -
ID
-
${heading}
- `; - headingColumns.innerHTML = ""; - headingColumns.innerHTML += headingColumn; -} -// Function that creates a single column and/or row -// that contain the information. -function singleColumns(info: string, contentColumn: any, heading: any) { - let contentNumber: any; - let headingArrayNumber: any; - - if (contentColumn === "a") { - contentNumber = 1; - headingArrayNumber = 1; - } else if (contentColumn === "b") { - contentNumber = 2; - headingArrayNumber = 2; - } else if (contentColumn === "c") { - contentNumber = 3; - headingArrayNumber = 3; - } else if (contentColumn === "d") { - contentNumber = 4; - headingArrayNumber = 4; - } else if (contentColumn === "e") { - contentNumber = 5; - headingArrayNumber = 5; - } else if (contentColumn === "f") { - contentNumber = 6; - headingArrayNumber = 6; - } else if (contentColumn === "g") { - contentNumber = 7; - headingArrayNumber = 7; - } else if (contentColumn === "h") { - contentNumber = 8; - headingArrayNumber = 8; - } else if (contentColumn === "i") { - contentNumber = 9; - headingArrayNumber = 9; - } else if (contentColumn === "j") { - contentNumber = 10; - headingArrayNumber = 10; + let numberOne: number = firstId; + let numberTwo: number = finalId; + + currentPage.innerHTML = numberOne + " -> " + numberTwo; + + if (numberOne === 0 && numberTwo === 15) { + previousBtn.style.display = "none"; } else { - alert("Sorry the data you have entered is incorrect. Please try again."); + //pass } - let columnHead = heading[headingArrayNumber]; - singleColumnHeading(columnHead); + nextBtn.addEventListener("click", () => { + console.log("next"); + const amountRecords: number = 16; + let nextNumberOne: number = numberOne + amountRecords; + let nextNumberTwo: number = numberTwo + amountRecords; + + if (nextNumberOne === 32 && nextNumberTwo === 47) { + nextBtn.style.display = "none"; + currentPage.innerHTML = ""; + currentPage.innerHTML = + nextNumberOne + " -> " + nextNumberTwo + " Final Page"; + numberOne = nextNumberOne; + numberTwo = nextNumberTwo; + } else { + currentPage.innerHTML = ""; + currentPage.innerHTML = nextNumberOne + " -> " + nextNumberTwo; + numberOne = nextNumberOne; + numberTwo = nextNumberTwo; + } + }); - let infoRow = ` -
-
${info[0]}
-
${info[contentNumber]}
-
`; - infoColumns.innerHTML += infoRow; -} -// + previousBtn.addEventListener("click", () => { + console.log("previous"); -// Function that creates the rows and highlights the data you are searching -// for in the multiple single records. -function multipleSingularColumns( - info: string, - columnPostion: string, - idOfData: string -) { - let infoColumns: any = document.querySelector("#info-columns"); - let infoRows = ` -
-
${info[0]}
-
${info[1]}
-
${info[2]}
-
${info[3]}
-
${info[4]}
-
${info[5]}
-
${info[6]}
-
${info[7]}
-
${info[8]}
-
${info[9]}
-
${info[10]}
-
`; - - if (columnPostion === "a") { - infoColumns.innerHTML += infoRows; - let infoColumnTargeted: any = document.querySelector( - "#one.certain-column" + idOfData - ); - infoColumnTargeted.style.color = "red"; - } else if (columnPostion === "b") { - infoColumns.innerHTML += infoRows; - let infoColumnTargeted: any = document.querySelector( - "#two.certain-column" + idOfData - ); - infoColumnTargeted.style.color = "red"; - } else if (columnPostion === "c") { - infoColumns.innerHTML += infoRows; - let infoColumnTargeted: any = document.querySelector( - "#three.certain-column" + idOfData - ); - infoColumnTargeted.style.color = "red"; - } else if (columnPostion === "d") { - infoColumns.innerHTML += infoRows; - let infoColumnTargeted: any = document.querySelector( - "#four.certain-column" + idOfData - ); - infoColumnTargeted.style.color = "red"; - } else if (columnPostion === "e") { - infoColumns.innerHTML += infoRows; - let infoColumnTargeted: any = document.querySelector( - "#five.certain-column" + idOfData - ); - infoColumnTargeted.style.color = "red"; - } else if (columnPostion === "f") { - infoColumns.innerHTML += infoRows; - let infoColumnTargeted: any = document.querySelector( - "#six.certain-column" + idOfData - ); - infoColumnTargeted.style.color = "red"; - } else if (columnPostion === "g") { - infoColumns.innerHTML += infoRows; - let infoColumnTargeted: any = document.querySelector( - "#seven.certain-column" + idOfData - ); - infoColumnTargeted.style.color = "red"; - } else if (columnPostion === "h") { - infoColumns.innerHTML += infoRows; - let infoColumnTargeted: any = document.querySelector( - "#eight.certain-column" + idOfData - ); - infoColumnTargeted.style.color = "red"; - } else if (columnPostion === "i") { - infoColumns.innerHTML += infoRows; - let infoColumnTargeted: any = document.querySelector( - "#nine.certain-column" + idOfData - ); - infoColumnTargeted.style.color = "red"; - } else if (columnPostion === "j") { - infoColumns.innerHTML += infoRows; - let infoColumnTargeted: any = document.querySelector( - "#ten.certain-column" + idOfData - ); - infoColumnTargeted.style.color = "red"; - } else { - alert("Error"); - } -} -// + const amountRecords: number = 15; + let nextNumberOne: number = numberOne - amountRecords; + let nextNumberTwo: number = numberTwo - amountRecords; -// Function that allows the user to filter between looking fo a singular record, multiple records or multiple singular records. -function recordSelection() { - // let confirmationBtn: any = document.querySelector("#select-confirmation-btn") runs the function in the html (onclick); - // Accesses the area on the page where the select is shown. - let selectionArea: any = recordNav; - // Checks how you want filter records. - let recordSelector: any = document.querySelector("#record-selection"); - let recordSelectionValue: string = recordSelector.value; - // - let records: any = []; - - // Checks if the select gives a proper value. - if ( - recordSelectionValue === "single" || - recordSelectionValue === "multiple" || - recordSelectionValue === "multiple-single" - ) { - if (recordSelectionValue === "single") { - // Creates a div that includes all the inputs, selects and buttons needed to filter. - let singleRecordSelection = ` - -
- - -
- - `; - selectionArea.innerHTML = ""; - selectionArea.innerHTML = singleRecordSelection; - - let returnBtn: any = document.querySelector( - "#single-return-btn.return-btn" - ); - returnBtn.addEventListener("click", () => { - headingColumns.innerHTML = ""; - infoColumns.innerHTML = ""; - fetchData(); - createSelect(); - }); - - let singleSubmitBtn: any = document.querySelector( - "#single-submit-btn.submit-btn" - ); - singleSubmitBtn.addEventListener("click", () => { - let recordId: any = document.querySelector("#record-id"); - let recordIdValue = recordId.value; - console.log(recordIdValue.length); - - let recordContent: any = document.querySelector("#record-content"); - let recordContentValue = recordContent.value; - - if (recordIdValue.length === 0) { - alert( - "You left one of the record id inputs empty or you have entered an incorrect character." - ); - } else { - if ( - (recordIdValue !== null && - recordContentValue === null && - recordIdValue !== "" && - recordContentValue === "") || - recordContentValue === "none" - ) { - fetch("http://localhost:2050/columns", { - method: "GET", - headers: { "Content-Type": "application/json" }, - }) - .then((response) => response.text()) - .then((data) => { - let headingDataList = JSON.parse(data); - headingColumns.innerHTML = ""; - - for (let i = 0; i < headingDataList.length; i++) { - columnHeading(headingDataList[i]); - } - // Fetching information - fetch( - "http://localhost:2050/records?from=" + - recordIdValue + - "&to=" + - recordIdValue, - { - method: "GET", - headers: { "Content-Type": "application/json" }, - } - ) - .then((response) => response.text()) - .then((data) => { - let columnDataList = JSON.parse(data); - - for (let i = 0; i < columnDataList.length; i++) { - let infoColumns: any = - document.querySelector("#info-columns"); - infoColumns.innerHTML = ""; - columns(columnDataList[i]); - } - }); - }); - } else if ( - recordIdValue !== null || - (recordContentValue !== null && recordIdValue !== "") || - recordContentValue !== "" || - recordContentValue !== "none" - ) { - // Fetching headings - let headingsList: any = []; - fetch("http://localhost:2050/columns", { - method: "GET", - headers: { "Content-Type": "application/json" }, - }) - .then((response) => response.text()) - .then((data) => { - let headingDataList = JSON.parse(data); - - for (let i = 0; i < headingDataList.length; i++) { - headingsList.push(headingDataList[i]); - } - // Fetching information - fetch( - "http://localhost:2050/records?from=" + - recordIdValue + - "&to=" + - recordIdValue, - { - method: "GET", - headers: { "Content-Type": "application/json" }, - } - ) - .then((response) => response.text()) - .then((data) => { - let columnDataList = JSON.parse(data); - - for (let i = 0; i < columnDataList.length; i++) { - let infoColumns: any = - document.querySelector("#info-columns"); - - infoColumns.innerHTML = ""; - - singleColumns( - columnDataList[i], - recordContentValue, - headingsList - ); - } - }); - }); - } else if ( - recordIdValue === "0" || - (recordIdValue === null && recordContentValue === "") || - recordContentValue === "none" - ) { - alert("hello"); - } else { - alert("Sorry there has been a problem. Can you please try again."); - let confirmation = confirm("Try again?"); - if (confirmation === true) { - recordIdValue.value = "0"; - recordContentValue.value = ""; - } else { - window.location.reload(); - } - } - } - }); - } else if (recordSelectionValue === "multiple") { - let multipleRecordSelection = ` - -
- -
- - `; - selectionArea.innerHTML = ""; - selectionArea.innerHTML = multipleRecordSelection; - - let returnBtn: any = document.querySelector( - "#multiple-return-btn.return-btn" - ); - returnBtn.addEventListener("click", () => { - records = []; - headingColumns.innerHTML = ""; - infoColumns.innerHTML = ""; - fetchData(); - createSelect(); - createSelect(); - }); - let multipleSubmitBtn: any = document.querySelector( - "#multiple-submit-btn.submit-btn" - ); - multipleSubmitBtn.addEventListener("click", () => { - let fromIdSelection: any = document.querySelector( - "#from-record-id.navigation-input" - ); - let toIdSelection: any = document.querySelector( - "#to-record-id.navigation-input" - ); - - let fromIdValue = fromIdSelection.value; - let toIdValue = toIdSelection.value; - - if (fromIdValue.length === 0 || toIdValue === 0) { - alert( - "You left one of the record id inputs empty or you have entered an incorrect character." - ); - } else { - if ( - (fromIdValue !== null && toIdValue !== null) || - (fromIdValue !== "" && toIdValue !== "") - ) { - const totalRecordsAllowed = 16; - let recordCount: number = - Number(toIdValue) - Number(fromIdValue) + 1; - if ( - recordCount > totalRecordsAllowed || - typeof recordCount !== "number" - ) { - let excessRecords = recordCount - totalRecordsAllowed; - toIdValue = toIdValue - excessRecords; - alert( - "The data you entered is incorrect or you trying to access to much records only " + - totalRecordsAllowed + - " records can be accessed at a time. You have " + - excessRecords + - " excess records" - ); - // Fetching information - fetch( - "http://localhost:2050/records?from=" + - fromIdValue + - "&to=" + - toIdValue, - { - method: "GET", - headers: { "Content-Type": "application/json" }, - } - ) - .then((response) => response.text()) - .then((data) => { - let columnDataList = JSON.parse(data); - - infoColumns.innerHTML = ""; - for (let i = 0; i < columnDataList.length; i++) { - columns(columnDataList[i]); - } - }); - } else if (recordCount <= 16 || typeof recordCount === "number") { - // Fetching information - fetch( - "http://localhost:2050/records?from=" + - fromIdValue + - "&to=" + - toIdValue, - { - method: "GET", - headers: { "Content-Type": "application/json" }, - } - ) - .then((response) => response.text()) - .then((data) => { - let columnDataList = JSON.parse(data); - - infoColumns.innerHTML = ""; - for (let i = 0; i < columnDataList.length; i++) { - columns(columnDataList[i]); - } - }); - } - } else { - alert( - "Sorry there has been a problem. Please check your inputs make sure you have both filled." - ); - } - } - }); - } else if (recordSelectionValue === "multiple-single") { - let multipleSingleRecordSelection = ` - -
- -
- - `; - selectionArea.innerHTML = ""; - selectionArea.innerHTML = multipleSingleRecordSelection; - let returnBtn: any = document.querySelector( - "#multiple-single-return-btn.return-btn" - ); - returnBtn.addEventListener("click", () => { - alert("Records you have viewed " + records); - headingColumns.innerHTML = ""; - infoColumns.innerHTML = ""; - fetchData(); - createSelect(); - createSelect(); - }); - let addMulitpleSingularRecords: any = document.querySelector( - "#add-records-btn.add-btn" - ); - - addMulitpleSingularRecords.addEventListener("click", () => { - // Inputs and selects - let IdSelection: any = document.querySelector( - "#record-id.navigation-input" - ); - - let letterValueSelection: any = - document.querySelector("#record-content"); - - //Values Needed - let IdValue = IdSelection.value; - let letterValue = letterValueSelection.value; - let numberCheck: number = 12 - Number(IdValue); - const recordAmount: number = 16; - let amountOfRecords = records.length; - - if (amountOfRecords > recordAmount) { - alert("That is the total amount of records that can be added"); - } else if (amountOfRecords === 0) { - infoColumns.innerHTML = ""; - } else { - //pass - } - - if (IdValue.length === 0 || letterValue === "none") { - alert( - "You left one of the record id inputs empty or you have entered an incorrect character." - ); - } else { - if ( - typeof numberCheck === "number" && - typeof letterValue === "string" - ) { - let record = { - Id: IdValue, - letterId: letterValue, - }; - let arrayRecord = JSON.stringify(record); - let isInArray = records.includes(arrayRecord); - - if (isInArray === false) { - // Fetching information - fetch( - "http://localhost:2050/records?from=" + - IdValue + - "&to=" + - IdValue, - { - method: "GET", - headers: { "Content-Type": "application/json" }, - } - ) - .then((response) => response.text()) - .then((data) => { - let columnDataList = JSON.parse(data); - - infoColumns.innerHTML += ""; - for (let i = 0; i < columnDataList.length; i++) { - multipleSingularColumns( - columnDataList[i], - letterValue, - IdValue - ); - } - }); - records.push(arrayRecord); - - for (let i = 0; i < records.length; i++) { - JSON.parse(records[i]); - } - } else { - alert("The record was already added"); - } - } else { - alert("Enter apropriate inputs please"); - } - } - }); - records = records; + if (numberOne === 0 && numberTwo === 15) { + previousBtn.style.display = "none"; + currentPage.innerHTML = ""; + currentPage.innerHTML = nextNumberOne + " -> " + nextNumberTwo; + numberOne = nextNumberOne; + numberTwo = nextNumberTwo; } else { - alert( - "Sorry there has been a problem. The page will reload can you please try again." - ); - window.location.reload(); + currentPage.innerHTML = ""; + currentPage.innerHTML = nextNumberOne + " -> " + nextNumberTwo; + numberOne = nextNumberOne; + numberTwo = nextNumberTwo; } - } else { - alert( - "Sorry there has been a problem. The page will reload can you please try again." - ); - window.location.reload(); - } + }); } +nextPrevious(0, 15); + // + +// function multipleSingularColumns( +// info: string, +// columnPostion: string, +// idOfData: string +// ) { +// let infoColumns: any = document.querySelector("#info-columns"); +// let infoRows = ` +//
+//
${info[0]}
+//
${info[1]}
+//
${info[2]}
+//
${info[3]}
+//
${info[4]}
+//
${info[5]}
+//
${info[6]}
+//
${info[7]}
+//
${info[8]}
+//
${info[9]}
+//
${info[10]}
+//
`; + +// if (columnPostion === "a") { +// infoColumns.innerHTML += infoRows; +// let infoColumnTargeted: any = document.querySelector( +// "#one.certain-column" + idOfData +// ); +// infoColumnTargeted.style.color = "red"; +// } else if (columnPostion === "b") { +// infoColumns.innerHTML += infoRows; +// let infoColumnTargeted: any = document.querySelector( +// "#two.certain-column" + idOfData +// ); +// infoColumnTargeted.style.color = "red"; +// } else if (columnPostion === "c") { +// infoColumns.innerHTML += infoRows; +// let infoColumnTargeted: any = document.querySelector( +// "#three.certain-column" + idOfData +// ); +// infoColumnTargeted.style.color = "red"; +// } else if (columnPostion === "d") { +// infoColumns.innerHTML += infoRows; +// let infoColumnTargeted: any = document.querySelector( +// "#four.certain-column" + idOfData +// ); +// infoColumnTargeted.style.color = "red"; +// } else if (columnPostion === "e") { +// infoColumns.innerHTML += infoRows; +// let infoColumnTargeted: any = document.querySelector( +// "#five.certain-column" + idOfData +// ); +// infoColumnTargeted.style.color = "red"; +// } else if (columnPostion === "f") { +// infoColumns.innerHTML += infoRows; +// let infoColumnTargeted: any = document.querySelector( +// "#six.certain-column" + idOfData +// ); +// infoColumnTargeted.style.color = "red"; +// } else if (columnPostion === "g") { +// infoColumns.innerHTML += infoRows; +// let infoColumnTargeted: any = document.querySelector( +// "#seven.certain-column" + idOfData +// ); +// infoColumnTargeted.style.color = "red"; +// } else if (columnPostion === "h") { +// infoColumns.innerHTML += infoRows; +// let infoColumnTargeted: any = document.querySelector( +// "#eight.certain-column" + idOfData +// ); +// infoColumnTargeted.style.color = "red"; +// } else if (columnPostion === "i") { +// infoColumns.innerHTML += infoRows; +// let infoColumnTargeted: any = document.querySelector( +// "#nine.certain-column" + idOfData +// ); +// infoColumnTargeted.style.color = "red"; +// } else if (columnPostion === "j") { +// infoColumns.innerHTML += infoRows; +// let infoColumnTargeted: any = document.querySelector( +// "#ten.certain-column" + idOfData +// ); +// infoColumnTargeted.style.color = "red"; +// } else { +// alert("Error"); +// } +// } + +// Function that allows the user to filter between looking fo a singular record, multiple records or multiple singular records. + +// function recordSelection() { +// // let confirmationBtn: any = document.querySelector("#select-confirmation-btn") runs the function in the html (onclick); +// // Accesses the area on the page where the select is shown. +// let selectionArea: any = recordNav; +// // Checks how you want filter records. +// let recordSelector: any = document.querySelector("#record-selection"); +// let recordSelectionValue: string = recordSelector.value; +// // +// let records: any = []; + +// // Checks if the select gives a proper value. +// if ( +// recordSelectionValue === "multiple" || +// recordSelectionValue === "multiple-single" +// ) { +// if (recordSelectionValue === "multiple") { +// let multipleRecordSelection = ` +// +//
+// +//
+// +// `; +// selectionArea.innerHTML = ""; +// selectionArea.innerHTML = multipleRecordSelection; + +// let returnBtn: any = document.querySelector( +// "#multiple-return-btn.return-btn" +// ); + +// returnBtn.addEventListener("click", () => { +// records = []; +// headingColumns.innerHTML = ""; +// infoColumns.innerHTML = ""; +// fetchData(); +// createNavigation(); +// }); + +// let multipleSubmitBtn: any = document.querySelector( +// "#multiple-submit-btn.submit-btn" +// ); +// multipleSubmitBtn.addEventListener("click", () => { +// let fromIdSelection: any = document.querySelector( +// "#from-record-id.navigation-input" +// ); +// let toIdSelection: any = document.querySelector( +// "#to-record-id.navigation-input" +// ); + +// let fromIdValue = fromIdSelection.value; +// let toIdValue = toIdSelection.value; + +// if (fromIdValue.length === 0 || toIdValue === 0) { +// alert( +// "You left one of the record id inputs empty or you have entered an incorrect character." +// ); +// } else { +// if ( +// (fromIdValue !== null && toIdValue !== null) || +// (fromIdValue !== "" && toIdValue !== "") +// ) { +// const totalRecordsAllowed = 16; +// let recordCount: number = +// Number(toIdValue) - Number(fromIdValue) + 1; +// if ( +// recordCount > totalRecordsAllowed || +// typeof recordCount !== "number" +// ) { +// let excessRecords = recordCount - totalRecordsAllowed; +// toIdValue = toIdValue - excessRecords; +// alert( +// "The data you entered is incorrect or you trying to access to much records only " + +// totalRecordsAllowed + +// " records can be accessed at a time. You have " + +// excessRecords + +// " excess records" +// ); +// // Fetching information +// fetch( +// "http://localhost:2050/records?from=" + +// fromIdValue + +// "&to=" + +// toIdValue, +// { +// method: "GET", +// headers: { "Content-Type": "application/json" }, +// } +// ) +// .then((response) => response.text()) +// .then((data) => { +// let columnDataList = JSON.parse(data); + +// infoColumns.innerHTML = ""; +// }); +// } else if (recordCount <= 16 || typeof recordCount === "number") { +// // Fetching information +// fetch( +// "http://localhost:2050/records?from=" + +// fromIdValue + +// "&to=" + +// toIdValue, +// { +// method: "GET", +// headers: { "Content-Type": "application/json" }, +// } +// ) +// .then((response) => response.text()) +// .then((data) => { +// let columnDataList = JSON.parse(data); + +// infoColumns.innerHTML = ""; +// for (let i = 0; i < columnDataList.length; i++) { + +// } +// }); +// } +// } else { +// alert( +// "Sorry there has been a problem. Please check your inputs make sure you have both filled." +// ); +// } +// } +// }); +// } else if (recordSelectionValue === "multiple-single") { +// let multipleSingleRecordSelection = ` +// +//
+// +//
+// +// `; +// selectionArea.innerHTML = ""; +// selectionArea.innerHTML = multipleSingleRecordSelection; +// let returnBtn: any = document.querySelector( +// "#multiple-single-return-btn.return-btn" +// ); +// returnBtn.addEventListener("click", () => { +// alert("Records you have viewed " + records); +// headingColumns.innerHTML = ""; +// infoColumns.innerHTML = ""; +// fetchData(); +// createNavigation(); +// }); +// let addMulitpleSingularRecords: any = document.querySelector( +// "#add-records-btn.add-btn" +// ); + +// addMulitpleSingularRecords.addEventListener("click", () => { +// // Inputs and selects +// let IdSelection: any = document.querySelector( +// "#record-id.navigation-input" +// ); + +// let letterValueSelection: any = +// document.querySelector("#record-content"); + +// //Values Needed +// let IdValue = IdSelection.value; +// let letterValue = letterValueSelection.value; +// let numberCheck: number = 12 - Number(IdValue); +// const recordAmount: number = 16; +// let amountOfRecords = records.length; + +// if (amountOfRecords > recordAmount) { +// alert("That is the total amount of records that can be added"); +// } else if (amountOfRecords === 0) { +// infoColumns.innerHTML = ""; +// } else { +// //pass +// } + +// if (IdValue.length === 0 || letterValue === "none") { +// alert( +// "You left one of the record id inputs empty or you have entered an incorrect character." +// ); +// } else { +// if ( +// typeof numberCheck === "number" && +// typeof letterValue === "string" +// ) { +// let record = { +// Id: IdValue, +// letterId: letterValue, +// }; +// let arrayRecord = JSON.stringify(record); +// let isInArray = records.includes(arrayRecord); + +// if (isInArray === false) { +// // Fetching information +// fetch( +// "http://localhost:2050/records?from=" + +// IdValue + +// "&to=" + +// IdValue, +// { +// method: "GET", +// headers: { "Content-Type": "application/json" }, +// } +// ) +// .then((response) => response.text()) +// .then((data) => { +// let columnDataList = JSON.parse(data); + +// infoColumns.innerHTML += ""; +// console.log(columnDataList); +// }); +// records.push(arrayRecord); + +// for (let i = 0; i < records.length; i++) { +// JSON.parse(records[i]); +// } +// } else { +// alert("The record was already added"); +// } +// } else { +// alert("Enter apropriate inputs please"); +// } +// } +// }); +// records = records; +// } else { +// alert( +// "Sorry there has been a problem. The page will reload can you please try again." +// ); +// window.location.reload(); +// } +// } else { +// alert("Error"); +// } +// } diff --git a/index.html b/index.html index 7b16eea4..e79d8cd2 100644 --- a/index.html +++ b/index.html @@ -10,10 +10,9 @@ -
-
-
+
+
+
- diff --git a/server/main.go b/server/main.go index de0930b4..f4ce292a 100644 --- a/server/main.go +++ b/server/main.go @@ -13,7 +13,7 @@ import ( "time" ) -var columns = [11]string{"ID", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"} +var columns = [13]string{"ID", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"} const recordCount = 1000000 const columnCount = len(columns); const delayResponse = 500 * time.Millisecond diff --git a/style.css b/style.css index 9d94a604..cdcb3d72 100644 --- a/style.css +++ b/style.css @@ -13,123 +13,111 @@ } /* */ -select, -button, -input { - text-align: center; - width: 250px; - height: 50px; - font-size: 18px; - border: 2px solid black; - border-radius: 5px; - background-color: transparent; - transition: all 0.5s; - transition-timing-function: ease-in-out; +/* Body */ +body { + display: flex; + flex-direction: column; + align-items: center; + height: 100vh; } -select:hover, -button:hover, -input:hover { - transform: scale(1.1); - color: white; - border-color: white; - background-color: black; +/* Buttons, selects and inputs */ +button, +select, +input { + width: 200px; + padding: 10px; } -/* Selection tabs */ -#record-navigation { +/* HTML containers */ +/* Navigation */ +#record-navigation-container { display: flex; align-items: center; - justify-content: space-evenly; + justify-content: space-between; flex-direction: row; - padding: 10px; - height: 10vh; + height: 15vh; + max-width: 100%; + min-width: 50%; + width: 100%; + padding: 20px; + border-bottom: 1px solid black; } -#user-input-data { +.next-previous-navigation { display: flex; align-items: center; justify-content: space-between; flex-direction: row; - height: 100%; + width: 40%; } -.navigation-input-area { +.next-previous-navigation-btns { display: flex; - align-items: center; flex-direction: row; - padding: 10px; + justify-content: space-around; + width: 100%; } -#from-id, -#to-id, -.navigation-input-area-id { +.current-page-container { display: flex; + justify-content: center; align-items: center; - flex-direction: row; - margin-left: 20px; height: 100%; + width: 20%; + border-left: 1px solid black; + border-right: 1px solid black; } -.record-labels { - padding: 5px 10px 0px 0px; +.current-page { + text-align: center; } -.navigation-input { - padding: 5px; +.select-confirm { + display: flex; + align-items: center; + justify-content: space-around; + flex-direction: row; + width: 40%; } /* */ - -/*Styling for the column headings*/ -#column-headings { +/* Headings */ +#column-headings-container { display: flex; - justify-content: space-between; - align-items: center; flex-direction: row; height: 10vh; width: 100%; - border-block: 2px solid black; - font-size: 30px; + border-bottom: 1px solid black; } .column-heading { - display: flex; - justify-content: center; - align-items: center; - border-left: 1px solid black; + padding: 20px; + text-align: center; border-right: 1px solid black; - width: 100%; height: 100%; + width: 100%; } /* */ -/*Styling for the columns*/ -#info-columns { +/* Data */ +#info-columns-container { display: flex; - flex-wrap: wrap; + justify-content: space-between; + flex-direction: column; + height: 75vh; width: 100%; - height: calc(100vh -15vh); } .info-row { display: flex; - justify-content: center; - align-items: center; - height: 5vh; + flex-direction: row; + justify-content: space-between; width: 100%; - border-bottom: 2px solid black; - font-size: 20px; - transition: all 0.5s; - transition-timing-function: ease-in-out; + height: 100%; + border-bottom: 1px solid black; } -.info-column { - display: flex; - justify-content: center; - align-items: center; - border-left: 1px solid black; - border-right: 1px solid black; +.info-data { width: 100%; - height: 100%; + border-right: 1px solid black; } -/* */ From 78d364611711cb26bccb46ff0208e8c5c866d5a2 Mon Sep 17 00:00:00 2001 From: AshtonMar Date: Thu, 14 Apr 2022 15:53:03 +0200 Subject: [PATCH 06/30] Todays changes --- app.ts | 821 ++++++++++++++++++++++++------------------------- server/main.go | 2 +- style.css | 18 +- 3 files changed, 408 insertions(+), 433 deletions(-) diff --git a/app.ts b/app.ts index 7484f019..d274ade8 100644 --- a/app.ts +++ b/app.ts @@ -9,6 +9,8 @@ function createNavigation() {
+ +
@@ -17,7 +19,7 @@ function createNavigation() {
-//
-// -//
-// -// `; -// selectionArea.innerHTML = ""; -// selectionArea.innerHTML = multipleRecordSelection; - -// let returnBtn: any = document.querySelector( -// "#multiple-return-btn.return-btn" -// ); - -// returnBtn.addEventListener("click", () => { -// records = []; -// headingColumns.innerHTML = ""; -// infoColumns.innerHTML = ""; -// fetchData(); -// createNavigation(); -// }); - -// let multipleSubmitBtn: any = document.querySelector( -// "#multiple-submit-btn.submit-btn" -// ); -// multipleSubmitBtn.addEventListener("click", () => { -// let fromIdSelection: any = document.querySelector( -// "#from-record-id.navigation-input" -// ); -// let toIdSelection: any = document.querySelector( -// "#to-record-id.navigation-input" -// ); - -// let fromIdValue = fromIdSelection.value; -// let toIdValue = toIdSelection.value; - -// if (fromIdValue.length === 0 || toIdValue === 0) { -// alert( -// "You left one of the record id inputs empty or you have entered an incorrect character." -// ); -// } else { -// if ( -// (fromIdValue !== null && toIdValue !== null) || -// (fromIdValue !== "" && toIdValue !== "") -// ) { -// const totalRecordsAllowed = 16; -// let recordCount: number = -// Number(toIdValue) - Number(fromIdValue) + 1; -// if ( -// recordCount > totalRecordsAllowed || -// typeof recordCount !== "number" -// ) { -// let excessRecords = recordCount - totalRecordsAllowed; -// toIdValue = toIdValue - excessRecords; -// alert( -// "The data you entered is incorrect or you trying to access to much records only " + -// totalRecordsAllowed + -// " records can be accessed at a time. You have " + -// excessRecords + -// " excess records" -// ); -// // Fetching information -// fetch( -// "http://localhost:2050/records?from=" + -// fromIdValue + -// "&to=" + -// toIdValue, -// { -// method: "GET", -// headers: { "Content-Type": "application/json" }, -// } -// ) -// .then((response) => response.text()) -// .then((data) => { -// let columnDataList = JSON.parse(data); - -// infoColumns.innerHTML = ""; -// }); -// } else if (recordCount <= 16 || typeof recordCount === "number") { -// // Fetching information -// fetch( -// "http://localhost:2050/records?from=" + -// fromIdValue + -// "&to=" + -// toIdValue, -// { -// method: "GET", -// headers: { "Content-Type": "application/json" }, -// } -// ) -// .then((response) => response.text()) -// .then((data) => { -// let columnDataList = JSON.parse(data); - -// infoColumns.innerHTML = ""; -// for (let i = 0; i < columnDataList.length; i++) { - -// } -// }); -// } -// } else { -// alert( -// "Sorry there has been a problem. Please check your inputs make sure you have both filled." -// ); -// } -// } -// }); -// } else if (recordSelectionValue === "multiple-single") { -// let multipleSingleRecordSelection = ` -// -//
-// -//
-// -// `; -// selectionArea.innerHTML = ""; -// selectionArea.innerHTML = multipleSingleRecordSelection; -// let returnBtn: any = document.querySelector( -// "#multiple-single-return-btn.return-btn" -// ); -// returnBtn.addEventListener("click", () => { -// alert("Records you have viewed " + records); -// headingColumns.innerHTML = ""; -// infoColumns.innerHTML = ""; -// fetchData(); -// createNavigation(); -// }); -// let addMulitpleSingularRecords: any = document.querySelector( -// "#add-records-btn.add-btn" -// ); - -// addMulitpleSingularRecords.addEventListener("click", () => { -// // Inputs and selects -// let IdSelection: any = document.querySelector( -// "#record-id.navigation-input" -// ); - -// let letterValueSelection: any = -// document.querySelector("#record-content"); - -// //Values Needed -// let IdValue = IdSelection.value; -// let letterValue = letterValueSelection.value; -// let numberCheck: number = 12 - Number(IdValue); -// const recordAmount: number = 16; -// let amountOfRecords = records.length; - -// if (amountOfRecords > recordAmount) { -// alert("That is the total amount of records that can be added"); -// } else if (amountOfRecords === 0) { -// infoColumns.innerHTML = ""; -// } else { -// //pass -// } - -// if (IdValue.length === 0 || letterValue === "none") { -// alert( -// "You left one of the record id inputs empty or you have entered an incorrect character." -// ); -// } else { -// if ( -// typeof numberCheck === "number" && -// typeof letterValue === "string" -// ) { -// let record = { -// Id: IdValue, -// letterId: letterValue, -// }; -// let arrayRecord = JSON.stringify(record); -// let isInArray = records.includes(arrayRecord); - -// if (isInArray === false) { -// // Fetching information -// fetch( -// "http://localhost:2050/records?from=" + -// IdValue + -// "&to=" + -// IdValue, -// { -// method: "GET", -// headers: { "Content-Type": "application/json" }, -// } -// ) -// .then((response) => response.text()) -// .then((data) => { -// let columnDataList = JSON.parse(data); - -// infoColumns.innerHTML += ""; -// console.log(columnDataList); -// }); -// records.push(arrayRecord); - -// for (let i = 0; i < records.length; i++) { -// JSON.parse(records[i]); -// } -// } else { -// alert("The record was already added"); -// } -// } else { -// alert("Enter apropriate inputs please"); -// } -// } -// }); -// records = records; -// } else { -// alert( -// "Sorry there has been a problem. The page will reload can you please try again." -// ); -// window.location.reload(); -// } -// } else { -// alert("Error"); -// } -// } +function recordSelection() { + let selectionArea: any = recordNav; + let recordSelector: any = document.querySelector("#record-selection"); + let recordSelectionValue: string = recordSelector.value; + let records: any = []; + + if ( + recordSelectionValue === "multiple" || + recordSelectionValue === "single" + ) { + if (recordSelectionValue === "multiple") { + let multipleRecordSelection = ` + +
+ +
+ + `; + selectionArea.innerHTML = ""; + selectionArea.innerHTML = multipleRecordSelection; + + let returnBtn: any = document.querySelector( + "#multiple-return-btn.return-btn" + ); + + returnBtn.addEventListener("click", () => { + records = []; + headingColumns.innerHTML = ""; + infoColumns.innerHTML = ""; + fetchData(); + createNavigation(); + }); + + let multipleSubmitBtn: any = document.querySelector( + "#multiple-submit-btn.submit-btn" + ); + multipleSubmitBtn.addEventListener("click", () => { + let fromIdSelection: any = document.querySelector( + "#from-record-id.navigation-input" + ); + let toIdSelection: any = document.querySelector( + "#to-record-id.navigation-input" + ); + + let fromIdValue = fromIdSelection.value; + let toIdValue = toIdSelection.value; + + if (fromIdValue.length === 0 || toIdValue === 0) { + alert( + "You left one of the record id inputs empty or you have entered an incorrect character." + ); + } else { + if ( + (fromIdValue !== null && toIdValue !== null) || + (fromIdValue !== "" && toIdValue !== "") + ) { + const totalRecordsAllowed = 16; + let recordCount: number = + Number(toIdValue) - Number(fromIdValue) + 1; + if ( + recordCount > totalRecordsAllowed || + typeof recordCount !== "number" + ) { + let excessRecords = recordCount - totalRecordsAllowed; + toIdValue = toIdValue - excessRecords; + alert( + "The data you entered is incorrect or you trying to access to much records only " + + totalRecordsAllowed + + " records can be accessed at a time. You have " + + excessRecords + + " excess records" + ); + // Fetching information + fetch( + "http://localhost:2050/records?from=" + + fromIdValue + + "&to=" + + toIdValue, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + } + ) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + + infoColumns.innerHTML = ""; + }); + } else if (recordCount <= 16 || typeof recordCount === "number") { + // Fetching information + fetch( + "http://localhost:2050/records?from=" + + fromIdValue + + "&to=" + + toIdValue, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + } + ) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + + infoColumns.innerHTML = ""; + for (let i = 0; i < columnDataList.length; i++) {} + }); + } + } else { + alert( + "Sorry there has been a problem. Please check your inputs make sure you have both filled." + ); + } + } + }); + } else if (recordSelectionValue === "single") { + let multipleSingleRecordSelection = ` + +
+ +
+ + `; + selectionArea.innerHTML = ""; + selectionArea.innerHTML = multipleSingleRecordSelection; + let returnBtn: any = document.querySelector( + "#multiple-single-return-btn.return-btn" + ); + returnBtn.addEventListener("click", () => { + alert("Records you have viewed " + records); + headingColumns.innerHTML = ""; + infoColumns.innerHTML = ""; + fetchData(); + createNavigation(); + }); + let addMulitpleSingularRecords: any = document.querySelector( + "#add-records-btn.add-btn" + ); + + addMulitpleSingularRecords.addEventListener("click", () => { + // Inputs and selects + let IdSelection: any = document.querySelector( + "#record-id.navigation-input" + ); + + let letterValueSelection: any = + document.querySelector("#record-content"); + + //Values Needed + let IdValue = IdSelection.value; + let letterValue = letterValueSelection.value; + let numberCheck: number = 12 - Number(IdValue); + const recordAmount: number = 16; + let amountOfRecords = records.length; + + if (amountOfRecords > recordAmount) { + alert("That is the total amount of records that can be added"); + } else if (amountOfRecords === 0) { + infoColumns.innerHTML = ""; + } else { + //pass + } + + if (IdValue.length === 0 || letterValue === "none") { + alert( + "You left one of the record id inputs empty or you have entered an incorrect character." + ); + } else { + if ( + typeof numberCheck === "number" && + typeof letterValue === "string" + ) { + let record = { + Id: IdValue, + letterId: letterValue, + }; + let arrayRecord = JSON.stringify(record); + let isInArray = records.includes(arrayRecord); + + if (isInArray === false) { + // Fetching information + fetch( + "http://localhost:2050/records?from=" + + IdValue + + "&to=" + + IdValue, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + } + ) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + + infoColumns.innerHTML += ""; + console.log(columnDataList); + }); + records.push(arrayRecord); + + for (let i = 0; i < records.length; i++) { + JSON.parse(records[i]); + } + } else { + alert("The record was already added"); + } + } else { + alert("Enter apropriate inputs please"); + } + } + }); + records = records; + } else { + alert( + "Sorry there has been a problem. The page will reload can you please try again." + ); + window.location.reload(); + } + } else { + alert("Error"); + } +} diff --git a/server/main.go b/server/main.go index f4ce292a..de0930b4 100644 --- a/server/main.go +++ b/server/main.go @@ -13,7 +13,7 @@ import ( "time" ) -var columns = [13]string{"ID", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"} +var columns = [11]string{"ID", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"} const recordCount = 1000000 const columnCount = len(columns); const delayResponse = 500 * time.Millisecond diff --git a/style.css b/style.css index cdcb3d72..10096a8e 100644 --- a/style.css +++ b/style.css @@ -3,6 +3,7 @@ padding: 0; box-sizing: border-box; font-family: sans-serif; + font-size: 12px; overflow-y: hidden; overflow-x: hidden; } @@ -27,6 +28,7 @@ select, input { width: 200px; padding: 10px; + margin: 5px; } /* HTML containers */ @@ -54,6 +56,7 @@ input { .next-previous-navigation-btns { display: flex; + flex-wrap: wrap; flex-direction: row; justify-content: space-around; width: 100%; @@ -91,6 +94,7 @@ input { } .column-heading { + font-size: 30px; padding: 20px; text-align: center; border-right: 1px solid black; @@ -102,22 +106,26 @@ input { /* Data */ #info-columns-container { display: flex; - justify-content: space-between; flex-direction: column; + justify-content: space-between; height: 75vh; width: 100%; } -.info-row { +.info-data-row { display: flex; flex-direction: row; justify-content: space-between; + height: 10vh; width: 100%; - height: 100%; border-bottom: 1px solid black; } -.info-data { +.info-column { + padding: 15px; + text-align: center; width: 100%; - border-right: 1px solid black; + border-right: 1px solid; } + +/* .info-data-row; */ From 20f8768654f98b6ca6abe1574576129875ca8a24 Mon Sep 17 00:00:00 2001 From: AshtonMar Date: Wed, 20 Apr 2022 12:35:10 +0200 Subject: [PATCH 07/30] Todays changes --- Project Notes | 1 + app.ts | 505 ++++++++++++++++++++++++------------------------- server/main.go | 2 +- style.css | 78 +++----- 4 files changed, 285 insertions(+), 301 deletions(-) create mode 100644 Project Notes diff --git a/Project Notes b/Project Notes new file mode 100644 index 00000000..206518fb --- /dev/null +++ b/Project Notes @@ -0,0 +1 @@ +ID and other columns have the number in common. e.g 0 diff --git a/app.ts b/app.ts index d274ade8..5ffd69b8 100644 --- a/app.ts +++ b/app.ts @@ -3,54 +3,54 @@ let recordNav: any = document.querySelector("#record-navigation-container"); //N let headingColumns: any = document.querySelector("#column-headings-container"); //Headings; let infoColumns: any = document.querySelector("#info-columns-container"); //Information; +// Creates the navigation. function createNavigation() { recordNav.innerHTML = ` -
-
-
-

-
-
+
-
+
+
+

+
+ `; } +// Heading and info grid being created. function createHeadingGrid(headings: any) { let headingsData: any = `

${headings}

`; headingColumns.innerHTML += headingsData; } -function createGrid(columnData: string) { - let infoRowColumns: any = ` -
-

${columnData[0]}

-

${columnData[1]}

-

${columnData[2]}

-

${columnData[3]}

-

${columnData[4]}

-

${columnData[5]}

-

${columnData[6]}

-

${columnData[7]}

-

${columnData[8]}

-

${columnData[9]}

-

${columnData[10]}

-
`; - infoColumns.innerHTML += infoRowColumns; +function dynamicGrid(columnData: any) { + // Creates the row that the info will display and adds it to the infoColumnsArea. + let infoDataRow = `
`; + infoColumns.innerHTML += infoDataRow; + // Gets the created rows. + let finalInfoDataRow: any = document.querySelector( + "#info-row-" + columnData[0] + ".info-rows" + ); + + // Loops through + for (let x = 0; x < columnData.length; x++) { + let Div = `

${columnData[x]}

`; + finalInfoDataRow.innerHTML += Div; + } } +// Adds data in the heading and info grid. function fetchData() { // Gets headings array fetch("http://localhost:2050/columns", { @@ -84,7 +84,8 @@ function fetchData() { .then((data) => { let columnDataList = JSON.parse(data); for (let i = 0; i < columnDataList.length; i++) { - createGrid(columnDataList[i]); + // createGrid(columnDataList[i]); + dynamicGrid(columnDataList[i]); } }); }); @@ -94,37 +95,26 @@ function fetchData() { fetchData(); -function nextPageData(firstNumber: any, secondNumber: any) { - // Fetching information - fetch( - "http://localhost:2050/records?from=" + firstNumber + "&to=" + secondNumber, - { - method: "GET", - headers: { "Content-Type": "application/json" }, - } - ) - .then((response) => response.text()) - .then((data) => { - let columnDataList = JSON.parse(data); - infoColumns.innerHTML = ""; - for (let i = 0; i < columnDataList.length; i++) { - createGrid(columnDataList[i]); - } - }); -} - +// The functionality to move through an amount of records. function nextPrevious(firstId: any, finalId: any) { + // Btn's used to move from page to page. let nextBtn: any = document.querySelector(".next-records-btn"); let previousBtn: any = document.querySelector(".previous-records-btn"); - let resetBtn: any = document.querySelector(".reset-records-btn"); + + // Btn's used to move directly to the last and first page. + let firstPageBtn: any = document.querySelector(".reset-records-btn"); let lastPageBtn: any = document.querySelector(".last-records-btn"); + + // The area where the current page is shown. let currentPage: any = document.querySelector(".current-page"); + // The id's of the records that represent the first and last record of the page. let numberOne: number = firstId; let numberTwo: number = finalId; const amountRecords: number = 15; - currentPage.innerHTML = numberOne + " -> " + numberTwo + " First Page"; + // Dsplays the current page. + currentPage.innerHTML = numberOne + " / " + numberTwo + " First Page"; if (numberOne === 0 && numberTwo === 14) { previousBtn.disabled = true; @@ -132,19 +122,22 @@ function nextPrevious(firstId: any, finalId: any) { //pass } - resetBtn.addEventListener("click", () => { + // The button that takes you to the first page. + firstPageBtn.addEventListener("click", () => { let nextNumberOne: number = 0; let nextNumberTwo: number = 14; previousBtn.disabled = true; nextBtn.disabled = false; currentPage.innerHTML = ""; - currentPage.innerHTML = nextNumberOne + " -> " + nextNumberTwo; + currentPage.innerHTML = + nextNumberOne + " / " + nextNumberTwo + " First Page"; numberOne = nextNumberOne; numberTwo = nextNumberTwo; nextPageData(numberOne, numberTwo); }); + // The button that takes you to the last page. lastPageBtn.addEventListener("click", () => { let nextNumberOne: number = 999985; let nextNumberTwo: number = 999999; @@ -152,12 +145,14 @@ function nextPrevious(firstId: any, finalId: any) { previousBtn.disabled = false; currentPage.innerHTML = ""; - currentPage.innerHTML = nextNumberOne + " -> " + nextNumberTwo; + currentPage.innerHTML = + nextNumberOne + " / " + nextNumberTwo + " Last Page"; numberOne = nextNumberOne; numberTwo = nextNumberTwo; nextPageData(numberOne, numberTwo); }); + // The button that takes you to the next page. nextBtn.addEventListener("click", () => { let nextNumberOne: number = numberOne + amountRecords; let nextNumberTwo: number = numberTwo + amountRecords; @@ -166,20 +161,21 @@ function nextPrevious(firstId: any, finalId: any) { if (nextNumberOne === 999985 && nextNumberTwo === 999999) { currentPage.innerHTML = ""; currentPage.innerHTML = - nextNumberOne + " -> " + nextNumberTwo + " Final Page"; + nextNumberOne + " / " + nextNumberTwo + " Final Page"; numberOne = nextNumberOne; numberTwo = nextNumberTwo; nextPageData(numberOne, numberTwo); nextBtn.disabled = true; } else { currentPage.innerHTML = ""; - currentPage.innerHTML = nextNumberOne + " -> " + nextNumberTwo; + currentPage.innerHTML = nextNumberOne + " / " + nextNumberTwo; numberOne = nextNumberOne; numberTwo = nextNumberTwo; nextPageData(numberOne, numberTwo); } }); + // The button that takes you to the previous page. previousBtn.addEventListener("click", () => { let nextNumberOne: number = numberOne - amountRecords; let nextNumberTwo: number = numberTwo - amountRecords; @@ -188,20 +184,41 @@ function nextPrevious(firstId: any, finalId: any) { if (nextNumberOne === 0 && nextNumberTwo === 14) { currentPage.innerHTML = ""; currentPage.innerHTML = - nextNumberOne + " -> " + nextNumberTwo + " First Page"; + nextNumberOne + " / " + nextNumberTwo + " First Page"; numberOne = nextNumberOne; numberTwo = nextNumberTwo; nextPageData(numberOne, numberTwo); previousBtn.disabled = true; } else { currentPage.innerHTML = ""; - currentPage.innerHTML = nextNumberOne + " -> " + nextNumberTwo; + currentPage.innerHTML = nextNumberOne + " / " + nextNumberTwo; numberOne = nextNumberOne; numberTwo = nextNumberTwo; nextPageData(numberOne, numberTwo); } }); } + +function nextPageData(firstNumber: any, secondNumber: any) { + // Fetching information that will display when you go to the next or previous page. + fetch( + "http://localhost:2050/records?from=" + firstNumber + "&to=" + secondNumber, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + } + ) + .then((response) => response.text()) + .then((data) => { + let columnDataList = JSON.parse(data); + infoColumns.innerHTML = ""; + for (let i = 0; i < columnDataList.length; i++) { + dynamicGrid(columnDataList[i]); + } + }); +} + +// Checks if you looking for a single or multiple records. function recordSelection() { let selectionArea: any = recordNav; let recordSelector: any = document.querySelector("#record-selection"); @@ -212,119 +229,99 @@ function recordSelection() { recordSelectionValue === "multiple" || recordSelectionValue === "single" ) { - if (recordSelectionValue === "multiple") { - let multipleRecordSelection = ` - -
-