-
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 14 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,233 @@ | ||
| let headingColumns: any = document.querySelector("#column-headings-container"); //Headings; | ||
| let infoColumns: any = document.querySelector("#info-columns-container"); //Information; | ||
| let debounce = (func: any, delay: number) => { | ||
| let timer: number; | ||
| return function () { | ||
| clearTimeout(timer); | ||
|
|
||
| timer = setTimeout(() => { | ||
| func(); | ||
| }, delay); | ||
| }; | ||
| }; | ||
|
|
||
| let tryCatch = (func: any) => { | ||
| try { | ||
| func; | ||
| } catch (error) { | ||
| console.log(error); | ||
| } | ||
| }; | ||
|
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. Let's not do it this way but rather on the Promise. |
||
|
|
||
| function createNavigation() { | ||
| let recordNav: any = document.querySelector("#record-navigation-container"); //Navigation area; | ||
| recordNav.innerHTML = ` | ||
| <div class="navigation-btns"> | ||
| <button class="first-page-btn">First Page</button> | ||
| <button class="previous-records-btn">Previous</button> | ||
| <button class="next-records-btn">Next</button> | ||
| <button 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 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; | ||
| } | ||
|
|
||
| function 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 specify the return type. |
||
| 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); | ||
| } | ||
| dataRowCreation(0); | ||
| }); | ||
| createNavigation(); | ||
| } | ||
|
|
||
| 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 nextPrevious = (fromNumber: number) => { | ||
|
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. Probably give this function a more descriptive name |
||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| let count: number = 0; | ||
|
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. Remove count. No need to multiply. The next function is supposed to be executed every time it passes debouncing. |
||
|
|
||
| let nextBtn: any = document.querySelector(".next-records-btn"); | ||
| let nextPage = () => { | ||
| fromNumber = fromNumber + numberOfRows * count; | ||
| tryCatch(dataRowCreation(fromNumber)); | ||
|
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. Remove tryCatch |
||
| count = 0; | ||
| }; | ||
|
|
||
| nextPage = debounce(nextPage, 500); | ||
| nextBtn.addEventListener("click", () => { | ||
| count++; | ||
| nextPage(); | ||
| }); | ||
|
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. Pass in directly |
||
|
|
||
| let previousBtn: any = document.querySelector(".previous-records-btn"); | ||
| let previousPage = () => { | ||
| fromNumber = fromNumber - numberOfRows * count; | ||
| tryCatch(dataRowCreation(fromNumber)); | ||
|
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. Remove tryCatch |
||
| count = 0; | ||
| }; | ||
|
|
||
| previousPage = debounce(previousPage, 500); | ||
| previousBtn.addEventListener("click", () => { | ||
| count++; | ||
| previousPage(); | ||
| }); | ||
|
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. Pass in directly. |
||
|
|
||
| if (fromNumber === 0) { | ||
| previousBtn.disabled = true; | ||
| } else { | ||
| previousBtn.disabled = false; | ||
| } | ||
|
|
||
| let firstBtn: any = document.querySelector(".first-page-btn"); | ||
| let firstPage = () => { | ||
| fromNumber = 0; | ||
| tryCatch(dataRowCreation(fromNumber)); | ||
| }; | ||
|
|
||
| firstPage = debounce(firstPage, 500); | ||
| firstBtn.addEventListener("click", () => { | ||
| firstPage(); | ||
| }); | ||
|
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 can pass debounce(firstPage, 500); in directly in this case. |
||
|
|
||
| let lastBtn: any = document.querySelector(".last-page-btn"); | ||
| let lastPage = () => { | ||
| let toNumber = 999999; | ||
| fromNumber = toNumber - numberOfRows; | ||
| tryCatch(dataRowCreation(fromNumber)); | ||
| }; | ||
|
|
||
| lastPage = debounce(lastPage, 500); | ||
| lastBtn.addEventListener("click", () => { | ||
| lastPage(); | ||
| }); | ||
|
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 can pass debounce(lastPage, 500); in directly in this case. |
||
| }; | ||
|
|
||
| function dataRowCreation(fromNumber: number) { | ||
| let toNumber: number; | ||
|
|
||
| let resizeScreen = () => { | ||
| let nextBtn: any = document.querySelector(".next-records-btn"); | ||
| nextBtn.disabled = false; | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| toNumber = fromNumber + numberOfRows; | ||
|
|
||
| if (toNumber >= 999999) { | ||
| let nextBtn: any = document.querySelector(".next-records-btn"); | ||
|
|
||
| toNumber = 999999; | ||
| fromNumber = toNumber - numberOfRows; | ||
|
|
||
| nextBtn.disabled = true; | ||
| } | ||
|
|
||
| fetch("http://localhost:2050/records?from=" + fromNumber + "&to=" + toNumber, { | ||
| method: "GET", | ||
| headers: { "Content-Type": "application/json" }, | ||
| }) | ||
| .then((response) => response.text()) | ||
| .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. Implement the catch on the Promise. .then().catch( () => {}); |
||
| 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 = ""; | ||
| currentPage.innerHTML = currentPage.innerHTML = fromNumber + " / " + toNumber + " " + (Number(numberOfRows) + 1) + " records only."; | ||
|
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. No need to clear it. If you set it a value, the previous values are overwritten. |
||
| }; | ||
|
|
||
| resizeScreen = debounce(resizeScreen, 500); | ||
| window.addEventListener("resize", resizeScreen); | ||
| tryCatch(resizeScreen()); | ||
| tryCatch(nextPrevious(fromNumber)); | ||
| } | ||
|
|
||
| headingRowCreation(); | ||
|
|
||
| function recordSelection() { | ||
| let selectionArea: any = document.querySelector("#record-navigation-container"); | ||
| let SingleRecordSelection = ` | ||
|
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 make it lowerCamelCase |
||
| <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" | ||
| 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 = ""; | ||
| selectionArea.innerHTML = SingleRecordSelection; | ||
|
|
||
| let returnBtn: any = document.querySelector("#return-btn"); | ||
|
|
||
| returnBtn.addEventListener("click", () => { | ||
| headingColumns.innerHTML = ""; | ||
| infoColumns.innerHTML = ""; | ||
| headingRowCreation(); | ||
| createNavigation(); | ||
| }); | ||
|
|
||
| let getSingleRecord: any = document.querySelector("#get-record-btn"); | ||
|
|
||
| getSingleRecord.addEventListener("click", () => { | ||
| let recordIdValue: any = document.querySelector("#record-id.navigation-input"); | ||
| let fromNumber: number = Number(recordIdValue.value); | ||
| let check = ["undefined", "string", ""]; | ||
|
|
||
| if (check.includes(typeof fromNumber) || fromNumber < 0) { | ||
| alert("Does not exists"); | ||
| recordIdValue.value = "0"; | ||
| } else if (typeof fromNumber === "number" && fromNumber >= 0) { | ||
| dataRowCreation(fromNumber); | ||
| } else { | ||
| alert("Error"); | ||
| } | ||
| }); | ||
| } | ||
| 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 |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ import ( | |
| ) | ||
|
|
||
|
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 columnCount = 11 | ||
|
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. Remove the whitespace |
||
| const delayResponse = 500 * time.Millisecond | ||
|
|
||
| var columns = [columnCount]string{"ID", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"} | ||
|
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. There should be any changes to this file. Looks like you accidentally removed the new lines. Make sure this file doesn't even popup on Files changed on GitHub. |
||
|
|
||
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.
Add whitespace between // and comment. Can probably remove the semi-colon as well.