Skip to content

Commit cd28f28

Browse files
committed
setup frontend
1 parent 0af5fe9 commit cd28f28

File tree

11 files changed

+126
-14
lines changed

11 files changed

+126
-14
lines changed

client/gulpfile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
var gulp = require('gulp');
4+
var sass = require('gulp-sass');
5+
6+
7+
gulp.task('sass:watch', function () {
8+
gulp.watch('./src/sass/**/*.scss', ['sass']);
9+
});

client/karma.conf.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = function (config) {
2+
config.set({
3+
basePath: '',
4+
files: [
5+
'static/lib.js',
6+
'node_modules/angular-mocks/angular-mocks.js',
7+
8+
'static/polls.js',
9+
'test/*.js',
10+
],
11+
12+
frameworks: ['jasmine'],
13+
14+
reporters: ['progress', 'mocha'],
15+
mochaReporter: {
16+
output: 'full'
17+
},
18+
19+
colors: true,
20+
21+
browsers: ['PhantomJS'],
22+
23+
singleRun: false,
24+
autoWatch: true
25+
});
26+
};

client/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "polls",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"dependencies": {},
6+
"devDependencies": {
7+
"browserify": "^13.0.1",
8+
"chai": "^3.5.0",
9+
"gulp": "^3.9.1",
10+
"gulp-sass": "^3.1.0",
11+
"gulp-util": "^3.0.7",
12+
"mocha": "^3.2.0",
13+
"vinyl-source-stream": "^1.1.0"
14+
},
15+
"scripts": {
16+
"test": "echo \"Error: no test specified\" && exit 1"
17+
},
18+
"author": "",
19+
"license": "ISC",
20+
"description": ""
21+
}

client/src/sass/polls.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.header {
2+
font-weight: bold;
3+
}
4+
5+
.table > .row:nth-child(even) {
6+
background: #f9f9f9;
7+
}

client/static/polls.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.header {
2+
font-weight: bold; }
3+
4+
.table > .row:nth-child(even) {
5+
background: #f9f9f9; }

client/static/app.js renamed to client/static/polls.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
var App = angular.module('App', []);
1+
var PollsApp = angular.module('PollsApp', []);
22

3-
App.config(function($interpolateProvider, $httpProvider) {
4-
$interpolateProvider.startSymbol('{[{');
5-
$interpolateProvider.endSymbol('}]}');
3+
PollsApp.config(function($interpolateProvider, $httpProvider) {
4+
$interpolateProvider.startSymbol('[{');
5+
$interpolateProvider.endSymbol('}]');
66
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
77
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
88
});
99

10-
App.controller('AppController', function ($scope, $http) {
10+
PollsApp.controller('PollsController', function ($scope, $http) {
1111
$scope.items = [];
1212

1313
$http({

client/test/polls.tests.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
describe('Polls tests', function () {
4+
var $scope, controller, $httpBackend;
5+
6+
beforeEach(function () {
7+
module('PollsApp');
8+
9+
inject(function ($controller, $rootScope, _$httpBackend_) {
10+
$scope = $rootScope.$new();
11+
$httpBackend = _$httpBackend_;
12+
13+
controller = $controller('PollsController', {
14+
$scope: $scope,
15+
});
16+
});
17+
});
18+
19+
it('Test items is empty by default', function () {
20+
expect($scope.items).toEqual([]);
21+
});
22+
23+
it('Test right number of items updated in scope', function () {
24+
expect($scope.items).toEqual([]);
25+
$httpBackend.expectGET('/polls/questions/').respond(200, '{"data":[1, 2, 3]}');
26+
$httpBackend.flush();
27+
expect($scope.items.data.length).toEqual(3);
28+
});
29+
});

polls/api_views.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
class QuestionSet(ViewSet):
1010
def list(self, request):
11-
with Timer() as t:
12-
questions = list_all_questions_with_total_votes()
11+
with Timer() as t:
12+
questions = list_all_questions_with_total_votes()
1313
serializer = QuestionSerializer(questions, many=True)
1414
res = {
15-
'data': serializer.data,
16-
'took': t.delta
17-
}
15+
'data': serializer.data,
16+
'took': t.delta
17+
}
1818
return Response(res)

polls/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
def list_all_questions_with_total_votes():
77
return Question.objects.all() \
8-
.filter(pub_date__lte=timezone.now()) \
8+
.filter(pub_date__lte=timezone.now()) \
99
.annotate(total_votes=Sum('choice__votes')) \
1010
.order_by('-total_votes', '-pub_date')

polls/templates/polls/index.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{% load staticfiles %}
22

33
<!DOCTYPE html>
4-
<html lang="en" ng-app="App">
4+
<html lang="en" ng-app="PollsApp">
55

66
<head>
77
<meta charset="UTF-8">
88
<title>Poll</title>
99

1010
<script src="{% static 'lib.js' %}"></script>
11-
<script src="{% static 'app.js' %}"></script>
11+
<script src="{% static 'polls.js' %}"></script>
1212

1313
<link rel="stylesheet" type="text/css" href="{% static 'lib.css' %}">
14-
<link rel="stylesheet" type="text/css" href="{% static 'ranking.css' %}">
14+
<link rel="stylesheet" type="text/css" href="{% static 'polls.css' %}">
1515
</head>
1616

1717
<body ng-controller="AppController">
@@ -41,7 +41,17 @@
4141
{% endif %}
4242

4343
</div>
44+
45+
</div>
46+
47+
<div class="row">
48+
<div class="col-sm-12">
49+
{% verbatim %}
50+
<pre> [{ items | json }] </pre>
51+
{% endverbatim %}
52+
</div>
4453
</div>
54+
4555
</div>
4656
</body>
4757

readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
## Test
88

99
coverage run --source=polls --omit='*/migrations/*' ./manage.py test && coverage report -m
10+
./node_modules/karma/bin/karma start karma.conf.js
1011

1112
## Run
1213

1314
./manage.py runserver
15+
16+
## Build frontend
17+
18+
gulp sass:watch

0 commit comments

Comments
 (0)