Zwischencommit 4 Agenturverbund

This commit is contained in:
holger.trampe 2020-04-12 20:52:31 +02:00
parent bf870a0951
commit d39aa9f2a4
7 changed files with 465 additions and 188 deletions

View File

@ -65,6 +65,8 @@ class Standards(models.Model):
# FIELD FOR AGENCYNETWORK
comments = models.ManyToManyField("StandardComments", blank=True, related_name='comments')
parent_standard = models.ForeignKey("Standards", related_name='partentedstandard', on_delete=models.PROTECT, blank=True, null=True, default=None)
shared_on = models.DateTimeField(default=timezone.now, blank=True)
#Counter, wie oft dieser Standard in eine andere Agentur kopiert wird

View File

@ -1,9 +1,42 @@
{% load counter_tag %}
<div class="row col">
<div class="card col-9" style="min-height: 500px">
<div class="card-body">
<h5 class="card-title"></h5>
<p class="card-text">
<canvas id="canvas"></canvas>
<div class="table-responsive">
<table class="table hover" id="agntable">
<thead>
<tr >
<th scope="col">Name</th>
<th scope="col">Erstelleragentur</th>
<th scope="col">Letzte Aktivität am</th>
<th scope="col">Agenturen</th>
<th scope="col">Standards</th>
</tr>
</thead>
<tbody id="">
{% for agn in agencynetworks %}
{% getsumofallag agn.pk as agsum %}
{% getoutstandinginvites agn.pk as outstanding %}
{% ifaginadminagn agn.pk request.user.profile.agency.pk as is_adminag %}
<tr onclick="window.location.href = '{% url 'standard-agn' agn.pk %}';" id="agn_{{agn.pk}}">
<td>{{agn.name}}</td>
<td>{{agn.creator_agency.name }}</td>
<td>{{agn.lastactivity}}</td>
<td>{{agsum}}</td>
<td>{{agn.standards.all|length}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</p>
</div>
</div>
@ -28,194 +61,39 @@
</div>
</div>
</div>
<style>
/* DATATABLES */
.paginate_button {
padding: 0px !important;
border: 0px !important;
}
</style>
<script type="text/javascript">
let resizeReset = function() {
w = canvasBody.width = window.innerWidth*0.55;
h = canvasBody.height = window.innerHeight/2;
}
const opts = {
particleColor: "rgb(200,200,200)",
lineColor: "rgb(200,200,200)",
particleAmount: 5,
defaultSpeed: 0.03,
variantSpeed: 0.4,
defaultRadius: 5,
variantRadius: 5,
linkRadius: 500,
};
function goToAgnStandard(agnid){
alert("GOTO " + agnid);
}
window.addEventListener("resize", function(){
deBouncer();
$(document).ready(function(){
$('#agntable').DataTable({
"language": {
"search" : "Suche",
"info": "Zeige _START_ bis _END_ von _TOTAL_ Einträgen",
"lengthMenu": "Zeige _MENU_ Einträge",
"zeroRecords": "Nichts gefunden",
"infoEmpty": "Keine Einträge",
"paginate": {
"first": "Erste",
"last": "Letzte",
"next": "Nächste",
"previous": "Zurück"
},
},
"buttons" : {
"className" : "btn-danger"
}
});
});
let deBouncer = function() {
clearTimeout(tid);
tid = setTimeout(function() {
resizeReset();
}, delay);
};
let checkDistance = function(x1, y1, x2, y2){
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
};
let linkPoints = function(point1, hubs){
for (let i = 0; i < hubs.length; i++) {
let distance = checkDistance(point1.x, point1.y, hubs[i].x, hubs[i].y);
let opacity = 1 - distance / opts.linkRadius;
if (opacity > 0) {
drawArea.lineWidth = 0.2;
drawArea.strokeStyle = "#CCCCCC";
drawArea.beginPath();
drawArea.moveTo(point1.x, point1.y);
drawArea.lineTo(hubs[i].x, hubs[i].y);
drawArea.closePath();
drawArea.stroke();
}
}
}
particles = [];
Particle = function(xPos, yPos){
this.name ="NAME";
this.agnid = "";
this.name_correction = 0;
this.x = Math.random() * (w*0.4)+250;
this.y = Math.random() * (h*0.4)+150;
this.speed = opts.defaultSpeed + Math.random() * opts.variantSpeed;
this.directionAngle = Math.floor(Math.random() * 360);
this.color = opts.particleColor;
this.radius = opts.defaultRadius;
this.vector = {
x: Math.cos(this.directionAngle) * this.speed,
y: Math.sin(this.directionAngle) * this.speed
};
this.update = function(){
this.border();
this.x += this.vector.x;
this.y += this.vector.y;
};
this.border = function(){
if (this.x >= w || this.x <= 0) {
this.vector.x *= -1;
}
if (this.y >= h || this.y <= 0) {
this.vector.y *= -1;
}
if (this.x > w) this.x = w;
if (this.y > h) this.y = h;
if (this.x < 0) this.x = 0;
if (this.y < 0) this.y = 0;
};
this.draw = function(){
drawArea.beginPath();
drawArea.arc(this.x, this.y, this.radius, 0, Math.PI*2);
drawArea.closePath();
drawArea.fillStyle = this.color;
drawArea.fill();
drawArea.font = "30px Arial";
drawArea.fillText(this.name, this.x-this.name_correction, this.y-15);
};
this.clicked = function(){
alert(1);
}
};
function getCursorPosition(canvas, event) {
const rect = canvas.getBoundingClientRect()
const x = event.clientX - rect.left
const y = event.clientY - rect.top
for (let i = 0; i < particles.length; i++){
x_border_l = Math.round(particles[i].x - 10);
x_border_r = Math.round(particles[i].x + 10);
y_border_l = Math.round(particles[i].y - 10);
y_border_r = Math.round(particles[i].y + 10);
if(x > x_border_l && x < x_border_r && y_border_r > y && y_border_l < y){
alert(particles[i].name + " ID: " + particles[i].agnid);
}
}
}
function getCursorPositionOver(canvas, event) {
const rect = canvas.getBoundingClientRect()
const x = event.clientX - rect.left
const y = event.clientY - rect.top
for (let i = 0; i < particles.length; i++){
x_border_l = Math.round(particles[i].x - 10);
x_border_r = Math.round(particles[i].x + 10);
y_border_l = Math.round(particles[i].y - 10);
y_border_r = Math.round(particles[i].y + 10);
if(x > x_border_l && x < x_border_r && y_border_r > y && y_border_l < y){
if(particles[i].radius < 25){
particles[i].radius = particles[i].radius+2.5;
}
}
else{
particles[i].radius = 5;
}
}
}
const canvas = document.querySelector('canvas')
canvas.addEventListener('mousedown', function(e) {
getCursorPosition(canvas, e)
})
canvas.addEventListener('mousemove', function(e) {
getCursorPositionOver(canvas, e)
})
function setup(){
resizeReset();
/*for (let i = 0; i < opts.particleAmount; i++){
p = new Particle();
particles.push( p );
}*/
{% for agn in agencynetworks %}
p_{{agn.pk}} = new Particle();
p_{{agn.pk}}.name = "{{agn.name}}";
p_{{agn.pk}}.agnid = {{agn.pk}};
particles.push( p_{{agn.pk}} );
{% endfor %}
window.requestAnimationFrame(loop);
}
function loop(){
window.requestAnimationFrame(loop);
drawArea.clearRect(0,0,w,h);
for (let i = 0; i < particles.length; i++){
particles[i].update();
particles[i].draw();
}
for (let i = 0; i < particles.length; i++){
linkPoints(particles[i], particles);
}
}
const canvasBody = document.getElementById("canvas"),
drawArea = canvasBody.getContext("2d");
let delay = 200, tid,
rgb = opts.lineColor.match(/\d+/g);
resizeReset();
setup();
</script>

View File

@ -0,0 +1,221 @@
<div class="row col">
<div class="card col-9" style="min-height: 500px">
<div class="card-body">
<h5 class="card-title"></h5>
<p class="card-text">
<canvas id="canvas"></canvas>
</p>
</div>
</div>
<div class="col-3">
<!--
<div class="card col-14 ml-1 mb-2" style="">
<div class="card-body">
<h5 class="card-title">UPDATES</h5>
<p class="card-text">
UPDATES
</p>
</div>
</div>-->
<div class="card col-14 ml-1 mb-2" style="">
<div class="card-body">
<h5 class="card-title">Beliebte Standards</h5>
<p class="card-text">
Keine
</p>
</div>
</div>
</div>
</div>
<script type="text/javascript">
let resizeReset = function() {
w = canvasBody.width = window.innerWidth*0.55;
h = canvasBody.height = window.innerHeight/2;
}
const opts = {
particleColor: "rgb(200,200,200)",
lineColor: "rgb(200,200,200)",
particleAmount: 5,
defaultSpeed: 0.03,
variantSpeed: 0.4,
defaultRadius: 5,
variantRadius: 5,
linkRadius: 500,
};
window.addEventListener("resize", function(){
deBouncer();
});
let deBouncer = function() {
clearTimeout(tid);
tid = setTimeout(function() {
resizeReset();
}, delay);
};
let checkDistance = function(x1, y1, x2, y2){
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
};
let linkPoints = function(point1, hubs){
for (let i = 0; i < hubs.length; i++) {
let distance = checkDistance(point1.x, point1.y, hubs[i].x, hubs[i].y);
let opacity = 1 - distance / opts.linkRadius;
if (opacity > 0) {
drawArea.lineWidth = 0.2;
drawArea.strokeStyle = "#CCCCCC";
drawArea.beginPath();
drawArea.moveTo(point1.x, point1.y);
drawArea.lineTo(hubs[i].x, hubs[i].y);
drawArea.closePath();
drawArea.stroke();
}
}
}
particles = [];
Particle = function(xPos, yPos){
this.name ="NAME";
this.agnid = "";
this.name_correction = 0;
this.x = Math.random() * (w*0.4)+250;
this.y = Math.random() * (h*0.4)+150;
this.speed = opts.defaultSpeed + Math.random() * opts.variantSpeed;
this.directionAngle = Math.floor(Math.random() * 360);
this.color = opts.particleColor;
this.radius = opts.defaultRadius;
this.vector = {
x: Math.cos(this.directionAngle) * this.speed,
y: Math.sin(this.directionAngle) * this.speed
};
this.update = function(){
this.border();
this.x += this.vector.x;
this.y += this.vector.y;
};
this.border = function(){
if (this.x >= w || this.x <= 0) {
this.vector.x *= -1;
}
if (this.y >= h || this.y <= 0) {
this.vector.y *= -1;
}
if (this.x > w) this.x = w;
if (this.y > h) this.y = h;
if (this.x < 0) this.x = 0;
if (this.y < 0) this.y = 0;
};
this.draw = function(){
drawArea.beginPath();
drawArea.arc(this.x, this.y, this.radius, 0, Math.PI*2);
drawArea.closePath();
drawArea.fillStyle = this.color;
drawArea.fill();
drawArea.font = "30px Arial";
drawArea.fillText(this.name, this.x-this.name_correction, this.y-15);
};
this.clicked = function(){
alert(1);
}
};
function getCursorPosition(canvas, event) {
const rect = canvas.getBoundingClientRect()
const x = event.clientX - rect.left
const y = event.clientY - rect.top
for (let i = 0; i < particles.length; i++){
x_border_l = Math.round(particles[i].x - 10);
x_border_r = Math.round(particles[i].x + 10);
y_border_l = Math.round(particles[i].y - 10);
y_border_r = Math.round(particles[i].y + 10);
if(x > x_border_l && x < x_border_r && y_border_r > y && y_border_l < y){
alert(particles[i].name + " ID: " + particles[i].agnid);
}
}
}
function getCursorPositionOver(canvas, event) {
const rect = canvas.getBoundingClientRect()
const x = event.clientX - rect.left
const y = event.clientY - rect.top
for (let i = 0; i < particles.length; i++){
x_border_l = Math.round(particles[i].x - 10);
x_border_r = Math.round(particles[i].x + 10);
y_border_l = Math.round(particles[i].y - 10);
y_border_r = Math.round(particles[i].y + 10);
if(x > x_border_l && x < x_border_r && y_border_r > y && y_border_l < y){
if(particles[i].radius < 25){
particles[i].radius = particles[i].radius+2.5;
}
}
else{
particles[i].radius = 5;
}
}
}
const canvas = document.querySelector('canvas')
canvas.addEventListener('mousedown', function(e) {
getCursorPosition(canvas, e)
})
canvas.addEventListener('mousemove', function(e) {
getCursorPositionOver(canvas, e)
})
function setup(){
resizeReset();
/*for (let i = 0; i < opts.particleAmount; i++){
p = new Particle();
particles.push( p );
}*/
{% for agn in agencynetworks %}
p_{{agn.pk}} = new Particle();
p_{{agn.pk}}.name = "{{agn.name}}";
p_{{agn.pk}}.agnid = {{agn.pk}};
particles.push( p_{{agn.pk}} );
{% endfor %}
window.requestAnimationFrame(loop);
}
function loop(){
window.requestAnimationFrame(loop);
drawArea.clearRect(0,0,w,h);
for (let i = 0; i < particles.length; i++){
particles[i].update();
particles[i].draw();
}
for (let i = 0; i < particles.length; i++){
linkPoints(particles[i], particles);
}
}
const canvasBody = document.getElementById("canvas"),
drawArea = canvasBody.getContext("2d");
let delay = 200, tid,
rgb = opts.lineColor.match(/\d+/g);
resizeReset();
setup();
</script>

View File

@ -0,0 +1,86 @@
{% extends "users/base.html" %}
{% load counter_tag %}
{% block content %}
<div class="content-section col-12">
<h3>Standards aus Agenturverbund {{agn.name}}</h3>
<small>Sie sehen nur veröffentlichte Standards innerhalb des Verbunds und Standards, die nicht von Ihrer Agentur geteilt sind.</small>
<hr>
<h4 class="mt-4 mb-4"></h4>
<div class="table-responsive">
<table class="table hover" id="agnstandards">
<thead>
<tr>
<th scope="col">Titel</th>
<th scope="col">Agentur</th>
<th scope="col">Zuletzt geändert am</th>
<th scope="col">Geteilt</th>
</tr>
</thead>
<tbody>
{% for standard in standards_of_agency_network %}
{% if standard.public and standard.agency != request.user.profile.agency %}
<tr>
<td><a href="{% url 'standard-single-agn' standard.pk %}">{{standard.name}}</a></td>
<td>{{standard.agency.name}}</td>
<td>{{standard.last_modified_on|date:"d.m.Y, H:i"}}</td>
<td>{{standard.agencynetworkcounter}}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#agnstandards').DataTable({
responsive: true,
"language": {
"search" : "Suche",
"zeroRecords": "Nichts gefunden",
"infoEmpty": "Keine Einträge",
"info": "Zeige _START_ bis _END_ von _TOTAL_ Einträgen",
"lengthMenu": "Zeige _MENU_ Einträge",
"paginate": {
"first": "Erste",
"last": "Letzte",
"next": "Nächste",
"previous": "Zurück"
},
},
"buttons" : {
"className" : "btn-danger"
}
});
})
</script>
<style>
/* DATATABLES */
.paginate_button {
padding: 0px !important;
border: 0px !important;
}
</style>
{% endblock content %}

