Skip to content

Commit

Permalink
changed the html structure of Document View
Browse files Browse the repository at this point in the history
  • Loading branch information
marubinotto committed Mar 20, 2013
1 parent 92bbf5d commit fc639cb
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 97 deletions.
123 changes: 61 additions & 62 deletions src/main/java/marubinotto/piggydb/ui/page/DocumentViewPage.java
Expand Up @@ -10,66 +10,65 @@

public class DocumentViewPage extends AbstractTemplateWebResource {

@Override
protected boolean needsAuthentication() {
return false;
}

//
// Input
//

public Long id;
public Fragment fragment;

@Override
protected boolean onPreInit() throws Exception {
if (this.id == null) {
getLogger().info("Missing parameter: id");
return true;
}

this.fragment = getDomain().getFragmentRepository().get(this.id.longValue());
if (this.fragment == null) {
getLogger().info("Missing fragment: #" + this.id);
return true;
}

if (!isAuthenticated() && !this.fragment.isPublic()) {
getLogger().info("Forbidden: #" + this.id);
setRedirectToLogin();
return false;
}

fetchTagsAdditionally(this.fragment);

return true;
}

private void fetchTagsAdditionally(Fragment fragment) throws Exception {
List<Fragment> tagNotFetched = new ArrayList<Fragment>();

// Grandchildren
tagNotFetched.addAll(ModelUtils.collectChildrenOfEach(fragment
.getChildren()));
// Great-grandchildren
tagNotFetched.addAll(ModelUtils.collectChildrenOfEach(tagNotFetched));

getDomain().getFragmentRepository().refreshClassifications(tagNotFetched);
}

//
// Model
//

public Boolean publicOnly;
public String additionalCssImports;

@Override
protected void setModels() throws Exception {
super.setModels();

this.publicOnly = !isAuthenticated();
this.additionalCssImports = PageImports.additionalCssImports.toString();
}
@Override
protected boolean needsAuthentication() {
return false;
}

//
// Input
//

public Long id;
public Fragment fragment;

@Override
protected boolean onPreInit() throws Exception {
if (this.id == null) {
getLogger().info("Missing parameter: id");
return true;
}

this.fragment = getDomain().getFragmentRepository().get(this.id.longValue());
if (this.fragment == null) {
getLogger().info("Missing fragment: #" + this.id);
return true;
}

if (!isAuthenticated() && !this.fragment.isPublic()) {
getLogger().info("Forbidden: #" + this.id);
setRedirectToLogin();
return false;
}

fetchTagsAdditionally(this.fragment);

return true;
}

private void fetchTagsAdditionally(Fragment fragment) throws Exception {
List<Fragment> tagNotFetched = new ArrayList<Fragment>();

// Grandchildren
tagNotFetched.addAll(ModelUtils.collectChildrenOfEach(fragment.getChildren()));
// Great-grandchildren
tagNotFetched.addAll(ModelUtils.collectChildrenOfEach(tagNotFetched));

getDomain().getFragmentRepository().refreshClassifications(tagNotFetched);
}

//
// Model
//

public Boolean publicOnly;
public String additionalCssImports;

@Override
protected void setModels() throws Exception {
super.setModels();

this.publicOnly = !isAuthenticated();
this.additionalCssImports = PageImports.additionalCssImports.toString();
}
}
81 changes: 48 additions & 33 deletions src/main/webapp/document-view.htm
Expand Up @@ -15,56 +15,71 @@
<script type="text/javascript" src="$context/js/vendor/prettify/prettify.js?$version"></script>
</head>
<body onload="prettyPrint()">
#if ($fragment.title) <h1>$fragment.title</h1> #end

#fragmentContentForDoc($fragment)
#set ($emptyTitle = $utils.raw("—"))

