- modify how we store whiteboard shapes as latecomers are not getting any shapes for the current page

This commit is contained in:
Richard Alam 2014-02-10 23:00:01 +00:00
parent c77ddd76d3
commit dcd5e0e8ec
2 changed files with 135 additions and 69 deletions

View File

@ -4,6 +4,11 @@ import org.bigbluebutton.core.api._
import org.bigbluebutton.conference.service.whiteboard.WhiteboardKeyUtil
import net.lag.logging.Logger
import org.bigbluebutton.core.MeetingActor
import org.bigbluebutton.core.apps.whiteboard.vo._
case class Page2(num:Int, current: Boolean = false, shapes: Seq[AnnotationVO])
case class Presentation2(val presentationID: String, val numPages: Int,
current: Boolean = false, pages:scala.collection.immutable.HashMap[Int, Page2])
trait WhiteboardApp {
this : MeetingActor =>

View File

@ -1,27 +1,22 @@
package org.bigbluebutton.core.apps.whiteboard
import scala.collection.mutable.HashMap
import org.bigbluebutton.core.apps.whiteboard.vo.AnnotationVO
import scala.collection.mutable.ArrayBuffer
class WhiteboardModel {
private val _presentations = new HashMap[String, Presentation]()
private var _presentations = new scala.collection.immutable.HashMap[String, Presentation2]()
private var _activePresentation = ""
private var _enabled = true
def activePresentation() = _activePresentation
def currentPage() = {
var curPage = 0
_presentations.get(_activePresentation) match {
case Some(p) => {
curPage = p.currentPage
}
case None => // do nothing
}
curPage
def getCurrentPresentation():Option[Presentation2] = {
_presentations.values find (pres => pres.current)
}
def getCurrentPage(pres: Presentation2):Option[Page2] = {
pres.pages.values find (page => page.current)
}
def numPages() = {
var numPages = 0
_presentations.get(_activePresentation) match {
@ -34,76 +29,142 @@ class WhiteboardModel {
numPages
}
private def savePresentation(pres: Presentation2) {
_presentations += pres.presentationID -> pres
}
def addAnnotationToShape(pres: Presentation2, page: Page2, shape: AnnotationVO) = {
val newPage = page.copy(shapes=(page.shapes :+ shape))
val newPages = pres.pages + (newPage.num -> newPage)
val newPres = pres.copy(pages=newPages)
savePresentation(newPres)
}
def addAnnotation(shape: AnnotationVO) {
_presentations.get(_activePresentation) match {
case Some(p) => {
p.addAnnotation(shape)
getCurrentPresentation() foreach { pres =>
getCurrentPage(pres) foreach {page =>
addAnnotationToShape(pres, page, shape)
}
case None => // do nothing
}
}
}
private def modifyTextInPage(pres: Presentation2, page: Page2, shape: AnnotationVO) = {
val removedLastText = page.shapes.dropRight(1)
val addedNewText = removedLastText :+ shape
val newPage = page.copy(shapes=addedNewText)
val newPages = pres.pages + (newPage.num -> newPage)
val newPres = pres.copy(pages=newPages)
savePresentation(newPres)
}
def modifyText(shape: AnnotationVO) {
_presentations.get(_activePresentation) match {
case Some(p) => {
p.modifyText(shape)
getCurrentPresentation() foreach { pres =>
getCurrentPage(pres) foreach {page =>
modifyTextInPage(pres, page, shape)
}
case None => // do nothing
}
}
}
def changePage(page: Int) {
_presentations.get(_activePresentation) match {
case Some(p) => {
p.changePage(page)
}
case None => // do nothing
}
}
def history():Array[AnnotationVO] = {
var shapes:Array[AnnotationVO] = new Array(0)
_presentations.get(_activePresentation) match {
case Some(p) => {
shapes = p.annotations
}
case None => // do nothing
private def deactivateCurrentPage(pres: Presentation2) {
getCurrentPage(pres) foreach {cp =>
val page = cp.copy(current = false)
val nPages = pres.pages + (page.num -> page)
val newPres = pres.copy(pages= nPages)
savePresentation(newPres)
println("Making whiteboard page[" + page.num + "] not current[" + page.current + "]")
println("After deact page. presentation id=[" + newPres.presentationID + "] current=[" + newPres.current + "]")
newPres.pages.values foreach {page =>
println("page num=[" + page.num + "] current=[" + page.current + "]")
}
}
shapes
}
private def makePageCurrent(pres: Presentation2, page: Int):Option[Page2] = {
pres.pages.values find (p => p.num == page) match {
case Some(newCurPage) => {
val page = newCurPage.copy(current=true)
val newPages = pres.pages + (page.num -> page)
val newPres = pres.copy(pages= newPages)
savePresentation(newPres)
println("Making page[" + page.num + "] current[" + page.current + "]")
Some(page)
}
case None => {
println("Could not find page[" + page + "] in presentation [" + pres.presentationID + "]")
None
}
}
}
def changePage(pageId: Int):Option[Page2] = {
getCurrentPresentation foreach {pres => deactivateCurrentPage(pres)}
for {
pres <- getCurrentPresentation
page <- makePageCurrent(pres, pageId)
} yield page
}
def history():Option[Page2] = {
for {
pres <- getCurrentPresentation
page <- getCurrentPage(pres)
} yield page
}
def clearWhiteboard() {
_presentations.get(_activePresentation) match {
case Some(p) => {
p.clear()
}
case None => // do nothing
}
}
def undoWhiteboard() {
_presentations.get(_activePresentation) match {
case Some(p) => {
p.undo()
}
case None => // do nothing
getCurrentPresentation foreach {pres =>
getCurrentPage(pres) foreach {page =>
val clearedShapes = page.shapes.drop(page.shapes.length)
val newPage = page.copy(shapes= clearedShapes)
val newPages = pres.pages + (newPage.num -> newPage)
val newPres = pres.copy(pages= newPages)
savePresentation(newPres)
}
}
}
def undoWhiteboard() {
getCurrentPresentation foreach {pres =>
getCurrentPage(pres) foreach {page =>
val droppedShapes = page.shapes.drop(page.shapes.length-1)
val newPage = page.copy(shapes= droppedShapes)
val newPages = pres.pages + (newPage.num -> newPage)
val newPres = pres.copy(pages= newPages)
savePresentation(newPres)
}
}
}
private def generatePages(numPages: Int):scala.collection.immutable.HashMap[Int, Page2] = {
var pages = new scala.collection.immutable.HashMap[Int, Page2]()
for (i <- 1 to numPages) {
val shapes = new ArrayBuffer[AnnotationVO]
val p = new Page2(num=i, current=false, shapes.toSeq)
pages += (p.num -> p)
}
pages
}
def setActivePresentation(presentationID: String, numPages: Int) {
_presentations.get(presentationID) match {
case Some(p) => {
_activePresentation = presentationID
}
case None => {
_activePresentation = presentationID
val pre = new Presentation(presentationID, numPages)
_presentations += presentationID -> pre
}
}
getCurrentPresentation foreach {curPres =>
savePresentation(curPres.copy(current=false))
}
_presentations.get(presentationID) match {
case Some(existingPres) => {
savePresentation(existingPres.copy(current=true))
}
case None => { // New presentation
val pages = generatePages(numPages)
val newPres = new Presentation2(presentationID, numPages,
current = true, pages)
savePresentation(newPres)
}
}
}
def enableWhiteboard(enable: Boolean) {