text: "use strict";angular.module("AMC-web",["ui.router","ngAnimate","ngTagsInput","ui.bootstrap","cgPrompt"]).config(["$stateProvider","$urlRouterProvider",function(e,t){t.when("/dashboard","/dashboard/create"),t.otherwise("/login"),e.state("base",{"abstract":!0,url:"",templateUrl:"views/base.html"}).state("login",{url:"/login",parent:"base",templateUrl:"views/login.html",controller:"AuthCtrl"}).state("register",{url:"/register",parent:"base",templateUrl:"views/register.html",controller:"AuthCtrl"}).state("dashboard",{url:"/dashboard",parent:"base",templateUrl:"views/dashboard.html",controller:"DashboardCtrl"}).state("create",{url:"/create",parent:"dashboard",templateUrl:"views/dashboard/create.html",controller:"CreateCtrl"}).state("list",{url:"/list",parent:"dashboard",templateUrl:"views/dashboard/list.html",controller:"ListCtrl",resolve:{postPromise:["questions",function(e){return e.getAll()}]}}).state("question",{url:"/question/{questionId}",parent:"dashboard",templateUrl:"views/dashboard/question.html",controller:"QuestionCtrl",resolve:{question:["questions","$stateParams",function(e,t){return e.get(t.questionId)}]}}).state("test",{url:"/test",parent:"dashboard",templateUrl:"views/dashboard/test.html",controller:"TestCtrl"})}]),angular.module("AMC-web").controller("AuthCtrl",["$location","$scope","auth",function(e,t,r){t.user={},t.register=function(){r.register(t.user).then(function(){e.path("/dashboard")},function(e){t.error=e.data})},t.logIn=function(){r.logIn(t.user).then(function(){e.path("/dashboard")},function(e){t.error=e.data})}}]),angular.module("AMC-web").controller("CreateCtrl",["$scope","auth","questions","requests","tags",function(e,t,r,n,s){function o(){return"QCM"===e.question.type?e.question.answers:"Vrai/Faux"===e.question.type?u():e.openAnswers}function a(){var t=[];for(var r in e.question.tags){var n=e.question.tags[r];s.createTag(n),t.push(n.name)}return t}function u(){var t={title:"Vrai"},r={title:"Faux"},n=[];return t.correct=e.VFAnswer,r.correct=!e.VFAnswer,n.push(t),n.push(r),n}function i(){e.openAnswers=[{title:"Réponse fausse",points:0},{title:"Réponse partielle",points:1},{title:"Réponse juste",points:3}]}e.answer={title:"",correct:!0,points:0},e.answers={corrects:0,incorrects:0},e.openAnswer={title:"",points:0},e.openAnswers=[{title:"Réponse fausse",points:0},{title:"Réponse partielle",points:1},{title:"Réponse juste",points:3}],e.question={answers:[]},e.questionTypes=["QCM","Vrai/Faux","Question ouverte"],e.someScopeValue=15,e.someOtherScopeValue=20,e.addAnswer=function(){e.answer.title&&""!==e.answer.title&&(e.question.answers.push(e.answer),e.answer.correct?e.answers.corrects++:e.answers.incorrects++,e.answer={title:"",correct:!1})},e.addOpenAnswer=function(){e.openAnswer.title&&""!==e.openAnswer.title&&(e.openAnswers.push(e.openAnswer),e.openAnswer={title:"",points:0})},e.createQuestion=function(){e.question.tags=a(),e.question.answers=o(),r.create(e.question).then(function(){e.successMessage="La question a bien été créée.",e.question={answers:[]},e.answers={corrects:0,incorrects:0},i(),e.VFAnswer=null},function(t){console.log("error :",t),e.error=t.data})},e.deleteAnswer=function(t){e.question.answers[t].correct?e.answers.corrects--:e.answers.incorrects--,e.question.answers.splice(t,1)},e.getCorrect=function(){return e.answer.correct?"Juste":"Fausse"},e.loadTags=function(e){return n.get("/tags?q="+e)},e.showButton=function(){var t=!e.question.title||!e.question.type;if("QCM"===e.question.type){var r=e.answers.corrects>0&&e.answers.incorrects>0;return t||!r}return"Vrai/Faux"===e.question.type?t||"undefined"==typeof e.VFAnswer:t}}]),angular.module("AMC-web").controller("DashboardCtrl",["$scope","$state","auth",function(e,t,r){e.currentUser=r.currentUser,e.$state=t}]),angular.module("AMC-web").controller("ListCtrl",["$scope","questions",function(e,t){e.questions=t.questions,e.sortType="cDate",e.sortReverse=!0,e.searchString="",e.removeQuestion=function(r){t.remove(r);var n=e.questions.indexOf(r);n>-1&&e.questions.splice(n,1)},e.searchFilter=function(t){var r=new RegExp(e.searchString,"i");return!e.searchString||r.test(t.title)||r.test(t.tags)||r.test(t.plainDate)||r.test(t.type)}}]),angular.module("AMC-web").controller("QuestionCtrl",["$location","$scope","prompt","question","questions","requests","tags",function(e,t,r,n,s,o,a){function u(){var e=[];for(var r in t.question.tags){var n=t.question.tags[r];a.createTag(n),e.push(n.name)}return e}function i(){var e={title:"Vrai"},r={title:"Faux"},n=[];return e.correct=t.VFAnswer,r.correct=!t.VFAnswer,n.push(e),n.push(r),n}function c(){var e={corrects:0,incorrects:0};for(var r in t.question.answers)t.question.answers[r].correct?e.corrects++:e.incorrects++;return e}t.question=n,t.answer={title:"",correct:!1,points:0},t.VFAnswer=n.answers[0].correct?!0:!1,t.openAnswer={title:"",points:0},t.addAnswer=function(){t.answer.title&&""!==t.answer.title&&(t.question.answers.push(t.answer),t.answer.correct?t.answers.corrects++:t.answers.incorrects++,t.answer={title:"",correct:!1})},t.addOpenAnswer=function(){t.openAnswer.title&&""!==t.openAnswer.title&&(t.question.answers.push(t.openAnswer),t.openAnswer={title:"",points:0})},t.deleteAnswer=function(e){t.question.answers[e].correct?t.answers.corrects--:t.answers.incorrects--,t.question.answers.splice(e,1)},t.deleteQuestion=function(){r({title:"Supprimer la question",message:"Êtes-vous sûr de vouloir supprimer la question '"+t.question.title+"' ?",buttons:[{label:"Supprimer","class":"btn-danger",primary:!0},{label:"Annuler",cancel:!0}]}).then(function(){s.remove(t.question).then(function(){t.successMessage="La question a été supprimée."},function(){t.errorMessage="Une erreur est survenue."}),e.path("/dashboard/list")})},t.editQuestion=function(){t.question.answers="Vrai/Faux"===t.question.type?i():t.question.answers,t.question.tags=u(),s.edit(t.question).then(function(){t.successMessage="La question a été modifiée."},function(){t.errorMessage="Une erreur est survenue."})},t.getCorrect=function(){return t.answer.correct?"Juste":"Fausse"},t.loadTags=function(e){return o.get("/tags?q="+e)},t.showButton=function(){var e=!t.question.title||!t.question.type;if("QCM"===t.question.type){var r=t.answers.corrects>0&&t.answers.incorrects>0;return e||!r}return"Vrai/Faux"===t.question.type?e||"undefined"==typeof t.VFAnswer:e},t.answers=c()}]),angular.module("AMC-web").controller("TestCtrl",["$scope",function(e){e.hello="Hello World !"}]),angular.module("AMC-web").factory("auth",["$http","$window",function(e,t){var r={};return r.saveToken=function(e){t.localStorage["amc-web-token"]=e},r.getToken=function(){return t.localStorage["amc-web-token"]},r.isLoggedIn=function(){var e=r.getToken();if(e){var n=JSON.parse(t.atob(e.split(".")[1]));return n.exp>Date.now()/1e3}return!1},r.currentUser=function(){if(r.isLoggedIn()){var e=r.getToken(),n=JSON.parse(t.atob(e.split(".")[1]));return n}},r.register=function(t){return e.post("/register",t).success(function(e){r.saveToken(e.token)})},r.logIn=function(t){return e.post("/login",t).success(function(e){r.saveToken(e.token)})},r.logOut=function(){t.localStorage.removeItem("amc-web-token")},r}]),angular.module("AMC-web").factory("questions",["auth","requests",function(e,t){var r={questions:[]};return r.create=function(e){return t.post("/question/create",e).then(function(e){r.questions.push(e.data)})},r.edit=function(e){return t.post("/question/edit",e)},r.get=function(e){return t.get("/question/"+e).then(function(e){return e.data})},r.getAll=function(){return t.get("/question/all").then(function(e){angular.copy(e.data,r.questions)})},r.remove=function(e){return t.put("/question/"+e._id+"/remove")},r}]),angular.module("AMC-web").factory("requests",["$http","auth",function(e,t){var r={},n={headers:{Authorization:"Bearer "+t.getToken()}};return r.post=function(t,r){return e.post(t,r,n)},r.get=function(t){return e.get(t,n)},r.put=function(t){return e.put(t,null,n)},r}]),angular.module("AMC-web").factory("tags",["auth","requests",function(e,t){var r={};return r.createTag=function(e){t.post("/tags",e)},r}]);