Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing holidays #12

Merged
merged 4 commits into from
Jun 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ angular
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
controller: 'MainCtrl',
resolve: {
holidays: ['Holidayservice', function (Holidayservice) {
return Holidayservice.getHolidays();
}]
}
})
.otherwise({
redirectTo: '/'
Expand Down
10 changes: 5 additions & 5 deletions app/scripts/controllers/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

angular.module('fridagarApp')
.controller('MainCtrl', function ($scope, Holidayservice) {
$scope.buttonValue = 'Yee boy';
Holidayservice.getHolidays().then(function (holidays) {
console.log(holidays);
});
.controller('MainCtrl', function ($scope, holidays) {
//
// scope variables
//
$scope.holidays = holidays.result;
});
41 changes: 24 additions & 17 deletions app/scripts/directives/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,30 @@ angular.module('fridagarApp')
.directive('calendar', function () {
return {
restrict: 'A',
link: function postLink(scope, element, attrs) {
console.log(attrs);
var template =
'<div class="clndr-grid"> \
<div class="days-of-the-week clearfix"> \
<% _.each(daysOfTheWeek, function(day) { %> \
<div class="header-day"><%= day %></div> \
<% }); %> \
<div class="days clearfix"> \
<% _.each(days, function(day) { %> \
<div class="<%= day.classes %>" id="<%= day.id %>"><span class="day-number"><%= day.day %></span></div> \
<% }); %> \
</div> \
</div> \
</div>';
$(element).clndr({
template: template
scope: {
events: '='
},
link: function postLink(scope, element) {
console.log(scope.events);
var _calendar,
_template =
'<div class="clndr-grid"> \
<div class="days-of-the-week clearfix"> \
<% _.each(daysOfTheWeek, function(day) { %> \
<div class="header-day"><%= day %></div> \
<% }); %> \
<div class="days clearfix"> \
<% _.each(days, function(day) { %> \
<div class="<%= day.classes %>" id="<%= day.id %>"><span class="day-number"><%= day.day %></span></div> \
<% }); %> \
</div> \
</div> \
</div>';
// finally, init the calendar
_calendar = $(element).clndr({
template: _template,
events: scope.events,
dateParameter: 'holidayDate'
});
}
};
Expand Down
5 changes: 2 additions & 3 deletions app/views/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<div class="row">
<div class="span12">
<div class="title-page">
<h2 class="title">Frídagar</h2>
<h3 class="title-description color-text">Hvenær er frí?</h3>
<h2 class="title">Frídagar.is <small class="title-description color-text">Hvenær er frí?</small></h2>
</div>
</div>
</div>
Expand All @@ -15,7 +14,7 @@ <h3 class="title-description color-text">Hvenær er frí?</h3>
<!-- Start BlockQuote/Tooltip Section -->
<div class="row">
<!-- Start CLNDR -->
<div class="cal clearfix" calendar></div>
<div class="cal clearfix" calendar events="holidays"></div>
<!-- End CLNDR -->
</div>
<!-- End BlockQuote/Tooltip Section -->
Expand Down
29 changes: 21 additions & 8 deletions test/spec/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,31 @@ describe('Controller: MainCtrl', function () {
// load the controller's module
beforeEach(module('fridagarApp'));

var MainCtrl,
scope;
var initController,
scope,
Holidayservice;

// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
beforeEach(inject(function ($controller, $rootScope, $injector) {
scope = $rootScope.$new();
MainCtrl = $controller('MainCtrl', {
$scope: scope
});
initController = function () {
return $controller('MainCtrl', {
$scope: scope,
holidays: { result: 1 }
});
};
Holidayservice = $injector.get('Holidayservice');
}));

it('should attach a list of awesomeThings to the scope', function () {
expect(scope.buttonValue).toBeDefined();
describe('Initialization', function () {
beforeEach(function () {
initController();
});
it('should have a \'holidays\' object', function () {
expect(scope.holidays).toBeDefined();
});
it('should take the value of the \'result\' object', function () {
expect(scope.holidays).toBe(1);
});
});
});