Skip to content

Commit

Permalink
Make Slash.pm's displayStory use the new tag-ui
Browse files Browse the repository at this point in the history
which required teaching setGetCombinedTags about stoids.
Separated out a simplified version of the firehose tag-ui widget; this
could probably _become_ the firehose widget if we figure out how to handle
the admin parts.
  • Loading branch information
scc committed Sep 29, 2008
1 parent a90233a commit 2a140a8
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 67 deletions.
28 changes: 13 additions & 15 deletions Slash/Slash.pm
Expand Up @@ -281,21 +281,19 @@ sub displayStory {
}
$return =~ s/\Q__TIME_TAG__\E/$atstorytime/;

if ($constants->{plugin}{Tags}
&& $user->{tags_canread_stories}
&& !$user->{tags_turnedoff}
&& (!$options->{dispmode} || $options->{dispmode} ne 'brief')) {

my @tags_top = split / /, ($story->{tags_top} || '');
my $tags_reader = getObject('Slash::Tags', { db_type => 'reader' });
my @tags_example = $tags_reader->getExampleTagsForStory($story);
$return .= slashDisplay('tagsstorydivtagbox', {
story => $story,
tags_top => \@tags_top,
tags_example => \@tags_example,
}, { Return => 1 });

}
#if ($constants->{plugin}{Tags}
# && $user->{tags_canread_stories}
# && !$user->{tags_turnedoff}
# && (!$options->{dispmode} || $options->{dispmode} ne 'brief')) {

# $return .= slashDisplay('tag_ui_widget', {
# user => $user,
# item => $story,
# key => $stoid,
# key_type => 'stoid',
# }, { Return => 1 });

#}
}

return $return;
Expand Down
15 changes: 3 additions & 12 deletions plugins/Admin/admin.pl
Expand Up @@ -1479,17 +1479,8 @@ sub editStory {
$add_related_text .= "$storyref->{related_urls_hr}{$_} $_\n";
}

my $tagbox_html = '';
if ($constants->{plugin}{Tags} && $storyref->{sid}) {
my @tags_top = split / /, ($story->{tags_top} || '');
my $tags_reader = getObject('Slash::Tags', { db_type => 'reader' });
my @tags_example = $tags_reader->getExampleTagsForStory($story);
$tagbox_html .= slashDisplay('tagsstorydivtagbox', {
story => $storyref,
tags_top => \@tags_top,
tags_example => \@tags_example,
}, { Return => 1 });
}
# TODO: add new tagui here

