Просмотр исходного кода

Fix #131: good enough, has some dupes in a few edge cases.

George S. Baugh 4 лет назад
Родитель
Сommit
64f9843d72

+ 1 - 1
Makefile

@@ -27,7 +27,7 @@ prereq-debs:
 	    libtext-xslate-perl libplack-perl libconfig-tiny-perl libdatetime-format-http-perl libjson-maybexs-perl          \
 	    libuuid-tiny-perl libcapture-tiny-perl libconfig-simple-perl libdbi-perl libfile-slurper-perl libfile-touch-perl \
 	    libfile-copy-recursive-perl libxml-rss-perl libmodule-install-perl libio-string-perl                             \
-	    libmoose-perl libmoosex-types-datetime-perl libxml-libxml-perl
+	    libmoose-perl libmoosex-types-datetime-perl libxml-libxml-perl liblist-moreutils-perl
 
 .PHONY: prereq-perl
 prereq-perl:

+ 5 - 0
lib/Trog/Data/DUMMY.pm

@@ -9,6 +9,7 @@ use feature qw{signatures};
 use Carp qw{confess};
 use JSON::MaybeXS;
 use File::Slurper;
+use List::Util qw{uniq};
 use parent qw{Trog::DataModule};
 
 =head1 WARNING
@@ -65,4 +66,8 @@ sub delete($self, @posts) {
     return 0;
 }
 
+sub tags($self) {
+    return (uniq map { @{$_->{tags}} } @$posts);
+}
+
 1;

+ 4 - 0
lib/Trog/Data/FlatFile.pm

@@ -123,4 +123,8 @@ sub delete($self, @posts) {
     return 0;
 }
 
+sub tags($self) {
+    return Trog::SQLite::TagIndex::tags();
+}
+
 1;

+ 1 - 0
lib/Trog/DataModule.pm

@@ -50,6 +50,7 @@ sub help  ($self) { ... }
 sub read  ($self,$query={}) { ... }
 sub write ($self) { ... }
 sub count ($self) { ... }
+sub tags  ($self) { ... }
 
 =head1 METHODS
 

+ 12 - 1
lib/Trog/Routes/HTML.pm

@@ -9,6 +9,7 @@ use feature qw{signatures state};
 use Errno qw{ENOENT};
 use File::Touch();
 use List::Util();
+use List::MoreUtils();
 use Capture::Tiny qw{capture};
 use HTML::SocialMeta;
 
@@ -924,6 +925,7 @@ sub posts ($query, $render_cb, $direct=0) {
         @{$post->{tags}} = grep { my $tag = $_; !grep { $tag eq $_ } @visibuddies } @{$post->{tags}};
     }
 
+    #XXX note that we are explicitly relying on the first tag to be the ACL
     my $aclselected = $tags->[0] || '';
     my @acls  = map {
         $_->{selected} = $_->{aclname} eq $aclselected ? 'selected' : '';
@@ -934,13 +936,22 @@ sub posts ($query, $render_cb, $direct=0) {
     my $forms = [qw{microblog.tx blog.tx file.tx}];
     my $edittype = $query->{primary_post} ? $query->{primary_post}->{child_form} : $query->{form};
 
+    # Grab the rest of the tags to dump into the edit form
+    state $data = Trog::Data->new($conf);
+    my @tags_all = $data->tags();
+    #Filter out the visibilities and special series tags
+    @tags_all = grep { my $subj = $_; scalar(grep { $_ eq $subj } qw{public private unlisted admin series about}) == 0 } @tags_all;
+
+    @posts = map { my @et = List::MoreUtils::singleton(@{$_->{tags}}, @tags_all); $_->{extra_tags} = \@et; $_ } @posts;
+    my @et = List::MoreUtils::singleton(@$tags, @tags_all);
+
     my $content = $processor->render('posts.tx', {
         app       => $app,
         acls      => \@acls,
         can_edit  => $is_admin,
         edittype  => $edittype,
         forms     => $forms,
-        post      => { tags => $tags, form => $edittype, visibility => $user_visibility },
+        post      => { tags => $tags, extra_tags => \@et, form => $edittype, visibility => $user_visibility },
         post_visibilities => \@visibuddies,
         failure   => $query->{failure},
         to        => $query->{to},

+ 7 - 0
lib/Trog/SQLite/TagIndex.pm

@@ -45,6 +45,13 @@ sub aliases {
     return %aliases;
 }
 
+sub tags {
+    my $dbh = _dbh();
+    my $rows = $dbh->selectall_arrayref("SELECT name FROM tag", { Slice => {} });
+    return () unless ref $rows eq 'ARRAY' && @$rows;
+    return map { $_->{name} } @$rows;
+}
+
 sub add_post ($post,$data_obj) {
     my $dbh = _dbh();
     build_index($data_obj,[$post]);

+ 1 - 1
www/templates/acls.tx

@@ -6,7 +6,7 @@ Visibility<br />
 </select>
 <div id="<: $post.id :>-aclselect" >
     ACLs / Series<br/ >
-    <select multiple class="cooltext" name="acls">
+    <select class="cooltext" name="acls">
         : for $acls -> $acl {
             <option value="<: $acl.aclname :>" <: $acl.selected :> ><: $acl.aclname :></option>
         : }

+ 3 - 0
www/templates/tags.tx

@@ -3,6 +3,9 @@ Tags:<br />
     : for $post.tags -> $tag {
         <option value="<: $tag :>" selected><: $tag :></option>
     : }
+    : for $post.extra_tags -> $tag {
+        <option value="<: $tag :>"><: $tag :></option>
+    : }
 </select>
 Add Custom Tag:<br />
 <input class="cooltext" type="text" id="<: $post.id :>-customtag" placeholder="MyTag" />