Skip to content
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
2 changes: 2 additions & 0 deletions bookhub/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ mpowaga:autoform-summernote
fortawesome:fontawesome
accounts-password
vasaka:livescript-compiler
cfs:standard-packages
cfs:filesystem
10 changes: 10 additions & 0 deletions bookhub/client/menu_sidebar/menu_sidebar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
if ( Meteor.isClient ) {

Template.menu_sidebar.helpers( {
userphoto: function() {
return IconsFS.findOne( {
"metadata.authorId": Meteor.userId(),
"metadata.iscur": 1
});
}
});

Template.menu_sidebar.events( {
'click .menu-btn': function() {
$('.left.menu.sidebar').sidebar( 'toggle' );
Expand Down
9 changes: 7 additions & 2 deletions bookhub/client/menu_sidebar/menu_sidebar.tpl.jade
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
div.ui.left.menu.sidebar.vertical.inverted
div.item
if currentUser
img.ui.circular.tiny.image.userphoto(src='/img/head.jpg')
a(href='/user/{{currentUser._id}}')
if userphoto
img.userphoto-size-small.tiny.image.userphoto(src="/userphoto-img/{{userphoto.copies.userphoto.key}}")
else
img.userphoto-size-small.tiny.image.userphoto(src='/img/default-userphoto.jpg')
a.username(href='/user/{{currentUser._id}}') {{currentUser.profile.pseudonym}}
else
img.ui.circular.tiny.image.userphoto(src='/img/default-userphoto.jpg')
a(href='/sign')
img.ui.circular.tiny.image.userphoto(src='/img/default-userphoto.jpg')
a.username(href='/sign') 未登录
a.item(href='/home')
i.home.icon
Expand Down
23 changes: 22 additions & 1 deletion bookhub/client/user/user.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,25 @@
margin: 0 auto;
}

/*章节选择*/
/*头像*/
.no-display {
display: none;
}

.userphoto-size-small {
width: 100px;
height: 100px;
border-radius: 50%;
display: block;
}

.userphoto-size-big {
width: 150px;
height: 150px;
border-radius: 50%;
display: block;
}

div.userphoto {
width: 100%;
}
107 changes: 102 additions & 5 deletions bookhub/client/user/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ if ( Meteor.isClient ) {
selector: {
close: '.close'
}
})
});
//--- edited by LY ---
$('.edit-userphoto-modal').modal({
selector: {
close: '.close'
}
});
//--- edited by LY ---
}),

Template.user.helpers( {
Expand All @@ -17,13 +24,22 @@ if ( Meteor.isClient ) {
},
selfbooks: function() {
var id = Router.current().params.id;
return Novel.find( {
authorId: id
}).fetch();
//--- edited by LY ---
return FilesFS.find( {
"metadata.authorId": id
}).fetch();
//--- edited by LY ---
},
forkbooks: function() {

//
},
userphoto: function() {
var id = Router.current().params.id;
return IconsFS.findOne( {
"metadata.authorId": id,
"metadata.iscur": 1
});
}
}),

Template.user.events( {
Expand Down Expand Up @@ -67,7 +83,88 @@ if ( Meteor.isClient ) {
chapters: [],
bookComment: []
});
//--- edited by LY ---
var pics = $('#bookface')[0].files;
for (var i = 0, ln = pics.length; i < ln; i++) {
var pic = pics[i];
var newpic = new FS.File(pic);
newpic.metadata = {
authorId: Meteor.userId(),
novelId: novel_id,
novelname: e.target.name.value,
haspic: 1
}
FilesFS.insert(newpic);
}
if (pics.length == 0) {
var newpic = new FS.File();
newpic.metadata = {
authorId: Meteor.userId(),
novelId: novel_id,
novelname: e.target.name.value,
haspic: 0
}
FilesFS.insert(newpic);
}

// 按提交之后表单都要清空
e.target.name.value = ''
e.target.type.value = ''
e.target.summary.value = ''
e.target.bookface.value = ''
$('.edit-bookface-div').fadeOut();
$('#edit-bookface').attr("src","/img/default-bookface.jpg");
//--- edited by LY ---
},
//--- edited by LY ---
'click #userphoto': function() {
$('.edit-userphoto-modal').modal('show');
},
'click #edit-bookface': function() {
$('.edit-bookface-div').fadeToggle();
},
'change #bookface': function(e) {
var docObj = document.getElementById("bookface");
var imgObjPreview = document.getElementById("edit-bookface");
if (docObj.files && docObj.files[0]){
imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
}
},
'change #newUserphoto': function(e) {
var docObj = document.getElementById("newUserphoto");
var imgObjPreview = document.getElementById("edit-userphoto");
$('.upload-userphoto').removeClass('no-display');
if (docObj.files && docObj.files[0]){
imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
}
},
'submit .edit-userphoto-modal.form': function(e) {
e.preventDefault();
$('.edit-userphoto-modal').modal('hide');
var curdate = new Date();

//--- edited by LY ---
var pics = $('#newUserphoto')[0].files;
for (var i = 0, ln = pics.length; i < ln; i++) {
var pic = pics[i];
var newpic = new FS.File(pic);

Meteor.call('update-userphoto');

newpic.metadata = {
authorId: Meteor.userId(),
iscur: 1
}
IconsFS.insert(newpic);
}


// 按提交之后表单都要清空
e.target.newUserphoto.value = ''
$('.upload-userphoto').addClass('no-display');
//--- edited by LY ---
},
//--- edited by LY ---
})
}

