OSDN Git Service

Archive: fix navigation to show only valid page (#7748, #7749)
authorhylom <hylom@users.osdn.me>
Wed, 5 Jun 2019 13:44:16 +0000 (13:44 +0000)
committerhylom <hylom@users.osdn.me>
Wed, 5 Jun 2019 13:44:16 +0000 (13:44 +0000)
src/newslash_web/lib/Newslash/Model/Comments.pm
src/newslash_web/lib/Newslash/Model/Cowrapper.pm
src/newslash_web/lib/Newslash/Model/Journals.pm
src/newslash_web/lib/Newslash/Model/Stories.pm
src/newslash_web/lib/Newslash/Model/Submissions.pm
src/newslash_web/lib/Newslash/Web/Controller/Archive.pm
src/newslash_web/templates/archive/index_header.html.tt2

index fcc6f24..18e21ed 100644 (file)
@@ -10,8 +10,19 @@ use Encode;
 
 sub count {
     my $self = shift;
+    my $params = {@_};
+
     my $join = 'LEFT JOIN firehose ON (comments.cid = firehose.srcid AND firehose.type = "comment")';
-    my $where = 'firehose.public != "no"';
+
+    my @clauses;
+    if ($params->{hide_future}) {
+       push @clauses,  'comments.ts < NOW()';
+    }
+    if ($params->{public_only}) {
+       push @clauses, 'firehose.public != "no"';
+    }
+    my $where = join " AND ", @clauses;
+
     return $self->generic_count(table => "comments",
                                 target => "cid",
                                 timestamp => "date",
index 9b39689..f5f0591 100644 (file)
@@ -1067,10 +1067,11 @@ sub generic_count {
     my $sql;
     my $where_clause = "";
     if ($params->{where}) {
-        $where_clause = "$params->{where} AND ";
+        $where_clause = "$params->{where} AND \n";
     }
     my $join_clause = $params->{join} || "";
 
+
     my @attrs;
     if ($term eq "day") {
         # `stories` table not contain display/non-display flag,
index 56f9a78..5223a38 100644 (file)
@@ -69,8 +69,18 @@ sub on_start_up {
 
 sub count {
     my $self = shift;
+    my $params = {@_};
     my $join = 'LEFT JOIN firehose ON (journals.id = firehose.srcid AND firehose.type = "journal")';
-    my $where = 'firehose.public != "no"';
+
+    my @clauses;
+    if ($params->{hide_future}) {
+       push @clauses,  'journals.date < NOW()';
+    }
+    if ($params->{public_only}) {
+       push @clauses, 'firehose.public != "no"';
+    }
+    my $where = join " AND ", @clauses;
+
     return $self->generic_count(table => "journals",
                                 target => "id",
                                 timestamp => "date",
index 1dbd836..acff2e1 100644 (file)
@@ -62,9 +62,20 @@ EOSQL
 
 sub count {
     my $self = shift;
+    my $params = {@_};
+
     my $join = 'LEFT JOIN firehose ON (stories.stoid = firehose.srcid AND firehose.type = "story")';
-    my $where = 'firehose.public != "no"';
-    return $self->generic_count(table => "stories",
+
+    my @clauses;
+    if ($params->{hide_future}) {
+       push @clauses,  'stories.time < NOW()';
+    }
+    if ($params->{public_only}) {
+       push @clauses, 'firehose.public != "no"';
+    }
+    my $where = join " AND ", @clauses;
+
+      return $self->generic_count(table => "stories",
                                 target => "stoid",
                                 timestamp => "time",
                                 join => $join,
index 19aefce..d16900c 100644 (file)
@@ -16,8 +16,18 @@ use constant FACULTIES => { 1000 => [qw(ipid subnetid note comment)] };
 
 sub count {
     my $self = shift;
+    my $params = {@_};
     my $join = 'LEFT JOIN firehose ON (submissions.subid = firehose.srcid AND firehose.type = "submission")';
-    my $where = 'firehose.public != "no"';
+
+    my @clauses;
+    if ($params->{hide_future}) {
+       push @clauses,  'submission.time < NOW()';
+    }
+    if ($params->{public_only}) {
+       push @clauses, 'firehose.public != "no"';
+    }
+    my $where = join " AND ", @clauses;
+
     return $self->generic_count(table => "submissions",
                                 target => "subid",
                                 timestamp => "time",
index f609c93..14962b1 100644 (file)
@@ -138,6 +138,59 @@ sub _render_archive {
         $next = Newslash::Util::Items->get_date_string_from_item($next_items->[0], $offset_sec, $unit);
     }
 
+
+    # get prev month
+    $dt = DateTime->new(year => $year,
+                       month => $month,
+                       day => 1);
+    my ($prev_month, $prev_month_date);
+    $dt->add(days => -1);
+    $prev_items = $model->select(until => $dt,
+                                offset_sec => $offset_sec,
+                                order_by => {create_time => "DESC"},
+                                hide_future => $user->{author} ? 0 : 1,
+                                public_only => $user->{author} ? 0 : 1,
+                                limit => 1
+                               );
+    if ($prev_items && @$prev_items) {
+       $dt = $c->format_timestamp(mysql => $prev_items->[0]->{create_time},
+                                  format => "datetime",
+                                  offset_sec => 0,
+                                 );
+       $dt->set(day => 1, hour => 0, minute => 0, second => 0);
+       $prev_items = $model->select(since => $dt,
+                                    offset_sec => $offset_sec,
+                                    order_by => {create_time => "ASC"},
+                                    hide_future => $user->{author} ? 0 : 1,
+                                    public_only => $user->{author} ? 0 : 1,
+                                    limit => 1
+                                   );
+       if ($prev_items && @$prev_items) {
+           $prev_month_date = Newslash::Util::Items->get_date_string_from_item($prev_items->[0], $offset_sec, "day");
+           $prev_month_date =~ m/^\d+\/0?(\d+)/;
+           $prev_month = $1;
+       }
+    }
+
+    # get next month
+    $dt = DateTime->new(year => $year,
+                       month => $month,
+                       day => 1);
+    my ($next_month, $next_month_date);
+    $dt->add(months => 1);
+    $next_items = $model->select(since => $dt,
+                                offset_sec => $offset_sec,
+                                order_by => {create_time => "ASC"},
+                                hide_future => $user->{author} ? 0 : 1,
+                                public_only => $user->{author} ? 0 : 1,
+                                limit => 1
+                               );
+    if ($next_items && @$next_items) {
+       $next_month_date = Newslash::Util::Items->get_date_string_from_item($next_items->[0], $offset_sec, "day");
+       $next_month_date =~ m/^\d+\/0?(\d+)/;
+       $next_month = $1;
+    }
+
     my $page = { content_type => $type,
                  type => "archive",
                  year => $year,
@@ -151,6 +204,10 @@ sub _render_archive {
                page => $page,
                prev => $prev,
                next => $next,
+              prev_month => $prev_month,
+              next_month => $next_month,
+              prev_month_date => $prev_month_date,
+              next_month_date => $next_month_date,
               );
 
     if (@$items == 0) {
index 2e1e070..8bb4dc9 100644 (file)
@@ -26,26 +26,25 @@ IF n_mm < 10; n_mm = "0" _ n_mm; END;
     [%- IF ctype == "poll" -%]
     <div class="prev">
       <a href="/[% ctype %]/[% p_yy %]/[% p_mm %]/">
-        [% p_mm + 0 %]月
+       前
       </a>
     </div>
     <div class="next">
       <a href="/[% ctype %]/[% n_yy %]/[% n_mm %]/">
-        [% n_mm + 0 %]月
+        次
       </a>
     </div>
     <div class="current">[% yyyy %]年[% m %]月</div>
-  </div>
-  [%- ELSE -%]
+    [%- ELSE -%]
     <div class="prev">
-      <a href="/[% ctype %]/[% p_yy %]/[% p_mm %]/01/">
-        [% p_mm + 0 %]月
-      </a>
+      [% IF prev_month %]
+      <a href="/[% ctype %]/[% prev_month_date %]">[% prev_month %]月</a>
+      [% END %]
     </div>
     <div class="next">
-      <a href="/[% ctype %]/[% n_yy %]/[% n_mm %]/01/">
-        [% n_mm + 0 %]月
-      </a>
+      [% IF next_month %]
+      <a href="/[% ctype %]/[% next_month_date %]">[% next_month %]月</a>
+      [% END %]
     </div>
     <div class="current">[% yyyy %]年[% m %]月[% d %]日</div>
   </div>