Skip to content

Commit

Permalink
Merge pull request #146 from nyrocron/map-child-ordering
Browse files Browse the repository at this point in the history
add dropdown for moving systems up/down on the map
  • Loading branch information
marbindrakon committed Apr 11, 2015
2 parents 1ed75ac + e7a839d commit 14fc279
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 13 deletions.
50 changes: 44 additions & 6 deletions evewspace/Map/models.py
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.db import models
from django.db import models, transaction
from django.conf import settings
from django.contrib.auth.models import Group
from core.models import SystemData
Expand Down Expand Up @@ -517,14 +517,52 @@ def promote_system(self, user):
True)

def move_up(self):
"""Assigns this system the highest display priority of its siblings"""
"""Switch display priority with the sibling above"""
if not self.parentsystem:
return

max_priority = self.parentsystem.childsystems.aggregate(
max_prio=models.Max('display_order_priority'))['max_prio']
self.display_order_priority = max_priority + 1
self.save()
with transaction.atomic():
siblings = self.parentsystem.childsystems.order_by(
'-display_order_priority', '-pk')
i = siblings.count()
it = siblings.iterator()
while True:
try:
mapsys = it.next()
if self == mapsys:
next_mapsys = it.next()
next_mapsys.display_order_priority = i
next_mapsys.save()
i -= 1
except StopIteration:
break
mapsys.display_order_priority = i
mapsys.save()
i -= 1

def move_down(self):
"""Switch display priority with the sibling below"""
if not self.parentsystem:
return

with transaction.atomic():
siblings = self.parentsystem.childsystems.order_by(
'display_order_priority', 'pk')
i = 0
it = siblings.iterator()
while True:
try:
mapsys = it.next()
if self == mapsys:
next_mapsys = it.next()
next_mapsys.display_order_priority = i
next_mapsys.save()
i += 1
except StopIteration:
break
mapsys.display_order_priority = i
mapsys.save()
i += 1

def as_dict(self):
"""Returns a dict representation of the system."""
Expand Down
3 changes: 3 additions & 0 deletions evewspace/Map/static/css/map.css
Expand Up @@ -323,3 +323,6 @@ fieldset.addSystemWormholeType label.checkbox input[type="checkbox"] {
margin: 0.8em 0.2em;
}

ul#moveDropdown li {
cursor: pointer;
}
4 changes: 2 additions & 2 deletions evewspace/Map/static/js/map_functions.js
Expand Up @@ -1666,8 +1666,8 @@ function togglepilotlist() {
RefreshMap();
}

function MoveSystemUp(msID) {
var address = "system/" + msID + "/moveup/";
function MoveSystem(msID, action) {
var address = "system/" + msID + "/movesys/" + action + "/";
$.ajax({
url: address,
type: "POST",
Expand Down
10 changes: 9 additions & 1 deletion evewspace/Map/templates/system_menu.html
Expand Up @@ -26,7 +26,15 @@
<a class="btn btn-small" onclick="GetAddSystemDialog({{mapsys.pk}});">Add System</a>
{% endif %}
{% if can_edit and mapsys.has_siblings %}
<a class="btn btn-small" onclick="MoveSystemUp({{mapsys.pk}});">Move Up</a>
<div id="moveButton" class="btn-group dropdown">
<a class="btn btn-small dropdown-toggle" data-toggle="dropdown">
Move <span class="caret"></span>
</a>
<ul id="moveDropdown" class="dropdown-menu" role="menu">
<li><a onclick="MoveSystem({{mapsys.pk}}, 'up');">Up</a></li>
<li><a onclick="MoveSystem({{mapsys.pk}}, 'down');">Down</a></li>
</ul>
</div>
{% endif %}
{% if perms.SiteTracker.can_sitetracker and not stfleets|length %}
<a class="btn btn-small" onclick="STCreateFleet({{mapsys.system.pk}});">ST Fleet Here</a>
Expand Down
2 changes: 1 addition & 1 deletion evewspace/Map/urls.py
Expand Up @@ -45,7 +45,7 @@
url(r'^signatures/(?P<sig_id>\d+)/', include(sigpatterns)),
url(r'^collapse/$', 'collapse_system'),
url(r'^resurrect/$', 'resurrect_system'),
url(r'^moveup/$', 'move_system_up'),
url(r'^movesys/(?P<action>up|down)/$', 'move_system'),
)

wormholepatterns = patterns(
Expand Down
2 changes: 1 addition & 1 deletion evewspace/Map/utils.py
Expand Up @@ -217,7 +217,7 @@ def create_syslist(self):

# sort children by priority
for l in children.values():
l.sort(key=priorities.__getitem__, reverse=True)
l.sort(key=priorities.__getitem__)

columns = []
todo = [(children[None][0], 0)]
Expand Down
10 changes: 8 additions & 2 deletions evewspace/Map/views.py
Expand Up @@ -1392,13 +1392,19 @@ def purge_signatures(request, map_id, ms_id):
return HttpResponse(status=400)

@require_map_permission(permission=2)
def move_system_up(request, map_id, ms_id):
def move_system(request, map_id, ms_id, action):
if not request.is_ajax():
raise PermissionDenied
if not request.method == "POST":
return HttpResponse(status=400)

mapsys = get_object_or_404(MapSystem, pk=ms_id)
mapsys.move_up()
if action == 'up':
mapsys.move_up()
elif action == 'down':
mapsys.move_down();
else:
raise Http404

return HttpResponse()

0 comments on commit 14fc279

Please sign in to comment.