Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
ede8ae67
Commit
ede8ae67
authored
Apr 21, 2017
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #182, #176
parent
18744975
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
45 deletions
+49
-45
get_meta.js
cps/static/js/get_meta.js
+45
-45
book_edit.html
cps/templates/book_edit.html
+3
-0
layout.html
cps/templates/layout.html
+1
-0
No files found.
cps/static/js/get_meta.js
View file @
ede8ae67
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
*/
*/
/* global i18nMsg */
/* global i18nMsg */
var
dbResults
=
[];
var
ggResults
=
[];
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
var
msg
=
i18nMsg
;
var
msg
=
i18nMsg
;
...
@@ -19,8 +21,6 @@ $(document).ready(function () {
...
@@ -19,8 +21,6 @@ $(document).ready(function () {
// var gg_get_info = "/books/v1/volumes/";
// var gg_get_info = "/books/v1/volumes/";
var
ggDone
=
false
;
var
ggDone
=
false
;
var
dbResults
=
[];
var
ggResults
=
[];
var
showFlag
=
0
;
var
showFlag
=
0
;
String
.
prototype
.
replaceAll
=
function
(
s1
,
s2
)
{
String
.
prototype
.
replaceAll
=
function
(
s1
,
s2
)
{
return
this
.
replace
(
new
RegExp
(
s1
,
"gm"
),
s2
);
return
this
.
replace
(
new
RegExp
(
s1
,
"gm"
),
s2
);
...
@@ -32,11 +32,11 @@ $(document).ready(function () {
...
@@ -32,11 +32,11 @@ $(document).ready(function () {
var
bookHtml
;
var
bookHtml
;
showFlag
++
;
showFlag
++
;
if
(
showFlag
===
1
)
{
if
(
showFlag
===
1
)
{
$
(
"#meta-info"
).
html
(
"<ul id=
\"
book-list
\"
class=
\"
media-list
\"
></ul>"
);
$
(
"#meta
Modal #meta
-info"
).
html
(
"<ul id=
\"
book-list
\"
class=
\"
media-list
\"
></ul>"
);
}
}
if
(
ggDone
&&
dbDone
)
{
if
(
ggDone
&&
dbDone
)
{
if
(
!
ggResults
&&
!
dbResults
)
{
if
(
!
ggResults
&&
!
dbResults
)
{
$
(
"#meta-info"
).
html
(
"<p class=
\"
text-danger
\"
>"
+
msg
.
no_result
+
"</p>"
);
$
(
"#meta
Modal #meta
-info"
).
html
(
"<p class=
\"
text-danger
\"
>"
+
msg
.
no_result
+
"</p>"
);
return
;
return
;
}
}
}
}
...
@@ -51,8 +51,8 @@ $(document).ready(function () {
...
@@ -51,8 +51,8 @@ $(document).ready(function () {
}
}
bookHtml
=
"<li class=
\"
media
\"
>"
+
bookHtml
=
"<li class=
\"
media
\"
>"
+
"<img class=
\"
pull-left img-responsive
\"
data-toggle=
\"
modal
\"
data-target=
\"
#metaModal
\"
src=
\"
"
+
"<img class=
\"
pull-left img-responsive
\"
data-toggle=
\"
modal
\"
data-target=
\"
#metaModal
\"
src=
\"
"
+
bookCover
+
"
\"
alt=
\"
Cover
\"
style=
\"
width:100px;height:150px
\"
onclick='
javascript:
getMeta(
\"
google
\"
,"
+
bookCover
+
"
\"
alt=
\"
Cover
\"
style=
\"
width:100px;height:150px
\"
onclick='getMeta(
\"
google
\"
,"
+
i
+
")
\\
>
\"
"
+
i
+
")
'>
"
+
"<div class=
\"
media-body
\"
>"
+
"<div class=
\"
media-body
\"
>"
+
"<h4 class=
\"
media-heading
\"
><a href=
\"
https://books.google.com/books?id="
+
"<h4 class=
\"
media-heading
\"
><a href=
\"
https://books.google.com/books?id="
+
book
.
id
+
"
\"
target=
\"
_blank
\"
>"
+
book
.
volumeInfo
.
title
+
"</a></h4>"
+
book
.
id
+
"
\"
target=
\"
_blank
\"
>"
+
book
.
volumeInfo
.
title
+
"</a></h4>"
+
...
@@ -62,7 +62,7 @@ $(document).ready(function () {
...
@@ -62,7 +62,7 @@ $(document).ready(function () {
"<p>"
+
msg
.
source
+
":<a href=
\"
https://books.google.com
\"
target=
\"
_blank
\"
>Google Books</a></p>"
+
"<p>"
+
msg
.
source
+
":<a href=
\"
https://books.google.com
\"
target=
\"
_blank
\"
>Google Books</a></p>"
+
"</div>"
+
"</div>"
+
"</li>"
;
"</li>"
;
$
(
"#book-list"
).
append
(
bookHtml
);
$
(
"#
metaModal #
book-list"
).
append
(
bookHtml
);
}
}
ggDone
=
false
;
ggDone
=
false
;
}
}
...
@@ -71,8 +71,8 @@ $(document).ready(function () {
...
@@ -71,8 +71,8 @@ $(document).ready(function () {
book
=
dbResults
[
i
];
book
=
dbResults
[
i
];
bookHtml
=
"<li class=
\"
media
\"
>"
+
bookHtml
=
"<li class=
\"
media
\"
>"
+
"<img class=
\"
pull-left img-responsive
\"
data-toggle=
\"
modal
\"
data-target=
\"
#metaModal
\"
src=
\"
"
+
"<img class=
\"
pull-left img-responsive
\"
data-toggle=
\"
modal
\"
data-target=
\"
#metaModal
\"
src=
\"
"
+
book
.
image
+
"
\"
alt=
\"
Cover
\"
style=
\"
width:100px;height: 150px
\"
onclick='
javascript:
getMeta(
\"
douban
\"
,"
+
book
.
image
+
"
\"
alt=
\"
Cover
\"
style=
\"
width:100px;height: 150px
\"
onclick='getMeta(
\"
douban
\"
,"
+
i
+
")
\\
'>"
+
i
+
")'>"
+
"<div class=
\"
media-body
\"
>"
+
"<div class=
\"
media-body
\"
>"
+
"<h4 class=
\"
media-heading
\"
><a href=
\"
https://book.douban.com/subject/"
+
"<h4 class=
\"
media-heading
\"
><a href=
\"
https://book.douban.com/subject/"
+
book
.
id
+
"
\"
target=
\"
_blank
\"
>"
+
book
.
title
+
"</a></h4>"
+
book
.
id
+
"
\"
target=
\"
_blank
\"
>"
+
book
.
title
+
"</a></h4>"
+
...
@@ -82,7 +82,7 @@ $(document).ready(function () {
...
@@ -82,7 +82,7 @@ $(document).ready(function () {
"<p>"
+
msg
.
source
+
":<a href=
\"
https://book.douban.com
\"
target=
\"
_blank
\"
>Douban Books</a></p>"
+
"<p>"
+
msg
.
source
+
":<a href=
\"
https://book.douban.com
\"
target=
\"
_blank
\"
>Douban Books</a></p>"
+
"</div>"
+
"</div>"
+
"</li>"
;
"</li>"
;
$
(
"#book-list"
).
append
(
bookHtml
);
$
(
"#
metaModal #
book-list"
).
append
(
bookHtml
);
}
}
dbDone
=
false
;
dbDone
=
false
;
}
}
...
@@ -106,38 +106,6 @@ $(document).ready(function () {
...
@@ -106,38 +106,6 @@ $(document).ready(function () {
});
});
}
}
function
getMeta
(
source
,
id
)
{
var
meta
;
var
tags
;
if
(
source
===
"google"
)
{
meta
=
ggResults
[
id
];
$
(
"#description"
).
val
(
meta
.
volumeInfo
.
description
);
$
(
"#bookAuthor"
).
val
(
meta
.
volumeInfo
.
authors
.
join
(
" & "
));
$
(
"#book_title"
).
val
(
meta
.
volumeInfo
.
title
);
if
(
meta
.
volumeInfo
.
categories
)
{
tags
=
meta
.
volumeInfo
.
categories
.
join
(
","
);
$
(
"#tags"
).
val
(
tags
);
}
if
(
meta
.
volumeInfo
.
averageRating
)
{
$
(
"#rating"
).
val
(
Math
.
round
(
meta
.
volumeInfo
.
averageRating
));
}
return
;
}
if
(
source
===
"douban"
)
{
meta
=
dbResults
[
id
];
$
(
"#description"
).
val
(
meta
.
summary
);
$
(
"#bookAuthor"
).
val
(
meta
.
author
.
join
(
" & "
));
$
(
"#book_title"
).
val
(
meta
.
title
);
tags
=
""
;
for
(
var
i
=
0
;
i
<
meta
.
tags
.
length
;
i
++
)
{
tags
=
tags
+
meta
.
tags
[
i
].
title
+
","
;
}
$
(
"#tags"
).
val
(
tags
);
$
(
"#rating"
).
val
(
Math
.
round
(
meta
.
rating
.
average
/
2
));
return
;
}
}
function
dbSearchBook
(
title
)
{
function
dbSearchBook
(
title
)
{
var
url
=
douban
+
dbSearch
+
"?q="
+
title
+
"&fields=all&count=10"
;
var
url
=
douban
+
dbSearch
+
"?q="
+
title
+
"&fields=all&count=10"
;
$
.
ajax
({
$
.
ajax
({
...
@@ -149,7 +117,7 @@ $(document).ready(function () {
...
@@ -149,7 +117,7 @@ $(document).ready(function () {
dbResults
=
data
.
books
;
dbResults
=
data
.
books
;
},
},
error
()
{
error
()
{
$
(
"#meta-info"
).
html
(
"<p class=
\"
text-danger
\"
>"
+
msg
.
search_error
+
"!</p>"
);
$
(
"#meta
Modal #meta
-info"
).
html
(
"<p class=
\"
text-danger
\"
>"
+
msg
.
search_error
+
"!</p>"
);
},
},
complete
()
{
complete
()
{
dbDone
=
true
;
dbDone
=
true
;
...
@@ -160,7 +128,7 @@ $(document).ready(function () {
...
@@ -160,7 +128,7 @@ $(document).ready(function () {
function
doSearch
(
keyword
)
{
function
doSearch
(
keyword
)
{
showFlag
=
0
;
showFlag
=
0
;
$
(
"#meta-info"
).
text
(
msg
.
loading
);
$
(
"#meta
Modal #meta
-info"
).
text
(
msg
.
loading
);
// var keyword = $("#keyword").val();
// var keyword = $("#keyword").val();
if
(
keyword
)
{
if
(
keyword
)
{
dbSearchBook
(
keyword
);
dbSearchBook
(
keyword
);
...
@@ -183,4 +151,36 @@ $(document).ready(function () {
...
@@ -183,4 +151,36 @@ $(document).ready(function () {
}
}
});
});
});
});
\ No newline at end of file
function
getMeta
(
source
,
id
)
{
var
meta
;
var
tags
;
if
(
source
===
"google"
)
{
meta
=
ggResults
[
id
];
$
(
"#description"
).
val
(
meta
.
volumeInfo
.
description
);
$
(
"#bookAuthor"
).
val
(
meta
.
volumeInfo
.
authors
.
join
(
" & "
));
$
(
"#book_title"
).
val
(
meta
.
volumeInfo
.
title
);
if
(
meta
.
volumeInfo
.
categories
)
{
tags
=
meta
.
volumeInfo
.
categories
.
join
(
","
);
$
(
"#tags"
).
val
(
tags
);
}
if
(
meta
.
volumeInfo
.
averageRating
)
{
$
(
"#rating"
).
val
(
Math
.
round
(
meta
.
volumeInfo
.
averageRating
));
}
return
;
}
if
(
source
===
"douban"
)
{
meta
=
dbResults
[
id
];
$
(
"#description"
).
val
(
meta
.
summary
);
$
(
"#bookAuthor"
).
val
(
meta
.
author
.
join
(
" & "
));
$
(
"#book_title"
).
val
(
meta
.
title
);
tags
=
""
;
for
(
var
i
=
0
;
i
<
meta
.
tags
.
length
;
i
++
)
{
tags
=
tags
+
meta
.
tags
[
i
].
title
+
","
;
}
$
(
"#tags"
).
val
(
tags
);
$
(
"#rating"
).
val
(
Math
.
round
(
meta
.
rating
.
average
/
2
));
return
;
}
}
cps/templates/book_edit.html
View file @
ede8ae67
...
@@ -117,6 +117,9 @@
...
@@ -117,6 +117,9 @@
</form>
</form>
{% endif %}
{% endif %}
{% endblock %}
{% block modal %}
{% if g.user.role_delete_books() %}
{% if g.user.role_delete_books() %}
<div
class=
"modal fade"
id=
"deleteModal"
role=
"dialog"
aria-labelledby=
"metaDeleteLabel"
>
<div
class=
"modal fade"
id=
"deleteModal"
role=
"dialog"
aria-labelledby=
"metaDeleteLabel"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-dialog"
>
...
...
cps/templates/layout.html
View file @
ede8ae67
...
@@ -188,6 +188,7 @@
...
@@ -188,6 +188,7 @@
</div>
</div>
</div>
</div>
</div>
</div>
{% block modal %}{% endblock %}
{% block js %}{% endblock %}
{% block js %}{% endblock %}
</body>
</body>
</html>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment