Skip to content

Commit

Permalink
Add filter "assigned to sbd"
Browse files Browse the repository at this point in the history
  • Loading branch information
piero-la-lune committed Mar 5, 2013
1 parent c886073 commit d5a29d4
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 72 deletions.
3 changes: 2 additions & 1 deletion classes/Issues.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function html_list($a) {
Text::ago($issue['date'])
), Trad::S_ISSUE_CREATED);
$color = $config['statuses'][$issue['status']]['color'];
$class = ($issue['open']) ? 'a-summary' : 'a-summary closed';
$html .= '<div class="div-preview-issue">'
.'<div class="table">'
.'<div class="cell-left">'
Expand All @@ -104,7 +105,7 @@ public function html_list($a) {
.'</a>'
.'</div>'
.'<div class="cell-right">'
.'<a class="a-summary" href="'.$url.'">'
.'<a class="'.$class.'" href="'.$url.'">'
.htmlspecialchars($issue['summary'])
.'</a>'
.'<span class="grey">'
Expand Down
19 changes: 19 additions & 0 deletions classes/OrderFilter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ public static function filter_label($a) {
}
return true;
}

public static function filter_user($a) {
if (in_array($a['openedby'], self::$filter)) { return true; }
foreach ($a['edits'] as $e) {
if (!empty($e) && in_array($e['by'], self::$filter)) {
return true;
}
}
return false;
}

public static function filter_status($a) {
foreach (self::$filter as $k => $v) {
if ($a['status'] != $k || $a['assignedto'] != $v) {
return false;
}
}
return true;
}
}

