Skip to content

Commit

Permalink
Merge pull request #65 from TheSecretOrganization/reindent
Browse files Browse the repository at this point in the history
reindent files
  • Loading branch information
Neffi42 authored Sep 11, 2024
2 parents bc12939 + da34e9a commit 8c7e1fc
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 129 deletions.
6 changes: 3 additions & 3 deletions django/src/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('auth/', include('ft_auth.urls')),
path('pages/', include('pages.urls')),
path('admin/', admin.site.urls),
path('auth/', include('ft_auth.urls')),
path('pages/', include('pages.urls')),
]
24 changes: 12 additions & 12 deletions django/src/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
main()
6 changes: 3 additions & 3 deletions django/src/pages/templates/404.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="h-100 d-flex align-items-center justify-content-center">
<div>
<p>Page not found</p>
</div>
<div>
<p>Page not found</p>
</div>
</div>
12 changes: 6 additions & 6 deletions django/src/pages/templates/games.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div id="gameSelection" class="d-flex justify-content-center">
<button id="pongBtn" class="btn btn-secondary">Pong</button>
<button id="game2Btn" class="btn btn-secondary">Tic-Tac-Toe</button>
<button id="pongBtn" class="btn btn-secondary">Pong</button>
<button id="game2Btn" class="btn btn-secondary">Tic-Tac-Toe</button>
</div>
<div id="game">
<button id="backBtn" class="btn btn-dark">Back</button>
<div class="center-content">
<canvas id="gameCanvas" width="800" height="600"></canvas>
</div>
<button id="backBtn" class="btn btn-dark">Back</button>
<div class="center-content">
<canvas id="gameCanvas" width="800" height="600"></canvas>
</div>
</div>
<div id="gameAgain" class="center-content"></div>
6 changes: 3 additions & 3 deletions django/src/pages/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="h-100 d-flex align-items-center justify-content-center">
<div>
<p>This is Index</p>
</div>
<div>
<p>This is Index</p>
</div>
</div>
2 changes: 1 addition & 1 deletion django/src/pages/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
urlpatterns = [
path('index/', views.index),
path('games/', views.games),
path('404/', views.error_404),
path('404/', views.error_404),
]
84 changes: 42 additions & 42 deletions nginx/src/css/styles.css
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
/* General */
html {
box-sizing: border-box;
font-size: 100%;
height: 100%;
scroll-behavior: smooth;
box-sizing: border-box;
font-size: 100%;
height: 100%;
scroll-behavior: smooth;
}

*, *::before, *::after {
box-sizing: inherit;
box-sizing: inherit;
}

body {
min-height: 100%;
line-height: 1.5;
margin: 0;
padding: 0;
font-family: 'Arial', sans-serif;
background-color: #f5f5f5;
color: #333;
min-height: 100%;
line-height: 1.5;
margin: 0;
padding: 0;
font-family: 'Arial', sans-serif;
background-color: #f5f5f5;
color: #333;
}

.list-group-item {
padding: 10px;
cursor: pointer;
text-align: center;
padding: 10px;
cursor: pointer;
text-align: center;
}

.list-group-item.active {
background-color: #007bff;
color: white;
background-color: #007bff;
color: white;
}

/* Page Content */
#page-container-wrapper {
position: relative;
position: relative;
}

/* Sidebar Toggle */
#sidebar-toggle {
position: fixed;
top: 1rem;
left: 1rem;
font-size: 20px;
z-index: 1050;
transition: all 0.3s ease;
position: fixed;
top: 1rem;
left: 1rem;
font-size: 20px;
z-index: 1050;
transition: all 0.3s ease;
}

#sidebar-toggle.toggled {
margin-left: 250px;
margin-left: 250px;
}

/* Sidebar */
#sidebar-wrapper {
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 250px;
border-radius: 0 5px 5px 0;
transition: all 0.3s ease;
z-index: 1000;
text-align: center;
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 250px;
border-radius: 0 5px 5px 0;
transition: all 0.3s ease;
z-index: 1000;
text-align: center;
}

#sidebar-wrapper.toggled {
margin-left: -250px;
margin-left: -250px;
}

#sidebar-wrapper .sidebar-heading {
padding: 1rem;
font-size: 1.5rem;
padding: 1rem;
font-size: 1.5rem;
}

#sidebar-wrapper .list-group-item {
padding: 1rem 1.5rem;
padding: 1rem 1.5rem;
}

