Permalink
Browse files

Give different categories different colors, depending on the category…

… title.
  • Loading branch information...
1 parent 89de779 commit 4e02399f3d2a790b50320557d8976e74d8c19c42 @breyten breyten committed Aug 4, 2011
Showing with 48 additions and 12 deletions.
  1. +5 −0 api.php
  2. +9 −9 codebasehq.inc.php
  3. +14 −1 css/screen.css
  4. +20 −2 js/kanban.js
View
5 api.php
@@ -7,6 +7,11 @@
$what = $_GET['f'];
+if ($what == 'categories') {
+ $categories = $cb->get_categories($codebaseMainProject);
+ echo json_encode($categories);
+}
+
if ($what == 'milestones') {
$milestones = $cb->get_milestones($codebaseMainProject);
echo json_encode($milestones);
View
18 codebasehq.inc.php
@@ -12,10 +12,10 @@ function base_url() {
return 'http://api3.codebasehq.com';
}
- function _get_request($full_path) {
+ function _get_request($full_path, $timeout = 300) {
$url = $this->base_url() . $full_path;
$cache_file = $this->cache_dir .'/'. sha1($url);
- if (!file_exists($cache_file) || ((time() - @filemtime($cache_file)) > 300)) {
+ if (!file_exists($cache_file) || ((time() - @filemtime($cache_file)) > $timeout)) {
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', 'Accept: application/xml'));
curl_setopt($process, CURLOPT_HEADER, 0);
@@ -39,29 +39,29 @@ function _parse_request($content) {
return simplexml_load_string($content);
}
- function _perform_request($full_path) {
- $content = $this->_get_request($full_path);
+ function _perform_request($full_path, $timeout = 300) {
+ $content = $this->_get_request($full_path, $timeout);
return $this->_parse_request($this->_get_request($full_path));
}
function get_statuses($project) {
- return $this->_perform_request(sprintf('/%s/tickets/statuses', $project));
+ return $this->_perform_request(sprintf('/%s/tickets/statuses', $project), 86400);
}
function get_priorities($project) {
- return $this->_perform_request(sprintf('/%s/tickets/priorities', $project));
+ return $this->_perform_request(sprintf('/%s/tickets/priorities', $project), 86400);
}
function get_categories($project) {
- return $this->_perform_request(sprintf('/%s/tickets/categories', $project));
+ return $this->_perform_request(sprintf('/%s/tickets/categories', $project), 86400);
}
function get_milestones($project) {
- return $this->_perform_request(sprintf('/%s/milestones', $project));
+ return $this->_perform_request(sprintf('/%s/milestones', $project), 86400);
}
function get_users($project) {
- return $this->_perform_request(sprintf('/%s/assignments', $project));
+ return $this->_perform_request(sprintf('/%s/assignments', $project), 86400);
}
function search_tickets($project, $query, $page = 1) {
View
15 css/screen.css
@@ -74,7 +74,7 @@ a:hover {
/* tickets */
.ticket {
- background-color: #FBF08F;
+ background-color: #FBF08F;
height: 90px;
margin: 0.625em auto;
width: 100%;
@@ -83,6 +83,19 @@ a:hover {
overflow: hidden;
}
+/* start custom ticket colors */
+.ticket-default {
+}
+
+.ticket-admin {
+ background-color: pink;
+}
+
+.ticket-other {
+ background-color: #BDB76B;
+}
+/* end custom ticket colors */
+
#closed .status .ticket {
float: left;
margin-right: 1em;
View
22 js/kanban.js
@@ -1,5 +1,6 @@
var statuses;
var milestones;
+var categories = {};
var priorities = {};
var users = {};
var activeMilestones;
@@ -71,14 +72,23 @@ function calcTimeAgo(date) {
}
function addTicket(ticket) {
+ var ticketTypeClass = 'ticket-default';
+ var ticketCategory = categories[ticket['category-id']];
var ticketPriority = priorities[ticket['priority-id']];
var ticketId = 'ticket-' + ticket['ticket-id'];
var gravatarHash = (users[ticket['assignee-id']] !== undefined) ? users[ticket['assignee-id']].hash : '';
var userName = (users[ticket['assignee-id']] !== undefined) ? users[ticket['assignee-id']]['first-name'] + ' ' + users[ticket['assignee-id']]['last-name'] : '';
var ticketSummary = (ticket.summary.length > 50) ? ticket.summary.substr(0, 50) + '...' : ticket.summary;
var timeAgo = calcTimeAgo(parseDate(ticket['updated-at']));
- $('#status-' + ticket['status-id']).append($('<div />').attr('id', ticketId).attr('class', 'ticket').attr('style', 'border-top: 2px solid ' + ticketPriority.colour + ';'));
+ // change color for other repo's
+ matches = ticketCategory.match(/^\s*(\w+)\s*[\-|\/]/);
+ console.dir(matches);
+ if (matches) {
+ ticketTypeClass = 'ticket-' + matches[1].toLowerCase();
+ }
+
+ $('#status-' + ticket['status-id']).append($('<div />').attr('id', ticketId).attr('class', 'ticket ' + ticketTypeClass).attr('style', 'border-top: 2px solid ' + ticketPriority.colour + ';'));
$('#' + ticketId).append($('<h3 />').attr('title', ticket.summary).text(ticketSummary));
$('#' + ticketId).append($('<abbr class="age" title="updated '+timeAgo['long']+' ago">'+timeAgo['short']+'</abbr>'));
$('#' + ticketId).append($('<a href="https://eduhub.codebasehq.com/projects/www/tickets/' + ticket['ticket-id'] + '" target="_blank" />').attr('class', 'ticket-link').text('#' + ticket['ticket-id']));
@@ -128,7 +138,15 @@ $(document).ready(function() {
priorities[priority.id] = priority;
});
- loadTickets(1);
+ $.get('/api.php?f=categories', function (data) {
+ rawCategories = data['ticketing-category'];
+
+ $.each(rawCategories, function (i, category) {
+ categories[category.id] = category.name;
+ });
+
+ loadTickets(1);
+ }, 'json');
}, 'json');
}, 'json');
}, 'json');

0 comments on commit 4e02399

Please sign in to comment.