done. ready!

This commit is contained in:
nemunaire 2018-07-20 05:04:06 +02:00
commit b3abc0d434
12 changed files with 326 additions and 111 deletions

View file

@ -1,4 +1,4 @@
angular.module("CheckHomeApp", ["ngRoute", "ngResource"])
angular.module("CheckHomeApp", ["ngRoute", "ngResource", "ngSanitize"])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when("/items", {
@ -60,18 +60,51 @@ angular.module("CheckHomeApp")
})
});
function newCheck(ItemChecks, iid, passed, cb) {
var c = new ItemChecks();
c.passed = passed;
c.comment = $("#comment").val();
c.$save({itemId: iid}, function(res) {
$("#comment").val("");
$('#commentModal').modal("hide");
cb(res);
});
}
angular.module("CheckHomeApp")
.controller("VersionController", function($scope, Version) {
$scope.v = Version.get();
})
.controller("RoomsController", function($scope, Room) {
.controller("RoomsController", function(ItemChecks, Room, $scope, $rootScope) {
$scope.rooms = Room.query();
$rootScope.tagsX = [];
$rootScope.tagsReverse = false;
$rootScope.tagsShown = {};
$rootScope.stateShown = { "yes": true, "yesbut": true, "nobut": true, "no": true, "next": false , "na": true };
$scope.newRoom = function() {
var t = new Room();
t.edit = true;
$scope.rooms.push(t);
}
$scope.toggleRoom = function() {
this.room.closed = !this.room.closed;
}
$scope.showOnlyThisRoom = function() {
$scope.rooms.forEach(function(r) {
r.closed = true;
});
this.room.closed = false;
}
$scope.toggleStateS = function(state) {
$rootScope.stateShown[state] = !$rootScope.stateShown[state];
}
$scope.toggleAllStates = function() {
Object.keys($rootScope.stateShown).forEach(function(v) {
$rootScope.stateShown[v] = $rootScope.statesSelect;
})
$rootScope.statesSelect = !$rootScope.statesSelect;
}
$scope.editRoom = function() {
this.room.edit = true;
}
@ -86,15 +119,63 @@ angular.module("CheckHomeApp")
$scope.room.splice(rk, 1);
});
}
$scope.skipCheck = function() {
$rootScope.selectedItem.action = "next";
$scope.submitModal();
}
$scope.submitModal = function() {
newCheck(ItemChecks, $rootScope.selectedItem.id, $rootScope.selectedItem.action, $rootScope.selectedItem.cb)
}
})
.controller("ItemsRoomController", function($scope, ItemRoom) {
.controller("ItemsRoomController", function($scope, $rootScope, ItemRoom) {
$scope.items = ItemRoom.query({roomId: $scope.room.id});
$scope.items.$promise.then(function(){
$scope.items.forEach(function(item) {
if (item.tags != null)
item.tags.forEach(function(v) {
if ($rootScope.tagsX.indexOf(v) == -1) {
$rootScope.tagsX.push(v);
$rootScope.tagsShown[v] = true;
}
})
})
});
$scope.filterByTag = function() {
if (this.item.tags == null)
return true;
if (!$rootScope.tagsReverse) {
var display = false;
this.item.tags.forEach(function(v) {
$rootScope.tagsX.forEach(function(t) {
if (display || ($rootScope.tagsShown[t] && t == v))
display = true;
});
});
return display;
} else {
var display = true;
this.item.tags.forEach(function(v) {
$rootScope.tagsX.forEach(function(t) {
if (!display || ($rootScope.tagsShown[t] && t == v))
display = false;
});
});
return display;
}
}
$scope.newItem = function() {
var t = new ItemRoom();
t.edit = true;
$scope.items.push(t);
}
$scope.toggleDescription = function() {
this.item.open = !this.item.open;
}
$scope.editItem = function() {
this.item.edit = true;
}
@ -105,19 +186,16 @@ angular.module("CheckHomeApp")
this.item.$update({roomId: this.room.id});
}
$scope.delItem = function(ik) {
this.item.$delete().then(function() {
this.item.$delete({roomId: this.room.id}).then(function() {
$scope.items.splice(ik, 1);
});
}
})
.controller("ChecksItemController", function($scope, ItemChecks) {
.controller("ChecksItemController", function($scope, ItemChecks, $rootScope) {
$rootScope.selectedItem = {};
$scope.ncomment = "";
$scope.checks = ItemChecks.query({itemId: $scope.item.id});
$scope.registerComment = function() {
$scope.newCheck($("#assocRes").val());
}
$scope.min_checks = function() {
function state2int(state) {
switch(state) {
@ -129,8 +207,10 @@ angular.module("CheckHomeApp")
return 2;
case "no":
return 1;
default:
case "next":
return 5;
default:
return 6;
}
}
var min = "N/A";
@ -140,28 +220,43 @@ angular.module("CheckHomeApp")
});
return min;
}
$scope.newCheck = function(passed) {
var c = new ItemChecks();
c.passed = passed;
c.comment = $("#comment").val();
c.$save({itemId: $scope.item.id}, function(res) {
$("#comment").val("");
$scope.checks.push(res)
$scope.filterByCheck = function() {
if ((this.checks == null || this.checks.length == 0) && $rootScope.stateShown["na"])
return true;
var display = false;
this.checks.forEach(function(v) {
Object.keys($rootScope.stateShown).forEach(function(k) {
if(display || (k == v["passed"] && $rootScope.stateShown[k]))
display = true;
});
});
return display;
}
$scope.checkOk = function() {
$scope.newCheck("yes");
$scope.checkCommon = function(modal, res) {
if (modal) {
var cb = function(res) { $scope.checks.push(res); }
$rootScope.selectedItem = this.item;
$rootScope.selectedItem.action = res;
$rootScope.selectedItem.cb = cb;
$('#commentModal').modal("show");
document.getElementById("comment").focus();
} else {
newCheck(ItemChecks, $scope.item.id, res, function(res) { $scope.checks.push(res); });
}
}
$scope.checkMok = function() {
$("#assocRes").val("yesbut");
$('#commentModal').modal("show");
$scope.checkOk = function(modal) {
$scope.checkCommon(modal, "yes");
}
$scope.checkMko = function() {
$("#assocRes").val("nobut");
$('#commentModal').modal("show");
$scope.checkMok = function(modal) {
$scope.checkCommon(modal, "yesbut");
}
$scope.checkKo = function() {
$scope.newCheck("no");
$scope.checkMko = function(modal) {
$scope.checkCommon(modal, "nobut");
}
$scope.checkKo = function(modal) {
$scope.checkCommon(modal, "no");
}
$scope.delCheck = function(ck) {
@ -170,9 +265,24 @@ angular.module("CheckHomeApp")
});
}
})
.controller("TagsController", function($scope, Tag) {
.controller("TagsController", function($scope, $rootScope, Tag) {
$scope.tags = Tag.query();
$rootScope.tagsSelect = false;
$scope.toggleAllTags = function() {
$rootScope.tagsX.forEach(function(v) {
$rootScope.tagsShown[v] = $rootScope.tagsSelect;
})
$rootScope.tagsSelect = !$rootScope.tagsSelect;
}
$scope.toggleReverseTags = function(tag) {
$rootScope.tagsReverse = !$rootScope.tagsReverse;
}
$scope.toggleTagS = function(tag) {
$rootScope.tagsShown[tag] = !$rootScope.tagsShown[tag];
$rootScope.tagsSelect = false;
}
$scope.newTag = function() {
var t = new Tag();
t.edit = true;
@ -193,7 +303,7 @@ angular.module("CheckHomeApp")
});
}
})
.controller("TagsItemController", function($scope, TagsItem) {
.controller("TagsItemController", function($scope, TagsItem, $http) {
$scope.itags = TagsItem.query({itemId: $scope.item.id});
$scope.newItemTag = function() {
@ -202,16 +312,19 @@ angular.module("CheckHomeApp")
$scope.itags.push(t);
}
$scope.editItemTag = function() {
this.tag.val = this.tag.id;
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();
else {
var v = this.tag;
var val = this.tag.val;
v.$delete({itemId: $scope.item.id, tagId: v.id}).then(function() {
v.$save({itemId: $scope.item.id, tagId: val});
});
}
}
$scope.delItemTag = function(tk) {
this.tag.$delete({itemId: $scope.item.id, tagId: this.tag.id}).then(function() {
@ -219,7 +332,7 @@ angular.module("CheckHomeApp")
});
}
})
.controller("UsersController", function($scope, User) {
.controller("UsersController", function($scope, User, $http, $location) {
$scope.users = User.query();
$scope.newUser = function() {
@ -245,4 +358,10 @@ angular.module("CheckHomeApp")
$scope.users.splice(uk, 1);
});
}
$scope.razchecks = function() {
if (confirm("Sûr d'effacer tous les tests effectués ?"))
$http.delete("/api/checks").then(function() {
$location.url("/");
});
}
});