mirror of
https://github.com/fazo96/markcloud.git
synced 2025-01-25 13:24:20 +01:00
implemented edit and delete documents
This commit is contained in:
parent
67d87ecf04
commit
1a7de61d0f
@ -35,6 +35,21 @@ Router.map ->
|
|||||||
onBeforeAction: ->
|
onBeforeAction: ->
|
||||||
Accounts.verifyEmail @params.token, (err) ->
|
Accounts.verifyEmail @params.token, (err) ->
|
||||||
if err then errCallback err else Router.go 'home'
|
if err then errCallback err else Router.go 'home'
|
||||||
|
@route 'edit',
|
||||||
|
path: '/edit/:_id'
|
||||||
|
template: 'new'
|
||||||
|
waitOn: -> Meteor.subscribe 'doc', @params._id
|
||||||
|
data: -> docs.findOne @params._id
|
||||||
|
@route 'list',
|
||||||
|
path: '/list/:user?'
|
||||||
|
waitOn: -> Meteor.subscribe 'docs', @params.user
|
||||||
|
data: -> userId: @params.user
|
||||||
|
onBeforeAction: ->
|
||||||
|
if Meteor.user() and !@params.user
|
||||||
|
Router.go 'list', user: Meteor.user()._id
|
||||||
|
action: ->
|
||||||
|
if !@params.user then @render '404'
|
||||||
|
else @render()
|
||||||
@route 'new'
|
@route 'new'
|
||||||
@route 'signup'
|
@route 'signup'
|
||||||
@route 'signin', path: 'login'
|
@route 'signin', path: 'login'
|
||||||
@ -57,29 +72,72 @@ Template.layout.showSpinner = ->
|
|||||||
Meteor.status().connected is no or Router.current().ready() is no
|
Meteor.status().connected is no or Router.current().ready() is no
|
||||||
Template.home.ndocs = -> docs.find().count()
|
Template.home.ndocs = -> docs.find().count()
|
||||||
Template.new.events
|
Template.new.events
|
||||||
'click #new-btn': (e,t) ->
|
'click #upload': (e,t) ->
|
||||||
if t.find('#title').value is ''
|
if t.find('#title').value is ''
|
||||||
return notify msg: 'please insert a title'
|
return notify msg: 'please insert a title'
|
||||||
if t.find('#editor').value is ''
|
if t.find('#editor').value is ''
|
||||||
return notify msg: "can't create empty document"
|
return notify msg: "empty documents are not valid"
|
||||||
docs.insert {
|
if @_id then docs.update @_id, $set: {
|
||||||
|
title: t.find('#title').value
|
||||||
|
text: t.find('#editor').value
|
||||||
|
showTitle: $('#show-title').is(':checked')
|
||||||
|
}, (err) =>
|
||||||
|
if err then errCallback err
|
||||||
|
else
|
||||||
|
notify type:'success', msg:'Document updated'
|
||||||
|
Router.go 'doc', _id: @_id
|
||||||
|
else docs.insert {
|
||||||
title: t.find('#title').value
|
title: t.find('#title').value
|
||||||
text: t.find('#editor').value
|
text: t.find('#editor').value
|
||||||
showTitle: $('#show-title').is(':checked')
|
showTitle: $('#show-title').is(':checked')
|
||||||
dateCreated: moment().unix()
|
dateCreated: moment().unix()
|
||||||
}, (err,id) ->
|
}, (err,id) ->
|
||||||
errCallback err
|
if err then errCallback err
|
||||||
|
else notify type:'success', msg:'Document created successfully'
|
||||||
if id then Router.go 'doc', _id: id
|
if id then Router.go 'doc', _id: id
|
||||||
|
###docs.upsert @_id, $set: {
|
||||||
|
title: t.find('#title').value
|
||||||
|
text: t.find('#editor').value
|
||||||
|
showTitle: $('#show-title').is(':checked')
|
||||||
|
dateCreated: moment().unix()
|
||||||
|
}, (err,resp) ->
|
||||||
|
if err then errCallback err
|
||||||
|
else if @_id
|
||||||
|
notify type:'success', msg:'Document updated'
|
||||||
|
Router.go 'doc', _id: @_id
|
||||||
|
else
|
||||||
|
notify type:'success', msg:'Document created successfully'
|
||||||
|
Router.go 'doc', _id: resp.insertedId###
|
||||||
|
|
||||||
|
Template.list.documents = -> docs.find owner: @userId
|
||||||
|
|
||||||
Template.doc.source = -> Router.current().route.name is 'src'
|
Template.doc.source = -> Router.current().route.name is 'src'
|
||||||
Template.doc.rows = -> ""+@text.split('\n').length
|
Template.doc.rows = -> ""+@text.split('\n').length
|
||||||
Template.doc.canEdit = -> "disabled" unless Meteor.user()._id is @owner
|
Template.doc.valid = -> @text?
|
||||||
|
Template.doc.owned = -> Meteor.user()._id is @owner
|
||||||
Template.doc.events
|
Template.doc.events
|
||||||
|
'click #edit-doc': -> Router.go 'edit', _id: @_id
|
||||||
|
'click #del-doc': ->
|
||||||
|
if Meteor.user()._id is @owner
|
||||||
|
docs.remove @_id, (err) ->
|
||||||
|
if err then errCallback err
|
||||||
|
else notify type:'success', msg:'Document removed'
|
||||||
'click #src-doc': ->
|
'click #src-doc': ->
|
||||||
if Router.current().route.name is 'src'
|
if Router.current().route.name is 'src'
|
||||||
Router.go 'doc', _id: @_id
|
Router.go 'doc', _id: @_id
|
||||||
else Router.go 'src', _id: @_id
|
else Router.go 'src', _id: @_id
|
||||||
|
|
||||||
|
Template.signin.events
|
||||||
|
'click #signin': (e,t) ->
|
||||||
|
if not t.find('#mail').value
|
||||||
|
return notify msg: 'please enter an email'
|
||||||
|
else if not t.find('#pw').value
|
||||||
|
return notify msg: "Please enter a password"
|
||||||
|
else
|
||||||
|
Meteor.loginWithPassword t.find('#mail').value, t.find('#pw').value,(e)->
|
||||||
|
if e then errCallback e
|
||||||
|
else notify type:'success', msg:'Welcome back!'; Router.go 'home'
|
||||||
|
|
||||||
Template.signup.events
|
Template.signup.events
|
||||||
'click #signup': (e,t) ->
|
'click #signup': (e,t) ->
|
||||||
if not t.find('#mail').value
|
if not t.find('#mail').value
|
||||||
|
@ -18,6 +18,10 @@
|
|||||||
margin-top: 2em;
|
margin-top: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notification-area {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
// Editor
|
// Editor
|
||||||
|
|
||||||
#title {
|
#title {
|
||||||
@ -26,17 +30,21 @@
|
|||||||
#editor {
|
#editor {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
#new-btn {
|
#upload {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Viewer
|
// Viewer
|
||||||
|
|
||||||
#tools {
|
#tools {
|
||||||
margin-top: 1em;
|
margin-top: 0.5em;
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#src {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
// Sign up
|
// Sign up
|
||||||
#signup-container, #signin-container {
|
#signup-container, #signin-container {
|
||||||
#mail { margin-top: 2em; }
|
#mail { margin-top: 2em; }
|
||||||
|
@ -28,11 +28,11 @@
|
|||||||
|
|
||||||
<template name="new">
|
<template name="new">
|
||||||
<p>Write your document in <a href="https://help.github.com/articles/github-flavored-markdown/">GitHub Flavored Markdown</a> then submit it with the button. You will be redirected to its permanent link</p>
|
<p>Write your document in <a href="https://help.github.com/articles/github-flavored-markdown/">GitHub Flavored Markdown</a> then submit it with the button. You will be redirected to its permanent link</p>
|
||||||
<input type="text" id="title" class="form-control" placeholder="Title">
|
<input type="text" id="title" class="form-control" placeholder="Title" value="{{title}}">
|
||||||
<input type="checkbox" id="show-title" checked> Show title in document
|
<input type="checkbox" id="show-title" checked> Show title in document
|
||||||
<textarea id="editor" class="form-control" rows="10" placeholder="Write your markdown :)" autofocus></textarea>
|
<textarea id="editor" class="form-control" rows="10" placeholder="Write your markdown :)" autofocus>{{text}}</textarea>
|
||||||
<button id="new-btn" class="btn btn-primary">
|
<button id="upload" class="btn btn-primary">
|
||||||
<i class="fa fa-upload"></i> Upload</button>
|
<i class="fa fa-upload"></i> {{#if _id}}Update{{else}}Upload{{/if}}</button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="docLayout">
|
<template name="docLayout">
|
||||||
@ -41,29 +41,39 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="doc">
|
<template name="doc">
|
||||||
|
{{#if valid}}
|
||||||
{{#if showTitle}}<h1>{{title}}</h1><hr>{{/if}}
|
{{#if showTitle}}<h1>{{title}}</h1><hr>{{/if}}
|
||||||
{{#if text}}
|
<div class="notification-area">
|
||||||
|
{{> notifications}}
|
||||||
|
</div>
|
||||||
{{#if source}}
|
{{#if source}}
|
||||||
<textarea id="src" class="form-control" rows="{{rows}}" readonly>{{text}}</textarea>
|
<textarea id="src" class="form-control" rows="{{rows}}" readonly>{{text}}</textarea>
|
||||||
{{else}}
|
{{else}}
|
||||||
<div id="doc">{{#markdown}}{{text}}{{/markdown}}</div>
|
<div id="doc">{{#markdown}}{{text}}{{/markdown}}</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h1>Sorry</h1>
|
<h1>404</h1>
|
||||||
<p>This document is empty, expired, or never existed.</p>
|
<div class="notification-area">
|
||||||
|
{{> notifications}}
|
||||||
|
</div>
|
||||||
|
<p>This document is invalid, expired, never existed or was deleted.</p>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<hr>
|
<hr>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
{{#unless currentUser}}
|
{{#unless currentUser}}
|
||||||
<a href="/login">Log in</a> to edit and delete your documents<br>
|
<p><a href="/login">Log in</a> to edit and delete your documents<br></p>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
{{#if owned}}
|
||||||
|
<p>This document is <b>yours</b>.</p>
|
||||||
|
{{/if}}
|
||||||
|
{{#if valid}}
|
||||||
<div class="btn-group" id="tools">
|
<div class="btn-group" id="tools">
|
||||||
{{#if currentUser}}
|
{{#if currentUser}}{{#if owned}}
|
||||||
<button id="edit-doc" class="btn btn-primary" {{canEdit}}>
|
<button id="edit-doc" class="btn btn-primary">
|
||||||
<i class="fa fa-edit"></i> Edit</button>
|
<i class="fa fa-edit"></i> Edit</button>
|
||||||
{{/if}}
|
{{/if}}{{/if}}
|
||||||
{{#if source}}
|
{{#if source}}
|
||||||
<button id="src-doc" class="btn btn-success">
|
<button id="src-doc" class="btn btn-success">
|
||||||
<i class="fa fa-book"></i> View Document</button>
|
<i class="fa fa-book"></i> View Document</button>
|
||||||
@ -71,12 +81,13 @@
|
|||||||
<button id="src-doc" class="btn btn-success">
|
<button id="src-doc" class="btn btn-success">
|
||||||
<i class="fa fa-code"></i> View Source</button>
|
<i class="fa fa-code"></i> View Source</button>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if currentUser}}
|
{{#if currentUser}}{{#if owned}}
|
||||||
<button id="del-doc" class="btn btn-danger">
|
<button id="del-doc" class="btn btn-danger">
|
||||||
<i class="fa fa-trash"></i> Delete</button>
|
<i class="fa fa-trash"></i> Delete</button>
|
||||||
{{/if}}
|
{{/if}}{{/if}}
|
||||||
</div>
|
</div>
|
||||||
<br>Powered by <a href="/">MarkCloud</a>
|
<br>
|
||||||
|
{{/if}}Powered by <a href="/">MarkCloud</a>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -132,3 +143,9 @@
|
|||||||
<div class="text-center">Need an account? <a href="/signup">Sign Up!</a></div>
|
<div class="text-center">Need an account? <a href="/signup">Sign Up!</a></div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template name="list">
|
||||||
|
{{#each documents}}
|
||||||
|
<a href="/d/{{_id}}">{{title}}</a>
|
||||||
|
{{/each}}
|
||||||
|
</template>
|
||||||
|
@ -6,7 +6,9 @@ validatedUser = (uid) ->
|
|||||||
return yes for mail in u.emails when mail.verified is yes; no
|
return yes for mail in u.emails when mail.verified is yes; no
|
||||||
|
|
||||||
Meteor.publish 'doc', (id) -> docs.find {_id: id}, limit: 1
|
Meteor.publish 'doc', (id) -> docs.find {_id: id}, limit: 1
|
||||||
Meteor.publish 'docs', -> docs.find {}, fields: text: 0
|
Meteor.publish 'docs', (userId) ->
|
||||||
|
if userId? then docs.find {owner: userId}, fields: text: 0
|
||||||
|
else docs.find {}, fields: text: 0
|
||||||
Meteor.publish 'user', ->
|
Meteor.publish 'user', ->
|
||||||
if @userId
|
if @userId
|
||||||
Meteor.users.find {_id: @userId}, fields: {dateCreated: 1}
|
Meteor.users.find {_id: @userId}, fields: {dateCreated: 1}
|
||||||
@ -18,9 +20,8 @@ docs.allow
|
|||||||
doc.dateCreated = moment().unix()
|
doc.dateCreated = moment().unix()
|
||||||
if doc.owner and !uid then return no
|
if doc.owner and !uid then return no
|
||||||
if uid then doc.owner = uid
|
if uid then doc.owner = uid
|
||||||
console.log 'ok'
|
console.log doc.dateCreated
|
||||||
return yes
|
return yes
|
||||||
console.log 'nope'
|
|
||||||
return no
|
return no
|
||||||
docs.allow
|
docs.allow
|
||||||
# Owners can update and remove their documents
|
# Owners can update and remove their documents
|
||||||
|
Loading…
Reference in New Issue
Block a user