1
0
mirror of https://github.com/fazo96/markcloud.git synced 2025-01-26 13:34:19 +01:00

can now make private documents

This commit is contained in:
fazo96 2014-10-07 10:21:07 +02:00
parent 66e3ea81a9
commit 0c37404201
4 changed files with 52 additions and 37 deletions

View File

@ -23,11 +23,9 @@ loggedInController = RouteController.extend
Router.map -> Router.map ->
@route 'home', @route 'home',
path: '/' path: '/'
waitOn: -> Meteor.subscribe 'docs'
action: -> action: ->
if !@ready() if !@ready() then @render 'spinner', to: 'outside'
@render(); @render 'spinner', to: 'outside' @render()
else @render()
@route 'doc', @route 'doc',
path: '/d/:_id' path: '/d/:_id'
controller: docController controller: docController
@ -41,7 +39,7 @@ Router.map ->
if err then errCallback err else Router.go 'home' if err then errCallback err else Router.go 'home'
@route 'edit', @route 'edit',
path: '/edit/:_id' path: '/edit/:_id'
template: 'new' template: 'editor'
controller: loggedInController controller: loggedInController
waitOn: -> Meteor.subscribe 'doc', @params._id waitOn: -> Meteor.subscribe 'doc', @params._id
data: -> docs.findOne @params._id data: -> docs.findOne @params._id
@ -50,16 +48,17 @@ Router.map ->
waitOn: -> waitOn: ->
[Meteor.subscribe('docs', @params.user), [Meteor.subscribe('docs', @params.user),
Meteor.subscribe('user',@params.user)] Meteor.subscribe('user',@params.user)]
data: -> userId: @params.user data: -> Meteor.users.findOne @params.user
onBeforeAction: -> onBeforeAction: ->
if Meteor.user() and !@params.user if Meteor.user() and !@params.user
Router.go 'profile', user: Meteor.user()._id Router.go 'profile', user: Meteor.user()._id
action: -> action: ->
if !@params.user then @render '404' if !@data() then @render '404'
else @render() else if @ready() then @render()
else @render 'loading'
@route 'delete', @route 'delete',
controller: loggedInController controller: loggedInController
@route 'new' @route 'new', template: 'editor'
@route 'signup', @route 'signup',
controller: loggedOutController controller: loggedOutController
@route 'signin', @route 'signin',
@ -84,8 +83,8 @@ Template.layout.notHome = -> Router.current().route.name isnt 'home'
Template.layout.showSpinner = -> 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.showTitleChecked = -> return "checked" unless @showTitle is no Template.editor.showTitleChecked = -> return "checked" unless @showTitle is no
Template.new.events Template.editor.events
'click #upload': (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'
@ -95,6 +94,7 @@ Template.new.events
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')
public: $('#make-public').is(':checked')
}, (err) => }, (err) =>
if err then errCallback err if err then errCallback err
else else
@ -104,17 +104,17 @@ Template.new.events
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')
public: $('#make-public').is(':checked')
}, (err,id) -> }, (err,id) ->
if err then errCallback err if err then errCallback err
else notify type:'success', msg:'Document created successfully' else notify type:'success', msg:'Document created successfully'
if id then Router.go 'doc', _id: id if id then Router.go 'doc', _id: id
Template.profile.name = -> Meteor.user().username
Template.profile.isMe = -> Template.profile.isMe = ->
Meteor.user() and Meteor.user()._id is @userId Meteor.user() and Meteor.user()._id is @_id
Template.profile.noDocs = -> docs.find(owner: @userId).count() is 0 Template.profile.noDocs = -> docs.find(owner: @_id).count() is 0
Template.profile.documents = -> Template.profile.documents = ->
docs.find {owner: @userId}, sort: dateCreated: -1 docs.find {owner: @_id}, sort: dateCreated: -1
Template.profile.events Template.profile.events
'click #logout': -> Meteor.logout(); Router.go 'home' 'click #logout': -> Meteor.logout(); Router.go 'home'

View File

@ -1,6 +1,7 @@
// Body // Body
.container { .container {
max-width: 40em; max-width: 35em;
margin-bottom: 1.5em;
} }
.close { .close {
@ -74,3 +75,7 @@
margin-top: 1em; margin-top: 1em;
margin-bottom: 1em; margin-bottom: 1em;
} }
.label {
margin-top: 2px;
}

View File