<div class="toc">
<div id="parents">
<ul>
#foreach ($childRel in $fragment.getChildRelations($publicOnly))
<li>
<a href="#r${childRel.id}">
$utils.blankToNbsp($utils.raw($html.fragmentHeadline($childRel.to)))
</a>
<a href="">test
<sub><img src="$context/images/arrow-in.gif" border="0" alt="-"/></sub></a>
</li>
#end
</ul>
</div>

#set ($emptyTitle = $utils.raw("—"))
#foreach ($childRel in $fragment.getChildRelations($publicOnly))
<div class="section">
<h2 id="r${childRel.id}">
<a class="title-link" href="$context/document-view.htm?id=$childRel.to.id">
$utils.defaultIfNull($childRel.to.title, $emptyTitle)</a>
</h2>

#fragmentContentForDoc($childRel.to)
<div id="main">
#if ($fragment.title) <h1>$fragment.title</h1> #end

#foreach ($grandchildRel in $childRel.to.getChildRelations($publicOnly))
<div class="subsection">
<h3 id="r${grandchildRel.id}">
<a class="title-link" href="$context/document-view.htm?id=$grandchildRel.to.id">
$utils.defaultIfNull($grandchildRel.to.title, $emptyTitle)
#if ($grandchildRel.to.hasChildren($publicOnly))
<img class="arrow-button" src="$context/images/arrow-with-children.gif" alt="&rarr; ..."/>
#end
</a>
</h3>

#fragmentContentForDoc($grandchildRel.to)
#fragmentContentForDoc($fragment)

<div class="toc">
<ul>
#foreach ($childRel in $fragment.getChildRelations($publicOnly))
<li>
<a href="#r${childRel.id}">
$utils.blankToNbsp($utils.raw($html.fragmentHeadline($childRel.to)))
</a>
</li>
#end
</ul>
</div>
#end ## foreach grandchildren


#foreach ($childRel in $fragment.getChildRelations($publicOnly))
<div class="section">
<h2 id="r${childRel.id}">
<a class="title-link" href="$context/document-view.htm?id=$childRel.to.id">
$utils.defaultIfNull($childRel.to.title, $emptyTitle)</a>
</h2>

#fragmentContentForDoc($childRel.to)

#foreach ($grandchildRel in $childRel.to.getChildRelations($publicOnly))
<div class="subsection">
<h3 id="r${grandchildRel.id}">
<a class="title-link" href="$context/document-view.htm?id=$grandchildRel.to.id">
$utils.defaultIfNull($grandchildRel.to.title, $emptyTitle)
#if ($grandchildRel.to.hasChildren($publicOnly))
<img class="arrow-button" src="$context/images/arrow-with-children.gif" alt="&rarr; ..."/>
#end
</a>
</h3>

#fragmentContentForDoc($grandchildRel.to)
</div>
#end ## foreach grandchildren

</div>
#end ## foreach children

</div>
#end ## foreach children

#else ## fragment is null

<title>&nbsp;</title>
<link rel="shortcut icon" href="$context/images/favicon.ico" type="image/vnd.microsoft.icon"/>
</head>
<body>

#end

</body>
</html>
6 changes: 5 additions & 1 deletion src/main/webapp/style/piggydb-document-view-phone.css
@@ -1,5 +1,9 @@
body {
padding: 0;

}

#main {
padding: 5px;
}

div.toc {
Expand Down
20 changes: 19 additions & 1 deletion src/main/webapp/style/piggydb-document-view.css
@@ -1,7 +1,9 @@
body {
margin: 0;
padding: 0;

color: #000000;
background-color: #fff;
padding: 0px 10px 10px 10px;

font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
Expand All @@ -10,6 +12,22 @@ body {
-webkit-text-size-adjust: 100%;
}

#parents {
margin: 0;
padding: 5px;
background-color: #f8f8f8;
border-bottom: 1px solid #ddd;
}

#parents ul {
list-style: none;
margin-left: 5px;
}

#main {
padding: 0px 10px 10px 10px;
}

h1 {
font-size: 1.5em;
}
Expand Down

0 comments on commit fc639cb

Please sign in to comment.