Skip to content

Commit

Permalink
yo
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidkahl committed Mar 11, 2012
1 parent e5a2cc6 commit 83ce3b4
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 45 deletions.
9 changes: 8 additions & 1 deletion articler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,12 @@ class Articler
callback err
else
callback null, articles, res


deleteById: (id, revision, callback) ->
@.db.remove id, revision, (err, res) ->
if (err)
callback err
else
callback null, res

exports.Articler = Articler
40 changes: 39 additions & 1 deletion main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ md = require('node-markdown').Markdown
auth = require './auth.coffee'
crypto = require 'crypto'

process.on 'uncaughtException', (err) ->
console.log err.stack

# Session perstistence implemented with CouchDB
sessionDB = require('connect-couchdb')(exp)
Expand Down Expand Up @@ -61,12 +63,16 @@ app.get '/new', (req, res) ->

app.post '/new', (req, res) ->
if (req.session.auth.loggedIn)
console.log req.session.auth
uid = req.session.auth.userId
scene.save {
createUserId: uid
createUserName: req.session.auth.twitter.user.name
title: req.param 'title'
body: req.param 'body'
url: req.param 'url'
found: req.param "found"
creator: req.param "creator"
created_at: new Date()
stories: []
}, (err, returnedDoc, returnedData) ->
Expand Down Expand Up @@ -99,15 +105,27 @@ app.get '/:id', (req, res) ->
else
res.redirect('/')

app.post '/:id/delete', (req, res) ->
storyId=req.params.id
scene.findById storyId, (err, doc) ->
if (req.session.auth.loggedIn)
uid = req.session.auth.userId
if (doc.value.createUserId == uid)
scene.deleteById storyId, doc.value._rev, (deleteErr, deleteRes) ->
throw deleteErr if deleteErr
res.redirect '/'

app.post '/:id/add', (req, res) ->
scene.findById req.params.id, (findErr, originalDoc) ->

if originalDoc
tempDoc = originalDoc.value
uid = req.session.auth.userId

newStory = {
title: req.param "title"
story: req.param "story"
createUserName: req.session.auth.twitter.user.name
createUserId: uid
}

Expand All @@ -124,8 +142,28 @@ app.post '/:id/add', (req, res) ->
console.log "could not retrieve original document"
res.redirect('/'+req.params.id)

app.post '/:id/save/:commentId', (req, res) ->
app.post '/:id/delete/:commentId', (req, res) ->
console.log "finding..."
scene.findById req.params.id, (err, doc) ->
newStoryUserId = 'not authed'
newStories = []
stories = doc.value.stories
stories.forEach (story) ->
if (story._id != req.params.commentId)
newStories.push story
else
newStoryUserId = story.createUserId
doc.value.stories = newStories
if (newStoryUserId == req.session.auth.userId)
scene.saveById req.params.id, doc.value, (saveErr, saveDoc, saveRes) ->
throw saveErr if saveErr
res.notice = 'Saved.'
res.redirect '/'+req.params.id
else
res.redirect '/'+req.params.id


