fix problem with boolean on the flask app;setup the front end to use query parameters;fail trying to get environment variables to work
This commit is contained in:
		
							parent
							
								
									77aa5f8b69
								
							
						
					
					
						commit
						963d4cc475
					
				@ -6,7 +6,8 @@ def roll_dices(dice_count, dice_sides, discard_lowest):
 | 
				
			|||||||
    discarded = []
 | 
					    discarded = []
 | 
				
			||||||
    for _ in range(dice_count):
 | 
					    for _ in range(dice_count):
 | 
				
			||||||
        roll_results.append(random.randint(1, dice_sides))
 | 
					        roll_results.append(random.randint(1, dice_sides))
 | 
				
			||||||
    if discard_lowest and len(roll_results) > 0:
 | 
					
 | 
				
			||||||
 | 
					    if discard_lowest and len(roll_results) > 1:
 | 
				
			||||||
        discarded.append(min(roll_results))
 | 
					        discarded.append(min(roll_results))
 | 
				
			||||||
        roll_results.remove(min(roll_results))
 | 
					        roll_results.remove(min(roll_results))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,13 +1,18 @@
 | 
				
			|||||||
from flask_restx import Resource, Namespace, reqparse
 | 
					from flask_restx import Resource, Namespace, reqparse
 | 
				
			||||||
from app.functions.roll_dices import roll_dices
 | 
					from app.functions.roll_dices import roll_dices
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def str_to_bool(val):
 | 
				
			||||||
 | 
					    return str(val).lower() == 'true'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace = Namespace('dice', description='Dice Operations')
 | 
					namespace = Namespace('dice', description='Dice Operations')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Define the parser and request args:
 | 
					# Define the parser and request args:
 | 
				
			||||||
parser = reqparse.RequestParser()
 | 
					parser = reqparse.RequestParser()
 | 
				
			||||||
parser.add_argument('quantity', type=int, required=True, help='Quantity of dice to roll')
 | 
					parser.add_argument('quantity', type=int, required=True, help='Quantity of dice to roll')
 | 
				
			||||||
parser.add_argument('geometry', type=int, required=True, help='Number of faces on the dice')
 | 
					parser.add_argument('geometry', type=int, required=True, help='Number of faces on the dice')
 | 
				
			||||||
