Commit 37c7213d by Estók Dániel

Improved dashboard-integration and refactor.

parent 6aa74424
......@@ -53,7 +53,7 @@ class Element(Model):
anchors = models.PositiveSmallIntegerField()
def __unicode__(self):
return self.service.name + ", id: " + self.display_id
return "%s (%s)" % (self.service.name, self.display_id)
class ElementConnection(Model):
......@@ -70,4 +70,4 @@ class ElementConnection(Model):
parameters = models.TextField()
def __unicode__(self):
return self.target.service.name + ", " + str(self.id)
return "%s (%d)" % (self.target.service.name, self.id)
......@@ -7,6 +7,8 @@
{% block content %}
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link type="text/css" rel="stylesheet" href="{% static 'setty/style.css' %}">
<div class="row" id="workspace">
......@@ -14,16 +16,14 @@
<div class="panel panel-default initHidden" id="informationPanel">
<div class="panel-heading text-center">
<div class="row">
<div class="col-xs-2 text-left">
<div class="col-xs-10 text-left">
<h3 class="no-margin"><i class="fa fa-info"></i>&nbsp;{% trans 'Information' %}</h3>
</div>
<div class="col-xs-2">
<button class="btn btn-danger btn-xs" id="closeInfoPanel">
<i class="fa fa-times"></i>
</button>
</div>
<div class="col-xs-8">
<h3 class="no-margin">{% trans 'Information' %}</h3>
</div>
<div class="col-xs-2">
</div>
</div>
</div>
<div class="panel-body" id="informationContainer">
......@@ -36,7 +36,9 @@
<div class="panel panel-default text-center" id="dragPanel">
<div class="panel-heading">
<div class="row">
<h3 class="no-margin">{% trans 'Elements' %}</h3>
<div class="col-xs-12 text-left">
<h3 class="no-margin"><i class="fa fa-outdent"></i> {% trans 'Elements' %}</h3>
</div>
</div>
</div>
<div class="panel-heading text-center">
......@@ -90,17 +92,17 @@
<div class="panel panel-default">
<div class="panel-heading text-center">
<div class="row">
<div class="col-xs-2">
<div class="col-xs-2 text-left">
<button class="btn btn-info btn-xs" id="undoMovement" title="{% trans 'Undo' %}"><i class="fa fa-undo"></i></button>
</div>
<div class="col-xs-2">
<div class="col-xs-2 text-left">
<button class="btn btn-info btn-xs" id="redoMovement" title="{% trans 'Redo' %}"><i class="fa fa-repeat"></i></button>
</div>
<div class="col-xs-4">
<h3 class="no-margin" id="serviceName" contenteditable="true">Service</h3>
<h3 class="no-margin" id="serviceName">Service</h3>
</div>
<div class="col-xs-2 text-right">
<button class="btn btn-info btn-xs" id="clearService" title="{% trans 'Clear workspace' %}"><i class="fa fa-trash-o"></i></button>
<button class="btn btn-info btn-xs" id="clearService" title="{% trans 'Clear workspace' %}"><i class="fa fa-eraser"></i></button>
</div>
<div class="col-xs-2 text-right">
<button class="btn btn-success btn-xs" id="saveService" title="{% trans 'Save workspace' %}"><i class="fa fa-floppy-o"></i></button>
......@@ -109,12 +111,51 @@
</div>
<div class="panel-body" id="dropContainer" oncontextmenu="return false;"></div>
<div class="panel-footer no-margin text-left">
<div class="row">
<div class="col-xs-2 text-left">
<label class="no-margin" id="serviceStatus"></label>
</div>
<div class="col-xs-2 col-xs-push-8 text-right">
<button class="btn btn-danger btn-xs" id="deteleService" title="{% trans 'Delete service' %}" data-toggle="modal" data-target="#deleteServiceDialog"><i class="fa fa-trash-o"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
{% if actualId %}
<!-- Modal -->
<div id="deleteServiceDialog" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><i class="fa fa-trash-o"></i> {% trans 'Deleting service' %}</h4>
</div>
<div class="modal-body">
<p>{% trans 'Are you sure you want to delete this service?' %}</p>
</div>
<div class="modal-footer">
<div class="row">
<div class="col-xs-2 col-xs-push-8">
<form method="post" action="{% url 'setty.views.service-delete' actualId %}">
{% csrf_token %}
<input type="submit" class="btn btn-danger btn-sm" value="{% trans 'Delete' %}" />
</form>
</div>
<div class="col-xs-2 col-xs-push-8">
<button type="button" class="btn btn-primary btn-sm" data-dismiss="modal">{% trans 'Close' %}</button>
</div>
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% endblock %}
<!DOCTYPE html>
<form method="post">{% csrf_token %}
Are you sure you want to delete "{{ object }}" ?
<input type="submit" value="Submit" />
</form>
\ No newline at end of file
......@@ -20,7 +20,7 @@ from . import views
urlpatterns = [
url(r'^create/$',
views.IndexView.as_view(),
views.CreateView.as_view(),
name='setty.views.service-create'),
url(r'^delete/(?P<pk>\d+)$',
views.DeleteView.as_view(),
......@@ -28,6 +28,12 @@ urlpatterns = [
url(r'^start/(?P<pk>\d+)$',
views.StartView.as_view(),
name='setty.views.service-start'),
url(r'^stop/(?P<pk>\d+)$',
views.StopView.as_view(),
name='setty.views.service-start'),
url(r'^stop/(?P<pk>\d+)$',
views.StartView.as_view(),
name='setty.views.service-stop'),
url(r'^list/$',
views.ListView.as_view(),
name='setty.views.service-list'),
......
......@@ -15,67 +15,46 @@
# 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.template import RequestContext
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView, DeleteView
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse_lazy
from django.db.models import Q
from django.http import HttpResponseForbidden, Http404
from django.shortcuts import redirect
from django.contrib import auth
from .models import (
Element,
ElementTemplate,
ElementConnection,
Service
)
from django.http import JsonResponse
from braces.views import LoginRequiredMixin
from django.views.generic import TemplateView, DeleteView, CreateView
from .models import Element, ElementTemplate, ElementConnection, Service
import json
class IndexView(TemplateView):
class DetailView(LoginRequiredMixin, TemplateView):
template_name = "setty/index.html"
def get(self, request, *args, **kwargs):
if self.request.user.is_authenticated():
return TemplateView.get(self, request, *args, **kwargs)
else:
return redirect(auth.views.login)
def get_context_data(self, **kwargs):
elementTemplateList = ElementTemplate.objects.all()
context = RequestContext(
self.request,
{'elementTemplateList': elementTemplateList})
context = super(DetailView, self).get_context_data(**kwargs)
context['elementTemplateList'] = ElementTemplate.objects.all()
return context
@csrf_exempt
def post(self, request, *args, **kwargs):
if not self.request.user.is_authenticated():
return redirect(auth.views.login)
if self.request.POST.get('event') == "saveService":
jsonData = json.loads(self.request.POST.get('data'))
serviceName = jsonData['serviceName']
data = json.loads(self.request.POST.get('data'))
service_name = data['serviceName']
if 'pk' in kwargs:
serviceObject = Service.objects.get(id=kwargs['pk'])
serviceObject.name = serviceName
serviceObject.save()
service = Service.objects.get(id=kwargs['pk'])
service.name = service_name
service.save()
Element.objects.filter(service=serviceObject).delete()
Element.objects.filter(service=service).delete()
else:
serviceObject = Service(
name=serviceName,
service = Service(
name=service_name,
user=self.request.user
)
serviceObject.save()
service.save()
for element in jsonData['elements']:
for element in data['elements']:
elementObject = Element(
service=serviceObject,
service=service,
parameters=element['parameters'],
display_id=element['displayId'],
pos_x=element['posX'],
......@@ -84,7 +63,7 @@ class IndexView(TemplateView):
)
elementObject.save()
for elementConnection in jsonData['elementConnections']:
for elementConnection in data['elementConnections']:
sourceId = elementConnection['sourceId']
targetId = elementConnection['targetId']
sourceEndpoint = elementConnection['sourceEndpoint']
......@@ -93,11 +72,11 @@ class IndexView(TemplateView):
targetObject = Element.objects.get(
display_id=targetId,
service=serviceObject)
service=service)
sourceObject = Element.objects.get(
display_id=sourceId,
service=serviceObject)
service=service)
connectionObject = ElementConnection(
target=targetObject,
......@@ -108,46 +87,11 @@ class IndexView(TemplateView):
)
connectionObject.save()
return HttpResponse(serviceObject.pk)
else:
return HttpResponse()
class DeleteView(DeleteView):
model = Service
success_url = reverse_lazy("dashboard.index")
class StartView(TemplateView):
pass
class ListView(TemplateView):
pass
class DetailView(IndexView):
def get(self, request, *args, **kwargs):
try:
serviceObject = Service.objects.get(id=kwargs['pk'])
if serviceObject.user != self.request.user:
return HttpResponseForbidden(
"You don't have permission to open the service.")
except:
raise Http404
else:
return IndexView.get(self, request, *args, **kwargs)
@csrf_exempt
def post(self, request, *args, **kwargs):
if not self.request.user.is_authenticated():
return redirect(auth.views.login)
return JsonResponse({'serviceName': service.name})
if self.request.POST.get('event') == "loadService":
serviceObject = Service.objects.get(id=kwargs['pk'])
elementList = Element.objects.filter(service=serviceObject)
elif self.request.POST.get('event') == "loadService":
service = Service.objects.get(id=kwargs['pk'])
elementList = Element.objects.filter(service=service)
elementConnectionList = ElementConnection.objects.filter(
Q(target__in=elementList) | Q(source__in=elementList))
......@@ -160,20 +104,39 @@ class DetailView(IndexView):
'displayId': item.display_id,
'posX': item.pos_x,
'posY': item.pos_y,
'anchors': item.anchors
})
'anchors': item.anchors})
for item in elementConnectionList:
elementConnections.append({
'targetEndpoint': item.target_endpoint,
'sourceEndpoint': item.source_endpoint,
'parameters': item.parameters
})
'parameters': item.parameters})
return HttpResponse(json.dumps(
{"elements": elements,
"elementConnections": elementConnections,
"serviceName": serviceObject.name}))
return JsonResponse(
{'elements': elements,
'elementConnections': elementConnections,
'serviceName': service.name})
else:
return IndexView.post(self, request, *args, **kwargs)
raise PermissionDenied
class DeleteView(LoginRequiredMixin, DeleteView):
model = Service
success_url = reverse_lazy("dashboard.index")
class CreateView(LoginRequiredMixin, CreateView):
pass
class StartView(LoginRequiredMixin, TemplateView):
pass
class StopView(LoginRequiredMixin, TemplateView):
pass
class ListView(LoginRequiredMixin, TemplateView):
pass
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