app.post '/:id/save/:commentId', (req, res) ->
scene.findById req.params.id, (err, doc) ->
newStoryUserId = 'not authed'
newStories = []
Expand Down
9 changes: 6 additions & 3 deletions public/less/bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -3686,7 +3686,10 @@ body {
h1 {
color: #0088cc;
}
.navbar .nav li a i {
font-size: 100%;
margin-right: 3px;
.sceneTitle {
margin-top: -5px;
margin-bottom: 10px;
}
.info p i {
color: #0088cc;
}
9 changes: 6 additions & 3 deletions public/less/utilities.less
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ h1 {
color:@linkColor;
}

.navbar .nav li a i {
font-size:100%;
margin-right: 3px;
.sceneTitle {
margin-top: -5px;
margin-bottom: 10px;
}



32 changes: 21 additions & 11 deletions views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,37 @@ html
div.container-fluid
a(href='/').brand
i.icon-fire.icon-white
| Spark.
|
span Spark.
div.nav-collapse
ul.nav
li.divider-vertical
li
a(href='/scenes')
i.icon-book.icon-white
| Browse Scenes
i.icon-book.icon-white
|
span Browse Scenes
li
a(href='/new')
i.icon-file.icon-white
| Add Scene
i.icon-file.icon-white
|
span Add Scene
li
a.highlight(href='/random')
i.icon-random.icon-white
|
span Inspire me!
li.divider-vertical
li
a(href='#')
i.icon-envelope.icon-white
| Contact
i.icon-envelope.icon-white
|
span Contact
li
a(href='/howto')
i.icon-info-sign.icon-white
| HowTo
i.icon-info-sign.icon-white
|
span HowTo
p.navbar-text.pull-right
- if (everyauth.loggedIn)
span= "Logged in as "+ everyauth.twitter.user.name +" "
Expand All @@ -49,8 +59,8 @@ html
|,
a(href= "http://lesscss.org/")="LESS"
|,
a(href= "http://coffeescript.org/")="Coffee-Script"
| and
a(href= "http://coffeescript.org/")="Coffee-Script"
| and
a(href= "http://twitter.github.com/bootstrap/")="Twitter Bootstrap"
|.
br
Expand Down
4 changes: 4 additions & 0 deletions views/new.jade
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ div.row
input.input-large(type="text", id="title", name="title", placeholder="Title of the image")
.control-group
input.input-large(type="text", id="url", name="url", placeholder="URL to image")
.control-group
input.input-large(type="text", id="found", name="found", placeholder="Please link the Thread/Site where this image came from")
.control-group
input.input-large(type="text", id="creator", name="creator", placeholder="Who created this image? Who is the © owner?")
.control-group
textarea.input-large(name="body", id="body", rows="2", placeholder="Please enter a short description here.")
.control-group
Expand Down
77 changes: 51 additions & 26 deletions views/single.jade
Original file line number Diff line number Diff line change
@@ -1,53 +1,78 @@
div.row
div.span4
.well
h4 Scene found at
.well.info
p
a(href="bla") CGTalk
h4 Scene created by
p Some guy on the web
i.icon-flag
|
strong Scene found at
a.pull-right(href=doc.found) Location
p
i.icon-user
|
strong Scene created by
span.pull-right= doc.creator
div.span4
.well
h4 Some other info
p Oh are you for real?
h4 The shocking fact
p The internet is for...
.well.info
p
i.icon-comment
|
strong Stories for this Scene
span.pull-right 2
p
i.icon-exclamation-sign
|
strong Copyright Information
span.pull-right
a(href="#") linked here
div.span4
.well
h4 Description
p And here is the ever so interesting lorem ipsum part. Blergh Blergh BLergh. Also, Cat Pictures.
.well.info
p
i.icon-cog
|
strong Feedback
span.pull-right Report Problem

- if (typeof(notice) != 'undefined')
p=notice

div.row
div.span6
.well
h1= doc.title
h1.sceneTitle= doc.title
div.created.hide #{(new Date(doc.created_at)).toGMTString()}
div.image
a#scene(href=doc.url)
img(src=doc.url)
script
$(function(){$('#scene').lightBox({overlayOpacity:0.9});});
h6.sceneUserName added by #{doc.createUserName}
- if (everyauth.userId == doc.createUserId)
- var editLink = "/"+doc._id+'/edit'
div.btn-group
a.btn.btn-mini.btn-warning(href= editLink) Edit Image
|
a.btn.btn-mini.btn-danger(href=("/"+doc._id+'/delete')) Delete Image
form(method="post", action="/"+doc._id+'/delete')
div.btn-group
button.btn.btn-mini.btn-warning.disabled(href= editLink) Edit Image
|
button.btn.btn-mini.btn-danger(href=("/"+doc._id+'/delete')) Delete Image
div.span6
- each story in doc.stories
div.well
- if (everyauth.userId == story.createUserId)
- switcheroo = "javascript:$('#"+story._id+"').removeClass('hide').addClass('show');$('#"+story._id+"_text').removeClass('show').addClass('hide');$('#"+story._id+"_alert').removeClass('show').addClass('hide');"
form.form-horizontal.hide(id=story._id, method="post", action="/"+id+"/save/"+story._id)
.control-group
input.input-xlarge(type="text", id="title", name="title", value=story.title)
.control-group
textarea.input-xlarge(name="story", id="story", rows="4")= story.story
.control-group
input.btn.btn-primary(type="submit", value="Save changes to your Scene.")
div.hide(id=story._id)
form.form-horizontal(method="post", action="/"+id+"/save/"+story._id)
.control-group
input.input-xlarge(type="text", id="title", name="title", value=story.title)
.control-group
textarea.input-xlarge(name="story", id="story", rows="4")= story.story
.control-group
input.btn.btn-primary.btn-mini(type="submit", value="Save changes to your Story.")
form(method="post", action='/'+id+'/delete/'+story._id)
input.btn.btn-danger.btn-mini(type='submit', value='Delete your Story')
div.alert.alert-info(id=story._id+'_alert',onclick=switcheroo) Click here to edit this Story.
div(id=story._id+'_text')
h4= story.title
p= story.story
h6.storyUserName written by #{story.createUserName}
p.story= story.story


- if (everyauth.loggedIn)
Expand Down

0 comments on commit 83ce3b4

Please sign in to comment.