fix nginx conf + improve ui

This commit is contained in:
rmanach 2023-09-20 19:41:19 +02:00
parent b3989a401a
commit 53c54e9553
17 changed files with 263 additions and 134 deletions

View File

@ -3,4 +3,4 @@ from django_eventstream.channelmanager import DefaultChannelManager
class DeploymentChannelManager(DefaultChannelManager): class DeploymentChannelManager(DefaultChannelManager):
def can_read_channel(self, user, channel): def can_read_channel(self, user, channel):
return user.is_authenticated return user is not None and user.is_authenticated

View File

@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-09-18 08:14 # Generated by Django 4.2.5 on 2023-09-20 17:23
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
@ -44,6 +44,8 @@ class Migration(migrations.Migration):
max_length=7, max_length=7,
), ),
), ),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
( (
"user", "user",
models.ForeignKey( models.ForeignKey(

View File

@ -1,4 +1,5 @@
from enum import Enum from enum import Enum
from datetime import datetime
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -36,6 +37,8 @@ class Deployment(models.Model):
status = models.CharField( status = models.CharField(
max_length=7, choices=Status.into_choices(), default=Status.READY.name max_length=7, choices=Status.into_choices(), default=Status.READY.name
) )
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self): def __str__(self):

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -25,13 +25,16 @@ var start = function (url) {
const tr = document.getElementById(message.id); const tr = document.getElementById(message.id);
if (tr) { if (tr) {
var th = tr.querySelector("th[name='status']"); var status = tr.querySelector("th[name='status']");
th.innerHTML = message.status; status.innerHTML = message.status;
var button = tr.querySelector("th[name='deploy']");
if (message.status == "SUCCESS") {
button.innerHTML = "";
}
if (message.status == "FAILED") { if (message.status == "FAILED") {
setTimeout(() => {
window.location.reload(); window.location.reload();
}, 2000);
} }
} }

View File

@ -14,14 +14,22 @@ from deployment.tasks import deploy as launch_deploy
def index(request): def index(request):
deployments = Deployment.objects.filter(user=request.user.id) deployments = Deployment.objects.filter(user=request.user.id).order_by(
"-created_at"
)
paginator = Paginator(deployments, 5) paginator = Paginator(deployments, 5)
page_number = request.GET.get("page") page_number = request.GET.get("page")
page_obj = paginator.get_page(page_number) page_obj = paginator.get_page(page_number)
return render( return render(
request, "deployment/board.html", {"page_obj": page_obj, "url": "events/"} request,
"deployment/board.html",
{
"page_obj": page_obj,
"range_pages": [i + 1 for i in range(page_obj.paginator.num_pages)],
"url": "events/",
},
) )

View File

@ -8,6 +8,15 @@ http {
server { server {
listen 8080; listen 8080;
types {
text/html html htm;
text/css css;
application/javascript js;
image/jpeg jpg jpeg;
image/png png;
image/svg+xml svg;
}
location /static/ { location /static/ {
alias /app/static/; alias /app/static/;
} }

View File

@ -1,26 +1,21 @@
{% load static %}
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head>
<head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>{% block title %}mumui{% endblock %}</title> <title>{% block title %}Mumui{% endblock %}</title>
{% block headscript %}{% endblock %} {% block headscript %}{% endblock %}
</head> <link href="{% static 'deployment/css/bootstrap.min.css' %}" rel="stylesheet" type="text/css">
</head>
<body {% block bodyattr %}{% endblock %}> <body {% block bodyattr %}{% endblock %}>
<main> {% include 'header.html' %}
{% if user.is_authenticated or "login" in request.path %} <div class="container-md">
{% block content %} {% block content %}
{% endblock %} {% endblock %}
{% if user.is_authenticated %} </div>
<p><a href="{% url 'logout' %}">log out</a></p> <script src="{% static 'deployment/js/bootstrap.bundle.min.js' %}" /></script>
{% endif %}
{% else %}
<p>You are not logged in</p>
<a href="{% url 'login' %}">log In</a>
{% endif %}
</main>
{% block script %}{% endblock %} {% block script %}{% endblock %}
</body> </body>
</html> </html>

View File

@ -2,7 +2,7 @@
{% load static %} {% load static %}
{% block title %} deployment's board {% endblock %} {% block title %} Deployments board {% endblock %}
{% block headscript %} {% block headscript %}
<script src="{% static 'django_eventstream/json2.js' %}"></script> <script src="{% static 'django_eventstream/json2.js' %}"></script>
@ -15,15 +15,14 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{{ user.username }}'s board {% if user.is_authenticated %}
{% if page_obj %} <table class="table table-striped table-hover">
<table>
<tr> <tr>
<th>name</th> <th scope="col-3">Name</th>
<th>type</th> <th scope="col-3">Type</th>
<th>status</th> <th scope="col-3">Status</th>
<th></th> <th class="col-1"></th>
<th></th> <th class="col-2"></th>
</tr> </tr>
{% for deployment in page_obj %} {% for deployment in page_obj %}
<tr id="{{ deployment.id }}"> <tr id="{{ deployment.id }}">
@ -32,46 +31,41 @@
<th name="status">{{ deployment.status }}</th> <th name="status">{{ deployment.status }}</th>
<th> <th>
<a href="{% url 'deployment-details' deployment.id %}"> <a href="{% url 'deployment-details' deployment.id %}">
<button>details</button> <button class="btn btn-primary">Details</button>
</a> </a>
</th> </th>
{% if deployment.status == "FAILED" or deployment.status == "READY" %} {% if deployment.status == "FAILED" or deployment.status == "READY" %}
<th name="deploy"> <th name="deploy">
<form action="{% url 'deployment-launch' deployment.id %}?page={{ page_obj.number }}" method="post"> <form action="{% url 'deployment-launch' deployment.id %}?page={{ page_obj.number }}" method="post">
{% csrf_token %} {% csrf_token %}
<input type="submit" value="deploy"> <button class="btn btn-success" type="submit">Deploy</button>
</form> </form>
</th> </th>
{% elif deployment.status == "RUNNING" %}
<th name="deploy">
<button class="btn btn-primary" type="button" disabled>
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
<span role="status">Deploy</span>
</button>
</th>
{% else %}
<th></th>
{% endif %} {% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
<div class="pagination"> {% include 'pagination.html' %}
<span class="step-links"> <a class="btn btn-success" href="{% url 'deployment-create' %}" role="button">Create</a>
{% if page_obj.has_previous %}
<a href="?page=1">&laquo; first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</div>
{% else %} {% else %}
<p>no deployments available</p> <div class="row justify-content-md-center">
<div class="col-lg-8 col-md-8 col-sm-6">
<h4 style="text-align: center;">Please log in !</h4>
</div>
</div>
{% endif %} {% endif %}
<a href="/deployment/create">
<button>create</button>
</a>
{% endblock %} {% endblock %}
{% block script %} {% block script %}
<script src="{% static 'deployment/js/event_source.js' %}" /> <script src="{% static 'deployment/js/event_source.js' %}" />
</script> </script>
{% endblock %} {% endblock %}

View File

@ -1,12 +1,20 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %} new deployment {% endblock %} {% block title %} New deployment {% endblock %}
{% block content %} {% block content %}
{% if user.is_authenticated %}
{{ user.username }}'s new deployment {{ user.username }}'s new deployment
<form action="" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
<input type="submit" value="create"> <input type="submit" value="create">
</form> </form>
{% else %}
<div class="row justify-content-md-center">
<div class="col-lg-8 col-md-8 col-sm-6">
<h4 style="text-align: center;">Please log in !</h4>
</div>
</div>
{% endif %}
{% endblock %} {% endblock %}

View File

@ -1,8 +1,9 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %} deployment details: {{ deployment.name }} {% endblock %} {% block title %} Deployment details: {{ deployment.name }} {% endblock %}
{% block content %} {% block content %}
{% if user.is_authenticated %}
<table> <table>
<tr> <tr>
<th>id</th> <th>id</th>
@ -21,4 +22,11 @@
{% csrf_token %} {% csrf_token %}
<input type="submit" value="delete"> <input type="submit" value="delete">
</form> </form>
{% else %}
<div class="row justify-content-md-center">
<div class="col-lg-8 col-md-8 col-sm-6">
<h4 style="text-align: center;">Please log in !</h4>
</div>
</div>
{% endif %}
{% endblock %} {% endblock %}

23
templates/header.html Normal file
View File

@ -0,0 +1,23 @@
<div class="container-fluid">
<header
class="d-flex flex-wrap align-items-center justify-content-center justify-content-md-between py-3 mb-4 border-bottom">
<div class="col-md-3 mb-2 mb-md-0">
<a href="/" class="d-inline-flex link-body-emphasis text-decoration-none">
Mumui
</a>
</div>
<ul class="nav col-12 col-md-auto mb-2 justify-content-center mb-md-0">
<li><a href="{% url 'deployment' %}" class="nav-link px-2">Deployments</a></li>
<li><a href="#" class="nav-link px-2">About</a></li>
</ul>
<div class="col-md-3 text-end">
{% if user.is_authenticated %}
<a href="{% url 'logout' %}"><button type="button" class="btn btn-outline-danger me-2">Logout</button></a>
{% else %}
<a href="{% url 'login' %}"><button type="button" class="btn btn-outline-primary me-2">Login</button></a>
{% endif %}
</div>
</header>
</div>

View File

@ -1,10 +1,27 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %}home{% endblock %} {% block title %}Home{% endblock %}
{% block content %} {% block content %}
Hi {{ user.username }}! {% if user.is_authenticated %}
<ul> <div class="row justify-content-md-center">
<li><a href="{% url 'deployment' %}">deployments</a></li> <div class="col-lg-4 col-md-8 col-sm-8">
</ul> <h2 style="text-align: center;">Hi {{ user.username }} ! How are you ?</h2>
</div>
</div>
<div class="row justify-content-md-center">
<div class="col-lg-6 col-md-8 col-sm-8">
<div style="text-align: center;">Forget, i don't care... Please go on
<a href="/deployment/">Deployments</a>
and enjoy the life !
</div>
</div>
</div>
{% else %}
<div class="row justify-content-md-center">
<div class="col-lg-6 col-md-8 col-sm-8">
<h4 style="text-align: center;">Please log in !</h4>
</div>
</div>
{% endif %}
{% endblock %} {% endblock %}

35
templates/pagination.html Normal file
View File

@ -0,0 +1,35 @@
<nav aria-label="pagination">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link">Previous</a>
</li>
{% endif %}
{% for page in range_pages %}
{% if page == page_obj.number %}
<li class="page-item active">
<a class="page-link" href="?page={{ page }}">{{ page }}</a>
</li>
{% else %}
<li class="page-item">
<a class="page-link" href="?page={{ page }}">{{ page }}</a>
</li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.next_page_number }}">Next</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link">Next</a>
</li>
{% endif %}
</ul>
</nav>

View File

@ -1,17 +1,27 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %} login {% endblock %} {% block title %} Login {% endblock %}
{% block content %} {% block content %}
<div class="row justify-content-md-center">
<div class="col-lg-4 col-md-4 col-sm-6">
{% if not user.is_authenticated %} {% if not user.is_authenticated %}
<h2>log in</h2> <h2>Log in</h2>
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.username.label_tag }} {{ form.username }} <div class="mb-3">
{{ form.password.label_tag }} {{ form.password }} <label for="id_username" class="form-label">Username</label>
<button type="submit">log in</button> <input type="username" class="form-control" id="id_username" name="username" required="">
</div>
<div class="mb-3">
<label for="id_password" class="form-label">Password</label>
<input type="password" id="id_password" name="password" class="form-control" required="">
</div>
<button type="submit" class="btn btn-success">Log in</button>
</form> </form>
{% else %} {% else %}
<div>you're already log in !</div> <h4 style="text-align: center;">You're already log in !</h4>
{% endif %} {% endif %}
</div>
</div>
{% endblock %} {% endblock %}