cdd7280276f85e5b User page - projects
authorTomas Zeman <tzeman@volny.cz>
Tue, 05 Jun 2012 15:40:45 +0200
changeset 106 83d4c4990086
parent 105 66aeb6b3a3a7
child 107 26e9d0e4a619
cdd7280276f85e5b User page - projects
src/main/scala/fis/aaa/ui/UserSnippet.scala
src/main/scala/fis/base/ui/TabPanel.scala
src/main/scala/fis/pm/model/PmSchema.scala
src/main/webapp/templates-hidden/tab-panel.html
--- a/src/main/scala/fis/aaa/ui/UserSnippet.scala	Tue Jun 05 15:40:45 2012 +0200
+++ b/src/main/scala/fis/aaa/ui/UserSnippet.scala	Tue Jun 05 15:40:45 2012 +0200
@@ -81,11 +81,28 @@
 
   private def panel: CssTr = "*" #> cur.map(UserPanel(_))
 
+  private def allQp(what: String) =
+    (S param ("all-"+what)) flatMap(asBoolean(_)) openOr false
+  private def allQp(url: String, what: String, all: Boolean) =
+    all.box(appendQueryParameters(url, List(("all-"+what) -> "1"))) openOr url
+
   private def projects: CssTr = "*" #> cur.map { u =>
-    ProjectTable(AssignedProjects(u)) }
+    val qp = allQp("project")
+    TabPanel(List((false, "projects.unfinished"), (true, "projects.all")) map { p =>
+        val url = allQp(allQp(S.uri, "task", allQp("task")), "project", p._1)
+        val tab = a(url)(i18n(p._2))
+        Either.cond(p._1 == qp, tab, tab)
+      })(ProjectTable(qp.box(AssignedProjects.all(u)) openOr AssignedProjects(u)))
+  }
 
   private def tasks: CssTr = "*" #> cur.map { u =>
-    TaskTable(AssignedTasks(u)) }
+    val qp = allQp("task")
+    TabPanel(List((false, "tasks.unfinished"), (true, "tasks.all")) map { p =>
+        val url = allQp(allQp(S.uri, "project", allQp("project")), "task", p._1)
+        val tab = a(url)(i18n(p._2))
+        Either.cond(p._1 == qp, tab, tab)
+      })(TaskTable(qp.box(AssignedTasks.all(u)) openOr AssignedTasks(u)))
+  }
 
   object url {
     def view: User => Box[String] = (viewLoc.calcHref _) andThen (Box !! _)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/fis/base/ui/TabPanel.scala	Tue Jun 05 15:40:45 2012 +0200
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2012 Tomas Zeman <tzeman@volny.cz>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package fis.base.ui
+
+import net.liftweb.http.Templates
+import net.liftweb.util._
+import net.liftweb.util.Helpers._
+import scala.xml.NodeSeq
+
+trait TabPanel {
+  /** Tab type: Right is active, Left inactive; think of Either.cond(active). */
+  type Tab = Either[NodeSeq, NodeSeq]
+
+  protected def load = Templates(List("templates-hidden", "tab-panel")) openOr
+    NodeSeq.Empty
+
+  def apply(tabs: Iterable[Tab])(content: => NodeSeq) = {
+    ("li" #> (tabs map {
+      case Left(ns) => <li>{ns}</li>
+      case Right(ns) => <li class="active">{ns}</li>
+    }) &
+    ".content *" #> content)(load)
+  }
+}
+
+object TabPanel extends TabPanel
+
+// vim: set ts=2 sw=2 et:
--- a/src/main/scala/fis/pm/model/PmSchema.scala	Tue Jun 05 15:40:45 2012 +0200
+++ b/src/main/scala/fis/pm/model/PmSchema.scala	Tue Jun 05 15:40:45 2012 +0200
@@ -129,12 +129,22 @@
 
 object AssignedTasks {
   def apply(u: User): Iterable[Task] =
+    from(PmSchema.taskResponsible.left(u), CodeListSchema.cli)((t, i) =>
+      where(t.stateFld === i.id and TaskState.unfinishedClause(i))
+      select(t) orderBy(t.deadline asc))
+
+  def all(u: User): Iterable[Task] =
     from(PmSchema.taskResponsible.left(u))(t =>
       select(t) orderBy(t.deadline asc))
 }
 
 object AssignedProjects {
   def apply(u: User): Iterable[Project] =
+    from(PmSchema.projectResponsible.left(u), CodeListSchema.cli)((p, i) =>
+      where(p.stateFld === i.id and ProjectState.unfinishedClause(i))
+      select(p) orderBy(p.deadline asc))
+
+  def all(u: User): Iterable[Project] =
     from(PmSchema.projectResponsible.left(u))(p =>
       select(p) orderBy(p.name asc))
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/webapp/templates-hidden/tab-panel.html	Tue Jun 05 15:40:45 2012 +0200
@@ -0,0 +1,7 @@
+<span>
+  <ul class="nav nav-tabs">
+    <li></li>
+  </ul>
+  <div class="content"></div>
+</span>
+