Skip to content

Commit

Permalink
Merge pull request #4 from OZ-United/canary
Browse files Browse the repository at this point in the history
0.1.0-beta
  • Loading branch information
janantala committed Sep 15, 2013
2 parents efaf2a9 + fee74b4 commit ec87325
Show file tree
Hide file tree
Showing 21 changed files with 407 additions and 28 deletions.
1 change: 1 addition & 0 deletions admin/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<script src="scripts/controllers/books/bookId.js"></script>
<script src="scripts/controllers/users/userId.js"></script>
<script src="scripts/controllers/rents/rentId.js"></script>
<script src="scripts/directives/infiniteScroll.js"></script>
<!-- endbuild -->
</body>
</html>
29 changes: 27 additions & 2 deletions admin/app/scripts/controllers/books.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

angular.module('adminApp')
.controller('BooksCtrl', function ($scope, Books) {
.controller('BooksCtrl', function ($scope, Books, $routeParams) {

$scope.book = {};
$scope.books = Books.query();
$scope.books = [];

$scope.addBook = function(){
if ($scope.addBookForm.$valid) {
Expand All @@ -29,4 +29,29 @@ angular.module('adminApp')
$scope.close = function () {
$scope.newBook = false;
};

$scope.query = function(){
if (!$scope.mayQuery) {
return false;
}

var query = {page: $scope.page + 1};
query = angular.extend(query, $routeParams);
console.log(query);
Books.query(query,
function(books){
if (!books.length) {
$scope.mayQuery = false;
}
$scope.books = $scope.books.concat(books);
$scope.page += 1;
},
function(error){

});
};

$scope.page = 0;
$scope.mayQuery = true;
$scope.query();
});
3 changes: 2 additions & 1 deletion admin/app/scripts/controllers/books/bookId.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ angular.module('adminApp')
$scope.book = book;
$scope.closeEdit();
});

};

$scope.minDate = new Date().setDate(new Date().getDate() + 1);
});
27 changes: 26 additions & 1 deletion admin/app/scripts/controllers/rents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

