Skip to content

Instantly share code, notes, and snippets.

@fmpwizard
fmpwizard / Overview.scala
Created December 17, 2010 03:53
Show a list of test names and their result status (PASS or FAIL)
package code {
package snippet {
import code.model.{AutomatedTests}
import _root_.scala.xml.{NodeSeq, Text}
import _root_.net.liftweb._
import util._
import common.Logger
@fmpwizard
fmpwizard / gist:833968
Created February 18, 2011 16:50
Add a named cometactor using Lift
object PutCometOnPage {
def render(xhtml: NodeSeq): NodeSeq = {
val id= "browser" + versionString
debug("Using CometActor with name: %s".format(id))
for (sess <- S.session) sess.sendCometActorMessage(
"BrowserDetails", Full(id), versionString
)
<lift:comet type="BrowserDetails" name={id}>{xhtml}</lift:comet>
}
}
@fmpwizard
fmpwizard / gist:833981
Created February 18, 2011 16:57
MyListeners object
object MyListeners extends Logger{
private var listeners: Map[String, LiftActor] = Map()
def listenerFor(str: String): LiftActor = synchronized {
listeners.get(str) match {
case Some(a) => info("Our map is %s".format(listeners)); a
case None => {
val ret = new DispatcherActor(str)
listeners += str -> ret
info("Our map is %s".format(listeners))
@fmpwizard
fmpwizard / gist:834021
Created February 18, 2011 17:19
REST API
/**
* listenerFor(srvmgrVersion) returns a DispatcherActor that in turn
* will send the CellToUpdate clas class to the comet actors that are
* displaying info about the version we got json data for
*/
listenerFor(srvmgrVersion) match {
case a: LiftActor => a ! CellToUpdate(
testName, browser, srvmgrVersion, testResult, cellNotes
)
case _ => info("No actor to send an update")
override def lowPriority: PartialFunction[Any,Unit] = {
case CellToUpdate(index, rowName, version, cssClass, cellNotes) => {
info("Comet Actor %s will do a partial update".format(this))
info("[API]: Updating BrowserTestResults for version: %s".format(version))
showingVersion = version
/**
* each td in the html grid has an id that is
* [0-9] + browser name
* I use this to uniquely identify which cell to update
package com.fmpwizard.weyesowl.code.snippet
import com.fmpwizard.weyesowl.code.model.{Inventory, InventoryDescription,
InventoryImages, InventoryOptionFields, InventoryPrice, InventoryStock,
InventoryXCategory, Categories}
import scala.xml.{NodeSeq, Text, Elem}
import java.io.{File,FileOutputStream}
@fmpwizard
fmpwizard / ReplaceOrAppend.scala
Created March 17, 2011 03:45
Case Class to replace html and if it fails, append some NodeSeq to some other ID
case class ReplaceOrAppend(replacementId: String, replacement: NodeSeq,
appendingId: String, appending: NodeSeq) extends JsCmd with HtmlFixer {
override val toJsCmd = {
val (replacementHtml, replacementJs) = fixHtmlAndJs("inline", replacement)
val (appendHtml, appendJs) = fixHtmlAndJs("inline", appending)
var ret =
"""
try {
var parent1 = document.getElementById(""" + replacementId.encJs + """);
<form class="lift:Upload?form=post” multipart=”true">
<form class="lift:Upload?form=post;multipart=true">
// bind the view to the dynamic HTML
def show(xhtml: Group): NodeSeq = {
val (name, js) = ajaxCall(JE.JsRaw("this.value"),
s => After(200, replace(s)))
bind("select", xhtml,
"state" -> select(AjaxForm.states.map(s => (s,s)),
Full(state), s => state = s, "onchange" -> js.toJsCmd) %
(new PrefixedAttribute("lift", "gc", name, Null)),
"city" -> cityChoice(state) % ("id" -> "city_select"),
"submit" -> submit(?("Save"),