This is a JavaScript project for all new developers to complete before venturing into our web frontend codebase.
Once you complete this project, and have been through code review, you will have a much better understanding of JavaScript and it's superset, TypeScript, that we use for development.
- HTML
- CSS
- JavaScript
- TypeScript
- Node Package Manager (npm)
- JQuery
You task is to build a grid/table in TypeScript that fetches data from a server and displays it. Here are the requirements:
- The grid should cover the entire screen. The browser scrollbar should not appear.
- The columns widths should be distributed evenly.
- Display column headings based on the data you get back from the web service.
- The grid should have controls to navigate through data. You can choose a suitable way of doing this.
- Display the first page of data when you open up page for first time.
- Don't use any third-party libraries other than JQuery (already included in
third_party
directory).
The web service you will retrieve data from is a little Golang REST service that is packaged with this repository. It runs on port 2050. Here are the relevant API calls:
-
Get total number of records
Path:HTTP GET /recordCount
Response: Integer number in body of response
Example response:
350
-
Get column names
Path:HTTP GET /columns
Response: JSON in body of response
Example response:
[ "ID", "City", "Population" ]
-
Get records
Path:HTTP GET /records?from={fromID}&to={toID}
Response: JSON in body of response
The order of entries in a record corresponds to the order of the columns returned by the/columns
API
Thefrom
andto
parameters correspond to the record index which run from0
torecord count - 1
Example response:
[ [0, "Cape Town", 3500000], [1, "New York", 8500000], [2, "Johannesburg", 4500000] ]
Once you are done and happy with your solution, submit your code for code review by creating a pull request in GITHUB. The code review will take the following into account:
- Was the brief correctly followed, does the grid work as expected
- Is the code style according to our JavaScript Style Guide
- User-centric thinking - is the grid easy to use
- Suitable comments
- Performance considerations
- Aesthetics
- You need to have set up your development environment as described here.
- We suggest using VSCode, but you can use your IDE of choice.
These steps include just enough detail to guide you. Each step will require some additional research on your part:
- Fork this GIT repository under your own GIT account
- Start up the backend server:
- Open console and change directory to
server
directory - Run
go run main.go
- Open up your browser and point it to http://localhost:2050. You should see "Hello"
- Open console and change directory to
- Create the frontend project:
- Open another console in the project root directory
- Run
npm init
to initialise the JavaScript project. You can just use the default options. - Install the TypeScript npm package.
- Install TypeScript type definitions for JQuery.
- Create an
app.ts
file in the root directory and add the following code to it:
window.onload = () => { $("body").text("Hello world"); }
- Add a npm script called "build" to
package.json
that does the TypeScript build (using thetsconfig.json
included in the project). - Run
npm run build
- You will see a new file
app.js
in the project root. Add an entry for this script inindex.html
. - Refresh http://localhost:2050. You should see "Hello world"
- Get coding!