Skip to content

Commit

Permalink
* Initial commit for Stackato Sample App Contest.
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyt committed Aug 20, 2011
0 parents commit a94b556
Show file tree
Hide file tree
Showing 111 changed files with 29,281 additions and 0 deletions.
685 changes: 685 additions & 0 deletions Changes.txt

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions LEGAL.txt
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,72 @@
SOCIALCALC LEGAL.txt FILE:

LEGAL INFORMATION

This LEGAL.txt file accompanies the SocialCalc program. It includes notices required by the
licenses as well as general legal notices.

=========================================
COPYRIGHT AND ATTRIBUTION NOTICES
=========================================

Copyright (C) 2009 Socialtext, Inc.
All Rights Reserved.

image:sc-logo.gif
"SocialCalc"
http://www.socialcalc.org/xoattrib

=========================================
SOURCE CODE AVAILABILITY NOTICE
=========================================

The source code for this product is available from:
http://socialcalc.org/.

=========================================
GENERAL LEGAL NOTICES
=========================================

wikiCalc, Garden, and Software Garden are registered trademarks of Software Garden, Inc.
Socialtext and SocialCalc are registered trademarks of Socialtext, Inc.
The Socialtext logo and Dreamcatcher are trademarks of Socialtext, Inc.

=========================================
LEGAL NOTICES REQUIRED BY THE LICENSE
=========================================

CHANGES MADE TO THE COVERED CODE (see CPAL Version 1.0 Section 3.3):

2008-02-08:
Original Code started as a translation to JavaScript of code in SocialCalc 1.1.0 plus
much new code.

Python code for the OLPC XO-1 initially coded by Luke Closs of Socialtext, Inc.

JavaScript initially coded by Dan Bricklin of Software Garden, Inc., for Socialtext, Inc.
Based in part on the SocialCalc 1.1.0 code written in Perl.
The SocialCalc 1.1.0 code was:
Portions (c) Copyright 2005, 2006, 2007 Software Garden, Inc.
All Rights Reserved.
Portions (c) Copyright 2007 Socialtext, Inc.
All Rights Reserved.
The Perl SocialCalc started as modifications to the wikiCalc(R) program, version 1.0.
wikiCalc 1.0 was written by Software Garden, Inc.
Unless otherwise specified, referring to "SocialCalc" in comments refers to this
JavaScript version of the code, not the SocialCalc Perl code.

----------

(Documentation of future changes as the result of Modifications, including the date of
change, will go here in this LEGAL.txt file. This documentation may be summaries of
changes with the more detailed descriptions included in the actual modified files as
appropriate.)

==========

THIRD PARTY CLAIMS (see CPAL Version 1.0 Section 3.4(a)):

None.

[End of LEGAL.txt]

705 changes: 705 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions README
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,32 @@
-=[MeetingCalc]=-

Language: CoffeeScript
Runtime: Node.js
Services: Redis
Browsers currently tested: Safari & Firefox.

.oO( Setup Instructions )Oo.

$ stackato push meetingcalc
Would you like to deploy from the current directory ? [Yn]:
Application Deployed URL: 'meetingcalc.stackato.local'?
Detected a Node.js Application, is this correct ? [Yn]:
Memory Reservation ? (64M, 128M, 256M, 512M, 1G, or 2G):
Would you like to bind any services to 'meetingcalc' ? [yN]: y
The following system services are available
1. mongodb
2. mysql
3. postgresql
4. redis
5. <None of the above>
Please select one you wish to provision: 4
Specify the name of the service [redis-dd80a]:
Creating Service: OK
Binding Service: OK
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (12K): 98% OK
Push Status: OK
Staging Application: OK
189 changes: 189 additions & 0 deletions app.coffee
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,189 @@
port = Number(process.env.VCAP_APP_PORT || 3000)
host = process.env.VCAP_APP_HOST || '127.0.0.1'
redisPort = null
redisHost = null
redisPass = null

services = JSON.parse(process.env.VCAP_SERVICES || "{}")
for name, items of services
continue unless /^redis/.test(name)
if items && items.length
redisPort = items[0].credentials.port
redisHost = items[0].credentials.hostname
redisPass = items[0].credentials.password

db = require('redis').createClient(redisPort, redisHost)
db.auth(redisPass) if redisPass

require('zappa') port, host, {db}, ->
enable 'serve jquery'
app.use express.static __dirname

def {db}

get '/': ->
response.contentType 'text/html'
response.sendfile 'index.mt'

get '/edit': ->
response.contentType 'text/html'
response.sendfile 'index.mt'

get '/start': -> render 'start'
get '/new': ->
response.redirect require("uuid-pure").newId(10)

view room: ->
coffeescript ->
window.location = '/#' + window.location.pathname.replace(/.*\//, '')

view start: ->
div id:"topnav_wrap", -> div id:"navigation"
div id:"intro-left", ->
h1 "MeetingCalc"
h2 "MeetingCalc is a web spreadsheet."
p "Your data is saved on the web, and people can edit the same document at the same time. Everybody's changes are instantly reflected on all screens."
p "Work together on inventories, survey forms, list managements, brainstorming sessions and more!"
div id:"intro-links", ->
a id:"newpadbutton", href:"/new", ->
span "Create new pad"
small "No sign-up, start editing instantly"

view layout: ->
html ->
head ->
title "MeetingCalc"
link href:"/start.css", rel:"stylesheet", type:"text/css"
body id:"framedpagebody", class:"home", ->
div id:"top", -> @body

at broadcast: ->
#io.sockets.in(@room).emit 'broadcast', @
switch @type
when 'chat'
db.rpush "chat-#{@room}", @msg, =>
io.sockets.emit 'chat', @
return
when 'ask.ecells'
db.hgetall "ecell-#{@room}", (err, values) =>
io.sockets.emit 'broadcast',
type: 'ecells'
ecells: values
room: @room
return
when 'my.ecell'
db.hset "ecell-#{@room}", @user, @ecell
return
when 'execute'
db.rpush "log-#{@room}", @cmdstr, =>
io.sockets.emit 'broadcast', @
return
when 'ask.snapshot'
db.lrange "log-#{@room}", 0, -1, (err, log) =>
db.lrange "chat-#{@room}", 0, -1, (err, chat) =>
io.sockets.emit 'broadcast',
type: 'log'
to: @user
room: @room
log: log
chat: chat
return
io.sockets.emit 'broadcast', @

client '/player.js': ->
SocialCalc ?= {}
SocialCalc._username = Math.random().toString()
SocialCalc.isConnected = true
SocialCalc.hadSnapshot = false
SocialCalc._room = window.location.hash.replace('#', '')
unless SocialCalc._room
window.location = '/start'
return

connect()
#subscribe(SocialCalc._room)

SocialCalc.Callbacks.broadcast = (type, data={}) ->
return unless SocialCalc.isConnected
data.user = SocialCalc._username
data.room = SocialCalc._room
data.type = type
emit 'broadcast', data

SocialCalc.isConnected = true
SocialCalc.Callbacks.broadcast "ask.snapshot"

at broadcast: ->
return unless SocialCalc?.isConnected
return if @user == SocialCalc._username
return if @to and @to != SocialCalc._username
return if @room and @room != SocialCalc._room

editor = SocialCalc.CurrentSpreadsheetControlObject.editor
switch @type
when "chat"
window.addmsg @msg
when "ecells"
for user, ecell of @ecells
continue if user == SocialCalc._username
peerClass = " " + user + " defaultPeer"
find = new RegExp(peerClass, "g")
cr = SocialCalc.coordToCr(ecell)
cell = SocialCalc.GetEditorCellElement(editor, cr.row, cr.col)
cell.element.className += peerClass if cell.element.className.search(find) == -1
break
when "ecell"
peerClass = " " + @user + " defaultPeer"
find = new RegExp(peerClass, "g")
if @original
origCR = SocialCalc.coordToCr(@original)
origCell = SocialCalc.GetEditorCellElement(editor, origCR.row, origCR.col)
origCell.element.className = origCell.element.className.replace(find, "")
cr = SocialCalc.coordToCr(@ecell)
cell = SocialCalc.GetEditorCellElement(editor, cr.row, cr.col)
cell.element.className += peerClass if cell.element.className.search(find) == -1
when "ask.snapshot"
SocialCalc.Callbacks.broadcast "snapshot",
to: @user
snapshot: SocialCalc.CurrentSpreadsheetControlObject.CreateSpreadsheetSave()
when "ask.ecell"
SocialCalc.Callbacks.broadcast "ecell",
to: @user
ecell: editor.ecell.coord
break
when "log"
break if SocialCalc.hadSnapshot
SocialCalc.hadSnapshot = true
spreadsheet = SocialCalc.CurrentSpreadsheetControlObject
window.addmsg @chat.join("\n"), true
cmdstr = @log.join("\n")
SocialCalc.CurrentSpreadsheetControlObject.context.sheetobj.ScheduleSheetCommands cmdstr, false, true
editor = SocialCalc.CurrentSpreadsheetControlObject.editor
# editor.MoveECellCallback.broadcast = (e) ->
# SocialCalc.Callbacks.broadcast "my.ecell"
# ecell: e.ecell.coord
when "snapshot"
break if SocialCalc.hadSnapshot
SocialCalc.hadSnapshot = true
spreadsheet = SocialCalc.CurrentSpreadsheetControlObject
parts = spreadsheet.DecodeSpreadsheetSave(@snapshot)
if parts
if parts.sheet
spreadsheet.sheet.ResetSheet()
spreadsheet.ParseSheetSave @snapshot.substring(parts.sheet.start, parts.sheet.end)
spreadsheet.editor.LoadEditorSettings @snapshot.substring(parts.edit.start, parts.edit.end) if parts.edit
if spreadsheet.editor.context.sheetobj.attribs.recalc == "off"
spreadsheet.ExecuteCommand "redisplay", ""
spreadsheet.ExecuteCommand "set sheet defaulttextvalueformat text-wiki"
else
spreadsheet.ExecuteCommand "recalc", ""
spreadsheet.ExecuteCommand "set sheet defaulttextvalueformat text-wiki"
break
when "execute"
SocialCalc.CurrentSpreadsheetControlObject.context.sheetobj.ScheduleSheetCommands @cmdstr, @saveundo, true
break

get '/:room': ->
@layout = no
render 'room', @

Loading

0 comments on commit a94b556

Please sign in to comment.