?>
2 changes: 1 addition & 1 deletion classes/Text.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public static function options($arr, $sel) {
if (preg_match('/%([a-z]+)%/', $v, $matches)) {
$data = ' data-match="'.$matches[1].'"';
}
$v = preg_replace('/%[a-z]+%/', '', $v);
$v = preg_replace('/%[a-z]+%/', Trad::W_SUSPENSION, $v);
$ret .= '<option value="'.$k.'"'.$data;
if ($k == $sel) { $ret .= ' selected'; }
$ret .= '>'.$v.'</option>';
Expand Down
4 changes: 4 additions & 0 deletions languages/Trad_en.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class Trad {
const S_NOTFOUND = 'The page you\'re looking for does not exist anymore...';
const S_FORBIDDEN = 'You are not allowed to access this page. Please log in/out to continue.';

const S_VIEW_PARTICIPATION = 'View his participation.';
const S_VIEW_STATUS = 'View issues “%status%”.';

const S_ISSUE_CREATED = 'by %user% %time%';
const S_ISSUE_UPDATED = '%adj% by %user% %time%.';
const S_ISSUE_STATUS_UPDATED = 'Status updated to %status% by %user% %time%.';
Expand Down Expand Up @@ -246,6 +249,7 @@ class Trad {
const F_FILTER_STATUSES = 'Filter statuses:';
const F_FILTER_STATES = 'Filter states:';
const F_FILTER_LABELS = 'Filter labels:';
const F_FILTER_USERS = 'Filter users:';

const F_WRITE = 'Write:';
const F_SUMMARY = 'Summary';
Expand Down
4 changes: 4 additions & 0 deletions languages/Trad_fr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class Trad {
const S_NOTFOUND = 'La page que vous recherchez n\'existe pas...';
const S_FORBIDDEN = 'Vous n\'êtes pas autorisé à accèder à cette page. Merci de vous connecter pour continuer.';

const S_VIEW_PARTICIPATION = 'Voir ses participations';
const S_VIEW_STATUS = 'Voir les demandes « %status% ».';

const S_ISSUE_CREATED = 'par %user% %time%';
const S_ISSUE_UPDATED = '%adj% par %user% %time%.';
const S_ISSUE_STATUS_UPDATED = 'Statut changé à %status% par %user% %time%.';
Expand Down Expand Up @@ -246,6 +249,7 @@ class Trad {
const F_FILTER_STATUSES = 'Filtrer les statuts :';
const F_FILTER_STATES = 'Filtrer les états :';
const F_FILTER_LABELS = 'Filtrer les labels :';
const F_FILTER_USERS = 'Filtrer les utilisateurs :';

const F_WRITE = 'Écrire :';
const F_SUMMARY = 'Résumé';
Expand Down
162 changes: 107 additions & 55 deletions pages/issues.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
if (isset($_GET['label'])) {
$url = new Url(getProject().'/labels/'.$_GET['label']);
}
if (isset($_POST['user'])) {
$url->addParam('user', $_POST['user']);
}
if (isset($_POST['status'])) {
$url->addParam('status', $_POST['status']);
}
if (isset($_POST['sort'])) {
$url->addParam('sort', $_POST['sort']);
}
Expand All @@ -29,85 +35,108 @@

$a = $issues->getAll();

$sortOrFilter = false;
$error404 = false;
$url = new Url(getProject().'/issues');

$label = NULL;
if (isset($_GET['label'])) {
if (!isset($config['labels'][$_GET['label']])) {
$error404 = true;
}
else {
if (isset($config['labels'][$_GET['label']])) {
OrderFilter::$filter = array($_GET['label']);
$a = array_filter($a, array('OrderFilter', 'filter_label'));
if (!isset($_GET['open'])) { $_GET['open'] = "all"; }
$url = new Url(getProject().'/labels/'.$_GET['label']);
$label = $config['labels'][$_GET['label']];
}
else {
$error404 = true;
}
}

$user = NULL;
if (isset($_GET['user'])) {
$id = intval($_GET['user']);
if (isset($config['users'][$id])) {
OrderFilter::$filter = array($id);
$a = array_filter($a, array('OrderFilter', 'filter_user'));
$url->addParam('user', $id);
$user = $config['users'][$id];
}
else {
$error404 = true;
}
}

$status = NULL;
if (isset($_GET['status'])) {
$p = explode(',', $_GET['status']);
if (count($p) == 2
&& isset($config['statuses'][$p[0]])
&& isset($config['users'][$p[1]])
) {
OrderFilter::$filter = array($p[0] => $p[1]);
$a = array_filter($a, array('OrderFilter', 'filter_status'));
$url->addParam('status', implode(',', $p));
$status = array($p[0] => $p[1]);
}
else {
$error404 = true;
}
}

$open = 'open';
if (isset($_GET['open'])) {
if ($_GET['open'] == 'closed') {
$filter_open = array(false);
OrderFilter::$filter = array(false);
$a = array_filter($a, array('OrderFilter', 'filter_open'));
$url->addParam('open', 'closed');
$open = 'closed';
}
else if ($_GET['open'] == 'open') {
$filter_open = array(true);
elseif ($_GET['open'] == 'open') {
OrderFilter::$filter = array(true);
$a = array_filter($a, array('OrderFilter', 'filter_open'));
$url->addParam('open', 'open');
$open = 'open';
}
else {
$filter_open = array();
$url->addParam('open', 'all');
$open = 'all';
}
$sortOrFilter = true;
}
else {
$filter_open = array(true);
OrderFilter::$filter = array(true);
$a = array_filter($a, array('OrderFilter', 'filter_open'));
}
if (isset($_GET['statuses'])) {
$statuses = explode(",", $_GET['statuses']);
$filter_statuses = array();
foreach ($statuses as $s) {

$statuses = array_keys($config['statuses']);
if (isset($_GET['statuses']) && !empty($_GET['statuses'])) {
$statuses = array();
$st = explode(",", $_GET['statuses']);
foreach ($st as $s) {
if (isset($config['statuses'][$s])) {
$filter_statuses[] = $s;
$statuses[] = $s;
}
}
OrderFilter::$filter = $filter_statuses;
OrderFilter::$filter = $statuses;
$a = array_filter($a, array('OrderFilter', 'filter_statuses'));
$sortOrFilter = true;
}
else {
$filter_statuses = array_keys($config['statuses']);
$url->addParam('statuses', implode(',', $statuses));
}

$sort = array(0 => 'id', 1 => 'desc');
if (isset($_GET['sort'])
&& method_exists('OrderFilter', 'order_'.$_GET['sort'])
) {
$sort = $_GET['sort'];
$sortOrFilter = true;
}
else {
$sort = 'id_desc';
$url->addParam('sort', $_GET['sort']);
$sort = explode('_', $_GET['sort']);
}
uasort($a, array('OrderFilter', 'order_'.$sort));
$arr_sort = explode('_', $sort);
uasort($a, array('OrderFilter', 'order_'.implode('_', $sort)));

if ($sortOrFilter) {
if (in_array(true, $filter_open)) { $open = 'open'; }
else if (in_array(false, $filter_open)) { $open = 'closed'; }
else { $open = 'all'; }
$url->addParam('sort', $sort);
$url->addParam('statuses', implode(',', $filter_statuses));
$url->addParam('open', $open);
}
$pager = new Pager();
$perpage = $config['issues_per_page'];
if (isset($_GET['perpage'])) {
$perpage = intval($_GET['perpage']);
if ($perpage <= 1) { $perpage = $config['issues_per_page']; }
$url->addParam('perpage', $perpage);
}
else {
$perpage = $config['issues_per_page'];
}

$pager = new Pager();
$html = $pager->get(
$a,
$url,
Expand Down Expand Up @@ -141,10 +170,10 @@
<div class="div-table-issues">
<div class="div-issues">'.$html.'</div>';

$open_selected = (empty($filter_open) || in_array(true, $filter_open)) ?
$open_selected = ($open != 'closed') ?
'btn-open selected':
'btn-open unselected';
$closed_selected = (empty($filter_open) || in_array(false, $filter_open)) ?
$closed_selected = ($open != 'open') ?
'btn-closed selected':
'btn-closed unselected';

Expand All @@ -153,8 +182,7 @@
.'<div class="box box-sort-filter">'
.'<div class="inner-form">'
.'<form action="'.$url->getBase().'" method="post">';
if (isset($_GET['label'])) {
$label = $config['labels'][$_GET['label']];
if ($label) {
$content .= '<p>'
.Trad::F_FILTER_LABELS
.'<a href="javascript:;" class="label" style="'
Expand All @@ -163,6 +191,15 @@
.'</a>'
.'</p>';
}
if ($user) {
$content .= '<p>'
.Trad::F_FILTER_USERS
.'&nbsp;<a href="javascript:;">'
.htmlspecialchars($user['username'])
.'</a>'
.'</p>'
.'<input type="hidden" name="user" value="'.$user['id'].'" />';
}
$content .= '<p>'
.Trad::F_FILTER_STATES
.'<a href="javascript:;" class="'.$open_selected.'">'
Expand All @@ -173,14 +210,29 @@
.'</p>'
.'<p>'
.Trad::F_FILTER_STATUSES;
foreach ($config['statuses'] as $k => $v) {
$selected = (in_array($k, $filter_statuses)) ?
'btn-status selected':
'btn-status unselected';
$content .= '<a href="javascript:;" class="'.$selected.'" style="'
.'background-color:'.$v['color'].'" data-id="'.$k.'" >'
.Text::status($k, NULL, false, false)
.'</a>';
if ($status) {
$val = array();
foreach ($status as $k => $v) {
$s = $config['statuses'][$k];
$content .= '<a href="javascript:;" class="btn-status disabled" style="'
.'background-color:'.$s['color'].'" data-id="'.$k.'" >'
.Text::status($k, $v, false)
.'</a>';
$val[] = $k.','.$v;
}
$content .= '<input type="hidden" name="status" value="'
.implode(',', $val).'" />';
}
else {
foreach ($config['statuses'] as $k => $v) {
$selected = (in_array($k, $statuses)) ?
'btn-status selected':
'btn-status unselected';
$content .= '<a href="javascript:;" class="'.$selected.'" style="'
.'background-color:'.$v['color'].'" data-id="'.$k.'" >'
.Text::status($k, NULL, false, false)
.'</a>';
}
}
$content .= '</p>'
.'<p>'
Expand All @@ -189,13 +241,13 @@
.Text::options(array(
'id' => Trad::F_SORT_ID,
'mod' => Trad::F_SORT_MOD
), $arr_sort[0])
), $sort[0])
.'</select>'
.'<select>'
.Text::options(array(
'desc' => Trad::F_SORT_DESC,
'asc' => Trad::F_SORT_ASC
), $arr_sort[1])
), $sort[1])
.'</select>'
.'</p>'
.'<p>'
Expand Down
2 changes: 1 addition & 1 deletion pages/new_issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
.'placeholder="'.Trad::F_CONTENT.'" required>'
.$form_t
.'</textarea>'
.'<div class="preview"></div>'
.'<div class="preview" style="display:none"></div>'
.$should_login
.'<div class="form-actions">'
.'<button type="button" class="btn btn-preview">'
Expand Down
Loading

0 comments on commit d5a29d4

Please sign in to comment.