-
Notifications
You must be signed in to change notification settings - Fork 35
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
Open
AshtonMar
wants to merge
30
commits into
IMQS:master
Choose a base branch
from
AshtonMar:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ashton Martin #45
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
3d76748
first commit
AshtonMar fc17d76
multiple-singular-select-functionality
AshtonMar f1e2d5e
3rd commit
AshtonMar abf2e25
first commit
AshtonMar 236ae3e
Todays changes
AshtonMar 78d3646
Todays changes
AshtonMar 20f8768
Todays changes
AshtonMar 25982e1
Todays changes
AshtonMar d5a0150
Coding changes, screen size checks, changed how single records work.
AshtonMar 27e37ab
Coding changes, screen size checks, changed how single records work.
AshtonMar 8e1c83c
Coding changes
AshtonMar 28c0127
Coding changes
AshtonMar c0cc0dd
Commit
AshtonMar 0a5e24a
try catch
AshtonMar 22ac146
Recent Changes
AshtonMar d868815
Recent fixes
AshtonMar a25fa90
Whitespace server/main.go
AshtonMar ed88ede
Recent Fixes
AshtonMar fdc8503
Recent Commit
AshtonMar 891521b
main.go spacing
AshtonMar 9c4f823
first commit
AshtonMar 2240555
test
AshtonMar ca85f76
first commit
AshtonMar 9c05769
Latest Changes
AshtonMar e991ebf
Latest Changes
AshtonMar b085bdd
Latest Changes
AshtonMar 921241f
adding gitignore file
AshtonMar a58c56d
Spaces to tabs
AshtonMar 19aeeb5
Recent file added
AshtonMar 78f5400
Recent
AshtonMar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /node_modules | ||
| app.js | ||
| app.js.map | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,333 @@ | ||
| let fromNumber = 0; | ||
| let recordNumberTotal: number; | ||
| let count = 0; | ||
| let timeout = 0; | ||
|
|
||
| function checkResponseError(response: Response) { | ||
| if (!response.ok) { | ||
| throw Error(response.statusText); | ||
| } | ||
| return response; | ||
| } | ||
|
|
||
| function debounce(func: () => void, delay: number) { | ||
| return function () { | ||
| clearTimeout(timeout); | ||
|
|
||
| timeout = setTimeout(() => { | ||
| func(); | ||
| }, delay); | ||
| }; | ||
| } | ||
|
|
||
| function createNavigation() { | ||
| let recordNav: HTMLElement | null = document.getElementById("record-navigation-container"); // Navigation area | ||
| if (recordNav) { | ||
| recordNav.innerHTML = ` | ||
| <div id="navigation-btns"> | ||
| <button value="first" id="first-page-btn">First Page</button> | ||
| <button value="previous" id="previous-records-btn">Previous</button> | ||
| <button value="next" id="next-records-btn">Next</button> | ||
| <button value="last" id="last-page-btn">Last Page</button> | ||
| <button id="confirmation-btn">Get Record</button> | ||
| </div> | ||
| <div class="current-page-container"> | ||
| <p id="current-page"></p> | ||
| </div> | ||
| `; | ||
| } | ||
| } | ||
|
|
||
| function getRecords(fromNumber: number, toNumber: number): Promise<void> { | ||
| return fetch(`http://localhost:2050/records?from=${fromNumber}&to=${toNumber}`, { | ||
| method: "GET", | ||
| headers: { "Content-Type": "application/json" }, | ||
| }) | ||
| .then(checkResponseError) | ||
| .then((response: Response) => response.json()) | ||
| .then((data: string[]) => { | ||
|
|
||
| let infoColumns: HTMLElement | null = document.getElementById("info-columns-container"); // Information | ||
| let currentPage: HTMLElement | null = document.getElementById("current-page"); | ||
|
|
||
| if (infoColumns) { | ||
| infoColumns.innerHTML = ""; | ||
|
|
||
| for (let i of data) { | ||
| dynamicGrid(i); | ||
| } | ||
| } | ||
|
|
||
| if (currentPage) { | ||
| currentPage.innerHTML = `${fromNumber} / ${toNumber}.`; | ||
| } | ||
| }) | ||
| .catch((error: Error) => { | ||
| console.log(error); | ||
| }); | ||
| } | ||
|
|
||
| function recordSelection() { | ||
| let recordNav: HTMLElement | null = document.getElementById("record-navigation-container"); // Navigation area | ||
| if (!recordNav) { | ||
| alert("The navigation is not working correctly refresh the page"); | ||
| return; | ||
|
|
||
| } | ||
|
|
||
| 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" 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>`; | ||
|
|
||
| recordNav.innerHTML = singleRecordSelection; | ||
|
|
||
| let returnBtn: HTMLElement | null = document.getElementById("return-btn"); | ||
| let recordIdInput = <HTMLInputElement | null>document.getElementById("record-id"); | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| let getSingleRecord: HTMLElement | null = document.getElementById("get-record-btn"); | ||
|
|
||
| if (returnBtn) { | ||
| // Resets to the first page | ||
| returnBtn.addEventListener("click", () => { | ||
| createNavigation(); | ||
| resizeScreenData(); | ||
| fromNumber = 0; | ||
| getRecords(fromNumber, fromNumber + numberOfRows); | ||
| new PageNavigation(); | ||
| }); | ||
| } | ||
|
|
||
| if (getSingleRecord) { | ||
| getSingleRecord.addEventListener("click", () => { | ||
| if (recordIdInput) { | ||
|
|
||
| let recordIdValue = recordIdInput.value; | ||
| fromNumber = Number(recordIdValue); | ||
|
|
||
| let toNumber = fromNumber + numberOfRows; | ||
| let finalRecord = recordNumberTotal - 1; | ||
|
|
||
| if (toNumber > finalRecord) { | ||
| toNumber = finalRecord; | ||
| fromNumber = toNumber - numberOfRows; | ||
| } | ||
|
|
||
| let check = ["undefined", "string", ""]; | ||
|
|
||
| if (check.includes(typeof fromNumber) || fromNumber < 0) { | ||
| alert("Does not exists"); | ||
| recordIdValue = "0"; | ||
| } else if (typeof fromNumber === "number" && fromNumber >= 0) { | ||
| getRecords(fromNumber, toNumber); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| function createHeadingGrid(headings: string) { | ||
| let headingColumns: HTMLElement | null = document.getElementById("column-headings-container"); // Headings | ||
| let headingsData = `<h1 class="column-heading">${headings}</h1>`; | ||
|
|
||
| if (headingColumns) { | ||
| headingColumns.innerHTML += headingsData; | ||
| } | ||
| } | ||
|
|
||
| function recordCount(): Promise<void> { | ||
| return fetch("http://localhost:2050/recordCount", { | ||
| method: "GET", | ||
| headers: { "Content-Type": "application/json" }, | ||
| }) | ||
| .then(checkResponseError) | ||
| .then((response: Response) => response.json()) | ||
| .then((data: number) => { | ||
| recordNumberTotal = data; | ||
| }) | ||
| .catch((error: Error) => { | ||
| console.log(error); | ||
| }); | ||
| } | ||
|
|
||
| function headingRowCreation(): Promise<void> { | ||
| return fetch("http://localhost:2050/columns", { | ||
| method: "GET", | ||
| headers: { "Content-Type": "application/json" }, | ||
| }) | ||
| .then(checkResponseError) | ||
| .then((response: Response) => response.json()) | ||
| .then((data: string[]) => { | ||
| for (let i of data) { | ||
| createHeadingGrid(i); | ||
| } | ||
| resizeScreenData(); | ||
| }) | ||
| .catch((error: Error) => { | ||
| console.log(error); | ||
| }); | ||
| } | ||
|
|
||
| function dynamicGrid(columnData: string) { | ||
|
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. Not sure how |
||
| let infoColumns: HTMLElement | null = document.getElementById("info-columns-container"); // Information | ||
| // 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>`; | ||
|
|
||
| if (infoColumns) { | ||
| infoColumns.innerHTML += infoDataRow; | ||
| // Gets the created rows. | ||
| let finalInfoDataRow = document.getElementById("info-row-" + columnData[0]); | ||
| if (finalInfoDataRow) { | ||
| // Loops through | ||
| for (let x of columnData) { | ||
| let infoData = `<p class="info-row-data">${x}</p>`; | ||
| finalInfoDataRow.innerHTML += infoData; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function resizeScreenData() { | ||
| let toNumber: number; | ||
| let recordNav: HTMLElement | null = document.getElementById("record-navigation-container"); | ||
| let nextBtn = <HTMLButtonElement | null>document.getElementById("next-records-btn"); | ||
| let previousBtn = <HTMLButtonElement | null>document.getElementById("previous-records-btn"); | ||
| let navBtns = document.getElementById("navigation-btns"); | ||
| if (recordNav) { | ||
| if (recordNav.contains(navBtns as HTMLDivElement) && nextBtn && previousBtn) { | ||
| 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) { | ||
| fromNumber = 0; | ||
|
|
||
| nextBtn.disabled = false; | ||
| previousBtn.disabled = true; | ||
| } | ||
|
|
||
| toNumber = fromNumber + numberOfRows; | ||
|
|
||
| getRecords(fromNumber, toNumber); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class PageNavigation { | ||
| nextBtn: HTMLButtonElement | null; | ||
| previousBtn: HTMLButtonElement | null; | ||
| firstPageBtn: HTMLButtonElement | null; | ||
| lastPageBtn: HTMLButtonElement | null; | ||
| confirmationBtn: HTMLButtonElement | null; | ||
|
|
||
| constructor() { | ||
|
|
||
| function navigationDebounce(func: (argOne: number, argTwo: number) => void, delay: number) { | ||
| return function (argOne: number, argTwo: number) { | ||
| clearTimeout(timeout); | ||
|
|
||
| timeout = setTimeout(() => { | ||
| func(argOne, argTwo); | ||
| }, delay); | ||
| }; | ||
| } | ||
|
|
||
| this.nextBtn = <HTMLButtonElement | null>document.getElementById("next-records-btn"); | ||
| this.previousBtn = <HTMLButtonElement | null>document.getElementById("previous-records-btn"); | ||
| this.firstPageBtn = <HTMLButtonElement | null>document.getElementById("first-page-btn"); | ||
| this.lastPageBtn = <HTMLButtonElement | null>document.getElementById("last-page-btn"); | ||
| this.confirmationBtn = <HTMLButtonElement | null>document.getElementById("confirmation-btn"); | ||
|
|
||
| if (this.confirmationBtn) { | ||
| this.confirmationBtn.addEventListener("click", recordSelection); | ||
| } | ||
|
|
||
| if (this.nextBtn && this.previousBtn && this.firstPageBtn && this.lastPageBtn) { | ||
| let nextPage = () => { | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| fromNumber = fromNumber + numberOfRows; | ||
| let toNumber = fromNumber + numberOfRows; | ||
|
|
||
| let finalRecord = recordNumberTotal - 1; | ||
| this.previousBtn!.disabled = false; | ||
|
|
||
| if (toNumber >= finalRecord) { | ||
| this.nextBtn!.disabled = true; | ||
| fromNumber = finalRecord - numberOfRows; | ||
| } | ||
|
|
||
| console.log(fromNumber, toNumber); | ||
|
|
||
| navigationDebounce(getRecords, 50)(fromNumber, toNumber) | ||
| }; | ||
|
|
||
|
|
||
| this.nextBtn.addEventListener("click", nextPage); | ||
|
|
||
| let previousPage = () => { | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| fromNumber = fromNumber - numberOfRows; | ||
| let toNumber = fromNumber + numberOfRows; | ||
|
|
||
| this.nextBtn!.disabled = false; | ||
|
|
||
| if (fromNumber <= 0) { | ||
| this.previousBtn!.disabled = true; | ||
| fromNumber = 0; | ||
| } | ||
|
|
||
| navigationDebounce(getRecords, 50)(fromNumber, toNumber) | ||
| }; | ||
|
|
||
| this.previousBtn.addEventListener("click", previousPage); | ||
|
|
||
| let firstPage = () => { | ||
| fromNumber = 0; | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| let toNumber = fromNumber + numberOfRows; | ||
|
|
||
| this.nextBtn!.disabled = false; | ||
| this.previousBtn!.disabled = true; | ||
|
|
||
| getRecords(fromNumber, toNumber); | ||
| }; | ||
|
|
||
| this.firstPageBtn.addEventListener("click", firstPage); | ||
|
|
||
| let lastPage = () => { | ||
| let finalRecord = recordNumberTotal - 1; | ||
| let numberOfRows = Math.floor(window.innerHeight / 50); | ||
| fromNumber = finalRecord - numberOfRows; | ||
|
|
||
| this.nextBtn!.disabled = true; | ||
| this.previousBtn!.disabled = false; | ||
|
|
||
| getRecords(fromNumber, finalRecord); | ||
| }; | ||
|
|
||
| this.lastPageBtn.addEventListener("click", lastPage); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| window.onload = () => { | ||
| createNavigation(); | ||
| headingRowCreation(); | ||
| fromNumber = 0; | ||
| new PageNavigation(); | ||
| window.addEventListener("resize", debounce(resizeScreenData, 500)); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| <!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> | ||
| <link rel="stylesheet" href="./style.css" /> | ||
| <script src="./app.js"></script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <p>Hello</p> | ||
| <div id="record-navigation-container"></div> | ||
| <div id="column-headings-container"></div> | ||
| <div id="info-columns-container"></div> | ||
| </body> | ||
|
|
||
| </html> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please specify a return type.
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.
Bump