Permalink
Browse files

Display active tickets

  • Loading branch information...
1 parent 6194d5c commit 56ed52993da4cf8521265684b2a5041a04377cc4 @vojtajina committed Sep 4, 2011
Showing with 33 additions and 8 deletions.
  1. +2 −1 app/index.html
  2. +7 −4 app/js/controllers.js
  3. +24 −3 test/unit/controllersSpec.js
View
@@ -29,7 +29,8 @@
<div id="menu">
<ul>
<li><a href="#!/intro" ng:class="activeCls('intro')">Intro</a></li>
- <li><a href="#!/tickets" ng:class="activeCls('tickets')">Tickets</a></li>
+ <li><a href="#!/tickets/active" ng:class="activeCls('tickets/active')">Tickets: Active</a>
+ <li><a href="#!/tickets/all" ng:class="activeCls('tickets/all')">Tickets: All</a></li>
<li><a href="#!/projects" ng:class="activeCls('projects')">Projects</a></li>
</ul>
View
@@ -15,7 +15,7 @@ function MainCtrl($route, $auth, $location, $status) {
$route.parent(scope);
$route.when('!/intro', {controller: IntroCtrl, template: 'partials/intro.html', title: 'Intro'});
- $route.when('!/tickets', {controller: TicketsCtrl, template: 'partials/tickets.html', title: 'Tickets'});
+ $route.when('!/tickets/:group', {controller: TicketsCtrl, template: 'partials/tickets.html', title: 'Tickets'});
$route.when('!/projects', {controller: ProjectsCtrl, template: 'partials/projects.html', title: 'Projects'});
$route.otherwise({redirectTo: '!/intro'});
@@ -56,12 +56,15 @@ MainCtrl.$inject = ['$route', '$auth', '$location', '$status'];
* @param {Object} $api API service
* @param {Object} $resource RESOURCE service
*/
-function TicketsCtrl($auth, $api, $resource) {
+function TicketsCtrl($auth, $api, $resource, $route) {
var self = this;
this.STATES = 'NEW ASSIGNED PENDING RESOLVED EXPLAIN CLOSED'.split(' ');
- $api('tickets', function(ticketsUrl) {
+ // TODO(vojta): support more ticket groups when implemented on server
+ var ticketsGroup = $route.current && $route.current.params.group == 'active'
+ ? 'active-tickets' : 'tickets';
+ $api(ticketsGroup, function(ticketsUrl) {
// TODO(vojta): remove temporary hack when implemented on service
// Content-Type should be application/vnd.helpdesk.ticket+json
self.tickets = $resource(ticketsUrl, 'application/json', {
@@ -131,7 +134,7 @@ TicketsCtrl.prototype = {
}
};
-TicketsCtrl.$inject = ['$auth', '$api', '$resource'];
+TicketsCtrl.$inject = ['$auth', '$api', '$resource', '$route'];
function RevisionFormCtrl() {
// TODO(vojta): set state and assignee to current value
@@ -1,3 +1,9 @@
+var API = {
+ tickets: '/all-tickets',
+ 'active-tickets': '/active-tickets',
+ users: '/users'
+};
+
describe('MainCtrl', function() {
var $auth, ctrl, scope;
@@ -60,9 +66,9 @@ describe('TicketsCtrl', function() {
revisions1 = ['/rev1', '/rev2'];
var xhr = scope.$service('$browser').xhr;
- xhr.expectGET(SERVICE_URL).respond({tickets: '/ticket-url', users: '/users'});
- xhr.expectGET('/ticket-url').respond({items: ['/url1', '/url2']});
- xhr.expectGET('/users').respond({items: []});
+ xhr.expectGET(SERVICE_URL).respond(API);
+ xhr.expectGET(API.tickets).respond({items: ['/url1', '/url2']});
+ xhr.expectGET(API.users).respond({items: []});
xhr.expectGET('/url1').respond(ticket1);
xhr.expectGET('/url2').respond(ticket2);
xhr.expectGET('/url-auth1').respond(author1);
@@ -116,6 +122,21 @@ describe('TicketsCtrl', function() {
expect(ticket.Revisions.items.length).toBe(0);
});
+ it('should load active tickets', function() {
+ scope = createScopeWithMockAuth();
+
+ var xhr = scope.$service('$browser').xhr;
+ scope.$service('$location').updateHash('/tickets/all');
+
+ xhr.expectGET(SERVICE_URL).respond(API);
+ xhr.expectGET(API['active-tickets']).respond({items: []});
+ xhr.expectGET(API.users).respond({items: []});
+
+ ctrl = scope.$new(MainCtrl).$new(TicketsCtrl);
+ xhr.flush();
+ console.log(scope.$service('$log').error.logs);
+ });
+
describe('createRevision', function() {
it('should set author and ticket url', function() {
var ticket = ctrl.tickets.items[0],

0 comments on commit 56ed529

Please sign in to comment.