parser.add_argument('discard_lowest', type=bool, required=True, help='Whether to discard lowest roll')
 | 
					parser.add_argument('discard_lowest', type=str_to_bool, required=True, help='Whether to discard lowest roll')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@namespace.route('/')  # resolves to: /dice
 | 
					@namespace.route('/')  # resolves to: /dice
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								web/config.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								web/config.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					// config.js
 | 
				
			||||||
 | 
					let environment = window.location.hostname === 'parmenides' ? 'dev' : 'prod';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fetch('./config.json')
 | 
				
			||||||
 | 
					    .then(response => response.json())
 | 
				
			||||||
 | 
					    .then(config => {
 | 
				
			||||||
 | 
					        window.BASE_URL = config[environment].BASE_URL;
 | 
				
			||||||
 | 
					        console.log("BASE URL:", window.BASE_URL);
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
 | 
					    .catch(error => console.error('Error:', error));
 | 
				
			||||||
							
								
								
									
										8
									
								
								web/config.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								web/config.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "dev": {
 | 
				
			||||||
 | 
					        "BASE_URL": "http://127.0.0.1:5000"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "prod": {
 | 
				
			||||||
 | 
					        "BASE_URL": "https://gammaworld.gmgauthier.com"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -4,7 +4,7 @@
 | 
				
			|||||||
    <meta charset="UTF-8">
 | 
					    <meta charset="UTF-8">
 | 
				
			||||||
    <title>Gamma World Die Roller</title>
 | 
					    <title>Gamma World Die Roller</title>
 | 
				
			||||||
    <link rel="stylesheet" type="text/css" href="styles.css">
 | 
					    <link rel="stylesheet" type="text/css" href="styles.css">
 | 
				
			||||||
    <script src="rolldice.js" defer></script>
 | 
					    <script type="module" src="rolldice.js" defer></script>
 | 
				
			||||||
</head>
 | 
					</head>
 | 
				
			||||||
<body>
 | 
					<body>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,22 +1,18 @@
 | 
				
			|||||||
window.onload = function () {
 | 
					window.onload = function () {
 | 
				
			||||||
    document.getElementById('diceForm').addEventListener('submit', function (event) {
 | 
					    document.getElementById('diceForm').addEventListener('submit', function (event) {
 | 
				
			||||||
        event.preventDefault();  // Prevent the form from submitting the normal way
 | 
					        event.preventDefault();  // Prevent the form from submitting via the default form action
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const quantity = parseInt(document.getElementById('quantity').value, 10);
 | 
					        const quantity = parseInt(document.getElementById('quantity').value, 10);
 | 
				
			||||||
        const geometry = parseInt(document.getElementById('geometry').value, 10);
 | 
					        const geometry = parseInt(document.getElementById('geometry').value, 10);
 | 
				
			||||||
        const discard = document.getElementById('discard').checked;
 | 
					        const discard = document.getElementById('discard').checked;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fetch('https://gammaworld.gmgauthier.com/roll/dice', {
 | 
					        const queryParams = new URLSearchParams({
 | 
				
			||||||
            method: 'POST',
 | 
					            quantity: quantity,
 | 
				
			||||||
            headers: {
 | 
					            geometry: geometry,
 | 
				
			||||||
                'Content-Type': 'application/json',
 | 
					            discard_lowest: discard
 | 
				
			||||||
            },
 | 
					        });
 | 
				
			||||||
            body: JSON.stringify({
 | 
					
 | 
				
			||||||
                quantity: quantity,
 | 
					        fetch(`http://127.0.0.1:5000/dice?${queryParams}`)
 | 
				
			||||||
                geometry: geometry,
 | 
					 | 
				
			||||||
                discard_lowest: discard
 | 
					 | 
				
			||||||
            }),
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
            .then(response => response.json())
 | 
					            .then(response => response.json())
 | 
				
			||||||
            .then(data => {
 | 
					            .then(data => {
 | 
				
			||||||
                const resultsDiv = document.getElementById('results');
 | 
					                const resultsDiv = document.getElementById('results');
 | 
				
			||||||
@ -25,10 +21,10 @@ window.onload = function () {
 | 
				
			|||||||
                    let diceSet = data['dice-set'];
 | 
					                    let diceSet = data['dice-set'];
 | 
				
			||||||
                    html += '<p><h3>Dice Set:</h3></p>';
 | 
					                    html += '<p><h3>Dice Set:</h3></p>';
 | 
				
			||||||
                    html += `<ul>
 | 
					                    html += `<ul>
 | 
				
			||||||
                                       <li>Mnemonic: ${diceSet['mnemonic']}</li>
 | 
					                               <li>Mnemonic: ${diceSet['mnemonic']}</li>
 | 
				
			||||||
                                       <li>Min Roll: ${diceSet['min-roll']}</li>
 | 
					                               <li>Min Roll: ${diceSet['min-roll']}</li>
 | 
				
			||||||
                                       <li>Max Roll: ${diceSet['max-roll']}</li>
 | 
					                               <li>Max Roll: ${diceSet['max-roll']}</li>
 | 
				
			||||||
                                      </ul>`;
 | 
					                             </ul>`;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (data['rolls'] && quantity > 1) {
 | 
					                if (data['rolls'] && quantity > 1) {
 | 
				
			||||||
                    html += `<p><h3>Rolls: </h3>${data['rolls'].join(', ')}</p>`;
 | 
					                    html += `<p><h3>Rolls: </h3>${data['rolls'].join(', ')}</p>`;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user