diff --git a/articler.coffee b/articler.coffee index c624001..cfb4cc1 100644 --- a/articler.coffee +++ b/articler.coffee @@ -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 \ No newline at end of file diff --git a/main.coffee b/main.coffee index 4033896..3f478f7 100644 --- a/main.coffee +++ b/main.coffee @@ -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) @@ -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) -> @@ -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 } @@ -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 = [] diff --git a/public/less/bootstrap.css b/public/less/bootstrap.css index fa0eea5..a782910 100644 --- a/public/less/bootstrap.css +++ b/public/less/bootstrap.css @@ -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; } diff --git a/public/less/utilities.less b/public/less/utilities.less index 7fd0217..8711d89 100755 --- a/public/less/utilities.less +++ b/public/less/utilities.less @@ -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; } + + + diff --git a/views/layout.jade b/views/layout.jade index c7ed6e6..1ddb9ae 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -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 +" " @@ -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 diff --git a/views/new.jade b/views/new.jade index de13944..850925b 100644 --- a/views/new.jade +++ b/views/new.jade @@ -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 diff --git a/views/single.jade b/views/single.jade index a288f38..1e228c3 100644 --- a/views/single.jade +++ b/views/single.jade @@ -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)