Skip to content

Commit

Permalink
Merge pull request #16 from hotungkhanh/develop
Browse files Browse the repository at this point in the history
Frontend succesfully deployed
  • Loading branch information
hotungkhanh authored Sep 22, 2024
2 parents bee7255 + 0defde9 commit 20b2791
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 18 deletions.
49 changes: 44 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,55 @@ name: Deploy
on:
push:
branches:
- deploy
- deploy-playground

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js for Frontend
uses: actions/setup-node@v2
with:
node-version: '20.17.0' # Specify your Node.js version

- name: Install Frontend Dependencies
run: |
cd frontend
npm install
- name: Build Frontend
run: |
cd frontend
npm run build # Adjust if necessary
# - name: Set up Java for Backend
# uses: actions/setup-java@v2
# with:
# java-version: '22.0.2' # Specify your Java version

# - name: Build Backend
# run: |
# cd backend
# mvn package # Use ./gradlew build for Gradle

deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: akhileshns/[email protected] # This is the action
- uses: akhileshns/[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: jetedge-test
heroku_email: [email protected]
appdir: "frontend"
heroku_app_name: ${{secrets.HEROKU_FRONTEND_APP_NAME}}
heroku_email: ${{secrets.HEROKU_EMAIL}}
appdir: "frontend"

# - uses: akhileshns/[email protected]
# with:
# heroku_api_key: ${{secrets.HEROKU_API_KEY}}
# heroku_app_name: ${{secrets.HEROKU_BACKEND_APP_NAME}}
# heroku_email: ${{secrets.HEROKU_EMAIL}}
# appdir: "backend"
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
.env/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# env variables
.env
6 changes: 3 additions & 3 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/src/components/Spreadsheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function Spreadsheet({ headers, storageKey, ...other }: Spreadshe
const options: jspreadsheet.JSpreadsheetOptions = {
columns: columns,
data: [[]],
minDimensions: [headers.length, 10],
minDimensions: [headers.length, 1],
// minSpareRows: 1,
allowManualInsertColumn: false,
allowInsertColumn: false,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/spreadsheets/Unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function Unit() {
<Spreadsheet
headers={["Unit Code ", "Duration (Lecture)", "Duration (Tutorial)", "Duration (Lab)"]}
storageKey={DB_UNITS}
// columns={[{readOnly: true}]}
columns={[{readOnly: true}]}
/>
</>
);
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/scripts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ export async function fetchTimetableSolution(problem: TimetableProblem): Promise
});

if (!response.ok) {
if (response.status === 500) {
alert(response.statusText + " " + response.status + ": server was not able to solve the problem. Please check for missing input (i.e. make sure there are at least 1 available room and no rooms with duplicate ID).");
}
throw new Error(`HTTP error! Status: ${response.status} ${response.statusText}`);
}

const solution: TimetableSolution = await response.json();
console.log(solution);
return solution;
}
catch (error) {
Expand Down
20 changes: 15 additions & 5 deletions frontend/src/scripts/handleInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { CellValue } from 'jspreadsheet-ce';
import { TimetableProblem, Unit, Room } from './api';
import { DB_UNITS, storeSpreadsheetData } from './persistence';

/*
* Return true if file is an Excel file
*/
function isExcelFile(file: File) {
const fileExtension = file.name.split('.').pop();
if (fileExtension === undefined || !['xlsx', 'xls'].includes(fileExtension)) {
Expand All @@ -12,6 +15,9 @@ function isExcelFile(file: File) {
return true;
}

/*
* Return true if enrolment data header file matches expected format
*/
function validateEnrolmentHeader(inputHeader: Row) {
const header = ['StudentID', 'Student Name', 'Personal Email', 'University Email',
'Student Type', 'Offer Type', 'Course Name', 'Campus', 'Original COE Start Date',
Expand Down Expand Up @@ -44,7 +50,7 @@ export async function getUnitsList(enrolmentExcel: File) {
// console.log(header.slice(14));
const unitsList = header.slice(14).map(elem => elem.toString());
const unitsData: Record<string, CellValue>[] = unitsList.map((u) => {
return { 0: u };
return { 0: u, 1: '', 2: '', 3: '' };
});

storeSpreadsheetData(unitsData, DB_UNITS);
Expand Down Expand Up @@ -79,10 +85,14 @@ export async function getTimetableProblem(enrolmentExcel: File, roomSpreadsheet:
});

unitSpreadsheet.map((record, index) => {
const totalDuration = (parseInt(record['1'].toString()) + parseInt(record['2'].toString()) + parseInt(record['3'].toString())) * 60;
const wantsLab = parseInt(record['3'].toString()) > 0;
units[index].duration = totalDuration;
units[index].wantsLab = wantsLab;
if (index >= units.length) {
}
else {
const totalDuration = (Number(record['1']) + Number(record['2']) + Number(record['3'])) * 60;
const wantsLab = Number(record['3']) > 0;
units[index].duration = totalDuration;
units[index].wantsLab = wantsLab;
}
})

// check each row and add students to each unit they're enrolled in
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/scripts/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ export async function storeSpreadsheetData(data: Record<string, CellValue>[], st

try {
if (storageObject === DB_BUILDINGS) {
await db.buildings.clear();
await db.buildings.bulkPut(records);
}
else if (storageObject === DB_ROOMS) {
await db.rooms.clear();
await db.rooms.bulkPut(records);
}
else if (storageObject === DB_UNITS) {
await db.units.clear();
await db.units.bulkPut(records);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/static.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"root": "./dist"
"root": "./dist"
}

0 comments on commit 20b2791

Please sign in to comment.