-
Notifications
You must be signed in to change notification settings - Fork 36
Ashton Martin #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Ashton Martin #45
Changes from 21 commits
3d76748
fc17d76
f1e2d5e
abf2e25
236ae3e
78d3646
20f8768
25982e1
d5a0150
27e37ab
8e1c83c
28c0127
c0cc0dd
0a5e24a
22ac146
d868815
a25fa90
ed88ede
fdc8503
891521b
9c4f823
2240555
ca85f76
9c05769
e991ebf
b085bdd
921241f
a58c56d
19aeeb5
78f5400
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,287 @@ | ||
| let headingColumns: any = document.querySelector("#column-headings-container"); // Headings | ||
| let infoColumns: any = document.querySelector("#info-columns-container"); // Information | ||
| let fromNumber = 0; | ||
| let recordNumberTotal: number; | ||
| let count = 0; | ||
| let timeout = 0; | ||
|
|
||
| window.onload = () => { | ||
| fromNumber = 0; | ||
| }; | ||
|
|
||
| let debounce = (func: any, delay: number) => { | ||
| return function () { | ||
| clearTimeout(timeout); | ||
|
|
||
| timeout = setTimeout(() => { | ||
| func(); | ||
| }, delay); | ||
| }; | ||
| }; | ||
|
|
||
| let createNavigation = () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change this variable to a normal function, seeing as that you never override the value. |
||
| let recordNav: any = document.querySelector("#record-navigation-container"); // Navigation area | ||
| recordNav.innerHTML = ` | ||
| <div class="navigation-btns"> | ||
| <button value="first" class="first-page-btn">First Page</button> | ||
| <button value="previous" class="previous-records-btn">Previous</button> | ||
| <button value="next" class="next-records-btn">Next</button> | ||
| <button value="last" class="last-page-btn">Last Page</button> | ||
| <button onclick="recordSelection()" id="confirmation-btn">Get Record</button> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should not specify your |
||
| </div> | ||
| <div class="current-page-container"> | ||
| <p class=current-page></p> | ||
| </div> | ||
| `; | ||
| }; | ||
|
|
||
| function recordSelection() { | ||
| let selectionArea: any = document.querySelector("#record-navigation-container"); | ||
| let singleRecordSelection = ` | ||
| <button id="return-btn">Return</button> | ||
| <div id="user-input-data"> | ||
| <div class="navigation-input-area-id" id="id"> | ||
| <label class="record-labels" for="record-id" | ||
| >Enter record ID : | ||
| </label> | ||
| <input | ||
| type="text" | ||
| min="0" | ||
| minlength="1" | ||
| maxlength="6" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding the max length here is a bad idea, as the maximum amount of rows that you could get is unknown. |
||
| name="record-id" | ||
| id="record-id" | ||
| class="navigation-input" | ||
| value="0" | ||
| /> | ||
| </div> | ||
| <p class="amount-of-records"></p> | ||
| </div> | ||
| <button id="get-record-btn">See Record</button> | ||
| `; | ||
|
|
||
| selectionArea.innerHTML = singleRecordSelection; | ||
|
|
||
| let returnBtn: any = document.querySelector("#return-btn"); | ||
| let recordIdValue: any = document.querySelector("#record-id.navigation-input"); | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
|
|
||
| returnBtn.addEventListener("click", () => { | ||
| window.location.reload(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you definitely do not want this line anywhere in your project... This is a single page app, reloading is not an option. |
||
| }); | ||
|
|
||
| let getSingleRecord: any = document.querySelector("#get-record-btn"); | ||
|
|
||
| getSingleRecord.addEventListener("click", () => { | ||
| fromNumber = Number(recordIdValue.value); | ||
| let toNumber = fromNumber + numberOfRows; | ||
| let finalRecord = recordNumberTotal - 1; | ||
|
|
||
| if (toNumber > finalRecord) { | ||
| toNumber = finalRecord; | ||
| fromNumber = toNumber - numberOfRows; | ||
| } | ||
|
|
||
| let check = ["undefined", "string", ""]; | ||
|
|
||
| try { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to complete this project with out using any |
||
| if (check.includes(typeof fromNumber) || fromNumber < 0) { | ||
| alert("Does not exists"); | ||
| recordIdValue.value = "0"; | ||
| } else if (typeof fromNumber === "number" && fromNumber >= 0) { | ||
| getRecords(fromNumber, toNumber); | ||
| } | ||
| } catch (error) { | ||
| alert(error); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function createHeadingGrid(headings: any) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please specify the real type here. |
||
| let headingsData: any = `<h1 class="column-heading">${headings}</h1>`; | ||
| headingColumns.innerHTML += headingsData; | ||
| } | ||
|
|
||
| let recordCount = () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change this to a normal function, seeing as that you are not overriding the variable anywhere. |
||
| fetch("http://localhost:2050/recordCount", { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add a |
||
| method: "GET", | ||
| headers: { "Content-Type": "application/json" }, | ||
| }) | ||
| .then((response) => response.text()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should check if |
||
| .then((data) => { | ||
| recordNumberTotal = JSON.parse(data); | ||
| }) | ||
| .catch((error) => { | ||
| console.log(error); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the |
||
| }; | ||
|
|
||
| let headingRowCreation = () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change this variable into a normal function, as you don't seem to be overriding the variable anywhere. |
||
| fetch("http://localhost:2050/columns", { | ||
| method: "GET", | ||
| headers: { "Content-Type": "application/json" }, | ||
| }) | ||
| .then((response) => response.text()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should check if |
||
| .then((data) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the |
||
| let headingDataList = JSON.parse(data); | ||
| let headings: string; | ||
|
|
||
| for (let i = 0; i < headingDataList.length; i++) { | ||
| headings = headingDataList[i]; | ||
| createHeadingGrid(headings); | ||
| } | ||
| resizeScreenData(); | ||
| }) | ||
| .catch((error) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the |
||
| console.log(error); | ||
| }); | ||
| }; | ||
|
|
||
| function dynamicGrid(columnData: any) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change the type for |
||
| // Creates the row that the info will display and adds it to the infoColumnsArea. | ||
| let infoDataRow = `<div id="info-row-${columnData[0]}" class="info-rows"></div>`; | ||
| 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 infoData = `<p class="info-row-data">${columnData[x]}</p>`; | ||
| finalInfoDataRow.innerHTML += infoData; | ||
| } | ||
| } | ||
|
|
||
| let resizeScreenData = () => { | ||
| let toNumber: number; | ||
| let selectionArea: any = document.querySelector("#record-navigation-container"); | ||
|
|
||
| if (selectionArea.contains(document.querySelector(".navigation-btns"))) { | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
|
|
||
| nextBtn.disabled = false; | ||
| previousBtn.disabled = false; | ||
|
|
||
| let finalRecord = recordNumberTotal - 1; | ||
|
|
||
| if (fromNumber + numberOfRows >= finalRecord) { | ||
| fromNumber = finalRecord - numberOfRows; | ||
| nextBtn.disabled = true; | ||
| previousBtn.disabled = false; | ||
| } else if (fromNumber <= 0) { | ||
| nextBtn.disabled = false; | ||
| previousBtn.disabled = true; | ||
| fromNumber = 0; | ||
| } | ||
|
|
||
| toNumber = fromNumber + numberOfRows; | ||
|
|
||
| getRecords(fromNumber, toNumber); | ||
| } | ||
| }; | ||
|
|
||
| function getRecords(fromNumber: number, toNumber: number) { | ||
| fetch(`http://localhost:2050/records?from=${fromNumber}&to=${toNumber}`, { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add a |
||
| method: "GET", | ||
| headers: { "Content-Type": "application/json" }, | ||
| }) | ||
| .then((response) => response.text()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should check if |
||
| .then((data) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a catch to log and handle errors.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the |
||
| let columnDataList = JSON.parse(data); | ||
| infoColumns.innerHTML = ""; | ||
| for (let i = 0; i < columnDataList.length; i++) { | ||
| dynamicGrid(columnDataList[i]); | ||
| } | ||
|
|
||
| let currentPage: any = document.querySelector(".current-page"); | ||
| currentPage.innerHTML = `${fromNumber} / ${toNumber}.`; | ||
| }) | ||
| .catch((error) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the |
||
| console.log(error); | ||
| }); | ||
| } | ||
|
|
||
| recordCount(); | ||
| resizeScreenData = debounce(resizeScreenData, 500); | ||
| window.addEventListener("resize", resizeScreenData); | ||
| createNavigation(); | ||
| headingRowCreation(); | ||
|
|
||
| let nextBtn: any = document.querySelector(".next-records-btn"); | ||
| let previousBtn: any = document.querySelector(".previous-records-btn"); | ||
| let firstPageBtn: any = document.querySelector(".first-page-btn"); | ||
| let lastPageBtn: any = document.querySelector(".last-page-btn"); | ||
|
|
||
| console.log(fromNumber); | ||
|
|
||
| let nextPage = () => { | ||
| console.log(fromNumber); | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| fromNumber = fromNumber + numberOfRows * count; | ||
| let toNumber = fromNumber + numberOfRows; | ||
|
|
||
| let finalRecord = recordNumberTotal - 1; | ||
|
|
||
| if (toNumber >= finalRecord) { | ||
| fromNumber = finalRecord - numberOfRows; | ||
| nextBtn.disabled = true; | ||
| previousBtn.disabled = false; | ||
| } | ||
|
|
||
| getRecords(fromNumber, toNumber); | ||
| count = 0; | ||
| }; | ||
|
|
||
| nextBtn.addEventListener("click", () => { | ||
| count++; | ||
| nextPage = debounce(nextPage, 500); | ||
| nextPage(); | ||
| }); | ||
|
|
||
| let previousPage = () => { | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| fromNumber = fromNumber - numberOfRows * count; | ||
| let toNumber = fromNumber + numberOfRows; | ||
|
|
||
| if (fromNumber <= 0) { | ||
| nextBtn.disabled = false; | ||
| previousBtn.disabled = true; | ||
| fromNumber = 0; | ||
| } | ||
|
|
||
| getRecords(fromNumber, toNumber); | ||
| count = 0; | ||
| }; | ||
|
|
||
| previousBtn.addEventListener("click", () => { | ||
| count++; | ||
| previousPage = debounce(previousPage, 500); | ||
| previousPage(); | ||
| }); | ||
|
|
||
| let firstPage = () => { | ||
| fromNumber = 0; | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| let toNumber = fromNumber + numberOfRows; | ||
| previousBtn.disabled = true; | ||
| nextBtn.disabled = false; | ||
|
|
||
| getRecords(fromNumber, toNumber); | ||
| }; | ||
|
|
||
| firstPageBtn.addEventListener("click", () => { | ||
| firstPage(); | ||
| }); | ||
|
|
||
| let lastPage = () => { | ||
| let finalRecord = recordNumberTotal - 1; | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| fromNumber = finalRecord - numberOfRows; | ||
| nextBtn.disabled = true; | ||
| previousBtn.disabled = false; | ||
|
|
||
| getRecords(fromNumber, finalRecord); | ||
| }; | ||
|
|
||
| lastPageBtn.addEventListener("click", () => { | ||
| lastPage(); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>JS Onboard Project</title> | ||
| <script type="text/javascript" charset="utf-8" src="third_party/jquery-2.0.3.min.js"></script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <p>Hello</p> | ||
| </body> | ||
|
|
||
| <head> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please convert this file back to using tabs. |
||
| <title>JS Onboard Project</title> | ||
| <script type="text/javascript" charset="utf-8" src="third_party/jquery-2.0.3.min.js"></script> | ||
| <link rel="stylesheet" href="./style.css" /> | ||
| <script src="./app.js" defer></script> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should not really be using |
||
| </head> | ||
| <body> | ||
| <div id="record-navigation-container"></div> | ||
| <div id="column-headings-container"></div> | ||
| <div id="info-columns-container"></div> | ||
| </body> | ||
| </html> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ import ( | |
| "strconv" | ||
| "time" | ||
| ) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file should not show up in this PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bump |
||
| const recordCount = 1000000 | ||
| const columnCount = 11 | ||
| const delayResponse = 500 * time.Millisecond | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way your code is written these lines will execute before those elements actually exist on the webpage. So they can definitely not be here. You should only try and get things from the webpage after it has been rendered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also change the
anyto the actual type.