Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe05ac7

Browse files
committed
除了用户相关的几个页面,其他页面改版都已完成
1 parent 34db035 commit fe05ac7

File tree

21 files changed

+318
-418
lines changed

21 files changed

+318
-418
lines changed

websites/code/studygolang/src/controller/message.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013 The StudyGolang Authors. All rights reserved.
1+
// Copyright 2013-2014 The StudyGolang Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44
// http://studygolang.com
@@ -7,21 +7,22 @@
77
package controller
88

99
import (
10-
"filter"
1110
"fmt"
12-
"github.com/studygolang/mux"
1311
"net/http"
14-
"service"
1512
"strconv"
13+
14+
"filter"
15+
"github.com/studygolang/mux"
16+
"service"
1617
"util"
1718
)
1819

1920
// 发短消息
2021
// uri: /message/send{json:(|.json)}
2122
func SendMessageHandler(rw http.ResponseWriter, req *http.Request) {
2223
vars := mux.Vars(req)
23-
content := req.FormValue("content")
24-
// 请求新建帖子页面
24+
content := req.PostFormValue("content")
25+
// 请求发送消息页面
2526
if content == "" || req.Method != "POST" || vars["json"] == "" {
2627
user := service.FindUserByUsername(req.FormValue("username"))
2728
filter.SetData(req, map[string]interface{}{"user": user})
@@ -30,13 +31,13 @@ func SendMessageHandler(rw http.ResponseWriter, req *http.Request) {
3031
}
3132

3233
user, _ := filter.CurrentUser(req)
33-
to := util.MustInt(req.FormValue("to"))
34+
to := util.MustInt(req.PostFormValue("to"))
3435
success := service.SendMessageTo(user["uid"].(int), to, content)
3536
if !success {
36-
fmt.Fprint(rw, `{"errno": 1, "error":"对不起,发送失败,请稍候再试!"}`)
37+
fmt.Fprint(rw, `{"ok": 0, "error":"对不起,发送失败,请稍候再试!"}`)
3738
return
3839
}
39-
fmt.Fprint(rw, `{"errno": 0, "error":""}`)
40+
fmt.Fprint(rw, `{"ok": 1, "error":""}`)
4041
}
4142

4243
// 消息列表
@@ -63,14 +64,14 @@ func MessageHandler(rw http.ResponseWriter, req *http.Request) {
6364
// uri: /message/delete.json
6465
func DeleteMessageHandler(rw http.ResponseWriter, req *http.Request) {
6566
if req.Method != "POST" {
66-
fmt.Fprint(rw, `{"errno": 1, "error":"非法请求!"}`)
67+
fmt.Fprint(rw, `{"ok": 0, "error":"非法请求!"}`)
6768
return
6869
}
69-
id := req.FormValue("id")
70-
msgtype := req.FormValue("msgtype")
70+
id := req.PostFormValue("id")
71+
msgtype := req.PostFormValue("msgtype")
7172
if !service.DeleteMessage(id, msgtype) {
72-
fmt.Fprint(rw, `{"errno": 1, "error":"对不起,删除失败,请稍候再试!"}`)
73+
fmt.Fprint(rw, `{"ok": 0, "error":"对不起,删除失败,请稍候再试!"}`)
7374
return
7475
}
75-
fmt.Fprint(rw, `{"errno": 0, "error":""}`)
76+
fmt.Fprint(rw, `{"ok": 1, "error":""}`)
7677
}

websites/code/studygolang/src/controller/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func ModifyProjectHandler(rw http.ResponseWriter, req *http.Request) {
154154
func ProjectDetailHandler(rw http.ResponseWriter, req *http.Request) {
155155
vars := mux.Vars(req)
156156
project := service.FindProject(vars["uniq"])
157-
if project == nil || project.Status != model.StatusOnline {
157+
if project == nil {
158158
util.Redirect(rw, req, "/projects")
159159
return
160160
}

websites/code/studygolang/src/controller/resource.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import (
1919
"util"
2020
)
2121

22-
// 在需要评论且要回调的地方注册评论对象
22+
// 在需要评论(喜欢)且要回调的地方注册评论(喜欢)对象
2323
func init() {
24-
// 注册评论对象
24+
// 注册评论(喜欢)对象
2525
service.RegisterCommentObject(model.TYPE_RESOURCE, service.ResourceComment{})
26+
service.RegisterLikeObject(model.TYPE_RESOURCE, service.ResourceLike{})
2627
}
2728

2829
// 资源索引页
@@ -54,8 +55,26 @@ func CatResourcesHandler(rw http.ResponseWriter, req *http.Request) {
5455
func ResourceDetailHandler(rw http.ResponseWriter, req *http.Request) {
5556
vars := mux.Vars(req)
5657
resource, comments := service.FindResource(vars["id"])
58+
59+
if len(resource) == 0 {
60+
util.Redirect(rw, req, "/resources")
61+
return
62+
}
63+
64+
likeFlag := 0
65+
hadCollect := 0
66+
user, ok := filter.CurrentUser(req)
67+
if ok {
68+
uid := user["uid"].(int)
69+
id := resource["id"].(int)
70+
likeFlag = service.HadLike(uid, id, model.TYPE_RESOURCE)
71+
hadCollect = service.HadFavorite(uid, id, model.TYPE_RESOURCE)
72+
}
73+
74+
service.Views.Incr(req, model.TYPE_RESOURCE, util.MustInt(vars["id"]))
75+
5776
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/resources/detail.html")
58-
filter.SetData(req, map[string]interface{}{"activeResources": "active", "resource": resource, "comments": comments})
77+
filter.SetData(req, map[string]interface{}{"activeResources": "active", "resource": resource, "comments": comments, "likeflag": likeFlag, "hadcollect": hadCollect})
5978
}
6079

6180
// 发布新资源

websites/code/studygolang/src/controller/topic.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@
77
package controller
88

99
import (
10-
"filter"
1110
"fmt"
12-
"github.com/studygolang/mux"
1311
"html/template"
14-
"model"
1512
"net/http"
16-
"service"
1713
"strconv"
14+
15+
"filter"
16+
"github.com/studygolang/mux"
17+
"model"
18+
"service"
1819
"util"
1920
)
2021

21-
// 在需要评论且要回调的地方注册评论对象
22+
// 在需要评论(喜欢)且要回调的地方注册评论(喜欢)对象
2223
func init() {
23-
// 注册评论对象
24+
// 注册评论(喜欢)对象
2425
service.RegisterCommentObject(model.TYPE_TOPIC, service.TopicComment{})
26+
service.RegisterLikeObject(model.TYPE_TOPIC, service.TopicLike{})
2527
}
2628

2729
// 社区帖子列表页
@@ -81,12 +83,22 @@ func TopicDetailHandler(rw http.ResponseWriter, req *http.Request) {
8183
return
8284
}
8385

86+
likeFlag := 0
87+
hadCollect := 0
88+
user, ok := filter.CurrentUser(req)
89+
if ok {
90+
uid := user["uid"].(int)
91+
tid := topic["tid"].(int)
92+
likeFlag = service.HadLike(uid, tid, model.TYPE_TOPIC)
93+
hadCollect = service.HadFavorite(uid, tid, model.TYPE_TOPIC)
94+
}
95+
8496
service.Views.Incr(req, model.TYPE_TOPIC, util.MustInt(vars["tid"]))
8597

8698
// 设置内容模板
8799
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/detail.html")
88100
// 设置模板数据
89-
filter.SetData(req, map[string]interface{}{"activeTopics": "active", "topic": topic, "replies": replies})
101+
filter.SetData(req, map[string]interface{}{"activeTopics": "active", "topic": topic, "replies": replies, "likeflag": likeFlag, "hadcollect": hadCollect})
90102
}
91103

92104
// 新建帖子

websites/code/studygolang/src/model/comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
// 不要修改常量的顺序
1515
const (
16-
TYPE_TOPIC = iota // 帖子
16+
TYPE_TOPIC = iota // 主题
1717
TYPE_ARTICLE // 博文
1818
TYPE_RESOURCE // 资源
1919
TYPE_WIKI // WIKI

websites/code/studygolang/src/service/article.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,8 @@ type ArticleLike struct{}
427427
// 更新该文章的喜欢数
428428
// objid:被喜欢对象id;num: 喜欢数(负数表示取消喜欢)
429429
func (self ArticleLike) UpdateLike(objid, num int) {
430-
id := strconv.Itoa(objid)
431-
432430
// 更新喜欢数(TODO:暂时每次都更新表)
433-
err := model.NewArticle().Where("id="+id).Increment("likenum", num)
431+
err := model.NewArticle().Where("id=?", objid).Increment("likenum", num)
434432
if err != nil {
435433
logger.Errorln("更新文章喜欢数失败:", err)
436434
}

websites/code/studygolang/src/service/book.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
package service
88

99
import (
10-
"config"
1110
"io/ioutil"
12-
"logger"
1311
"os"
1412
"path/filepath"
1513
"strconv"
14+
"strings"
1615
"sync"
1716
"time"
17+
18+
"config"
19+
"logger"
1820
"util"
1921
)
2022

@@ -171,7 +173,7 @@ func initMaxOnlineNum() {
171173
logger.Errorln("read data file error:", err)
172174
return
173175
}
174-
maxOnlineNum = util.MustInt(string(data))
176+
maxOnlineNum = util.MustInt(strings.TrimSpace(string(data)))
175177
}
176178
}
177179

websites/code/studygolang/src/service/project.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func FindProject(uniq string) *model.OpenProject {
134134
}
135135

136136
project := model.NewOpenProject()
137-
err = project.Where(field+"=?", uniq).Find()
137+
err = project.Where(field+"=? AND status IN(?,?)", uniq, model.StatusNew, model.StatusOnline).Find()
138138

139139
if err != nil {
140140
logger.Errorln("project service FindProject error:", err)
@@ -262,10 +262,8 @@ type ProjectLike struct{}
262262
// 更新该项目的喜欢数
263263
// objid:被喜欢对象id;num: 喜欢数(负数表示取消喜欢)
264264
func (self ProjectLike) UpdateLike(objid, num int) {
265-
id := strconv.Itoa(objid)
266-
267265
// 更新喜欢数(TODO:暂时每次都更新表)
268-
err := model.NewOpenProject().Where("id="+id).Increment("likenum", num)
266+
err := model.NewOpenProject().Where("id=?", objid).Increment("likenum", num)
269267
if err != nil {
270268
logger.Errorln("更新项目喜欢数失败:", err)
271269
}

websites/code/studygolang/src/service/resource.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,20 @@ func (self ResourceComment) SetObjinfo(ids []int, commentMap map[int][]*model.Co
318318
}
319319
}
320320
}
321+
322+
// 资源喜欢
323+
type ResourceLike struct{}
324+
325+
// 更新该主题的喜欢数
326+
// objid:被喜欢对象id;num: 喜欢数(负数表示取消喜欢)
327+
func (self ResourceLike) UpdateLike(objid, num int) {
328+
// 更新喜欢数(TODO:暂时每次都更新表)
329+
err := model.NewResourceEx().Where("id=?", objid).Increment("likenum", num)
330+
if err != nil {
331+
logger.Errorln("更新资源喜欢数失败:", err)
332+
}
333+
}
334+
335+
func (self ResourceLike) String() string {
336+
return "resource"
337+
}

websites/code/studygolang/src/service/topic.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,20 @@ func (self TopicComment) SetObjinfo(ids []int, commentMap map[int][]*model.Comme
489489
}
490490
}
491491
}
492+
493+
// 主题喜欢
494+
type TopicLike struct{}
495+
496+
// 更新该主题的喜欢数
497+
// objid:被喜欢对象id;num: 喜欢数(负数表示取消喜欢)
498+
func (self TopicLike) UpdateLike(objid, num int) {
499+
// 更新喜欢数(TODO:暂时每次都更新表)
500+
err := model.NewTopicEx().Where("tid=?", objid).Increment("like", num)
501+
if err != nil {
502+
logger.Errorln("更新主题喜欢数失败:", err)
503+
}
504+
}
505+
506+
func (self TopicLike) String() string {
507+
return "topic"
508+
}

websites/code/studygolang/src/service/view.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package service
99
import (
1010
"net/http"
1111
"strconv"
12-
"strings"
1312
"sync"
1413

1514
"logger"
@@ -72,8 +71,7 @@ func newViews() *views {
7271
}
7372

7473
func (this *views) Incr(req *http.Request, objtype uint8, objid int) {
75-
pos := strings.LastIndex(req.RemoteAddr, ":")
76-
ip := req.RemoteAddr[:pos]
74+
ip := util.Ip(req)
7775
user := int(util.Ip2long(ip))
7876

7977
key := strconv.Itoa(int(objtype)) + strconv.Itoa(objid)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.message {}
2+
.message .nav {background: #fff; margin-top: 10px; padding: 20px 0 0 20px;}
3+
.message .data {padding-left: 20px; padding-right: 20px; }
4+
.message .data li {border-bottom: 1px dotted #999;margin: 10px 0;padding-bottom: 15px;position: relative;}
5+
.message .data li h3 {font-size: 14px;color: #999;line-height: 18px;font-weight: normal;padding-bottom: 8px;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; margin:0;}
6+
.message .data li h3 a img {float: left; margin-right: 10px;}
7+
.message .data li .info {line-height:18px;min-height:18px;}
8+
.message .data li .cmd {position: absolute;right: 0;top: 0;}

websites/code/studygolang/static/css/resources.css

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,4 @@ border-bottom: 1px solid #DDD;}
99
.resources .resource .rinfo .host {color: #888;}
1010
.resources .resource .rinfo .ino {margin: 5px 0;color: #888;font-size: 13px;}
1111
.resources .resource .rinfo .edi {margin: 0 0 9px;font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 13px;line-height: 18px;}
12-
.resources .resource .rinfo .edi a {margin-right: 8px;color: #777;}
13-
.resources .resource .right-info {margin-left: 58px;}
14-
.resources .resource .right-info .title {margin-bottom: 5px; font-size: 120%;}
15-
.resources .resource .right-info .title a {color:#474747}
16-
.resources .resource .right-info .title a:hover {color: #DB6D4C;text-decoration: none;}
17-
.resources .resource .right-info .meta {color: #bbb; font-size: 13px;}
18-
.resources .resource .right-info .meta .node {padding: 1px 5px;color: #778087;text-decoration: none;background-color: #f5f5f5;}
19-
.resources .resource .right-info .meta .node:hover {background-color: #222;text-decoration: none; color:#fff;}
20-
.resources .resource .right-info .meta .author {color: #778087;}
21-
.resources .resource .right-info .meta .num {margin-right: 10px;}
22-
.resources .resource .right-info .meta .num a {color: #979797; text-decoration: none;}
23-
.resources .resource .right-info .meta .num a:hover {text-decoration: none;color: #DB6D4C;}
24-
.resources .resource .right-info .meta .num span {margin-left: 5px;margin-right: 10px;}
25-
26-
.nodes .title {position: relative;border-bottom: 1px solid #ccc;}
27-
.nodes .title h3 {line-height: 24px;font-size: 14px;font-weight: bold;padding-top: 10px;}
28-
.nodes ul li {line-height: 200%;font-size: 14px;padding: 8px 10px;border-top: 1px solid #DDD;position: relative;overflow: auto;}
29-
.nodes ul li label {font-size: 12px;color: #999;display: inline-block;width: 120px;margin-right: -130px;padding-right: 10px;float: left;text-align: right;}
30-
.nodes ul li .childnodes {float: left;margin-left: 130px;}
31-
.nodes ul li .childnodes a {color:#424242;text-decoration: none;background-color: #f5f5f5;}
32-
.nodes ul li .childnodes a:hover {background-color:#222;color:#fff;text-decoration: none;}
33-
34-
.node-info {background-color: #FAFAFA;padding: 10px 10px 0;border-bottom: 1px solid #ddd;margin-top: 5px;}
35-
.node-info h2 {line-height: 100%;display: inline;font-size: 16px;margin-right: 10px;font-weight: bold;}
36-
.node-info .title span {font-size: 13px;}
37-
.node-info .desc {color: #999;margin: 10px 0;font-size: 13px;}
12+
.resources .resource .rinfo .edi a, .resources .resource .rinfo .edi span {margin-right: 8px;color: #777;}

0 commit comments

Comments
 (0)