angular.module("CheckHomeApp", ["ngRoute", "ngResource"]) .config(function($routeProvider, $locationProvider) { $routeProvider .when("/items", { templateUrl: "views/items.html", controller: "RoomsController" }) .when("/rooms", { templateUrl: "views/rooms.html", controller: "RoomsController" }) .when("/tags", { templateUrl: "views/tags.html", controller: "TagsController" }) .when("/users", { templateUrl: "views/users.html", controller: "UsersController" }) .when("/", { templateUrl: "views/home.html", controller: "RoomsController" }); $locationProvider.html5Mode(true); }); angular.module("CheckHomeApp") .factory("Version", function($resource) { return $resource("/api/version") }) .factory("Room", function($resource) { return $resource("/api/rooms/:roomId", { roomId: '@id' }, { 'update': {method: 'PUT'}, }) }) .factory("ItemChecks", function($resource) { return $resource("/api/items/:itemId/checks/:checkId", { itemId: '@id', checkId: '@id' }, { 'update': {method: 'PUT'}, }) }) .factory("ItemRoom", function($resource) { return $resource("/api/rooms/:roomId/items/:itemId", { roomId: '@id', itemId: '@id' }, { 'update': {method: 'PUT'}, }) }) .factory("User", function($resource) { return $resource("/api/users/:userId", { userId: '@id' }, { 'update': {method: 'PUT'}, }) }) .factory("TagsItem", function($resource) { return $resource("/api/items/:itemId/tags/:tagId", { itemId: '@id', tagId: '@id' }, { 'save': {method: 'PUT'}, 'update': {method: 'PUT'}, }) }) .factory("Tag", function($resource) { return $resource("/api/tags/:tagId", { tagId: '@id' }, { 'update': {method: 'PUT'}, }) }); angular.module("CheckHomeApp") .controller("VersionController", function($scope, Version) { $scope.v = Version.get(); }) .controller("RoomsController", function($scope, Room) { $scope.rooms = Room.query(); $scope.newRoom = function() { var t = new Room(); t.edit = true; $scope.rooms.push(t); } $scope.editRoom = function() { this.room.edit = true; } $scope.saveRoom = function() { if (this.room.id === undefined) this.room.$save() else this.room.$update(); } $scope.delRoom = function() { this.room.$remove(); } }) .controller("ItemsRoomController", function($scope, ItemRoom) { $scope.items = ItemRoom.query({roomId: $scope.room.id}); $scope.newItem = function() { var t = new ItemRoom(); t.edit = true; $scope.items.push(t); } $scope.editItem = function() { this.item.edit = true; } $scope.saveItem = function() { if (this.item.id === undefined) this.item.$save({roomId: $scope.room.id}) else this.item.$update(); } $scope.delItem = function() { this.item.$remove(); } }) .controller("ChecksItemController", function($scope, ItemChecks) { $scope.checks = ItemChecks.query({itemId: $scope.item.id}); $scope.newCheck = function(passed) { var c = new ItemChecks(); c.passed = passed; c.$save({itemId: $scope.item.id}, function(res) { $scope.checks.push(res) }) } $scope.checkOk = function() { $scope.newCheck("yes"); } $scope.checkMok = function() { $scope.newCheck("yesbut"); } $scope.checkMko = function() { $scope.newCheck("nobut"); } $scope.checkKo = function() { $scope.newCheck("no"); } }) .controller("TagsController", function($scope, Tag) { $scope.tags = Tag.query(); $scope.newTag = function() { var t = new Tag(); t.edit = true; $scope.tags.push(t); } $scope.editTag = function() { this.tag.edit = true; } $scope.saveTag = function() { if (this.tag.id === undefined) this.tag.$save() else this.tag.$update(); } $scope.delTag = function() { this.tag.$remove(); } }) .controller("TagsItemController", function($scope, TagsItem) { $scope.itags = TagsItem.query({itemId: $scope.item.id}); $scope.newItemTag = function() { var t = new TagsItem(); t.edit = true; $scope.itags.push(t); } $scope.editItemTag = function() { this.tag.edit = true; } $scope.editItemTagPass = function() { this.tag.editpass = true; } $scope.saveItemTag = function() { if (this.tag.id === undefined) this.tag.$save({itemId: $scope.item.id, tagId: this.tag.val}) else this.tag.$update(); } $scope.delItemTag = function() { this.tag.$remove({itemId: $scope.item.id, tagId: this.tag.id}); } }) .controller("UsersController", function($scope, User) { $scope.users = User.query(); $scope.newUser = function() { var t = new User(); t.edit = true; t.editpass = true; $scope.users.push(t); } $scope.editUser = function() { this.user.edit = true; } $scope.editUserPass = function() { this.user.editpass = true; } $scope.saveUser = function() { if (this.user.id === undefined) this.user.$save() else this.user.$update(); } $scope.delUser = function() { this.user.$remove(); } });