- added two dialogs to manage bookmark tags in YaCy-UI

- fixed renameTag() in bookmarksDB
- added /api/bookmarks/tags/addTag.xml
- added /api/bookmarks/tags/editTag.xml

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5525 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
apfelmaennchen 16 years ago
parent 12511bd236
commit 6dd52422ea

@ -0,0 +1,30 @@
import de.anomic.http.httpRequestHeader;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.data.bookmarksDB.Bookmark;
public class addTag {
public static serverObjects respond(final httpRequestHeader header, final serverObjects post, final serverSwitch<?> env) {
// return variable that accumulates replacements
final plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
final serverObjects prop = new serverObjects();
prop.put("result", "0");//error
//rename tags
if(post != null) {
if (post.containsKey("selectTag") && post.containsKey("addTag")) {
switchboard.bookmarksDB.addTag(post.get("selectTag"), post.get("addTag"));
prop.put("result", "1");//success
} else if (post.containsKey("urlhash") && post.containsKey("addTag")) {
final Bookmark bm = switchboard.bookmarksDB.getBookmark(post.get("urlhash"));
bm.addTag(post.get("addTag"));
prop.put("result", "1");//success
}
}
// return rewrite properties
return prop;
}
}

@ -0,0 +1,2 @@
<?xml version='1.0' encoding="UTF-8" standalone='yes'?>
<result>#(result)#something went wrong::done#(/result)#</result>

@ -0,0 +1,22 @@
import de.anomic.http.httpRequestHeader;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
public class editTag {
public static serverObjects respond(final httpRequestHeader header, final serverObjects post, final serverSwitch<?> env) {
// return variable that accumulates replacements
final plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
final serverObjects prop = new serverObjects();
prop.put("result", "0");//error
//rename tags
if(post != null && post.containsKey("old") && post.containsKey("new")){
if(switchboard.bookmarksDB.renameTag(post.get("old"), post.get("new")))
prop.put("result", "1");//success
}
// return rewrite properties
return prop;
}
}

@ -0,0 +1,2 @@
<?xml version='1.0' encoding="UTF-8" standalone='yes'?>
<result>#(result)#something went wrong::done#(/result)#</result>