View File

@ -0,0 +1,64 @@
{% extends "users/base.html" %}
{% load counter_tag %}
{% block content %}
<div class="content-section col-12">
<h2>{{standard.name}}</h2>
<hr>
<div class="row col">
{% if standard.addedfiles.all|length > 0 or standard.linked_standards.all|length > 0 or standard.authority.count > 0 or standard.executor.count > 0 or standard.representative.count > 0 or standard.addedfiles.all|length > 0 or standard.linked_standards.all|length > 0 or standard.freefield_title|length > 0 %}
<div class="card col-9" style="min-height: 500px">
{% else %}
<div class="card col-12" style="min-height: 500px">
{% endif %}
<div class="card-body">
<h5 class="card-title"></h5>
<p class="card-text">
{{standard.media}}
{{standard.content|safe}}
</p>
</div>
</div>
<div class="col-3">
{% if standard.freefield_title|length > 0 %}
<div class="card col-14 ml-1 mb-2" style="">
<div class="card-body">
<h5 class="card-title">{{standard.freefield_title}}</h5>
<p class="card-text">
{{standard.freefield_content}}
</p>
</div>
</div>
{% endif %}
<!-- FILES -->
{% if standard.addedfiles.all|length > 0 %}
<div class="card col-14 ml-1 mb-2" style="">
<div class="card-body">
<h5 class="card-title">Dateien</h5>
<p class="card-text">
{% for files in standard.addedfiles.all %}
{{files.name|truncatechars:30}}
{% endfor %}
</p>
</div>
</div>
{% endif %}
<!-- STANDARDS -->
</div>
</div>
<div class="mt-2">
<small>
Erstellt in Agentur <b>{{standard.agency.name}}</b> und zuletzt bearbeitet am {{ standard.last_modified_on}}. Der Standard wurde bereits {{standard.agencynetworkcounter}} geteilt.
</small>
</div>
</div>
{% endblock content %}

