2019-11-25 16:45:41 +00:00
var alertNbLines = true ;
2019-01-17 21:30:39 +00:00
function treatFlagKey ( flag ) {
if ( flag . values !== undefined ) {
if ( flag . separator ) {
for ( var i = flag . values . length - 1 ; i >= 0 ; i -- ) {
2019-11-25 16:45:41 +00:00
if ( flag . nb _lines && ( flag . values [ i ] == undefined || ! flag . values [ i ] . length ) ) {
if ( alertNbLines ) {
alertNbLines = false ;
if ( ! confirm ( "Lorsque plusieurs flags sont attendus pour une même question, ceux-ci ne sont pas validés un par un. Ils ne sont validés qu'une fois tous les champs remplis correctement. (Sauf mention contraire, l'ordre n'importe pas)" ) )
console . log ( flag . values [ 9999 ] . length ) ; // Launch exception here to avoid form validation
}
}
else if ( ! flag . values [ i ] . length ) {
flag . values . splice ( i , 1 ) ;
}
2019-01-17 21:30:39 +00:00
}
if ( flag . ignore _order )
flag . value = flag . values . slice ( ) . sort ( ) . join ( flag . separator ) + flag . separator ;
else
flag . value = flag . values . join ( flag . separator ) + flag . separator ;
if ( flag . values . length == 0 )
flag . values = [ "" ] ;
}
else
flag . value = flag . values [ 0 ] ;
}
if ( flag . found == null && flag . soluce !== undefined ) {
2019-01-25 06:26:52 +00:00
if ( flag . value && flag . soluce ) {
if ( flag . ignore _case )
flag . value = flag . value . toLowerCase ( ) ;
if ( flag . validator _regexp ) {
var re = new RegExp ( flag . validator _regexp , flag . ignore _case ? 'ui' : 'u' ) ;
var match = re . exec ( flag . value ) ;
match . shift ( ) ;
flag . value = match . join ( "+" ) ;
}
2019-01-17 21:30:39 +00:00
2019-01-25 06:26:52 +00:00
if ( flag . soluce == b2sum ( flag . value ) )
flag . found = new Date ( ) ;
}
2019-01-17 21:30:39 +00:00
}
2019-01-25 06:26:52 +00:00
return flag . found !== undefined && flag . found !== false ;
2019-01-17 21:30:39 +00:00
}
2016-01-23 11:29:19 +00:00
angular . module ( "FICApp" , [ "ngRoute" , "ngSanitize" ] )
2016-01-16 21:40:59 +00:00
. config ( function ( $routeProvider , $locationProvider ) {
$routeProvider
2016-12-04 18:07:52 +00:00
. when ( "/rules" , {
controller : "HomeController" ,
templateUrl : "views/rules.html"
} )
2016-01-16 21:40:59 +00:00
. when ( "/edit" , {
controller : "MyTeamController" ,
templateUrl : "views/team-edit.html"
} )
2020-01-20 14:56:02 +00:00
. when ( "/issue" , {
controller : "IssueController" ,
templateUrl : "views/issue.html"
} )
. when ( "/issue/:eid" , {
controller : "IssueController" ,
templateUrl : "views/issue.html"
} )
2016-01-16 21:40:59 +00:00
. when ( "/rank" , {
2016-01-21 04:00:15 +00:00
controller : "RankController" ,
templateUrl : "views/rank.html"
2016-01-16 21:40:59 +00:00
} )
2017-12-21 21:18:18 +00:00
. when ( "/register" , {
controller : "RegisterController" ,
templateUrl : "views/register.html"
} )
2017-04-02 18:29:15 +00:00
. when ( "/videos" , {
controller : "VideosController" ,
templateUrl : "views/videos.html"
} )
2018-11-21 02:10:35 +00:00
. when ( "/tags/:tag" , {
controller : "TagController" ,
templateUrl : "views/tag.html"
} )
2016-01-16 21:40:59 +00:00
. when ( "/:theme" , {
2016-01-21 00:38:43 +00:00
controller : "ExerciceController" ,
2016-01-16 21:40:59 +00:00
templateUrl : "views/theme.html"
} )
. when ( "/:theme/:exercice" , {
controller : "ExerciceController" ,
2020-01-16 16:15:34 +00:00
templateUrl : function ( e ) {
if ( e . theme == "BlueMoney" && e . exercice == "JackSpearrow" )
return "views/defi-SE.html"
else
return "views/defi.html" ;
}
2016-01-16 21:40:59 +00:00
} )
2016-01-21 00:38:43 +00:00
. when ( "/" , {
2016-01-16 21:40:59 +00:00
controller : "HomeController" ,
templateUrl : "views/home.html"
2016-01-21 00:38:43 +00:00
} )
. otherwise ( {
redirectTo : "/"
2016-01-16 21:40:59 +00:00
} ) ;
$locationProvider . html5Mode ( true ) ;
} )
2018-12-01 15:14:34 +00:00
. run ( function ( $rootScope ) {
2016-01-21 00:38:43 +00:00
$rootScope . current _theme = 0 ;
$rootScope . current _exercice = 0 ;
2018-11-25 04:48:44 +00:00
$rootScope . current _tag = undefined ;
2018-12-01 17:15:03 +00:00
$rootScope . notify _field = 0 ;
2020-01-23 15:03:31 +00:00
$rootScope . issues _known _responses = 0 ;
2018-12-01 17:15:03 +00:00
2019-01-19 07:04:54 +00:00
if ( 'Notification' in window )
Notification . requestPermission ( function ( result ) {
if ( result == "granted" ) {
if ( localStorage && localStorage . notification )
$rootScope . notify _field = localStorage . notification ;
else
$rootScope . notify _field = 63 ;
}
else
$rootScope . notify _field = 0 ;
} ) ;
2018-12-01 15:14:34 +00:00
} )
2019-01-17 21:30:39 +00:00
. component ( 'flagKey' , {
bindings : {
kid : '=' ,
key : '=' ,
settings : '=' ,
wantchoices : '=' ,
} ,
controller : function ( ) {
this . additem = function ( key ) {
this . key . values . push ( "" ) ;
} ;
} ,
template : `
< div class = "form-group" >
2019-11-25 15:49:37 +00:00
< label for = "sol_{{ $ctrl.kid }}_0" ng - class = "{'text-light': !$ctrl.key.found}" > { { $ctrl . key . label } } & nbsp ; : < / l a b e l >
2019-01-17 21:30:39 +00:00
< span ng - if = "$ctrl.key.found && $ctrl.key.value" ng - bind = "$ctrl.key.value" > < / s p a n >
< div class = "input-group" ng - repeat = "v in $ctrl.key.values track by $index" ng - class = "{'mt-1': !$first}" ng - if = "!$ctrl.key.found" >
2020-01-16 14:33:28 +00:00
< input type = "text" class = "form-control flag" id = "sol_{{ $ctrl.kid }}_{{ $index }}" autocomplete = "off" name = "sol_{{ $ctrl.kid }}_{{ $index }}" ng - model = "$ctrl.key.values[$index]" ng - if = "!$ctrl.key.choices && !$ctrl.key.multiline" placeholder = "{{ $ctrl.key.help }}" title = "{{ $ctrl.key.help }}" >
< textarea class = "form-control flag" id = "sol_{{ $ctrl.kid }}_{{ $index }}" autocomplete = "off" name = "sol_{{ $ctrl.kid }}_{{ $index }}" ng - model = "$ctrl.key.values[$index]" ng - if = "!$ctrl.key.choices && $ctrl.key.multiline" placeholder = "{{ $ctrl.key.help }}" title = "{{ $ctrl.key.help }}" > < / t e x t a r e a >
2019-01-17 21:30:39 +00:00
< select class = "custom-select" id = "sol_{{ $ctrl.kid }}" name = "sol_{{ $ctrl.kid }}" ng - model = "$ctrl.key.values[$index]" ng - if = "$ctrl.key.choices" ng - options = "l as v for (l, v) in $ctrl.key.choices" > < / s e l e c t >
< div class = "input-group-append" ng - if = "$ctrl.key.choices_cost" >
< button class = "btn btn-success" type = "button" ng - click = "$ctrl.wantchoices($ctrl.kid)" ng - class = "{disabled: $ctrl.key.wcsubmitted}" title = "Cliquez pour échanger ce champ de texte par une liste de choix. L'opération vous coûtera {{ $ctrl.key.choices_cost * $ctrl.settings.wchoiceCurrentCoefficient }} points." >
< span class = "glyphicon glyphicon-tasks" aria - hidden = "true" > < / s p a n >
Liste de propositions ( < ng - pluralize count = "$ctrl.key.choices_cost * $ctrl.settings.wchoiceCurrentCoefficient" when = "{'one': '{} point', 'other': '{} points'}" > < / n g - p l u r a l i z e > )
< / b u t t o n >
< / d i v >
2019-11-25 16:45:41 +00:00
< div class = "input-group-append" ng - if = "$ctrl.key.separator && !$ctrl.key.nb_lines && $last" >
2019-01-17 21:30:39 +00:00
< button class = "btn btn-success" type = "button" ng - click = "$ctrl.additem(key)" title = "Ajouter un élément." >
< span class = "glyphicon glyphicon-plus" aria - hidden = "true" > < / s p a n >
< / b u t t o n >
< / d i v >
< / d i v >
< small class = "form-text text-muted" ng - if = "!$ctrl.key.found && $ctrl.key.help2.length > 0" ng - bind = "$ctrl.key.help2" > < / s m a l l >
< span class = "glyphicon glyphicon-ok form-control-feedback text-success" aria - hidden = "true" ng - if = "$ctrl.key.found" title = "Flag trouvé à {{ $ctrl.key.found | date:'mediumTime'}}" > < / s p a n >
< / d i v >
`
} )
2018-12-01 15:14:34 +00:00
. controller ( "DataController" , function ( $sce , $scope , $http , $rootScope , $interval , $location ) {
2016-01-21 00:38:43 +00:00
var actMenu = function ( ) {
if ( $scope . my && $scope . themes ) {
2018-11-25 04:01:26 +00:00
var tags = { } ;
2016-01-21 00:38:43 +00:00
angular . forEach ( $scope . themes , function ( theme , key ) {
$scope . themes [ key ] . exercice _solved = 0 ;
2018-11-27 18:59:47 +00:00
var last _exercice = null ;
2016-01-21 00:38:43 +00:00
angular . forEach ( theme . exercices , function ( exercice , k ) {
2018-11-27 18:59:47 +00:00
if ( last _exercice != null )
last _exercice . next = k ;
last _exercice = exercice ;
2017-12-14 02:20:38 +00:00
if ( $scope . my . exercices && $scope . my . exercices [ k ] && $scope . my . exercices [ k ] . solved ) {
2016-01-21 00:38:43 +00:00
$scope . themes [ key ] . exercice _solved ++ ;
}
2018-11-25 04:01:26 +00:00
angular . forEach ( exercice . tags , function ( tag ) {
if ( ! tags [ tag ] )
tags [ tag ] = { count : 1 , solved : 0 } ;
else
tags [ tag ] . count += 1 ;
if ( $scope . my . exercices && $scope . my . exercices [ k ] && $scope . my . exercices [ k ] . solved )
tags [ tag ] . solved += 1 ;
} ) ;
2016-01-21 00:38:43 +00:00
} ) ;
} ) ;
2018-11-25 04:01:26 +00:00
$scope . tags = tags ;
2018-12-04 19:11:21 +00:00
$scope . tagsl = Object . keys ( tags ) . sort ( ) ;
2016-01-21 00:38:43 +00:00
}
}
2018-12-01 15:14:34 +00:00
var refreshSettingsInterval
var refreshSettings = function ( ) {
if ( refreshSettingsInterval )
$interval . cancel ( refreshSettingsInterval ) ;
refreshSettingsInterval = $interval ( refreshSettings , Math . floor ( Math . random ( ) * 24000 ) + 32000 ) ;
2019-02-04 16:38:12 +00:00
$http . get ( "settings.json" ) . then ( function ( response ) {
2019-01-17 12:03:15 +00:00
var time = $rootScope . recvTime ( response ) ;
2019-02-18 17:00:54 +00:00
if ( response . data . start )
response . data . start = new Date ( response . data . start ) ;
if ( response . data . end )
response . data . end = new Date ( response . data . end ) ;
if ( response . data . generation )
response . data . generation = new Date ( response . data . generation ) ;
if ( response . data . activateTime )
response . data . activateTime = new Date ( response . data . activateTime ) ;
if ( $rootScope . settings === undefined || response . data . activateTime === undefined || response . data . activateTime <= new Date ( Date . now ( ) + ( time . cu - time . he ) ) ) {
2019-01-17 12:03:15 +00:00
$rootScope . settings = response . data ;
2019-01-19 07:04:10 +00:00
if ( response . data . eventKindness && refreshEventsInterval ) {
$interval . cancel ( refreshEventsInterval ) ;
refreshEventsInterval = null ;
}
else if ( ! response . data . eventKindness && ! refreshEventsInterval ) {
refreshEvents ( ) ;
}
}
2019-01-17 12:03:15 +00:00
else
$rootScope . settings . activateTime = response . data . activateTime ;
2018-12-01 15:14:34 +00:00
} ) ;
}
2020-01-23 15:03:31 +00:00
var refreshIssuesInterval
var refreshIssues = function ( ) {
if ( refreshIssuesInterval )
$interval . cancel ( refreshIssuesInterval ) ;
refreshIssuesInterval = $interval ( refreshIssues , Math . floor ( Math . random ( ) * 24000 ) + 32000 ) ;
$http . get ( "issues.json" ) . then ( function ( response ) {
$rootScope . issues _nb _responses = 0 ;
$rootScope . issues _need _info = 0 ;
$rootScope . issues = response . data ;
$rootScope . issues . forEach ( function ( issue ) {
$rootScope . issues _nb _responses += issue . texts . length ;
if ( issue . state == 'need-info' ) $rootScope . issues _need _info ++ ;
} )
} ) ;
}
2018-12-01 15:14:34 +00:00
var refreshThemesInterval
var refreshThemes = function ( ) {
if ( refreshThemesInterval )
$interval . cancel ( refreshThemesInterval ) ;
refreshThemesInterval = $interval ( refreshThemes , Math . floor ( Math . random ( ) * 24000 ) + 32000 ) ;
2019-02-04 16:38:12 +00:00
$http . get ( "themes.json" ) . then ( function ( response ) {
2018-12-01 15:14:34 +00:00
$scope . themes = response . data ;
$scope . max _gain = 0 ;
$scope . max _solved = 0 ;
$scope . themesUrl = { } ;
$scope . exercicesUrl = { } ;
angular . forEach ( response . data , function ( theme , key ) {
$scope . themesUrl [ theme . urlid ] = key ;
this [ key ] . exercice _count = Object . keys ( theme . exercices ) . length ;
this [ key ] . exercice _coeff _max = 0 ;
this [ key ] . gain = 0 ;
this [ key ] . solved = 0 ;
angular . forEach ( theme . exercices , function ( ex , k ) {
2018-12-05 14:22:35 +00:00
$scope . exercicesUrl [ theme . urlid + "/" + ex . urlid ] = k ;
2018-12-01 15:14:34 +00:00
this . gain += ex . gain ;
this . solved += ex . solved ;
this . exercice _coeff _max = Math . max ( this . exercice _coeff _max , ex . curcoeff ) ;
} , theme ) ;
$scope . max _gain += theme . gain ;
$scope . max _solved = Math . max ( $scope . max _solved , theme . solved ) ;
} , response . data ) ;
2016-01-21 00:38:43 +00:00
actMenu ( ) ;
2018-12-01 15:14:34 +00:00
} ) ;
}
var refreshTeamsInterval ;
$rootScope . refreshTeams = function ( ) {
if ( refreshTeamsInterval )
$interval . cancel ( refreshTeamsInterval ) ;
refreshTeamsInterval = $interval ( $rootScope . refreshTeams , Math . floor ( Math . random ( ) * 24000 ) + 32000 ) ;
2019-02-04 16:38:12 +00:00
$http . get ( "teams.json" ) . then ( function ( response ) {
2018-12-01 15:14:34 +00:00
var teams = response . data ;
$scope . teams _count = Object . keys ( teams ) . length
$scope . teams = teams ;
$scope . rank = [ ] ;
angular . forEach ( $scope . teams , function ( team , tid ) {
team . id = tid ;
this . push ( team ) ;
} , $scope . rank ) ;
} ) ;
}
2018-12-01 17:15:03 +00:00
var refreshEventsInterval ;
var eventsLastRefresh ;
var eventsLastTreated ;
var refreshEvents = function ( ) {
if ( refreshEventsInterval )
$interval . cancel ( refreshEventsInterval ) ;
var refreshRate = 1200 ;
if ( $rootScope . notify _field == 0 && eventsLastTreated )
refreshRate = 30000 ;
2019-01-25 07:29:39 +00:00
if ( $scope . my && ! $scope . my . team _id )
return ;
2018-12-01 17:15:03 +00:00
refreshEventsInterval = $interval ( refreshEvents , Math . floor ( Math . random ( ) * refreshRate * 2 ) + refreshRate ) ;
if ( ! eventsLastTreated ) {
eventsLastTreated = $rootScope . getSrvTime ( ) ;
if ( ! eventsLastTreated )
return ;
}
2019-02-04 16:38:12 +00:00
$http . get ( "events.json" ) . then ( function ( response ) {
2018-12-01 17:15:03 +00:00
if ( eventsLastRefresh != undefined && eventsLastRefresh == response . headers ( ) [ "last-modified" ] )
return ;
eventsLastRefresh = response . headers ( ) [ "last-modified" ] ;
var maxTimeSeen = eventsLastTreated ;
for ( var i = response . data . length - 1 ; i >= 0 ; i -- ) {
var event = response . data [ i ] ;
event . time = new Date ( event . time ) ;
if ( event . time <= eventsLastTreated )
continue ;
else if ( event . time > maxTimeSeen )
maxTimeSeen = event . time ;
2019-01-19 07:04:54 +00:00
// Determine the kind of event
var kind = 1 ;
if ( event . txt . match ( /<\/strong> qui vient de nous rejoindre/ ) ) {
kind = 64 ;
} else {
var res = event . txt . match ( /(\w+) le <strong>\d+<sup>e<\/sup><\/strong> défi [^&]+/ )
if ( res ) {
if ( res [ 1 ] == "résolu" )
kind = 8 ;
else if ( res [ 1 ] == "pour" )
kind = 16 ;
else if ( res [ 1 ] == "tente" )
kind = 32 ;
}
}
if ( kind != 1 ) {
if ( $scope . my && $scope . my . name && event . txt . indexOf ( $scope . my . name ) >= 0 )
kind |= 2 ;
else
kind |= 4 ;
}
if ( ( kind & $rootScope . notify _field ) == kind ) {
2019-01-17 18:50:16 +00:00
var notification = new Notification ( "Challenge forensic" , { body : event . txt . replace ( /&#(\d+);/g , function ( match , dec ) { return String . fromCharCode ( dec ) ; } ) . replace ( /(<([^>]+)>)/ig , "" ) , badge : "/img/icon-" + event . kind + ".ico" , icon : "/img/icon-" + event . kind + ".ico" } ) ;
2018-12-01 17:15:03 +00:00
notification . onclick = function ( ev ) {
2019-02-04 16:38:12 +00:00
$location . url ( "edit" ) ;
2018-12-01 17:15:03 +00:00
} ;
setTimeout ( notification . close . bind ( notification ) , 4000 ) ;
}
} ;
if ( maxTimeSeen > eventsLastTreated )
eventsLastTreated = maxTimeSeen ;
} ) ;
}
2018-12-01 15:14:34 +00:00
var refreshMyInterval ;
var refreshMy = function ( ) {
if ( refreshMyInterval )
$interval . cancel ( refreshMyInterval ) ;
refreshMyInterval = $interval ( refreshMy , Math . floor ( Math . random ( ) * 24000 ) + 24000 ) ;
2019-02-04 16:38:12 +00:00
$http . get ( "my.json" ) . then ( function ( response ) {
2018-12-02 00:24:38 +00:00
$rootScope . recvMy ( response . data ) ;
} , function ( response ) {
if ( ! $scope . my && response . status == 404 ) {
2019-02-04 16:38:12 +00:00
$location . url ( "register" ) ;
2018-12-02 00:24:38 +00:00
}
} ) ;
}
$rootScope . recvMy = function ( data ) {
if ( data . team _id == 0 ) {
angular . forEach ( data . exercices , function ( exercice , eid ) {
2017-11-12 21:14:03 +00:00
angular . forEach ( exercice . hints , function ( hint , hid ) {
2018-12-01 15:14:34 +00:00
if ( $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . hints [ hid ] && $scope . my . exercices [ eid ] . hints [ hid ] . hidden !== undefined )
2018-12-02 00:24:38 +00:00
data . exercices [ eid ] . hints [ hid ] . hidden = $scope . my . exercices [ eid ] . hints [ hid ] . hidden ;
2018-12-01 15:14:34 +00:00
else
2018-12-02 00:24:38 +00:00
data . exercices [ eid ] . hints [ hid ] . hidden = true ;
2017-11-12 21:14:03 +00:00
} ) ;
} ) ;
}
2018-12-02 00:24:38 +00:00
angular . forEach ( data . exercices , function ( exercice , eid ) {
2019-01-18 03:41:17 +00:00
if ( $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . submitted )
data . exercices [ eid ] . timeouted = true ;
2019-01-25 06:26:52 +00:00
if ( $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . solved !== undefined )
data . exercices [ eid ] . solved = $scope . my . exercices [ eid ] . solved ;
2019-02-03 20:01:17 +00:00
if ( $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . solved _time !== undefined && data . exercices [ eid ] . solved _time === undefined )
data . exercices [ eid ] . solved _time = $scope . my . exercices [ eid ] . solved _time ;
if ( $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . tries !== undefined && data . exercices [ eid ] . tries === undefined )
data . exercices [ eid ] . tries = $scope . my . exercices [ eid ] . tries ;
2018-12-02 00:04:25 +00:00
angular . forEach ( exercice . flags , function ( flag , fid ) {
2019-01-25 06:26:52 +00:00
if ( $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . flags && $scope . my . exercices [ eid ] . flags [ fid ] && $scope . my . exercices [ eid ] . flags [ fid ] . found !== undefined )
data . exercices [ eid ] . flags [ fid ] . found = $scope . my . exercices [ eid ] . flags [ fid ] . found ;
2019-01-18 03:23:18 +00:00
if ( $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . flags && $scope . my . exercices [ eid ] . flags [ fid ] && $scope . my . exercices [ eid ] . flags [ fid ] . value !== undefined )
2018-12-02 00:24:38 +00:00
data . exercices [ eid ] . flags [ fid ] . value = $scope . my . exercices [ eid ] . flags [ fid ] . value ;
2019-01-18 03:23:18 +00:00
if ( $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . flags && $scope . my . exercices [ eid ] . flags [ fid ] && $scope . my . exercices [ eid ] . flags [ fid ] . values !== undefined )
2018-12-04 17:34:38 +00:00
data . exercices [ eid ] . flags [ fid ] . values = $scope . my . exercices [ eid ] . flags [ fid ] . values ;
2019-11-25 16:45:41 +00:00
else if ( data . exercices [ eid ] . flags [ fid ] . nb _lines )
data . exercices [ eid ] . flags [ fid ] . values = Array ( data . exercices [ eid ] . flags [ fid ] . nb _lines ) ;
2018-12-04 17:34:38 +00:00
else
data . exercices [ eid ] . flags [ fid ] . values = [ "" ] ;
2018-12-02 00:04:25 +00:00
} ) ;
2019-01-25 06:26:52 +00:00
angular . forEach ( exercice . mcqs , function ( mcq , mid ) {
if ( $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . mcqs && $scope . my . exercices [ eid ] . mcqs [ mid ] && $scope . my . exercices [ eid ] . mcqs [ mid ] . solved !== undefined )
data . exercices [ eid ] . mcqs [ mid ] . solved = $scope . my . exercices [ eid ] . mcqs [ mid ] . solved ;
} ) ;
2018-12-02 00:04:25 +00:00
} ) ;
2018-12-02 00:24:38 +00:00
angular . forEach ( data . exercices , function ( exercice , eid ) {
2018-12-02 00:04:25 +00:00
angular . forEach ( exercice . mcqs , function ( mcq , mid ) {
angular . forEach ( mcq . choices , function ( choice , cid ) {
2018-12-02 03:52:15 +00:00
if ( ! ( choice instanceof Object ) )
this [ cid ] = {
label : choice ,
} ;
2019-01-17 21:30:39 +00:00
this [ cid ] . disabled = mcq . solved || mcq . part _solved || ( this [ cid ] . justification && this [ cid ] . justification . solved ) ;
2018-12-02 03:52:15 +00:00
if ( ! this [ cid ] . disabled )
this [ cid ] . value = $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . mcqs [ mid ] && $scope . my . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] && $scope . my . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] . value
2018-12-02 00:04:25 +00:00
2019-01-17 21:30:39 +00:00
if ( mcq . justify ) {
if ( ! this [ cid ] . justification )
this [ cid ] . justification = { } ;
if ( ! this [ cid ] . justification . label ) {
this [ cid ] . justification . label = "Flag correspondant" ;
this [ cid ] . justification . help2 = "Trouvez et validez les choix du QCM pour avoir des indications supplémentaires" ;
}
if ( $scope . my && $scope . my . exercices [ eid ] && $scope . my . exercices [ eid ] . mcqs [ mid ] && $scope . my . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] && $scope . my . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] . justification ) {
if ( $scope . my . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] . justification . value !== undefined )
data . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] . justification . value = $scope . my . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] . justification . value ;
if ( $scope . my . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] . justification . values !== undefined )
data . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] . justification . values = $scope . my . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] . justification . values ;
else
data . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] . justification . values = [ "" ] ;
}
else
data . exercices [ eid ] . mcqs [ mid ] . choices [ cid ] . justification . values = [ "" ] ;
2018-12-02 00:04:25 +00:00
}
} , mcq . choices ) ;
} ) ;
} ) ;
2018-12-01 15:14:34 +00:00
$scope . my = data ;
angular . forEach ( $scope . my . exercices , function ( exercice , eid ) {
exercice . solved = exercice . solved _rank > 0 ;
if ( exercice . video _uri ) {
exercice . video _uri = $sce . trustAsResourceUrl ( exercice . video _uri ) ;
}
} ) ;
actMenu ( ) ;
}
2019-01-17 12:03:15 +00:00
$rootScope . refresh = function ( justMy , justSettings ) {
2018-12-01 15:14:34 +00:00
if ( ! justMy ) {
refreshSettings ( ) ;
refreshThemes ( ) ;
$rootScope . refreshTeams ( ) ;
2018-12-01 17:15:03 +00:00
refreshEvents ( ) ;
2020-01-23 15:03:31 +00:00
refreshIssues ( ) ;
2018-12-01 15:14:34 +00:00
}
2019-01-17 12:03:15 +00:00
else if ( justSettings ) {
refreshSettings ( ) ;
}
2018-12-01 15:14:34 +00:00
refreshMy ( ) ;
2016-01-21 00:38:43 +00:00
}
2016-01-23 11:29:19 +00:00
$rootScope . refresh ( ) ;
2016-01-21 00:38:43 +00:00
} )
2016-12-09 10:55:58 +00:00
. controller ( "ExerciceController" , function ( $scope , $routeParams , $http , $rootScope , $timeout ) {
2018-11-25 01:02:06 +00:00
if ( window . scrollY > 112 )
window . scrollTo ( window . scrollX , 112 ) ;
2018-11-25 04:48:44 +00:00
$rootScope . current _tag = undefined ;
2018-11-21 04:36:52 +00:00
$scope . $watch ( "themesUrl" , function ( themesUrl ) {
if ( themesUrl != undefined )
$rootScope . current _theme = themesUrl [ $routeParams . theme ] ;
} )
2016-01-21 00:38:43 +00:00
if ( $routeParams . exercice ) {
2018-11-21 04:36:52 +00:00
$scope . $watch ( "exercicesUrl" , function ( exercicesUrl ) {
if ( exercicesUrl != undefined )
2018-12-05 14:22:35 +00:00
$rootScope . current _exercice = exercicesUrl [ $routeParams . theme + "/" + $routeParams . exercice ] ;
2018-11-21 04:36:52 +00:00
} )
2019-01-20 23:35:07 +00:00
$scope . $watchGroup ( [ "themes" , "current_theme" , "current_exercice" ] , function ( newValues ) {
var themes = newValues [ 0 ] ;
var current _theme = newValues [ 1 ] ;
var current _exercice = newValues [ 2 ] ;
if ( themes != undefined && themes [ current _theme ] != undefined && themes [ current _theme ] . exercices != undefined && themes [ current _theme ] . exercices [ current _exercice ] != undefined )
$rootScope . title = themes [ current _theme ] . name + " > " + themes [ current _theme ] . exercices [ current _exercice ] . title ;
} ) ;
2016-01-21 00:38:43 +00:00
} else {
2018-11-25 02:08:07 +00:00
$rootScope . current _exercice = 0 ;
2019-01-20 23:35:07 +00:00
$scope . $watchGroup ( [ "themes" , "current_theme" ] , function ( newValues ) {
var themes = newValues [ 0 ] ;
var current _theme = newValues [ 1 ] ;
if ( themes != undefined && themes [ current _theme ] != undefined )
$rootScope . title = themes [ current _theme ] . name ;
} ) ;
2016-01-21 00:38:43 +00:00
}
2018-12-01 15:14:34 +00:00
var cbh ;
2016-12-09 10:55:58 +00:00
$scope . hsubmit = function ( hint ) {
hint . submitted = true ;
2018-12-01 15:13:53 +00:00
$scope . hinterror = null ;
2019-02-04 16:38:12 +00:00
$http ( { url : "openhint/" + $rootScope . current _exercice , method : "POST" , data : { id : hint . id } } ) . then ( function ( response ) {
2016-12-09 10:55:58 +00:00
var checkDiffHint = function ( ) {
2019-02-04 16:38:12 +00:00
$http . get ( "my.json" ) . then ( function ( response ) {
2017-12-14 02:20:38 +00:00
var my = response . data ;
2016-12-09 10:55:58 +00:00
angular . forEach ( my . exercices [ $rootScope . current _exercice ] . hints , function ( h , hid ) {
if ( hint . id == h . id ) {
if ( hint . content != h . content ) {
2018-12-01 15:14:34 +00:00
$rootScope . recvMy ( my ) ;
2016-12-09 10:55:58 +00:00
} else {
2018-12-01 15:14:34 +00:00
if ( cbh )
$timeout . cancel ( cbh ) ;
cbh = $timeout ( checkDiffHint , 750 ) ;
2016-12-09 10:55:58 +00:00
}
}
} ) ;
} ) ;
} ;
checkDiffHint ( ) ;
2018-12-01 15:14:34 +00:00
} , function ( response ) {
2018-12-01 15:13:53 +00:00
$scope . hinterror = response . data . errmsg ;
2016-12-09 10:55:58 +00:00
hint . submitted = false ;
} ) ;
} ;
2016-01-23 11:29:19 +00:00
} )
. controller ( "SubmissionController" , function ( $scope , $http , $rootScope , $timeout ) {
2018-12-01 23:43:11 +00:00
$scope . sberr = null ;
2016-01-23 11:29:19 +00:00
2018-12-01 15:14:34 +00:00
var cbs ;
var cbd ;
2016-01-23 11:29:19 +00:00
$scope . ssubmit = function ( ) {
2018-11-28 06:39:50 +00:00
var resp = { }
2018-11-28 03:15:14 +00:00
var check = undefined
2018-12-01 23:43:11 +00:00
$scope . sberr = null ;
2016-01-23 11:29:19 +00:00
2018-11-28 01:27:51 +00:00
if ( $scope . my . exercices [ $rootScope . current _exercice ] . flags && Object . keys ( $scope . my . exercices [ $rootScope . current _exercice ] . flags ) . length )
2017-12-16 01:12:44 +00:00
{
2018-11-28 06:39:50 +00:00
resp [ "flags" ] = { } ;
2018-11-28 01:27:51 +00:00
angular . forEach ( $scope . my . exercices [ $rootScope . current _exercice ] . flags , function ( flag , kid ) {
2019-01-25 06:26:52 +00:00
if ( check === undefined ) check = true ;
check &= treatFlagKey ( flag ) || flag . found ;
if ( flag . soluce === undefined ) {
check = undefined ;
if ( flag . found == null ) {
resp [ "flags" ] [ kid ] = flag . value ;
}
2018-11-28 03:15:14 +00:00
}
2017-12-16 01:12:44 +00:00
} ) ;
}
2018-11-28 01:27:51 +00:00
if ( $scope . my . exercices [ $rootScope . current _exercice ] . mcqs && Object . keys ( $scope . my . exercices [ $rootScope . current _exercice ] . mcqs ) . length )
2017-12-16 01:12:44 +00:00
{
resp [ "mcqs" ] = { } ;
2018-11-28 01:27:51 +00:00
angular . forEach ( $scope . my . exercices [ $rootScope . current _exercice ] . mcqs , function ( mcq ) {
2019-01-25 06:26:52 +00:00
var soluce = "" ;
2018-11-28 03:15:14 +00:00
if ( mcq . solved == null ) {
angular . forEach ( mcq . choices , function ( choice , cid ) {
if ( mcq . soluce !== undefined ) {
if ( check === undefined ) check = true ;
soluce += choice . value ? "t" : "f" ;
} else {
2018-11-28 05:39:38 +00:00
if ( choice . value ) {
resp [ "mcqs" ] [ cid ] = choice . value ;
2019-01-17 21:30:39 +00:00
if ( choice . justification !== undefined ) {
2018-11-28 06:39:50 +00:00
if ( resp [ "justifications" ] == undefined )
resp [ "justifications" ] = { } ;
2019-01-17 21:30:39 +00:00
treatFlagKey ( choice . justification ) ;
resp [ "justifications" ] [ cid ] = choice . justification . value ;
2018-11-28 05:39:38 +00:00
}
}
2018-11-28 03:15:14 +00:00
}
} ) ;
if ( mcq . soluce !== undefined ) {
if ( mcq . soluce == b2sum ( soluce ) )
mcq . solved = new Date ( ) ;
check &= mcq . solved ;
}
}
2017-12-16 01:12:44 +00:00
} ) ;
}
2016-01-23 11:29:19 +00:00
2018-11-28 03:15:14 +00:00
if ( check !== undefined )
{
2019-02-03 20:00:41 +00:00
if ( ! $scope . my . exercices [ $rootScope . current _exercice ] . tries )
$scope . my . exercices [ $rootScope . current _exercice ] . tries = 0 ;
2018-11-28 03:15:14 +00:00
$scope . my . exercices [ $rootScope . current _exercice ] . tries += 1 ;
$scope . my . exercices [ $rootScope . current _exercice ] . solved _time = new Date ( ) ;
if ( check ) {
$scope . my . exercices [ $rootScope . current _exercice ] . solved = true ;
}
return ;
}
2019-02-04 16:38:12 +00:00
$http ( { url : "submit/" + $rootScope . current _exercice , method : "POST" , data : resp } ) . then ( function ( response ) {
2018-12-01 23:43:11 +00:00
$scope . messageClass = { "text-success" : true } ;
$scope . message = response . data . errmsg ;
$scope . sberr = null ;
2016-01-24 13:32:46 +00:00
angular . forEach ( $scope . flags , function ( flag , kid ) {
flag . value = "" ;
} ) ;
2016-01-21 00:38:43 +00:00
2016-01-23 11:29:19 +00:00
var checkDiff = function ( ) {
2019-02-04 16:38:12 +00:00
$http . get ( "my.json" ) . then ( function ( response ) {
2017-12-14 02:20:38 +00:00
var my = response . data ;
2017-12-16 01:12:44 +00:00
if ( $scope . my . exercices [ $rootScope . current _exercice ] . tries != my . exercices [ $rootScope . current _exercice ] . tries || $scope . my . exercices [ $rootScope . current _exercice ] . solved _time != my . exercices [ $rootScope . current _exercice ] . solved _time ) {
2019-01-19 23:17:52 +00:00
$scope . my . exercices [ $rootScope . current _exercice ] . submitted = false ;
2018-12-01 15:14:34 +00:00
$rootScope . recvMy ( my ) ;
$rootScope . refreshTeams ( ) ;
2016-01-21 00:38:43 +00:00
} else {
2018-12-01 15:14:34 +00:00
if ( cbd )
$timeout . cancel ( cbd ) ;
cbd = $timeout ( checkDiff , 750 ) ;
2016-01-21 00:38:43 +00:00
}
} ) ;
} ;
2016-01-23 12:19:59 +00:00
checkDiff ( ) ;
2018-12-01 23:43:11 +00:00
} , function ( response ) {
if ( response . status >= 500 ) {
2016-01-21 00:38:43 +00:00
$scope . my . exercices [ $rootScope . current _exercice ] . submitted = false ;
}
2018-12-01 23:43:11 +00:00
$scope . messageClass = { "text-danger" : true } ;
$scope . sberr = "Oups !" ;
$scope . message = response . data . errmsg ;
2016-01-21 00:38:43 +00:00
} ) ;
2019-01-18 03:41:17 +00:00
$scope . my . exercices [ $rootScope . current _exercice ] . timeouted = false ;
2016-01-21 00:38:43 +00:00
$scope . my . exercices [ $rootScope . current _exercice ] . submitted = true ;
} ;
2018-12-02 22:18:32 +00:00
$scope . wantchoices = function ( kid ) {
$scope . my . exercices [ $rootScope . current _exercice ] . flags [ kid ] . wcsubmitted = true ;
2019-02-04 16:38:12 +00:00
$http ( { url : "wantchoices/" + $rootScope . current _exercice , method : "POST" , data : { id : Math . floor ( kid ) } } ) . then ( function ( response ) {
2018-12-02 22:18:32 +00:00
var checkDiffWC = function ( ) {
2019-02-04 16:38:12 +00:00
$http . get ( "my.json" ) . then ( function ( response ) {
2018-12-02 22:18:32 +00:00
var my = response . data ;
if ( my . exercices [ $rootScope . current _exercice ] . flags [ kid ] . choices )
$rootScope . recvMy ( my ) ;
else {
if ( cbd )
$timeout . cancel ( cbd ) ;
cbd = $timeout ( checkDiffWC , 750 ) ;
}
} ) ;
} ;
checkDiffWC ( ) ;
} , function ( response ) {
$scope . messageClass = { "text-danger" : true } ;
$scope . sberr = "Oups !" ;
$scope . message = response . data . errmsg ;
$scope . my . exercices [ $rootScope . current _exercice ] . flags [ kid ] . wcsubmitted = false ;
} ) ;
}
2016-01-16 21:40:59 +00:00
} )
2020-01-20 14:56:02 +00:00
. controller ( "IssueController" , function ( $scope , $http , $rootScope , $routeParams ) {
$rootScope . current _tag = undefined ;
$rootScope . current _exercice = $routeParams . eid ;
2020-01-23 15:03:31 +00:00
$rootScope . issues _known _responses = $rootScope . issues _nb _responses ;
2020-01-20 14:56:02 +00:00
$scope . issue = {
id _exercice : parseInt ( $routeParams . eid , 10 ) ,
subject : "" ,
description : "" ,
}
$scope . isubmit = function ( ) {
$rootScope . sberr = "" ;
if ( $scope . issue . subject . length < 3 ) {
$rootScope . messageClass = { "text-danger" : true } ;
$rootScope . sberr = "L'object de votre rapport d'anomalie est trop court !" ;
return false ;
}
$http ( {
url : "submit/issue" ,
method : "POST" ,
data : $scope . issue
} ) . then ( function ( response ) {
$rootScope . messageClass = { "text-success" : true } ;
$rootScope . message = response . data . errmsg ;
$scope . issue . subject = "" ;
$scope . issue . description = "" ;
} , function ( response ) {
$rootScope . messageClass = { "text-danger" : true } ;
$rootScope . message = response . data . errmsg ;
if ( response . status != 402 ) {
$rootScope . sberr = "Une erreur est survenue lors de l'envoi. Veuillez réessayer dans quelques instants." ;
}
} ) ;
} ;
} )
2019-01-19 07:04:54 +00:00
. controller ( "MyTeamController" , function ( $scope , $http , $rootScope , $timeout , $location ) {
2016-01-16 21:40:59 +00:00
$rootScope . current _theme = 0 ;
$rootScope . current _exercice = 0 ;
2018-11-25 04:48:44 +00:00
$rootScope . current _tag = undefined ;
2016-01-24 13:23:04 +00:00
if ( $scope . my ) {
$rootScope . title = $scope . my . name ;
$rootScope . authors = $scope . my . members . map ( function ( cur ) {
return cur . firstname . capitalize ( ) + " " + cur . lastname . capitalize ( ) ;
} ) . join ( ", " ) ;
}
$rootScope . message = "" ;
$rootScope . sberr = "" ;
2019-01-19 07:04:54 +00:00
$scope . notify = {
info : ( $rootScope . notify _field & 1 ) != 1 ,
team : ( $rootScope . notify _field & 2 ) != 2 ,
others : ( $rootScope . notify _field & 4 ) != 4 ,
solve : ( $rootScope . notify _field & 8 ) != 8 ,
hint : ( $rootScope . notify _field & 16 ) != 16 ,
tries : ( $rootScope . notify _field & 32 ) != 32 ,
rename : ( $rootScope . notify _field & 64 ) != 64 ,
}
$scope . alternotify = function ( ) {
$rootScope . notify _field =
( $scope . notify . info ? 0 : 1 ) |
( $scope . notify . team ? 0 : 2 ) |
( $scope . notify . others ? 0 : 4 ) |
( $scope . notify . solve ? 0 : 8 ) |
( $scope . notify . hint ? 0 : 16 ) |
( $scope . notify . tries ? 0 : 32 ) |
( $scope . notify . rename ? 0 : 64 ) ;
if ( $rootScope . notify _field != 0 )
localStorage . notification = $rootScope . notify _field ;
else
delete localStorage . notification ;
2019-02-04 16:38:12 +00:00
$location . url ( "." ) ;
2019-01-19 07:04:54 +00:00
}
2018-12-01 15:14:34 +00:00
var cbt ;
2016-01-24 13:23:04 +00:00
$scope . tsubmit = function ( ) {
$rootScope . sberr = "" ;
2019-01-17 18:13:46 +00:00
if ( $scope . my . newName . length < 1 ) {
2016-01-24 13:23:04 +00:00
$rootScope . messageClass = { "text-danger" : true } ;
$rootScope . sberr = "Nom d'équipe invalide: pas d'entrée." ;
return false ;
}
2019-01-17 18:13:46 +00:00
else if ( $scope . my . newName . length > 32 ) {
2016-01-24 13:23:04 +00:00
$rootScope . messageClass = { "text-danger" : true } ;
$rootScope . sberr = "Nom d'équipe invalide: pas plus de 32 caractères." ;
return false ;
}
2019-01-17 18:13:46 +00:00
else if ( ! $scope . my . newName . match ( /^[A-Za-z0-9 àéèêëîïôùûü_-]+$/ ) ) {
2016-01-24 13:23:04 +00:00
$rootScope . messageClass = { "text-danger" : true } ;
$rootScope . sberr = "Nom d'équipe invalide: seuls les caractères alpha-numériques sont autorisés." ;
return false ;
}
$http ( {
2019-02-04 16:38:12 +00:00
url : "submit/name" ,
2016-01-24 13:23:04 +00:00
method : "POST" ,
2019-01-17 18:13:46 +00:00
data : { newName : $scope . my . newName }
2018-12-01 15:14:34 +00:00
} ) . then ( function ( response ) {
2016-01-24 13:23:04 +00:00
$rootScope . messageClass = { "text-success" : true } ;
2017-12-14 02:20:38 +00:00
$rootScope . message = response . data . errmsg ;
2016-01-24 13:23:04 +00:00
var checkDiff = function ( ) {
2019-02-04 16:38:12 +00:00
$http . get ( "my.json" ) . then ( function ( response ) {
2017-12-14 02:20:38 +00:00
if ( $scope . my . name != response . data . name ) {
2019-01-17 18:13:46 +00:00
$scope . my . newName = undefined ;
2016-01-24 13:23:04 +00:00
$rootScope . message = "" ;
2018-12-01 15:14:34 +00:00
$rootScope . recvMy ( response . data ) ;
$rootScope . refreshTeams ( ) ;
2016-01-24 13:23:04 +00:00
} else {
2018-12-01 15:14:34 +00:00
if ( cbt )
$timeout . cancel ( cbt ) ;
cbt = $timeout ( checkDiff , 750 ) ;
2016-01-24 13:23:04 +00:00
}
} ) ;
} ;
checkDiff ( ) ;
2018-12-01 15:14:34 +00:00
} , function ( response ) {
2016-01-24 13:23:04 +00:00
$rootScope . messageClass = { "text-danger" : true } ;
2017-12-14 02:20:38 +00:00
$rootScope . message = response . data . errmsg ;
2018-12-01 15:14:34 +00:00
if ( response . status != 402 ) {
2016-01-24 13:23:04 +00:00
$rootScope . sberr = "Une erreur est survenue lors de l'envoi. Veuillez réessayer dans quelques instants." ;
}
} ) ;
} ;
2016-01-16 21:40:59 +00:00
} )
2018-12-02 01:12:53 +00:00
. controller ( "RegisterController" , function ( $scope , $rootScope , $location , $http , $interval ) {
2017-12-21 21:18:18 +00:00
$rootScope . current _theme = 0 ;
$rootScope . current _exercice = 0 ;
2018-11-25 04:48:44 +00:00
$rootScope . current _tag = undefined ;
2017-12-21 21:18:18 +00:00
$rootScope . title = "Bienvenue au challenge forensic !" ;
$rootScope . authors = null ;
2019-02-04 17:14:46 +00:00
$scope . form = { "teamName" : "" , "jTeam" : 0 , "members" : [ { } ] } ;
2017-12-21 21:18:18 +00:00
$scope . AddMember = function ( ) {
2018-12-02 01:12:53 +00:00
$scope . form . members . push ( { } ) ;
2017-12-21 21:18:18 +00:00
}
$scope . RemoveMember = function ( k ) {
2018-12-02 01:12:53 +00:00
$scope . form . members . splice ( k , 1 ) ;
2017-12-21 21:18:18 +00:00
}
$scope . Validate = function ( ) {
2018-12-02 01:12:53 +00:00
if ( $scope . form . teamName . length <= 3 ) {
2017-12-21 21:18:18 +00:00
$ ( '#teamName' ) . addClass ( "is-invalid" )
return ;
} else {
2019-02-04 17:14:46 +00:00
$ ( '#teamName' ) . removeClass ( "is-invalid" )
2017-12-21 21:18:18 +00:00
$ ( '#vldBtn' ) . removeClass ( "input-group-btn" ) ;
$ ( '#vldBtn' ) . css ( "display" , "none" ) ;
2019-02-04 17:14:46 +00:00
$ ( '#jvldBtn' ) . css ( "display" , "none" ) ;
$scope . partR = true ;
$scope . partJ = false ;
}
}
$scope . JValidate = function ( ) {
if ( ! $scope . teams [ $scope . form . jTeam ] ) {
$ ( '#jTeam' ) . addClass ( "is-invalid" )
return ;
} else {
$ ( '#jTeam' ) . removeClass ( "is-invalid" )
$ ( '#jvldBtn' ) . removeClass ( "input-group-btn" ) ;
$ ( '#jvldBtn' ) . css ( "display" , "none" ) ;
$ ( '#vldBtn' ) . css ( "display" , "none" ) ;
$scope . partR = false ;
$scope . partJ = true ;
2017-12-21 21:18:18 +00:00
}
}
2019-02-04 17:14:46 +00:00
var commonsubmit = function ( registration ) {
2017-12-21 21:18:18 +00:00
// Remove empty members
2018-12-02 01:12:53 +00:00
$scope . form . members = $scope . form . members . filter ( function ( m ) {
2017-12-21 21:18:18 +00:00
return ( ( m . lastname != undefined && m . lastname != "" ) || ( m . firstname != undefined && m . firstname != "" ) || ( m . nickname != undefined && m . nickname != "" ) ) ;
} ) ;
2018-12-02 01:12:53 +00:00
if ( $scope . form . members . length == 0 ) {
2017-12-21 21:18:18 +00:00
$scope . messageClass = { "text-danger" : true } ;
$scope . message = "Veuillez ajouter au moins un membre dans votre équipe !" ;
2018-12-02 01:12:53 +00:00
$scope . form . members . push ( { } ) ;
2017-12-21 21:18:18 +00:00
return ;
}
2019-02-04 17:14:46 +00:00
$scope . form . jTeam = parseInt ( $scope . form . jTeam ) ;
2017-12-21 21:18:18 +00:00
$http ( {
2019-02-04 16:38:12 +00:00
url : "registration" ,
2017-12-21 21:18:18 +00:00
method : "POST" ,
2018-12-02 01:12:53 +00:00
data : $scope . form
} ) . then ( function ( response ) {
2017-12-21 21:18:18 +00:00
$scope . messageClass = { "text-success" : true } ;
$scope . message = response . data . errmsg ;
2018-12-02 01:12:53 +00:00
$interval ( function ( ) {
2019-02-04 16:38:12 +00:00
$http . get ( "my.json" ) . then ( function ( response ) {
2018-12-02 01:12:53 +00:00
$rootScope . refresh ( ) ;
} ) ;
} , 1500 ) ;
2017-12-21 21:18:18 +00:00
} , function ( response ) {
$scope . messageClass = { "text-danger" : true } ;
if ( response . data && response . data . errmsg )
$scope . message = response . data . errmsg ;
else
$scope . message = "Une erreur est survenue lors de l'inscription de l'équipe. Veuillez réessayer dans quelques instants." ;
} ) ;
}
2019-02-04 17:14:46 +00:00
$scope . rsubmit = function ( ) {
if ( ! $scope . partR )
return $scope . Validate ( ) ;
else
return commonsubmit ( true ) ;
}
$scope . jsubmit = function ( ) {
if ( ! $scope . partJ )
return $scope . JValidate ( ) ;
else
return commonsubmit ( false ) ;
}
2018-12-02 01:12:53 +00:00
$scope . $watch ( "my" , function ( my ) {
if ( my )
2019-02-04 16:38:12 +00:00
$location . url ( "." ) ;
2018-12-02 01:12:53 +00:00
} ) ;
2017-12-21 21:18:18 +00:00
} )
2018-12-08 19:22:41 +00:00
. controller ( "TagController" , function ( $scope , $rootScope , $routeParams , $location ) {
2018-11-21 02:10:35 +00:00
$rootScope . current _theme = 0 ;
$rootScope . current _exercice = 0 ;
2018-11-25 04:48:44 +00:00
$rootScope . current _tag = $routeParams . tag ;
2018-11-21 02:10:35 +00:00
$rootScope . title = "Challenges " + $routeParams . tag ;
$rootScope . authors = "" ;
$scope . tag = $routeParams . tag ;
$scope . exercices = [ ] ;
$scope . $watch ( "themes" , function ( themes ) {
$scope . exercices = [ ] ;
angular . forEach ( themes , function ( theme , tid ) {
angular . forEach ( theme . exercices , function ( exercice , eid ) {
if ( exercice . tags . indexOf ( $scope . tag ) >= 0 )
$scope . exercices . push ( { "exercice" : exercice , "theme" : theme , "eid" : eid , "tid" : tid } ) ;
} )
} )
} )
2018-12-08 19:22:41 +00:00
$scope . goDefi = function ( ) {
2019-02-04 16:38:12 +00:00
$location . url ( this . ex . theme . urlid + "/" + this . ex . exercice . urlid ) ;
2018-12-08 19:22:41 +00:00
}
2018-11-21 02:10:35 +00:00
} )
2016-01-21 00:38:43 +00:00
. controller ( "RankController" , function ( $scope , $rootScope ) {
$rootScope . current _theme = 0 ;
$rootScope . current _exercice = 0 ;
2018-11-25 04:48:44 +00:00
$rootScope . current _tag = undefined ;
2016-01-21 00:38:43 +00:00
$rootScope . title = "Classement général" ;
2016-01-24 13:32:46 +00:00
$rootScope . authors = "" ;
2016-01-21 00:38:43 +00:00
$scope . fields = [ "rank" , "name" , "score" ] ;
$scope . rankOrder = "rank" ;
$scope . reverse = false ;
$scope . order = function ( fld ) {
if ( $scope . rankOrder == fld ) {
$scope . reverse = ! $scope . reverse ;
} else {
$scope . rankOrder = fld ;
2017-01-14 14:01:18 +00:00
$scope . reverse = ( fld == "score" ) ;
2016-01-21 00:38:43 +00:00
}
} ;
} )
2017-04-02 18:29:15 +00:00
. controller ( "VideosController" , function ( $scope , $rootScope ) {
$rootScope . current _theme = 0 ;
$rootScope . current _exercice = 0 ;
2018-11-25 04:48:44 +00:00
$rootScope . current _tag = undefined ;
2017-04-02 18:29:15 +00:00
$rootScope . title = "Vidéos de résolution" ;
$rootScope . authors = "" ;
} )
2018-12-08 19:22:41 +00:00
. controller ( "HomeController" , function ( $scope , $rootScope , $location ) {
2016-01-16 21:40:59 +00:00
$rootScope . current _theme = 0 ;
$rootScope . current _exercice = 0 ;
2018-11-25 04:48:44 +00:00
$rootScope . current _tag = undefined ;
2018-11-25 01:02:06 +00:00
$rootScope . title = "Bienvenue au challenge forensic de l'ÉPITA !" ;
2016-01-24 13:32:46 +00:00
$rootScope . authors = "" ;
2018-12-08 19:22:41 +00:00
$scope . goTheme = function ( ) {
2019-02-04 16:38:12 +00:00
$location . url ( this . theme . urlid ) ;
2018-12-08 19:22:41 +00:00
}
2016-01-16 21:40:59 +00:00
} ) ;
2016-01-21 00:38:43 +00:00
function sready ( ) {
if ( $ ( "#solution" ) . val ( ) . length ) {
$ ( "#sbmt" ) . removeClass ( "disabled" ) ;
} else {
$ ( "#sbmt" ) . addClass ( "disabled" ) ;
}
} ;