Skip to content

Commit

Permalink
Item1918: introducing clickable tagsclouds
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/TagsPlugin@5065 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OliverKrueger authored and OliverKrueger committed Sep 21, 2009
1 parent 3871986 commit d049c6d
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 11 deletions.
1 change: 1 addition & 0 deletions data/System/TagsPlugin.txt
Expand Up @@ -45,6 +45,7 @@ You can disable the <nop>TagsPlugin =TAGCLOUD= macro in =configure=, if you want
use the =TAGCLOUD= macro from the Foswiki:Extensions.TagCloudPlugin instead. See {TagsPlugin}{EnableTagCloud}.

%INCLUDE{%SYSTEMWEB%.VarTAGSEARCH}%
%INCLUDE{%SYSTEMWEB%.VarTAGCLOUDCLICK}%

---+++ SEARCHing
To search for topics that are tagged with (or not tagged with), use a %SYSTEMWEB%.QuerySearch
Expand Down
11 changes: 11 additions & 0 deletions data/System/TagsPluginTagListJSON.txt
@@ -0,0 +1,11 @@
%META:TOPICINFO{author="BaseUserMapping_333" date="1253507705" format="1.1" reprev="1.1" version="1.1"}%
%TAGSEARCH{
query="tag"
web="%URLPARAM{"tagweb" default="%TAGWEB%"}%"
topic="%URLPARAM{"tagtopic" default="%TAGTOPIC%"}%"
user="%URLPARAM{"taguser" default="%TAGUSER%"}%"
header="[ "
format="'$tag'"
footer=" ]"
sep=", "
}%
16 changes: 16 additions & 0 deletions data/System/VarTAGCLOUDCLICK.txt
@@ -0,0 +1,16 @@
%META:TOPICINFO{author="BaseUserMapping_333" date="1252340265" format="1.1" version="1.2"}%
%META:TOPICPARENT{name="TagsPlugin"}%
#VarTAGCLOUDCLICK

---+++ TAGCLOUDCLICK -- render a clickable tagcloud
* Inline tag search, shows a tag search result embedded in a topic
* Syntax: =%<nop>TAGCLOUDCLICK{...}%=
* %X% Limitation: This macro can only be used once per page.
* Supported parameters:
| *Parameter:* | *Description:* | *Default:* |
| =sourceuser="wikiname"= <br /> =sourceuser="all"= | When rendering the tagcloud, this filter is used for the user-dimension. Leave out the =%MAINWEB%= part here. | ="all"= |
| =sourceweb="Name"= <br /> =sourceweb="%USERSWEB%, Know"= <br /> =sourceweb="all"= | Comma-separated list of webs to render the tagcloud. The special word =all= means all webs (inlcuding those which have the =NOSEARCHALL= preference set to =on=). Use =%= as a wildcard. | ="all"= |
| =targetweb="Name"= | Webname of the target topic. This is where the tags are posted to. | =current web= |
| =targettopic="Name"= | Topicname of the target topic. This is where the tags are posted to. | =current topic= |
| =targetuser="wikiname"= | New tags are created with this ownership. | =%TAGPUBLIC%= |
| =cloudtopic="Web.Topic"= | This topic is used (included) to actually render the tagcloud. | =%SYSTEMWEB%.<nop>TagsPluginTagCloud= |
20 changes: 13 additions & 7 deletions lib/Foswiki/Plugins/TagsPlugin.pm
Expand Up @@ -45,13 +45,14 @@ sub initPlugin {
return 0;
}

Foswiki::Func::registerTagHandler( 'TAGLIST', \&_TAGLIST );
Foswiki::Func::registerTagHandler( 'TAGENTRY', \&_TAGENTRY );
Foswiki::Func::registerTagHandler( 'TAGCLOUD', \&_TAGCLOUD ) if ( defined($Foswiki::cfg{TagsPlugin}{EnableTagCloud}) && $Foswiki::cfg{TagsPlugin}{EnableTagCloud} );
Foswiki::Func::registerTagHandler( 'TAGSEARCH', \&_TAGSEARCH );
Foswiki::Func::registerTagHandler( 'TAGGROUPS', \&_TAGGROUPS );
Foswiki::Func::registerTagHandler( 'TAGPUBLIC', \&_TAGPUBLIC );
Foswiki::Func::registerTagHandler( 'ISTAGADMIN', \&_ISTAGADMIN );
Foswiki::Func::registerTagHandler( 'TAGLIST', \&_TAGLIST );
Foswiki::Func::registerTagHandler( 'TAGENTRY', \&_TAGENTRY );
Foswiki::Func::registerTagHandler( 'TAGCLOUD', \&_TAGCLOUD ) if ( defined($Foswiki::cfg{TagsPlugin}{EnableTagCloud}) && $Foswiki::cfg{TagsPlugin}{EnableTagCloud} );
Foswiki::Func::registerTagHandler( 'TAGCLOUDCLICK', \&_TAGCLOUDCLICK );
Foswiki::Func::registerTagHandler( 'TAGSEARCH', \&_TAGSEARCH );
Foswiki::Func::registerTagHandler( 'TAGGROUPS', \&_TAGGROUPS );
Foswiki::Func::registerTagHandler( 'TAGPUBLIC', \&_TAGPUBLIC );
Foswiki::Func::registerTagHandler( 'ISTAGADMIN', \&_ISTAGADMIN );

