environment: delete service page (#64924)

This commit is contained in:
Yann Weber 2024-02-01 12:07:18 +01:00
parent 9761c8fec4
commit f7529918e1
8 changed files with 5 additions and 161 deletions

View File

@ -13,7 +13,7 @@
</p>
<div class="buttons">
<button>{% trans 'Delete' %}</button>
<a class="cancel" href="{% url 'environment-home' %}">{% trans 'Cancel' %}</a>
<a class="cancel" href="{% url 'home' %}">{% trans 'Cancel' %}</a>
</div>
</form>
{% endblock %}

View File

@ -1,135 +0,0 @@
{% extends "hobo/base.html" %}
{% load i18n service %}
{% block breadcrumb %}
{{ block.super }}
<a href="{% url 'environment-home' %}">{% trans 'Sites' %}</a>
{% endblock %}
{% block appbar %}
<h2>{% trans 'Sites' %}</h2>
{% endblock %}
{% block content %}
<p>
<span>{% trans 'Add new service:' %}</span>
<span id="new-service">
{% for service in available_services %}
<a rel="popup" data-service="{{ service.id }}" href="{% url 'create-service' service=service.id %}">{{ service.label }}</a>
{% endfor %}
</span>
</p>
{% for service in installed_services %}
<div data-service-id="{{ service.Extra.service_id }}"
data-slug="{{ service.slug }}"
class="bo-block service-block {{ service.Extra.service_id }}-block"
{% if service.wants_frequent_checks %}data-wants-check="true"{% endif %}>
<h3>{{ service.title }} <span class="slug">[{{service.slug}},
<a href="{{service.base_url}}">{{service.base_url}}</a>]</span></h3>
{% if not service.is_operational %}
{% if service.wants_frequent_checks %}
<p class="info being-deployed">
{% trans 'This service is still being deployed.' %}
</p>
{% else %}
<p class="warning">
{% trans 'This service is not operational.' %}
<a rel="popup" class="icon-remove-sign" href="{% url 'delete-service' service=service.Extra.service_id slug=service.slug %}" title="{% trans 'Delete service' %}"></a>
</p>
{% endif %}
{% endif %}
<form class="small" method="post" action=" {{ service|save_url }}" >
{% csrf_token %}
{{ service|as_update_form }}
<button class="enable-on-change" disabled="disabled">{% trans 'Save' %}</button>
<h4 class="custom-variables untoggled">{% trans "Custom variables" %}</h4>
<div>
{% for variable in service.variables.all %}
{% if not variable.auto %}
<p class="variable">
<label data-variable-id="{{ variable.id }}">{{ variable.get_field_label }}</label>
<input type="text" size="80" value="{{ variable.value }}" readonly>
<a rel="popup" class="update-variable" href="{% url 'update-variable' pk=variable.id %}" title="{% trans 'Update variable' %}">{% trans 'edit' %}</a>
<a rel="popup" class="icon-remove-sign" href="{% url 'delete-variable' pk=variable.id %}" title="{% trans 'Delete variable' %}"></a>
</p>
{% endif %}
{% endfor %}
<a rel="popup" class="button" href="{% url 'new-variable-service' service=service.Extra.service_id slug=service.slug %}">{% trans 'Add new variable' %}</a>
</div>
</form>
{% if service.legacy_urls %}
<h4>
{% blocktrans trimmed count counter=service.legacy_urls|length %}
Legacy URL
{% plural%}
Legacy URLS
{% endblocktrans %}
</h4>
<ul>
{% for legacy_url in service.legacy_urls %}
<li>{{ legacy_url.base_url }} {% if legacy_url.datetime %}({% trans 'until' %} {{ legacy_url.datetime }}){% endif %}</li>
{% endfor %}
</ul>
{% endif%}
</div>
{% endfor %}
{% endblock %}
{% block page-end %}
<script>
jQuery.fn.extend({
operational_check: function() {
return this.each(function() {
var div = $(this)
var p_info = $(div).find('p.info');
var url = 'check_operational/' + $(div).data('service-id') + '/' + $(div).data('slug');
$.getJSON(url, function(data) {
if (data.operational == true) {
$(p_info).hide('size');
} else {
setTimeout(function() { $(div).operational_check(); }, 10000);
}
});
});
}
});
$(function() {
/* turn the new service links into a select box */
var select_new_service = $('<select><option></option></select>').insertAfter($('#new-service'));
$('#new-service').hide();
$('#new-service a').each(function(index, element) {
var text = $(element).text();
var option = $('<option value="' + $(element).data('service') + '">' + text + "</option>"
).appendTo(select_new_service);
});
$(select_new_service).change(function() {
var service_id = $(this).val();
if (service_id) {
$('#new-service a[data-service=' + service_id + ']').click();
$(this).val('');
}
});
$('a.update-variable').hide();
$('p.variable label, p.variable input').click(function() {
$(this).parent().find('a.update-variable').click();
});
$("div[data-wants-check='true']").each(function(index, element) {
$(element).operational_check();
});
$('button.enable-on-change').each(function(index, element) {
var button = $(element);
$(element).parent('form').find('input').on('change keydown',
function() { $(button).prop('disabled', null); });
});
});
</script>
{% endblock %}

View File

@ -20,7 +20,7 @@
{% block buttons %}
<div class="buttons">
<a class="cancel" href="{% url 'environment-home' %}">{% trans 'Cancel' %}</a>
<a class="cancel" href="{% url 'home' %}">{% trans 'Cancel' %}</a>
</div>
{% endblock %}
</div>

View File

@ -15,7 +15,7 @@
{% block buttons %}
<div class="buttons">
<button class="submit-button">{% trans 'Save' %}</button>
<a class="cancel" href="{% url 'environment-home' %}">{% trans 'Cancel' %}</a>
<a class="cancel" href="{% url 'home' %}">{% trans 'Cancel' %}</a>
</div>
{% endblock %}
</form>

View File

@ -15,7 +15,7 @@
{% block buttons %}
<div class="buttons">
<button class="submit-button">{% trans 'Save' %}</button>
<a class="cancel" href="{% url 'environment-home' %}">{% trans 'Cancel' %}</a>
<a class="cancel" href="{% url 'home' %}">{% trans 'Cancel' %}</a>
</div>
{% endblock %}
</form>

View File

@ -15,7 +15,7 @@
{% block buttons %}
<div class="buttons">
<button class="submit-button">{% trans 'Save' %}</button>
<a class="cancel" href="{% url 'environment-home' %}">{% trans 'Cancel' %}</a>
<a class="cancel" href="{% url 'home' %}">{% trans 'Cancel' %}</a>
</div>
{% endblock %}
</form>

View File

@ -19,7 +19,6 @@ from django.urls import path, re_path
from . import views
urlpatterns = [
path('', views.HomeView.as_view(), name='environment-home'),
path('variables', views.VariablesView.as_view(), name='environment-variables'),
re_path(
r'^variables-(?P<service>\w+)/(?P<slug>[\w-]+)$',

View File

@ -14,7 +14,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import datetime
import json
from django.contrib.contenttypes.models import ContentType
@ -37,25 +36,6 @@ class AvailableService:
self.label = klass._meta.verbose_name
class HomeView(TemplateView):
template_name = 'environment/home.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['available_services'] = [AvailableService(x) for x in AVAILABLE_SERVICES if x.is_enabled()]
installed_services = [x for x in utils.get_installed_services() if not x.secondary]
for service in installed_services:
for legacy_url in service.legacy_urls:
try:
legacy_url['datetime'] = datetime.datetime.strptime(
legacy_url['timestamp'], '%Y-%m-%d %H:%M:%S'
)
except ValueError:
pass
context['installed_services'] = installed_services
return context
class VariablesView(TemplateView):
template_name = 'environment/variables.html'