浏览代码

Work on #130: editing inline, yay

George S. Baugh 4 年之前
父节点
当前提交
c9a1b1b2d5

+ 22 - 5
data/DUMMY-dist.json

@@ -113,18 +113,35 @@
       "aclname" : "admin",
       "content_type" : "text/plain",
       "created" : 1604424769,
-      "data" : "Admin ACL",
+      "data" : "",
       "href" : "/config",
       "id" : "900",
       "local_href" : "/config",
       "preview" : "/img/sys/testpattern.jpg",
       "tags" : [
-         "series",
          "private",
          "admin"
       ],
-      "callback" : "Trog::Routes::HTML::series",
-      "title" : "Administrative Posts",
+      "callback" : "Trog::Routes::HTML::config",
+      "title" : "Configure tCMS",
+      "user" : "Nobody",
+      "version" : 0
+   },
+   {
+      "aclname" : "admin",
+      "content_type" : "text/plain",
+      "created" : 1604424769,
+      "data" : "",
+      "href" : "/config/save",
+      "id" : "901",
+      "local_href" : "/config/save",
+      "preview" : "/img/sys/testpattern.jpg",
+      "tags" : [
+         "private",
+         "admin"
+      ],
+      "callback" : "Trog::Routes::HTML::config_save",
+      "title" : "Configure tCMS",
       "user" : "Nobody",
       "version" : 0
    },
@@ -170,7 +187,7 @@
       "audio_href" : "",
       "content_type" : null,
       "created" : 1604424769,