View File

@ -16,6 +16,8 @@ urlpatterns = [
path('standards/<int:pk>/delete', StandardDeleteView.as_view(), name='standard-delete'),
path('standard/<int:pk>/changestat', views.StandardChangePublic, name="standard-status"),
path('standard/<int:pk>/single', views.StandardSingle, name="standard-single"),
path('standard/<int:pk>/singleagn', views.StandardSingleAgn, name="standard-single-agn"),
path('standard/<int:pk>/area', views.StandardArea, name="standard-area"),
path('standard/<int:pk>/task', views.StandardTask, name="standard-task")
path('standard/<int:pk>/task', views.StandardTask, name="standard-task"),
path('standardsagn/<int:pk>', views.StandardFromAgn, name="standard-agn"),
]

View File

@ -44,6 +44,7 @@ class StandardsManagement(LoginRequiredMixin, ListView):
context.update({'active_link' : 'standards', 'unpubstandards_of_user' : unpubstandards_of_user, 'areas' : areas, 'standards_of_user' : standards_of_user, 'standardcontent' : standardcontent, "agencynetworks" : agencynetworks})
return context
@ -373,6 +374,15 @@ def StandardSingle(request, pk):
}
return render(request, 'standards/standards_noentrie.html', context)
@login_required
def StandardSingleAgn(request, pk):
context = {
'active_link':'standards',
'standard' : Standards.objects.get(pk=pk)
}
return render(request, 'standards/standards_single_agn.html', context)
@login_required
def StandardArea(request, pk):
@ -463,3 +473,17 @@ def updatesbyajax(request, pk):
success = False
return JsonResponse({"success" : success})
@login_required
def StandardFromAgn(request, pk):
agn = AgencyNetwork.objects.get(pk=pk)
print(agn.standards.all())
context = {
'active_link':'standards',
'standards_of_agency_network' : agn.standards.all(),
'agn' :agn,
}
return render(request, 'standards/standards_from_agn.html', context)