Encapsulated some duplicate code.

This commit is contained in:
Maxim Khlobystov 2014-09-15 09:46:02 -07:00
parent e852cceeac
commit fe526f5277
3 changed files with 19 additions and 21 deletions

View File

@ -76,9 +76,8 @@ Handlebars.registerHelper "getMeetingName", ->
window.getMeetingName()
Handlebars.registerHelper "getShapesForSlide", ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
currentSlide = getCurrentSlideDoc()
# try to reuse the lines above
Meteor.Shapes.find({whiteboardId: currentSlide?.slide?.id})
@ -259,11 +258,14 @@ Meteor.methods
if !thickness.toString().match(/.*px$/)
"#" + thickness + "px" # leading "#" - to be compatible with Firefox
thickness
# applies zooming to the stroke thickness
@zoomStroke = (thickness) ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
currentSlide = @getCurrentSlideDoc()
ratio = (currentSlide?.slide.width_ratio + currentSlide?.slide.height_ratio) / 2
thickness * 100 / ratio
@getCurrentSlideDoc = -> # returns only one document
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})

View File

@ -3,9 +3,8 @@ Template.slide.rendered = ->
console.log "height = #{height}"
$('#whiteboard-paper').height((height-$("#whiteboard-navbar").height()-10)+'px')
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
currentSlide = getCurrentSlideDoc()
if currentSlide?.slide?.png_uri?
Template.slide.createWhiteboardPaper (wpm) ->
Template.slide.displaySlide wpm
@ -16,9 +15,7 @@ Template.slide.helpers
callback(Template.slide.whiteboardPaperModel)
displaySlide: (wpm) ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
currentSlide = getCurrentSlideDoc()
wpm.create()
wpm._displayPage(currentSlide?.slide?.png_uri)
@ -28,9 +25,8 @@ Template.slide.helpers
wpm?.moveCursor(pointer.x, pointer.y)
manuallyDisplayShapes: ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
currentSlide = getCurrentSlideDoc()
wpm = Template.slide.whiteboardPaperModel
shapes = Meteor.Shapes.find({whiteboardId: currentSlide?.slide?.id}).fetch()

View File

@ -806,10 +806,8 @@ class @WhiteboardPaperModel
boardWidth = @containerWidth
boardHeight = @containerHeight
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
currentSlide = getCurrentSlideDoc()
# TODO currentSlide undefined in some cases - will check later why
imageWidth = boardWidth * (currentSlide?.slide.width_ratio/100) or boardWidth
@ -824,8 +822,10 @@ class @WhiteboardPaperModel
console.log "imageWidth: #{imageWidth}"
console.log "imageHeight: #{imageHeight}"
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlideCursor = Meteor.Slides.find({"presentationId": presentationId, "slide.current": true})
_this = this
currentSlideCursor.observe # watching the current slide changes
changed: (newDoc, oldDoc) ->