Expand Down
40 changes: 34 additions & 6 deletions bookhub/client/user/user.tpl.jade
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
div.pusher
div.user-info-banner
div.userphoto
img.ui.small.circular.image(src="/img/head.jpg")
if userphoto
img#userphoto.middle.small.userphoto-size-big.image(src="/userphoto-img/{{userphoto.copies.userphoto.key}}")
else
img#userphoto.middle.small.userphoto-size-big.image(src="/img/default-userphoto.jpg")
div.username
h2 {{user.profile.pseudonym}}
div.main.container
Expand All @@ -14,9 +17,12 @@ div.pusher
div.four.wide.column
div.book
div.book-bottom-shadow
img.bookface-size.bookface(src='/img/default-bookface.jpg')
p.bookname 《{{name}}》
p.book_id(hidden) {{_id}}
if metadata.haspic
img.bookface-size.bookface(src='/upload-img/{{copies.images.key}}')
else
img.bookface-size.bookface(src='/img/default-bookface.jpg')
p.bookname 《{{metadata.novelname}}》
p.book_id(hidden) {{metadata.novelId}}
div.four.wide.column
div.ui.green.icon.button.bookface-size.create-book-btn
i.huge.plus.icon
Expand Down Expand Up @@ -62,7 +68,11 @@ div.ui.dimmer.modals.page
div.content
div.ui.image
div.upload-bookface.book-bottom-shadow.book
img.bookface-size.bookface(src='/img/default-bookface.jpg')
img#edit-bookface.bookface-size.bookface(src='/img/default-bookface.jpg')
div.fields
div.seven.wide.field.edit-bookface-div.no-display
label 封面图
input(id='bookface' type='file' name='bookface')
div.description
div.fields
div.seven.wide.field
Expand All @@ -76,4 +86,22 @@ div.ui.dimmer.modals.page
textarea(name='summary' required)
div.actions
div.ui.black.button.close 取消
input.ui.green.button(type='submit' value='创建')
input.ui.green.button(type='submit' value='创建')

div.ui.modals
form.ui.small.modal.form.edit-userphoto-modal
i.close.icon
div.header 修改头像
div.content
div.ui.image
div.upload-userphoto.book-bottom-shadow.book.no-display
img#edit-userphoto.bookface-size.bookface(src='/img/default-userphoto.jpg')

div.description
div.fields
div.seven.wide.field
label 新头像
input(id='newUserphoto' type='file' name='newUserphoto' required)
div.actions
div.ui.black.button.close 取消
input.ui.green.button(type='submit' value='确定')
61 changes: 61 additions & 0 deletions bookhub/data.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
var root = typeof exports != 'undefined' && exports !== null ? exports : this;

var base = "";
if (Meteor.isServer) {
base = process.env.PWD;
}

var FilesFS = new FS.Collection('images', {
stores: [new FS.Store.FileSystem('images', {
path: base + '/public/upload-img'
})]
});

var IconsFS = new FS.Collection('userphoto', {
stores: [new FS.Store.FileSystem('userphoto', {
path: base + '/public/userphoto-img'
})]
});


FilesFS.allow({
insert: function(userId, party){
return true;
},
update: function(userId, party){
return true;
},
remove: function(userId, party){
return true;
},
download: function(userId, party){
return true;
}
});


IconsFS.allow({
insert: function(userId, party){
return true;
},
update: function(userId, party){
return true;
},
remove: function(userId, party){
return true;
},
download: function(userId, party){
return true;
}
});

root.Novel = new Mongo.Collection("Novel");

root.FilesFS = FilesFS;

root.IconsFS = IconsFS;

Meteor.methods({
'update-userphoto': function() {
IconsFS.update( {
"metadata.authorId": Meteor.userId(),
}, {$set : { "metadata.iscur": 0 }}, {multi: true});
}
})