diff --git a/Mundialito/Client/src/Dashboard/Dashboard.html b/Mundialito/Client/src/Dashboard/Dashboard.html index 735ceb9..d8d78f8 100644 --- a/Mundialito/Client/src/Dashboard/Dashboard.html +++ b/Mundialito/Client/src/Dashboard/Dashboard.html @@ -82,7 +82,12 @@
{{::game.AwayTeam.Name}}
- {{item[0]}} +
+ {{item[0]}} +
+
+ +
{ + const shortName = team.ShortName; + if (!acc[shortName]) { + acc[shortName] = []; + } + acc[shortName].push(team); + return acc; + }, {}); + } + $scope.groupedTeams = groupTeamsByShortName(teams); + $scope.changed = (game) => { if ($scope.toggleValue[game.GameId]) { $scope.selectedDic[game.GameId] = $scope.marksDic[game.GameId]; diff --git a/Mundialito/Views/Home/Index.cshtml b/Mundialito/Views/Home/Index.cshtml index fe89393..e3739d3 100644 --- a/Mundialito/Views/Home/Index.cshtml +++ b/Mundialito/Views/Home/Index.cshtml @@ -145,11 +145,11 @@ @if (env.IsProduction()) { - + } else { - + }
diff --git a/Mundialito/wwwroot/App/Dashboard/Dashboard.html b/Mundialito/wwwroot/App/Dashboard/Dashboard.html index 735ceb9..d8d78f8 100644 --- a/Mundialito/wwwroot/App/Dashboard/Dashboard.html +++ b/Mundialito/wwwroot/App/Dashboard/Dashboard.html @@ -82,7 +82,12 @@
{{::game.AwayTeam.Name}}
- {{item[0]}} +
+ {{item[0]}} +
+
+ +
{ + const shortName = team.ShortName; + if (!acc[shortName]) { + acc[shortName] = []; + } + acc[shortName].push(team); + return acc; + }, {}); + } + $scope.groupedTeams = groupTeamsByShortName(teams); + $scope.changed = (game) => { if ($scope.toggleValue[game.GameId]) { $scope.selectedDic[game.GameId] = $scope.marksDic[game.GameId]; diff --git a/Mundialito/wwwroot/js/app-min-b9de64167c2b03c8f2f816e6e633631e.js b/Mundialito/wwwroot/js/app-min-b9de64167c2b03c8f2f816e6e633631e.js new file mode 100644 index 0000000..15e0443 --- /dev/null +++ b/Mundialito/wwwroot/js/app-min-b9de64167c2b03c8f2f816e6e633631e.js @@ -0,0 +1 @@ +angular.module("mundialitoApp",["key-value-editor","security","ngSanitize","ngRoute","ngAnimate","ui.bootstrap","autofields.bootstrap","cgBusy","ajoslin.promise-tracker","ui.select","ui.bootstrap.datetimepicker","ui.grid","ui.grid.autoResize","googlechart","toaster","ui.grid.saveState","ui.grid.resizeColumns","ui.toggle"]).value("cgBusyTemplateName","App/Partials/angular-busy.html").config(["$routeProvider","$httpProvider","$locationProvider","$parseProvider","securityProvider","Constants",function(e,a,t,r,s,n){t.html5Mode(!0),a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.interceptors.push("myHttpInterceptor"),s.urls.login=n.LOGIN_PATH,s.usePopups=!1,e.when("/",{templateUrl:"App/Dashboard/Dashboard.html",controller:"DashboardCtrl",resolve:{teams:["TeamsManager",e=>e.loadAllTeams()],players:["PlayersManager",e=>e.loadAllPlayers()]}}).when("/bets_center",{templateUrl:"App/Bets/BetsCenter.html",controller:"BetsCenterCtrl",resolve:{games:["GamesManager",e=>e.loadOpenGames()]}}).when("/users/:username",{templateUrl:"App/Users/UserProfile.html",controller:"UserProfileCtrl",resolve:{profileUser:["$route","UsersManager",(e,a)=>{var t=e.current.params.username;return a.getUser(t,!0)}],userGameBets:["$route","BetsManager",(e,a)=>{var t=e.current.params.username;return a.getUserBets(t)}],teams:["TeamsManager",e=>e.loadAllTeams()],generalBetsAreOpen:["GeneralBetsManager",e=>e.canSubmtiGeneralBet()],players:["PlayersManager",e=>e.loadAllPlayers()],allUsers:["UsersManager",e=>e.loadAllUsers()]}}).when("/manage_users",{templateUrl:"App/Users/ManageApp.html",controller:"ManageAppCtrl",resolve:{users:["UsersManager",e=>e.loadAllUsers()],teams:["TeamsManager",e=>e.loadAllTeams()],generalBets:["GeneralBetsManager",e=>e.loadAllGeneralBets()],players:["PlayersManager",e=>e.loadAllPlayers()]}}).when("/teams",{templateUrl:"App/Teams/Teams.html",controller:"TeamsCtrl",resolve:{teams:["TeamsManager",e=>e.loadAllTeams()]}}).when("/teams/:teamId",{templateUrl:"App/Teams/Team.html",controller:"TeamCtrl",resolve:{team:["$route","TeamsManager",(e,a)=>{var t=e.current.params.teamId;return a.getTeam(t)}],games:["$route","GamesManager",(e,a)=>{var t=e.current.params.teamId;return a.getTeamGames(t)}]}}).when("/games/:gameId",{templateUrl:"App/Games/Game.html",controller:"GameCtrl",resolve:{teams:["TeamsManager",e=>e.loadAllTeams()],players:["PlayersManager",e=>e.loadAllPlayers()],game:["$route","GamesManager",(e,a)=>{var t=e.current.params.gameId;return a.getGame(t)}],userBet:["$route","BetsManager",(e,a)=>{var t=e.current.params.gameId;return a.getUserBetOnGame(t)}]}}).when("/games",{templateUrl:"App/Games/Games.html",controller:"GamesCtrl",resolve:{games:["GamesManager",e=>e.loadAllGames()],teams:["TeamsManager",e=>e.loadAllTeams()]}}).when("/stadiums/:stadiumId",{templateUrl:"App/Stadiums/Stadium.html",controller:"StadiumCtrl",resolve:{stadium:["$q","$route","StadiumsManager",(e,a,t)=>{var r=a.current.params.stadiumId;return t.getStadium(r,!0)}]}}).when("/stadiums",{templateUrl:"App/Stadiums/Stadiums.html",controller:"StadiumsCtrl",resolve:{stadiums:["StadiumsManager",e=>e.loadAllStadiums()]}}).when("/login",{templateUrl:"App/Accounts/Login.html"}).when("/forgot",{templateUrl:"App/Accounts/ForgetPassword.html",controller:"ForgetPasswordCtrl"}).when("/reset",{templateUrl:"App/Accounts/ResetPassword.html",controller:"ResetPasswordCtrl"}).when("/join",{templateUrl:"App/Accounts/Register.html"}).when("/manage",{templateUrl:"App/Accounts/Manage.html"}).otherwise({redirectTo:"/"})}]).run(["$rootScope","$log","security","$route","$location","PluginsProvider","FootballDataGamePlugin","FootballDataTeamStatsPlugin",function(e,a,t,r,s,n,i,o){n.registerGameFactory(i),n.registerTeamFactory(o),t.events.login=function(t,r){a.log("Current user details: "+angular.toJson(r)),e.mundialitoApp.authenticating=!1},t.events.reloadUser=function(t,r){a.log("User reloaded"+angular.toJson(r)),e.mundialitoApp.authenticating=!1},t.events.logout=function(e){a.log("User logged out"),e.authenticate()},e.mundialitoApp={params:null,loading:!0,authenticating:!0,message:null},["/reset","/forgot","/join","/login"].includes(s.$$path)||(a.log("Starting authentication"),t.authenticate()),e.security=t,e.$on("$locationChangeStart",function(){a.debug("$locationChangeStart"),e.mundialitoApp.loading=!0}),e.$on("$locationChangeSuccess",function(){a.debug("$locationChangeSuccess"),e.mundialitoApp.params=angular.copy(r.current.params),e.mundialitoApp.loading=!1}),e.$on("$routeChangeStart",function(){a.debug("$routeChangeStart"),e.mundialitoApp.message="Loading..."}),e.$on("$routeChangeSuccess",function(){a.debug("$routeChangeSuccess"),e.mundialitoApp.message=null})}]),angular.module("mundialitoApp").constant("Constants",{LOGIN_PATH:"/login",REFRESH_TIME:3e5,TABLE_GRID_OPTIONS:{saveWidths:!0,saveVisible:!0,saveOrder:!0,enableRowSelection:!1,enableSelectAll:!1,multiSelect:!1,rowTemplate:'
',columnDefs:[{field:"Place",displayName:"",resizable:!1,maxWidth:30},{field:"Name",displayName:"Name",resizable:!0,minWidth:115},{field:"Points",displayName:"Points",resizable:!0,minWidth:45,maxWidth:75},{field:"GeneralBet.WinningTeam",displayName:"Team",resizable:!1,maxWidth:45,cellTemplate:'
'},{field:"GeneralBet.GoldenBootPlayer.Name",displayName:"Player",resizable:!1,minWidth:50,maxWidth:50,cellTemplate:"
{{COL_FIELD.split(' ')[0].charAt(0)}}.{{COL_FIELD.split(' ')[1].charAt(0)}}
"},{field:"Marks",displayName:"Marks",resizable:!0},{field:"Results",displayName:"Results",resizable:!0},{field:"YellowCards",displayName:"Yellow Cards Marks",maxWidth:55,resizable:!1,headerCellTemplate:'
'},{field:"Corners",displayName:"Corners Marks",maxWidth:55,resizable:!1,headerCellTemplate:'
'},,{field:"PlaceDiff",displayName:"",resizable:!1,maxWidth:45,cellTemplate:"
{{::COL_FIELD}}
"}]}}),angular.module("mundialitoApp").controller("ForgetPasswordCtrl",["$scope","$rootScope","security","Alert",function(e,a,t,r){a.mundialitoApp.authenticating=!1;e.user=new function(){return{Email:""}},e.forget=function(){e.emailForm.$valid&&(a.mundialitoApp.message="Processing...",t.forgotPassword(angular.copy(e.user)).then(()=>{r.success("Reset password token was sent to your email, please follow the link from there")}).catch(e=>{r.error("Failed to generate reset password token: "+e)}).finally(function(){a.mundialitoApp.message=null}))},e.schema=[{property:"Email",label:"Email Address",type:"email",attr:{required:!0}}]}]),angular.module("mundialitoApp").controller("LoginCtrl",["$scope","$rootScope","security",function(e,a,t){a.mundialitoApp.authenticating=!1;e.user=new function(){return{username:"",password:"",rememberMe:!1}},e.login=(()=>{e.loginForm.$valid&&(a.mundialitoApp.message="Processing Login...",t.login(angular.copy(e.user)).finally(function(){a.mundialitoApp.message=null}))}),e.schema=[{property:"username",type:"text",attr:{ngMinlength:4,required:!0}},{property:"password",type:"password",attr:{ngMinlength:4,required:!0}},{property:"rememberMe",label:"Keep me logged in",type:"checkbox"}],window.login=(e=>{console.log("Got response from Google: "+e),a.mundialitoApp.message="Processing Login...",t.googleLogin(e).finally(function(){a.mundialitoApp.message=null})}),window.onload=function(){google.accounts.id.initialize({client_id:e.mundialitoApp.GoogleClientId,callback:login}),google.accounts.id.renderButton(document.getElementById("buttonDiv"),{theme:"filled_blue",size:"large",text:"continue_with",shape:"circle"}),google.accounts.id.prompt()}}]),angular.module("mundialitoApp").controller("ManageCtrl",["$scope","Alert",function(e,a){var t=function(){return{oldPassword:"",newPassword:"",confirmPassword:""}};e.changingPassword=null,e.changePassword=function(){e.changingPassword=new t},e.cancel=function(){e.changingPassword=null},e.updatePassword=function(){if(e.manageForm.$valid){var t=angular.copy(e.changingPassword);e.changingPassword=null,e.security.changePassword(t).then(function(){a.success("Password was changed sucessfully")},function(){a.error("Failed to change password"),e.changingPassword=t})}},e.changePasswordSchema=[{property:"oldPassword",type:"password",attr:{required:!0}},{property:"newPassword",type:"password",attr:{ngMinlength:4,required:!0}},{property:"confirmPassword",type:"password",attr:{confirmPassword:"changingPassword.newPassword",required:!0}}]}]),angular.module("mundialitoApp").controller("RegisterCtrl",["$scope","security",function(e,a){e.mundialitoApp.authenticating=!1;e.user=new function(){return{firstname:"",lastname:"",email:"",username:"",password:"",confirmPassword:""}},e.join=function(){e.joinForm.$valid&&(e.isJoinActive=!0,e.mundialitoApp.message="Processing Registration...",a.register(angular.copy(e.user)).finally(function(){e.mundialitoApp.message=null,e.isJoinActive=!1}))},e.schema=[{property:"firstname",label:"First Name",type:"text",attr:{required:!0}},{property:"lastname",label:"Last Name",type:"text",attr:{required:!0}},{property:"email",label:"Email Address",type:"email",attr:{required:!0}},{property:"username",type:"text",attr:{ngMinlength:4,required:!0}},{property:"password",type:"password",attr:{required:!0}},{property:"confirmPassword",label:"Confirm Password",type:"password",attr:{confirmPassword:"user.password",required:!0}}]}]),angular.module("mundialitoApp").controller("ResetPasswordCtrl",["$scope","$rootScope","security","$location","Alert",function(e,a,t,r,s){a.mundialitoApp.authenticating=!1;e.user=new function(){return{confirmPassword:"",password:"",email:r.search().email,token:r.search().token}},e.reset=function(){e.resetForm.$valid&&(a.mundialitoApp.message="Processing Reset Password...",t.resetPassword(angular.copy(e.user)).then(()=>{s.success("Your was was reset successfully")}).finally(function(){a.mundialitoApp.message=null}))},e.schema=[{property:"password",type:"password",attr:{required:!0}},{property:"confirmPassword",label:"Confirm Password",type:"password",attr:{confirmPassword:"user.password",required:!0}}]}]),angular.module("mundialitoApp").factory("Bet",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)},getTeamByCornersMark:function(){return"1"===this.CornersMark?this.Game.HomeTeam:"2"===this.CornersMark?this.Game.AwayTeam:null},getTeamByCardsMark:function(){return"1"===this.CardsMark?this.Game.HomeTeam:"2"===this.CardsMark?this.Game.AwayTeam:null},update:function(){return a.debug("Bet: Will update bet "+this.BetId),e.put("api/bets/"+this.BetId,this,{tracker:"updateBet"})},getGameUrl:function(){return"/games/"+this.Game.GameId},getClass:function(){return this.Points>=7?"success":this.Points>=5?"primary":this.Points>=3?"info":this.Points>0?"warning":"danger"}},t}]),angular.module("mundialitoApp").controller("BetsCenterCtrl",["$scope","$log","$timeout","Alert","BetsManager","games",function(e,a,t,r,s,n){e.games=n,e.bets={};var i=function(){angular.isDefined(e.security.user)&&null!=e.security.user?e.getUserBetsPromise=s.getUserBets(e.security.user.Username).then(t=>{for(var r=0;r{r.success("Bet was updated successfully"),s.setBet(e)}).catch(function(){r.error("Failed to update Bet, please try again")})):(a.debug("BetsCenterCtrl: Will create new bet"),s.addBet(e.bets[t]).then(function(s){a.log("BetsCenterCtrl: Bet "+s.BetId+" was added"),e.bets[t]=s,r.success("Bet was added successfully")}).catch(function(){r.error("Failed to add Bet, please try again")}))},e.shuffleBet=function(t){var r,s,n=["1","X","2"],i=[0,0,0,0,1,1,1,1,2,2,3,3,4,5],o=n[Math.floor(3*Math.random())];do{r=i[Math.floor(Math.random()*i.length)],s=i[Math.floor(Math.random()*i.length)]}while("X"!==o&&r===s);a.debug("Random game mark is "+o),"X"===o&&(s=r),a.debug("Home goals: "+r),a.debug("Away goals: "+s),e.bets[t].HomeScore=r,e.bets[t].AwayScore=s,e.bets[t].CardsMark=n[Math.floor(3*Math.random())],e.bets[t].CornersMark=n[Math.floor(3*Math.random())]}}]),angular.module("mundialitoApp").factory("BetsManager",["$http","$q","Bet","$log","MundialitoUtils","GamesManager",function(e,a,t,r,s,n){return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("BetsManager: updating existing instance of bet "+e),s.setData(a)):(r.debug("BetsManager: saving new instance of bet "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("BetsManager: will fetch bet "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("BetsManager: Instance was loaded at "+a.LoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("BetsManager: will fetch bet "+a+" from server"),e.get("api/bets/"+a,{tracker:"getBet"}).then(e=>{var a=s._retrieveInstance(e.data.BetId,e.data);t.resolve(a)}).catch(()=>{t.reject()})},addBet:function(t){var s=a.defer(),n=this;return r.debug("BetsManager: will add new bet - "+angular.toJson(t)),e.post("api/bets/",t,{tracker:"addBetOnGame"}).then(e=>{var a=n._retrieveInstance(e.data.BetId,e.data);s.resolve(a)}).catch(e=>{r.error("Failed to add bet"),s.reject(e)}),s.promise},getBet:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},getGameBets:function(t){var s=a.defer(),n=this;return r.debug("BetsManager: will fetch all bets of game "+t+" from server"),e.get("api/games/"+t+"/bets",{tracker:"getGameBets"}).then(e=>{var a=[];e.data.forEach(e=>{var t=n._retrieveInstance(e.BetId,e);a.push(t)}),s.resolve(a)}).catch(function(){s.reject()}),s.promise},getUserBets:function(t){var s=a.defer(),n=this;return r.debug("BetsManager: will fetch user "+t+" bets from server"),e.get("api/bets/user/"+t,{tracker:"getUserBets"}).then(e=>{var a=[];e.data.forEach(e=>{var t=n._retrieveInstance(e.BetId,e);a.push(t)}),s.resolve(a)}).catch(function(){s.reject()}),s.promise},getUserBetOnGame:function(t){var s=a.defer(),n=this;return r.debug("BetsManager: will fetch user bet of game "+t+" from server"),e.get("api/games/"+t+"/mybet",{tracker:"getUserBetOnGame"}).then(e=>{if(-1!=e.data.BetId){var a=n._retrieveInstance(e.data.BetId,e.data);s.resolve(a)}s.resolve(e.data)}).catch(()=>{s.reject()}),s.promise},setBet:function(e){r.debug("BetsManager: will set bet "+e.BetId+" to -"+angular.toJson(e));var a=this._search(e.BetId);return a?a.setData(e):a=this._retrieveInstance(e.BetId,e),a}}}]),angular.module("mundialitoApp").controller("DashboardCtrl",["$scope","$log","Constants","$location","$timeout","GamesManager","UsersManager","GeneralBetsManager","teams","players","BetsManager","MundialitoUtils",function(e,a,t,r,s,n,i,o,l,u,d,m){e.generalBetsAreOpen=!1,e.submittedGeneralBet=!0,e.pendingUpdateGames=!1,e.oneAtATime=!0,e.status={},e.toggleValue={},e.players=u,e.groupedTeams=function(e){return e.reduce((e,a)=>{const t=a.ShortName;return e[t]||(e[t]=[]),e[t].push(a),e},{})}(l),e.changed=(a=>{e.toggleValue[a.GameId]?(e.selectedDic[a.GameId]=e.marksDic[a.GameId],e.selectedPercentage[a.GameId]=e.marksPercentage[a.GameId]):(e.selectedDic[a.GameId]=e.resultsDic[a.GameId],e.selectedPercentage[a.GameId]=e.resultsPercentage[a.GameId])}),e.getGamesPromise=n.loadAllGames().then(t=>{e.games=t,e.resultsDic={},e.marksDic={},e.selectedDic={},e.resultsPercentage={},e.marksPercentage={},e.selectedPercentage={},e.pendingUpdateGames=void 0!==_.findWhere(e.games,{IsPendingUpdate:!0}),e.pendingUpdateGamesFolloweesBets={},a.info("DashboardCtrl: followees:"+e.security.user.Followees),_.filter(e.games,e=>e.IsPendingUpdate).forEach(a=>{d.getGameBets(a.GameId).then(t=>{let r=_.groupBy(t,e=>e.HomeScore+"-"+e.AwayScore),s=_.groupBy(t,e=>e.HomeScore===e.AwayScore?"X":e.HomeScore>e.AwayScore?e.Game.HomeTeam.ShortName:e.Game.AwayTeam.ShortName);e.resultsDic[a.GameId]=Object.entries(r).sort((e,a)=>a[1].length-e[1].length),e.marksDic[a.GameId]=Object.entries(s).sort((e,a)=>a[1].length-e[1].length),e.resultsPercentage[a.GameId]={},e.resultsDic[a.GameId].forEach(r=>{e.resultsPercentage[a.GameId][r[0]]=Math.round(r[1].length/t.length*100)}),e.marksPercentage[a.GameId]={},e.marksDic[a.GameId].forEach(r=>{e.marksPercentage[a.GameId][r[0]]=Math.round(r[1].length/t.length*100)});let n=_.filter(t,a=>e.security.user.Followees.includes(a.User.Username)||e.security.user.Username===a.User.Username);e.pendingUpdateGamesFolloweesBets[a.GameId]=n,e.changed(a)})})});var c=()=>{angular.isDefined(e.security.user)&&null!=e.security.user?o.hasGeneralBet(e.security.user.Username).then(a=>{e.submittedGeneralBet=!0===a}):(a.debug("DashboardCtrl: user info not loaded yet, will retry in 1 second"),s(c,1e3))};function g(){var a=e.gridApi.saveState.save();localStorage.setItem("gridState",a)}c(),o.canSubmtiGeneralBet().then(a=>{e.generalBetsAreOpen=!0===a,e.generalBetsAreOpen||o.loadAllGeneralBets().then(function(a){e.generalBets=a,e.winningTeams={},e.winningPlayers={};for(var t=0;t{e.users=a,e.usersDic=a.reduce((e,a)=>(e[a.Id]=a,e),{})}),e.isOpenForBetting=(e=>e.IsOpen),e.isPendingUpdate=(e=>e.IsPendingUpdate),e.isDecided=function(e){return!e.IsOpen&&!e.IsPendingUpdate},e.isGameBet=(e=>a=>a.Game.GameId===e.GameId),e.hasBets=(a=>void 0!==e.pendingUpdateGamesFolloweesBets[a.GameId]&&e.pendingUpdateGamesFolloweesBets[a.GameId].length>0),e.gridOptions={...t.TABLE_GRID_OPTIONS,data:"users",onRegisterApi:a=>{e.gridApi=a,e.gridApi.colResizable.on.columnSizeChanged(e,g),e.gridApi.core.on.columnVisibilityChanged(e,g),e.gridApi.core.on.sortChanged(e,g)}},e.getTableHeight=(()=>{var t=30*(e.users?e.users.length:0)+30;return a.debug("Total Height: "+t),{height:t+"px"}}),e.goToUser=(e=>{r.path(e.entity.getUrl())})}]),angular.module("mundialitoApp").factory("Game",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)},delete:function(){if(confirm("Are you sure you would like to delete game "+this.GameId))return a.debug("Game: Will delete game "+this.GameId),e.delete("api/games/"+this.GameId,{tracker:"deleteGame"})},update:function(){return a.debug("Game: Will update game "+this.GameId),e.put("api/games/"+this.GameId,this,{tracker:"editGame"})},getUrl:function(){return"/games/"+this.GameId}},t}]),angular.module("mundialitoApp").controller("GameCtrl",["$scope","$log","Constants","UsersManager","GamesManager","BetsManager","game","userBet","Alert","$location","PluginsProvider","keyValueEditorUtils","MundialitoUtils","teams","players",function(e,a,t,r,s,n,i,o,l,u,d,m,c,g,p){e.game=i,e.teamsDic={},e.playersDic={},e.simulatedGame={},e.plugins={},e.userBet=o,e.userBet.GameId=i.GameId,e.showEditForm=!1,e.toKeyValue=(e=>_.keys(e).map(a=>({name:a,value:e[a]}))),e.integrationsData=e.toKeyValue(e.game.IntegrationsData);for(var f=0;fnew Date(e.Date)).filter(e=>e.IsBetResolved).map(e=>c.getGameMark(e,t)).value();e.teamsForm[t]={form:r,games:_.filter(a,e=>e.IsBetResolved)}}d.getGameDetailsFromAll(e.game).then(a=>{a.forEach(a=>{e.plugins[a.property]={data:a.data,template:a.template}})}),e.game.IsOpen||(e.getGameBetsPromsie=n.getGameBets(e.game.GameId).then(t=>{a.debug("GameCtrl: get game bets"+angular.toJson(t)),e.gameBets=t;var s={type:"PieChart",options:{displayExactValues:!0,is3D:!0,backgroundColor:{fill:"transparent"},chartArea:{left:10,top:20,bottom:0,height:"100%"},title:"Bets Distribution"}},n=_.filter(t,function(e){return e.HomeScore>e.AwayScore}).length,i=_.filter(t,function(e){return e.HomeScore===e.AwayScore}).length,o=_.filter(t,function(e){return e.HomeScore{e.usersMap=new Map,a.forEach(a=>{e.usersMap.set(a.Username,a)});let t=_.chain(a).filter(a=>e.security.user.Followees.includes(a.Username)).pluck("Username").value();e.followeesBets=_.filter(e.gameBets,e=>t.includes(e.User.Username));let r=_.chain(a).first(3).pluck("Username").value();e.top3UsersBets=_.filter(e.gameBets,e=>r.includes(e.User.Username));let s=0;a.forEach((a,t)=>{a.Username===e.security.user.Username&&(s=t)});let n=Math.max(s-3,0),i=Math.min(s+3,a.length),o=_.chain(a.slice(n,i+1)).pluck("Username").filter(a=>a!==e.security.user.Username).value();e.neighborsBets=_.filter(e.gameBets,e=>o.includes(e.User.Username))})})),e.updateGame=(()=>{angular.isDefined(i.Stadium.Games)&&null!=i.Stadium.Games&&delete i.Stadium.Games,e.game.IntegrationsData=m.mapEntries(m.compactEntries(e.integrationsData)),e.updateGamePromise=e.game.update().then(e=>{l.success("Game was updated successfully"),s.setGame(e.data)}).catch(e=>{l.error("Failed to update game, please try again"),a.error("Error updating game",e)})}),e.updateBet=(()=>{-1!==e.userBet.BetId?e.updateBetPromise=e.userBet.update().then(e=>{l.success("Bet was updated successfully"),n.setBet(e)}).catch(e=>{l.error("Failed to update bet, please try again"),a.error("Error updating bet",e)}):n.addBet(e.userBet).then(t=>{a.log("GameCtrl: Bet "+t.BetId+" was added"),e.userBet=t,l.success("Bet was added successfully")},e=>{l.error("Failed to add bet, please try again"),a.error("Error adding bet",e)})}),e.simulateGame=(()=>{a.debug("GameCtrl: simulating game"),e.simulateGamePromise=s.simulateGame(e.game.GameId,e.simulatedGame).then(a=>{e.users=a,l.success("Table updated with simulation result")}).catch(e=>{l.error("Failed to simulate game, please try again"),a.error("Error simulating game",e)})}),e.sort=(t=>{a.debug("GameCtrl: sorting by "+t),e.gameBets=_.sortBy(e.gameBets,e=>{switch(t){case"points":return e.Points;case"cards":return e.CardsMark;case"corners":return e.CornersMark;case"user":return e.User.FirstName+e.User.LastName;case"result":return e.HomeScore+"-"+e.AwayScore}})}),e.gridOptions={...t.TABLE_GRID_OPTIONS,data:"users",onRegisterApi:a=>{e.gridApi=a,e.gridApi.colResizable.on.columnSizeChanged(e,h),e.gridApi.core.on.columnVisibilityChanged(e,h),e.gridApi.core.on.sortChanged(e,h)}},e.getTableHeight=(()=>{var t=30*(e.users?e.users.length:0)+30;return a.debug("Total Height: "+t),{height:t+"px"}}),e.goToUser=(e=>{u.path(e.entity.getUrl())}),e.getUserPlace=(a=>e.usersMap.get(a.Username).Place),e.$watch("simulatedGame",()=>{e.users=void 0},!0),e.loadTeamsForm=(()=>{e.teamsForm={},e.getTeamGamesPromise=s.getTeamGames(e.game.HomeTeam.TeamId).then(a=>{v(a,e.game.HomeTeam.TeamId)}).catch(e=>{l.error("Failed to get teams form"),a.error("Failed to get teams form",e)}),s.getTeamGames(e.game.AwayTeam.TeamId).then(a=>{v(a,e.game.AwayTeam.TeamId)}).catch(e=>{l.error("Failed to get teams form"),a.error("Failed to get teams form",e)})}),e.loadTeamsForm()}]),angular.module("mundialitoApp").controller("GamesCtrl",["$scope","$log","GamesManager","games","teams","StadiumsManager","Alert",function(e,a,t,r,s,n,i){e.newGame=null,e.gamesFilter="Open",e.gamesToggle=!1,e.games=r,e.teams=s,e.changed=(()=>{"Open"===e.gamesFilter?e.gamesFilter="All":e.gamesFilter="Open"}),n.loadAllStadiums().then(function(a){e.stadiums=a}),e.addNewGame=function(){$(".selectpicker").selectpicker("refresh"),e.newGame=t.getEmptyGameObject()},e.saveNewGame=function(){e.addGamePromise=t.addGame(e.newGame).then(a=>{i.success("Game was added successfully"),e.newGame=t.getEmptyGameObject(),e.games.push(a)})},e.isPendingUpdate=function(e){return e.IsPendingUpdate},e.updateGame=function(a){angular.isDefined(a.Stadium.Games)&&null!=a.Stadium.Games&&delete a.Stadium.Games,e.editGamePromise=a.update().then(e=>{i.success("Game was updated successfully"),t.setGame(e)})}}]),angular.module("mundialitoApp").factory("GamesManager",["$http","$q","Game","$log","MundialitoUtils","User",function(e,a,t,r,s,n){var i=void 0,o=void 0;return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("GamesManager: updating existing instance of game "+e),s.setData(a)):(r.debug("GamesManager: saving new instance of game "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("GamesManager: will fetch game "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("GamesManager: Instance was loaded at "+a.LoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("GamesManager: will fetch game "+a+" from server"),e.get("api/games/"+a,{tracker:"getGame"}).then(e=>{var a=s._retrieveInstance(e.data.GameId,e.data);t.resolve(a)}).catch(()=>{t.reject()})},getEmptyGameObject:function(){return{HomeTeam:"",AwayTeam:"",Date:"",Stadium:""}},addGame:function(t){var s=a.defer();angular.isObject(t.AwayTeam)||(t.AwayTeam=angular.fromJson(t.AwayTeam)),angular.isObject(t.HomeTeam)||(t.HomeTeam=angular.fromJson(t.HomeTeam)),angular.isObject(t.Stadium)||(t.Stadium=angular.fromJson(t.Stadium));var n=this;return r.debug("GamesManager: will add new game - "+angular.toJson(t)),e.post("api/games",t,{tracker:"addGame"}).then(e=>{var a=n._retrieveInstance(e.data.GameId,e.data);s.resolve(a)}).catch(function(){s.reject()}),s.promise},getGame:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},loadAllGames:function(){if(i)return i;var t=a.defer(),s=this;return r.debug("GamesManager: will fetch all games from server"),e.get("api/games",{tracker:"getGames"}).then(e=>{var a=[];e.data.forEach(e=>{var t=s._retrieveInstance(e.GameId,e);a.push(t)}),t.resolve(a)}).catch(()=>{t.reject()}),i=t.promise,t.promise},loadOpenGames:function(){if(o)return o;var t=a.defer(),s=this;return r.debug("GamesManager: will fetch all open games from server"),e.get("api/games/open",{tracker:"getOpenGames"}).then(e=>{var a=[];e.data.forEach(e=>{var t=s._retrieveInstance(e.GameId,e);a.push(t)}),t.resolve(a)}).catch(()=>{t.reject()}),o=t.promise,t.promise},getTeamGames:function(t){var s=a.defer(),n=this;return r.debug("GamesManager: will fetch all games of team "+t+" from server"),e.get("api/teams/"+t+"/games",{tracker:"getTeamGames"}).then(e=>{var a=[];e.data.forEach(e=>{var t=n._retrieveInstance(e.GameId,e);a.push(t)}),s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},getStadiumGames:function(t){var s=a.defer(),n=this;return r.debug("GamesManager: will fetch all games in stadium "+t+" from server"),e.get("api/games/Stadium/"+t,{tracker:"getStadiumGames"}).then(function(e){var a=[];e.data.forEach(e=>{var t=n._retrieveInstance(e.GameId,e);a.push(t)}),s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},simulateGame:function(t,s){var i=a.defer();return r.debug("GamesManager: will simulate game "+t),e.post("api/games/"+t+"/simulate",s,{tracker:"simulateGame"}).then(e=>{var a=[];e.data.forEach(e=>{a.push(new n(e))}),i.resolve(a)}).catch(e=>{i.reject(e)}),i.promise},setGame:function(e){r.debug("GamesManager: will set game "+e.GameId+" to -"+angular.toJson(e));var a=this._search(e.GameId);return a?a.setData(e):a=this._retrieveInstance(e.GameId,e),a}}}]),angular.module("mundialitoApp").directive("mundialitoGames",["Alert",function(e){return{restrict:"E",scope:{games:"=info",gamesType:"=filter",showOnly:"=",onAdd:"&"},templateUrl:"App/Games/gamesTemplate.html",link:a=>{a.allGames=a.games,a.$watch("gamesType",function(e){a.games=e&&"All"!==e?a.games.filter(e=>e.IsOpen):a.allGames}),a.deleteGame=(t=>{var r=t;t.delete().then(()=>{e.success("Game was deleted successfully"),a.games.splice(a.games.indexOf(r),1)})})}}}]),angular.module("mundialitoApp").factory("Alert",["toaster","$log","$rootScope",function(e,a,t){return{success:function(a){e.pop("success","Success",a)},error:function(a,t){e.pop("error",t||"Error",a)},note:function(a){e.pop("note","Info",a)}}}]),angular.module("mundialitoApp").factory("ErrorHandler",["$rootScope","$log","Alert","$location","Constants",function(e,a,t,r,s){return this.handle=((e,n,i,o)=>{if(a.log(e),!o.ignoreError){if(401===n)return localStorage.removeItem("accessToken"),sessionStorage.removeItem("accessToken"),void r.path(s.LOGIN_PATH);var l=[],u=void 0;e.Message&&(u=e.Message),e.errors&&angular.forEach(e.errors,e=>{angular.forEach(e,e=>{l.push(e)})}),e.ModelState&&angular.forEach(e.ModelState,function(e){l.push(e)}),e.ExceptionMessage&&l.push(e.ExceptionMessage),e.error_description&&l.push(e.error_description),0!==l.length||u||(u="General Error",l.push("Looks like the server is down, please try again in few minutes")),t.error(l.join("\n"),u)}}),this}]).factory("myHttpInterceptor",["ErrorHandler","$q",function(e,a){return{response:function(e){return e},responseError:function(t){return e.handle(t.data,t.status,t.headers,t.config),a.reject(t)}}}]),angular.module("mundialitoApp").factory("MundialitoUtils",["Constants",function(e){return{shouldRefreshInstance:a=>{return!(!angular.isDefined(a.LoadTime)||!angular.isDate(a.LoadTime))&&(new Date).getTime()-a.LoadTime.getTime()>e.REFRESH_TIME},shortName:e=>{if(-1!==e.indexOf(" ")){let a=e.split(" ");return a[0].substring(0,1)+"."+a[1].substring(0,1)}return e.substring(0,1)},getGameMark:(e,a)=>e.HomeTeam.TeamId===a?e.HomeScore>e.AwayScore?{game:e.GameId,mark:"W"}:e.HomeScoree.AwayScore?{game:e.GameId,mark:"L"}:e.HomeScore({restrict:"E",scope:{team:"=",style:"="},templateUrl:"App/General/teamFlagTemplate.html",link:a=>{a.useFlagsCss=e.mundialitoApp.clientConfig.UseFlagsCss}})]),angular.module("mundialitoApp").factory("GeneralBet",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)},update:function(){return a.debug("General Bet: Will update general bet "+this.GeneralBetId),e.put("api/generalbets/"+this.GeneralBetId,this,{tracker:"updateGeneralBet"})},resolve:function(){a.debug("General Bet: Will resolve general bet "+this.GeneralBetId);var t={TeamIsRight:this.TeamIsRight||!1,PlayerIsRight:this.PlayerIsRight||!1};return e.put("api/generalbets/"+this.GeneralBetId+"/resolve",t,{tracker:"resolveGeneralBet"})}},t}]),angular.module("mundialitoApp").factory("GeneralBetsManager",["$http","$q","GeneralBet","$log","MundialitoUtils",function(e,a,t,r,s){return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("GeneralBetsManager: updating existing instance of bet "+e),s.setData(a)):(r.debug("GeneralBetsManager: saving new instance of bet "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("GeneralBetsManager: will fetch bet "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("GeneralBetsManager: Instance was loaded at "+a.LoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("GeneralBetsManager: will fetch bet "+a+" from server"),e.get("api/generalbets/"+a,{tracker:"getGeneralBet"}).then(e=>{var a=s._retrieveInstance(e.data.GeneralBetId,e.data);t.resolve(a)}).catch(e=>{t.reject(e)})},addGeneralBet:function(t){var s=a.defer(),n=this;return r.debug("GeneralBetsManager: will add new bet - "+angular.toJson(t)),e.post("api/generalbets/",t,{tracker:"addGeneralBet"}).then(e=>{var a=n._retrieveInstance(e.data.GeneralBetId,e.data);s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},getGeneralBet:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},loadAllGeneralBets:function(){var t=a.defer(),s=this;return r.debug("GeneralBetsManager: will fetch all general bets from server"),e.get("api/generalbets",{tracker:"getGeneralBets"}).then(e=>{var a=[];e.data.forEach(e=>{var t=s._retrieveInstance(e.GeneralBetId,e);a.push(t)}),t.resolve(a)}).catch(e=>{t.reject(e)}),t.promise},hasGeneralBet:function(t){var s=a.defer();return r.debug("GeneralBetsManager: will check if user "+t+" has general bets"),e.get("api/generalbets/has-bet/"+t,{tracker:"getUserGeneralBet"}).then(e=>{s.resolve(e.data)}).catch(e=>{s.reject(e)}),s.promise},canSubmtiGeneralBet:function(){var t=a.defer();return r.debug("GeneralBetsManager: will check if user general bets are closed"),e.get("api/generalbets/cansubmitbets/",{tracker:"getCanSubmitGeneralBets"}).then(e=>{t.resolve(e.data)}).catch(e=>{t.reject(e)}),t.promise},getUserGeneralBet:function(t){var s=a.defer(),n=this;return r.debug("GeneralBetsManager: will fetch user "+t+" general bet from server"),e.get("api/generalbets/user/"+t,{tracker:"getUserGeneralBet"}).then(e=>{var a=n._retrieveInstance(e.data.GeneralBetId,e.data);s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},setGeneralBet:function(e){r.debug("GeneralBetsManager: will set bet "+e.GeneralBetId+" to -"+angular.toJson(e));var a=this._search(e.GeneralBetId);return a?a.setData(e):a=this._retrieveInstance(e.GeneralBetId,e),a}}}]),angular.module("mundialitoApp").factory("Player",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)}},t}]),angular.module("mundialitoApp").factory("PlayersManager",["$http","$q","Player","$log",function(e,a,t,r){var s=void 0;return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("playersPromise: updating existing instance of player "+e),s.setData(a)):(r.debug("playersPromise: saving new instance of player "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},getPlayerSchema:function(){return[{property:"Name",label:"Name",type:"text",attr:{required:!0}}]},loadAllPlayers:function(){if(s)return s;var t=a.defer(),n=this;return r.debug("PlayersManager: will fetch all players from server"),e.get("api/players",{tracker:"getPlayers",cache:!0}).then(e=>{var a=[];e.data.forEach(e=>{var t=n._retrieveInstance(e.PlayerId,e);a.push(t)}),t.resolve(a)}).catch(e=>{t.reject(e)}),s=t.promise,t.promise}}}]),angular.module("mundialitoApp").factory("Stadium",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)},delete:function(){if(confirm("Are you sure you would like to delete stadium "+this.Name))return a.debug("Stadium: Will delete stadium "+this.StadiumId),e.delete("api/stadiums/"+this.StadiumId,{tracker:"deleteStadium"})},update:function(){a.debug("Stadium: Will update stadium "+this.StadiumId);var t={};return angular.copy(this,t),delete t.Games,e.put("api/stadiums/"+this.StadiumId,t,{tracker:"editStadium"})},getUrl:function(){return"/stadiums/"+this.StadiumId}},t}]),angular.module("mundialitoApp").controller("StadiumCtrl",["$scope","$log","StadiumsManager","GamesManager","stadium","Alert",function(e,a,t,r,s,n){e.stadium=s,e.showEditForm=!1,e.getStadiumGamesPromise=r.getStadiumGames(e.stadium.StadiumId).then(t=>{a.debug("StadiumCtrl: Got games of stadium"),e.games=t}),e.updateStadium=(()=>{e.editStadiumPromise=e.stadium.update().then(()=>{n.success("Stadium was updated successfully")})}),e.schema=t.getStaidumSchema()}]),angular.module("mundialitoApp").controller("StadiumsCtrl",["$scope","$log","StadiumsManager","stadiums","Alert",function(e,a,t,r,s){e.stadiums=r,e.showNewStadium=!1,e.newStadium=null,e.addNewStadium=(()=>{e.newStadium=t.getEmptyStadiumObject()}),e.saveNewStadium=(()=>{t.addStadium(e.newStadium).then(a=>{s.success("Stadium was added successfully"),e.newStadium=null,e.stadiums.push(a)})}),e.deleteStadium=(a=>{var t=a;a.delete().then(()=>{s.success("Stadium was deleted successfully"),e.stadiums.splice(e.stadiums.indexOf(t),1)})}),e.schema=t.getStaidumSchema()}]),angular.module("mundialitoApp").factory("StadiumsManager",["$http","$q","Stadium","$log","MundialitoUtils",function(e,a,t,r,s){var n=void 0;return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("StadiumsManager: updating existing instance of stadium "+e),s.setData(a)):(r.debug("StadiumsManager: saving new instance of stadium "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("StadiumsManager: will fetch stadium "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("StadiumsManager: Instance was loaded at "+a.LoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("StadiumsManager: will fetch stadium "+a+" from server"),e.get("api/stadiums/"+a,{tracker:"getStadium"}).then(e=>{var a=s._retrieveInstance(e.data.StadiumId,e.data);t.resolve(a)}).catch(e=>{t.reject(e)})},getStaidumSchema:function(){return[{property:"Name",label:"Name",type:"text",attr:{required:!0}},{property:"City",label:"City",type:"text",attr:{required:!0}},{property:"Capacity",label:"Capacity",type:"number",attr:{required:!0}}]},getEmptyStadiumObject:function(){return{HomeTeam:"",AwayTeam:""}},addStadium:function(t){var s=a.defer(),n=this;return r.debug("StadiumsManager: will add new stadium - "+angular.toJson(t)),e.post("api/stadiums",t,{tracker:"addStadium"}).then(e=>{var a=n._retrieveInstance(e.data.StadiumId,e.data);s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},getStadium:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},loadAllStadiums:function(){if(n)return n;var t=a.defer(),s=this;return r.debug("StadiumsManager: will fetch all games from server"),e.get("api/stadiums",{tracker:"getStadiums",cache:!0}).then(e=>{var a=[];e.data.forEach(e=>{var t=s._retrieveInstance(e.StadiumId,e);a.push(t)}),t.resolve(a)}).catch(e=>{t.reject(e)}),n=t.promise,t.promise},setStadium:function(e){r.debug("StadiumsManager: will set stadium "+e.StadiumId+" to -"+angular.toJson(e));var a=this._search(e.StadiumId);return a?a.setData(e):a=this._retrieveInstance(e.StadiumId,e),a}}}]),angular.module("mundialitoApp").factory("Team",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e),this.Logo=this.Logo.toLowerCase(),this.Flag=this.Flag.toLowerCase()},delete:function(){if(confirm("Are you sure you would like to delete team "+this.Name))return a.debug("Team: Will delete team "+this.TeamId),e.delete("api/teams/"+this.TeamId,{tracker:"deleteTeam"})},update:function(){return a.debug("Team: Will update game "+this.TeamId),e.put("api/teams/"+this.TeamId,this,{tracker:"editTeam"})},getUrl:function(){return"/teams/"+this.TeamId}},t}]),angular.module("mundialitoApp").controller("TeamCtrl",["$scope","$log","TeamsManager","team","games","Alert","PluginsProvider","MundialitoUtils",function(e,a,t,r,s,n,i,o){e.team=r,e.games=s,e.plugins={},e.teamsForm={},e.showEditForm=!1,e.toKeyValue=(e=>_.keys(e).map(a=>({name:a,value:e[a]}))),e.IntegrationsData=e.toKeyValue(e.team.IntegrationsData),e.fromKeyValue=(e=>{let a={};return e.forEach(e=>{""!==e.name&&(a[e.name]=e.value)}),a});const l=_.chain(e.games).sortBy(e=>new Date(e.Date)).filter(e=>e.IsBetResolved).map(a=>o.getGameMark(a,e.team.TeamId)).value();e.teamsForm[e.team.TeamId]={form:l,games:_.filter(e.games,e=>e.IsBetResolved)},i.getTeamDetailsFromAll(e.team).then(a=>{a.forEach(a=>{e.plugins[a.property]={data:a.data,template:a.template}})}),e.updateTeam=(()=>{e.team.IntegrationsData=e.fromKeyValue(e.IntegrationsData),e.editTeamPromise=e.team.update().then(e=>{n.success("Team was updated successfully"),t.setTeam(e.data)})}),e.schema=t.getTeamSchema()}]),angular.module("mundialitoApp").controller("TeamsCtrl",["$scope","$log","TeamsManager","teams","Alert",function(e,a,t,r,s){e.teams=r,e.showNewTeam=!1,e.newTeam=null,e.addNewTeam=function(){$(".selectpicker").selectpicker("refresh"),e.newTeam=t.getEmptyTeamObject()},e.saveNewTeam=function(){t.addTeam(e.newTeam).then(function(a){s.success("Team was added successfully"),e.newTeam=null,e.teams.push(a)})},e.deleteTeam=function(a){var t=a;a.delete().then(()=>{s.success("Team was deleted successfully"),e.teams.splice(e.teams.indexOf(t),1)})},e.schema=t.getTeamSchema()}]),angular.module("mundialitoApp").factory("TeamsManager",["$http","$q","Team","$log","MundialitoUtils",function(e,a,t,r,s){return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("TeamsManager: updating existing instance of team "+e),s.setData(a)):(r.debug("TeamsManager: saving new instance of team "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("TeamsManager: will fetch team "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("TeamsManager: Instance was loaded at "+instanceLoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("TeamsManager: will fetch team "+a+" from server"),e.get("api/teams/"+a,{tracker:"getTeam"}).then(e=>{var a=s._retrieveInstance(e.data.TeamId,e.data);t.resolve(a)}).catch(e=>{t.reject(e)})},getTeamSchema:function(){return[{property:"Name",label:"Name",type:"text",attr:{required:!0}},{property:"Flag",label:"Flag",type:"url",attr:{required:!0}},{property:"TeamPage",label:"TeamPage",type:"url",attr:{required:!1}},{property:"Logo",label:"Logo",type:"url",attr:{required:!0}},{property:"ShortName",label:"Short Name",type:"text",attr:{ngMaxlength:3,ngMinlength:3,required:!0}},{property:"TournamentTeamId",label:"Tournament Team Id",type:"number",attr:{required:!1}}]},getEmptyTeamObject:function(){return{Name:"",Flag:"",Logo:"",ShortName:"",TournamentTeamId:null,TeamPage:null}},addTeam:function(t){var s=a.defer(),n=this;return r.debug("TeamsManager: will add new team - "+angular.toJson(t)),e.post("api/teams",t,{tracker:"addTeam"}).then(e=>{var a=n._retrieveInstance(e.data.TeamId,e.data);s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},getTeam:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},loadAllTeams:function(){var t=a.defer(),s=this;return r.debug("TeamsManager: will fetch all teams from server"),e.get("api/teams",{tracker:"getTeams",cache:!0}).then(e=>{var a=[];e.data.forEach(e=>{var t=s._retrieveInstance(e.TeamId,e);a.push(t)}),t.resolve(a)}).catch(e=>{t.reject(e)}),t.promise},setTeam:function(e){r.debug("TeamsManager: will set team "+e.TeamId+" to -"+angular.toJson(e));var a=this._search(e.TeamId);return a?a.setData(e):a=this._retrieveInstance(e.TeamId,e),a}}}]),angular.module("mundialitoApp").controller("ManageAppCtrl",["$scope","$log","Alert","users","teams","generalBets","UsersManager","players",function(e,a,t,r,s,n,i,o){e.users=r,e.generalBets=n,e.deleteUser=(a=>{var r=a;e.deleteUserPromise=a.delete().then(()=>{t.success("User was deleted successfully"),e.users.splice(e.users.indexOf(r),1)})}),e.resolveBet=(a=>{e.resolveGeneralBetPromise=a.resolve().then(()=>{t.success("General bet was resolved successfully")})}),e.makeAdmin=(e=>{e.makeAdmin().then(()=>{t.success("User is now admin"),e.Roles="Admin"})}),e.activate=(e=>{e.activate().then(()=>{t.success("User was activated successfully")})}),e.deactivate=(e=>{e.deactivate().then(()=>{t.success("User was deactivated successfully")})})}]),angular.module("mundialitoApp").factory("User",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)},getUrl:function(){return"/users/"+this.Username},delete:function(){if(confirm("Are you sure you would like to delete user "+this.Username))return a.debug("User: Will delete user "+this.Username),e.delete("api/users/"+this.Id,{tracker:"deleteUser"})},makeAdmin:function(){if(confirm("Are you sure you would like to make "+this.Name+" Admin?"))return a.debug("User: Will make user "+this.Username+" admin"),e.post("api/users/makeadmin/"+this.Id,{tracker:"makeAdmin"})},activate:function(){if(confirm("Are you sure you would like to activate "+this.Name))return a.debug("User: Will actiavte user "+this.Username),e.post("api/users/"+this.Id+"/activate")},deactivate:function(){if(confirm("Are you sure you would like to deactiavte "+this.Name))return a.debug("User: Will deactiavte user "+this.Username),e.delete("api/users/"+this.Id+"/activate")}},t}]),angular.module("mundialitoApp").controller("UserProfileCtrl",["$scope","$log","UsersManager","Alert","GeneralBetsManager","profileUser","userGameBets","teams","generalBetsAreOpen","players",function(e,a,t,r,s,n,i,o,l,u){e.profileUser=n,e.userGameBets=i,e.teams=o,e.players=u,e.noGeneralBetWasSubmitted=!1,e.generalBetsAreOpen=!0===l,a.debug("UserProfileCtrl: generalBetsAreOpen = "+l),e.alreadyFollow=e.security.user.Followees.includes(e.profileUser.Username),e.isLoggedUserProfile=(()=>{var t=null!=e.security.user&&e.security.user.Username===e.profileUser.Username;return a.debug("UserProfileCtrl: isLoggedUserProfile = "+t),null!=e.security.user&&e.security.user.Username===e.profileUser.Username}),e.isGeneralBetClosed=(()=>{var t=!e.generalBetsAreOpen;return a.debug("UserProfileCtrl: isGeneralBetClosed = "+t),t}),e.isGeneralBetReadOnly=(()=>{var t=!e.isLoggedUserProfile()||e.isGeneralBetClosed();return a.debug("UserProfileCtrl: isGeneralBetReadOnly = "+t),t}),e.shoudLoadGeneralBet=(()=>{var t=e.isLoggedUserProfile()||e.isGeneralBetClosed();return a.debug("UserProfileCtrl: shoudLoadGeneralBet = "+t),t}),e.shoudLoadGeneralBet()&&(e.generalBetsPromise=s.hasGeneralBet(e.profileUser.Username).then(t=>{if(a.debug("UserProfileCtrl: hasGeneralBet = "+t),!0===t)s.getUserGeneralBet(e.profileUser.Username).then(t=>{a.info("UserProfileCtrl: got user general bet - "+angular.toJson(t)),e.generalBet=t});else{if(e.generalBet={},e.isGeneralBetClosed())return void(e.noGeneralBetWasSubmitted=!0);if(e.isLoggedUserProfile()&&!e.isGeneralBetClosed())return;e.noGeneralBetWasSubmitted=!0}})),e.saveGeneralBet=(()=>{angular.isDefined(e.generalBet.GeneralBetId)?e.generalBetsPromise=e.generalBet.update().then(()=>{r.success("General Bet was updated successfully")},()=>{r.error("Failed to update General Bet, please try again")}):e.generalBetsPromise=s.addGeneralBet(e.generalBet).then(t=>{a.log("UserProfileCtrl: General Bet "+t.GeneralBetId+" was added"),e.generalBet=t,r.success("General Bet was added successfully")},()=>{r.error("Failed to add General Bet, please try again")})}),e.social=(()=>{e.alreadyFollow?t.unfollow(e.profileUser.Username).then(()=>{e.alreadyFollow=!1;const a=e.security.user.Followees.indexOf(e.profileUser.Username);e.security.user.Followees.splice(a,1),r.success("You no longer following "+e.profileUser.Username)}).catch(a=>{r.error("Failed to unfollow "+e.profileUser.Username+": "+a)}):t.follow(e.profileUser.Username).then(()=>{e.alreadyFollow=!0,e.security.user.Followees.push(e.profileUser.Username),r.success("You are now following "+e.profileUser.Username)}).catch(a=>{r.error("Failed to follow "+e.profileUser.Username+": "+a)})}),e.getSocialPromise=t.getSocial(e.profileUser.Username).then(t=>{a.log("UserProfileCtrl: Got social response"),e.followers=t.followers,e.followees=t.followees}),e.isLoggedUserProfile()?e.getStatsPromise=t.getMyStats().then(a=>{e.performance=a}).catch(e=>{a.error("Failed to get user slef statistics",e),r.error("Failed to fetch user statistics: "+e)}):e.getStatsPromise=t.getStats(e.profileUser.Username).then(a=>{e.performance=a}).catch(e=>{a.error("Failed to get user statistics",e),r.error("Failed to fetch user statistics: "+e)}),e.security.user.Username===e.profileUser.Username?e.compareUsersPromise=t.getUserProgess(e.security.user.Username):e.compareUsersPromise=t.compareUsers(e.security.user.Username,e.profileUser.Username),e.compareUsersPromise.then(a=>{if(a.length>0){let r=_.map(a[0].Entries,e=>e.Name);var t=_.map(r,e=>({id:e,label:e,type:"number"}));t.unshift({id:"date",label:"Date",type:"date"});let s=_.map(a,e=>{var a={c:[{v:new Date(e.Date)}]};return _.each(e.Entries,e=>{a.c.push({v:e.Place})}),a});e.chart={type:"LineChart",data:{cols:t,rows:s},options:{colors:["#0000FF","#009900","#CC0000","#DD9900"],defaultColors:["#0000FF","#009900","#CC0000","#DD9900"],displayExactValues:!0,is3D:!0,backgroundColor:{fill:"transparent"},vAxis:{title:"Place"},hAxis:{title:"Date"}}}}}).catch(e=>{a.error("Failed to compare users",e),r.error("Failed to compare users: "+e)}),e.capture=(()=>{html2canvas(document.body).then(a=>{var t=a.toDataURL("image/png"),r=document.createElement("a");r.href=t,r.download=e.profileUser.Username+".png",document.body.appendChild(r),r.click(),document.body.removeChild(r)})})}]),angular.module("mundialitoApp").factory("UsersManager",["$http","$q","User","$log","MundialitoUtils",function(e,a,t,r,s){var n=void 0;return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("UsersManager: updating existing instance of user "+e),s.setData(a)):(r.debug("UsersManager: saving new instance of user "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("UsersManager: will fetch user "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("UsersManager: Instance was loaded at "+a,LoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("UsersManager: will fetch user "+a+" from server"),e.get("api/users/"+a,{tracker:"getUser"}).then(e=>{var a=s._retrieveInstance(e.data.Username,e.data);t.resolve(a)}).catch(e=>{t.reject(e)})},getUser:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},getSocial:a=>(r.debug("UsersManager: will fetch followers and followees of user "+a),e.get("api/users/"+a+"/followees",{tracker:"getSocial"}).then(t=>e.get("api/users/"+a+"/followers",{tracker:"getSocial"}).then(e=>({followers:e.data,followees:t.data})))),compareUsers:(a,t)=>(r.debug("UsersManager: will compare users: "+a+" and "+t),e.get("api/users/compare/"+a+"/"+t).then(e=>e.data)),getUserProgess:()=>(r.debug("UsersManager: will get user progress"),e.get("api/users/me/progress").then(e=>e.data)),getMyStats:()=>(r.debug("UsersManager: will the stats of logged user"),e.get("api/stats/me",{tracker:"getStats"}).then(e=>e.data)),getStats:a=>(r.debug("UsersManager: will the stats of "+a),e.get("api/stats/"+a,{tracker:"getStats"}).then(e=>e.data)),follow:a=>(r.debug("UsersManager: will follow "+a),e.post("api/users/follow/"+a,void 0,{tracker:"follow"})),unfollow:a=>(r.debug("UsersManager: will unfollow "+a),e.delete("api/users/follow/"+a,void 0,{tracker:"unfollow"})),loadAllUsers:function(){if(n)return n;var t=a.defer(),s=this;return r.debug("UsersManager: will fetch all users from server"),e.get("api/users",{tracker:"getUsers"}).then(e=>{var a=[];e.data.forEach(function(e){var t=s._retrieveInstance(e.Username,e);a.push(t)}),t.resolve(a)}).catch(e=>{t.reject(e)}),n=t.promise,t.promise},setUser:function(e){r.debug("UsersManager: will set user "+e.Username+" to -"+angular.toJson(e));var a=this._search(e.Username);return a?a.setData(e):a=this._retrieveInstance(e.Username,e),a}}}]),angular.module("mundialitoApp").factory("FootballDataGamePlugin",["$q","$rootScope","GenericProxyService",function(e,a,t){var r="https://api.football-data.org/v4/matches/";const s="football-data";return{getGameDetails:function(n){var i=r+n.IntegrationsData[s];return a.mundialitoApp.clientConfig&&a.mundialitoApp.clientConfig["football-data-api-key"]?t.proxyRequest("GET",i,void 0,{"X-Auth-Token":a.mundialitoApp.clientConfig["football-data-api-key"]}).then(e=>({data:e,property:"odds",template:"App/General/Plugins/FootballDataGameTemplate.html"})).catch(a=>e.reject(a)):e.reject("Skipping football-data as no api key provided")},integrationKey:s}}]),angular.module("mundialitoApp").factory("FootballDataTeamStatsPlugin",["$q","$rootScope","GenericProxyService",function(e,a,t){var r="https://api.football-data.org/v4/teams/";const s="football-data";function n(e){return(new Date).getFullYear()-parseInt(e.substring(0,4),10)}return{getTeamDetails:function(i){var o=r+i.IntegrationsData[s];return a.mundialitoApp.clientConfig&&a.mundialitoApp.clientConfig["football-data-api-key"]?t.proxyRequest("GET",o,void 0,{"X-Auth-Token":a.mundialitoApp.clientConfig["football-data-api-key"]}).then(e=>(e.coach.age=n(e.coach.dateOfBirth),e.squad.forEach(e=>{e.age=n(e.dateOfBirth),e.icon="goalkeeper"===e.position.toLowerCase()?"goalkeeper":"player"}),{data:e,property:"team-squad",template:"App/General/Plugins/FootballDataTeamStatsTemplate.html"})).catch(a=>e.reject(a)):e.reject("Skipping football-data as no api key provided")},integrationKey:s}}]),angular.module("mundialitoApp").factory("GenericProxyService",["$http","$q",function(e,a){var t="api/genericproxy";return{proxyRequest:function(r,s,n,i){var o=a.defer();return e({method:r,url:t+"?url="+s,data:n,headers:i,ignoreError:!0}).then(e=>{o.resolve(e.data)}).catch(e=>{o.reject(e)}),o.promise}}}]),angular.module("mundialitoApp").factory("PluginsProvider",["$q","$log",function(e,a){var t=[],r=[];return{getGameDetailsFromAll:function(r){let s=[];r.IntegrationsData&&(s=_.filter(t,e=>void 0!==r.IntegrationsData[e.integrationKey]));var n=s.map(e=>e.getGameDetails(r));return e.all(n).then(e=>e).catch(t=>(a.warn("Error fetching game details: "+t),e.reject(t)))},getTeamDetailsFromAll:function(t){let s=[];t.IntegrationsData&&(s=_.filter(r,e=>void 0!==t.IntegrationsData[e.integrationKey]));var n=s.map(e=>e.getTeamDetails(t));return e.all(n).then(e=>e).catch(t=>(a.warn("Error fetching team details: "+t),e.reject(t)))},registerGameFactory:e=>{t.push(e)},registerTeamFactory:e=>{r.push(e)}}}]); \ No newline at end of file diff --git a/Mundialito/wwwroot/js/app-min-edab6c6f8348e96ec77828311e34fb09.js b/Mundialito/wwwroot/js/app-min-edab6c6f8348e96ec77828311e34fb09.js deleted file mode 100644 index 61aabbd..0000000 --- a/Mundialito/wwwroot/js/app-min-edab6c6f8348e96ec77828311e34fb09.js +++ /dev/null @@ -1 +0,0 @@ -angular.module("mundialitoApp",["key-value-editor","security","ngSanitize","ngRoute","ngAnimate","ui.bootstrap","autofields.bootstrap","cgBusy","ajoslin.promise-tracker","ui.select","ui.bootstrap.datetimepicker","ui.grid","ui.grid.autoResize","googlechart","toaster","ui.grid.saveState","ui.grid.resizeColumns","ui.toggle"]).value("cgBusyTemplateName","App/Partials/angular-busy.html").config(["$routeProvider","$httpProvider","$locationProvider","$parseProvider","securityProvider","Constants",function(e,a,t,r,s,n){t.html5Mode(!0),a.defaults.headers.common["X-Requested-With"]="XMLHttpRequest",a.interceptors.push("myHttpInterceptor"),s.urls.login=n.LOGIN_PATH,s.usePopups=!1,e.when("/",{templateUrl:"App/Dashboard/Dashboard.html",controller:"DashboardCtrl",resolve:{teams:["TeamsManager",e=>e.loadAllTeams()],players:["PlayersManager",e=>e.loadAllPlayers()]}}).when("/bets_center",{templateUrl:"App/Bets/BetsCenter.html",controller:"BetsCenterCtrl",resolve:{games:["GamesManager",e=>e.loadOpenGames()]}}).when("/users/:username",{templateUrl:"App/Users/UserProfile.html",controller:"UserProfileCtrl",resolve:{profileUser:["$route","UsersManager",(e,a)=>{var t=e.current.params.username;return a.getUser(t,!0)}],userGameBets:["$route","BetsManager",(e,a)=>{var t=e.current.params.username;return a.getUserBets(t)}],teams:["TeamsManager",e=>e.loadAllTeams()],generalBetsAreOpen:["GeneralBetsManager",e=>e.canSubmtiGeneralBet()],players:["PlayersManager",e=>e.loadAllPlayers()],allUsers:["UsersManager",e=>e.loadAllUsers()]}}).when("/manage_users",{templateUrl:"App/Users/ManageApp.html",controller:"ManageAppCtrl",resolve:{users:["UsersManager",e=>e.loadAllUsers()],teams:["TeamsManager",e=>e.loadAllTeams()],generalBets:["GeneralBetsManager",e=>e.loadAllGeneralBets()],players:["PlayersManager",e=>e.loadAllPlayers()]}}).when("/teams",{templateUrl:"App/Teams/Teams.html",controller:"TeamsCtrl",resolve:{teams:["TeamsManager",e=>e.loadAllTeams()]}}).when("/teams/:teamId",{templateUrl:"App/Teams/Team.html",controller:"TeamCtrl",resolve:{team:["$route","TeamsManager",(e,a)=>{var t=e.current.params.teamId;return a.getTeam(t)}],games:["$route","GamesManager",(e,a)=>{var t=e.current.params.teamId;return a.getTeamGames(t)}]}}).when("/games/:gameId",{templateUrl:"App/Games/Game.html",controller:"GameCtrl",resolve:{teams:["TeamsManager",e=>e.loadAllTeams()],players:["PlayersManager",e=>e.loadAllPlayers()],game:["$route","GamesManager",(e,a)=>{var t=e.current.params.gameId;return a.getGame(t)}],userBet:["$route","BetsManager",(e,a)=>{var t=e.current.params.gameId;return a.getUserBetOnGame(t)}]}}).when("/games",{templateUrl:"App/Games/Games.html",controller:"GamesCtrl",resolve:{games:["GamesManager",e=>e.loadAllGames()],teams:["TeamsManager",e=>e.loadAllTeams()]}}).when("/stadiums/:stadiumId",{templateUrl:"App/Stadiums/Stadium.html",controller:"StadiumCtrl",resolve:{stadium:["$q","$route","StadiumsManager",(e,a,t)=>{var r=a.current.params.stadiumId;return t.getStadium(r,!0)}]}}).when("/stadiums",{templateUrl:"App/Stadiums/Stadiums.html",controller:"StadiumsCtrl",resolve:{stadiums:["StadiumsManager",e=>e.loadAllStadiums()]}}).when("/login",{templateUrl:"App/Accounts/Login.html"}).when("/forgot",{templateUrl:"App/Accounts/ForgetPassword.html",controller:"ForgetPasswordCtrl"}).when("/reset",{templateUrl:"App/Accounts/ResetPassword.html",controller:"ResetPasswordCtrl"}).when("/join",{templateUrl:"App/Accounts/Register.html"}).when("/manage",{templateUrl:"App/Accounts/Manage.html"}).otherwise({redirectTo:"/"})}]).run(["$rootScope","$log","security","$route","$location","PluginsProvider","FootballDataGamePlugin","FootballDataTeamStatsPlugin",function(e,a,t,r,s,n,i,o){n.registerGameFactory(i),n.registerTeamFactory(o),t.events.login=function(t,r){a.log("Current user details: "+angular.toJson(r)),e.mundialitoApp.authenticating=!1},t.events.reloadUser=function(t,r){a.log("User reloaded"+angular.toJson(r)),e.mundialitoApp.authenticating=!1},t.events.logout=function(e){a.log("User logged out"),e.authenticate()},e.mundialitoApp={params:null,loading:!0,authenticating:!0,message:null},["/reset","/forgot","/join","/login"].includes(s.$$path)||(a.log("Starting authentication"),t.authenticate()),e.security=t,e.$on("$locationChangeStart",function(){a.debug("$locationChangeStart"),e.mundialitoApp.loading=!0}),e.$on("$locationChangeSuccess",function(){a.debug("$locationChangeSuccess"),e.mundialitoApp.params=angular.copy(r.current.params),e.mundialitoApp.loading=!1}),e.$on("$routeChangeStart",function(){a.debug("$routeChangeStart"),e.mundialitoApp.message="Loading..."}),e.$on("$routeChangeSuccess",function(){a.debug("$routeChangeSuccess"),e.mundialitoApp.message=null})}]),angular.module("mundialitoApp").constant("Constants",{LOGIN_PATH:"/login",REFRESH_TIME:3e5,TABLE_GRID_OPTIONS:{saveWidths:!0,saveVisible:!0,saveOrder:!0,enableRowSelection:!1,enableSelectAll:!1,multiSelect:!1,rowTemplate:'
',columnDefs:[{field:"Place",displayName:"",resizable:!1,maxWidth:30},{field:"Name",displayName:"Name",resizable:!0,minWidth:115},{field:"Points",displayName:"Points",resizable:!0,minWidth:45,maxWidth:75},{field:"GeneralBet.WinningTeam",displayName:"Team",resizable:!1,maxWidth:45,cellTemplate:'
'},{field:"GeneralBet.GoldenBootPlayer.Name",displayName:"Player",resizable:!1,minWidth:50,maxWidth:50,cellTemplate:"
{{COL_FIELD.split(' ')[0].charAt(0)}}.{{COL_FIELD.split(' ')[1].charAt(0)}}
"},{field:"Marks",displayName:"Marks",resizable:!0},{field:"Results",displayName:"Results",resizable:!0},{field:"YellowCards",displayName:"Yellow Cards Marks",maxWidth:55,resizable:!1,headerCellTemplate:'
'},{field:"Corners",displayName:"Corners Marks",maxWidth:55,resizable:!1,headerCellTemplate:'
'},,{field:"PlaceDiff",displayName:"",resizable:!1,maxWidth:45,cellTemplate:"
{{::COL_FIELD}}
"}]}}),angular.module("mundialitoApp").controller("ForgetPasswordCtrl",["$scope","$rootScope","security","Alert",function(e,a,t,r){a.mundialitoApp.authenticating=!1;e.user=new function(){return{Email:""}},e.forget=function(){e.emailForm.$valid&&(a.mundialitoApp.message="Processing...",t.forgotPassword(angular.copy(e.user)).then(()=>{r.success("Reset password token was sent to your email, please follow the link from there")}).catch(e=>{r.error("Failed to generate reset password token: "+e)}).finally(function(){a.mundialitoApp.message=null}))},e.schema=[{property:"Email",label:"Email Address",type:"email",attr:{required:!0}}]}]),angular.module("mundialitoApp").controller("LoginCtrl",["$scope","$rootScope","security",function(e,a,t){a.mundialitoApp.authenticating=!1;e.user=new function(){return{username:"",password:"",rememberMe:!1}},e.login=(()=>{e.loginForm.$valid&&(a.mundialitoApp.message="Processing Login...",t.login(angular.copy(e.user)).finally(function(){a.mundialitoApp.message=null}))}),e.schema=[{property:"username",type:"text",attr:{ngMinlength:4,required:!0}},{property:"password",type:"password",attr:{ngMinlength:4,required:!0}},{property:"rememberMe",label:"Keep me logged in",type:"checkbox"}],window.login=(e=>{console.log("Got response from Google: "+e),a.mundialitoApp.message="Processing Login...",t.googleLogin(e).finally(function(){a.mundialitoApp.message=null})}),window.onload=function(){google.accounts.id.initialize({client_id:e.mundialitoApp.GoogleClientId,callback:login}),google.accounts.id.renderButton(document.getElementById("buttonDiv"),{theme:"filled_blue",size:"large",text:"continue_with",shape:"circle"}),google.accounts.id.prompt()}}]),angular.module("mundialitoApp").controller("ManageCtrl",["$scope","Alert",function(e,a){var t=function(){return{oldPassword:"",newPassword:"",confirmPassword:""}};e.changingPassword=null,e.changePassword=function(){e.changingPassword=new t},e.cancel=function(){e.changingPassword=null},e.updatePassword=function(){if(e.manageForm.$valid){var t=angular.copy(e.changingPassword);e.changingPassword=null,e.security.changePassword(t).then(function(){a.success("Password was changed sucessfully")},function(){a.error("Failed to change password"),e.changingPassword=t})}},e.changePasswordSchema=[{property:"oldPassword",type:"password",attr:{required:!0}},{property:"newPassword",type:"password",attr:{ngMinlength:4,required:!0}},{property:"confirmPassword",type:"password",attr:{confirmPassword:"changingPassword.newPassword",required:!0}}]}]),angular.module("mundialitoApp").controller("RegisterCtrl",["$scope","security",function(e,a){e.mundialitoApp.authenticating=!1;e.user=new function(){return{firstname:"",lastname:"",email:"",username:"",password:"",confirmPassword:""}},e.join=function(){e.joinForm.$valid&&(e.isJoinActive=!0,e.mundialitoApp.message="Processing Registration...",a.register(angular.copy(e.user)).finally(function(){e.mundialitoApp.message=null,e.isJoinActive=!1}))},e.schema=[{property:"firstname",label:"First Name",type:"text",attr:{required:!0}},{property:"lastname",label:"Last Name",type:"text",attr:{required:!0}},{property:"email",label:"Email Address",type:"email",attr:{required:!0}},{property:"username",type:"text",attr:{ngMinlength:4,required:!0}},{property:"password",type:"password",attr:{required:!0}},{property:"confirmPassword",label:"Confirm Password",type:"password",attr:{confirmPassword:"user.password",required:!0}}]}]),angular.module("mundialitoApp").controller("ResetPasswordCtrl",["$scope","$rootScope","security","$location","Alert",function(e,a,t,r,s){a.mundialitoApp.authenticating=!1;e.user=new function(){return{confirmPassword:"",password:"",email:r.search().email,token:r.search().token}},e.reset=function(){e.resetForm.$valid&&(a.mundialitoApp.message="Processing Reset Password...",t.resetPassword(angular.copy(e.user)).then(()=>{s.success("Your was was reset successfully")}).finally(function(){a.mundialitoApp.message=null}))},e.schema=[{property:"password",type:"password",attr:{required:!0}},{property:"confirmPassword",label:"Confirm Password",type:"password",attr:{confirmPassword:"user.password",required:!0}}]}]),angular.module("mundialitoApp").factory("Bet",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)},getTeamByCornersMark:function(){return"1"===this.CornersMark?this.Game.HomeTeam:"2"===this.CornersMark?this.Game.AwayTeam:null},getTeamByCardsMark:function(){return"1"===this.CardsMark?this.Game.HomeTeam:"2"===this.CardsMark?this.Game.AwayTeam:null},update:function(){return a.debug("Bet: Will update bet "+this.BetId),e.put("api/bets/"+this.BetId,this,{tracker:"updateBet"})},getGameUrl:function(){return"/games/"+this.Game.GameId},getClass:function(){return this.Points>=7?"success":this.Points>=5?"primary":this.Points>=3?"info":this.Points>0?"warning":"danger"}},t}]),angular.module("mundialitoApp").controller("BetsCenterCtrl",["$scope","$log","$timeout","Alert","BetsManager","games",function(e,a,t,r,s,n){e.games=n,e.bets={};var i=function(){angular.isDefined(e.security.user)&&null!=e.security.user?e.getUserBetsPromise=s.getUserBets(e.security.user.Username).then(t=>{for(var r=0;r{r.success("Bet was updated successfully"),s.setBet(e)}).catch(function(){r.error("Failed to update Bet, please try again")})):(a.debug("BetsCenterCtrl: Will create new bet"),s.addBet(e.bets[t]).then(function(s){a.log("BetsCenterCtrl: Bet "+s.BetId+" was added"),e.bets[t]=s,r.success("Bet was added successfully")}).catch(function(){r.error("Failed to add Bet, please try again")}))},e.shuffleBet=function(t){var r,s,n=["1","X","2"],i=[0,0,0,0,1,1,1,1,2,2,3,3,4,5],o=n[Math.floor(3*Math.random())];do{r=i[Math.floor(Math.random()*i.length)],s=i[Math.floor(Math.random()*i.length)]}while("X"!==o&&r===s);a.debug("Random game mark is "+o),"X"===o&&(s=r),a.debug("Home goals: "+r),a.debug("Away goals: "+s),e.bets[t].HomeScore=r,e.bets[t].AwayScore=s,e.bets[t].CardsMark=n[Math.floor(3*Math.random())],e.bets[t].CornersMark=n[Math.floor(3*Math.random())]}}]),angular.module("mundialitoApp").factory("BetsManager",["$http","$q","Bet","$log","MundialitoUtils","GamesManager",function(e,a,t,r,s,n){return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("BetsManager: updating existing instance of bet "+e),s.setData(a)):(r.debug("BetsManager: saving new instance of bet "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("BetsManager: will fetch bet "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("BetsManager: Instance was loaded at "+a.LoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("BetsManager: will fetch bet "+a+" from server"),e.get("api/bets/"+a,{tracker:"getBet"}).then(e=>{var a=s._retrieveInstance(e.data.BetId,e.data);t.resolve(a)}).catch(()=>{t.reject()})},addBet:function(t){var s=a.defer(),n=this;return r.debug("BetsManager: will add new bet - "+angular.toJson(t)),e.post("api/bets/",t,{tracker:"addBetOnGame"}).then(e=>{var a=n._retrieveInstance(e.data.BetId,e.data);s.resolve(a)}).catch(e=>{r.error("Failed to add bet"),s.reject(e)}),s.promise},getBet:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},getGameBets:function(t){var s=a.defer(),n=this;return r.debug("BetsManager: will fetch all bets of game "+t+" from server"),e.get("api/games/"+t+"/bets",{tracker:"getGameBets"}).then(e=>{var a=[];e.data.forEach(e=>{var t=n._retrieveInstance(e.BetId,e);a.push(t)}),s.resolve(a)}).catch(function(){s.reject()}),s.promise},getUserBets:function(t){var s=a.defer(),n=this;return r.debug("BetsManager: will fetch user "+t+" bets from server"),e.get("api/bets/user/"+t,{tracker:"getUserBets"}).then(e=>{var a=[];e.data.forEach(e=>{var t=n._retrieveInstance(e.BetId,e);a.push(t)}),s.resolve(a)}).catch(function(){s.reject()}),s.promise},getUserBetOnGame:function(t){var s=a.defer(),n=this;return r.debug("BetsManager: will fetch user bet of game "+t+" from server"),e.get("api/games/"+t+"/mybet",{tracker:"getUserBetOnGame"}).then(e=>{if(-1!=e.data.BetId){var a=n._retrieveInstance(e.data.BetId,e.data);s.resolve(a)}s.resolve(e.data)}).catch(()=>{s.reject()}),s.promise},setBet:function(e){r.debug("BetsManager: will set bet "+e.BetId+" to -"+angular.toJson(e));var a=this._search(e.BetId);return a?a.setData(e):a=this._retrieveInstance(e.BetId,e),a}}}]),angular.module("mundialitoApp").controller("DashboardCtrl",["$scope","$log","Constants","$location","$timeout","GamesManager","UsersManager","GeneralBetsManager","teams","players","BetsManager","MundialitoUtils",function(e,a,t,r,s,n,i,o,l,u,d,m){e.generalBetsAreOpen=!1,e.submittedGeneralBet=!0,e.pendingUpdateGames=!1,e.oneAtATime=!0,e.status={},e.toggleValue={},e.players=u,e.changed=(a=>{e.toggleValue[a.GameId]?(e.selectedDic[a.GameId]=e.marksDic[a.GameId],e.selectedPercentage[a.GameId]=e.marksPercentage[a.GameId]):(e.selectedDic[a.GameId]=e.resultsDic[a.GameId],e.selectedPercentage[a.GameId]=e.resultsPercentage[a.GameId])}),e.getGamesPromise=n.loadAllGames().then(t=>{e.games=t,e.resultsDic={},e.marksDic={},e.selectedDic={},e.resultsPercentage={},e.marksPercentage={},e.selectedPercentage={},e.pendingUpdateGames=void 0!==_.findWhere(e.games,{IsPendingUpdate:!0}),e.pendingUpdateGamesFolloweesBets={},a.info("DashboardCtrl: followees:"+e.security.user.Followees),_.filter(e.games,e=>e.IsPendingUpdate).forEach(a=>{d.getGameBets(a.GameId).then(t=>{let r=_.groupBy(t,e=>e.HomeScore+"-"+e.AwayScore),s=_.groupBy(t,e=>e.HomeScore===e.AwayScore?"X":e.HomeScore>e.AwayScore?e.Game.HomeTeam.ShortName:e.Game.AwayTeam.ShortName);e.resultsDic[a.GameId]=Object.entries(r).sort((e,a)=>a[1].length-e[1].length),e.marksDic[a.GameId]=Object.entries(s).sort((e,a)=>a[1].length-e[1].length),e.resultsPercentage[a.GameId]={},e.resultsDic[a.GameId].forEach(r=>{e.resultsPercentage[a.GameId][r[0]]=Math.round(r[1].length/t.length*100)}),e.marksPercentage[a.GameId]={},e.marksDic[a.GameId].forEach(r=>{e.marksPercentage[a.GameId][r[0]]=Math.round(r[1].length/t.length*100)});let n=_.filter(t,a=>e.security.user.Followees.includes(a.User.Username)||e.security.user.Username===a.User.Username);e.pendingUpdateGamesFolloweesBets[a.GameId]=n,e.changed(a)})})});var c=()=>{angular.isDefined(e.security.user)&&null!=e.security.user?o.hasGeneralBet(e.security.user.Username).then(a=>{e.submittedGeneralBet=!0===a}):(a.debug("DashboardCtrl: user info not loaded yet, will retry in 1 second"),s(c,1e3))};function g(){var a=e.gridApi.saveState.save();localStorage.setItem("gridState",a)}c(),o.canSubmtiGeneralBet().then(a=>{e.generalBetsAreOpen=!0===a,e.generalBetsAreOpen||o.loadAllGeneralBets().then(function(a){e.generalBets=a,e.winningTeams={},e.winningPlayers={};for(var t=0;t{e.users=a,e.usersDic=a.reduce((e,a)=>(e[a.Id]=a,e),{})}),e.isOpenForBetting=(e=>e.IsOpen),e.isPendingUpdate=(e=>e.IsPendingUpdate),e.isDecided=function(e){return!e.IsOpen&&!e.IsPendingUpdate},e.isGameBet=(e=>a=>a.Game.GameId===e.GameId),e.hasBets=(a=>void 0!==e.pendingUpdateGamesFolloweesBets[a.GameId]&&e.pendingUpdateGamesFolloweesBets[a.GameId].length>0),e.gridOptions={...t.TABLE_GRID_OPTIONS,data:"users",onRegisterApi:a=>{e.gridApi=a,e.gridApi.colResizable.on.columnSizeChanged(e,g),e.gridApi.core.on.columnVisibilityChanged(e,g),e.gridApi.core.on.sortChanged(e,g)}},e.getTableHeight=(()=>{var t=30*(e.users?e.users.length:0)+30;return a.debug("Total Height: "+t),{height:t+"px"}}),e.goToUser=(e=>{r.path(e.entity.getUrl())})}]),angular.module("mundialitoApp").factory("Game",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)},delete:function(){if(confirm("Are you sure you would like to delete game "+this.GameId))return a.debug("Game: Will delete game "+this.GameId),e.delete("api/games/"+this.GameId,{tracker:"deleteGame"})},update:function(){return a.debug("Game: Will update game "+this.GameId),e.put("api/games/"+this.GameId,this,{tracker:"editGame"})},getUrl:function(){return"/games/"+this.GameId}},t}]),angular.module("mundialitoApp").controller("GameCtrl",["$scope","$log","Constants","UsersManager","GamesManager","BetsManager","game","userBet","Alert","$location","PluginsProvider","keyValueEditorUtils","MundialitoUtils","teams","players",function(e,a,t,r,s,n,i,o,l,u,d,m,c,g,p){e.game=i,e.teamsDic={},e.playersDic={},e.simulatedGame={},e.plugins={},e.userBet=o,e.userBet.GameId=i.GameId,e.showEditForm=!1,e.toKeyValue=(e=>_.keys(e).map(a=>({name:a,value:e[a]}))),e.integrationsData=e.toKeyValue(e.game.IntegrationsData);for(var f=0;fnew Date(e.Date)).filter(e=>e.IsBetResolved).map(e=>c.getGameMark(e,t)).value();e.teamsForm[t]={form:r,games:_.filter(a,e=>e.IsBetResolved)}}d.getGameDetailsFromAll(e.game).then(a=>{a.forEach(a=>{e.plugins[a.property]={data:a.data,template:a.template}})}),e.game.IsOpen||(e.getGameBetsPromsie=n.getGameBets(e.game.GameId).then(t=>{a.debug("GameCtrl: get game bets"+angular.toJson(t)),e.gameBets=t;var s={type:"PieChart",options:{displayExactValues:!0,is3D:!0,backgroundColor:{fill:"transparent"},chartArea:{left:10,top:20,bottom:0,height:"100%"},title:"Bets Distribution"}},n=_.filter(t,function(e){return e.HomeScore>e.AwayScore}).length,i=_.filter(t,function(e){return e.HomeScore===e.AwayScore}).length,o=_.filter(t,function(e){return e.HomeScore{e.usersMap=new Map,a.forEach(a=>{e.usersMap.set(a.Username,a)});let t=_.chain(a).filter(a=>e.security.user.Followees.includes(a.Username)).pluck("Username").value();e.followeesBets=_.filter(e.gameBets,e=>t.includes(e.User.Username));let r=_.chain(a).first(3).pluck("Username").value();e.top3UsersBets=_.filter(e.gameBets,e=>r.includes(e.User.Username));let s=0;a.forEach((a,t)=>{a.Username===e.security.user.Username&&(s=t)});let n=Math.max(s-3,0),i=Math.min(s+3,a.length),o=_.chain(a.slice(n,i+1)).pluck("Username").filter(a=>a!==e.security.user.Username).value();e.neighborsBets=_.filter(e.gameBets,e=>o.includes(e.User.Username))})})),e.updateGame=(()=>{angular.isDefined(i.Stadium.Games)&&null!=i.Stadium.Games&&delete i.Stadium.Games,e.game.IntegrationsData=m.mapEntries(m.compactEntries(e.integrationsData)),e.updateGamePromise=e.game.update().then(e=>{l.success("Game was updated successfully"),s.setGame(e.data)}).catch(e=>{l.error("Failed to update game, please try again"),a.error("Error updating game",e)})}),e.updateBet=(()=>{-1!==e.userBet.BetId?e.updateBetPromise=e.userBet.update().then(e=>{l.success("Bet was updated successfully"),n.setBet(e)}).catch(e=>{l.error("Failed to update bet, please try again"),a.error("Error updating bet",e)}):n.addBet(e.userBet).then(t=>{a.log("GameCtrl: Bet "+t.BetId+" was added"),e.userBet=t,l.success("Bet was added successfully")},e=>{l.error("Failed to add bet, please try again"),a.error("Error adding bet",e)})}),e.simulateGame=(()=>{a.debug("GameCtrl: simulating game"),e.simulateGamePromise=s.simulateGame(e.game.GameId,e.simulatedGame).then(a=>{e.users=a,l.success("Table updated with simulation result")}).catch(e=>{l.error("Failed to simulate game, please try again"),a.error("Error simulating game",e)})}),e.sort=(t=>{a.debug("GameCtrl: sorting by "+t),e.gameBets=_.sortBy(e.gameBets,e=>{switch(t){case"points":return e.Points;case"cards":return e.CardsMark;case"corners":return e.CornersMark;case"user":return e.User.FirstName+e.User.LastName;case"result":return e.HomeScore+"-"+e.AwayScore}})}),e.gridOptions={...t.TABLE_GRID_OPTIONS,data:"users",onRegisterApi:a=>{e.gridApi=a,e.gridApi.colResizable.on.columnSizeChanged(e,h),e.gridApi.core.on.columnVisibilityChanged(e,h),e.gridApi.core.on.sortChanged(e,h)}},e.getTableHeight=(()=>{var t=30*(e.users?e.users.length:0)+30;return a.debug("Total Height: "+t),{height:t+"px"}}),e.goToUser=(e=>{u.path(e.entity.getUrl())}),e.getUserPlace=(a=>e.usersMap.get(a.Username).Place),e.$watch("simulatedGame",()=>{e.users=void 0},!0),e.loadTeamsForm=(()=>{e.teamsForm={},e.getTeamGamesPromise=s.getTeamGames(e.game.HomeTeam.TeamId).then(a=>{v(a,e.game.HomeTeam.TeamId)}).catch(e=>{l.error("Failed to get teams form"),a.error("Failed to get teams form",e)}),s.getTeamGames(e.game.AwayTeam.TeamId).then(a=>{v(a,e.game.AwayTeam.TeamId)}).catch(e=>{l.error("Failed to get teams form"),a.error("Failed to get teams form",e)})}),e.loadTeamsForm()}]),angular.module("mundialitoApp").controller("GamesCtrl",["$scope","$log","GamesManager","games","teams","StadiumsManager","Alert",function(e,a,t,r,s,n,i){e.newGame=null,e.gamesFilter="Open",e.gamesToggle=!1,e.games=r,e.teams=s,e.changed=(()=>{"Open"===e.gamesFilter?e.gamesFilter="All":e.gamesFilter="Open"}),n.loadAllStadiums().then(function(a){e.stadiums=a}),e.addNewGame=function(){$(".selectpicker").selectpicker("refresh"),e.newGame=t.getEmptyGameObject()},e.saveNewGame=function(){e.addGamePromise=t.addGame(e.newGame).then(a=>{i.success("Game was added successfully"),e.newGame=t.getEmptyGameObject(),e.games.push(a)})},e.isPendingUpdate=function(e){return e.IsPendingUpdate},e.updateGame=function(a){angular.isDefined(a.Stadium.Games)&&null!=a.Stadium.Games&&delete a.Stadium.Games,e.editGamePromise=a.update().then(e=>{i.success("Game was updated successfully"),t.setGame(e)})}}]),angular.module("mundialitoApp").factory("GamesManager",["$http","$q","Game","$log","MundialitoUtils","User",function(e,a,t,r,s,n){var i=void 0,o=void 0;return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("GamesManager: updating existing instance of game "+e),s.setData(a)):(r.debug("GamesManager: saving new instance of game "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("GamesManager: will fetch game "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("GamesManager: Instance was loaded at "+a.LoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("GamesManager: will fetch game "+a+" from server"),e.get("api/games/"+a,{tracker:"getGame"}).then(e=>{var a=s._retrieveInstance(e.data.GameId,e.data);t.resolve(a)}).catch(()=>{t.reject()})},getEmptyGameObject:function(){return{HomeTeam:"",AwayTeam:"",Date:"",Stadium:""}},addGame:function(t){var s=a.defer();angular.isObject(t.AwayTeam)||(t.AwayTeam=angular.fromJson(t.AwayTeam)),angular.isObject(t.HomeTeam)||(t.HomeTeam=angular.fromJson(t.HomeTeam)),angular.isObject(t.Stadium)||(t.Stadium=angular.fromJson(t.Stadium));var n=this;return r.debug("GamesManager: will add new game - "+angular.toJson(t)),e.post("api/games",t,{tracker:"addGame"}).then(e=>{var a=n._retrieveInstance(e.data.GameId,e.data);s.resolve(a)}).catch(function(){s.reject()}),s.promise},getGame:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},loadAllGames:function(){if(i)return i;var t=a.defer(),s=this;return r.debug("GamesManager: will fetch all games from server"),e.get("api/games",{tracker:"getGames"}).then(e=>{var a=[];e.data.forEach(e=>{var t=s._retrieveInstance(e.GameId,e);a.push(t)}),t.resolve(a)}).catch(()=>{t.reject()}),i=t.promise,t.promise},loadOpenGames:function(){if(o)return o;var t=a.defer(),s=this;return r.debug("GamesManager: will fetch all open games from server"),e.get("api/games/open",{tracker:"getOpenGames"}).then(e=>{var a=[];e.data.forEach(e=>{var t=s._retrieveInstance(e.GameId,e);a.push(t)}),t.resolve(a)}).catch(()=>{t.reject()}),o=t.promise,t.promise},getTeamGames:function(t){var s=a.defer(),n=this;return r.debug("GamesManager: will fetch all games of team "+t+" from server"),e.get("api/teams/"+t+"/games",{tracker:"getTeamGames"}).then(e=>{var a=[];e.data.forEach(e=>{var t=n._retrieveInstance(e.GameId,e);a.push(t)}),s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},getStadiumGames:function(t){var s=a.defer(),n=this;return r.debug("GamesManager: will fetch all games in stadium "+t+" from server"),e.get("api/games/Stadium/"+t,{tracker:"getStadiumGames"}).then(function(e){var a=[];e.data.forEach(e=>{var t=n._retrieveInstance(e.GameId,e);a.push(t)}),s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},simulateGame:function(t,s){var i=a.defer();return r.debug("GamesManager: will simulate game "+t),e.post("api/games/"+t+"/simulate",s,{tracker:"simulateGame"}).then(e=>{var a=[];e.data.forEach(e=>{a.push(new n(e))}),i.resolve(a)}).catch(e=>{i.reject(e)}),i.promise},setGame:function(e){r.debug("GamesManager: will set game "+e.GameId+" to -"+angular.toJson(e));var a=this._search(e.GameId);return a?a.setData(e):a=this._retrieveInstance(e.GameId,e),a}}}]),angular.module("mundialitoApp").directive("mundialitoGames",["Alert",function(e){return{restrict:"E",scope:{games:"=info",gamesType:"=filter",showOnly:"=",onAdd:"&"},templateUrl:"App/Games/gamesTemplate.html",link:a=>{a.allGames=a.games,a.$watch("gamesType",function(e){a.games=e&&"All"!==e?a.games.filter(e=>e.IsOpen):a.allGames}),a.deleteGame=(t=>{var r=t;t.delete().then(()=>{e.success("Game was deleted successfully"),a.games.splice(a.games.indexOf(r),1)})})}}}]),angular.module("mundialitoApp").factory("Alert",["toaster","$log","$rootScope",function(e,a,t){return{success:function(a){e.pop("success","Success",a)},error:function(a,t){e.pop("error",t||"Error",a)},note:function(a){e.pop("note","Info",a)}}}]),angular.module("mundialitoApp").factory("ErrorHandler",["$rootScope","$log","Alert","$location","Constants",function(e,a,t,r,s){return this.handle=((e,n,i,o)=>{if(a.log(e),!o.ignoreError){if(401===n)return localStorage.removeItem("accessToken"),sessionStorage.removeItem("accessToken"),void r.path(s.LOGIN_PATH);var l=[],u=void 0;e.Message&&(u=e.Message),e.errors&&angular.forEach(e.errors,e=>{angular.forEach(e,e=>{l.push(e)})}),e.ModelState&&angular.forEach(e.ModelState,function(e){l.push(e)}),e.ExceptionMessage&&l.push(e.ExceptionMessage),e.error_description&&l.push(e.error_description),0!==l.length||u||(u="General Error",l.push("Looks like the server is down, please try again in few minutes")),t.error(l.join("\n"),u)}}),this}]).factory("myHttpInterceptor",["ErrorHandler","$q",function(e,a){return{response:function(e){return e},responseError:function(t){return e.handle(t.data,t.status,t.headers,t.config),a.reject(t)}}}]),angular.module("mundialitoApp").factory("MundialitoUtils",["Constants",function(e){return{shouldRefreshInstance:a=>{return!(!angular.isDefined(a.LoadTime)||!angular.isDate(a.LoadTime))&&(new Date).getTime()-a.LoadTime.getTime()>e.REFRESH_TIME},shortName:e=>{if(-1!==e.indexOf(" ")){let a=e.split(" ");return a[0].substring(0,1)+"."+a[1].substring(0,1)}return e.substring(0,1)},getGameMark:(e,a)=>e.HomeTeam.TeamId===a?e.HomeScore>e.AwayScore?{game:e.GameId,mark:"W"}:e.HomeScoree.AwayScore?{game:e.GameId,mark:"L"}:e.HomeScore({restrict:"E",scope:{team:"=",style:"="},templateUrl:"App/General/teamFlagTemplate.html",link:a=>{a.useFlagsCss=e.mundialitoApp.clientConfig.UseFlagsCss}})]),angular.module("mundialitoApp").factory("GeneralBet",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)},update:function(){return a.debug("General Bet: Will update general bet "+this.GeneralBetId),e.put("api/generalbets/"+this.GeneralBetId,this,{tracker:"updateGeneralBet"})},resolve:function(){a.debug("General Bet: Will resolve general bet "+this.GeneralBetId);var t={TeamIsRight:this.TeamIsRight||!1,PlayerIsRight:this.PlayerIsRight||!1};return e.put("api/generalbets/"+this.GeneralBetId+"/resolve",t,{tracker:"resolveGeneralBet"})}},t}]),angular.module("mundialitoApp").factory("GeneralBetsManager",["$http","$q","GeneralBet","$log","MundialitoUtils",function(e,a,t,r,s){return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("GeneralBetsManager: updating existing instance of bet "+e),s.setData(a)):(r.debug("GeneralBetsManager: saving new instance of bet "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("GeneralBetsManager: will fetch bet "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("GeneralBetsManager: Instance was loaded at "+a.LoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("GeneralBetsManager: will fetch bet "+a+" from server"),e.get("api/generalbets/"+a,{tracker:"getGeneralBet"}).then(e=>{var a=s._retrieveInstance(e.data.GeneralBetId,e.data);t.resolve(a)}).catch(e=>{t.reject(e)})},addGeneralBet:function(t){var s=a.defer(),n=this;return r.debug("GeneralBetsManager: will add new bet - "+angular.toJson(t)),e.post("api/generalbets/",t,{tracker:"addGeneralBet"}).then(e=>{var a=n._retrieveInstance(e.data.GeneralBetId,e.data);s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},getGeneralBet:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},loadAllGeneralBets:function(){var t=a.defer(),s=this;return r.debug("GeneralBetsManager: will fetch all general bets from server"),e.get("api/generalbets",{tracker:"getGeneralBets"}).then(e=>{var a=[];e.data.forEach(e=>{var t=s._retrieveInstance(e.GeneralBetId,e);a.push(t)}),t.resolve(a)}).catch(e=>{t.reject(e)}),t.promise},hasGeneralBet:function(t){var s=a.defer();return r.debug("GeneralBetsManager: will check if user "+t+" has general bets"),e.get("api/generalbets/has-bet/"+t,{tracker:"getUserGeneralBet"}).then(e=>{s.resolve(e.data)}).catch(e=>{s.reject(e)}),s.promise},canSubmtiGeneralBet:function(){var t=a.defer();return r.debug("GeneralBetsManager: will check if user general bets are closed"),e.get("api/generalbets/cansubmitbets/",{tracker:"getCanSubmitGeneralBets"}).then(e=>{t.resolve(e.data)}).catch(e=>{t.reject(e)}),t.promise},getUserGeneralBet:function(t){var s=a.defer(),n=this;return r.debug("GeneralBetsManager: will fetch user "+t+" general bet from server"),e.get("api/generalbets/user/"+t,{tracker:"getUserGeneralBet"}).then(e=>{var a=n._retrieveInstance(e.data.GeneralBetId,e.data);s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},setGeneralBet:function(e){r.debug("GeneralBetsManager: will set bet "+e.GeneralBetId+" to -"+angular.toJson(e));var a=this._search(e.GeneralBetId);return a?a.setData(e):a=this._retrieveInstance(e.GeneralBetId,e),a}}}]),angular.module("mundialitoApp").factory("Player",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)}},t}]),angular.module("mundialitoApp").factory("PlayersManager",["$http","$q","Player","$log",function(e,a,t,r){var s=void 0;return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("playersPromise: updating existing instance of player "+e),s.setData(a)):(r.debug("playersPromise: saving new instance of player "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},getPlayerSchema:function(){return[{property:"Name",label:"Name",type:"text",attr:{required:!0}}]},loadAllPlayers:function(){if(s)return s;var t=a.defer(),n=this;return r.debug("PlayersManager: will fetch all players from server"),e.get("api/players",{tracker:"getPlayers",cache:!0}).then(e=>{var a=[];e.data.forEach(e=>{var t=n._retrieveInstance(e.PlayerId,e);a.push(t)}),t.resolve(a)}).catch(e=>{t.reject(e)}),s=t.promise,t.promise}}}]),angular.module("mundialitoApp").factory("Stadium",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)},delete:function(){if(confirm("Are you sure you would like to delete stadium "+this.Name))return a.debug("Stadium: Will delete stadium "+this.StadiumId),e.delete("api/stadiums/"+this.StadiumId,{tracker:"deleteStadium"})},update:function(){a.debug("Stadium: Will update stadium "+this.StadiumId);var t={};return angular.copy(this,t),delete t.Games,e.put("api/stadiums/"+this.StadiumId,t,{tracker:"editStadium"})},getUrl:function(){return"/stadiums/"+this.StadiumId}},t}]),angular.module("mundialitoApp").controller("StadiumCtrl",["$scope","$log","StadiumsManager","GamesManager","stadium","Alert",function(e,a,t,r,s,n){e.stadium=s,e.showEditForm=!1,e.getStadiumGamesPromise=r.getStadiumGames(e.stadium.StadiumId).then(t=>{a.debug("StadiumCtrl: Got games of stadium"),e.games=t}),e.updateStadium=(()=>{e.editStadiumPromise=e.stadium.update().then(()=>{n.success("Stadium was updated successfully")})}),e.schema=t.getStaidumSchema()}]),angular.module("mundialitoApp").controller("StadiumsCtrl",["$scope","$log","StadiumsManager","stadiums","Alert",function(e,a,t,r,s){e.stadiums=r,e.showNewStadium=!1,e.newStadium=null,e.addNewStadium=(()=>{e.newStadium=t.getEmptyStadiumObject()}),e.saveNewStadium=(()=>{t.addStadium(e.newStadium).then(a=>{s.success("Stadium was added successfully"),e.newStadium=null,e.stadiums.push(a)})}),e.deleteStadium=(a=>{var t=a;a.delete().then(()=>{s.success("Stadium was deleted successfully"),e.stadiums.splice(e.stadiums.indexOf(t),1)})}),e.schema=t.getStaidumSchema()}]),angular.module("mundialitoApp").factory("StadiumsManager",["$http","$q","Stadium","$log","MundialitoUtils",function(e,a,t,r,s){var n=void 0;return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("StadiumsManager: updating existing instance of stadium "+e),s.setData(a)):(r.debug("StadiumsManager: saving new instance of stadium "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("StadiumsManager: will fetch stadium "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("StadiumsManager: Instance was loaded at "+a.LoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("StadiumsManager: will fetch stadium "+a+" from server"),e.get("api/stadiums/"+a,{tracker:"getStadium"}).then(e=>{var a=s._retrieveInstance(e.data.StadiumId,e.data);t.resolve(a)}).catch(e=>{t.reject(e)})},getStaidumSchema:function(){return[{property:"Name",label:"Name",type:"text",attr:{required:!0}},{property:"City",label:"City",type:"text",attr:{required:!0}},{property:"Capacity",label:"Capacity",type:"number",attr:{required:!0}}]},getEmptyStadiumObject:function(){return{HomeTeam:"",AwayTeam:""}},addStadium:function(t){var s=a.defer(),n=this;return r.debug("StadiumsManager: will add new stadium - "+angular.toJson(t)),e.post("api/stadiums",t,{tracker:"addStadium"}).then(e=>{var a=n._retrieveInstance(e.data.StadiumId,e.data);s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},getStadium:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},loadAllStadiums:function(){if(n)return n;var t=a.defer(),s=this;return r.debug("StadiumsManager: will fetch all games from server"),e.get("api/stadiums",{tracker:"getStadiums",cache:!0}).then(e=>{var a=[];e.data.forEach(e=>{var t=s._retrieveInstance(e.StadiumId,e);a.push(t)}),t.resolve(a)}).catch(e=>{t.reject(e)}),n=t.promise,t.promise},setStadium:function(e){r.debug("StadiumsManager: will set stadium "+e.StadiumId+" to -"+angular.toJson(e));var a=this._search(e.StadiumId);return a?a.setData(e):a=this._retrieveInstance(e.StadiumId,e),a}}}]),angular.module("mundialitoApp").factory("Team",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e),this.Logo=this.Logo.toLowerCase(),this.Flag=this.Flag.toLowerCase()},delete:function(){if(confirm("Are you sure you would like to delete team "+this.Name))return a.debug("Team: Will delete team "+this.TeamId),e.delete("api/teams/"+this.TeamId,{tracker:"deleteTeam"})},update:function(){return a.debug("Team: Will update game "+this.TeamId),e.put("api/teams/"+this.TeamId,this,{tracker:"editTeam"})},getUrl:function(){return"/teams/"+this.TeamId}},t}]),angular.module("mundialitoApp").controller("TeamCtrl",["$scope","$log","TeamsManager","team","games","Alert","PluginsProvider","MundialitoUtils",function(e,a,t,r,s,n,i,o){e.team=r,e.games=s,e.plugins={},e.teamsForm={},e.showEditForm=!1,e.toKeyValue=(e=>_.keys(e).map(a=>({name:a,value:e[a]}))),e.IntegrationsData=e.toKeyValue(e.team.IntegrationsData),e.fromKeyValue=(e=>{let a={};return e.forEach(e=>{""!==e.name&&(a[e.name]=e.value)}),a});const l=_.chain(e.games).sortBy(e=>new Date(e.Date)).filter(e=>e.IsBetResolved).map(a=>o.getGameMark(a,e.team.TeamId)).value();e.teamsForm[e.team.TeamId]={form:l,games:_.filter(e.games,e=>e.IsBetResolved)},i.getTeamDetailsFromAll(e.team).then(a=>{a.forEach(a=>{e.plugins[a.property]={data:a.data,template:a.template}})}),e.updateTeam=(()=>{e.team.IntegrationsData=e.fromKeyValue(e.IntegrationsData),e.editTeamPromise=e.team.update().then(e=>{n.success("Team was updated successfully"),t.setTeam(e.data)})}),e.schema=t.getTeamSchema()}]),angular.module("mundialitoApp").controller("TeamsCtrl",["$scope","$log","TeamsManager","teams","Alert",function(e,a,t,r,s){e.teams=r,e.showNewTeam=!1,e.newTeam=null,e.addNewTeam=function(){$(".selectpicker").selectpicker("refresh"),e.newTeam=t.getEmptyTeamObject()},e.saveNewTeam=function(){t.addTeam(e.newTeam).then(function(a){s.success("Team was added successfully"),e.newTeam=null,e.teams.push(a)})},e.deleteTeam=function(a){var t=a;a.delete().then(()=>{s.success("Team was deleted successfully"),e.teams.splice(e.teams.indexOf(t),1)})},e.schema=t.getTeamSchema()}]),angular.module("mundialitoApp").factory("TeamsManager",["$http","$q","Team","$log","MundialitoUtils",function(e,a,t,r,s){return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("TeamsManager: updating existing instance of team "+e),s.setData(a)):(r.debug("TeamsManager: saving new instance of team "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("TeamsManager: will fetch team "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("TeamsManager: Instance was loaded at "+instanceLoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("TeamsManager: will fetch team "+a+" from server"),e.get("api/teams/"+a,{tracker:"getTeam"}).then(e=>{var a=s._retrieveInstance(e.data.TeamId,e.data);t.resolve(a)}).catch(e=>{t.reject(e)})},getTeamSchema:function(){return[{property:"Name",label:"Name",type:"text",attr:{required:!0}},{property:"Flag",label:"Flag",type:"url",attr:{required:!0}},{property:"TeamPage",label:"TeamPage",type:"url",attr:{required:!1}},{property:"Logo",label:"Logo",type:"url",attr:{required:!0}},{property:"ShortName",label:"Short Name",type:"text",attr:{ngMaxlength:3,ngMinlength:3,required:!0}},{property:"TournamentTeamId",label:"Tournament Team Id",type:"number",attr:{required:!1}}]},getEmptyTeamObject:function(){return{Name:"",Flag:"",Logo:"",ShortName:"",TournamentTeamId:null,TeamPage:null}},addTeam:function(t){var s=a.defer(),n=this;return r.debug("TeamsManager: will add new team - "+angular.toJson(t)),e.post("api/teams",t,{tracker:"addTeam"}).then(e=>{var a=n._retrieveInstance(e.data.TeamId,e.data);s.resolve(a)}).catch(e=>{s.reject(e)}),s.promise},getTeam:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},loadAllTeams:function(){var t=a.defer(),s=this;return r.debug("TeamsManager: will fetch all teams from server"),e.get("api/teams",{tracker:"getTeams",cache:!0}).then(e=>{var a=[];e.data.forEach(e=>{var t=s._retrieveInstance(e.TeamId,e);a.push(t)}),t.resolve(a)}).catch(e=>{t.reject(e)}),t.promise},setTeam:function(e){r.debug("TeamsManager: will set team "+e.TeamId+" to -"+angular.toJson(e));var a=this._search(e.TeamId);return a?a.setData(e):a=this._retrieveInstance(e.TeamId,e),a}}}]),angular.module("mundialitoApp").controller("ManageAppCtrl",["$scope","$log","Alert","users","teams","generalBets","UsersManager","players",function(e,a,t,r,s,n,i,o){e.users=r,e.generalBets=n,e.deleteUser=(a=>{var r=a;e.deleteUserPromise=a.delete().then(()=>{t.success("User was deleted successfully"),e.users.splice(e.users.indexOf(r),1)})}),e.resolveBet=(a=>{e.resolveGeneralBetPromise=a.resolve().then(()=>{t.success("General bet was resolved successfully")})}),e.makeAdmin=(e=>{e.makeAdmin().then(()=>{t.success("User is now admin"),e.Roles="Admin"})}),e.activate=(e=>{e.activate().then(()=>{t.success("User was activated successfully")})}),e.deactivate=(e=>{e.deactivate().then(()=>{t.success("User was deactivated successfully")})})}]),angular.module("mundialitoApp").factory("User",["$http","$log",function(e,a){function t(e){e&&this.setData(e)}return t.prototype={setData:function(e){angular.extend(this,e)},getUrl:function(){return"/users/"+this.Username},delete:function(){if(confirm("Are you sure you would like to delete user "+this.Username))return a.debug("User: Will delete user "+this.Username),e.delete("api/users/"+this.Id,{tracker:"deleteUser"})},makeAdmin:function(){if(confirm("Are you sure you would like to make "+this.Name+" Admin?"))return a.debug("User: Will make user "+this.Username+" admin"),e.post("api/users/makeadmin/"+this.Id,{tracker:"makeAdmin"})},activate:function(){if(confirm("Are you sure you would like to activate "+this.Name))return a.debug("User: Will actiavte user "+this.Username),e.post("api/users/"+this.Id+"/activate")},deactivate:function(){if(confirm("Are you sure you would like to deactiavte "+this.Name))return a.debug("User: Will deactiavte user "+this.Username),e.delete("api/users/"+this.Id+"/activate")}},t}]),angular.module("mundialitoApp").controller("UserProfileCtrl",["$scope","$log","UsersManager","Alert","GeneralBetsManager","profileUser","userGameBets","teams","generalBetsAreOpen","players",function(e,a,t,r,s,n,i,o,l,u){e.profileUser=n,e.userGameBets=i,e.teams=o,e.players=u,e.noGeneralBetWasSubmitted=!1,e.generalBetsAreOpen=!0===l,a.debug("UserProfileCtrl: generalBetsAreOpen = "+l),e.alreadyFollow=e.security.user.Followees.includes(e.profileUser.Username),e.isLoggedUserProfile=(()=>{var t=null!=e.security.user&&e.security.user.Username===e.profileUser.Username;return a.debug("UserProfileCtrl: isLoggedUserProfile = "+t),null!=e.security.user&&e.security.user.Username===e.profileUser.Username}),e.isGeneralBetClosed=(()=>{var t=!e.generalBetsAreOpen;return a.debug("UserProfileCtrl: isGeneralBetClosed = "+t),t}),e.isGeneralBetReadOnly=(()=>{var t=!e.isLoggedUserProfile()||e.isGeneralBetClosed();return a.debug("UserProfileCtrl: isGeneralBetReadOnly = "+t),t}),e.shoudLoadGeneralBet=(()=>{var t=e.isLoggedUserProfile()||e.isGeneralBetClosed();return a.debug("UserProfileCtrl: shoudLoadGeneralBet = "+t),t}),e.shoudLoadGeneralBet()&&(e.generalBetsPromise=s.hasGeneralBet(e.profileUser.Username).then(t=>{if(a.debug("UserProfileCtrl: hasGeneralBet = "+t),!0===t)s.getUserGeneralBet(e.profileUser.Username).then(t=>{a.info("UserProfileCtrl: got user general bet - "+angular.toJson(t)),e.generalBet=t});else{if(e.generalBet={},e.isGeneralBetClosed())return void(e.noGeneralBetWasSubmitted=!0);if(e.isLoggedUserProfile()&&!e.isGeneralBetClosed())return;e.noGeneralBetWasSubmitted=!0}})),e.saveGeneralBet=(()=>{angular.isDefined(e.generalBet.GeneralBetId)?e.generalBetsPromise=e.generalBet.update().then(()=>{r.success("General Bet was updated successfully")},()=>{r.error("Failed to update General Bet, please try again")}):e.generalBetsPromise=s.addGeneralBet(e.generalBet).then(t=>{a.log("UserProfileCtrl: General Bet "+t.GeneralBetId+" was added"),e.generalBet=t,r.success("General Bet was added successfully")},()=>{r.error("Failed to add General Bet, please try again")})}),e.social=(()=>{e.alreadyFollow?t.unfollow(e.profileUser.Username).then(()=>{e.alreadyFollow=!1;const a=e.security.user.Followees.indexOf(e.profileUser.Username);e.security.user.Followees.splice(a,1),r.success("You no longer following "+e.profileUser.Username)}).catch(a=>{r.error("Failed to unfollow "+e.profileUser.Username+": "+a)}):t.follow(e.profileUser.Username).then(()=>{e.alreadyFollow=!0,e.security.user.Followees.push(e.profileUser.Username),r.success("You are now following "+e.profileUser.Username)}).catch(a=>{r.error("Failed to follow "+e.profileUser.Username+": "+a)})}),e.getSocialPromise=t.getSocial(e.profileUser.Username).then(t=>{a.log("UserProfileCtrl: Got social response"),e.followers=t.followers,e.followees=t.followees}),e.isLoggedUserProfile()?e.getStatsPromise=t.getMyStats().then(a=>{e.performance=a}).catch(e=>{a.error("Failed to get user slef statistics",e),r.error("Failed to fetch user statistics: "+e)}):e.getStatsPromise=t.getStats(e.profileUser.Username).then(a=>{e.performance=a}).catch(e=>{a.error("Failed to get user statistics",e),r.error("Failed to fetch user statistics: "+e)}),e.security.user.Username===e.profileUser.Username?e.compareUsersPromise=t.getUserProgess(e.security.user.Username):e.compareUsersPromise=t.compareUsers(e.security.user.Username,e.profileUser.Username),e.compareUsersPromise.then(a=>{if(a.length>0){let r=_.map(a[0].Entries,e=>e.Name);var t=_.map(r,e=>({id:e,label:e,type:"number"}));t.unshift({id:"date",label:"Date",type:"date"});let s=_.map(a,e=>{var a={c:[{v:new Date(e.Date)}]};return _.each(e.Entries,e=>{a.c.push({v:e.Place})}),a});e.chart={type:"LineChart",data:{cols:t,rows:s},options:{colors:["#0000FF","#009900","#CC0000","#DD9900"],defaultColors:["#0000FF","#009900","#CC0000","#DD9900"],displayExactValues:!0,is3D:!0,backgroundColor:{fill:"transparent"},vAxis:{title:"Place"},hAxis:{title:"Date"}}}}}).catch(e=>{a.error("Failed to compare users",e),r.error("Failed to compare users: "+e)}),e.capture=(()=>{html2canvas(document.body).then(a=>{var t=a.toDataURL("image/png"),r=document.createElement("a");r.href=t,r.download=e.profileUser.Username+".png",document.body.appendChild(r),r.click(),document.body.removeChild(r)})})}]),angular.module("mundialitoApp").factory("UsersManager",["$http","$q","User","$log","MundialitoUtils",function(e,a,t,r,s){var n=void 0;return{_pool:{},_retrieveInstance:function(e,a){var s=this._pool[e];return s?(r.debug("UsersManager: updating existing instance of user "+e),s.setData(a)):(r.debug("UsersManager: saving new instance of user "+e),s=new t(a),this._pool[e]=s),s.LoadTime=new Date,s},_search:function(e){r.debug("UsersManager: will fetch user "+e+" from local pool");var a=this._pool[e];if(!angular.isDefined(a)||!s.shouldRefreshInstance(a))return a;r.debug("UsersManager: Instance was loaded at "+a,LoadTime+", will reload it from server")},_load:function(a,t){var s=this;r.debug("UsersManager: will fetch user "+a+" from server"),e.get("api/users/"+a,{tracker:"getUser"}).then(e=>{var a=s._retrieveInstance(e.data.Username,e.data);t.resolve(a)}).catch(e=>{t.reject(e)})},getUser:function(e,t){var r=a.defer(),s=void 0;return angular.isDefined(t)&&t||(s=this._search(e)),s?r.resolve(s):this._load(e,r),r.promise},getSocial:a=>(r.debug("UsersManager: will fetch followers and followees of user "+a),e.get("api/users/"+a+"/followees",{tracker:"getSocial"}).then(t=>e.get("api/users/"+a+"/followers",{tracker:"getSocial"}).then(e=>({followers:e.data,followees:t.data})))),compareUsers:(a,t)=>(r.debug("UsersManager: will compare users: "+a+" and "+t),e.get("api/users/compare/"+a+"/"+t).then(e=>e.data)),getUserProgess:()=>(r.debug("UsersManager: will get user progress"),e.get("api/users/me/progress").then(e=>e.data)),getMyStats:()=>(r.debug("UsersManager: will the stats of logged user"),e.get("api/stats/me",{tracker:"getStats"}).then(e=>e.data)),getStats:a=>(r.debug("UsersManager: will the stats of "+a),e.get("api/stats/"+a,{tracker:"getStats"}).then(e=>e.data)),follow:a=>(r.debug("UsersManager: will follow "+a),e.post("api/users/follow/"+a,void 0,{tracker:"follow"})),unfollow:a=>(r.debug("UsersManager: will unfollow "+a),e.delete("api/users/follow/"+a,void 0,{tracker:"unfollow"})),loadAllUsers:function(){if(n)return n;var t=a.defer(),s=this;return r.debug("UsersManager: will fetch all users from server"),e.get("api/users",{tracker:"getUsers"}).then(e=>{var a=[];e.data.forEach(function(e){var t=s._retrieveInstance(e.Username,e);a.push(t)}),t.resolve(a)}).catch(e=>{t.reject(e)}),n=t.promise,t.promise},setUser:function(e){r.debug("UsersManager: will set user "+e.Username+" to -"+angular.toJson(e));var a=this._search(e.Username);return a?a.setData(e):a=this._retrieveInstance(e.Username,e),a}}}]),angular.module("mundialitoApp").factory("FootballDataGamePlugin",["$q","$rootScope","GenericProxyService",function(e,a,t){var r="https://api.football-data.org/v4/matches/";const s="football-data";return{getGameDetails:function(n){var i=r+n.IntegrationsData[s];return a.mundialitoApp.clientConfig&&a.mundialitoApp.clientConfig["football-data-api-key"]?t.proxyRequest("GET",i,void 0,{"X-Auth-Token":a.mundialitoApp.clientConfig["football-data-api-key"]}).then(e=>({data:e,property:"odds",template:"App/General/Plugins/FootballDataGameTemplate.html"})).catch(a=>e.reject(a)):e.reject("Skipping football-data as no api key provided")},integrationKey:s}}]),angular.module("mundialitoApp").factory("FootballDataTeamStatsPlugin",["$q","$rootScope","GenericProxyService",function(e,a,t){var r="https://api.football-data.org/v4/teams/";const s="football-data";function n(e){return(new Date).getFullYear()-parseInt(e.substring(0,4),10)}return{getTeamDetails:function(i){var o=r+i.IntegrationsData[s];return a.mundialitoApp.clientConfig&&a.mundialitoApp.clientConfig["football-data-api-key"]?t.proxyRequest("GET",o,void 0,{"X-Auth-Token":a.mundialitoApp.clientConfig["football-data-api-key"]}).then(e=>(e.coach.age=n(e.coach.dateOfBirth),e.squad.forEach(e=>{e.age=n(e.dateOfBirth),e.icon="goalkeeper"===e.position.toLowerCase()?"goalkeeper":"player"}),{data:e,property:"team-squad",template:"App/General/Plugins/FootballDataTeamStatsTemplate.html"})).catch(a=>e.reject(a)):e.reject("Skipping football-data as no api key provided")},integrationKey:s}}]),angular.module("mundialitoApp").factory("GenericProxyService",["$http","$q",function(e,a){var t="api/genericproxy";return{proxyRequest:function(r,s,n,i){var o=a.defer();return e({method:r,url:t+"?url="+s,data:n,headers:i,ignoreError:!0}).then(e=>{o.resolve(e.data)}).catch(e=>{o.reject(e)}),o.promise}}}]),angular.module("mundialitoApp").factory("PluginsProvider",["$q","$log",function(e,a){var t=[],r=[];return{getGameDetailsFromAll:function(r){let s=[];r.IntegrationsData&&(s=_.filter(t,e=>void 0!==r.IntegrationsData[e.integrationKey]));var n=s.map(e=>e.getGameDetails(r));return e.all(n).then(e=>e).catch(t=>(a.warn("Error fetching game details: "+t),e.reject(t)))},getTeamDetailsFromAll:function(t){let s=[];t.IntegrationsData&&(s=_.filter(r,e=>void 0!==t.IntegrationsData[e.integrationKey]));var n=s.map(e=>e.getTeamDetails(t));return e.all(n).then(e=>e).catch(t=>(a.warn("Error fetching team details: "+t),e.reject(t)))},registerGameFactory:e=>{t.push(e)},registerTeamFactory:e=>{r.push(e)}}}]); \ No newline at end of file