Skip to content

Commit

Permalink
Added search. Refactored stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dpp committed Feb 28, 2011
1 parent 2e165fe commit 9145411
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 51 deletions.
4 changes: 1 addition & 3 deletions samples/shopwithme/src/main/scala/code/comet/ListPages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class ListPages extends CometActor {
*/
def render = {
"tbody *" #> SessionPresenceInfo.pages.map{
_._2.wholePath.mkString("/", "/", "")
}.map {
path => "td *" #> path
path => "td *" #> path._2
}
}

Expand Down
6 changes: 3 additions & 3 deletions samples/shopwithme/src/main/scala/code/comet/WhatPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.xml.NodeSeq
* A simple presence CometActor
*/
class WhatPage extends CometActor {
private var thePath: Box[ParsePath] = Empty
private var thePath: Box[String] = Empty
private var lastToken = Helpers.nextFuncName

override def lifespan = Full(3 seconds)
Expand Down Expand Up @@ -47,7 +47,7 @@ class WhatPage extends CometActor {
* the keeping the whole Req reference.
*/
override protected def captureInitialReq(initialReq: Box[Req]) {
thePath = initialReq.map(_.path)
thePath = initialReq.map(_.uri)
this.addPresence()
}

Expand Down Expand Up @@ -126,7 +126,7 @@ private case class HeartBeat()
* are being viewed
*/
class PresenceInfo {
val pages = ValueCell[Set[(String, ParsePath)]](Set())
val pages = ValueCell[Set[(String, String)]](Set())
}


Expand Down
4 changes: 2 additions & 2 deletions samples/shopwithme/src/main/scala/code/lib/Cart.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class Cart {
/**
* The current tax rate
*/
val taxRate = ValueCell(BigDecimal("0.5"))
val taxRate = ValueCell(BigDecimal("0.07"))

/**
* The contents of the cart
*/
val contents = ValueCell[Vector[CartItem]](Vector(CartItem(Item.items(2), 1), CartItem(Item.items(1), 2)))
val contents = ValueCell[Vector[CartItem]](Vector())

/**
* The subtotal
Expand Down
21 changes: 11 additions & 10 deletions samples/shopwithme/src/main/scala/code/snippet/AllItemsPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import util._
import Helpers._

object AllItemsPage {
lazy val menu = Menu.i("Items") / "item"
lazy val menu = Menu.i("Items") / "item" >>
Loc.Snippet("Items", render)

def render =
"tbody *" #> Item.items.map(item => {
"@name" #> ("a *" #> item.name &
"a [href]" #>
Menu.ParamMenuable.toLoc(AnItemPage.menu).calcHref(item)) &
"@description *" #> item.description &
"@price *" #> item.price.toString &
"@add_to_cart [onclick]" #>
SHtml.ajaxInvoke(() => TheCart.addItem(item))
})
"tbody *" #> renderItems(Item.items)

def renderItems(in: Seq[Item]) =
"tr" #> in.map(item => {
"a *" #> item.name &
"@description *" #> item.description &
"@price *" #> item.price.toString &
"a [href]" #> AnItemPage.menu.calcHref(item) &
"@add_to_cart [onclick]" #>
SHtml.ajaxInvoke(() => TheCart.addItem(item))})
}

12 changes: 11 additions & 1 deletion samples/shopwithme/src/main/scala/code/snippet/SearchPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ import model.Item

import net.liftweb._
import http._
import util._
import Helpers._
import sitemap._
import Loc._

object SearchPage {
def menu = Menu.i("Woof") / "search"
def menu = Menu.i("Search") / "search" >>
If(() => S.param("q").isDefined, "Need Search Term") >>
Snippet("Items", render)

def render = {
"tbody *" #> AllItemsPage.
renderItems(Item.search(S.param("q") openOr "*****^^^^"))
}
}

10 changes: 10 additions & 0 deletions samples/shopwithme/src/main/webapp/_items.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<table class="lift:Items">
<tbody>
<tr>
<td name="name"><a href="#">Name</a></td>
<td name="description">Desc</td>
<td name="price">$50.00</td>
<td><button name="add_to_cart">Add to Cart</button></td>
</tr>
</tbody>
</table>
6 changes: 2 additions & 4 deletions samples/shopwithme/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
</head>
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">

<div lift="AddRandom">Add something</div>

</div>
Some text about this application
</div>
</body>
</html>

14 changes: 2 additions & 12 deletions samples/shopwithme/src/main/webapp/item.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">

<table class="lift:AllItemsPage">
<tbody>
<tr>
<td name="name"><a href="#">Name</a></td>
<td name="description">Desc</td>
<td name="price">$50.00</td>
<td><button name="add_to_cart">Add to Cart</button></td>
</tr>
</tbody>
</table>


<meta lift="embed?what=_items">

</div>
</body>
</html>
Expand Down
14 changes: 14 additions & 0 deletions samples/shopwithme/src/main/webapp/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>Home</title>
</head>
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">

<meta lift="embed?what=_items">

</div>
</body>
</html>
24 changes: 8 additions & 16 deletions samples/shopwithme/src/main/webapp/templates-hidden/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@
</head>
<body>
<div class="container">
<div class="column span-12 last" style="text-align: right">
<h1 class="alt">app<img alt="" id="ajax-loader" style="display:none; margin-bottom: 0px; margin-left: 5px" src="/images/ajax-loader.gif"></h1>
<div class="column span-12" style="text-align: right">
<h1 class="alt">Shop with Me<img alt="" id="ajax-loader"
style="display:none; margin-bottom: 0px; margin-left: 5px"
src="/images/ajax-loader.gif"></h1>
</div>
<div class="column span-11 last">
<span style="float: right"><form action="/search"><input
name="q"><input type="submit" value="search"></form></span>
</div>

<hr>
Expand Down Expand Up @@ -99,20 +105,6 @@ <h1 class="alt">app<img alt="" id="ajax-loader" style="display:none; margin-bott

<br/>

<div style="border: 1px solid #ccc">
I'm on pages:

<div lift="comet?type=ListPages" >
<table id="listPagesContents">
<tbody id="page_list_tbody">
<tr><td>an item</td></tr>
</tbody>
</table>
</div>
</div>

<br>

<div>
<button lift="Link.request">Share Cart</button>
</div>
Expand Down

0 comments on commit 9145411

Please sign in to comment.