Skip to content

Commit

Permalink
Start of an admin area. #14 #15.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Conway committed Aug 29, 2012
1 parent e4909cb commit 620046c
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 2 deletions.
84 changes: 84 additions & 0 deletions app/controllers/Admin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package controllers;


import java.util.List;
import java.math.BigInteger;

import javax.persistence.Query;

import play.db.jpa.JPA;

import models.MetroArea;
import models.NtdAgency;

public class Admin extends Mapper {
/**
* The main admin screen.
*/
public static void index () {
// get counts for various types of problems
// Feeds with no agency
Query q = JPA.em().createNativeQuery("SELECT count(*) FROM GtfsFeed WHERE review = 'NO_AGENCY'");
List<BigInteger> results = q.getResultList();
int feedsNoAgency = results.get(0).intValue();

q = JPA.em().createNativeQuery("SELECT count(*) FROM NtdAgency WHERE review = 'AGENCY_MULTIPLE_AREAS'");
results = q.getResultList();
int agenciesNoMetro = results.get(0).intValue();

render(feedsNoAgency, agenciesNoMetro);
}


/**
* Actually perform the split for a given metro
*/
//
public static void saveSplitMetro () {
// we get the number of splits then parse down the URL params; each metro is named
// metron, where n is a number greater than or equal to 1 and less than or equal to splits.
int splits = params.get("splits", Integer.class);
MetroArea original = MetroArea.findById(params.get("original", Long.class));

// This is an array of lists of long.
NtdAgency[][] splitAgencies = new NtdAgency[splits][];
String[] currentAgencies;

for (int i = 1; i <= splits; i++) {
// get all of the agencies with the metro of this index
currentAgencies = params.getAll("metro" + i);
splitAgencies[i - 1] = new NtdAgency[currentAgencies.length];

// loop through each one, getting the agencies
for (int j = 0; j < currentAgencies.length; j++) {
splitAgencies[i - 1][j] = NtdAgency.findById(Long.parseLong(currentAgencies[j]));
}
}

// now, create new metros for each
MetroArea metro;
for (NtdAgency[] agencies: splitAgencies) {
metro = new MetroArea();
for (NtdAgency agency : agencies) {
metro.agencies.add(agency);
}
metro.autoname();
metro.save();
}

original.disabled = true;
original.note = "superseded by split metro.";
original.save();
}

/**
* Split a metro area into the given number of parts interactively.
* @param metroId The metro area to split
* @param splits The number of pieces to split it into
*/
public static void splitMetroInteractively (long metroId, int splits) {
MetroArea original = MetroArea.findById(metroId);
render(original, splits);
}

}
15 changes: 15 additions & 0 deletions app/views/Admin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#{extends 'main.html' /}
#{set title:'Transit Data Dashboard Administration' /}

<h2>Items requiring review</h2>

<ul>
<li><a href="feedsNoAgencies">Feeds with no agencies
<span class="label label-info">${feedsNoAgency}</span></a></li>
<li><a href="agenciesNoMetros">Agencies with no metro areas
<span class="label label-info">${agenciesNoMetro}</span></a></li>
</ul>




34 changes: 34 additions & 0 deletions app/views/Admin/splitMetroInteractively.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#{extends 'main.html' /}
#{set title:'Split Metro Area' /}

<h2>Splitting metro ${original.toString()} into ${splits}</h2>

Select the agencies to include in each resulting metro:
<form action="saveSplitMetro" method="GET">
<input type="submit" />
<input type="hidden" name="splits" value="${splits}" />
<input type="hidden" name="original" value="${original.id}" />
<table>
<thead>
<th>Agency</th>
%{ for (int i = 1; i <= splits; i++) { }%
<th>${i}</th>
%{ } }%
</thead>
<tbody>
%{ for (agency in original.agencies) { }%
<tr>
<td>${agency.name}</td>
%{ for (int i = 1; i <= splits; i++) { }%
<td><input type="checkbox" name="metro${i}" value="${agency.id}" /></td>
%{ } }%
</tr>
%{ } }%
</tbody>
</table>
<input type="submit" />
</form>




31 changes: 29 additions & 2 deletions app/views/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,37 @@
<head>
<title>#{get 'title' /}</title>
<meta charset="${_response_encoding}">
#{get 'moreStyles' /}
<link rel="stylesheet" href="/javascripts/leaflet/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="javascripts/leaflet/leaflet.ie.css" />
<![endif]-->
<link rel="stylesheet"
href="/css/ui-lightness/jquery-ui-1.8.21.custom.css" />
<link rel="stylesheet" href="/stylesheets/main.css" />
<link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css" />

<script src="/javascripts/leaflet/leaflet.js"></script>
<script src="/javascripts/jquery-1.7.2.min.js"></script>
<script src="/javascripts/client.js"></script>
<script src="/js/jquery-ui-1.8.21.custom.min.js"></script>

#{get 'moreStyles' /}
#{get 'moreScripts' /}
</head>
<body>
#{doLayout /}
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">Transit Data Dashboard</a>
<h4>Administration</h4>
</div>
</div>
<div class="container">
<div class="row">
<div class="span12">
#{doLayout /}
</div>
</div>
</div>
</body>
</html>

0 comments on commit 620046c

Please sign in to comment.