Commit ea8d0946 by Estók Dániel

setty: listing site added, beautification

parent 0b80f225
......@@ -248,6 +248,7 @@ $(function () {
register_search($("#dashboard-group-search-form"), $("#dashboard-group-list"), generateGroupHTML);
register_search($("#dashboard-user-search-form"), $("#dashboard-user-list"), generateUserHTML);
register_search($("#dashboard-template-search-form"), $("#dashboard-template-list"), generateTemplateHTML);
register_search($("#dashboard-service-search-form"), $("#dashboard-service-list"), generateServiceHTML);
/* notification message toggle */
$(document).on('click', ".notification-message-subject", function() {
......@@ -347,6 +348,15 @@ function generateTemplateHTML(data, is_last) {
'</a>';
}
function generateServiceHTML(data, is_last) {
return '<a href="' + data.url + '" class="list-group-item real-link' + (is_last ? " list-group-item-last" : "") +'">'+
' <span class="index-template-list-name">' +
' <i class="fa fa-server"></i> '+ safe_tags_replace(data.name) +
' </span>' +
' <div class="clearfix"></div>' +
'</a>';
}
function generateNodeHTML(data, is_last) {
return '<a href="' + data.url + '" class="list-group-item real-link' + (is_last ? ' list-group-item-last' : '') + '">' +
'<span class="index-node-list-name">' +
......
......@@ -4,7 +4,7 @@
<span class="btn btn-default btn-xs infobtn pull-right" data-container="body" title="{% trans 'List of your Setty services. You can create new ones or customize existing ones.' %}">
<i class="fa fa-info-circle"></i>
</span>
<h3 class="no-margin"><i class="fa fa-server"></i> {% trans 'Services' %}
<h3 class="no-margin"><i class="fa fa-server"></i>&nbsp;{% trans 'Services' %}
</h3>
</div>
<div class="list-group" id="template-list-view">
......@@ -16,7 +16,7 @@
<i class="fa fa-server"></i>&nbsp;{{ s.name }}
</span>
<small class="text-muted index-template-list-system">{{ s.status }}</small>
<div data-href="{% url 'setty.views.service-start' pk=s.pk %}" class="pull-right">
<!-- <div data-href="{% url 'setty.views.service-start' pk=s.pk %}" class="pull-right">
{% if s.status == "stopped" %}
<i data-container="body" title="{% trans 'Start service' %}"
class="fa fa-play"></i>
......@@ -24,8 +24,7 @@
<i data-container="body" title="{% trans 'Stop service' %}"
class="fa fa-stop"></i>
{% endif %}
</div>
</div> -->
<div class="clearfix"></div>
</a>
{% empty %}
......@@ -43,7 +42,7 @@
<div class="col-xs-5 col-sm-6">
<form action="{% url 'setty.views.service-list' %}" method="GET" id="dashboard-service-search-form">
<div class="input-group input-group-sm">
<input name="serviceSearch" type="text" class="form-control" placeholder="{% trans 'Search...' %}" />
<input name="s" type="text" class="form-control" placeholder="{% trans 'Search...' %}" />
<div class="input-group-btn">
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
</div>
......
......@@ -43,7 +43,7 @@
</div>
{% endif %}
{% if perms.vm.create_template %}
{% if perms.setty.add_service %}
<div class="col-lg-4 col-sm-6">
{% include "dashboard/index-setty.html" %}
</div>
......
......@@ -102,7 +102,11 @@ class IndexView(LoginRequiredMixin, TemplateView):
'operator', user, disregard_superuser=True).all()[:5]
# setty services
if user.has_perm('vm.create_template'):
if user.has_perm('setty.add_service'):
if user.is_superuser:
context['services'] = Service.objects.all().order_by(
'-pk')[:5]
else:
context['services'] = Service.objects.filter(
user=user).order_by('-pk')[:5]
......
This source diff could not be displayed because it is too large. You can view the blob instead.
# Copyright 2014 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from django import forms
from django.utils.translation import ugettext as _
class ServiceListSearchForm(forms.Form):
s = forms.CharField(widget=forms.TextInput(attrs={
'class': "form-control input-tags",
'placeholder': _("Search...")
}))
......@@ -779,6 +779,7 @@ jsPlumb.ready(function() {
});
$(document).ready(function() {
if(!$("#dropContainer").length) return; // Protection for not posting sites that differ from setty sites.
$.post("", {
event: "loadService"
}, function(result) {
......
# Copyright 2014 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from django_tables2 import Table
from django_tables2.columns import TemplateColumn
from setty.models import Service
from django.utils.translation import ugettext as _
class ServiceListTable(Table):
name = TemplateColumn(
template_name="setty/tables/column-name.html",
attrs={'th': {'data-sort': "string"}}
)
owner = TemplateColumn(
template_name="setty/tables/column-owner.html",
verbose_name=_("Owner"),
attrs={'th': {'data-sort': "string"}}
)
running = TemplateColumn(
template_name="setty/tables/column-running.html",
verbose_name=_("Running"),
attrs={'th': {'data-sort': "string"}},
)
class Meta:
model = Service
attrs = {'class': ('table table-bordered table-striped table-hover'
' template-list-table')}
fields = ('name', 'owner', 'running', )
prefix = "service-"
......@@ -3,7 +3,7 @@
{% load staticfiles %}
{% load i18n %}
{% block title-page %}{% trans 'Setty' %}{% endblock %}
{% block title-page %}Setty{% endblock %}
{% block content %}
......@@ -37,15 +37,15 @@
<input class="form-control form-control-sm initHidden" id="serviceNameEdit" type="text" style="margin-top: -4px !important; margin-bottom: -4px !important; width: 80%;" />
<button class="btn btn-success btn-xs initHidden" id="serviceNameSave">{% trans 'OK' %}</button>
</div>
<div class="col-xs-1 text-right">
<div class="col-xs-1 col-xs-push-1 text-right">
<button class="btn btn-info btn-xs btn-block hidden-xs hidden-sm hidden-md" id="clearService">{% trans 'Clean' %}</button>
<button class="btn btn-info btn-xs hidden-lg" id="clearService"><i class="fa fa-eraser"></i></button>
</div>
<div class="col-xs-1 text-right">
<div class="col-xs-1 col-xs-push-1 text-right">
<button class="btn btn-success btn-xs btn-block hidden-xs hidden-sm hidden-md" id="saveService">{% trans 'Save' %}</button>
<button class="btn btn-success btn-xs hidden-lg" id="saveService"><i class="fa fa-floppy-o"></i></button>
</div>
<div class="col-xs-1 text-right">
<div class="col-xs-1 col-xs-push-1 text-right">
<button class="btn btn-danger btn-xs btn-block hidden-xs hidden-sm hidden-md" id="deleteService" data-toggle="modal" data-target="#deleteServiceDialog">{% trans 'Delete' %}</button>
<button class="btn btn-danger btn-xs hidden-lg" id="deleteService" data-toggle="modal" data-target="#deleteServiceDialog"><i class="fa fa-trash-o"></i></button>
</div>
......
<a href="{% url "setty.views.service-detail" pk=record.pk %}">
{{ record.name }}
</a>
{% include "dashboard/_display-name.html" with user=record.user show_org=True new_line=True %}
{% extends "dashboard/base.html" %}
{% load staticfiles %}
{% load i18n %}
{% load render_table from django_tables2 %}
{% block title-page %}{% trans "Services" %}{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<a href="{% url "setty.views.service-create" %}" class="pull-right btn btn-success btn-xs template-choose">
<i class="fa fa-plus"></i> {% trans "new service" %}
</a>
<h3 class="no-margin"><i class="fa fa-server"></i> {% trans "Services" %}</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-offset-8 col-md-4" id="template-list-search">
<form action="" method="GET">
<div class="input-group">
{{ search_form.s }}
<div class="input-group-btn">
<button type="submit" class="btn btn-primary input-tags">
<i class="fa fa-search"></i>
</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="panel-body">
<div class="table-responsive">
{% render_table table %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
......@@ -15,16 +15,26 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from django.contrib import messages # NOTE: ezt tettem ide
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse_lazy
from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import Q
from django.http import JsonResponse
from django.http import HttpResponse, JsonResponse
from django.shortcuts import redirect
from braces.views import LoginRequiredMixin
from django.views.generic import TemplateView, DeleteView
from django_tables2 import SingleTableView
from .models import Element, ElementTemplate, ElementConnection, Service
from dashboard.views.util import FilterMixin
from django.utils.translation import ugettext as _
import json
import logging
from tables import ServiceListTable
from forms import ServiceListSearchForm
logger = logging.getLogger(__name__)
class DetailView(LoginRequiredMixin, TemplateView):
......@@ -145,6 +155,7 @@ class CreateView(LoginRequiredMixin, TemplateView):
service = Service(
name=service_name,
status="stopped",
user=self.request.user
)
service.save()
......@@ -159,5 +170,49 @@ class StopView(LoginRequiredMixin, TemplateView):
pass
class ListView(LoginRequiredMixin, TemplateView):
pass
class ListView(LoginRequiredMixin, FilterMixin, SingleTableView):
template_name = "setty/tables/service-list.html"
model = Service
table_class = ServiceListTable
table_pagination = False
allowed_filters = {
'name': "name__icontains",
}
def get_context_data(self, *args, **kwargs):
context = super(ListView, self).get_context_data(*args, **kwargs)
context['search_form'] = self.search_form
return context
def get(self, *args, **kwargs):
self.search_form = ServiceListSearchForm(self.request.GET)
self.search_form.full_clean()
if self.request.is_ajax():
services = [{
'url': reverse("setty.views.service-detail",
kwargs={'pk': i.pk}),
'status': i.status,
'name': i.name} for i in self.get_queryset()]
return HttpResponse(
json.dumps(services),
content_type="application/json",
)
else:
return super(ListView, self).get(*args, **kwargs)
def get_queryset(self):
logger.debug('ListView.get _queryset() called. User: %s',
unicode(self.request.user))
qs = self.model.objects.all()
self.create_fake_get() # NOTE: ezt tettem ide
try:
filters, excludes = self.get_queryset_filters()
if not self.request.user.is_superuser:
filters['user'] = self.request.user # NOTE: ezt visszairtam
qs = qs.filter(**filters).exclude(**excludes).distinct()
except ValueError:
messages.error(self.request, _("Error during filtering."))
return qs
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment