Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to share and edit code #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ app.get '/chats/:chat_id', ensureSession, (req, res) ->
if err
res.send(500, err)
else
res.render 'chat', {title: TITLE, user: JSON.stringify(user), user_dict: user, chat: JSON.stringify(chat)}
res.render 'chat', {title: TITLE, user: JSON.stringify(user), user_dict: user, chat: JSON.stringify(chat), code: chat}

app.get '/logout', (req, res) ->
req.session = null
Expand All @@ -156,6 +156,12 @@ io.sockets.on 'connection', (socket) ->

socket.on 'propogate_hack', (hack_body) ->
io.sockets.in(room).emit 'new_hack', hack_body
models.Chat.update {_id: room}, {code: hack_body}, (err) ->
if err
console.error "ERROR SAVING MESSAGE TO CHAT #{room}: #{err}"
else
console.error "success"


socket.on 'update_title', (title) ->
socket.broadcast.to(room).emit 'title_update', title
Expand All @@ -177,3 +183,4 @@ io.sockets.on 'connection', (socket) ->
console.error "ERROR SAVING MESSAGE TO CHAT #{room}: #{err}"
else
console.error "success"

1 change: 1 addition & 0 deletions models.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ChatSchema = new mongoose.Schema
title: String
users: [{type: mongoose.Schema.ObjectId, ref: 'user'}]
messages: []
code: String

UserSchema = new mongoose.Schema
name: String
Expand Down
20 changes: 15 additions & 5 deletions static/js/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ $("#propogate-hack").click ->
socket.emit "propogate_hack", hack_body
$("#hackmodal").modal('hide');

getCode: ->
$('#hackmodal').modal({backdrop: 'static'});
$("#hackmodal").on 'shown.bs.modal', ->
window.editor.refresh()

window.ChatView = Backbone.View.extend
el: 'body'

events:
"keyup .sendbox": "onSendBoxKeyUp"
"click .sendbutton": "sendFromButton"
"keyup #title": "onTitleEditorKeyUp"
"click .addCode": "getCode"

initialize: (user, chat) ->
@chat = chat
Expand All @@ -74,13 +80,12 @@ window.ChatView = Backbone.View.extend

socket.emit 'subscribe', @chat._id

socket.on "new_hack", (hack_body) ->
console.log "RECIEVED HACK!!"
window.hacks.push(hack_body)
console.log "window.hacks is below"
console.log window.hacks
socket.on "new_hack", (hack_body) ->
console.log "RECEIVED HACK!!"
editor.doc.setValue(hack_body)
window.TURNED_ON = true


if @chat.title
@updateTitle @chat.title

Expand Down Expand Up @@ -112,6 +117,11 @@ window.ChatView = Backbone.View.extend
document.title = title
$("#title").val(title);

getCode: ->
$('#hackmodal').modal({backdrop: 'static'});
$("#hackmodal").on 'shown.bs.modal', ->
window.editor.refresh()

scrollToBottom: ->
$("#chatbox").scrollTop $('#chatbox')[0].scrollHeight

Expand Down
10 changes: 2 additions & 8 deletions views/chat.jade
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ block content
span.alt : 
input.sendbox(type="text", required="required", placeholder="Message")
button.sendbutton(disabled="true") Send
button.addCode Code
i.ion-ios7-paperplane
#hackmodal.modal.fade
.modal-dialog
Expand All @@ -24,14 +25,7 @@ block content
h4.modal-title Hack the Chat
.modal-body(style='text-align:left')
textarea.hackbox(style="width:100%; height: 300px", autofocus='autofocus')
| function (text, callback) {
| // This is what you want to capture
| var INDENTIFIER = "";
|
| if (text.slice(0, INDENTIFIER.length - 1) is INDENTIFIER) {
| // Your code goes here!
| }
|}
| #{code.code}
.modal-footer
button.btn.btn-default(type='button', data-dismiss='modal', style="float:left") Close
button.btn.btn-danger#propogate-hack(type='button') Propogate hack
Expand Down