@ -158,6 +158,15 @@ img.help {
.flexigrid div.fbutton .load {
background: url(../img/flexigrid/load.png) no-repeat center left;
}
.flexigrid div.fbutton .addTag {
background: url(../img/tags/tag_blue_add.png) no-repeat center left;
}
.flexigrid div.fbutton .editTag {
background: url(../img/tags/tag_blue_edit.png) no-repeat center left;
}
.flexigrid div.fbutton .deleteTag {
background: url(../img/tags/tag_blue_delete.png) no-repeat center left;
}
/* YaCy Bookmarks ---------------------------*/
.url {

@ -44,8 +44,18 @@
HTMLenc = function(s) {
return $('<div/>').text(s).html();
}
String.prototype.startsWith = function(str) {
return (this.match("^"+str)==str)
}
String.prototype.trim = function() {
return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))
}
String.prototype.endsWith = function(str) {
return (this.match(str+"$")==str)
}
$(function() {
qtag = "";
flex = {};
tabid = "Welcome";
/* Initialize Tabs and set up close function */
$tabs = $('#container ul').tabs({
@ -114,6 +124,79 @@
Cancel: function() { $("#bmadd").dialog("close"); }
}
});
/* Initialize Edit Tags Dialog */
$("#tagedit").dialog({
autoOpen: false,
height: 250,
width: 250,
resizable: false,
buttons: {
Add: function() {
data = {
selectTag: $("input[@name='tag1']").getValue(),
addTag: $("input[@name='tag2']").getValue()
};
$.ajax({
type: "GET",
url: "/api/bookmarks/tags/addTag.xml",
data: data,
dataType: "xml",
success: function(xml) {
alert($(xml).find('result').text());
loadTagCloud();
reloadBM();
$("#tagadd").dialog('close');
}
});
},
Edit: function() {
data = {
old: $("input[@name='tag1']").getValue(),
new: $("input[@name='tag2']").getValue()
};
$.ajax({
type: "GET",
url: "/api/bookmarks/tags/editTag.xml",
data: data,
dataType: "xml"
});
loadTagCloud();
reloadBM();
$("#tagedit").dialog('close');
},
Cancel: function() { $("#tagedit").dialog("close"); }
}
});
/* Initialize Add Tags Dialog */
$("#tagadd").dialog({
autoOpen: false,
height: 225,
width: 250,
resizable: false,
buttons: {
Add: function() {
$('.trSelected',flex).each(function() {
data = {
urlhash: $(this).find('td :first').text(),
addTag: $("input[@name='tag']").getValue()
};
$.ajax({
type: 'POST',
url: "/api/bookmarks/tags/addTag.xml",
data: data,
dataType: 'xml'
}); // close $.ajax(
}); //close each(
loadTagCloud();
reloadBM();
$("#tagadd").dialog("close");
},
Cancel: function() {
$("input[@name='tag1']").setValue("cancel");
$("#tagadd").dialog("close");
}
}
});
/* Load Sidebar */
$("#side1").load("sidebar/sidebar_1.html");
$("#side2").load("sidebar/sidebar_2.html");
@ -201,6 +284,30 @@
</select>
</form>
</div>
<!-- Tag Edit Dialog -->
<div id="tagedit" class="bmdialog" title="YaCy Bookmark Edit Tags">
<p>This dialog lets you rename (edit) tag names. You can also add a new tag to all bookmarks tagged with old tag.
</p>
<form id="tageditform" class="small" method="post" accept-charset="UTF-8" action="jQuery">
<label for="qtag">Old Tag:</label>
<br />
<input type="text" name="tag1" id="tag1" class="filter" size="80" />
<br />
<label for="tag">New Tag:</label>
<br />
<input type="text" name="tag2" id="tag2" class="filter" size="80" />
<br />
</form>
</div>
<!-- Tag Add Dialog -->
<div id="tagadd" class="bmdialog" title="YaCy Bookmark Add Tags">
<p>This dialog lets you add tags or folders to the selected bookmarks.</p>
<form id="tagaddform" class="small" method="post" accept-charset="UTF-8" action="jQuery">
<label for="qtag">Tag Name:</label>
<br />
<input type="text" name="tag" id="tag" class="filter" size="80" />
</form>
</div>
</body>
</html>

@ -13,16 +13,14 @@
colModel: [
{display: 'Hash', name : 'hash', width : 50, sortable : false, align: 'center', hide: true},
{display: 'Public', name : 'public', width : 25, sortable : true, align: 'center'},
{display: 'Title', name : 'title', width : 450, sortable : true, align: 'left'},
{display: 'Tags', name : 'tags', width : 240, sortable : false, align: 'left'},
{display: 'Folders', name : 'folders', width : 240, sortable : false, align: 'left', hide: true},
{display: 'Title', name : 'title', width : 400, sortable : true, align: 'left'},
{display: 'Tags', name : 'tags', width : 160, sortable : false, align: 'left'},
{display: 'Folders', name : 'folders', width : 160, sortable : false, align: 'left', hide: false},
{display: 'Date', name : 'date', width : 100, sortable : true, align: 'left'}
],
buttons: [
{name: 'Add', bclass: 'bookmark', onpress: bm_action},
{name: 'Crawl', bclass: 'crawl', onpress: bm_action},
{separator: true},
{name: 'Bookmark', bclass: 'bookmark', onpress: bm_action},
{separator: true},
{name: 'Edit', bclass: 'edit', onpress: bm_action},
{name: 'Delete', bclass: 'delete', onpress: bm_action},
{separator: true},
@ -30,7 +28,8 @@
{name: 'XBEL', bclass: 'xml', onpress: bm_action},
{name: 'XML', bclass: 'xml', onpress: bm_action},
{separator: true},
{name: 'Import', bclass: 'import', onpress: bm_action},
{name: 'Add', bclass: 'addTag', onpress: tag_action},
{name: 'Rename', bclass: 'editTag', onpress: tag_action},
{separator: true},
{name: 'Help', bclass: 'help', onpress: bm_action},
],
@ -53,13 +52,15 @@
});
function bm_action(com,grid) {
if (com=='XBEL') {
window.document.location.href = '/api/bookmarks/get_bookmarks.xml?display=xbel';
var qtype = "tags";
if (qtag.startsWith("/")) qtype = "folders";
window.document.location.href = '/api/bookmarks/get_bookmarks.xml?display=xbel&qtype='+qtype+'&query='+qtag;
}
else if (com=='RSS') {
window.document.location.href = '/Bookmarks.rss';
window.document.location.href = '/Bookmarks.rss?qtype=tags&query='+qtag;
}
else if (com=='XML') {
window.document.location.href = '/api/bookmarks/get_bookmarks.xml';
window.document.location.href = '/api/bookmarks/get_bookmarks.xml?tag='+qtag;
}
else if (com=='Delete') {
confirm('Delete ' + $('.trSelected',grid).length + ' bookmark(s)?')
@ -71,11 +72,10 @@
dataType: 'xml'
}); // close $.ajax(
}); //close each(
loadFolders();
loadTagCloud();
$tabs.tabs("load", 3);
reloadBM();
}
else if (com=='Bookmark') {
else if (com=='Add') {
$('#bmaddform').resetForm();
$("#bm_url").blur(function() {
var url = $("input[@name='bm_url']").getValue();
@ -104,14 +104,24 @@
return false;
}
$("input[@name='bm_url']").setValue($('.trSelected',grid).find('.url').text());
$("textarea[@name='bm_title']").setValue($('.trSelected',grid).find('h3.linktitle').text().replace(/^\s+/g,""));
$("textarea[@name='bm_desc']").setValue($('.trSelected',grid).find('p.desc').text().replace(/^\s+/g,""));
$("input[@name='bm_tags']").setValue($('.trSelected',grid).find('p.tags').text().replace(/\s+/g,""));
$("input[@name='bm_path']").setValue($('.trSelected',grid).find('p.folders').text());
$("textarea[@name='bm_title']").setValue($('.trSelected',grid).find('h3.linktitle').text().trim());
$("textarea[@name='bm_desc']").setValue($('.trSelected',grid).find('p.desc').text().trim());
$("input[@name='bm_tags']").setValue($('.trSelected',grid).find('p.tags').text().trim().replace(/,\s/g,","));
$("input[@name='bm_path']").setValue($('.trSelected',grid).find('p.folders').text().replace(/,\s/g,","));
$("select[@name='bm_public']").setValue($('.trSelected',grid).find('img').attr('alt'));
$("#bmadd").dialog('open');
}
}
function tag_action(com,grid) {
if (com=='Add') {
flex = grid;
$('#tagaddform').resetForm();
$("#tagadd").dialog('open');
} else {
$('#tageditform').resetForm();
$("#tagedit").dialog('open');
}
}
//]]>
</script>

@ -8,6 +8,7 @@
apfelmaennchen
<h3>Change Log</h3>
<ul>
<li>27-01-2009: added two dialogs for managing tags (finally fixed the renameTag() method in bookmarksDB)</li>
<li>26-01-2009: reworked search interface, still has timing problems, but now uses yacysearch.json and has full support for flexigrid</li>
<li>25-01-2009: bookmark folders sidebar is now directly linked to flexigrid if bookmark tab is selected</li>
<li>25-01-2009: successfully migrated bookmark folders to treeview.async mode (==> new json api)</li>

@ -720,31 +720,34 @@ public class bookmarksDB {
public boolean renameTag(final String oldName, final String newName){
final String oldHash=tagHash(oldName);
//String newHash=tagHash(newName);
final Tag tag=getTag(oldHash); // set tag to oldHash
if (tag != null) {
final Set<String> urlHashes = tag.getUrlHashes(); // preserve urlHashes of tag
removeTag(oldHash);
final Tag oldTag=getTag(tagHash(oldName));
if (oldTag != null) {
final Set<String> urlHashes = oldTag.getUrlHashes(); // preserve urlHashes of oldTag
removeTag(tagHash(oldName)); // remove oldHash from TagsDB
final Iterator<String> it = urlHashes.iterator();
Bookmark bookmark;
Set<String> tags;
String tagsString;
while (it.hasNext()) { // looping through all bookmarks which were tagged with oldName
Set<String> tags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
while (it.hasNext()) { // looping through all bookmarks which were tagged with oldName
bookmark = getBookmark(it.next());
tagsString = bookmark.getTagsString();
// Set<String> tags is difficult with case sensitivity, so I tried
// Set<String> tags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER), but it didn't do the trick :-(
// so I chose the tagsString and replaceAll() as workaround
// unfortunately doing the replaceAll with Patterns (regexp) really costs performance
tags=listManager.string2set(Pattern.compile(oldName,66).matcher(tagsString).replaceAll(newName)); // TODO: need better solution for renaming tags
bookmark.setTags(tags, true); // I had to adjust setTags() for this to work
tags = bookmark.getTags();
tags.remove(oldName);
bookmark.setTags(tags, true); // might not be needed, but doesn't hurt
if(!newName.equals("")) bookmark.addTag(newName);
saveBookmark(bookmark);
}
return true;
}
return false;
}
public void addTag(final String selectTag, final String newTag){
final Iterator<String> it = getTag(tagHash(selectTag)).getUrlHashes().iterator(); // get urlHashes for selectTag
Bookmark bookmark;
while (it.hasNext()) { // looping through all bookmarks which were tagged with selectTag
bookmark = getBookmark(it.next());
bookmark.addTag(newTag);
}
}
// --------------------------------------
// bookmarksDB's Import/Export functions
@ -1072,10 +1075,9 @@ public class bookmarksDB {
public Bookmark(final String urlHash, final Map<String, String> map) {
this.entry = map;
this.urlHash=urlHash;
tags=new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
if(map.containsKey(BOOKMARK_TAGS))
tags=listManager.string2set(map.get(BOOKMARK_TAGS));
else
tags=new HashSet<String>();
tags.addAll(listManager.string2set(map.get(BOOKMARK_TAGS)));
loadTimestamp();
}
@ -1230,8 +1232,9 @@ public class bookmarksDB {
//setBookmarksTable();
}
public void addTag(final String tag){
tags.add(tag);
public void addTag(final String tagName){
tags.add(tagName);
setTags(tags);
}
/**

Loading…
Cancel
Save