#game {
display: none;
margin-block: 5px;
display: none;
margin-block: 5px;
}

#gameCanvas {
background-color: black;
border: 3px solid lightskyblue;
background-color: black;
border: 3px solid lightskyblue;
}
119 changes: 60 additions & 59 deletions nginx/src/js/router.js
Original file line number Diff line number Diff line change
@@ -1,87 +1,88 @@

function route(e) {
e.preventDefault();
window.history.pushState({}, "", e.target.getAttribute('data-route'));
handleLocation();
e.preventDefault();
window.history.pushState({}, "", e.target.getAttribute('data-route'));
handleLocation();
};

async function fetchPage(pageName) {
const response = await fetch(`/api/pages/${pageName}/`);
if (!response.ok) {
console.error(`Failed to fetch ${pageName}: ${response.statusText}`);
return null;
}
const data = await response.json();
if (data.error) {
console.error(`Failed to fetch ${pageName}: ${data.error}`);
return null;
}
return data.html;
const response = await fetch(`/api/pages/${pageName}/`);
if (!response.ok) {
console.error(`Failed to fetch ${pageName}: ${response.statusText}`);
return null;
}
const data = await response.json();
if (data.error) {
console.error(`Failed to fetch ${pageName}: ${data.error}`);
return null;
}
return data.html;
};

function loadScripts() {
const container = document.getElementById("page-container");
const scripts = container.querySelectorAll('script');
const container = document.getElementById("page-container");
const scripts = container.querySelectorAll('script');

scripts.forEach(script => {
const newScript = document.createElement('script');
if (script.src) {
newScript.src = script.src;
} else {
newScript.textContent = script.textContent;
}
document.body.appendChild(newScript);
document.body.removeChild(newScript);
});
scripts.forEach(script => {
const newScript = document.createElement('script');
if (script.src) {
newScript.src = script.src;
} else {
newScript.textContent = script.textContent;
}
document.body.appendChild(newScript);
document.body.removeChild(newScript);
});
};

function updateTitle(pageName) {
const titles = {
"index": "Home",
"games": "Games",
"404": "Page Not Found"
};
const title = titles[pageName] || "Page Not Found";
document.title = title;
const titles = {
"index": "Home",
"games": "Games",
"404": "Page Not Found"
};
const title = titles[pageName] || "Page Not Found";
document.title = title;
};

function updateActiveRoute(path) {
document.querySelectorAll('#sidebar-list .list-group-item').forEach(item => {
item.classList.remove('active');
});
const activeRoute = document.querySelector(`[data-route="${path}"]`);
if (activeRoute) {
activeRoute.classList.add('active');
}
document.querySelectorAll('#sidebar-list .list-group-item').forEach(item => {
item.classList.remove('active');
});
const activeRoute = document.querySelector(`[data-route="${path}"]`);
if (activeRoute) {
activeRoute.classList.add('active');
}
}

async function handleLocation() {
let path = window.location.pathname;
let pageName = path === '/' ? 'index' : path.substring(1);
let html = await fetchPage(pageName);
if (html === null) {
html = await fetchPage('404');
}
let path = window.location.pathname;
let pageName = path === '/' ? 'index' : path.substring(1);
let html = await fetchPage(pageName);
if (html === null) {
html = await fetchPage('404');
}

document.getElementById("page-container").innerHTML = html;
loadScripts();
updateTitle(pageName);
updateActiveRoute(path);
document.getElementById("page-container").innerHTML = html;
loadScripts();
updateTitle(pageName);
updateActiveRoute(path);
};

document.addEventListener("DOMContentLoaded", () => {
window.onpopstate = handleLocation;
window.route = route;
handleLocation();
window.onpopstate = handleLocation;
window.route = route;
handleLocation();
});

document.addEventListener("click", (e) => {
if (e?.target?.hasAttribute('data-route')) {
route(e);
}
if (e?.target?.hasAttribute('data-route')) {
route(e);
}
});

document.getElementById("sidebar-toggle").addEventListener("click", function (e) {
e.preventDefault();
document.getElementById("sidebar-wrapper").classList.toggle("toggled");
this.classList.toggle("toggled");
e.preventDefault();
document.getElementById("sidebar-wrapper").classList.toggle("toggled");
this.classList.toggle("toggled");
});

0 comments on commit 8c7e1fc

Please sign in to comment.