From d0929c3b36d0af1d1911394dcdfbd824359794cb Mon Sep 17 00:00:00 2001 From: morninlark Date: Fri, 28 Mar 2014 15:26:55 +0100 Subject: [PATCH] Display permission of views using CompleteViewJson --- .gitignore | 1 + src/main/scala/code/lib/ObpAPI.scala | 12 +++++ .../scala/code/snippet/ViewsOverview.scala | 54 ++++++++++++++----- .../banks/star/accounts/star/views/list.html | 41 ++++++++++---- 4 files changed, 83 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index f8b8df0e..339911a5 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ src/main/resources/git.properties src/main/webapp/WEB-INF/jetty.xml src/main/webapp/conf.html target/ +*.iml diff --git a/src/main/scala/code/lib/ObpAPI.scala b/src/main/scala/code/lib/ObpAPI.scala index e41cf496..20863313 100644 --- a/src/main/scala/code/lib/ObpAPI.scala +++ b/src/main/scala/code/lib/ObpAPI.scala @@ -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], diff --git a/src/main/scala/code/snippet/ViewsOverview.scala b/src/main/scala/code/snippet/ViewsOverview.scala index 5fd067de..a82f827b 100644 --- a/src/main/scala/code/snippet/ViewsOverview.scala +++ b/src/main/scala/code/snippet/ViewsOverview.scala @@ -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()) + } - \ No newline at end of file + def getPermissionValues(permName: String) :List[String] = { + views.map( view => view.permissions(permName).toString()) + } + } \ No newline at end of file diff --git a/src/main/webapp/banks/star/accounts/star/views/list.html b/src/main/webapp/banks/star/accounts/star/views/list.html index 2767e8db..6489f3f3 100644 --- a/src/main/webapp/banks/star/accounts/star/views/list.html +++ b/src/main/webapp/banks/star/accounts/star/views/list.html @@ -29,19 +29,38 @@ Berlin 13359, Germany Ayoub Benali: ayoub AT tesobe DOT com -->
-
-
- +
+
+
+ + + + + + - - - - - - + + + + + + + + + + + + + + + + + + +
PermissonsView name
A random viewDescriptionDetailsEditDelete
Short nameView short name
Aliasno alias
Descriptiondescription
Is public
Permission name
-
-
+
+ \ No newline at end of file