Skip to content

Commit 4b67df5

Browse files
Merge pull request #20 from ashirrwad/ui
Tutorial
2 parents e483227 + a4b665a commit 4b67df5

File tree

8 files changed

+272
-14
lines changed

8 files changed

+272
-14
lines changed

Backend/Pipfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ name = "pypi"
77
flask = "*"
88
docker = "*"
99
flask-cors = "*"
10+
pyyaml = "*"
1011

1112
[dev-packages]
12-

Backend/app.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import docker
55
import os
66
import tarfile
7-
7+
import yaml
8+
import json
89
app = Flask(__name__)
910

1011
cors = CORS(app)
@@ -15,13 +16,22 @@
1516
client = docker.from_env()
1617
container = client.containers.run("playground-small", tty=True, detach=True, network_disabled=True, mem_limit="16g")
1718

19+
#Converting tutorial YAML
20+
with open('tutorial.yml', 'r') as file:
21+
configuration = yaml.safe_load(file)
22+
23+
with open('../frontend/src/tutorial.json', 'w+') as json_file:
24+
json.dump(configuration, json_file)
25+
26+
1827
# Editing the file with code inside editor
1928
def edit_file(code, input=""):
2029
Fortran_file = open("./File.f90", "w+")
2130
Fortran_file.write(code)
31+
Fortran_file.close()
2232
program_input = open("./program_input.txt", "w+")
2333
program_input.write(input)
24-
34+
program_input.close()
2535

2636
# Copying file with fortran code to container
2737
def copy_to(src, dst, container):
@@ -64,6 +74,10 @@ def run_code():
6474
edit_file(data["code"], data["programInput"])
6575
code_result = execute_code_in_container()
6676
if code_result.exit_code == 0:
77+
if code_result.output[0] == None:
78+
output = jsonify({"executed": ""})
79+
return output, 202
80+
6781
print(code_result.output[0].decode())
6882
output = jsonify({"executed": code_result.output[0].decode()})
6983
else:

Backend/tutorial.yml

+180
Large diffs are not rendered by default.

frontend/src/App.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Card from 'react-bootstrap/Card'
1111
import RunCode from './run.png'
1212
import ResetCode from './reset.png'
1313
import InputBox from './InputBox';
14-
14+
import TutorialCard from './TutorialCard';
1515

