Skip to content

Commit

Permalink
code style and admin del book
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangmitiao committed Jul 1, 2017
1 parent 9770beb commit 682382e
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 60 deletions.
18 changes: 15 additions & 3 deletions app/controllers/api/Book.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"strconv"
"time"
"path/filepath"
)

type Book struct {
Expand Down Expand Up @@ -114,14 +115,14 @@ func (c *Book) UploadBook() revel.Result {
c.addUploadRecord(format, user)
return c.RenderJSON(models.NewOKApiWithMessageAndInfo("add book success", format))
} else {
return c.RenderJSON(models.NewErrorApiWithMessageAndInfo("add book error",nil))
return c.RenderJSON(models.NewErrorApiWithMessageAndInfo("add book error", nil))

}
} else {
rcali.Logger.Debug("read file error :", err.Error())
return c.RenderJSON(models.NewErrorApiWithMessageAndInfo(err.Error(),nil))
return c.RenderJSON(models.NewErrorApiWithMessageAndInfo(err.Error(), nil))
}
return c.RenderJSON(models.NewErrorApiWithMessageAndInfo("file read error",nil))
return c.RenderJSON(models.NewErrorApiWithMessageAndInfo("file read error", nil))
}

func (c Book) addUploadRecord(format models.CaliFormat, user models.UserInfo) {
Expand Down Expand Up @@ -184,3 +185,14 @@ func (c *Book) Search() revel.Result {
return c.RenderJSONP(c.Request.FormValue("callback"), models.NewOKApiWithInfo(bookService.SearchBooks(q, limit, start)))
}
}

func (c *Book) DelJSON()revel.Result {
formats :=formatService.GetNoBookLink()
bookpathdir,_ :=rcali.GetBooksPath()
for _,format := range formats{
rcali.DeleteRealBook(filepath.Join(bookpathdir,format.FileName))
formatService.DeleteById(format.Id)
}
rcali.DeleteTmpBook()
return c.RenderJSON("ok")
}
1 change: 1 addition & 0 deletions app/models/RoleAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func init() {
RoleAction{Id: "adminBookUploadBookConfirm", Role: "admin", Controller: "Book", Method: "UploadBookConfirm"},
RoleAction{Id: "adminBookSearch", Role: "admin", Controller: "Book", Method: "Search"},
RoleAction{Id: "adminBookSearchCount", Role: "admin", Controller: "Book", Method: "SearchCount"},
RoleAction{Id: "adminBookDelJSON", Role: "admin", Controller: "Book", Method: "DelJSON"},

RoleAction{Id: "adminCategoryIndex", Role: "admin", Controller: "Category", Method: "Index"},
RoleAction{Id: "adminCategoryAll", Role: "admin", Controller: "Category", Method: "All"},
Expand Down
16 changes: 16 additions & 0 deletions app/rcali/Calibredb.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"path/filepath"
"strconv"
"strings"
)

