Skip to content

Commit 0749556

Browse files
committed
progress
1 parent 7c894bb commit 0749556

File tree

14 files changed

+237
-13
lines changed

14 files changed

+237
-13
lines changed

java-admin-web/.project

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<projects>
66
</projects>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
813
<buildCommand>
914
<name>org.eclipse.jdt.core.javabuilder</name>
1015
<arguments>
@@ -17,7 +22,9 @@
1722
</buildCommand>
1823
</buildSpec>
1924
<natures>
20-
<nature>org.eclipse.m2e.core.maven2Nature</nature>
25+
<nature>net.vtst.ow.eclipse.less.nature</nature>
26+
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
2127
<nature>org.eclipse.jdt.core.javanature</nature>
28+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
2229
</natures>
2330
</projectDescription>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
body {
2+
background-color: #fff;
3+
}
4+
5+
#header {
6+
background-color: #eee;
7+
border-bottom: 1px solid #ddd;
8+
margin: 0 0 20px;
9+
}
10+
11+
#header h1 {
12+
margin: 15px 0;
13+
}

java-admin-web/resources/static/test.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

java-admin-web/resources/templates/page.peb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@
1515
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
1616
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
1717
<![endif]-->
18+
19+
<link href="{{ static_href }}/css/main.css" rel="stylesheet">
1820
</head>
1921
<body>
22+
<div id="header">
23+
<div class="container">
24+
<h1>{{ site_title }}</h1>
25+
</div>
26+
</div>
2027
<div class="container">
28+
<ul class="nav nav-tabs">
29+
{% for item in main_menu_items %}
30+
<li role="presentation"{% if item == active_page %} class="active"{% endif %}><a href="{{ admin_root }}{{ item.path }}">{{ item.label }}</a></li>
31+
{% endfor %}
32+
</ul>
2133
{% block content %}{% endblock %}
2234
</div>
2335

java-admin-web/src/java/net/compsoc/ox/web/admin/AdminServlet.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
import net.compsoc.ox.web.admin.util.PageBuilder;
1515
import net.compsoc.ox.web.admin.util.PageRenderer;
1616
import net.compsoc.ox.web.admin.util.PathInfo;
17+
import net.compsoc.ox.web.admin.util.StatusException;
1718

1819
public class AdminServlet extends HttpServlet {
1920

2021
private final Database database;
2122
private final PageRenderer pageRenderer = new PageRenderer();
2223
private final Section rootSection = new RootSection();
2324

24-
public AdminServlet(){
25+
public AdminServlet() {
2526
// Create Database
2627
database = new DummyDatabase();
2728
}
@@ -30,7 +31,12 @@ public AdminServlet(){
3031
protected void doGet(HttpServletRequest request, HttpServletResponse response)
3132
throws ServletException, IOException {
3233

33-
rootSection.handlePage(new PathInfo(), new PageBuilder(pageRenderer, request, response));
34+
try {
35+
rootSection.handle(new PathInfo(request), new PageBuilder(pageRenderer, database,
36+
request, response));
37+
} catch (StatusException e) {
38+
response.sendError(e.code);
39+
}
3440

3541
}
3642
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package net.compsoc.ox.web.admin;
2+
3+
public class Constants {
4+
5+
public static final String SITE_TITLE = "Compsoc Admin Panel";
6+
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package net.compsoc.ox.web.admin.sections;
2+
3+
public enum MainSectionsEnum {
4+
HOME("Home", "/"),
5+
EVENTS("Events", "/events/"),
6+
MEMBERS("Members", "/members/");
7+
8+
public final String label;
9+
public final String path;
10+
11+
private MainSectionsEnum(String label, String path){
12+
this.label = label;
13+
this.path = path;
14+
}
15+
}

java-admin-web/src/java/net/compsoc/ox/web/admin/sections/RootSection.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33

44
import java.io.IOException;
55

6+
import net.compsoc.ox.web.admin.sections.events.EventsSection;
7+
import net.compsoc.ox.web.admin.sections.members.MembersSection;
68
import net.compsoc.ox.web.admin.templating.Template;
79
import net.compsoc.ox.web.admin.util.PageBuilder;
810
import net.compsoc.ox.web.admin.util.PathInfo;
911

10-
public class RootSection implements Section {
12+
public class RootSection extends Section {
13+
14+
private final Section eventsSection = new EventsSection();
15+
private final Section membersSection = new MembersSection();
1116

1217
@Override
1318
public void visitSection(PathInfo info, PageBuilder builder) {
@@ -16,8 +21,23 @@ public void visitSection(PathInfo info, PageBuilder builder) {
1621
}
1722

1823
@Override
19-
public void handlePage(PathInfo info, PageBuilder builder) throws IOException {
24+
public void renderPage(PathInfo info, PageBuilder builder) throws IOException {
25+
builder.setActivePage(MainSectionsEnum.HOME);
26+
27+
builder.put("title", "home");
28+
2029
builder.render(Template.HOME);
2130
}
31+
32+
@Override
33+
public Section getSubsection(String slug) {
34+
switch(slug){
35+
case "events":
36+
return eventsSection;
37+
case "members":
38+
return membersSection;
39+
}
40+
return null;
41+
}
2242

2343
}

java-admin-web/src/java/net/compsoc/ox/web/admin/sections/Section.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,30 @@
44

55
import net.compsoc.ox.web.admin.util.PageBuilder;
66
import net.compsoc.ox.web.admin.util.PathInfo;
7+
import net.compsoc.ox.web.admin.util.StatusException;
78

8-
public interface Section {
9+
public abstract class Section {
910

10-
public void visitSection(PathInfo info, PageBuilder builder);
11+
public abstract void visitSection(PathInfo info, PageBuilder builder) throws StatusException;
1112

12-
public void handlePage(PathInfo info, PageBuilder builder) throws IOException;
13+
public abstract void renderPage(PathInfo info, PageBuilder builder) throws IOException,
14+
StatusException;
15+
16+
public abstract Section getSubsection(String slug);
17+
18+
public void handle(PathInfo info, PageBuilder builder) throws IOException, StatusException {
19+
visitSection(info, builder);
20+
21+
PathInfo next = info.next();
22+
if (next != null) {
23+
Section subSection = getSubsection(next.slug());
24+
if (subSection != null)
25+
subSection.handle(next, builder);
26+
else
27+
throw StatusException.do404();
28+
} else {
29+
renderPage(info, builder);
30+
}
31+
}
1332

1433
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package net.compsoc.ox.web.admin.sections.events;
2+
3+
import java.io.IOException;
4+
5+
import net.compsoc.ox.web.admin.sections.MainSectionsEnum;
6+
import net.compsoc.ox.web.admin.sections.Section;
7+
import net.compsoc.ox.web.admin.templating.Template;
8+
import net.compsoc.ox.web.admin.util.PageBuilder;
9+
import net.compsoc.ox.web.admin.util.PathInfo;
10+
import net.compsoc.ox.web.admin.util.StatusException;
11+
12+
public class EventsSection extends Section {
13+
14+
@Override
15+
public void visitSection(PathInfo info, PageBuilder builder) throws StatusException {
16+
builder.setActivePage(MainSectionsEnum.EVENTS);
17+
}
18+
19+
@Override
20+
public void renderPage(PathInfo info, PageBuilder builder) throws IOException, StatusException {
21+
builder.put("title", "events");
22+
builder.render(Template.HOME);
23+
}
24+
25+
@Override
26+
public Section getSubsection(String slug) {
27+
return null;
28+
}
29+
30+
}

0 commit comments

Comments
 (0)