Display permission of views using CompleteViewJson

This commit is contained in:
morninlark 2014-03-28 15:26:55 +01:00
parent 74823fe104
commit d0929c3b36
4 changed files with 83 additions and 25 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ src/main/resources/git.properties
src/main/webapp/WEB-INF/jetty.xml
src/main/webapp/conf.html
target/
*.iml

View File

@ -504,6 +504,11 @@ object ObpJson {
case _ => None
}
val alias: Option[String] = json.get("alias") match {
case s:Some[String] => s
case _ => None
}
val description: Option[String] = json.get("description") match {
case s:Some[String] => s
case _ => None
@ -513,6 +518,13 @@ object ObpJson {
case b:Some[Boolean] => b
case _ => None
}
val permissions = json
.filterNot(_.key == "id")
.filterNot(_.key == "short_name")
.filterNot(_.key == "alias")
.filterNot(_.key == "description")
.filterNot(_.key == "is_public")
}
case class AccountJson(id: Option[String],

View File

@ -2,30 +2,56 @@ package code.snippet
import net.liftweb.util.Helpers._
import scala.xml.NodeSeq
import net.liftweb.util.CssSel
import net.liftweb.mapper.By
import code.lib.ObpJson.CompleteViewJson
class ViewsOverview(views : List[CompleteViewJson]) {
def showAll(xhtml: NodeSeq) : NodeSeq ={
def getTableContent(xhtml: NodeSeq) :NodeSeq = {
views.flatMap {
view => {
val id = view.id
val shortName = view.shortName
val description = view.description
val permissionsCollection: List[Map[String, Any]] = views.map(view => view.permissions)
val permissions: Map[String, Any] = permissionsCollection(0)
val viewId = ".view_name [id]" #> id
val viewShortName = ".view_name *" #> shortName
val viewDescription = ".view_description *" #> description
val viewNames = getShortNames()
val viewNameSel = ".view_name *" #> viewNames
val shortNamesSel = ".short_name *" #> viewNames
val aliasSel = ".alias *" #> getAliases()
val descriptionSel = ".description *" #> getDescriptions()
val isPublicSel = ".is_public *" #> getIfIsPublic()
(viewId & viewShortName & viewDescription).apply(xhtml)
}
val permissionNames = permissions.keys
val permSel = ".permissions *" #>
permissionNames.map(
permName => {
".permission_name *" #> permName.capitalize.replace("_", " ") &
".permission_value *" #> getPermissionValues(permName)
}
)
(viewNameSel & shortNamesSel & aliasSel & descriptionSel & isPublicSel & permSel).apply(xhtml)
}
def getShortNames() :List[String] = {
views.map( view => view.shortName.getOrElse(""))
}
}
def getAliases() :List[String] = {
views.map( view => view.alias.getOrElse(""))
}
}
def getDescriptions() :List[String] = {
views.map( view => view.description.getOrElse(""))
}
def getIfIsPublic() :List[String] = {
views.map( view => view.isPublic.getOrElse("").toString())
}
def getPermissionValues(permName: String) :List[String] = {
views.map( view => view.permissions(permName).toString())
}
}

View File

@ -29,19 +29,38 @@ Berlin 13359, Germany
Ayoub Benali: ayoub AT tesobe DOT com
-->
<div class="lift:surround?with=default;at=content">
<div class="views">
<div>
<table id="view_table" class="view tablesorter">
<div class="views">
<div>
<table class="lift:ViewsOverview.getTableContent" id="view_table">
<thead>
<tr class="view_head">
<th class="view_permissions">Permissons</th>
<th class="view_name" id="123">View name</th>
</tr>
</thead>
<tbody>
<tr class="lift:ViewsOverview.showAll">
<td class="view_name" id="123" >A random view</td>
<td class="view_description">Description</td>
<td class="view_details"><a href="#">Details</a></td>
<td class="view_edit"><a href="#">Edit</a></td>
<td class="view_delete"><a href="#">Delete</a></td>
<tr class="short_name_head">
<td>Short name</td>
<td class="short_name">View short name</td>
</tr>
<tr class="alias_head">
<td>Alias</td>
<td class="alias">no alias</td>
</tr>
<tr class="description_head">
<td>Description</td>
<td class="description">description</td>
</tr>
<tr class="is_public_head">
<td>Is public</td>
<td class="is_public"></td>
</tr>
<tr class="permissions">
<td class="permission_name">Permission name</td>
<td class="permission_value"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>