@ -27,6 +27,11 @@
</div> </div>
</template> </template>
<template name="docLayout">
{{> yield region="outside"}}
<div class="container">{{> yield}}</div>
</template>
<template name="home"> <template name="home">
{{#markdown}} {{#markdown}}
### Share your markdown easily ### Share your markdown easily
@ -65,21 +70,18 @@ You will be able to delete your account and all your data whenever you want.
</div> </div>
</template> </template>
<template name="new"> <template name="editor">
<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" value="{{title}}"> <input type="text" id="title" class="form-control" placeholder="Title" value="{{title}}">
<input type="checkbox" id="show-title" {{showTitleChecked}}> <input type="checkbox" id="show-title" {{showTitleChecked}}>
Show title in document Show title in document
<input type="checkbox" id="make-public" {{public}}>
Make document visible on your profile
<textarea id="editor" class="form-control" rows="10" placeholder="Write your markdown :)" autofocus>{{text}}</textarea> <textarea id="editor" class="form-control" rows="10" placeholder="Write your markdown :)" autofocus>{{text}}</textarea>
<button id="upload" class="btn btn-primary"> <button id="upload" class="btn btn-primary">
<i class="fa fa-upload"></i> {{#if _id}}Update{{else}}Create{{/if}}</button> <i class="fa fa-upload"></i> {{#if _id}}Update{{else}}Create{{/if}}</button>
</template> </template>
<template name="docLayout">
{{> yield region="outside"}}
<div class="container">{{> yield}}</div>
</template>
<template name="doc"> <template name="doc">
{{#if valid}} {{#if valid}}
{{#if showTitle}}<h1>{{title}}</h1><hr>{{/if}} {{#if showTitle}}<h1>{{title}}</h1><hr>{{/if}}
@ -192,20 +194,12 @@ You will be able to delete your account and all your data whenever you want.
<template name="profile"> <template name="profile">
{{#if isMe}} {{#if isMe}}
<div class="text-center">
<p>Hello {{name}} ({{mail}}). This is your profile.</p>
</div>
{{/if}}
{{#if noDocs}}
<div class="text-center"> <div class="text-center">
{{#if isMe}} <p>Hello <b>{{username}}</b> ({{mail}}). This is your profile.</p>
<p>You don't have any documents yet.</p> {{#if noDocs}}
{{else}} <p>You don't have any documents yet.</p>
<p>This user does not have any documents.</p> {{/if}}
{{/if}}
</div> </div>
{{/if}}
{{#if isMe}}
<div class="text-center" id="profile-tools"> <div class="text-center" id="profile-tools">
<a class="btn btn-primary" id="logout"> <a class="btn btn-primary" id="logout">
<i class="fa fa-sign-out"></i> Logout</a> <i class="fa fa-sign-out"></i> Logout</a>
@ -214,11 +208,24 @@ You will be able to delete your account and all your data whenever you want.
<a class="btn btn-danger" href="/delete"> <a class="btn btn-danger" href="/delete">
<i class="fa fa-exclamation-circle"></i> Delete Account</a> <i class="fa fa-exclamation-circle"></i> Delete Account</a>
</div> </div>
{{else}}
<div class="text-center">
{{#if noDocs}}
<p>{{username}} doesn't have any public documents.</p>
{{else}}
<p>These are {{username}}'s public documents.</p>
{{/if}}
</div>
{{/if}} {{/if}}
{{#unless noDocs}} {{#unless noDocs}}
<ul class="list-group"> <ul class="list-group">
{{#each documents}} {{#each documents}}
<a class="list-group-item" href="/d/{{_id}}">{{title}}</a> <a class="list-group-item" href="/d/{{_id}}">
{{title}}
{{#if public}}
<span class="label label-primary pull-right">Public</span>
{{/if}}
</a>
{{/each}} {{/each}}
</ul> </ul>
{{/unless}} {{/unless}}

View File

@ -20,10 +20,13 @@ validatedUser = (uid) ->
Meteor.publish 'doc', (id) -> docs.find {_id: id}, limit: 1 Meteor.publish 'doc', (id) -> docs.find {_id: id}, limit: 1
Meteor.publish 'docs', (userId) -> Meteor.publish 'docs', (userId) ->
if userId? then docs.find {owner: userId}, fields: text: 0 if userId?
if userId is @userId
docs.find {owner: userId}, fields: text: 0
else docs.find {owner: userId, public: yes}, fields: text: 0
else docs.find {}, fields: text: 0 else docs.find {}, fields: text: 0
Meteor.publish 'user', (id) -> Meteor.publish 'user', (id) ->
Meteor.users.find {_id: id}, fields: {username: 1} Meteor.users.find id, fields: {username: 1}
docs.allow docs.allow
insert: (uid,doc) -> insert: (uid,doc) ->