/**
Expand Down Expand Up @@ -68,6 +69,21 @@ func CopyFile(srcName, dstName string) error {
return err
}

func DeleteRealBook(bookpath string) {
os.Remove(bookpath)
}

func DeleteTmpBook() {
uploadbookdir ,_:=GetUploadPath()
uploadbookdir = path.Join(uploadbookdir)
filepath.Walk(uploadbookdir, func(path string, info os.FileInfo, err error) error {
if (strings.ToLower(filepath.Ext(info.Name())) == ".epub" || strings.ToLower(filepath.Ext(info.Name())) == ".mobi") && filepath.Dir(path)==uploadbookdir{
os.Remove(filepath.Join(uploadbookdir,info.Name()))
}
return nil
})
}

func DeleteBook(bookid int) bool {
if hasCalibredb() {
cmd := exec.Command(calibredbPath(), "remove", strconv.Itoa(bookid))
Expand Down
2 changes: 1 addition & 1 deletion app/services/CaliBookService.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (service CaliBookService) QueryBookFile(formatid string) (*os.File, error)
//find a book by bookid
func (service CaliBookService) QueryBook(bookid string) (has bool, book models.CaliBook) {
if has, _ := engine.Where("id = ?", bookid).Get(&book); has {
return true,book
return true, book
} else {
return false, book
}
Expand Down
10 changes: 10 additions & 0 deletions app/services/CaliFormatService.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ func (service CaliFormatService) GetFormatBySize(size int64) (format models.Cali
engine.Where("uncompressed_size = ? ", size).And("cali_book != ?", "").Get(&format)
return
}

func (service CaliFormatService)GetNoBookLink()(formats []models.CaliFormat) {
formats = make([]models.CaliFormat,0)
engine.Where("cali_book = ?","").Find(&formats)
return formats
}

func (service CaliFormatService) DeleteById(formatid string) {
engine.Where("id = ?",formatid).Delete(models.CaliFormat{})
}
12 changes: 6 additions & 6 deletions app/views/View/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<div class="row">
<!--<div class="col-md-3">-->

<!--<div class="panel panel-default">-->
<!--&lt;!&ndash;<div class="panel-heading"><span v-text="$t('lang.discover')"></span></div>&ndash;&gt;-->
<!--<div class="panel-body">-->
<!--<p>Search in books and authors</p>-->
<!--</div>-->
<!--</div>-->
<!--<div class="panel panel-default">-->
<!--&lt;!&ndash;<div class="panel-heading"><span v-text="$t('lang.discover')"></span></div>&ndash;&gt;-->
<!--<div class="panel-body">-->
<!--<p>Search in books and authors</p>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<div class="col-md-12">
<div class="row">
Expand Down
80 changes: 40 additions & 40 deletions app/views/View/signup.html
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<title>Cali {{msg . "signup"}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cali {{msg . "signup"}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="/public/v/css/styles.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="/public/v/css/styles.css" rel="stylesheet">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->

{{if ne .cnzzid ""}}
<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan style='display:none' id='cnzz_stat_icon_{{.cnzzid}}'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s22.cnzz.com/z_stat.php%3Fid%3D{{.cnzzid}}' type='text/javascript'%3E%3C/script%3E"));</script>
{{end}}
{{if ne .cnzzid ""}}
<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan style='display:none' id='cnzz_stat_icon_{{.cnzzid}}'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s22.cnzz.com/z_stat.php%3Fid%3D{{.cnzzid}}' type='text/javascript'%3E%3C/script%3E"));</script>
{{end}}
</head>
<body class="login-bg">
<div id="root">
<headerdiv></headerdiv>
<headerdiv></headerdiv>

<div class="page-content container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-wrapper">
<div class="box">
<div class="content-wrap">
<h6><span v-text="$t('lang.signup')"></span></h6>
<input class="form-control" type="text" maxlength="64" :placeholder="$t('lang.email')" v-model="loginName">
<div class="page-content container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="login-wrapper">
<div class="box">
<div class="content-wrap">
<h6><span v-text="$t('lang.signup')"></span></h6>
<input class="form-control" type="text" maxlength="64" :placeholder="$t('lang.email')" v-model="loginName">

<input class="form-control" type="password" maxlength="64" :placeholder="$t('lang.loginPassword')" v-model="loginPassword">
<input class="form-control" type="password" maxlength="64" :placeholder="$t('lang.confirmloginPassword')" v-model="repeatLoginPassword">
<p style="color: red;"><span v-text="tipinfo==''?'':$t(tipinfo)"></span></p>
<div class="action">
<a class="btn btn-primary signup" @click="regist"><span v-text="$t('lang.signup')"></span></a>
</div>
</div>
</div>
<input class="form-control" type="password" maxlength="64" :placeholder="$t('lang.loginPassword')" v-model="loginPassword">
<input class="form-control" type="password" maxlength="64" :placeholder="$t('lang.confirmloginPassword')" v-model="repeatLoginPassword">
<p style="color: red;"><span v-text="tipinfo==''?'':$t(tipinfo)"></span></p>
<div class="action">
<a class="btn btn-primary signup" @click="regist"><span v-text="$t('lang.signup')"></span></a>
</div>
</div>
</div>

<div class="already">
<p><span v-text="$t('lang.haaa')"></span></p>
<a href="/login"><span v-text="$t('lang.login')"></span></a>
</div>
</div>
</div>
</div>
</div>
<div class="already">
<p><span v-text="$t('lang.haaa')"></span></p>
<a href="/login"><span v-text="$t('lang.login')"></span></a>
</div>
</div>
</div>
</div>
</div>

<footerdiv></footerdiv>
<footerdiv></footerdiv>

<tipsmodaldiv></tipsmodaldiv>
<tipsmodaldiv></tipsmodaldiv>
</div>
<script src="https://cdn.bootcss.com/store.js/1.3.20/store.min.js"></script>
<script src="https://cdn.bootcss.com/fetch/2.0.3/fetch.min.js"></script>
Expand Down
12 changes: 6 additions & 6 deletions public/v/js/cali.person.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ $(document).ready(function(){
}
},
addcategory:function () {
let form = commonData();
form.append("categoryName",this.newcategory.category);
fetch('/api/category/add',{method:'post',body:form}).then(function(response) {
let form = commonData();
form.append("categoryName",this.newcategory.category);
fetch('/api/category/add',{method:'post',body:form}).then(function(response) {
if (response.redirected){
let tmpJson = {};
tmpJson.statusCode = 500;
Expand All @@ -311,16 +311,16 @@ $(document).ready(function(){
}else {
return response.json();
}
}).then(function(json) {
}).then(function(json) {
if (json.statusCode ===200){
app.showcategories();
tips("info","add categoy success");
}else {
tips("error",json.message);
}
}).catch(function(ex) {
}).catch(function(ex) {
tips("error", ex);
});
});
},
deletecategory:function (c) {
let form = commonData();
Expand Down
5 changes: 1 addition & 4 deletions public/v/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ $(document).ready(function(){
el: "#root",
data: {},
methods: {
ooo:function () {
tips("hello","<h4>world</h4>");
}
},
computed: {},
omputed: {},
created: function() {
//console.log("created");
},
Expand Down

0 comments on commit 682382e

Please sign in to comment.