add ability to remove a tag from a paper as well
This commit is contained in:
@@ -251,6 +251,30 @@ def add(pid=None, tag=None):
|
|||||||
print("added paper %s to tag %s for user %s" % (pid, tag, user))
|
print("added paper %s to tag %s for user %s" % (pid, tag, user))
|
||||||
return "ok: " + str(d) # return back the user library for debugging atm
|
return "ok: " + str(d) # return back the user library for debugging atm
|
||||||
|
|
||||||
|
@app.route('/sub/<pid>/<tag>')
|
||||||
|
def sub(pid=None, tag=None):
|
||||||
|
user = 'root'
|
||||||
|
with get_tags_db(flag='c') as tags_db:
|
||||||
|
|
||||||
|
# if the user doesn't have any tags, there is nothing to do
|
||||||
|
if not user in tags_db:
|
||||||
|
return "user has no library of tags ¯\_(ツ)_/¯"
|
||||||
|
|
||||||
|
# fetch the user library object
|
||||||
|
d = tags_db[user]
|
||||||
|
|
||||||
|
# add the paper to the tag
|
||||||
|
if tag not in d:
|
||||||
|
return "user doesn't have the tag %s" % (tag, )
|
||||||
|
else:
|
||||||
|
d[tag].remove(pid)
|
||||||
|
|
||||||
|
# write back to database
|
||||||
|
tags_db[user] = d
|
||||||
|
|
||||||
|
print("removed from paper %s the tag %s for user %s" % (pid, tag, user))
|
||||||
|
return "ok: " + str(d) # return back the user library for debugging atm
|
||||||
|
|
||||||
@app.route('/del/<tag>')
|
@app.route('/del/<tag>')
|
||||||
def delete_tag(tag=None):
|
def delete_tag(tag=None):
|
||||||
user = 'root'
|
user = 'root'
|
||||||
|
|||||||
@@ -14,19 +14,24 @@ const UTag = props => {
|
|||||||
|
|
||||||
const Paper = props => {
|
const Paper = props => {
|
||||||
const p = props.paper;
|
const p = props.paper;
|
||||||
const adder = () => fetch("/add/" + p.id + "/" + prompt("tag name:"))
|
const adder = () => fetch("/add/" + p.id + "/" + prompt("tag to add to this paper:"))
|
||||||
|
.then(response => console.log(response.text()));
|
||||||
|
const subber = () => fetch("/sub/" + p.id + "/" + prompt("tag to subtract from this paper:"))
|
||||||
.then(response => console.log(response.text()));
|
.then(response => console.log(response.text()));
|
||||||
const utags = p.utags.map((utxt, ix) => <UTag key={ix} tag={utxt} />);
|
const utags = p.utags.map((utxt, ix) => <UTag key={ix} tag={utxt} />);
|
||||||
const similar_url = "/?rank=tags&pid=" + p.id;
|
const similar_url = "/?rank=tags&pid=" + p.id;
|
||||||
return (
|
return (
|
||||||
<div class='rel_paper'>
|
<div class='rel_paper'>
|
||||||
<div class="rel_add" onClick={adder}>+</div>
|
|
||||||
<div class="rel_score">{p.weight.toFixed(2)}</div>
|
<div class="rel_score">{p.weight.toFixed(2)}</div>
|
||||||
<div class='rel_title'><a href={'http://arxiv.org/abs/' + p.id}>{p.title}</a></div>
|
<div class='rel_title'><a href={'http://arxiv.org/abs/' + p.id}>{p.title}</a></div>
|
||||||
<div class='rel_authors'>{p.authors}</div>
|
<div class='rel_authors'>{p.authors}</div>
|
||||||
<div class="rel_time">{p.time}</div>
|
<div class="rel_time">{p.time}</div>
|
||||||
<div class='rel_tags'>{p.tags}</div>
|
<div class='rel_tags'>{p.tags}</div>
|
||||||
<div class='rel_utags'>{utags}</div>
|
<div class='rel_utags'>
|
||||||
|
<div class="rel_utag rel_utag_add" onClick={adder}>+</div>
|
||||||
|
<div class="rel_utag rel_utag_sub" onClick={subber}>-</div>
|
||||||
|
{utags}
|
||||||
|
</div>
|
||||||
<div class='rel_abs'>{p.summary}</div>
|
<div class='rel_abs'>{p.summary}</div>
|
||||||
<div class='rel_more'><a href={similar_url}>similar</a></div>
|
<div class='rel_more'><a href={similar_url}>similar</a></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -64,7 +69,7 @@ const TagList = props => {
|
|||||||
.then(response => console.log(response.text()));
|
.then(response => console.log(response.text()));
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div class="rel_del" onClick={deleter}>-</div>
|
<div class="rel_tag" onClick={deleter}>-</div>
|
||||||
<div id="tagList" class="rel_utags">
|
<div id="tagList" class="rel_utags">
|
||||||
{tlst}
|
{tlst}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+18
-17
@@ -65,7 +65,18 @@ body {
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
}
|
}
|
||||||
.rel_utag {
|
.rel_tag { /* deletes a whole tag */
|
||||||
|
position: absolute;
|
||||||
|
color: white;
|
||||||
|
left: 7px;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 3px;
|
||||||
|
background-color: #f55;
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
}
|
||||||
|
.rel_utag { /* shows an active tag for a paper */
|
||||||
background-color: #009;
|
background-color: #009;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
@@ -73,28 +84,18 @@ body {
|
|||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
padding: 0 4px 0 4px;
|
padding: 0 4px 0 4px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.rel_add {
|
.rel_utag_add { /* adds a paper to a tag */
|
||||||
position: absolute;
|
|
||||||
width: 26px;
|
|
||||||
height: 26px;
|
|
||||||
background-color: #55f;
|
background-color: #55f;
|
||||||
color: white;
|
margin-right: 2px;
|
||||||
left: 7px;
|
width: 12px;
|
||||||
cursor: pointer;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
border-radius: 3px;
|
|
||||||
}
|
}
|
||||||
.rel_del {
|
.rel_utag_sub { /* subs a tag from a paper */
|
||||||
position: absolute;
|
|
||||||
width: 22px;
|
|
||||||
height: 22px;
|
|
||||||
background-color: #f55;
|
background-color: #f55;
|
||||||
color: white;
|
width: 12px;
|
||||||
left: 7px;
|
|
||||||
cursor: pointer;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
border-radius: 3px;
|
|
||||||
}
|
}
|
||||||
.rel_utag a {
|
.rel_utag a {
|
||||||
color: white;
|
color: white;
|
||||||
|
|||||||
Reference in New Issue
Block a user