From 1d28434122681bb89b514491225992ed3a99f340 Mon Sep 17 00:00:00 2001 From: SimbaScorpio <425830509@qq.com> Date: Wed, 17 Jun 2015 12:53:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果图片上传不成功请修改data.js里的path为绝对路径 --- bookhub/.meteor/packages | 2 + bookhub/.meteor/versions | 19 ++++ bookhub/client/menu_sidebar/menu_sidebar.js | 10 ++ .../client/menu_sidebar/menu_sidebar.tpl.jade | 9 +- bookhub/client/user/user.css | 23 +++- bookhub/client/user/user.js | 107 +++++++++++++++++- bookhub/client/user/user.tpl.jade | 40 ++++++- bookhub/data.js | 61 ++++++++++ 8 files changed, 257 insertions(+), 14 deletions(-) diff --git a/bookhub/.meteor/packages b/bookhub/.meteor/packages index f06967a..e114742 100644 --- a/bookhub/.meteor/packages +++ b/bookhub/.meteor/packages @@ -19,3 +19,5 @@ mpowaga:autoform-summernote fortawesome:fontawesome accounts-password vasaka:livescript-compiler +cfs:standard-packages +cfs:filesystem diff --git a/bookhub/.meteor/versions b/bookhub/.meteor/versions index 141eba5..f9d874f 100644 --- a/bookhub/.meteor/versions +++ b/bookhub/.meteor/versions @@ -10,6 +10,23 @@ blaze@2.1.2 blaze-tools@1.0.3 boilerplate-generator@1.0.3 callback-hook@1.0.3 +cfs:access-point@0.1.49 +cfs:base-package@0.0.30 +cfs:collection@0.5.5 +cfs:collection-filters@0.2.4 +cfs:data-man@0.0.6 +cfs:file@0.1.17 +cfs:filesystem@0.1.2 +cfs:http-methods@0.0.29 +cfs:http-publish@0.0.13 +cfs:power-queue@0.9.11 +cfs:reactive-list@0.0.9 +cfs:reactive-property@0.0.4 +cfs:standard-packages@0.5.9 +cfs:storage-adapter@0.2.2 +cfs:tempstore@0.1.5 +cfs:upload-http@0.0.20 +cfs:worker@0.1.4 check@1.0.5 copleykj:jquery-autosize@1.17.8 ddp@1.1.0 @@ -46,6 +63,7 @@ minimongo@1.0.8 mobile-status-bar@1.0.3 momentjs:moment@2.8.4 mongo@1.1.0 +mongo-livedata@1.0.8 mpowaga:autoform-summernote@0.4.1 mquandalle:jade@0.4.3 mquandalle:jade-compiler@0.4.3 @@ -55,6 +73,7 @@ npm-bcrypt@0.7.8_2 observe-sequence@1.0.6 ordered-dict@1.0.3 ovcharik:jsdiff@1.4.0 +raix:eventemitter@0.1.2 random@1.0.3 reactive-dict@1.1.0 reactive-var@1.0.5 diff --git a/bookhub/client/menu_sidebar/menu_sidebar.js b/bookhub/client/menu_sidebar/menu_sidebar.js index 42fcd19..0f5f0b8 100755 --- a/bookhub/client/menu_sidebar/menu_sidebar.js +++ b/bookhub/client/menu_sidebar/menu_sidebar.js @@ -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' ); diff --git a/bookhub/client/menu_sidebar/menu_sidebar.tpl.jade b/bookhub/client/menu_sidebar/menu_sidebar.tpl.jade index 975b8d9..9591c35 100755 --- a/bookhub/client/menu_sidebar/menu_sidebar.tpl.jade +++ b/bookhub/client/menu_sidebar/menu_sidebar.tpl.jade @@ -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 diff --git a/bookhub/client/user/user.css b/bookhub/client/user/user.css index 7a81a46..c6dbee0 100755 --- a/bookhub/client/user/user.css +++ b/bookhub/client/user/user.css @@ -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%; +} \ No newline at end of file diff --git a/bookhub/client/user/user.js b/bookhub/client/user/user.js index 0aa47fc..bc3c0c2 100755 --- a/bookhub/client/user/user.js +++ b/bookhub/client/user/user.js @@ -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( { @@ -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( { @@ -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 --- }) } diff --git a/bookhub/client/user/user.tpl.jade b/bookhub/client/user/user.tpl.jade index 5d04b6d..1724c58 100755 --- a/bookhub/client/user/user.tpl.jade +++ b/bookhub/client/user/user.tpl.jade @@ -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 @@ -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 @@ -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 @@ -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='创建') \ No newline at end of file + 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='确定') \ No newline at end of file diff --git a/bookhub/data.js b/bookhub/data.js index c8fa918..2caa642 100644 --- a/bookhub/data.js +++ b/bookhub/data.js @@ -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}); + } +}) \ No newline at end of file