gitprep / templates / issues.html.ep /
9df2ba8 8 years ago
2 contributor
135 lines | 4.5kb
<%
  # API
  my $api = gitprep_api;

  # Parameters
  my $user_id = param('user');
  my $project_id = param('project');
  
  my $is = param('is') // '';
  
  my $open = $is eq 'closed' ? 0 : 1;
  
  # Git
  my $git = $self->app->git;
  
  # Project row id
  my $project_row_id = $api->get_project_row_id($user_id, $project_id);
  
  # Issues(which don't have pull request)
  my $issues = app->dbi->model('issue')->select(
    [
      {__MY__ => '*'},
      {open_user => ['id']},
    ],
    where => [
      ['and', ':issue.open{=}', 'pull_request = 0', ':project{=}'],
      {'issue.open' => $open, project => $project_row_id}
    ]
  )->all;
  
  # Open count
  my $open_count = $api->get_open_issue_count($user_id, $project_id);
  
  # Close count
  my $close_count = $api->get_close_issue_count($user_id, $project_id);
  
  # Initialize labels if there are no labels
  my $labels_count = app->dbi->model('label')->select(
    'count(*)',
    where => {project => $project_row_id}
  )->value;
  if ($labels_count == 0) {
    my @labels = (
      {id => 'bug', color => '#fc2929'},
      {id => 'duplicate', color => '#cccccc'},
      {id => 'enhancement', color => '#84b6eb'},
      {id => 'invalid', color => '#e6e6e6'},
      {id => 'question', color => '#cc317c'},
      {id => 'wontfix', color => '#ffffff'}
    );
    for my $label (@labels) {
      my $project_row_id = app->dbi->model('project')->select(
        'project.row_id',
        where => {'user.id' => $user_id, 'project.id' => $project_id}
      )->value;
      $label->{project} = $project_row_id;
      app->dbi->model('label')->insert($label);
    }
  }

  layout 'common', title => "Issues - $user_id/$project_id";
%>
  
  %= include '/include/header';
  
  <div class="container">
    <div class="issues-button-container">
      <div class="issues-button-container-left">
        <div class="issues-labels"><a href="<%= url_for("/$user_id/$project_id/labels") %>">Labels</a></div>
      </div>
      <div class="issues-button-container-right">
        % if ($api->logined) {
          <a href="<%= url_for("/$user_id/$project_id/issues/new") %>" class="btn btn-success">New issue</a>
        % }
      </div>
    </div>
    <div class="issues">
      <div class="issues-header">
        % if ($open) {
          <b><%= $open_count %> Open</b>
          <a href="<%= url_with->query([is => 'closed']) %>" style="margin-left:5px;color:#767676"><%= "\x{2714}" %><%= $close_count %> Closed</a>
        % } else {
          <a  style="margin-left:5px;color:#767676" href="<%= url_with->query([is => undef]) %>"><%= $open_count %> Open</a>
          <b>
            <span style="margin-left:5px;color:#767676"><%= "\x{2714}" %><%= $close_count %> Closed</span>
          </b>
        % }
      </div>
      <div class="issues-body">
        % if (@$issues) {
          <ul>
            % for my $issue (@$issues) {
              <%
                my $issue_labels = app->dbi->model('issue_label')->select(
                  {label => ['id', 'color']},
                  where => {issue => $issue->{row_id}}
                )->all;
              %>

              <%
                my $open_time = $issue->{open_time};
                my $open_time_age = Time::Moment->now->epoch - $open_time;
                my $open_time_age_string = $self->app->git->_age_string($open_time_age);
              %>
              <li>
                <div class="issues-title">
                  <a href="<%= url_for("/$user_id/$project_id/issues/$issue->{number}") %>">
                    <b><%= $issue->{title} %></b>
                  </a>
                  <ul class="issues-label-pallet">
                    % for my $issue_label (@$issue_labels) {
                      <li style="background:<%= $issue_label->{'label.color'} %>">
                        <%= $issue_label->{'label.id'} %>
                      </li>
                    % }
                  </ul>
                </div>
                <div class="issues-description">
                  #<%= $issue->{number} %> <%= $issue->{open} ? 'opened' : 'closed' %>
                  <%= $open_time_age_string %>
                  by <%= $issue->{'open_user.id'} %>
                </div>
              </li>
            % }
          </ul>
        % } else {
          <div class="issues-no-request">
            <div style="font-size:18px"><b>There aren’t any issues.</b></div>
          </div>
        % }
      </div>
    </div>
  </div>
  
  %= include '/include/footer';