diff --git a/commentaries/forms.py b/commentaries/forms.py index 03d3c775317673029a5e17bd73b0f6ae88ba3c73..c1a092475a3a594fb6f4393317cd1164a966d0dc 100644 --- a/commentaries/forms.py +++ b/commentaries/forms.py @@ -23,7 +23,11 @@ class DOIToQueryForm(forms.Form): class RequestCommentaryForm(forms.ModelForm): class Meta: model = Commentary - fields = ['type', 'discipline', 'domain', 'specialization', 'pub_title', 'author_list', 'pub_date', 'arxiv_link', 'pub_DOI_link', 'pub_abstract'] + fields = ['type', 'discipline', 'domain', 'specialization', + 'pub_title', 'author_list', + 'journal', 'volume', 'pages', 'pub_date', + 'arxiv_link', + 'pub_DOI_link', 'pub_abstract'] def __init__(self, *args, **kwargs): super(RequestCommentaryForm, self).__init__(*args, **kwargs) diff --git a/commentaries/models.py b/commentaries/models.py index 7fd5fad79ae8a4b6a95ff122449cf2ece423eeaa..f9accb16d53dee467435411a59f0a1761fe223bc 100644 --- a/commentaries/models.py +++ b/commentaries/models.py @@ -33,6 +33,9 @@ class Commentary(models.Model): authors = models.ManyToManyField (Contributor, blank=True, related_name='authors_com') authors_claims = models.ManyToManyField (Contributor, blank=True, related_name='authors_com_claims') authors_false_claims = models.ManyToManyField (Contributor, blank=True, related_name='authors_com_false_claims') + journal = models.CharField(max_length=300, blank=True, null=True) + volume = models.CharField(max_length=50, blank=True, null=True) + pages = models.CharField(max_length=50, blank=True, null=True) pub_date = models.DateField(verbose_name='date of original publication', blank=True, null=True) pub_abstract = models.TextField(verbose_name='abstract') latest_activity = models.DateTimeField(default=timezone.now) diff --git a/commentaries/templates/commentaries/request_commentary.html b/commentaries/templates/commentaries/request_commentary.html index cd2ce8f1ca040a1c8dd74655a786ecef7150783d..cf2a5f63101f41055bec41d3e52785e976c7c245 100644 --- a/commentaries/templates/commentaries/request_commentary.html +++ b/commentaries/templates/commentaries/request_commentary.html @@ -15,8 +15,8 @@ $(this).hide() }) - var preprint = [5,7] - var published = [6] + var preprint = [5,6,7,8,10] + var published = [9] function show(indices){ allToggableRows.each(function(index){ diff --git a/commentaries/views.py b/commentaries/views.py index 2c51e4b5be5f0fb80535f0bb12790195fbfc2936..b55ada04d696a78dd0063aa0d99f3d71d51b4652 100644 --- a/commentaries/views.py +++ b/commentaries/views.py @@ -73,9 +73,13 @@ def prefill_using_DOI(request): doiqueryJSON['message']['author'][0]['family']) for author in doiqueryJSON['message']['author'][1:]: authorlist += ', ' + author['given'] + ' ' + author['family'] + journal = doiqueryJSON['message']['container-title'][1] + volume = doiqueryJSON['message']['volume'] + pages = doiqueryJSON['message']['article-number'] form = RequestCommentaryForm( initial={'pub_title': pub_title, - 'author_list': authorlist}) + 'author_list': authorlist, + 'journal': journal, 'volume': volume, 'pages': pages}) context = {'form': form, 'doiform': doiform} context['title'] = pub_title return render(request, 'commentaries/request_commentary.html', context) diff --git a/scipost/management/commands/add_groups_and_permissions.py b/scipost/management/commands/add_groups_and_permissions.py index f7fed8ffc379abc4b27cfbf69d3421d59da6de68..b77616a3defb65e409b3dc29761a172ebd57c6c8 100644 --- a/scipost/management/commands/add_groups_and_permissions.py +++ b/scipost/management/commands/add_groups_and_permissions.py @@ -93,23 +93,6 @@ class Command(BaseCommand): name= 'Can act as a referee and submit reports on Submissions', content_type=content_type) -# # Lists -# can_create_list, created = Permission.objects.get_or_create( -# codename='can_create_list', -# name= 'Can create a new List', -# content_type=content_type) -# # Teams -# can_create_team, created = Permission.objects.get_or_create( -# codename='can_create_team', -# name= 'Can create a new Team', -# content_type=content_type) -# # Graphs -# can_create_graph, created = Permission.objects.get_or_create( -# codename='can_create_graph', -# name= 'Can create a new Graph', -# content_type=content_type) - - # Assign permissions to groups SciPostAdmin.permissions.add(can_manage_registration_invitations, diff --git a/scipost/static/scipost/SciPost.css b/scipost/static/scipost/SciPost.css index 07b051957110c32bac74b5fab586b98703c64b44..7c8c7babb515df8b30aff97de21c5eb276ed4589 100644 --- a/scipost/static/scipost/SciPost.css +++ b/scipost/static/scipost/SciPost.css @@ -108,6 +108,30 @@ ul.personalTabMenu li a.inactive { background-color: #eeeeff; } +.AddItemToList { + background-color: #000099; + border: 1px; + color: white; + padding: 4px; + font-size: 50%; +} +.RemoveItemFromList { + background-color: #990000; + border: 1px; + color: white; + padding: 4px; + font-size: 50%; +} + +.GraphButton { + background-color: #dddddd; + font-size: 50%; + padding: 4px; +} +.GraphButton h1 { + padding: 1px; +} + .reportid { display: inline-block; box-shadow: 5px 5px 10px #888888; diff --git a/scipost/templates/scipost/edit_graph_node.html b/scipost/templates/scipost/edit_graph_node.html index 2ff59425f4e628ce0aea493045414a2553f4bc6b..09e9db0715bcd8aa10e8a0d945860607fd3d1846 100644 --- a/scipost/templates/scipost/edit_graph_node.html +++ b/scipost/templates/scipost/edit_graph_node.html @@ -12,7 +12,7 @@ {% else %} - <form action="{% url 'scipost:edit_graph_node' graph_id=graph.id node_id=node.id %}" method="post"> + <form action="{% url 'scipost:edit_graph_node' node_id=node.id %}" method="post"> {% csrf_token %} <table> {{ edit_node_form.as_table }} diff --git a/scipost/templates/scipost/graph.html b/scipost/templates/scipost/graph.html index cc3b66c52202f8aeffe79f9059de01d4ac937c16..ac3ec912134a6590c69f1799f278a53df932dbee 100644 --- a/scipost/templates/scipost/graph.html +++ b/scipost/templates/scipost/graph.html @@ -34,21 +34,27 @@ text { $(document).ready(function(){ +$(".node_contents").hide(); +$(".delete_node").hide(); + +$("#NodeForm").hide(); +$("#LinkForm").hide(); $("#ManageTeamsForm").hide(); + $("#ManageTeamsFormButton").click(function(){ $("#ManageTeamsForm").toggle(); -}); - -$(".node_contents").hide(); $("#NodeForm").hide(); $("#LinkForm").hide(); +}); $("#NodeFormButton").click(function(){ +$("#ManageTeamsForm").hide(); $("#NodeForm").toggle(); $("#LinkForm").hide(); }); $("#LinkFormButton").click(function(){ +$("#ManageTeamsForm").hide(); $("#NodeForm").hide(); $("#LinkForm").toggle(); }); @@ -58,9 +64,11 @@ d3.json("{% url 'scipost:api_graph' graph_id=graph.id %}", function(error, json) if (error) return console.warn(error); var nodesjson = json['nodes']; -var nodes = {}; +var nodes = []; nodesjson.forEach(function(node) { nodes[node.name] = node; + nodes[node.name].x = 300 + 100 * Math.random(); + nodes[node.name].y = 150 + 100 * Math.random(); }); var links = json['links']; @@ -69,18 +77,35 @@ links.forEach(function(link) { link.target = nodes[link.target]; }); -var width = 700, - height = 300; +var width = 600; +var height = 300; var force = d3.layout.force() .nodes(d3.values(nodes)) .links(links) .size([width, height]) - .linkDistance(100) - .charge(-300) + .friction(0.9) + .linkStrength(1) + .linkDistance(80) + .charge(-400) + .gravity(0.1) + .theta(0.8) + .alpha(0.1) .on("tick", tick) .start(); + +// .call(d3.behavior.zoom().on("zoom", rescale)) +function rescale() { + trans=d3.event.translate; + scale=d3.event.scale; + + vis.attr("transform", + "translate(" + trans + ")" + + " scale(" + scale + ")"); +} + + var svg = d3.select("#graphic").append("svg") .attr("width", width) .attr("height", height); @@ -113,11 +138,13 @@ circle.on("click", function(){ d3.selectAll("circle").style("fill", "#ccc"); d3.select(this).style("fill", "blue"); $(".node_contents").hide(); + $(".delete_node").hide(); $(".node_id" + $(this).attr("id")).show(); }); -circle.on("dblclick", function() - {d3.select(this).style("fill", "red");}); +circle.on("dblclick", function(){ + d3.select(this).style("fill", "red"); +}); var text = svg.append("g").selectAll("text") .data(force.nodes()) @@ -170,16 +197,16 @@ function transform(d) { {% if "change_graph" in graph_perms %} <div class="row"> - <div class="col-3"> + <div class="col-2"> {% if graph.private %} - <button id="ManageTeamsFormButton"><h1>Manage Team(s)</h1> (show/hide form)</button> + <button class="GraphButton" id="ManageTeamsFormButton"><h1>Manage Team(s)</h1></button> <form action="{% url 'scipost:graph' graph_id=graph.id %}" method="post" id="ManageTeamsForm"> {% csrf_token %} {{ attach_teams_form }} <input type="submit" value="Submit" /> </form> {% endif %} - <button id="NodeFormButton"><h1>Add a Node</h1> (show/hide form)</button> + <button class="GraphButton" id="NodeFormButton"><h1>Add a Node</h1></button> <form action="{% url 'scipost:graph' graph_id=graph.id %}" method="post" id="NodeForm"> {% csrf_token %} <table> @@ -187,7 +214,7 @@ function transform(d) { </table> <input type="submit" value="Create Node" /> </form> - <button id="LinkFormButton"><h1>Add a Link</h1> (show/hide form)</button> + <button class="GraphButton" id="LinkFormButton"><h1>Add a Link</h1></button> <form action="{% url 'scipost:graph' graph_id=graph.id %}" method="post" id="LinkForm"> {% csrf_token %} <table> @@ -196,7 +223,7 @@ function transform(d) { <input type="submit" value="Create Link" /> </form> </div> - <div class="col-9"> + <div class="col-10"> <div id="graphic"></div> </div> </div> @@ -210,7 +237,8 @@ function transform(d) { {% for node in nodes %} {{ node.contents }} - <a href="{% url 'scipost:edit_graph_node' graph_id=graph.id node_id=node.id %}" class="node_contents node_id{{ node.id}}">Edit this Node's contents</a> + <a href="{% url 'scipost:edit_graph_node' node_id=node.id %}" class="node_contents node_id{{ node.id }}" style="margin: 10px;">Edit this Node's contents</a> + <a href="{% url 'scipost:delete_graph_node' node_id=node.id %}" class="delete_node node_id{{ node.id }}" style="color: red; margin: 10px;">Delete this Node</a> {% endfor %} diff --git a/scipost/templates/scipost/list.html b/scipost/templates/scipost/list.html index 64ce0dcf0fc10b4530f3a93443facb7e83cb7761..006f57fbfbf18bb2773eeec4e0492de818972547 100644 --- a/scipost/templates/scipost/list.html +++ b/scipost/templates/scipost/list.html @@ -45,7 +45,7 @@ {{ commentary.header_as_li }} <form action="{% url 'scipost:list_add_element' list_id=list.id type='C' element_id=commentary.id %}" method="post"> {% csrf_token %} - <input type="submit" value="Add to List"/> + <input class="AddItemToList" type="submit" value="Add"/> </form> {% endfor %} </ul> @@ -60,7 +60,7 @@ {{ submission.header_as_li }} <form action="{% url 'scipost:list_add_element' list_id=list.id type='S' element_id=submission.id %}" method="post"> {% csrf_token %} - <input type="submit" value="Add to List"/> + <input class="AddItemToList" type="submit" value="Add"/> </form> {% endfor %} </ul> @@ -75,7 +75,7 @@ {{ thesislink.header_as_li }} <form action="{% url 'scipost:list_add_element' list_id=list.id type='T' element_id=thesislink.id %}" method="post"> {% csrf_token %} - <input type="submit" value="Add to List"/> + <input class="AddItemToList" type="submit" value="Add"/> </form> {% endfor %} </ul> @@ -90,7 +90,7 @@ {{ comment.header_as_li }} <form action="{% url 'scipost:list_add_element' list_id=list.id type='c' element_id=comment.id %}" method="post"> {% csrf_token %} - <input type="submit" value="Add to List"/> + <input class="AddItemToList" type="submit" value="Add"/> </form> {% endfor %} </ul> diff --git a/scipost/templates/scipost/list_contents.html b/scipost/templates/scipost/list_contents.html index b508f95cd8b48faa60223c4ed661a59b2811e53d..12597bdeb112ae8fb7874de8b1d4b4364cf16ff4 100644 --- a/scipost/templates/scipost/list_contents.html +++ b/scipost/templates/scipost/list_contents.html @@ -22,7 +22,7 @@ {% if "change_list" in list_perms %} <form action="{% url 'scipost:list_remove_element' list_id=list.id type='S' element_id=sub.id %}" method="post"> {% csrf_token %} - <input type="submit" value="Remove from List"/> + <input class="RemoveItemFromList" type="submit" value="Remove"/> </form> {% endif %} {% endfor %} @@ -38,7 +38,7 @@ {% if "change_list" in list_perms %} <form action="{% url 'scipost:list_remove_element' list_id=list.id type='C' element_id=com.id %}" method="post"> {% csrf_token %} - <input type="submit" value="Remove from List"/> + <input class="RemoveItemFromList" type="submit" value="Remove"/> </form> {% endif %} {% endfor %} @@ -54,7 +54,7 @@ {% if "change_list" in list_perms %} <form action="{% url 'scipost:list_remove_element' list_id=list.id type='T' element_id=tl.id %}" method="post"> {% csrf_token %} - <input type="submit" value="Remove from List"/> + <input class="RemoveItemFromList" type="submit" value="Remove"/> </form> {% endif %} {% endfor %} @@ -70,7 +70,7 @@ {% if "change_list" in list_perms %} <form action="{% url 'scipost:list_remove_element' list_id=list.id type='c' element_id=comment.id %}" method="post"> {% csrf_token %} - <input type="submit" value="Remove from List"/> + <input class="RemoveItemFromList" type="submit" value="Remove"/> </form> {% endif %} {% endfor %} diff --git a/scipost/urls.py b/scipost/urls.py index 9a64dc3c5dc44d41426fa694ba00b16731e7d9e9..ae5c4f0b4668ead9e90f6613212bcc109f8fde6e 100644 --- a/scipost/urls.py +++ b/scipost/urls.py @@ -78,5 +78,6 @@ urlpatterns = [ url(r'^create_graph$', views.create_graph, name='create_graph'), url(r'^graph/(?P<graph_id>[0-9]+)$', views.graph, name='graph'), url(r'^edit_graph_node/(?P<node_id>[0-9]+)$', views.edit_graph_node, name='edit_graph_node'), + url(r'^delete_graph_node/(?P<node_id>[0-9]+)$', views.delete_graph_node, name='delete_graph_node'), url(r'^api/graph/(?P<graph_id>[0-9]+)$', views.api_graph, name='api_graph'), ] diff --git a/scipost/views.py b/scipost/views.py index 1a9062d0c601d7c578a7c3ac5061709569f86ccf..9590fd2e70d0fb27e9846b63aadd487ceba6ead2 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -11,6 +11,7 @@ from django.contrib.auth.decorators import login_required #from django.contrib.auth.decorators import permission_required # Superseded by guardian from django.contrib.auth.models import User, Group, Permission from django.contrib.auth.views import password_reset, password_reset_confirm +from django.core.exceptions import PermissionDenied from django.core.mail import EmailMessage from django.core.urlresolvers import reverse from django.http import HttpResponse, HttpResponseRedirect, JsonResponse @@ -883,8 +884,9 @@ def graph(request, graph_id): elif create_link_form.has_changed() and create_link_form.is_valid(): sourcenode = create_link_form.cleaned_data['source'] targetnode = create_link_form.cleaned_data['target'] - targetnode.arcs_in.add(sourcenode) - targetnode.save() + if sourcenode != targetnode: + targetnode.arcs_in.add(sourcenode) + targetnode.save() else: attach_teams_form = ManageTeamsForm(contributor=request.user.contributor, initial={'teams_with_access': graph.teams_with_access.all()} @@ -921,6 +923,21 @@ def edit_graph_node(request, node_id): return render(request, 'scipost/edit_graph_node.html', context) +def delete_graph_node(request, node_id): + node = get_object_or_404(Node, pk=node_id) + errormessage = '' + if not request.user.has_perm('scipost.change_graph', node.graph): + raise PermissionDenied + else: + # Remove all the graph arcs + nodes = Node.objects.filter(graph=node.graph) + for othernode in nodes: + othernode.arcs_in.remove(node) + othernode.save() + node.delete() + return redirect(reverse('scipost:graph', kwargs={'graph_id': node.graph.id})) + + @permission_required_or_403('scipost.view_graph', (Graph, 'id', 'graph_id')) def api_graph(request, graph_id): """ Produce JSON data to plot graph """