Commit 37c7213d by Estók Dániel

Improved dashboard-integration and refactor.

parent 6aa74424
...@@ -53,7 +53,7 @@ class Element(Model): ...@@ -53,7 +53,7 @@ class Element(Model):
anchors = models.PositiveSmallIntegerField() anchors = models.PositiveSmallIntegerField()
def __unicode__(self): def __unicode__(self):
return self.service.name + ", id: " + self.display_id return "%s (%s)" % (self.service.name, self.display_id)
class ElementConnection(Model): class ElementConnection(Model):
...@@ -70,4 +70,4 @@ class ElementConnection(Model): ...@@ -70,4 +70,4 @@ class ElementConnection(Model):
parameters = models.TextField() parameters = models.TextField()
def __unicode__(self): def __unicode__(self):
return self.target.service.name + ", " + str(self.id) return "%s (%d)" % (self.target.service.name, self.id)
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
{% block content %} {% 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' %}"> <link type="text/css" rel="stylesheet" href="{% static 'setty/style.css' %}">
<div class="row" id="workspace"> <div class="row" id="workspace">
...@@ -14,16 +16,14 @@ ...@@ -14,16 +16,14 @@
<div class="panel panel-default initHidden" id="informationPanel"> <div class="panel panel-default initHidden" id="informationPanel">
<div class="panel-heading text-center"> <div class="panel-heading text-center">
<div class="row"> <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"> <button class="btn btn-danger btn-xs" id="closeInfoPanel">
<i class="fa fa-times"></i> <i class="fa fa-times"></i>
</button> </button>
</div> </div>
<div class="col-xs-8">
<h3 class="no-margin">{% trans 'Information' %}</h3>
</div>
<div class="col-xs-2">
</div>
</div> </div>
</div> </div>
<div class="panel-body" id="informationContainer"> <div class="panel-body" id="informationContainer">
...@@ -36,7 +36,9 @@ ...@@ -36,7 +36,9 @@
<div class="panel panel-default text-center" id="dragPanel"> <div class="panel panel-default text-center" id="dragPanel">
<div class="panel-heading"> <div class="panel-heading">
<div class="row"> <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> </div>
<div class="panel-heading text-center"> <div class="panel-heading text-center">
...@@ -90,17 +92,17 @@ ...@@ -90,17 +92,17 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading text-center"> <div class="panel-heading text-center">
<div class="row"> <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> <button class="btn btn-info btn-xs" id="undoMovement" title="{% trans 'Undo' %}"><i class="fa fa-undo"></i></button>
</div> </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> <button class="btn btn-info btn-xs" id="redoMovement" title="{% trans 'Redo' %}"><i class="fa fa-repeat"></i></button>
</div> </div>
<div class="col-xs-4"> <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>
<div class="col-xs-2 text-right"> <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>
<div class="col-xs-2 text-right"> <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> <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 @@ ...@@ -109,12 +111,51 @@
</div> </div>
<div class="panel-body" id="dropContainer" oncontextmenu="return false;"></div> <div class="panel-body" id="dropContainer" oncontextmenu="return false;"></div>
<div class="panel-footer no-margin text-left"> <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> <label class="no-margin" id="serviceStatus"></label>
</div> </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> </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 %} {% 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 ...@@ -20,7 +20,7 @@ from . import views
urlpatterns = [ urlpatterns = [
url(r'^create/$', url(r'^create/$',
views.IndexView.as_view(), views.CreateView.as_view(),
name='setty.views.service-create'), name='setty.views.service-create'),
url(r'^delete/(?P<pk>\d+)$', url(r'^delete/(?P<pk>\d+)$',
views.DeleteView.as_view(), views.DeleteView.as_view(),
...@@ -28,6 +28,12 @@ urlpatterns = [ ...@@ -28,6 +28,12 @@ urlpatterns = [
url(r'^start/(?P<pk>\d+)$', url(r'^start/(?P<pk>\d+)$',
views.StartView.as_view(), views.StartView.as_view(),
name='setty.views.service-start'), 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/$', url(r'^list/$',
views.ListView.as_view(), views.ListView.as_view(),
name='setty.views.service-list'), name='setty.views.service-list'),
......
...@@ -15,67 +15,46 @@ ...@@ -15,67 +15,46 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from django.template import RequestContext from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView, DeleteView
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponseForbidden, Http404 from django.http import JsonResponse
from django.shortcuts import redirect from braces.views import LoginRequiredMixin
from django.contrib import auth from django.views.generic import TemplateView, DeleteView, CreateView
from .models import ( from .models import Element, ElementTemplate, ElementConnection, Service
Element,
ElementTemplate,
ElementConnection,
Service
)
import json import json
class IndexView(TemplateView): class DetailView(LoginRequiredMixin, TemplateView):
template_name = "setty/index.html" 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): def get_context_data(self, **kwargs):
elementTemplateList = ElementTemplate.objects.all() context = super(DetailView, self).get_context_data(**kwargs)
context = RequestContext( context['elementTemplateList'] = ElementTemplate.objects.all()
self.request,
{'elementTemplateList': elementTemplateList})
return context return context
@csrf_exempt
def post(self, request, *args, **kwargs): 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": if self.request.POST.get('event') == "saveService":
jsonData = json.loads(self.request.POST.get('data')) data = json.loads(self.request.POST.get('data'))
service_name = data['serviceName']
serviceName = jsonData['serviceName']
if 'pk' in kwargs: if 'pk' in kwargs:
serviceObject = Service.objects.get(id=kwargs['pk']) service = Service.objects.get(id=kwargs['pk'])
serviceObject.name = serviceName service.name = service_name
serviceObject.save() service.save()
Element.objects.filter(service=serviceObject).delete() Element.objects.filter(service=service).delete()
else: else:
serviceObject = Service( service = Service(
name=serviceName, name=service_name,
user=self.request.user user=self.request.user
) )
serviceObject.save() service.save()
for element in jsonData['elements']: for element in data['elements']:
elementObject = Element( elementObject = Element(
service=serviceObject, service=service,
parameters=element['parameters'], parameters=element['parameters'],
display_id=element['displayId'], display_id=element['displayId'],
pos_x=element['posX'], pos_x=element['posX'],
...@@ -84,7 +63,7 @@ class IndexView(TemplateView): ...@@ -84,7 +63,7 @@ class IndexView(TemplateView):
) )
elementObject.save() elementObject.save()
for elementConnection in jsonData['elementConnections']: for elementConnection in data['elementConnections']:
sourceId = elementConnection['sourceId'] sourceId = elementConnection['sourceId']
targetId = elementConnection['targetId'] targetId = elementConnection['targetId']
sourceEndpoint = elementConnection['sourceEndpoint'] sourceEndpoint = elementConnection['sourceEndpoint']
...@@ -93,11 +72,11 @@ class IndexView(TemplateView): ...@@ -93,11 +72,11 @@ class IndexView(TemplateView):
targetObject = Element.objects.get( targetObject = Element.objects.get(
display_id=targetId, display_id=targetId,
service=serviceObject) service=service)
sourceObject = Element.objects.get( sourceObject = Element.objects.get(
display_id=sourceId, display_id=sourceId,
service=serviceObject) service=service)
connectionObject = ElementConnection( connectionObject = ElementConnection(
target=targetObject, target=targetObject,
...@@ -108,46 +87,11 @@ class IndexView(TemplateView): ...@@ -108,46 +87,11 @@ class IndexView(TemplateView):
) )
connectionObject.save() connectionObject.save()
return HttpResponse(serviceObject.pk) return JsonResponse({'serviceName': service.name})
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)
if self.request.POST.get('event') == "loadService": elif self.request.POST.get('event') == "loadService":
serviceObject = Service.objects.get(id=kwargs['pk']) service = Service.objects.get(id=kwargs['pk'])
elementList = Element.objects.filter(service=serviceObject) elementList = Element.objects.filter(service=service)
elementConnectionList = ElementConnection.objects.filter( elementConnectionList = ElementConnection.objects.filter(
Q(target__in=elementList) | Q(source__in=elementList)) Q(target__in=elementList) | Q(source__in=elementList))
...@@ -160,20 +104,39 @@ class DetailView(IndexView): ...@@ -160,20 +104,39 @@ class DetailView(IndexView):
'displayId': item.display_id, 'displayId': item.display_id,
'posX': item.pos_x, 'posX': item.pos_x,
'posY': item.pos_y, 'posY': item.pos_y,
'anchors': item.anchors 'anchors': item.anchors})
})
for item in elementConnectionList: for item in elementConnectionList:
elementConnections.append({ elementConnections.append({
'targetEndpoint': item.target_endpoint, 'targetEndpoint': item.target_endpoint,
'sourceEndpoint': item.source_endpoint, 'sourceEndpoint': item.source_endpoint,
'parameters': item.parameters 'parameters': item.parameters})
})
return HttpResponse(json.dumps( return JsonResponse(
{"elements": elements, {'elements': elements,
"elementConnections": elementConnections, 'elementConnections': elementConnections,
"serviceName": serviceObject.name})) 'serviceName': service.name})
else: 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