Foswiki::Func::registerRESTHandler( 'tag', \&tagCall );
Foswiki::Func::registerRESTHandler( 'untag', \&untagCall );
Expand Down Expand Up @@ -296,6 +297,11 @@ sub _TAGCLOUD {
return _TAGLIST( $session, $params, $theTopic, $theWeb );
}

sub _TAGCLOUDCLICK {
use Foswiki::Plugins::TagsPlugin::TAGCLOUDCLICK;
return Foswiki::Plugins::TagsPlugin::TAGCLOUDCLICK::do( @_ );
}

sub _TAGSEARCH {
use Foswiki::Plugins::TagsPlugin::TAGSEARCH;
return Foswiki::Plugins::TagsPlugin::TAGSEARCH::do( @_ );
Expand Down
4 changes: 4 additions & 0 deletions lib/Foswiki/Plugins/TagsPlugin/MANIFEST
Expand Up @@ -5,15 +5,18 @@ data/System/TagsPluginAutoCompleteBackend.txt 0644 Topic
data/System/TagsPluginViewsTagSearch.txt 0644 Topic
data/System/TagsPluginNoHeaderViewTemplate.txt 0644 Topic
data/System/TagsPluginTagList.txt 0644 Topic
data/System/TagsPluginTagListJSON.txt 0644 Topic
data/System/TagsPluginTagCloud.txt 0644 Topic
data/System/TagsPluginTagDetails.txt Topic
data/System/TagsPluginTagDetailsSimple.txt Topic
data/System/TagsPluginTagDetailsAdmin.txt Topic
data/System/TagsPluginUserSelector.txt Topic
data/System/TagsPluginWebSelector.txt Topic
data/System/VarTAGSEARCH.txt 0644 Documentation
data/System/VarTAGCLOUDCLICK.txt 0644 Documentation
pub/System/TagsPlugin/tagsplugin.css 0644 Stylesheets
pub/System/TagsPlugin/tagsplugin.js 0644 Javascript
pub/System/TagsPlugin/tagsplugin-cloudclick.js 0644 Javascript
lib/Foswiki/Plugins/TagsPlugin.pm 0644 Perl module
lib/Foswiki/Plugins/TagsPlugin/Tag.pm 0644 Perl module
lib/Foswiki/Plugins/TagsPlugin/Untag.pm 0644 Perl module
Expand All @@ -22,6 +25,7 @@ lib/Foswiki/Plugins/TagsPlugin/Rename.pm 0644 Perl module
lib/Foswiki/Plugins/TagsPlugin/Merge.pm 0644 Perl module
lib/Foswiki/Plugins/TagsPlugin/TAGSEARCH.pm 0644 Perl module
lib/Foswiki/Plugins/TagsPlugin/TAGGROUPS.pm 0644 Perl module
lib/Foswiki/Plugins/TagsPlugin/TAGCLOUDCLICK.pm 0644 Perl module
templates/tagsplugin.tmpl
templates/view.tagsplugin.tmpl
templates/view.tagspluginjquery.tmpl
Expand Down
62 changes: 62 additions & 0 deletions lib/Foswiki/Plugins/TagsPlugin/TAGCLOUDCLICK.pm
@@ -0,0 +1,62 @@
# This script Copyright
# (c) 2009 Oliver Krueger, (wiki-one.net)
# and distributed under the GPL (see below)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html
#
# Author(s): Oliver Krueger

package Foswiki::Plugins::TagsPlugin::TAGCLOUDCLICK;

use strict;
use warnings;
use Error qw(:try);

use constant DEBUG => 1; # toggle me

=begin TML
---++ do( $session, $params, $topic, $web )
Taghandler for TAGCLOUDCLICK.
Returns an INCLUDE statement based on the input parameters plus add meta data to html header and include a js file.
Return:
Clickable Tag Cloud.
=cut

sub do {
my ( $session, $params, $topic, $web ) = @_;

my $theSourceUser = $params->{sourceuser} || "all";
my $theTargetUser = $params->{targetuser} || Foswiki::Func::getPreferencesValue("TAGSPLUGIN_TAGUSER") || Foswiki::Func::getWikiName();
my $theSourceWeb = $params->{sourceweb} || $web;
my $theTargetWeb = $params->{targetweb} || $web;
my $theTargetTopic = $params->{targettopic} || $topic;
my $theCloudTopic = $params->{cloudtopic} || "%SYSTEMWEB%.TagsPluginTagCloud";

my $header = "<meta name='foswiki.tagsplugin.cloudclick.targetuser' content='$theTargetUser' />\n";
$header .= "<meta name='foswiki.tagsplugin.cloudclick.targetweb' content='$theTargetWeb' />\n";
$header .= "<meta name='foswiki.tagsplugin.cloudclick.targettopic' content='$theTargetTopic' />\n";
$header .= "<meta name='foswiki.tagsplugin.cloudclick.sourceuser' content='$theSourceUser' />\n";
$header .= "<meta name='foswiki.tagsplugin.cloudclick.sourceweb' content='$theSourceWeb' />\n";
$header .= "<meta name='foswiki.tagsplugin.cloudclick.cloudtopic' content='$theCloudTopic' />\n";
$header .= "<script type='text/javascript' src='%PUBURL%/System/TagsPlugin/tagsplugin-cloudclick.js'></script>\n";
Foswiki::Func::addToHEAD('TAGSPLUGIN::CLOUDCLICK', "\n".$header );

my $output = "<div id='tagsplugin_cloudclick'>%INCLUDE{\"$theCloudTopic\" TAGUSER=\"$theSourceUser\" TAGWEB=\"$theSourceWeb\"}%</div>\n";
$output .= "<div id='tagsplugin_cloudclick_processing'>%ICON{processing-bg}%</div>\n";
$output .= "<div id='tagsplugin_cloudclick_dialog' />\n";
return $output;
}

1;
152 changes: 152 additions & 0 deletions pub/System/TagsPlugin/tagsplugin-cloudclick.js
@@ -0,0 +1,152 @@
(function($){
$(function(){
tagsplugin_cloudclick_refresh()
}); // ready handler

function tagsplugin_cloudclick_mark() {

$("div#tagsplugin_cloudclick .tagsplugin_tagcloud_tag:not(.tagsplugin_tagcloud_tag_bound)")
.bind(
'click',
function(event) {
event.preventDefault();
tagsplugin_cloudclick_toggletag(event);
}
)
.addClass("tagsplugin_tagcloud_tag_bound");
$.getJSON(
foswiki.scriptUrl+"/view/"+foswiki.systemWebName+"/TagsPluginTagListJSON",
{
skin: "text",
cover: "text",
tagweb: foswiki.tagsplugin.cloudclick.targetweb,
tagtopic: foswiki.tagsplugin.cloudclick.targettopic,
taguser: foswiki.tagsplugin.cloudclick.targetuser
},
function(data) {
for(var i = 0; i < data.length; i++)
$("div#tagsplugin_cloudclick .tagsplugin_tagcloud_tag[tag='"+data[i]+"']").addClass("tagsplugin_tagged");
}
)
}

function tagsplugin_cloudclick_toggletag(event) {
if ( $(event.target).hasClass("tagsplugin_tagged") ) {
$("#tagsplugin_cloudclick_processing img").show();
var tag = $(event.target).attr("tag");
var item = foswiki.tagsplugin.cloudclick.targetweb+"."+foswiki.tagsplugin.cloudclick.targettopic;
var user = foswiki.tagsplugin.cloudclick.targetuser;
tagsplugin_be_untag( tag, item, user );
$(event.target).removeClass("tagsplugin_tagged");
} else {
$("#tagsplugin_cloudclick_processing img").show();
var tag = $(event.target).attr("tag");
var item = foswiki.tagsplugin.cloudclick.targetweb+"."+foswiki.tagsplugin.cloudclick.targettopic;
var user = foswiki.tagsplugin.cloudclick.targetuser;
tagsplugin_be_tag( tag, item, user );
$(event.target).addClass("tagsplugin_tagged");
}
}

function tagsplugin_cloudclick_refresh() {
$("#tagsplugin_cloudclick_processing img").show();
$.get(
foswiki.scriptUrl+"/view/"+foswiki.tagsplugin.cloudclick.cloudtopic,
{ skin : "text",
cover : "text",
tagweb : foswiki.tagsplugin.cloudclick.sourceweb,
taguser : foswiki.tagsplugin.cloudclick.sourceuser
},
function(data) {
$("div#tagsplugin_cloudclick").html(data);
tagsplugin_cloudclick_mark();
$("#tagsplugin_cloudclick_processing img").hide();
}
);
}

function tagsplugin_be_tag(tag, item, user) {
$.ajax(
{ url: foswiki.scriptUrl+'/rest/TagsPlugin/tag',
type: "POST",
data: { tag : tag,
item : item,
user : user
},
complete: function(xhr, statusText) {
switch (xhr.status) {
case 200:
tagsplugin_cloudclick_refresh();
break;
case 400:
tagsplugin_alert("Assuming you are logged-in and assuming you provided a tag name you probably just revealed a software bug. I'm sorry about that. (400)");
break;
case 401:
tagsplugin_alert("According to my data, you are not logged in. Please log-in before you retry.");
break;
case 403:
tagsplugin_alert("I'm sorry, but you are not allowed to do that.");
break;
case 500:
tagsplugin_alert("Something beyond your sphere of influence went wrong. Most probably a problem with the database. May I kindly ask you to inform your administrator? Thank you.");
break;
default:
tagsplugin_alert("Unknown error in tagsplugin_be_tag.");
break;
}
$("#tagsplugin_cloudclick_processing img").hide();
}
}
);
}

function tagsplugin_be_untag(tag, item, user) {
$.ajax(
{ url: foswiki.scriptUrl+'/rest/TagsPlugin/untag',
type: "POST",
data: { tag : tag,
item : item,
user : user
},
complete: function(xhr, statusText) {
switch (xhr.status) {
case 200:
tagsplugin_cloudclick_refresh();
break;
case 400:
tagsplugin_alert("Assuming you are logged in you probably just revealed a software bug. I'm sorry about that. (400)");
break;
case 401:
tagsplugin_alert("According to my data, you are not logged in. Please log-in before you retry.");
break;
case 403:
tagsplugin_alert("I'm sorry, but you are not allowed to do that.");
break;
case 404:
tagsplugin_alert("I'm sorry, but either the tag or the topic does not exist.");
break;
case 500:
tagsplugin_alert("Something beyond your sphere of influence went wrong. Most probably a problem with the database. May I kindly ask you to inform your administrator? Thank you.");
break;
default:
tagsplugin_alert("Unknown error in tagsplugin_be_untag.");
break;
}
$("#tagsplugin_cloudclick_processing img").hide();
}
}
);
}

function tagsplugin_alert(text) {
$("#tagsplugin_cloudclick_dialog")
.html(text)
.dialog()
.dialog('option', 'modal', true)
.dialog('option', 'width', 460)
.dialog('option', 'title', 'May I kindly ask for your attention?')
.dialog('option', 'buttons', { "Ok": function() { $(this).dialog("close"); } })
.dialog("open");
}

})(jQuery);
6 changes: 6 additions & 0 deletions pub/System/TagsPlugin/tagsplugin.css
Expand Up @@ -138,6 +138,12 @@
line-height: 90%;
text-decoration: none;
}
div#tagsplugin_cloudclick a.tagsplugin_tagged {
background-color:#CCE7F1;
}
div#tagsplugin_cloudclick_processing img {
display: none;
}
div#tagsplugin_clear {
clear: both;
}
8 changes: 4 additions & 4 deletions pub/System/TagsPlugin/tagsplugin.js
Expand Up @@ -63,7 +63,7 @@
);

// webselector bindings
$(".tagsplugin_web").bind(
$("div#tagsplugin .tagsplugin_web").bind(
'click',
function(event) {
event.preventDefault();
Expand All @@ -74,7 +74,7 @@
);

// userselector bindings
$(".tagsplugin_user").bind(
$("div#tagsplugin .tagsplugin_user").bind(
'click',
function(event) {
event.preventDefault();
Expand All @@ -87,8 +87,8 @@
}); // ready handler

function tagsplugin_fe_redirect_details() {
$(".tagsplugin_tag")
.add(".tagsplugin_tagcloud_tag")
$("div#tagsplugin .tagsplugin_tag")
.add("div#tagsplugin .tagsplugin_tagcloud_tag")
.bind(
'click',
function(event) {
Expand Down

0 comments on commit d049c6d

Please sign in to comment.