angular.module('adminApp')
.controller('RentsCtrl', function ($scope, Rents, $location, $routeParams) {
$scope.rents = Rents.query($routeParams);
$scope.rents = [];

$scope.returnBook = function(rent){
Rents.returnBook({'rentId': rent.rentId}, function(res){
Expand All @@ -17,4 +17,29 @@ angular.module('adminApp')
return 'warning';
}
};

$scope.query = function(){
if (!$scope.mayQuery) {
return false;
}

var query = {page: $scope.page + 1};
query = angular.extend(query, $routeParams);
console.log(query);
Rents.query(query,
function(rents){
if (!rents.length) {
$scope.mayQuery = false;
}
$scope.rents = $scope.rents.concat(rents);
$scope.page += 1;
},
function(error){

});
};

$scope.page = 0;
$scope.mayQuery = true;
$scope.query();
});
29 changes: 27 additions & 2 deletions admin/app/scripts/controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

angular.module('adminApp')
.controller('UsersCtrl', function ($scope, Users) {
$scope.users = Users.query();
.controller('UsersCtrl', function ($scope, Users, $routeParams) {
$scope.users = [];

$scope.addUser = function(){
if ($scope.addUserForm.$valid) {
Expand All @@ -21,4 +21,29 @@ angular.module('adminApp')
$scope.close = function() {
$scope.newUser = false;
};

$scope.query = function(){
if (!$scope.mayQuery) {
return false;
}

var query = {page: $scope.page + 1};
query = angular.extend(query, $routeParams);
console.log(query);
Users.query(query,
function(users){
if (!users.length) {
$scope.mayQuery = false;
}
$scope.users = $scope.users.concat(users);
$scope.page += 1;
},
function(error){

});
};

$scope.page = 0;
$scope.mayQuery = true;
$scope.query();
});
19 changes: 19 additions & 0 deletions admin/app/scripts/directives/infiniteScroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

angular.module('adminApp')
.directive('infinitescroll', [ '$window', function ($window) {
return {
link: function (scope, element, attrs) {
var offset = parseInt(attrs.threshold) || 0;
var e = element[0];

window.onscroll = function () {
console.log(scope.$eval(attrs.canload), e.scrollTop + e.offsetHeight, e.scrollHeight - offset, e.scrollTop + e.offsetHeight >= e.scrollHeight - offset);
if (scope.$eval(attrs.canload) && e.scrollTop + e.offsetHeight >= e.scrollHeight - offset) {
console.log('eval');
scope.$apply(attrs.infinitescroll);
}
};
}
};
}]);
4 changes: 3 additions & 1 deletion admin/app/views/books.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ <h4 style="text-align: center;margin: 50px auto;">Zoznam kníh</h4>
</tr>
</tbody>
</table>

<button class="btn btn-block" ng-click="query()" ng-show="mayQuery">Ďalšie</button>
</section>

<button class="btn" ng-click="open()">Nová kniha</button>
Expand Down Expand Up @@ -92,7 +94,7 @@ <h3>Nová kniha</h3>

<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-success">Pridať</button>
<button type="submit" class="btn btn-success hide">Pridať</button>
</div>
</div>
</form>
Expand Down
10 changes: 6 additions & 4 deletions admin/app/views/books/bookId.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,22 @@ <h3>Požičať knihu</h3>
<div class="control-group">
<label class="control-label" for="inputEndDate">Do kedy</label>
<div class="controls">
<input type="date" ng-model="rentCopy.endDate" id="inputEndDate" class="input-field" required placeholder="YYYY-MM-DD">
<div ng-model="rentCopy.endDate" >
<datepicker min="minDate" show-weeks="false" starting-day="1" id="inputEndDate" ng-required="true"></datepicker>
</div>
</div>
</div>

<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-success">Požičať</button>
<button type="submit" class="btn btn-success hide">Požičať</button>
</div>
</div>

</form>
</div>
<div class="modal-footer">
<button class="btn cancel" ng-click="close()">Zrušiť</button>
<button class="btn cancel" ng-click="closeRent()">Zrušiť</button>
<button class="btn btn-success" ng-click="save()">Požičať</button>
</div>
</div>
Expand Down Expand Up @@ -133,7 +135,7 @@ <h3>Nová kniha</h3>

<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-success">Aktualizovať</button>
<button type="submit" class="btn btn-success hide">Aktualizovať</button>
</div>
</div>
</form>
Expand Down
2 changes: 2 additions & 0 deletions admin/app/views/rents.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ <h4 style="text-align: center;margin: 50px auto;">Zoznam požičaní</h4>
</tr>
</tbody>
</table>

<button class="btn btn-block" ng-click="query()" ng-show="mayQuery">Ďalšie</button>
</section>
6 changes: 4 additions & 2 deletions admin/app/views/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ <h4 style="text-align: center;margin: 50px auto;">Zoznam používateľov</h4>
</tr>
</tbody>
</table>

<button class="btn btn-block" ng-click="query()" ng-show="mayQuery">Ďalšie</button>
</section>

<button class="btn" ng-click="open()">Nový používateľ</button>
Expand Down Expand Up @@ -74,7 +76,7 @@ <h3>Nový používateľ</h3>

<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-success">Pridať</button>
<button type="submit" class="btn btn-success hide">Pridať</button>
</div>
</div>

Expand All @@ -83,6 +85,6 @@ <h3>Nový používateľ</h3>

<div class="modal-footer">
<button class="btn cancel" ng-click="close()">Zrušiť</button>
<button type="submit" class="btn btn-success" ng-click="addUser()">Pridať</button>
<button class="btn btn-success" ng-click="addUser()">Pridať</button>
</div>
</div>
20 changes: 20 additions & 0 deletions admin/test/spec/directives/infiniteScroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

describe('Directive: infiniteScroll', function () {

// load the directive's module
beforeEach(module('adminApp'));

var element,
scope;

beforeEach(inject(function ($rootScope) {
scope = $rootScope.$new();
}));

it('should make hidden element visible', inject(function ($compile) {
element = angular.element('<infinite-scroll></infinite-scroll>');
element = $compile(element)(scope);
expect(element.text()).toBe('this is the infiniteScroll directive');
}));
});
12 changes: 12 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module.exports = {
app: {
name: 'United Library - Development',
tld: 'united-library'
},
email: {
address: '[email protected]',
password: process.env.EMAILPASS || 'kniznica'
}
},
test: {
Expand All @@ -18,6 +22,10 @@ module.exports = {
app: {
name: 'United Library - Test',
tld: 'united-library'
},
email: {
address: '[email protected]',
password: process.env.EMAILPASS || 'kniznica'
}
},
production: {
Expand All @@ -27,6 +35,10 @@ module.exports = {
app: {
name: 'United Library - Production',
tld: 'united-library'
},
email: {
address: '[email protected]',
password: process.env.EMAILPASS || 'kniznica'
}
}
};
13 changes: 9 additions & 4 deletions config/cron.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module.exports = function() {
var routes = require('../routes');

var notification = require('cron').CronJob;
new notification('0 0 */1 * * *', function(){
// TODO
var reminders = require('cron').CronJob;
new reminders('0 0 17 * * *', function(){
routes.sendReminders();
}, null, true, 'Europe/Bratislava');

var tickets = require('cron').CronJob;
new tickets('0 0 16 * * *', function(){
routes.sendTickets();
}, null, true, 'Europe/Bratislava');

var routes = require('../routes');
var clenup = require('cron').CronJob;
new clenup('0 0 */1 * * *', function(){
routes.clearTmp();
Expand Down
8 changes: 6 additions & 2 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ module.exports = function(app, auth) {
}
});

var emails = require('../routes/emails');

// index
var routes = require('../routes');
app.get('/', routes.index);
app.get('/reminders', routes.sendReminders);
app.get('/tickets', routes.sendTickets);
app.post('/upload', routes.upload);

// users
Expand Down Expand Up @@ -45,10 +49,10 @@ module.exports = function(app, auth) {
var rents = require('../routes/rents');
app.get('/rents', rents.query);
app.get('/rents/:rentId', rents.get);
app.post('/rents', rents.create);
app.post('/rents', rents.create, emails.rentBook);
app.put('/rents/:rentId/', rents.update);
app.del('/rents/:rentId', rents.remove);
app.post('/rents/:rentId/returnBook', rents.returnBook);
app.post('/rents/:rentId/returnBook', rents.returnBook, emails.returnBook);

app.param('rentId', rents.rent);
};
Loading

0 comments on commit ec87325

Please sign in to comment.