1616
function NewlineText(props) {
1717
const text = props.text;
@@ -24,6 +24,7 @@ function App() {
2424
const [output, setOutput] = useState('')//State to store output
2525
const [isLoading, setIsLoading] = useState(false);//Loading animations
2626
const [ input, setInput ] = useState('')
27+
const [inputOn, setinputOn] = useState(false)
2728

2829

2930
const handleInputChange = (e) => {
@@ -32,7 +33,10 @@ function App() {
3233
console.log(input)
3334
};
3435

35-
36+
const handleInputBox = (e) =>{
37+
{inputOn ? setinputOn(false) : setinputOn(true)}
38+
//setinputOn(true)
39+
}
3640
//POST request to Flask server
3741
const handleClick = async () => {
3842

@@ -55,7 +59,7 @@ function App() {
5559
<div style={{paddingBottom: "0.5rem"}}><Navigationbar/></div>
5660
<div className='code-wrapper'>
5761
{/*Editor Component*/}
58-
<Editor value={text} onChange={value => setText(value)}/>
62+
<Editor value={text} height={""} width={"50%"} onChange={value => setText(value)}/>
5963

6064
{/* Buttons */}
6165
<div className='options'><Button onClick={resetCode} ><img src={ResetCode} /></Button>
@@ -81,7 +85,7 @@ function App() {
8185
{/*Card component to display output*/}
8286
<div className='terminal'>
8387

84-
<Card style={{width:'100%'}}>
88+
<Card style={{width:'100%'}} className="overflow-auto">
8589
<Card.Header>Terminal</Card.Header>
8690
<Card.Body>
8791

@@ -93,8 +97,13 @@ function App() {
9397

9498
</Card.Body>
9599
</Card>
100+
101+
<TutorialCard />
96102
{/* Input Box to provide input for program */}
97-
<InputBox value={input} onChange={handleInputChange}/>
103+
{/*<InputBox value={input} onChange={handleInputChange}/> */}
104+
<Button onClick={handleInputBox}>INPUT</Button>
105+
{inputOn ? <InputBox value={input} onChange={handleInputChange}/> : null}
106+
98107
</div>
99108

100109
</div>

frontend/src/Editor.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export default function Editor(props){
1717
name="UNIQUE_ID_OF_DIV"
1818
editorProps={{ $blockScrolling: true }}
1919
value={props.value}
20-
width="50%"
21-
height=""
20+
width={props.width}
21+
height={props.height}
22+
readOnly={props.snippet}
23+
showGutter={props.gutter}
24+
highlightActiveLine={props.highlight}
2225
/>)
2326
}

frontend/src/Navbar.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Nav from 'react-bootstrap/Nav'
44
import Container from 'react-bootstrap/Container'
55
export default function Navigationbar(){
66
return(
7-
<>
7+
88

99
<Navbar bg="dark" variant="dark">
1010
<Container>
@@ -19,10 +19,10 @@ export default function Navigationbar(){
1919
Fortran Playground
2020
</Navbar.Brand>
2121
</Container>
22-
<Nav.Link href="https://fortran-lang.org/learn/" target="_blank" rel="noopener noreferrer" ><span className="linkText">Learn</span></Nav.Link>
23-
<Nav.Link href="https://fortran-lang.org/" target="_blank" rel="noopener noreferrer" ><span className="linkText">Home</span></Nav.Link>
22+
<Nav.Link href="https://fortran-lang.org/learn/" target="_blank" rel="noopener noreferrer" ><span className="linkText">Learn</span></Nav.Link>&nbsp;
23+
<Nav.Link href="https://fortran-lang.org/" target="_blank" rel="noopener noreferrer" ><span className="linkText">Home</span></Nav.Link>&nbsp;
2424
</Navbar>
2525

26-
</>
26+
2727
)
2828
}

frontend/src/TutorialCard.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import Card from 'react-bootstrap/Card';
2+
import Editor from './Editor';
3+
import Tutorial from './tutorial.json'
4+
import { useState } from 'react';
5+
import Button from 'react-bootstrap/Button'
6+
7+
8+
function NewlineText(props) {
9+
const text = props.text;
10+
return <div className='output-formmating'>{text}</div>;
11+
}
12+
13+
14+
function TutorialCard(props) {
15+
16+
const [exercise, setExercise] = useState(0)
17+
const goRight = () => {
18+
if(exercise<Tutorial.length - 1){
19+
setExercise(exercise + 1)
20+
}
21+
}
22+
const goLeft = () => {
23+
if(exercise>0){
24+
setExercise(exercise - 1)
25+
}
26+
}
27+
return (
28+
<Card style={{ width: '100%', height: '100%' }} className="overflow-auto">
29+
30+
<Card.Body>
31+
<Card.Title>{Tutorial[exercise].title}</Card.Title>
32+
<Editor highlight={true}
33+
value={Tutorial[exercise].code}
34+
snippet={false}
35+
gutter={false}
36+
height={"50%"}
37+
width={"100%"}/>
38+
<Card.Text>
39+
40+
41+
<NewlineText text={Tutorial[exercise].content} />
42+
</Card.Text>
43+
44+
<Button onClick={goLeft} >Prev</Button>&nbsp;
45+
<Button onClick={goRight}>Next</Button>
46+
</Card.Body>
47+
</Card>
48+
);
49+
}
50+
51+
export default TutorialCard;

frontend/src/tutorial.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"title": "Hello World", "content": "Let us start with our first Hello World program", "code": "program hello\r\n ! This is a comment line; it is ignored by the compiler\r\n print *, 'Hello, World!'\r\nend program hello\r\n"}, {"title": "Declaring variables", "content": "Variable names must start with a letter and can consist of letters, numbers and underscores. In the following example we declare a variable for each of the built-in types.", "code": "program variables\r\n implicit none\r\n\r\n integer :: amount\r\n real :: pi\r\n complex :: frequency\r\n character :: initial\r\n logical :: isOkay\r\n\r\nend program variables"}, {"title": "Declaring variables", "content": "Once we have declared a variable, we can assign and reassign values to it using the assignment operator =.", "code": "program variables\r\n implicit none\r\n\r\n integer :: amount\r\n real :: pi\r\n complex :: frequency\r\n character :: initial\r\n logical :: isOkay\r\n\r\n amount = 10\r\n pi = 3.1415927\r\n frequency = (1.0, -0.5)\r\n initial = 'A'\r\n isOkay = .false.\r\nend program variables"}, {"title": "Standard output", "content": "We can use the print statement introduced earlier to print variable values to stdout", "code": "program variables\r\n implicit none\r\n\r\n integer :: amount\r\n real :: pi\r\n complex :: frequency\r\n character :: initial\r\n logical :: isOkay\r\n\r\n amount = 10\r\n pi = 3.1415927\r\n frequency = (1.0, -0.5)\r\n initial = 'A'\r\n isOkay = .false.\r\n \r\n print *, 'The value of amount (integer) is: ', amount\r\n print *, 'The value of pi (real) is: ', pi\r\n\r\nend program variables"}, {"title": "Standard input", "content": "In a similar way, we can read values from the command window using the read statement. Enter values in the box below.", "code": "program read_value\r\n implicit none\r\n integer :: age\r\n\r\n print *, 'Please enter your age: '\r\n read(*,*) age\r\n\r\n print *, 'Your age is: ', age\r\n\r\nend program read_value"}]

0 commit comments

Comments
 (0)