-
Notifications
You must be signed in to change notification settings - Fork 35
updated onboarding project #40
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?
Changes from all commits
62eee76
fd00445
4731cd9
c7cac80
eeb8e54
c652401
031b614
027b329
909ce8f
1de2f8d
fa95818
0e43a23
b2e0238
32a64cc
4f10567
97d4868
98cbe57
2672789
5aaf23d
89e549c
ea585f3
879f4ae
e8f6188
1baa7d2
b50d91d
a1a101a
17a729f
980ab3f
aa08fe6
07be5f0
f02c455
53b603d
39faae7
6082bc3
88d921b
a329804
7939c12
7591502
bcc9696
f7fe9a7
44aad0a
5ee895e
14fbe67
6b25495
ae33eae
19d0292
6aa32a9
5efc63c
8aab829
b25c082
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /node_modules | ||
| app.js | ||
| app.js.map | ||
| dist.min.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "type": "pwa-chrome", | ||
| "request": "launch", | ||
| "name": "Launch Chrome against localhost", | ||
| "url": "http://localhost:8080", | ||
| "webRoot": "${workspaceFolder}" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "compile-hero.disable-compile-files-on-did-save-code": false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| import { data } from "jquery"; | ||
|
|
||
| namespace onboardproject { | ||
|
|
||
| module onboardprojects { | ||
|
|
||
| // Load Variable declarations | ||
| let Load = 50; | ||
|
|
||
| // Previous Variable declarations | ||
| let previous: number; | ||
|
|
||
| // Previous Process Variable declarations | ||
| let previousprocess: number; | ||
|
|
||
| // Trigger async function | ||
| async function getRecordCountCall(): Promise<void> { | ||
| const response = await fetch('http://localhost:2050/recordCount'); | ||
| if (!response.ok) { | ||
| const message = `An error has occured: ${response.status}`; | ||
| throw new Error(message); | ||
| } | ||
| } | ||
|
|
||
| // Trigger async function | ||
| async function getColumnNamesCall(): Promise<void> { | ||
| const response = await fetch('http://localhost:2050/columns'); | ||
| if (!response.ok) { | ||
| const message = `An error has occured: ${response.status}`; | ||
| throw new Error(message); | ||
| } | ||
| } | ||
|
|
||
| // Trigger async function | ||
| async function getRecordsCall(fromID: number, toID: number): Promise<number[]> { | ||
| const response = await fetch(`http://localhost:2050/records?from=${(fromID)}&to=${(toID)}`); | ||
| if (!response.ok) { | ||
| const message = `An error has occured: ${response.status}`; | ||
| throw new Error(message); | ||
| } | ||
| return response.json(); | ||
| } | ||
|
|
||
| // Region Data Loading methods | ||
| async function LoadRecordsData(fromID: number, toID: number): Promise<void> { | ||
| const recordsvalue = await getRecordsCall(fromID, toID); | ||
| let DisplayContent = ''; | ||
| for (const records of recordsvalue) { | ||
| DisplayContent += `<tr id="table-row-${records}">`; | ||
| for (const column of record) { | ||
| DisplayContent += `<td align="center">${column}</td>`; | ||
| } | ||
| DisplayContent += '</tr>'; | ||
| $("#wrapper-table-content-body").empty(); | ||
| $("#wrapper-table-content-body").append(DisplayContent); | ||
| } | ||
| } | ||
|
|
||
| // Load Records Function | ||
| function RecordsFromCursor(cursor: number[]): Promise<void> { | ||
| cursor = cursor.sort((a, b) => { return a - b }); | ||
| } | ||
|
|
||
| // Handlers | ||
| async function LoadPageContent(fromID: number, toID: number): Promise<void> { | ||
| let DisplayContent = ""; | ||
| const columns = await getColumnNamesCall(); | ||
| for (const column of columns) { | ||
| DisplayContent += `<th align="center">${column}</th>`; | ||
| $("#wrapper-table-header-row").empty(); | ||
| $("#wrapper-table-header-row").append(DisplayContent); | ||
| } | ||
| } | ||
|
|
||
| // Conversion Function | ||
| function ConvertNumber(input: string | number, parseAsInt: boolean = true): number { | ||
| switch (typeof input) { | ||
| case ('string'): | ||
| if (parseAsInt == true) { | ||
| return parseInt(input as string); | ||
| } | ||
| return parseFloat(input as string); | ||
| case ("number"): | ||
| return input as number; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| // Height Diplay Function | ||
| function calculateToId(fromId: number): number { | ||
| const possibleRecordsData = Math.max((window.innerHeight - ($("#form-content").innerHeight() as number)) / 37); | ||
| let recordDisplayset = 0; | ||
| return recordDisplayset; | ||
| } | ||
|
|
||
| // Next_Page_Resize Function | ||
| function nextPageResize(previous: number[]): number { | ||
| const fromID = ConvertNumber(previous.sort((a, b) => { return a - b })[0]); | ||
| const toID = ConvertNumber(previous.sort((a, b) => { return a - b })[1]); | ||
| const documentHeight = Math.max((window.innerHeight - ($(`#table-row-${fromID}`).height() as number))); | ||
| for (let i = fromID; i <= toID; i++) { | ||
| const elementHeightOffset = ($(`#table-row-${i}`).offset() as JQueryCoordinates).top; | ||
| if (elementHeightOffset < documentHeight) continue; | ||
| return i; | ||
| } | ||
| return toID; | ||
| } | ||
|
|
||
| // Onload Function | ||
| window.onload = async () => { | ||
|
|
||
| // Previous_Page_Resize Function | ||
| function previousPageResize(previous: number[]): number[] { | ||
| let nextPage = nextPageResize([]); | ||
| const toId = calculateToId(previous[0] - nextPage); | ||
| return [previous[0] - (nextPage - previous[0]), toId]; | ||
| } | ||
|
|
||
| // On Resize_Function | ||
| window.onresize = () => { | ||
|
|
||
| try { | ||
| const nextToId = calculateToId(previous); | ||
| clearTimeout(Load); | ||
| Load = setTimeout(async () => { | ||
| const recordCount = await getRecordCountCall(); | ||
| if (nextToId >= recordCount - 1) { | ||
| const fromId = recordCount - 1 - (calculateToId(previous) - previous); | ||
| const toId = recordCount - 1; | ||
| //previous = await LoadRecordsData(fromId, toId); | ||
| } else { | ||
| //previous = await LoadRecordsData(previous[0], nextToId); | ||
| } | ||
| }, 250); | ||
| } catch (error) { | ||
| // throw new Error("Error" + error); | ||
| } | ||
| } | ||
|
|
||
| //Loading Content Function | ||
| //previous = await LoadPageContent(0, calculateToId(0)); | ||
|
|
||
| // Click function for previewing page | ||
| $("#previous").click(async () => { | ||
| const CountData = await getRecordCountCall(); | ||
| previous = previousPageResize(previous); | ||
| let fromId = previous >= 0 ? previous : 0; | ||
| const possibleStep = calculateToId(fromId) - fromId; | ||
| let toId = (previous >= 0 ? previous : possibleStep); | ||
| fromId = fromId == CountData - 1 ? fromId - possibleStep : fromId; | ||
| toId = toId <= CountData - 1 ? toId : CountData - 1; | ||
| //previous = await LoadRecordsData(fromId, toId); | ||
| }); | ||
|
|
||
| // Click function for Skipping to next page | ||
| $("#next").click(async () => { | ||
| try { | ||
| const recordCount = await getRecordCountCall(); | ||
| const fromId = nextPageResize(previous); | ||
| const possibleStep = calculateToId(fromId) - fromId; | ||
| if (fromId <= recordCount - possibleStep - 1) { | ||
| const toId = fromId + possibleStep <= recordCount - 1 ? fromId + possibleStep : recordCount - 1; | ||
| // previous = await LoadRecordsData(fromId, toId); | ||
| } else if (fromId <= recordCount - 1) { | ||
| //previous = await LoadRecordsData(recordCount - 1 - (calculateToId(fromId) - fromId), recordCount - 1); | ||
| } else { | ||
| throw new Error("Error 404"); | ||
| } | ||
| } catch (error) { | ||
| } | ||
| }); | ||
|
|
||
| $("#go-button").click(async () => { | ||
| const recordCount = await getRecordCountCall(); | ||
|
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 are allowed to skip this step. For this project the record count will not change after the initial call. |
||
| const fromId = ConvertNumber($("#index").val() as string, false); | ||
| const possibleStep = calculateToId(fromId) - fromId; | ||
| if (fromId < 0) { | ||
| alert('only insert Id greater than or equal to 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. add a return here so we can remove the next "else" below. This is more readable and reduces excessive indentation in cases where larger nested "if else" statements exist.
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. The comment on this line is still relevant. |
||
| } | ||
| else { | ||
| if (Math.floor(fromId).toString() == fromId.toString() === true) { | ||
| if (fromId > recordCount - possibleStep) { | ||
| alert(`You may not insert a desired Id greater than ${recordCount - possibleStep}`); | ||
| } else { | ||
| let toId = (fromId) + possibleStep < recordCount ? (fromId) + possibleStep : recordCount - 1; | ||
|
|
||
| // previous = await LoadRecordsData(fromId, toId); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,27 @@ | ||
| <!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> | ||
| <script src="app.js"> </script> | ||
| <link rel="stylesheet" type="text/css" href="/style.css"> | ||
| </head> | ||
|
|
||
| <body> | ||
| <p>Hello</p> | ||
| <body id="body"> | ||
| <div id="form-content"> | ||
| Go To Start Index:<input type="number" id="index" value="0" min="0"> | ||
| <button id="go-button" type="button">GOT TO INDEX PAGE </button> | ||
| <button id="previous" type="button">Go to Previous </button> | ||
| <button id="next" type="button">Go to Next </button> | ||
| </div> | ||
| <table id='wrapper-table'> | ||
| <thead id="wrapper-table-header-row"> | ||
| </thead> | ||
| <tbody id="wrapper-table-content-body"> | ||
| </tbody> | ||
| </table> | ||
| <div id="table-arbitrary-footer"></div> | ||
| </body> | ||
|
|
||
| </html> | ||
|
|
Some generated files are not rendered by default. Learn more about how customized files appear 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.
You are allowed to skip this step. For this project the record count will not change after the initial call.