Fix #532, add system notice
parent
54c9844d66
commit
1aa76bd279
@ -0,0 +1,64 @@ |
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package models |
||||
|
||||
import ( |
||||
"time" |
||||
|
||||
"github.com/Unknwon/com" |
||||
) |
||||
|
||||
type NoticeType int |
||||
|
||||
const ( |
||||
NOTICE_REPOSITORY NoticeType = iota + 1 |
||||
) |
||||
|
||||
// Notice represents a system notice for admin.
|
||||
type Notice struct { |
||||
Id int64 |
||||
Type NoticeType |
||||
Description string `xorm:"TEXT"` |
||||
Created time.Time `xorm:"CREATED"` |
||||
} |
||||
|
||||
// TrStr returns a translation format string.
|
||||
func (n *Notice) TrStr() string { |
||||
return "admin.notices.type_" + com.ToStr(n.Type) |
||||
} |
||||
|
||||
// CreateNotice creates new system notice.
|
||||
func CreateNotice(tp NoticeType, desc string) error { |
||||
n := &Notice{ |
||||
Type: tp, |
||||
Description: desc, |
||||
} |
||||
_, err := x.Insert(n) |
||||
return err |
||||
} |
||||
|
||||
// CreateRepositoryNotice creates new system notice with type NOTICE_REPOSITORY.
|
||||
func CreateRepositoryNotice(desc string) error { |
||||
return CreateNotice(NOTICE_REPOSITORY, desc) |
||||
} |
||||
|
||||
// CountNotices returns number of notices.
|
||||
func CountNotices() int64 { |
||||
count, _ := x.Count(new(Notice)) |
||||
return count |
||||
} |
||||
|
||||
// GetNotices returns given number of notices with offset.
|
||||
func GetNotices(num, offset int) ([]*Notice, error) { |
||||
notices := make([]*Notice, 0, num) |
||||
err := x.Limit(num, offset).Desc("id").Find(¬ices) |
||||
return notices, err |
||||
} |
||||
|
||||
// DeleteNotice deletes a system notice by given ID.
|
||||
func DeleteNotice(id int64) error { |
||||
_, err := x.Id(id).Delete(new(Notice)) |
||||
return err |
||||
} |
@ -0,0 +1,46 @@ |
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin |
||||
|
||||
import ( |
||||
"github.com/Unknwon/com" |
||||
|
||||
"github.com/gogits/gogs/models" |
||||
"github.com/gogits/gogs/modules/base" |
||||
"github.com/gogits/gogs/modules/log" |
||||
"github.com/gogits/gogs/modules/middleware" |
||||
) |
||||
|
||||
const ( |
||||
NOTICES base.TplName = "admin/notice" |
||||
) |
||||
|
||||
func Notices(ctx *middleware.Context) { |
||||
ctx.Data["Title"] = ctx.Tr("admin.notices") |
||||
ctx.Data["PageIsAdmin"] = true |
||||
ctx.Data["PageIsAdminNotices"] = true |
||||
|
||||
pageNum := 50 |
||||
p := pagination(ctx, models.CountNotices(), pageNum) |
||||
|
||||
notices, err := models.GetNotices(pageNum, (p-1)*pageNum) |
||||
if err != nil { |
||||
ctx.Handle(500, "GetNotices", err) |
||||
return |
||||
} |
||||
ctx.Data["Notices"] = notices |
||||
ctx.HTML(200, NOTICES) |
||||
} |
||||
|
||||
func DeleteNotice(ctx *middleware.Context) { |
||||
id := com.StrTo(ctx.Params(":id")).MustInt64() |
||||
if err := models.DeleteNotice(id); err != nil { |
||||
ctx.Handle(500, "DeleteNotice", err) |
||||
return |
||||
} |
||||
log.Trace("System notice deleted by admin(%s): %d", ctx.User.Name, id) |
||||
ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) |
||||
ctx.Redirect("/admin/notices") |
||||
} |
@ -1 +1 @@ |
||||
0.5.5.1007 Beta |
||||
0.5.5.1008 Beta |
@ -0,0 +1,54 @@ |
||||
{{template "ng/base/head" .}} |
||||
{{template "ng/base/header" .}} |
||||
<div id="admin-wrapper"> |
||||
<div id="setting-wrapper" class="main-wrapper"> |
||||
<div id="admin-setting" class="container clear"> |
||||
{{template "admin/nav" .}} |
||||
<div class="grid-4-5 left"> |
||||
<div class="setting-content"> |
||||
{{template "ng/base/alert" .}} |
||||
<div id="setting-content"> |
||||
<div class="panel panel-radius"> |
||||
<div class="panel-header"> |
||||
<strong>{{.i18n.Tr "admin.notices.system_notice_list"}}</strong> |
||||
</div> |
||||
<div class="panel-body admin-panel"> |
||||
<div class="admin-table"> |
||||
<table class="table table-striped"> |
||||
<thead> |
||||
<tr> |
||||
<th>Id</th> |
||||
<th>{{.i18n.Tr "admin.notices.type"}}</th> |
||||
<th>{{.i18n.Tr "admin.notices.desc"}}</th> |
||||
<th>{{.i18n.Tr "admin.users.created"}}</th> |
||||
<th>{{.i18n.Tr "admin.notices.op"}}</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
{{range .Notices}} |
||||
<tr> |
||||
<td>{{.Id}}</td> |
||||
<td>{{$.i18n.Tr .TrStr}}</td> |
||||
<td class="grid-1-2"><span>{{.Description}}</span></td> |
||||
<td>{{.Created}}</td> |
||||
<td><a href="{{AppSubUrl}}/admin/notices/{{.Id}}/delete"><i class="fa fa-trash-o text-red"></i></a></td> |
||||
</tr> |
||||
{{end}} |
||||
</tbody> |
||||
</table> |
||||
{{if or .LastPageNum .NextPageNum}} |
||||
<ul class="pagination"> |
||||
{{if .LastPageNum}}<li><a class="btn btn-medium btn-gray btn-radius" href="{{AppSubUrl}}/admin/users?p={{.LastPageNum}}">« {{.i18n.Tr "admin.prev"}}</a></li>{{end}} |
||||
{{if .NextPageNum}}<li><a class="btn btn-medium btn-gray btn-radius" href="{{AppSubUrl}}/admin/users?p={{.NextPageNum}}">» {{.i18n.Tr "admin.next"}}</a></li>{{end}} |
||||
</ul> |
||||
{{end}} |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
{{template "ng/base/footer" .}} |
Loading…
Reference in new issue