-      "data" : "Here, cavemanzzzsdfgsdf",
+      "data" : "Here, cavemanzzzsdfgsdf <: embed(90211,'media') :>",
       "href" : "/",
       "id" : "665",
       "tags" : [

+ 0 - 3
lib/TCMS.pm

@@ -78,9 +78,6 @@ If a path passed is not a defined route (or regex route), but exists as a file u
 sub app {
     my $env = shift;
 
-    #use Data::Dumper;
-    #print Dumper($env);
-
     my $last_fetch = 0;
     if ($env->{HTTP_IF_MODIFIED_SINCE}) {
         $last_fetch = DateTime::Format::HTTP->parse_datetime($env->{HTTP_IF_MODIFIED_SINCE})->epoch();

+ 1 - 0
lib/Trog/DataModule.pm

@@ -156,6 +156,7 @@ sub filter ($self, $query, @filtered) {
     @filtered = grep { $_->{title} =~ m/\Q$query->{like}\E/i || $_->{data} =~ m/\Q$query->{like}\E/i } @filtered if $query->{like};
 
     @filtered = grep { $_->{user} eq $query->{author} } @filtered if $query->{author};
+
     return @filtered;
 }
 

+ 24 - 36
lib/Trog/Routes/HTML.pm

@@ -66,17 +66,6 @@ our %routes = (
         nostatic => 1,
         callback => \&Trog::Routes::HTML::login,
     },
-    '/post' => {
-        method   => 'GET',
-        auth     => 1,
-        callback => \&Trog::Routes::HTML::post,
-    },
-    '/post/(.*)' => {
-        method   => 'GET',
-        auth     => 1,
-        callback => \&Trog::Routes::HTML::post,
-        captures => ['id'],
-    },
     '/post/save' => {
         method   => 'POST',
         auth     => 1,
@@ -145,17 +134,6 @@ our %routes = (
         data     => { tag => ['about'] },
     },
 
-    #TODO make all these routes dynamic from data
-    '/config' => {
-        method   => 'GET',
-        auth     => 1,
-        callback => \&Trog::Routes::HTML::config,
-    },
-    '/config/save' => {
-        method   => 'POST',
-        auth     => 1,
-        callback => \&Trog::Routes::HTML::config_save,
-    },
     '/posts' => {
         method   => 'GET',
         callback => \&Trog::Routes::HTML::posts,
@@ -183,18 +161,10 @@ our %routes = (
     },
 );
 
+#XXX these need to be fetched dynamically from all the header categories?
+# Is used by the sitemap, maybe just fix there
 my @post_aliases = qw{news blog video images audio files series about};
 
-#TODO clean this up so we don't need _build_post_type
-@routes{map { "/post/$_" } qw{image video audio files}} = map { my %copy = %{$routes{'/post'}}; $copy{data}{tag} = [$_]; $copy{data}{type} = 'file'; \%copy } qw{image video audio files};
-$routes{'/post/news'}    = { method => 'GET', auth => 1, callback => \&Trog::Routes::HTML::post, data => { tag => ['news'],    type => 'microblog' } };
-$routes{'/post/blog'}    = { method => 'GET', auth => 1, callback => \&Trog::Routes::HTML::post, data => { tag => ['blog'],    type => 'blog'      } };
-$routes{'/post/about'}   = { method => 'GET', auth => 1, callback => \&Trog::Routes::HTML::post, data => { tag => ['about'],   type => 'profile'   } };
-$routes{'/post/series'}  = { method => 'GET', auth => 1, callback => \&Trog::Routes::HTML::post, data => { tag => ['series'],  type => 'series'    } };
-
-# Build aliases for /post/(.*) with extra data
-@routes{map { "/post/$_/(.*)" } @post_aliases} = map { my %copy = %{$routes{'/post/(.*)'}}; \%copy } @post_aliases;
-
 # Grab theme routes
 my $themed = 0;
 if ($theme_dir) {
@@ -711,7 +681,8 @@ Displays identified series, not all series.
 =cut
 
 sub series ($query, $render_cb) {
-    $query->{exclude_tags} = ['topbar'];
+    my $is_admin = grep { $_ eq 'admin' } @{$query->{acls}};
+    $query->{exclude_tags} = ['topbar'] unless $is_admin;
 
     #we are either viewed one of two ways, /series/$id or /$aclname
     my (undef,$aclname) = split(/\//,$query->{route});
@@ -790,8 +761,10 @@ sub posts ($query, $render_cb, $direct=0) {
     push(@$tags, $tag) if $tag && $tag ne 'posts';
     $query->{id} = $id if $id;
 
+    my $is_admin = grep { $_ eq 'admin' } @{$query->{acls}};
     push(@{$query->{acls}}, 'public');
     push(@{$query->{acls}}, 'unlisted') if $query->{id};
+    push(@{$query->{acls}}, 'private')  if $is_admin;
     my @posts;
 
     if ($query->{user_obj}) {
@@ -815,7 +788,9 @@ sub posts ($query, $render_cb, $direct=0) {
         unshift @posts, $user;
     }
 
-    return notfound($query, $render_cb) unless @posts;
+    if (!$is_admin) {
+        return notfound($query, $render_cb) unless @posts;
+    }
 
     my $fmt = $query->{format} || '';
     return _rss($query,\@posts) if $fmt eq 'rss';
@@ -885,7 +860,20 @@ sub posts ($query, $render_cb, $direct=0) {
         undef $footer;
     }
 
+    my %routemap;
+    @routemap{qw{/news /about /series /image /video /audio /files}} = qw{microblog profile series file file file file};
+    my $edittype =  $routemap{$query->{route}} // 'blog';
+
+    my $older = !@posts ? 0 : $posts[-1]->{created};
+    $query->{failed} = -1;
+    $query->{id} //= '';
+
     my $content = $processor->render('posts.tx', {
+        can_edit  => $is_admin,
+        edittype  => $edittype,
+        failure   => $query->{failed},
+        message   => $query->{failure} ? "Failed to add post!" : "Successfully added Post as $query->{id}",
+        direct    => !!$id,
         title     => $query->{title},
         style     => $query->{style},
         posts     => \@posts,
@@ -894,10 +882,10 @@ sub posts ($query, $render_cb, $direct=0) {
         route     => $query->{route},
         limit     => $limit,
         pages     => scalar(@posts) == $limit,
-        older     => $posts[-1]->{created},
+        older     => $older,
         sizes     => [25,50,100],
         rss       => !$query->{id} && !$query->{older},
-        tiled     => scalar(grep { $_ eq $query->{route} } qw{/files /audio /video /image /series /about}),
+        tiled     => !$is_admin && scalar(grep { $_ eq $query->{route} } qw{/files /audio /video /image /series /about}),
         category  => $ph,
         subhead   => $query->{subhead},
         header    => $header,

+ 1 - 1
www/templates/jsalert.tx

@@ -2,7 +2,7 @@
     document.addEventListener("DOMContentLoaded", function(event) {
         var loginFailure = <: $failure :>;
         if( loginFailure === -1 ) {
-            document.querySelector('#jsalert').style.cssText = 'visibility: hidden;';
+            document.querySelector('#jsalert').style.cssText = 'display:none;';
         } else if ( loginFailure === 1 ) {
             document.querySelector('#jsalert').classList.remove("alert-success");
             document.querySelector('#jsalert').classList.add("alert-danger");

+ 0 - 22
www/templates/mbengine.tx

@@ -1,22 +0,0 @@
-<div id="mbengine">
-    : if ( !$id ) {
-    <div id="submissions">
-        : include $edittype ~ ".tx";
-    </div>
-    : }
-    <div id="stories">
-        : include "posts.tx";
-    </div>
-</div>
-<script type="text/javascript" src="/scripts/fgEmojiPicker.js"></script>
-<script type="text/javascript">
-new FgEmojiPicker({
-    trigger: ['button.emojiPicker'],
-    position: ['bottom'],
-    dir: `/scripts/`,
-    emit(obj, triggerElement) {
-        const emoji = obj.emoji;
-        document.querySelector('textarea').value += emoji;
-    }
-});
-</script>

+ 0 - 3
www/templates/post.tx

@@ -1,3 +0,0 @@
-: include "sysbar.tx";
-: include "jsalert.tx";
-: include "mbengine.tx";

+ 23 - 1
www/templates/posts.tx

@@ -1,3 +1,25 @@
+: if ( $can_edit ) {
+    <script type="text/javascript" src="/scripts/post.js"></script>
+    : if (!$direct) {
+        : include "jsalert.tx";
+        <a style="cursor:pointer" onclick="switchMenu('submissions')">[Add Post]</a><hr />
+        <div id="submissions" style="display:none">
+          : include $edittype ~ ".tx";
+        </div>
+        <script type="text/javascript" src="/scripts/fgEmojiPicker.js"></script>
+        <script type="text/javascript">
+        new FgEmojiPicker({
+            trigger: ['button.emojiPicker'],
+            position: ['bottom'],
+            dir: `/scripts/`,
+            emit(obj, triggerElement) {
+                const emoji = obj.emoji;
+                document.querySelector('textarea').value += emoji;
+            }
+        });
+        </script>
+    : }
+: }
 <span class="title">
 : if ( $rss ) {
 <a title="RSS" class="rss" href="<: $route :>?format=rss"></a>
@@ -119,7 +141,7 @@
             : }
             : if ( $can_edit ) {
             <br />
-            <a style="display: inline-block;" onclick="switchMenu('<: $post.id :>-<: $post.version :>');">[Edit]</a>
+            <a style="display: inline-block;cursor:pointer;" onclick="switchMenu('<: $post.id :>-<: $post.version :>');">[Edit]</a>
             <div id="<: $post.id :>-<: $post.version :>" style="display:none;">
                 : include $post.type ~ ".tx" { post => $post };
                 <form class="Submissions" action="/post/delete" method="POST" class="inline">

+ 0 - 1
www/templates/sysbar.tx

@@ -4,7 +4,6 @@
         <a href="/"            title="Back home"     class="topbar">Home</a>
         <a href="/config"      title="Configuration" class="topbar">Settings</a>
         <a href="/manual"      title="Manual"        class="topbar">Manual</a>
-        : include "categories.tx";
         <a href="/logout"      title="Logout"        class="topbar">🚪</a>
     </span>
 </div>