my $pending_file_count = 0;
my $story_static_files = [];
if ($stoid || $form->{sid}) {
Expand All @@ -1504,7 +1495,7 @@ sub editStory {
storyref => $storyref,
story => $story,
storycontent => $storycontent,
tagbox_html => $tagbox_html,
tagbox_html => '',
sid => $sid,
subid => $subid,
fhid => $fhid,
Expand Down
1 change: 1 addition & 0 deletions plugins/Ajax/PLUGIN
Expand Up @@ -57,3 +57,4 @@ template=templates/prefs_authors;ajax;default
template=templates/prefs_main;ajax;default
template=templates/prefs_admin;ajax;default
template=templates/sectionpref;ajax;default
template=templates/tag_ui_widget;misc;default
8 changes: 5 additions & 3 deletions plugins/Ajax/htdocs/images/admin.js
Expand Up @@ -33,7 +33,7 @@ function tagsHistory(id, type) {
var $positioners;
if ( type == 'firehose' ) {
var $entry = $('#firehose-'+id);
var $widget = $('#tag-widget-'+id, $entry[0]);
var $widget = $entry.find('div.tag-widget.body-widget:first');

// hang the pop-up from the first available of:
$positioners =
Expand Down Expand Up @@ -105,7 +105,7 @@ function firehose_handle_admin_commands( commands ){
var signoff_tag_server = this;
this._ajax_request('', {
op: 'admin_signoff',
stoid: $('[stoid]', this).attr('stoid'),
stoid: this.article_info('stoid'),
ajax: { success: function(){ $('[context=signoff]', signoff_tag_server).remove(); } }
});
}
Expand Down Expand Up @@ -303,7 +303,9 @@ function firehose_reject (el) {
firehose_remove_entry(el.value);
}

function firehose_init_note_flags( $entries ){
function firehose_init_note_flags(){
var $entries = $(document).article_info__find_articles(':not(:has(.title h3 span.note-flag))');

// set up the "note flag"
return $entries.each(function(){
var $entry = $(this), id = firehose_id_of(this);
Expand Down
21 changes: 21 additions & 0 deletions plugins/Ajax/htdocs/images/common.js
Expand Up @@ -724,6 +724,27 @@ function firehose_handle_comment_nodnix( commands ){
}


function tag_ui_init_new_articles(){
if ( $('#firehose').length ) {
return firehose_init_tag_ui();
}

var $new_articles = $(document).article_info__find_articles(':not(:has(span.sd-info-block .tag-ui))');
$new_articles.
each(function(){
install_tag_server(this);
});
$init_tag_widgets($new_articles.find('.tag-widget-stub'));
init_tag_ui_styles($new_articles);
$new_articles.article_info('tag-ui', true);
return $new_articles;
}

$(function(){
tag_ui_init_new_articles();
});


function firehose_init_tag_ui( $new_entries ){
if ( ! $new_entries || ! $new_entries.length ) {
var $firehoselist = $('#firehoselist');
Expand Down
2 changes: 1 addition & 1 deletion plugins/Ajax/htdocs/images/slash.article-info.js
Expand Up @@ -76,7 +76,7 @@ function find_key( elem ){

function $find_info_blocks( $list ){
return $list.map(function(){
return $(this).find_nearest(select_info_blocks, 'down', 'up').get();
return $(this).find_nearest(select_info_blocks, 'self', 'down', 'up').get();
});
}

Expand Down
21 changes: 12 additions & 9 deletions plugins/Ajax/htdocs/images/slash.util.js
Expand Up @@ -458,16 +458,16 @@ Package({ named: 'Slash.Util.Algorithm',
// Yes, I could phrase this as a Package; but I don't need to, here.
$.fn.extend({
find_nearest: function( selector ){
var args = arguments, N = Math.min(3, args.length);
var args = arguments, N = Math.min(4, args.length);
var answer = this.map(function(){
var $this = $(this);
if ( $this.is(selector) ) {
return this;
}

var match;
var $this = $(this), match, $matches;
for ( var i=1; i<N && !match; ++i ) {
switch ( args[i] ) {
case 'self':
if ( $this.is(selector) ) {
return this;
}
break;
case 'up':
$this.parents().each(function(){
if ( $(this).is(selector) ) {
Expand All @@ -477,7 +477,10 @@ $.fn.extend({
});
break;
case 'down':
match = $this.find(selector)[0];
$matches = $this.find(selector);
if ( $matches.length ) {
match = $matches.get()
}
break;
}
}
Expand All @@ -486,7 +489,7 @@ $.fn.extend({
return this.pushStack($.unique(answer))
},
nearest_parent: function( selector ){
return this.find_nearest(selector, 'up');
return this.find_nearest(selector, 'self', 'up');
},
setClass: function( cn ) {
var fn = $.isFunction(cn) ? cn : function(){ return cn; };
Expand Down
6 changes: 6 additions & 0 deletions plugins/Ajax/htdocs/images/tag-ui.js
Expand Up @@ -761,6 +761,12 @@ var tag_widget_fns = {
}

return this;
},
toggle_widget: function( twisty ){
var $twisty = $(twisty);
var if_expanding = $twisty.is('.collapse');

$twisty.mapClass({'collapse':'expand', 'expand':'collapse'});
}

}; // tag_widget_fns
Expand Down
65 changes: 65 additions & 0 deletions plugins/Ajax/templates/tag_ui_widget;misc;default
@@ -0,0 +1,65 @@
__section__
default
__description__
A default tag widget that should work anywhere.

user
item
key
key_type
__title__
__page__
misc
__lang__
en_US
__name__
tag_ui_widget
__seclev__
10000
__template__
[% IF user.tags_canread_stories %]
[%# the tag-widget itself %]
<div class="tag-widget-stub body-widget" init="context_timeout:15000">

[%# the disclosure triangle %]
<a class="edit-toggle"
[% IF user.tags_canwrite_stories %] href="#" onclick="this.blur(); this.parentNode.toggle_widget(this); return false"
[%- ELSIF user.is_anon %] href="#" onclick="this.blur(); show_login_box(); return false"
[%- ELSE %] href="[% gSkin.rootdir %]/subscribe.pl"
[%- END %]>
<span class="button collapse"></span>
</a>

[% IF user.tags_canwrite_stories %]
[%# the tag input field %]
<form class="tag-editor" onsubmit="form_submit_tags(this, {fade_remove: 400, order: 'prepend', classes:'not-saved'}); return false">
<input class="tag-entry" type="text" size="10">
<span class="tag-server-busy"><img src="[% constants.imagedir %]/spinner[% IF !featured %]2[% END %].gif"></span>
</form>
[% END %]

[%# the tag 'bars' %]
<div class="tag-display-set train">
[% IF user.tags_canwrite_stories %]
<div class="tag-display-stub" context="user" init="legend:'my&nbsp;tags'"></div>
[% END %]
[% tags_reader = Slash.getObject('Slash::Tags'); tags = tags_reader.setGetCombinedTags(key, key_type); %]
<div class="tag-display-stub" context="top" init="legend:'top&nbsp;tags'">[% tags.top %]</div>
<div class="tag-display-stub" context="system" init="legend:'system&nbsp;tags'">[% tags.system %]</div>
[%- IF item.type == "story" &&
constants.signoff_use &&
((user.is_admin && !user.firehose_usermode) || user.acl.signoff_allowed) &&
! Slash.db.hasUserSignedStory(item.srcid, user.uid) -%]
<div class="tag-display-stub" context="signoff" init="legend:'signoff', menu:false">unsigned</div>
[%- END -%]
</div>
[% IF user.tags_canwrite_stories %]
[%# the suggestions bar %]
<div class="related">
<div class="tag-display-stub" context="related" init="legend:'suggestions', menu:false"></div>
</div>
[% END %]
</div>
[% END %]
__version__
$Id$
2 changes: 1 addition & 1 deletion plugins/FireHose/PLUGIN
Expand Up @@ -3,7 +3,6 @@ name=FireHose
description="FireHose"
glob=firehosecss:htdocs/firehose.css
firehosecss=firehose.css
firehosecss=../Ajax/htdocs/images/tag-ui.css
firehosecss=../Ajax/htdocs/images/jquery/jquery.autocomplete.css
css=htdocs/firehose.css
htdoc=firehose.pl
Expand All @@ -28,6 +27,7 @@ template=templates/firehose_usage;misc;default
template=templates/firehose_options;misc;default
template=templates/formatHoseIntro;misc;default
template=templates/formatHoseTitle;misc;default
template=templates/nodnix_capsule;firehose;default
template=templates/paginate;firehose;default
template=templates/portalmap;firehose;default
template=templates/reject_firehose;misc;default
Expand Down
3 changes: 1 addition & 2 deletions plugins/FireHose/templates/list;firehose;default
Expand Up @@ -221,9 +221,8 @@ $(function(){
});

$('#firehoselist').click(firehose_click_tag);
var $entries = firehose_init_tag_ui();
if ( fh_is_admin ) {
firehose_init_note_flags($entries);
firehose_init_note_flags();
}
});

Expand Down
24 changes: 24 additions & 0 deletions plugins/FireHose/templates/nodnix_capsule;firehose;default
@@ -0,0 +1,24 @@
__section__
default
__description__
__title__
__page__
firehose
__lang__
en_US
__name__
nodnix_capsule
__seclev__
10000
__template__
[% IF user.tags_canread_stories && !form.skipvote && !options.nothumbs && !skipvote %]
[%# the nod/nix 'capsule' %]
<div class="tags">
<span id="updown-[% item.id %]" class="vote[% IF vote == 'down' %]ddown[% ELSIF vote == 'up' %]dup[% END %]">
<a href="#" class="up" title="Vote this item up">+</a>
<a href="#" class="down" title="Vote this item down">-</a>
</span>
</div>
[% END %]
__version__
$Id$
6 changes: 2 additions & 4 deletions plugins/FireHose/templates/view;firehose;default
Expand Up @@ -30,11 +30,9 @@ __template__
<script type="text/javascript">
var firehose_user_class = [% user.is_anon ? 0 : 1 %];
$(function(){
var $entries = firehose_init_tag_ui(
$('#firehose > .view > .head > [id^=firehose-]')
.click(firehose_click_tag) );
$().article_info__find_articles().click(firehose_click_tag);
if ( fh_is_admin ) {
firehose_init_note_flags($entries);
firehose_init_note_flags();
}
});
</script>
Expand Down
25 changes: 5 additions & 20 deletions plugins/Tags/Tags.pm
Expand Up @@ -894,23 +894,6 @@ sub getTagnameSfnetadmincmds {
$where_clause);
}

sub getExampleTagsForStory {
my($self, $story) = @_;
my $slashdb = getCurrentDB();
my $constants = getCurrentStatic();
my $cur_time = $slashdb->getTime();
my @examples = split / /,
$constants->{tags_stories_examples};
my $chosen_ar = $self->getTopiclistForStory($story->{stoid});
$#$chosen_ar = 3 if $#$chosen_ar > 3; # XXX should be a var
my $tree = $self->getTopicTree();
push @examples,
grep { $self->tagnameSyntaxOK($_) }
map { $tree->{$_}{keyword} }
@$chosen_ar;
return @examples;
}

sub removeTagnameFromIndexTop {
my($self, $tagname) = @_;
my $tagid = $self->getTagnameidCreate($tagname);
Expand Down Expand Up @@ -1078,11 +1061,13 @@ sub ajaxSetGetCombinedTags {
if ( $key_type eq 'url' ) {
$key = $firehose->getFireHoseIdFromUrl($key);
$key_type = 'firehose-id';
} elsif ( $key_type eq 'sid' ) {
$key = $slashdb->getStoidFromSidOrStoid($key);
$key_type = 'stoid';
}

if ( $key_type eq 'sid' ) {
my $stoid = $slashdb->getStoidFromSidOrStoid($key);
$globjid = $slashdb->getGlobjidFromTargetIfExists('stories', $stoid);
if ( $key_type eq 'stoid' ) {
$globjid = $slashdb->getGlobjidFromTargetIfExists('stories', $key);
$firehose_id = $firehose->getFireHoseIdFromGlobjid($globjid);
$firehose_item = $firehose->getFireHose($firehose_id);
} elsif ( $key_type eq 'firehose-id' ) {
Expand Down

0 comments on commit 2a140a8

Please sign in to comment.