2016-12-26 00:16:49 +00:00
angular . module ( "FICApp" , [ "ngRoute" , "ngResource" , "ngSanitize" ] )
2016-01-13 00:22:54 +00:00
. config ( function ( $routeProvider , $locationProvider ) {
$routeProvider
2016-01-22 16:37:29 +00:00
. when ( "/themes" , {
controller : "ThemesListController" ,
templateUrl : "views/theme-list.html"
} )
. when ( "/themes/:themeId" , {
controller : "ThemeController" ,
templateUrl : "views/theme.html"
} )
2016-12-26 00:23:31 +00:00
. when ( "/themes/:themeId/exercices/:exerciceId" , {
controller : "ExerciceController" ,
templateUrl : "views/exercice.html"
} )
2023-10-23 10:03:40 +00:00
. when ( "/repositories" , {
controller : "RepositoriesController" ,
templateUrl : "views/repositories.html"
} )
2022-05-19 19:15:25 +00:00
. when ( "/sync" , {
controller : "SyncController" ,
templateUrl : "views/sync.html"
} )
2017-01-15 01:37:59 +00:00
. when ( "/settings" , {
controller : "SettingsController" ,
templateUrl : "views/settings.html"
} )
2018-01-21 13:18:26 +00:00
. when ( "/pki" , {
controller : "PKIController" ,
templateUrl : "views/pki.html"
} )
2016-12-26 00:23:31 +00:00
. when ( "/exercices" , {
controller : "AllExercicesListController" ,
templateUrl : "views/exercice-list.html"
} )
. when ( "/exercices/:exerciceId" , {
2016-01-22 16:37:29 +00:00
controller : "ExerciceController" ,
templateUrl : "views/exercice.html"
} )
2020-01-28 13:05:00 +00:00
. when ( "/exercices/:exerciceId/flags" , {
controller : "ExerciceController" ,
templateUrl : "views/exercice-flags.html"
} )
2019-01-19 00:02:10 +00:00
. when ( "/exercices/:exerciceId/resolution" , {
controller : "ExerciceController" ,
templateUrl : "views/exercice-resolution.html"
} )
2022-05-24 19:25:27 +00:00
. when ( "/tags" , {
controller : "TagsListController" ,
templateUrl : "views/tags.html"
} )
2016-01-13 00:22:54 +00:00
. when ( "/teams" , {
controller : "TeamsListController" ,
templateUrl : "views/team-list.html"
} )
2017-04-02 10:43:48 +00:00
. when ( "/teams/print" , {
controller : "TeamsListController" ,
templateUrl : "views/team-print.html"
} )
2017-12-26 22:57:16 +00:00
. when ( "/teams/export" , {
controller : "TeamsListController" ,
templateUrl : "views/team-export.html"
} )
2016-10-13 17:52:54 +00:00
. when ( "/teams/:teamId" , {
2017-01-28 18:36:28 +00:00
controller : "TeamController" ,
templateUrl : "views/team-edit.html"
} )
. when ( "/teams/:teamId/stats" , {
2016-10-13 17:52:54 +00:00
controller : "TeamController" ,
2017-04-02 09:38:40 +00:00
templateUrl : "views/team-stats.html"
2016-10-13 17:52:54 +00:00
} )
2019-01-17 12:51:44 +00:00
. when ( "/teams/:teamId/score" , {
controller : "TeamController" ,
templateUrl : "views/team-score.html"
} )
2017-12-17 23:30:23 +00:00
. when ( "/public/:screenId" , {
2017-01-20 18:18:43 +00:00
controller : "PublicController" ,
templateUrl : "views/public.html"
} )
2017-12-27 00:53:01 +00:00
. when ( "/files" , {
controller : "FilesListController" ,
templateUrl : "views/file-list.html"
} )
2016-12-26 02:44:04 +00:00
. when ( "/events" , {
controller : "EventsListController" ,
templateUrl : "views/event-list.html"
} )
. when ( "/events/:eventId" , {
controller : "EventController" ,
templateUrl : "views/event.html"
} )
2018-01-17 00:21:32 +00:00
. when ( "/claims" , {
controller : "ClaimsListController" ,
templateUrl : "views/claim-list.html"
} )
. when ( "/claims/:claimId" , {
controller : "ClaimController" ,
templateUrl : "views/claim.html"
} )
2016-10-13 17:52:54 +00:00
. when ( "/" , {
templateUrl : "views/home.html"
2016-01-13 00:22:54 +00:00
} ) ;
$locationProvider . html5Mode ( true ) ;
} ) ;
2018-01-17 00:21:32 +00:00
function setCookie ( name , value , days ) {
var expires ;
if ( days ) {
var date = new Date ( ) ;
date . setTime ( date . getTime ( ) + ( days * 24 * 60 * 60 * 1000 ) ) ;
expires = "; expires=" + date . toGMTString ( ) ;
} else {
expires = "" ;
}
document . cookie = encodeURIComponent ( name ) + "=" + encodeURIComponent ( value ) + expires + "; path=/" ;
}
function getCookie ( name ) {
var nameEQ = encodeURIComponent ( name ) + "=" ;
var ca = document . cookie . split ( ';' ) ;
for ( var i = 0 ; i < ca . length ; i ++ ) {
var c = ca [ i ] ;
while ( c . charAt ( 0 ) === ' ' )
c = c . substring ( 1 , c . length ) ;
if ( c . indexOf ( nameEQ ) === 0 )
return decodeURIComponent ( c . substring ( nameEQ . length , c . length ) ) ;
}
return null ;
}
2018-01-07 23:41:23 +00:00
angular . module ( "FICApp" )
. directive ( 'autofocus' , [ '$timeout' , function ( $timeout ) {
return {
restrict : 'A' ,
link : function ( $scope , $element ) {
$timeout ( function ( ) {
$element [ 0 ] . focus ( ) ;
} ) ;
}
}
2020-03-08 11:48:25 +00:00
} ] )
. component ( 'toast' , {
bindings : {
date : '=' ,
msg : '=' ,
timeout : '=' ,
title : '=' ,
variant : '=' ,
yesNo : '=' ,
onyes : '=' ,
onno : '=' ,
} ,
controller : function ( $element ) {
if ( this . timeout === 0 )
$element . children ( 0 ) . toast ( { autohide : false } ) ;
else if ( ! this . timeout && this . timeout !== 0 )
$element . children ( 0 ) . toast ( { delay : 7000 } ) ;
else
$element . children ( 0 ) . toast ( { delay : this . timeout } ) ;
$element . children ( 0 ) . toast ( 'show' ) ;
2022-05-26 09:37:43 +00:00
$element . children ( 0 ) . on ( 'hidden.bs.toast' , function ( ) {
$element . children ( 0 ) . toast ( 'dispose' ) ;
} ) ;
2020-03-08 11:48:25 +00:00
this . yesFunc = function ( ) {
2022-05-26 09:37:43 +00:00
$element . children ( 0 ) . toast ( 'hide' ) ;
2020-03-08 11:48:25 +00:00
if ( this . onyes )
this . onyes ( ) ;
}
this . noFunc = function ( ) {
2022-05-26 09:37:43 +00:00
$element . children ( 0 ) . toast ( 'hide' ) ;
2020-03-08 11:48:25 +00:00
if ( this . onno )
this . onno ( ) ;
}
} ,
template : ` <div class="toast mb-2" role="alert" aria-live="assertive" aria-atomic="true">
< div class = "toast-header" >
< span ng - if = "$ctrl.variant" class = "badge badge-pill badge-{{ $ctrl.variant }}" style = "padding: .25em .66em" > & nbsp ; < / s p a n > & n b s p ;
< strong class = "mr-auto" ng - bind = "$ctrl.title" > < / s t r o n g >
< small class = "text-muted" ng - bind = "$ctrl.date" > just now < / s m a l l >
< button type = "button" class = "ml-2 mb-1 close" data - dismiss = "toast" aria - label = "Close" >
< span aria - hidden = "true" > & times ; < / s p a n >
< / b u t t o n >
< / d i v >
2022-05-31 14:41:36 +00:00
< div class = "toast-body text-break" ng - bind - html = "$ctrl.msg" ng - if = "$ctrl.msg" > < / d i v >
2020-03-08 11:48:25 +00:00
< div class = "d-flex justify-content-around mb-1" ng - if = "$ctrl.yesNo" >
< button type = "button" class = "ml-2 btn btn-sm btn-success" ng - click = "$ctrl.yesFunc()" > Yes < / b u t t o n >
< button type = "button" class = "btn btn-sm btn-danger" ng - click = "$ctrl.noFunc()" > No < / b u t t o n >
< / d i v >
< / d i v > `
} ) ;
2018-01-07 23:41:23 +00:00
2016-01-13 00:22:54 +00:00
angular . module ( "FICApp" )
2016-10-13 17:52:54 +00:00
. factory ( "Version" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/version" )
2016-10-13 17:52:54 +00:00
} )
2019-10-31 15:05:58 +00:00
. factory ( "Timestamp" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/timestamps.json" )
2019-10-31 15:05:58 +00:00
} )
2020-01-29 10:35:01 +00:00
. factory ( "Health" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/health.json" )
2020-01-29 10:35:01 +00:00
} )
2019-01-23 00:47:56 +00:00
. factory ( "Monitor" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/monitor/:machineId" , { machineId : '@id' } )
2019-01-23 00:47:56 +00:00
} )
2016-12-26 02:44:04 +00:00
. factory ( "Event" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/events/:eventId" , { eventId : '@id' } , {
2016-12-26 02:44:04 +00:00
'update' : { method : 'PUT' } ,
} )
} )
2018-01-17 00:21:32 +00:00
. factory ( "Claim" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/claims/:claimId" , { claimId : '@id' } , {
2018-01-17 00:21:32 +00:00
'update' : { method : 'PUT' } ,
} )
} )
. factory ( "ClaimAssignee" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/claims-assignees/:assigneeId" , { assigneeId : '@id' } , {
2018-01-17 00:21:32 +00:00
'update' : { method : 'PUT' } ,
} )
} )
2018-01-21 13:18:26 +00:00
. factory ( "Certificate" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/certs/:serial" , { serial : '@id' } , {
2018-01-21 13:18:26 +00:00
'update' : { method : 'PUT' } ,
} )
} )
. factory ( "CACertificate" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/ca/:serial" , { serial : '@id' } )
2018-01-21 13:18:26 +00:00
} )
2017-12-27 00:53:01 +00:00
. factory ( "File" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/files/:fileId" , { fileId : '@id' } )
2017-12-27 00:53:01 +00:00
} )
2017-12-11 01:56:26 +00:00
. factory ( "ROSettings" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/settings-ro.json" )
2017-12-11 01:56:26 +00:00
} )
2017-01-15 01:37:59 +00:00
. factory ( "Settings" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/settings.json" , null , {
2017-01-15 01:37:59 +00:00
'update' : { method : 'PUT' } ,
} )
} )
2022-05-26 20:54:46 +00:00
. factory ( "NextSettings" , function ( $resource ) {
return $resource ( "api/settings-next/:tsId" , { tsId : '@id' } , {
'update' : { method : 'PUT' } ,
} )
} )
2022-05-02 08:59:43 +00:00
. factory ( "SettingsChallenge" , function ( $resource ) {
return $resource ( "api/challenge.json" , null , {
'update' : { method : 'PUT' } ,
} )
} )
2017-01-20 18:18:43 +00:00
. factory ( "Scene" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/public/:screenId" , { screenId : '@id' } , {
2019-01-19 07:01:29 +00:00
'update' : { method : 'PUT' } ,
2017-01-20 18:18:43 +00:00
} )
} )
2016-01-13 00:22:54 +00:00
. factory ( "Team" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/teams/:teamId" , { teamId : '@id' } , {
2016-12-15 23:51:56 +00:00
'update' : { method : 'PUT' } ,
2016-01-22 16:37:29 +00:00
} )
2016-10-13 17:52:54 +00:00
} )
2018-01-21 13:18:26 +00:00
. factory ( "TeamCertificate" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/teams/:teamId/certificates" , { teamId : '@id' } )
2018-01-21 13:18:26 +00:00
} )
2019-02-04 18:59:29 +00:00
. factory ( "TeamAssociation" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/teams/:teamId/associations/:assoc" , { teamId : '@teamId' , assoc : '@assoc' } )
2019-02-04 18:59:29 +00:00
} )
2016-10-13 17:52:54 +00:00
. factory ( "TeamMember" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/teams/:teamId/members" , { teamId : '@id' } , {
2017-01-28 18:36:28 +00:00
'save' : { method : 'PUT' } ,
} )
2016-10-13 17:52:54 +00:00
} )
. factory ( "TeamMy" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/teams/:teamId/my.json" , { teamId : '@id' } )
2016-10-13 17:52:54 +00:00
} )
. factory ( "Teams" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/teams.json" )
2016-10-13 17:52:54 +00:00
} )
2017-11-12 23:57:48 +00:00
. factory ( "TeamHistory" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/teams/:teamId/history.json" , { teamId : '@id' } )
2017-11-12 23:57:48 +00:00
} )
2019-01-17 12:51:44 +00:00
. factory ( "TeamScore" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/teams/:teamId/score-grid.json" , { teamId : '@id' } )
2019-01-17 12:51:44 +00:00
} )
2016-10-13 17:52:54 +00:00
. factory ( "TeamStats" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/teams/:teamId/stats.json" , { teamId : '@id' } )
2016-10-13 17:52:54 +00:00
} )
. factory ( "TeamPresence" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/teams/:teamId/tries" , { teamId : '@id' } )
2016-10-13 17:52:54 +00:00
} )
2016-01-22 16:37:29 +00:00
. factory ( "Theme" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/themes/:themeId" , { themeId : '@id' } , {
2016-12-15 23:51:56 +00:00
update : { method : 'PUT' }
} ) ;
2016-10-13 17:52:54 +00:00
} )
. factory ( "Themes" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/themes.json" , null , {
2016-10-13 17:52:54 +00:00
'get' : { method : 'GET' } ,
2016-01-13 00:22:54 +00:00
} )
2016-10-13 17:52:54 +00:00
} )
2016-12-26 00:23:31 +00:00
. factory ( "ThemedExercice" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/themes/:themeId/exercices/:exerciceId" , { themeId : '@id' , exerciceId : '@idExercice' } , {
2016-12-26 00:23:31 +00:00
update : { method : 'PUT' }
} )
} )
2016-10-13 17:52:54 +00:00
. factory ( "Exercice" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId" , { exerciceId : '@id' } , {
2018-11-21 00:19:13 +00:00
update : { method : 'PUT' } ,
patch : { method : 'PATCH' }
2016-12-15 23:51:56 +00:00
} )
2016-12-26 00:23:31 +00:00
} )
2020-01-20 09:41:21 +00:00
. factory ( "ExerciceClaims" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/claims" , { exerciceId : '@idExercice' } )
2020-01-20 09:41:21 +00:00
} )
2018-11-18 21:44:23 +00:00
. factory ( "ExerciceTags" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/tags" , { exerciceId : '@idExercice' } , {
2018-11-18 21:44:23 +00:00
update : { method : 'PUT' }
} )
} )
2019-02-03 21:30:29 +00:00
. factory ( "ExerciceHistory" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/history.json" , { exerciceId : '@id' } )
2019-02-03 21:30:29 +00:00
} )
2020-01-29 14:57:34 +00:00
. factory ( "ExercicesStats" , function ( $resource ) {
2022-05-16 09:38:46 +00:00
return $resource ( "api/exercices_stats.json" , { themeId : '@id' } )
2020-01-29 14:57:34 +00:00
} )
2020-01-28 13:01:13 +00:00
. factory ( "ExerciceStats" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/stats.json" , { exerciceId : '@id' } )
2020-01-28 13:01:13 +00:00
} )
2016-12-26 00:23:31 +00:00
. factory ( "ExerciceFile" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/files/:fileId" , { exerciceId : '@idExercice' , fileId : '@id' } , {
2016-12-27 20:08:36 +00:00
update : { method : 'PUT' }
2016-12-26 00:23:31 +00:00
} )
} )
. factory ( "ExerciceHint" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/hints/:hintId" , { exerciceId : '@idExercice' , hintId : '@id' } , {
2016-12-27 20:08:36 +00:00
update : { method : 'PUT' }
2016-12-26 00:23:31 +00:00
} )
} )
2020-01-23 13:23:02 +00:00
. factory ( "ExerciceHintDeps" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/hints/:hintId/dependancies" , { exerciceId : '@idExercice' , hintId : '@id' } )
2020-01-23 13:23:02 +00:00
} )
2018-09-24 08:00:17 +00:00
. factory ( "ExerciceFlag" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/flags/:flagId" , { exerciceId : '@idExercice' , flagId : '@id' } , {
2016-12-27 20:08:36 +00:00
update : { method : 'PUT' }
2016-12-26 00:23:31 +00:00
} )
2018-06-24 16:12:26 +00:00
} )
2020-01-23 13:23:02 +00:00
. factory ( "ExerciceFlagChoices" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/flags/:flagId/choices/:choiceId" , { exerciceId : '@idExercice' , flagId : '@idFlag' , choiceId : '@id' } , {
2020-01-28 13:05:00 +00:00
'update' : { method : 'PUT' } ,
} )
2020-01-23 13:23:02 +00:00
} )
. factory ( "ExerciceFlagDeps" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/flags/:flagId/dependancies" , { exerciceId : '@idExercice' , flagId : '@id' } )
2020-01-23 13:23:02 +00:00
} )
2018-09-24 08:00:17 +00:00
. factory ( "ExerciceMCQFlag" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/quiz/:mcqId" , { exerciceId : '@idExercice' , mcqId : '@id' } , {
2018-06-24 16:12:26 +00:00
update : { method : 'PUT' }
} )
2020-01-23 13:23:02 +00:00
} )
. factory ( "ExerciceMCQDeps" , function ( $resource ) {
2021-07-21 21:17:47 +00:00
return $resource ( "api/exercices/:exerciceId/quiz/:mcqId/dependancies" , { exerciceId : '@idExercice' , mcqId : '@id' } )
2016-01-13 00:22:54 +00:00
} ) ;
angular . module ( "FICApp" )
2017-12-26 22:57:16 +00:00
. filter ( "countHints" , function ( ) {
return function ( input ) {
if ( input == undefined )
return 0 ;
return input . reduce ( function ( sum , n ) { return sum + ( n . content || n . file ) ? 1 : 0 ; } , 0 ) ;
}
} )
2017-01-28 18:36:28 +00:00
. filter ( "toColor" , function ( ) {
2020-01-20 09:41:21 +00:00
return function ( num ) {
2017-01-28 18:36:28 +00:00
num >>>= 0 ;
2024-03-25 10:42:32 +00:00
var b = ( num & 0xFF ) . toString ( 16 ) ,
g = ( ( num & 0xFF00 ) >>> 8 ) . toString ( 16 ) ,
r = ( ( num & 0xFF0000 ) >>> 16 ) . toString ( 16 ) ,
2017-01-28 18:36:28 +00:00
a = ( ( num & 0xFF000000 ) >>> 24 ) / 255 ;
2024-03-25 10:42:32 +00:00
if ( r . length <= 1 ) r = "0" + r ;
if ( g . length <= 1 ) g = "0" + g ;
if ( b . length <= 1 ) b = "0" + b ;
return "#" + r + g + b ;
2017-01-28 18:36:28 +00:00
}
} )
2016-12-26 00:23:31 +00:00
. filter ( "cksum" , function ( ) {
return function ( input ) {
if ( input == undefined )
return input ;
var raw = atob ( input ) . toString ( 16 ) ;
var hex = '' ;
for ( var i = 0 ; i < raw . length ; i ++ ) {
var _hex = raw . charCodeAt ( i ) . toString ( 16 )
hex += ( _hex . length == 2 ? _hex : '0' + _hex ) ;
}
return hex
}
} )
2016-10-13 17:52:54 +00:00
2020-01-23 13:23:02 +00:00
. component ( 'dependancy' , {
bindings : {
dep : '=' ,
deleteDep : '=' ,
} ,
controller : function ( ) { } ,
template : `
< li >
< span ng - if = "$ctrl.dep.label" > Flag { { $ctrl . dep . label } } < / s p a n >
< span ng - if = "$ctrl.dep.title" > QCM { { $ctrl . dep . title } } < / s p a n >
< button type = "button" class = "btn btn-sm btn-danger" ng - if = "$ctrl.deleteDep" ng - click = "$ctrl.deleteDep()" > < span class = "glyphicon glyphicon-trash" > < / s p a n > < / b u t t o n >
< / l i >
`
} )
2017-01-28 18:36:28 +00:00
. directive ( 'color' , function ( ) {
return {
require : 'ngModel' ,
link : function ( scope , ele , attr , ctrl ) {
ctrl . $formatters . unshift ( function ( num ) {
num >>>= 0 ;
2024-03-25 10:42:32 +00:00
var b = ( num & 0xFF ) . toString ( 16 ) ,
g = ( ( num & 0xFF00 ) >>> 8 ) . toString ( 16 ) ,
r = ( ( num & 0xFF0000 ) >>> 16 ) . toString ( 16 ) ,
a = ( ( num & 0xFF000000 ) >>> 24 ) / 255 ;
if ( r . length <= 1 ) r = "0" + r ;
if ( g . length <= 1 ) g = "0" + g ;
if ( b . length <= 1 ) b = "0" + b ;
return "#" + r + g + b ;
2017-01-28 18:36:28 +00:00
} ) ;
ctrl . $parsers . unshift ( function ( viewValue ) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i . exec ( viewValue ) ;
return result ? (
parseInt ( result [ 1 ] , 16 ) * 256 * 256 +
parseInt ( result [ 2 ] , 16 ) * 256 +
parseInt ( result [ 3 ] , 16 )
) : 0 ;
} ) ;
}
} ;
} )
2016-12-27 20:08:36 +00:00
. directive ( 'integer' , function ( ) {
return {
require : 'ngModel' ,
link : function ( scope , ele , attr , ctrl ) {
ctrl . $parsers . unshift ( function ( viewValue ) {
return parseInt ( viewValue , 10 ) ;
} ) ;
}
} ;
} )
2017-01-15 01:37:59 +00:00
. directive ( 'float' , function ( ) {
return {
require : 'ngModel' ,
link : function ( scope , ele , attr , ctrl ) {
ctrl . $parsers . unshift ( function ( viewValue ) {
return parseFloat ( viewValue , 10 ) ;
} ) ;
}
} ;
} )
2023-06-17 00:07:27 +00:00
. run ( function ( $rootScope , $http , $interval , $timeout , Settings , $location ) {
2022-05-26 21:51:34 +00:00
$rootScope . $location = $location ;
2022-06-01 11:25:58 +00:00
$rootScope . Utils = {
keys : Object . keys
} ;
2022-07-11 09:11:35 +00:00
$rootScope . refreshSettings = function ( ) {
2021-07-21 21:17:47 +00:00
$http . get ( "api/settings.json" ) . then ( function ( response ) {
2018-12-05 03:09:42 +00:00
response . data . start = new Date ( response . data . start ) ;
response . data . end = new Date ( response . data . end ) ;
response . data . generation = new Date ( response . data . generation ) ;
2024-03-16 11:19:16 +00:00
if ( $rootScope . settings && $rootScope . settings . activateTime instanceof Date )
response . data . activateTime = $rootScope . settings . activateTime ;
$rootScope . settings = response . data ;
2018-12-05 03:09:42 +00:00
$rootScope . recvTime ( response ) ;
} )
}
2022-07-11 09:11:35 +00:00
$rootScope . refreshSettings ( ) ;
$interval ( $rootScope . refreshSettings , 10000 ) ;
2018-12-05 05:54:50 +00:00
2020-03-08 11:48:25 +00:00
$rootScope . toasts = [ ] ;
$rootScope . addToast = function ( kind , title , msg , yesFunc , noFunc , tmout ) {
$rootScope . toasts . unshift ( {
variant : kind ,
title : title ,
msg : msg ,
timeout : tmout ,
yesFunc : yesFunc ,
noFunc : noFunc ,
} ) ;
}
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate = 0 ;
2023-07-10 10:10:03 +00:00
$rootScope . staticRegenerationInProgress = false ;
2018-12-05 05:54:50 +00:00
$rootScope . regenerateStaticFiles = function ( ) {
2023-07-10 10:10:03 +00:00
$rootScope . staticRegenerationInProgress = true ;
$http . post ( "api/full-generation" ) . then ( function ( response ) {
$rootScope . staticFilesNeedUpdate = 0 ;
$rootScope . staticRegenerationInProgress = false ;
$rootScope . addToast ( 'success' , 'Regeneration ended' ) ;
} , function ( response ) {
$rootScope . staticRegenerationInProgress = false ;
$rootScope . addToast ( 'error' , 'An error occurs when saving settings:' , response . data . errmsg ) ;
2018-12-05 05:54:50 +00:00
} )
}
2023-06-17 00:07:27 +00:00
$rootScope . $on ( '$locationChangeStart' , function ( event , next , current ) {
if ( $rootScope . staticFilesNeedUpdate ) {
$timeout ( function ( ) {
document . getElementById ( "circle1" ) . classList . add ( "play" ) ;
} , 10 ) ;
$timeout ( function ( ) {
document . getElementById ( "circle1" ) . classList . remove ( "play" ) ;
} , 710 ) ;
$timeout ( function ( ) {
document . getElementById ( "circle2" ) . classList . add ( "play" ) ;
} , 50 ) ;
$timeout ( function ( ) {
document . getElementById ( "circle2" ) . classList . remove ( "play" ) ;
} , 750 ) ;
}
} ) ;
2024-03-17 10:20:38 +00:00
$rootScope . logged = parseInt ( getCookie ( "myassignee" ) ) > 0 ;
2018-12-05 03:09:42 +00:00
} )
2016-10-13 17:52:54 +00:00
. controller ( "VersionController" , function ( $scope , Version ) {
$scope . v = Version . get ( ) ;
} )
2024-02-09 12:46:36 +00:00
. controller ( "TimestampController" , function ( $scope , $interval , Timestamp ) {
2019-10-31 15:05:58 +00:00
$scope . t = Timestamp . get ( ) ;
var refresh = function ( ) {
$scope . t = Timestamp . get ( ) ;
}
var myinterval = $interval ( refresh , 2500 ) ;
$scope . $on ( '$destroy' , function ( ) { $interval . cancel ( myinterval ) ; } ) ;
} )
2024-02-09 16:56:05 +00:00
. controller ( "HealthController" , function ( $scope , $interval , Health , $http ) {
2020-01-29 10:35:01 +00:00
var refresh = function ( ) {
$scope . health = Health . query ( ) ;
}
refresh ( ) ;
var myinterval = $interval ( refresh , 2500 ) ;
2024-02-09 16:56:05 +00:00
$scope . drop _submission = function ( path ) {
$scope . addToast ( 'info' , 'Delete submission' , 'Ensure this submission is not interesting. Continue?' ,
function ( ) {
$http . delete ( "api/submissions" + path ) . then ( function ( response ) {
refresh ( ) ;
} , function ( response ) {
$scope . addToast ( 'danger' , 'An error occurs when deleting submission:' , response . data . errmsg ) ;
} ) ;
}
) ;
}
2020-01-29 10:35:01 +00:00
$scope . $on ( '$destroy' , function ( ) { $interval . cancel ( myinterval ) ; } ) ;
} )
2019-01-23 00:47:56 +00:00
. controller ( "MonitorController" , function ( $scope , Monitor ) {
$scope . monitor = Monitor . get ( ) ;
} )
2023-07-25 07:04:31 +00:00
. controller ( "AllTeamAssociationsController" , function ( $scope , $http ) {
$scope . allAssociations = [ ] ;
$http . get ( "api/teams-associations.json" ) . then ( function ( response ) {
$scope . allAssociations = response . data ;
} )
} )
2022-05-26 20:54:46 +00:00
. controller ( "SettingsController" , function ( $scope , $rootScope , NextSettings , Settings , SettingsChallenge , $location , $http , $interval ) {
$scope . nextsettings = NextSettings . query ( ) ;
$scope . erase = false ;
$scope . editNextSettings = function ( ns ) {
2024-03-16 11:19:16 +00:00
$scope . activateTime = new Date ( ns . date ) ;
$rootScope . settings . activateTime = $scope . activateTime ;
2022-05-26 20:54:46 +00:00
$scope . erase = true ;
Object . keys ( ns . values ) . forEach ( function ( k ) {
$scope . config [ k ] = ns . values [ k ] ;
} ) ;
$scope . config . enableExerciceDepend = $scope . config . unlockedChallengeDepth >= 0 ;
2022-06-08 02:39:20 +00:00
$scope . config . disabledsubmitbutton = $scope . config . disablesubmitbutton && $scope . config . disablesubmitbutton . length > 0 ;
2022-05-26 20:54:46 +00:00
}
$scope . deleteNextSettings = function ( ns ) {
ns . $delete ( ) . then ( function ( ) {
$scope . nextsettings = NextSettings . query ( ) ;
} )
}
2019-09-05 08:28:45 +00:00
$scope . displayDangerousActions = false ;
2022-05-26 10:53:47 +00:00
$scope . config = Settings . get ( ) ;
$scope . dist _config = { } ;
2018-08-17 20:17:51 +00:00
$scope . config . $promise . then ( function ( response ) {
2024-03-14 14:14:26 +00:00
response . start = new Date ( response . start ) ;
if ( response . end ) response . end = new Date ( response . end ) ;
else response . end = null ;
response . generation = new Date ( response . generation ) ;
response . activateTime = new Date ( response . activateTime ) ;
2022-05-26 10:53:47 +00:00
$scope . dist _config = Object . assign ( { } , response ) ;
2024-03-14 14:14:26 +00:00
2019-01-18 19:30:47 +00:00
response . enableExerciceDepend = response . unlockedChallengeDepth >= 0 ;
2022-06-08 02:39:20 +00:00
response . disabledsubmitbutton = response . disablesubmitbutton && response . disablesubmitbutton . length > 0 ;
2018-08-17 20:17:51 +00:00
} )
2022-05-02 08:59:43 +00:00
$scope . challenge = SettingsChallenge . get ( ) ;
2022-05-24 21:00:49 +00:00
$scope . duration = 360 ;
2024-03-16 11:19:16 +00:00
$scope . activateTime = "" ;
2022-05-24 21:00:49 +00:00
$scope . challenge . $promise . then ( function ( c ) {
if ( c . duration )
$scope . duration = c . duration ;
} ) ;
2017-01-15 01:37:59 +00:00
2022-01-21 08:17:46 +00:00
$scope . exerciceDependChange = function ( ) {
if ( $scope . config . enableExerciceDepend )
$scope . config . unlockedChallengeDepth = 0 ;
else
$scope . config . unlockedChallengeDepth = - 1 ;
} ;
2022-06-08 02:39:20 +00:00
$scope . submitButtonStateChange = function ( ) {
if ( $scope . config . disabledsubmitbutton )
$scope . config . disablesubmitbutton = "Mise à jour en cours..." ;
else
$scope . config . disablesubmitbutton = "" ;
} ;
2023-07-25 07:04:31 +00:00
$scope . newdqa = "" ;
$scope . addDelegatedQA = function ( ) {
if ( $scope . newdqa . length ) {
if ( ! $scope . config . delegated _qa )
$scope . config . delegated _qa = [ ] ;
$scope . config . delegated _qa . push ( $scope . newdqa ) ;
$scope . saveSettings ( ) ;
$scope . newdqa = "" ;
}
}
$scope . dropDelegatedQA = function ( member ) {
if ( $scope . config . delegated _qa ) {
$scope . config . delegated _qa = [ ] ;
angular . forEach ( $scope . config . delegated _qa , function ( m , k ) {
if ( member == m )
$scope . config . delegated _qa . splice ( k , 1 ) ;
} ) ;
$scope . saveSettings ( ) ;
}
}
$scope . saveChallengeInfo = function ( ) {
2022-05-24 21:00:49 +00:00
this . challenge . duration = $scope . duration ;
2022-05-02 08:59:43 +00:00
this . challenge . $update ( function ( response ) {
$scope . addToast ( 'success' , 'Infos du challenge mises à jour avec succès !' ) ;
} , function ( response ) {
$scope . addToast ( 'danger' , 'An error occurs when saving challenge info:' , response . data . errmsg ) ;
} ) ;
}
2017-11-10 19:38:31 +00:00
$scope . saveSettings = function ( msg ) {
if ( msg === undefined ) { msg = 'New settings saved!' ; }
2023-05-12 12:53:15 +00:00
if ( this . config . end == "" ) this . config . end = null ;
var nStart = this . config . start ;
var nEnd = this . config . end ;
2018-08-17 20:17:51 +00:00
var nGen = this . config . generation ;
2019-01-18 19:30:47 +00:00
var state = this . config . enableExerciceDepend ;
this . config . unlockedChallengeDepth = ( this . config . enableExerciceDepend ? this . config . unlockedChallengeDepth : - 1 )
2022-06-08 02:39:20 +00:00
this . config . disablesubmitbutton = ( this . config . disabledsubmitbutton ? this . config . disablesubmitbutton : '' )
2022-05-26 20:54:46 +00:00
var updateQuery = { } ;
2024-03-16 11:19:16 +00:00
if ( this . activateTime && this . activateTime != '' ) {
2022-05-26 20:54:46 +00:00
updateQuery [ 't' ] = this . activateTime ;
2024-03-16 11:19:16 +00:00
this . activateTime = null ;
2022-05-26 20:54:46 +00:00
}
if ( this . erase ) {
updateQuery [ 'erase' ] = true ;
this . erase = false ;
}
this . config . $update ( updateQuery , function ( response ) {
2022-05-26 10:53:47 +00:00
$scope . dist _config = Object . assign ( { } , response ) ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , msg ) ;
2022-05-26 20:54:46 +00:00
$scope . nextsettings = NextSettings . query ( ) ;
2019-01-18 19:30:47 +00:00
response . enableExerciceDepend = response . unlockedChallengeDepth >= 0 ;
2022-06-08 02:39:20 +00:00
response . disabledsubmitbutton = response . disablesubmitbutton && response . disablesubmitbutton . length > 0 ;
2018-08-17 20:17:51 +00:00
$rootScope . settings . start = new Date ( nStart ) ;
2023-05-12 12:53:15 +00:00
if ( nEnd ) {
$rootScope . settings . end = new Date ( nEnd ) ;
} else {
$rootScope . settings . end = null ;
}
2018-08-17 20:17:51 +00:00
$rootScope . settings . generation = new Date ( nGen ) ;
2024-03-16 11:19:16 +00:00
$scope . updateActivateTime ( ) ;
2017-11-10 19:38:31 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when saving settings:' , response . data . errmsg ) ;
2017-01-15 01:37:59 +00:00
} ) ;
}
$scope . launchChallenge = function ( ) {
2024-02-09 12:46:36 +00:00
var ts = $rootScope . getSrvTime ( ) . getTime ( ) - $rootScope . getSrvTime ( ) . getTime ( ) % 60000 ;
2024-03-14 14:14:26 +00:00
this . config . start = new Date ( ts + 120000 ) ;
this . config . end = new Date ( ts + 120000 + this . duration * 60000 ) ;
2017-11-12 13:42:54 +00:00
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'info' , 'Challenge ready to start,' , 'propagate the changes?' ,
2017-11-12 13:42:54 +00:00
function ( ) {
$scope . saveSettings ( ) ;
} ) ;
2017-01-15 01:37:59 +00:00
}
2022-02-03 15:56:34 +00:00
$scope . updateActivateTime = function ( ) {
2022-05-26 20:54:46 +00:00
$rootScope . settings . activateTime = this . activateTime ;
2022-02-03 15:56:34 +00:00
}
2021-09-08 00:39:51 +00:00
$scope . updActivateTime = function ( modulo ) {
2024-03-16 11:19:16 +00:00
if ( modulo ) {
2024-02-09 12:46:36 +00:00
var ts = Math . floor ( ( new Date ( this . config . end ) - $rootScope . getSrvTime ( ) . getTime ( ) - ( 60000 * modulo / 2 ) ) / ( 60000 * modulo ) ) * ( 60000 * modulo ) ;
2021-09-08 00:39:51 +00:00
var d = new Date ( this . config . end ) - ts ;
2024-03-14 14:14:26 +00:00
this . activateTime = new Date ( d ) ;
2022-02-03 15:56:34 +00:00
this . updateActivateTime ( ) ;
2024-03-16 11:19:16 +00:00
} else {
this . activateTime = null ;
this . updateActivateTime ( ) ;
}
2019-01-17 12:03:15 +00:00
}
2019-09-05 08:28:45 +00:00
$scope . reset = function ( type ) {
var txts = {
2020-11-13 10:25:29 +00:00
"settings" : "En validant, vous remettrez les paramètres de cette page à leur valeur initiale, y compris la date de début du challenge." ,
2022-05-02 09:39:27 +00:00
"challengeInfo" : "En validant, vous effacerez les informations descriptives du challenge." ,
2019-09-05 08:28:45 +00:00
"challenges" : "En validant, vous retirerez toutes les données statiques des challenges." ,
"teams" : "En validant, vous supprimerez l'ensemble des équipes enregistreées." ,
"game" : "En validant, vous supprimerez toutes les tentatives, les validations, ... faites par les équipes." ,
2017-01-29 12:38:39 +00:00
}
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'warning' , txts [ type ] , 'Êtes-vous sûr de vouloir continuer ?' ,
2019-09-05 08:28:45 +00:00
function ( ) {
if ( confirm ( "Êtes-vous vraiment sûr ?\n" + txts [ type ] ) ) {
2021-07-21 21:17:47 +00:00
$http . post ( "api/reset" , { "type" : type } ) . then ( function ( time ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , type + 'reseted' ) ;
2019-09-05 08:28:45 +00:00
$location . url ( "/" ) ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when reseting ' + type + ':' , response . data . errmsg ) ;
2019-09-05 08:28:45 +00:00
} ) ;
}
} ) ;
} ;
2022-07-11 09:11:35 +00:00
$scope . switchToProd = function ( ) {
$scope . addToast ( 'warning' , "Activer le mode challenge ?" , "L'activation du mode challenge est temporaire (vous devriez plutôt relancer le daemon avec l'option `-4real`). Ce mode permet d'éviter les mauvaises manipulations et désactive le hook git de synchronisation automatique. Êtes-vous sûr de vouloir continuer ?" ,
function ( ) {
$http . put ( "api/prod" , true ) . then ( function ( time ) {
$rootScope . refreshSettings ( )
$scope . addToast ( 'success' , 'Mode challenge activé' ) ;
} , function ( response ) {
$scope . addToast ( 'danger' , 'An error occurs when activating challenge mode:' , response . data . errmsg ) ;
} ) ;
} ) ;
} ;
2022-05-19 19:15:25 +00:00
} )
2023-10-23 10:03:40 +00:00
. controller ( "RepositoriesController" , function ( $scope , $http ) {
$http . get ( "api/repositories" ) . then ( function ( response ) {
$scope . repositories = response . data . repositories ;
} ) ;
} )
2023-10-23 17:22:19 +00:00
. component ( 'repositoryUptodate' , {
bindings : {
repository : '<' ,
} ,
controller : function ( $http ) {
var ctrl = this ;
ctrl . status = { } ;
ctrl . color = "badge-secondary" ;
ctrl . $onInit = function ( ) {
$http . post ( "api/repositories/" + ctrl . repository . path ) . then ( function ( response ) {
ctrl . status = response . data ;
if ( ctrl . repository . hash . startsWith ( ctrl . status . hash ) ) {
ctrl . color = "badge-success" ;
} else {
ctrl . color = "badge-danger" ;
}
} ) ;
} ;
} ,
template : ` <span class="badge {{ $ ctrl.color }}">{{ $ ctrl.status.hash }}</span> <small>{{ $ ctrl.status.text }}</small> `
} )
2023-10-23 10:03:40 +00:00
2022-05-19 19:15:25 +00:00
. controller ( "SyncController" , function ( $scope , $rootScope , ROSettings , $location , $http , $interval ) {
$scope . displayDangerousActions = false ;
$scope . configro = ROSettings . get ( ) ;
var needRefreshSyncReportWhenReady = false ;
var refreshSyncReport = function ( ) {
needRefreshSyncReportWhenReady = false ;
$http . get ( "full_import_report.json" ) . then ( function ( response ) {
$scope . syncReport = response . data ;
} )
} ;
refreshSyncReport ( )
var progressInterval = $interval ( function ( ) {
$http . get ( "api/sync/deep" ) . then ( function ( response ) {
if ( response . data . progress && response . data . progress != 255 )
needRefreshSyncReportWhenReady = true ;
else if ( needRefreshSyncReportWhenReady )
refreshSyncReport ( ) ;
2022-05-20 08:00:46 +00:00
if ( response . data && response . data . progress ) {
$scope . syncPercent = Math . floor ( response . data . progress * 100 / 255 ) ;
2022-05-19 19:15:25 +00:00
$scope . syncProgress = Math . floor ( response . data . progress * 100 / 255 ) + " %" ;
2022-05-20 08:00:46 +00:00
} else {
2022-05-19 19:15:25 +00:00
$scope . syncProgress = response . data ;
2022-05-20 08:00:46 +00:00
$scope . syncPercent = 0 ;
}
2022-05-19 19:15:25 +00:00
} , function ( response ) {
2022-05-20 08:00:46 +00:00
$scope . syncPercent = 0 ;
2022-05-19 19:15:25 +00:00
if ( response . data && response . data . errmsg )
$scope . syncProgress = response . data . errmsg ;
else
$scope . syncProgress = response . data ;
} )
} , 1500 ) ;
$scope . $on ( '$destroy' , function ( ) { $interval . cancel ( progressInterval ) ; } ) ;
2018-12-05 05:21:32 +00:00
$scope . deepSyncInProgress = false ;
2020-01-20 07:41:36 +00:00
$scope . deepSync = function ( theme ) {
if ( theme ) {
question = 'Faire une synchronisation intégrale du thème ' + theme . name + ' ?'
2021-07-21 21:17:47 +00:00
url = "api/sync/deep/" + theme . id
2020-01-20 07:41:36 +00:00
} else {
question = 'Faire une synchronisation intégrale ?'
2021-07-21 21:17:47 +00:00
url = "api/sync/deep"
2020-01-20 07:41:36 +00:00
}
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'warning' , question , '' ,
2018-12-05 05:21:32 +00:00
function ( ) {
$scope . deepSyncInProgress = true ;
2020-01-20 07:41:36 +00:00
$http . post ( url ) . then ( function ( ) {
2018-12-05 05:21:32 +00:00
$scope . deepSyncInProgress = false ;
2022-05-16 09:38:13 +00:00
$scope . addToast ( 'success' , 'Synchronisation intégrale terminée.' , '<a href="check_import.html" target="_self">Voir le rapport</a>.' , null , null , 15000 ) ;
2018-12-05 05:21:32 +00:00
} , function ( response ) {
$scope . deepSyncInProgress = false ;
2022-05-16 09:38:13 +00:00
$scope . addToast ( 'warning' , 'Synchronisation intégrale terminée.' , '<a href="check_import.html" target="_self">Voir le rapport</a>.' , null , null , 15000 ) ;
2018-12-05 05:21:32 +00:00
} ) ;
} ) ;
} ;
2020-01-20 07:41:36 +00:00
$scope . speedyDeepSync = function ( ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'warning' , 'Faire une synchronisation profonde rapide, sans s\'occuper des fichiers ?' , '' ,
2020-01-20 07:41:36 +00:00
function ( ) {
$scope . deepSyncInProgress = true ;
2021-07-21 21:17:47 +00:00
$http . post ( "api/sync/speed" ) . then ( function ( ) {
2020-01-20 07:41:36 +00:00
$scope . deepSyncInProgress = false ;
2022-05-16 09:38:13 +00:00
$scope . addToast ( 'success' , 'Synchronisation profonde rapide terminée.' , '<a href="check_import.html" target="_self">Voir le rapport</a>.' , null , null , 15000 ) ;
2020-01-20 07:41:36 +00:00
} , function ( response ) {
$scope . deepSyncInProgress = false ;
2022-05-16 09:38:13 +00:00
$scope . addToast ( 'warning' , 'Synchronisation profinde rapide terminée.' , '<a href="check_import.html" target="_self">Voir le rapport</a>.' , null , null , 15000 ) ;
2021-11-13 10:06:24 +00:00
} ) ;
} ) ;
} ;
$scope . baseSync = function ( ) {
$scope . addToast ( 'warning' , 'Tirer les mises à jour du dépôt ?' , '' ,
function ( ) {
$scope . deepSyncInProgress = true ;
$http . post ( "api/sync/base" ) . then ( function ( ) {
$scope . deepSyncInProgress = false ;
$scope . addToast ( 'success' , 'Mise à jour terminée.' ) ;
} , function ( response ) {
$scope . deepSyncInProgress = false ;
$scope . addToast ( 'danger' , 'Mise à jour terminée.' , response . data . errmsg ) ;
2020-01-20 07:41:36 +00:00
} ) ;
} ) ;
} ;
2022-06-12 10:15:39 +00:00
$scope . syncVideos = function ( ) {
$scope . addToast ( 'warning' , 'Synchroniser les vidéos de résolution ?' , 'ATTENTION il ne faut pas lancer cette synchronisation durant le challenge. Seulement une fois le challenge terminé, cela permet de rendre les vidéos accessibles dans l\'interface joueurs.' ,
function ( ) {
$scope . deepSyncInProgress = true ;
$http . post ( "api/sync/videos" ) . then ( function ( ) {
$scope . deepSyncInProgress = false ;
$scope . addToast ( 'success' , 'Import des vidéos terminé.' ) ;
} , function ( response ) {
$scope . deepSyncInProgress = false ;
$scope . addToast ( 'danger' , 'Import des vidéos terminé.' , response . data . errmsg ) ;
} ) ;
} ) ;
} ;
2024-03-14 17:43:07 +00:00
$scope . dropSoluces = function ( ) {
$scope . addToast ( 'warning' , 'Effacer les solutions' , 'Ceci va retirer les textes de résolution de la base de données ainsi que les liens vers les vidéos.' ,
function ( ) {
$scope . deepSyncInProgress = true ;
$http . post ( "api/sync/drop_soluces" ) . then ( function ( ) {
$scope . deepSyncInProgress = false ;
$scope . addToast ( 'success' , 'Effacement des solutions terminé.' ) ;
} , function ( response ) {
$scope . deepSyncInProgress = false ;
$scope . addToast ( 'danger' , 'Effacement des solutions terminé avec des erreurs.' , response . data . errmsg ) ;
} ) ;
} ) ;
} ;
2017-01-15 01:37:59 +00:00
} )
2018-01-21 13:18:26 +00:00
. controller ( "PKIController" , function ( $scope , $rootScope , Certificate , CACertificate , Team , $location , $http ) {
2020-01-21 17:51:43 +00:00
var ts = Date . now ( ) - Date . now ( ) % 86400000 ;
2019-11-25 13:49:19 +00:00
var d = new Date ( ts ) ;
var f = new Date ( ts + 3 * 86400000 ) ;
2020-01-21 17:51:43 +00:00
$scope . newca = {
notAfter : f . toISOString ( ) ,
notBefore : d . toISOString ( ) ,
} ;
2019-11-25 13:49:19 +00:00
2018-01-21 13:18:26 +00:00
$scope . teams = Team . query ( ) ;
$scope . certificates = Certificate . query ( ) ;
$scope . ca = CACertificate . get ( ) ;
$scope . revoke = function ( ) {
var targetserial = $ ( "#revokeModal" ) . data ( "certificate" ) ;
if ( targetserial ) {
Certificate . delete ( { serial : targetserial } ) . $promise . then (
function ( ) {
$ ( '#revokeModal' ) . modal ( 'hide' ) ;
2019-02-05 00:44:41 +00:00
$scope . certificates = Certificate . query ( ) . $promise . then ( function ( certificates ) {
certificates . forEach ( function ( certificate , cid ) {
certificate . serial = parseInt ( certificate . id ) . toString ( 16 ) ;
} ) ;
} ) ;
2018-01-21 13:18:26 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when trying to associate certificate:' , response . data . errmsg ) ;
2018-01-21 13:18:26 +00:00
}
) ;
}
} ;
2020-01-28 15:20:01 +00:00
$scope . validateSearch = function ( keyEvent ) {
if ( keyEvent . which === 13 ) {
var myCertificate = null ;
$scope . certificates . forEach ( function ( certificate ) {
if ( String ( certificate . id ) . indexOf ( $scope . query . toUpperCase ( ) ) >= 0 ) {
if ( myCertificate === null )
myCertificate = certificate ;
else
myCertificate = false ;
}
} ) ;
if ( myCertificate && myCertificate . id _team == null ) {
$ ( '#associationModal' ) . data ( 'certificate' , myCertificate . id )
$ ( '#associationModal' ) . modal ( )
}
}
} ;
2020-01-24 16:46:28 +00:00
$scope . validatePKIForm = function ( keyEvent ) {
if ( keyEvent . which === 13 )
$scope . associate ( )
} ;
2018-01-21 13:18:26 +00:00
$scope . associate = function ( ) {
var targetserial = $ ( "#associationModal" ) . data ( "certificate" ) ;
if ( ! targetserial ) return ;
Certificate . update ( { serial : targetserial } , { id _team : $scope . selectedTeam } ) . $promise . then (
function ( ) {
$ ( '#associationModal' ) . modal ( 'hide' ) ;
$scope . certificates = Certificate . query ( ) ;
$scope . selectedTeam = null ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when trying to associate certificate:' , response . data . errmsg ) ;
2018-01-21 13:18:26 +00:00
}
) ;
} ;
$scope . generateCA = function ( ) {
2021-07-21 21:17:47 +00:00
$http . post ( "api/ca/new" , $scope . newca ) . then ( function ( ) {
2018-01-21 13:18:26 +00:00
$scope . ca = CACertificate . get ( ) ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when generating CA:' , response . data . errmsg ) ;
2018-01-21 13:18:26 +00:00
} ) ;
} ;
2020-01-21 17:51:43 +00:00
$scope . renewCA = function ( ) {
$scope . ca = { } ;
} ;
2018-01-21 13:18:26 +00:00
$scope . generateCert = function ( ) {
2021-07-21 21:17:47 +00:00
$http . post ( "api/certs" ) . then ( function ( ) {
2018-01-21 13:18:26 +00:00
$scope . certificates = Certificate . query ( ) ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when generating certificate:' , response . data . errmsg ) ;
2018-01-21 13:18:26 +00:00
} ) ;
} ;
2020-01-23 18:03:45 +00:00
$scope . generateHtpasswd = function ( ) {
2021-07-21 21:17:47 +00:00
$http . post ( "api/htpasswd" ) . then ( function ( ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , 'Fichier htpasswd généré avec succès' ) ;
2020-01-23 18:03:45 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when generating htpasswd file:' , response . data . errmsg ) ;
2020-01-23 18:03:45 +00:00
} ) ;
} ;
$scope . removeHtpasswd = function ( ) {
2021-07-21 21:17:47 +00:00
$http . delete ( "api/htpasswd" ) . then ( function ( ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , 'Fichier htpasswd supprimé avec succès' ) ;
2020-01-23 18:03:45 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when deleting htpasswd file:' , response . data . errmsg ) ;
2020-01-23 18:03:45 +00:00
} ) ;
} ;
2018-01-21 13:18:26 +00:00
} )
2017-12-17 23:30:23 +00:00
. controller ( "PublicController" , function ( $scope , $rootScope , $routeParams , $location , Scene , Theme , Teams , Exercice ) {
2024-03-14 16:44:21 +00:00
$scope . propagationtime = null ;
$scope . presetName = "" ;
2017-12-17 23:30:23 +00:00
$scope . screens = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ;
$scope . screenid = $routeParams . screenId ;
2019-01-19 07:01:29 +00:00
$scope . display = Scene . get ( { screenId : $routeParams . screenId } ) ;
2024-03-14 16:44:21 +00:00
$scope . listScenes = Scene . get ( ) ;
2017-01-20 18:18:43 +00:00
$scope . themes = Theme . query ( ) ;
$scope . teams = Teams . get ( ) ;
2017-12-17 23:30:23 +00:00
$scope . chScreen = function ( sid ) {
if ( $scope . screenid )
$location . url ( "/public/" + $scope . screenid ) ;
else
$location . url ( "/public/" ) ;
}
2017-01-20 18:18:43 +00:00
$scope . types = {
"welcome" : "Messages de bienvenue" ,
2017-12-17 19:44:23 +00:00
"countdown" : "Compte à rebours" ,
2017-01-20 18:18:43 +00:00
"message" : "Message" ,
"panel" : "Boîte" ,
2018-02-02 20:10:31 +00:00
"carousel" : "Carousel" ,
2017-01-20 18:18:43 +00:00
"exercice" : "Exercice" ,
"table" : "Tableau" ,
"rank" : "Classement" ,
2020-01-29 17:20:09 +00:00
"graph" : "Graphique" ,
2017-01-20 18:18:43 +00:00
} ;
2019-01-19 07:01:29 +00:00
$scope . typeside = {
"welcome" : "Messages de bienvenue" ,
"themes" : "Présentation des thèmes" ,
"exercice_follow" : "Dernier exercice des événements" ,
"exercice" : "Exercice" ,
2019-01-23 00:02:45 +00:00
"rank" : "Classement" ,
2020-01-30 17:50:10 +00:00
"graph" : "Graphique" ,
2019-01-19 07:01:29 +00:00
"message" : "Message" ,
"panel" : "Boîte" ,
} ;
2017-01-20 18:18:43 +00:00
$scope . welcome _types = {
2017-12-17 19:44:23 +00:00
"teams" : "Accueil des équipes" ,
2017-01-20 18:18:43 +00:00
"public" : "Accueil du public" ,
} ;
2018-02-02 20:10:31 +00:00
$scope . carousel _types = {
"exercices" : "Exercices" ,
"teams" : "Équipes" ,
"themes" : "Thèmes" ,
2018-02-04 20:24:40 +00:00
"ranking" : "Classement" ,
2018-02-02 20:10:31 +00:00
} ;
2017-12-17 19:44:23 +00:00
$scope . colors = {
"primary" : "Primaire" ,
"secondary" : "Secondaire" ,
"info" : "Info" ,
"success" : "Success" ,
"warning" : "Warning" ,
"danger" : "Danger" ,
"light" : "Clair" ,
"dark" : "Foncé" ,
2017-01-20 18:18:43 +00:00
} ;
$scope . rank _types = {
"general" : "Classement général" ,
2020-01-30 17:47:46 +00:00
"final" : "Classement final" ,
2017-01-20 18:18:43 +00:00
} ;
2019-01-23 00:02:45 +00:00
$scope . rank _types _side = {
"carousel" : "Classement général carousel" ,
"general" : "Classement général" ,
} ;
2017-01-20 18:18:43 +00:00
$scope . table _types = {
"levels" : "Niveaux d'exercices" ,
"teams" : "Équipes" ,
} ;
$scope . exercices = Exercice . query ( ) ;
$scope . clearScene = function ( ) {
2017-11-21 21:23:49 +00:00
$scope . someUpdt = true ;
2019-01-19 07:01:29 +00:00
$scope . display . scenes = [ ] ;
2017-01-20 18:18:43 +00:00
} ;
2017-12-17 19:44:23 +00:00
$scope . presetScene = function ( scene ) {
$scope . someUpdt = true ;
2019-01-19 07:01:29 +00:00
if ( scene == "registration" ) {
$scope . display . scenes = [
2017-12-17 19:44:23 +00:00
{
type : "welcome" ,
2019-11-25 13:28:21 +00:00
params : { kind : "teams" , url : "https://fic.srs.epita.fr/" } ,
2017-12-17 19:44:23 +00:00
} ,
{
type : "welcome" ,
params : { kind : "public" , notitle : true } ,
} ,
] ;
2019-01-19 07:01:29 +00:00
$scope . display . side = [
2017-12-17 19:44:23 +00:00
{
2019-01-19 07:01:29 +00:00
type : "themes" ,
params : { } ,
2017-12-17 19:44:23 +00:00
} ,
2019-01-19 07:01:29 +00:00
] ;
}
else if ( scene == "welcome" ) {
$scope . display . scenes = [
2018-01-23 02:49:23 +00:00
{
2018-12-09 21:46:17 +00:00
type : "carousel" ,
params : { color : "info" , kind : "themes" , title : "Présentation des entreprises ciblées" } ,
2018-01-23 02:49:23 +00:00
} ,
2017-12-17 19:44:23 +00:00
] ;
2019-01-19 07:01:29 +00:00
$scope . display . side = [
{
type : "welcome" ,
params : { kind : "public" } ,
} ,
] ;
}
else if ( scene == "start" ) {
$scope . display . scenes = [
2017-12-17 19:44:23 +00:00
{
type : "welcome" ,
params : { kind : "public" } ,
} ,
{
type : "countdown" ,
params : { color : "success" , end : null , lead : "Go, go, go !" , title : "Le challenge forensic va bientôt commencer !" } ,
} ,
] ;
2019-01-19 07:01:29 +00:00
$scope . display . side = [
{
type : "themes" ,
params : { } ,
} ,
] ;
}
2020-01-30 17:47:46 +00:00
else if ( scene == "end" ) {
$scope . display . scenes = [
{
type : "rank" ,
params : { which : "final" } ,
} ,
{
type : "table" ,
params : { kind : "teams" , themes : $scope . themes . map ( function ( z , i ) { return z . id ; } ) , total : true , teams : [ ] } ,
} ,
] ;
angular . forEach ( $scope . teams , function ( team , tid ) {
if ( team . rank >= 1 && team . rank <= 4 )
$scope . display . scenes [ 1 ] . params . teams . push ( tid )
} ) ;
$scope . display . side = [
{
type : "rank" ,
params : { which : "carousel" } ,
} ,
{
type : "graph" ,
params : { teams : [ ] , height : 400 , legend : false , hide : true } ,
} ,
{
type : "message" ,
params : { html : '<div class="row"><div class="col"><a href="http://www.epita.fr/" class="align-middle text-center"><img class="mt-4" src="/img/epita.png" alt="Epita"></a></div><div class="col mr-3"> <a href="http://www.epita.fr/"><img src="/img/comcyber.png" alt="Réserves de cyberdéfense" style="height: 100px;"></a></div></div>' , hide : true } ,
} ,
] ;
angular . forEach ( $scope . teams , function ( team , tid ) {
if ( team . rank >= 1 && team . rank <= 9 )
$scope . display . side [ 1 ] . params . teams . push ( tid )
} ) ;
$scope . display . hideEvents = true ;
$scope . display . hideCountdown = true ;
}
2017-12-17 19:44:23 +00:00
else if ( scene == "summary" ) {
2020-01-30 03:17:53 +00:00
$scope . display . scenes = [
{
type : "table" ,
params : { kind : "levels" , levels : [ 1 , 2 , 3 , 4 , 5 ] , themes : $scope . themes . map ( function ( z , i ) { return z . id ; } ) , total : true } ,
} ,
{
type : "graph" ,
2021-09-08 02:02:06 +00:00
params : { teams : [ ] , height : 337 , legend : true } ,
2020-01-30 03:17:53 +00:00
} ,
] ;
angular . forEach ( $scope . teams , function ( team , tid ) {
if ( team . rank >= 1 && team . rank <= 9 )
$scope . display . scenes [ 1 ] . params . teams . push ( tid )
} ) ;
$scope . display . side = [
{
type : "exercice_follow" ,
params : { } ,
} ,
] ;
2020-01-30 17:47:46 +00:00
$scope . display . hideEvents = false ;
$scope . display . hideCountdown = false ;
2020-01-30 03:17:53 +00:00
}
else if ( scene == "summary2" ) {
$scope . display . scenes = [
{
type : "graph" ,
params : { teams : [ ] , height : 400 , legend : false } ,
} ,
{
type : "rank" ,
params : { limit : 10 , which : "general" , legend : true } ,
} ,
] ;
angular . forEach ( $scope . teams , function ( team , tid ) {
if ( team . rank >= 1 && team . rank <= 9 )
$scope . display . scenes [ 0 ] . params . teams . push ( tid )
} ) ;
$scope . display . side = [
{
type : "exercice_follow" ,
params : { } ,
} ,
] ;
2020-01-30 17:47:46 +00:00
$scope . display . hideEvents = false ;
$scope . display . hideCountdown = false ;
2020-01-30 03:17:53 +00:00
}
else if ( scene == "summary3" ) {
2019-01-19 07:01:29 +00:00
$scope . display . scenes = [
2017-12-17 19:44:23 +00:00
{
type : "table" ,
2018-12-09 21:46:17 +00:00
params : { kind : "levels" , levels : [ 1 , 2 , 3 , 4 , 5 ] , themes : $scope . themes . map ( function ( z , i ) { return z . id ; } ) , total : true } ,
2017-12-17 19:44:23 +00:00
} ,
{
type : "rank" ,
2020-01-30 03:17:53 +00:00
params : { limit : 10 , which : "general" , legend : false } ,
2017-12-17 19:44:23 +00:00
} ,
] ;
2019-01-19 07:01:29 +00:00
$scope . display . side = [
2018-01-23 02:52:53 +00:00
{
2019-01-19 07:01:29 +00:00
type : "exercice_follow" ,
params : { } ,
2018-01-23 02:52:53 +00:00
} ,
] ;
2020-01-30 17:47:46 +00:00
$scope . display . hideEvents = false ;
$scope . display . hideCountdown = false ;
2018-01-23 02:52:53 +00:00
}
2019-01-19 07:01:29 +00:00
else if ( scene == "happyhour" ) {
$scope . display . customCountdown = {
show : true ,
shadow : "#E8CF5C" ,
2024-02-09 12:46:36 +00:00
end : new Date ( $rootScope . getSrvTime ( ) . getTime ( ) + 1802000 ) . toISOString ( ) ,
2019-01-19 07:01:29 +00:00
before : "Heure joyeuse : chaque résolution compte double !" ,
after : "Heure joyeuse terminée !" ,
}
}
else if ( scene == "freehintquarter" ) {
$scope . display . customCountdown = {
show : true ,
shadow : "#3DD28F" ,
2024-02-09 12:46:36 +00:00
end : new Date ( $rootScope . getSrvTime ( ) . getTime ( ) + 902000 ) . toISOString ( ) ,
2019-01-19 07:01:29 +00:00
before : "Quart d'heure facile : indices dévoilés !" ,
after : "Quart d'heure facile terminée !" ,
}
}
2017-12-17 19:44:23 +00:00
} ;
2017-12-17 23:30:23 +00:00
2019-01-19 07:01:29 +00:00
$scope . genSceneCountdownDate = function ( scene , duration ) {
2024-02-09 12:46:36 +00:00
scene . params . end = ( new Date ( $rootScope . getSrvTime ( ) . getTime ( ) + duration ) ) . toISOString ( ) ;
2019-01-19 07:01:29 +00:00
}
2020-01-23 12:28:10 +00:00
$scope . genCustomCountdownDate = function ( duration ) {
if ( duration == null ) {
$scope . display . customCountdown . end = $rootScope . settings . activateTime ;
} else {
2024-02-09 12:46:36 +00:00
$scope . display . customCountdown . end = ( new Date ( $rootScope . getSrvTime ( ) . getTime ( ) + duration ) ) . toISOString ( ) ;
2020-01-23 12:28:10 +00:00
}
2019-01-19 07:01:29 +00:00
}
2024-03-14 16:44:21 +00:00
$scope . loadFile = function ( fname ) {
$scope . display = Scene . get ( { screenId : fname } ) ;
$scope . someUpdt = true ;
} ;
$scope . deleteFile = function ( fname ) {
Scene . delete ( { screenId : fname } ) ;
$scope . listScenes = Scene . get ( ) ;
} ;
$scope . latePropagation = function ( ) {
$scope . someUpdt = false ;
var prms = Scene . update ( { screenId : $scope . screenid , t : $scope . propagationTime } , $scope . display ) ;
prms . $promise . then ( function ( ) {
$scope . addToast ( 'success' , 'Scene successfully planned!' ) ;
} , function ( response ) {
$scope . addToast ( 'danger' , 'An error occurs when planning scene:' , response . data . errmsg ) ;
} ) ;
} ;
$scope . savePreset = function ( ) {
$scope . someUpdt = false ;
var prms = Scene . update ( { screenId : $scope . screenid , p : $scope . presetName } , $scope . display ) ;
prms . $promise . then ( function ( ) {
$scope . addToast ( 'success' , 'Preset successfully saved!' ) ;
} , function ( response ) {
$scope . addToast ( 'danger' , 'An error occurs when saving preset:' , response . data . errmsg ) ;
} ) ;
} ;
2017-01-20 18:18:43 +00:00
$scope . saveScenes = function ( ) {
2017-11-21 21:23:49 +00:00
$scope . someUpdt = false ;
2019-01-19 07:01:29 +00:00
var prms = Scene . update ( { screenId : $scope . screenid } , $scope . display ) ;
2017-11-21 21:23:49 +00:00
prms . $promise . then ( function ( ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , 'Scene successfully published!' ) ;
2017-11-21 21:23:49 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when saving scene:' , response . data . errmsg ) ;
2017-11-21 21:23:49 +00:00
} ) ;
2017-01-20 18:18:43 +00:00
} ;
2019-01-19 07:01:29 +00:00
$scope . addSide = function ( ) {
$scope . someUpdt = true ;
$scope . display . side . push ( { params : { } } ) ;
} ;
$scope . delSide = function ( s ) {
$scope . someUpdt = true ;
angular . forEach ( $scope . display . side , function ( scene , k ) {
if ( scene == s )
$scope . display . side . splice ( k , 1 ) ;
} ) ;
} ;
$scope . upSide = function ( s ) {
$scope . someUpdt = true ;
angular . forEach ( $scope . display . side , function ( scene , k ) {
if ( scene == s && k > 0 ) {
$scope . display . side . splice ( k , 1 ) ;
$scope . display . side . splice ( k - 1 , 0 , scene ) ;
}
} ) ;
} ;
$scope . downSide = function ( s ) {
$scope . someUpdt = true ;
var move = true ;
angular . forEach ( $scope . display . side , function ( scene , k ) {
if ( move && scene == s ) {
$scope . display . side . splice ( k , 1 ) ;
$scope . display . side . splice ( k + 1 , 0 , scene ) ;
move = false ;
}
} ) ;
} ;
2017-01-20 18:18:43 +00:00
$scope . addScene = function ( ) {
2017-11-21 21:23:49 +00:00
$scope . someUpdt = true ;
2019-01-19 07:01:29 +00:00
$scope . display . scenes . push ( { params : { } } ) ;
2017-01-20 18:18:43 +00:00
} ;
$scope . delScene = function ( s ) {
2017-11-21 21:23:49 +00:00
$scope . someUpdt = true ;
2019-01-19 07:01:29 +00:00
angular . forEach ( $scope . display . scenes , function ( scene , k ) {
2017-01-20 18:18:43 +00:00
if ( scene == s )
2019-01-19 07:01:29 +00:00
$scope . display . scenes . splice ( k , 1 ) ;
2017-01-20 18:18:43 +00:00
} ) ;
} ;
$scope . upScene = function ( s ) {
2017-11-21 21:23:49 +00:00
$scope . someUpdt = true ;
2019-01-19 07:01:29 +00:00
angular . forEach ( $scope . display . scenes , function ( scene , k ) {
2017-01-20 18:18:43 +00:00
if ( scene == s && k > 0 ) {
2019-01-19 07:01:29 +00:00
$scope . display . scenes . splice ( k , 1 ) ;
$scope . display . scenes . splice ( k - 1 , 0 , scene ) ;
2017-01-20 18:18:43 +00:00
}
} ) ;
} ;
$scope . downScene = function ( s ) {
2017-11-21 21:23:49 +00:00
$scope . someUpdt = true ;
2017-01-20 18:18:43 +00:00
var move = true ;
2019-01-19 07:01:29 +00:00
angular . forEach ( $scope . display . scenes , function ( scene , k ) {
2017-01-20 18:18:43 +00:00
if ( move && scene == s ) {
2019-01-19 07:01:29 +00:00
$scope . display . scenes . splice ( k , 1 ) ;
$scope . display . scenes . splice ( k + 1 , 0 , scene ) ;
2017-01-20 18:18:43 +00:00
move = false ;
}
} ) ;
} ;
} )
2017-12-27 00:53:01 +00:00
. controller ( "FilesListController" , function ( $scope , File , $location , $http , $rootScope ) {
$scope . files = File . query ( ) ;
2024-03-17 14:03:30 +00:00
$scope . errfnd = null ;
$scope . errzip = null ;
2024-03-17 15:03:40 +00:00
$scope . fields = [ "id" , "path" , "name" , "size" ] ;
2017-12-27 00:53:01 +00:00
$scope . clearFiles = function ( id ) {
File . delete ( function ( ) {
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2017-12-27 00:53:01 +00:00
$scope . files = [ ] ;
} ) ;
} ;
2024-03-17 14:03:30 +00:00
$scope . gunzipFile = function ( f ) {
f . gunzipWIP = true ;
$http ( {
url : "api/files/" + f . id + "/gunzip" ,
method : "POST"
} ) . then ( function ( response ) {
f . gunzipWIP = false ;
f . err = true ;
} , function ( response ) {
f . gunzipWIP = false ;
$scope . inSync = false ;
$scope . errzip += 1 ;
f . err = response . data . errmsg ;
} )
} ;
2017-12-27 00:53:01 +00:00
$scope . checksum = function ( f ) {
2024-03-17 15:03:40 +00:00
f . checkWIP = true ;
2017-12-27 00:53:01 +00:00
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/files/" + f . id + "/check" ,
2018-08-19 20:19:49 +00:00
method : "POST"
2017-12-27 00:53:01 +00:00
} ) . then ( function ( response ) {
2024-03-17 15:03:40 +00:00
f . checkWIP = false ;
2018-08-19 20:19:49 +00:00
f . err = true ;
2017-12-27 00:53:01 +00:00
} , function ( response ) {
2024-03-17 15:03:40 +00:00
f . checkWIP = false ;
2017-12-27 00:53:01 +00:00
$scope . inSync = false ;
2018-08-19 20:19:49 +00:00
$scope . errfnd += 1 ;
f . err = response . data . errmsg ;
2017-12-27 00:53:01 +00:00
} )
} ;
$scope . checksumAll = function ( ) {
2024-03-17 14:03:30 +00:00
$scope . errfnd = null ;
2017-12-27 00:53:01 +00:00
angular . forEach ( $scope . files , function ( file ) {
$scope . checksum ( file ) ;
} ) ;
2024-03-17 14:03:30 +00:00
if ( $scope . errfnd === null ) $scope . errfnd = 0 ;
} ;
$scope . gunzipFiles = function ( ) {
$scope . errzip = null ;
angular . forEach ( $scope . files , function ( file ) {
$scope . gunzipFile ( file ) ;
} ) ;
if ( $scope . errzip === null ) $scope . errzip = 0 ;
2017-12-27 00:53:01 +00:00
} ;
$scope . show = function ( f ) {
$location . url ( "/exercices/" + f . idExercice ) ;
} ;
} )
2016-12-26 02:44:04 +00:00
. controller ( "EventsListController" , function ( $scope , Event , $location ) {
$scope . events = Event . query ( ) ;
$scope . fields = [ "id" , "kind" , "txt" , "time" ] ;
$scope . clearEvents = function ( id ) {
Event . delete ( function ( ) {
$scope . events = [ ] ;
} ) ;
} ;
$scope . show = function ( id ) {
$location . url ( "/events/" + id ) ;
} ;
} )
. controller ( "EventController" , function ( $scope , Event , $routeParams , $location ) {
$scope . event = Event . get ( { eventId : $routeParams . eventId } ) ;
$scope . fields = [ "kind" , "txt" , "time" ] ;
$scope . kinds = {
2018-12-09 17:35:28 +00:00
"secondary" : "Par défaut" ,
"primary" : "Mise en valeur" ,
"info" : "Info" ,
"warning" : "Warning" ,
"success" : "Success" ,
"danger" : "Danger" ,
"light" : "Clair" ,
"dark" : "Foncé" ,
2016-12-26 02:44:04 +00:00
} ;
$scope . saveEvent = function ( ) {
if ( this . event . id ) {
this . event . $update ( ) ;
} else {
this . event . $save ( function ( ) {
$location . url ( "/events/" + $scope . event . id ) ;
} ) ;
}
}
$scope . deleteEvent = function ( ) {
this . event . $remove ( function ( ) { $location . url ( "/events/" ) ; } ) ;
}
} )
2018-01-17 00:21:32 +00:00
. controller ( "AssigneesListController" , function ( $scope , ClaimAssignee , $location ) {
$scope . assignees = ClaimAssignee . query ( ) ;
$scope . setMyAId = function ( aid ) {
setCookie ( "myassignee" , aid , 5 ) ;
$location . url ( "/claims/" ) ;
}
$scope . whoami = getCookie ( "myassignee" ) ;
$scope . newAssignee = function ( ) {
$scope . assignees . push ( new ClaimAssignee ( ) ) ;
}
$scope . edit = function ( a ) {
a . edit = true ;
}
$scope . updateAssignee = function ( a ) {
if ( a . id ) {
a . $update ( function ( ) { $location . url ( "/claims/" ) ; } ) ;
} else {
a . $save ( )
}
}
$scope . removeAssignee = function ( a ) {
a . $remove ( function ( ) { $location . url ( "/claims/" ) ; } ) ;
}
} )
2020-01-20 07:46:13 +00:00
. controller ( "ClaimsTinyListController" , function ( $scope , Claim , ClaimAssignee , $interval ) {
$scope . whoami = getCookie ( "myassignee" ) ;
var priorities = {
"low" : 1 ,
"medium" : 2 ,
"high" : 3 ,
"critical" : 4 ,
} ;
$scope . priorities = [
"secondary" ,
2020-01-24 17:25:35 +00:00
"light" ,
2020-01-20 07:46:13 +00:00
"info" ,
"warning" ,
"danger" ,
] ;
var refresh = function ( ) {
Claim . query ( ) . $promise . then ( function ( claims ) {
$scope . newClaims = 0 ;
$scope . newClaimsMaxLevel = 0 ;
$scope . myClaims = 0 ;
$scope . myClaimsMaxLevel = 0 ;
claims . forEach ( function ( claim , cid ) {
if ( $scope . whoami && ! claim . id _assignee && claim . state == 'new' ) {
$scope . newClaims ++ ;
if ( priorities [ claim . priority ] > $scope . newClaimsMaxLevel )
$scope . newClaimsMaxLevel = priorities [ claim . priority ] ;
}
else if ( $scope . whoami && claim . id _assignee == $scope . whoami && claim . state != 'closed' && claim . state != 'invalid' ) {
$scope . myClaims ++ ;
2020-01-24 17:25:35 +00:00
if ( claim . state == 'new' && priorities [ claim . priority ] > $scope . myClaimsMaxLevel )
2020-01-20 07:46:13 +00:00
$scope . myClaimsMaxLevel = priorities [ claim . priority ] ;
}
} )
} ) ;
} ;
refresh ( ) ;
$interval ( refresh , 10000 ) ;
} )
2020-01-28 16:00:37 +00:00
. controller ( "ClaimsListController" , function ( $scope , Claim , ClaimAssignee , Teams , $interval , $location ) {
var refresh = function ( ) {
$scope . claims = Claim . query ( ) ;
$scope . assignees = ClaimAssignee . query ( ) ;
}
refresh ( ) ;
2023-04-03 22:13:13 +00:00
var myinterval = $interval ( refresh , 10000 ) ;
2020-01-28 16:00:37 +00:00
$scope . $on ( '$destroy' , function ( ) { $interval . cancel ( myinterval ) ; } ) ;
2018-01-17 00:21:32 +00:00
$scope . whoami = getCookie ( "myassignee" ) ;
$scope . teams = Teams . get ( ) ;
2020-01-24 17:24:20 +00:00
$scope . fields = [ "subject" , "id_team" , "state" , "id_assignee" , "last_update" , "id" ] ;
2018-01-17 00:21:32 +00:00
$scope . order = "priority" ;
$scope . chOrder = function ( no ) {
$scope . order = no ;
} ;
$scope . clearClaims = function ( id ) {
Claim . delete ( function ( ) {
$scope . claims = [ ] ;
} ) ;
} ;
$scope . show = function ( id ) {
$location . url ( "/claims/" + id ) ;
} ;
} )
2020-01-24 17:24:20 +00:00
. controller ( "ClaimLastUpdateController" , function ( $scope , $http ) {
$scope . init = function ( claim ) {
2021-07-21 21:17:47 +00:00
$http . get ( "api/claims/" + claim . id + "/last_update" ) . then ( function ( response ) {
2020-01-24 17:24:20 +00:00
if ( response . data )
$scope . last _update = response . data ;
else
$scope . last _update = claim . creation ;
claim . last _update = $scope . last _update ;
} , function ( response ) {
$scope . last _update = claim . creation ;
} )
}
} )
2020-01-20 09:41:21 +00:00
. controller ( "ClaimController" , function ( $scope , Claim , ClaimAssignee , Teams , Exercice , $routeParams , $location , $http , $rootScope ) {
2018-01-17 00:21:32 +00:00
$scope . claim = Claim . get ( { claimId : $routeParams . claimId } , function ( v ) {
v . id _team = "" + v . id _team ;
if ( ! v . priority )
v . priority = "medium" ;
} ) ;
if ( $routeParams . claimId == "new" )
2020-01-20 09:41:21 +00:00
$scope . fields = [ "id_team" , "id_exercice" , "subject" , "priority" , "id_assignee" ] ;
2018-01-17 00:21:32 +00:00
else
2020-01-20 14:57:26 +00:00
$scope . fields = [ "subject" , "priority" , "id_exercice" , "id_assignee" , "id_team" , "creation" , "state" ] ;
2018-01-17 00:21:32 +00:00
$scope . assignees = ClaimAssignee . query ( ) ;
2020-01-30 17:48:28 +00:00
$scope . comm = { ndescription : "" } ;
$scope . whoami = Math . floor ( getCookie ( "myassignee" ) ) ;
2018-01-17 00:21:32 +00:00
$scope . teams = Teams . get ( ) ;
2020-01-20 08:24:24 +00:00
$scope . exercices = Exercice . query ( ) ;
$scope . namedFields = {
2018-01-17 00:21:32 +00:00
"subject" : "Objet" ,
2020-01-24 17:25:35 +00:00
"id_assignee" : "Assigné à" ,
2018-01-17 00:21:32 +00:00
"state" : "État" ,
"id_team" : "Équipe" ,
2020-01-20 08:24:24 +00:00
"id_exercice" : "Challenge" ,
2018-01-17 00:21:32 +00:00
"creation" : "Création" ,
"priority" : "Priorité" ,
"description" : "Description" ,
} ;
$scope . states = {
"new" : "Nouveau" ,
"need-info" : "Besoin d'infos" ,
"confirmed" : "Confirmé" ,
"in-progress" : "En cours" ,
"need-review" : "Fait" ,
"closed" : "Clos" ,
"invalid" : "Invalide" ,
} ;
$scope . priorities = {
"low" : "Basse" ,
"medium" : "Moyenne" ,
"high" : "Haute" ,
"critical" : "Critique" ,
} ;
2020-01-20 14:57:26 +00:00
$scope . changeState = function ( state ) {
this . claim . state = state ;
2020-01-24 17:23:06 +00:00
if ( ( state == "in-progress" || state == "invalid" ) && this . claim . id _assignee )
this . claim . id _assignee = $scope . whoami ;
2020-01-20 14:57:26 +00:00
if ( this . claim . id )
2020-01-23 15:03:31 +00:00
this . saveClaim ( state == "invalid" || state == "closed" ) ;
2020-01-20 14:57:26 +00:00
}
2018-01-17 00:21:32 +00:00
$scope . assignToMe = function ( ) {
this . claim . id _assignee = $scope . whoami ;
if ( this . claim . id )
2020-01-20 14:57:26 +00:00
this . saveClaim ( false ) ;
2018-01-17 00:21:32 +00:00
}
2020-01-23 15:03:31 +00:00
$scope . updateDescription = function ( description ) {
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/claims/" + $scope . claim . id + "/descriptions" ,
2020-01-23 15:03:31 +00:00
method : "PUT" ,
data : description
} ) . then ( function ( response ) {
$scope . claim = Claim . get ( { claimId : $routeParams . claimId } , function ( v ) {
v . id _team = "" + v . id _team ;
if ( ! v . priority )
v . priority = "medium" ;
} ) ;
} ) ;
}
2018-01-17 00:21:32 +00:00
$scope . saveDescription = function ( ) {
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/claims/" + $scope . claim . id ,
2018-01-17 00:21:32 +00:00
method : "POST" ,
data : {
"id_assignee" : $scope . whoami ,
2020-01-30 17:48:28 +00:00
"content" : $scope . comm . ndescription
2018-01-17 00:21:32 +00:00
}
2018-08-17 20:17:51 +00:00
} ) . then ( function ( response ) {
2018-02-04 21:04:54 +00:00
$location . url ( "/claims/" + $scope . claim . id + "/" ) ;
2018-01-17 00:21:32 +00:00
} ) ;
}
2020-01-23 15:03:31 +00:00
$scope . saveClaim = function ( backToList ) {
2020-01-24 17:23:06 +00:00
this . claim . whoami = $scope . whoami ;
2018-01-17 00:21:32 +00:00
if ( this . claim . id _team ) {
2020-01-20 14:57:26 +00:00
this . claim . id _team = parseInt ( this . claim . id _team , 10 ) ;
2018-01-17 00:21:32 +00:00
} else {
this . claim . id _team = null ;
}
if ( this . claim . id ) {
this . claim . $update ( function ( v ) {
v . id _team = "" + v . id _team ;
2020-01-30 17:48:28 +00:00
if ( $scope . comm . ndescription )
2018-01-17 00:21:32 +00:00
$scope . saveDescription ( ) ;
2020-01-20 14:57:26 +00:00
else if ( backToList )
2018-01-17 00:21:32 +00:00
$location . url ( "/claims/" ) ;
2020-01-20 14:57:26 +00:00
else
$scope . claim = Claim . get ( { claimId : $routeParams . claimId } , function ( v ) {
v . id _team = "" + v . id _team ;
if ( ! v . priority )
v . priority = "medium" ;
} ) ;
2018-01-17 00:21:32 +00:00
} ) ;
} else {
this . claim . $save ( function ( ) {
2020-01-30 17:48:28 +00:00
if ( ! $scope . comm . ndescription )
$scope . comm . ndescription = "Création de la tâche" ;
2018-01-17 00:21:32 +00:00
$scope . saveDescription ( ) ;
2020-01-20 09:41:21 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when trying to save claim:' , response . data . errmsg ) ;
2018-01-17 00:21:32 +00:00
} ) ;
}
}
$scope . deleteClaim = function ( ) {
this . claim . $remove ( function ( ) { $location . url ( "/claims/" ) ; } ) ;
}
} )
2017-12-17 14:39:20 +00:00
. controller ( "ThemesListController" , function ( $scope , Theme , $location , $rootScope , $http ) {
2016-01-22 16:37:29 +00:00
$scope . themes = Theme . query ( ) ;
2018-12-08 20:24:30 +00:00
$scope . fields = [ "name" , "authors" , "headline" , "path" ] ;
2016-01-22 16:37:29 +00:00
2020-01-29 17:18:25 +00:00
$scope . validateSearch = function ( keyEvent ) {
if ( keyEvent . which === 13 ) {
var myTheme = null ;
$scope . themes . forEach ( function ( theme ) {
if ( String ( theme . name . toLowerCase ( ) ) . indexOf ( $scope . query . toLowerCase ( ) ) >= 0 ) {
if ( myTheme === null )
myTheme = theme ;
else
myTheme = false ;
}
} ) ;
if ( myTheme )
$location . url ( "themes/" + myTheme . id ) ;
}
} ;
2016-01-22 16:37:29 +00:00
$scope . show = function ( id ) {
$location . url ( "/themes/" + id ) ;
} ;
2017-12-17 14:39:20 +00:00
$scope . inSync = false ;
$scope . sync = function ( ) {
$scope . inSync = true ;
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/sync/themes" ,
2018-01-06 14:08:05 +00:00
method : "POST"
2017-12-17 14:39:20 +00:00
} ) . then ( function ( response ) {
$scope . inSync = false ;
$scope . themes = Theme . query ( ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2017-12-17 14:39:20 +00:00
if ( response . data )
2020-05-16 01:53:07 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchronizing theme list:' , response . data ) ;
2017-12-17 14:39:20 +00:00
else
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , 'Synchronisation de la liste des thèmes terminée avec succès.' ) ;
2017-12-17 14:39:20 +00:00
} , function ( response ) {
$scope . inSync = false ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchronizing theme list:' , response . data . errmsg ) ;
2017-12-17 14:39:20 +00:00
} ) ;
} ;
2016-01-22 16:37:29 +00:00
} )
2017-12-17 14:39:20 +00:00
. controller ( "ThemeController" , function ( $scope , Theme , $routeParams , $location , $rootScope , $http ) {
2016-01-22 16:37:29 +00:00
$scope . theme = Theme . get ( { themeId : $routeParams . themeId } ) ;
2024-03-18 10:26:01 +00:00
$scope . fields = [ "name" , "urlid" , "locked" , "authors" , "headline" , "intro" , "image" , "background_color" , "partner_txt" , "partner_href" , "partner_img" ] ;
2016-01-22 16:37:29 +00:00
$scope . saveTheme = function ( ) {
2016-12-27 20:08:36 +00:00
if ( this . theme . id ) {
this . theme . $update ( ) ;
} else {
this . theme . $save ( function ( ) {
$location . url ( "/themes/" + $scope . theme . id ) ;
} ) ;
}
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2016-12-26 00:20:06 +00:00
}
$scope . deleteTheme = function ( ) {
2018-12-05 04:03:21 +00:00
this . theme . $remove ( function ( ) {
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2018-12-05 04:03:21 +00:00
$location . url ( "/themes/" ) ;
2017-12-17 14:39:20 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when trying to delete theme:' , response . data . errmsg ) ;
2017-12-17 14:39:20 +00:00
} ) ;
2018-12-05 04:03:21 +00:00
}
2016-01-22 16:37:29 +00:00
} )
2022-05-24 19:25:27 +00:00
. controller ( "TagsListController" , function ( $scope , $http ) {
$scope . tags = [ ] ;
$http ( {
url : "api/tags" ,
method : "GET"
} ) . then ( function ( response ) {
$scope . tags = response . data
} ) ;
} )
2018-12-08 20:17:37 +00:00
. controller ( "AllExercicesListController" , function ( $scope , Exercice , Theme , $routeParams , $location , $rootScope , $http , $filter ) {
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/themes.json" ,
2018-12-08 20:17:37 +00:00
method : "GET"
} ) . then ( function ( response ) {
$scope . themes = response . data
} ) ;
2016-12-26 00:23:31 +00:00
$scope . exercices = Exercice . query ( ) ;
2018-11-21 00:19:13 +00:00
$scope . exercice = { } ; // Array used to save fields to updates in selected exercices
2018-12-08 20:24:30 +00:00
$scope . fields = [ "title" , "headline" ] ;
2016-01-22 16:37:29 +00:00
2020-01-29 17:18:25 +00:00
$scope . validateSearch = function ( keyEvent ) {
if ( keyEvent . which === 13 ) {
var myExercice = null ;
$scope . exercices . forEach ( function ( exercice ) {
if ( String ( exercice . title . toLowerCase ( ) ) . indexOf ( $scope . query . toLowerCase ( ) ) >= 0 ) {
if ( myExercice === null )
myExercice = exercice ;
else
myExercice = false ;
}
} ) ;
if ( myExercice )
$location . url ( "exercices/" + myExercice . id ) ;
}
} ;
2018-11-21 00:19:13 +00:00
$scope . toggleSelectAll = function ( ) {
angular . forEach ( $filter ( 'filter' ) ( $scope . exercices , $scope . query ) , function ( ex ) {
ex . selected = ! $scope . selectall
} )
}
$scope . updateExercices = function ( ) {
angular . forEach ( $scope . exercices , function ( ex ) {
if ( ex . selected ) {
Exercice . patch ( { exerciceId : ex . id } , $scope . exercice ) ;
}
} )
$scope . exercice = { } ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , 'Édition de masse terminée avec succès' ) ;
2018-11-21 00:19:13 +00:00
}
2016-01-22 16:37:29 +00:00
$scope . show = function ( id ) {
2016-12-26 00:23:31 +00:00
$location . url ( "/exercices/" + id ) ;
2016-01-22 16:37:29 +00:00
} ;
2017-12-17 14:39:20 +00:00
$scope . inSync = false ;
$scope . syncFull = function ( ) {
$scope . inSync = true ;
$scope . done = - 1 ;
$scope . total = 0 ;
var work = [ ] ;
var go = function ( ) {
if ( ! work . length ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'info' , "Synchronisation des exercices terminée." ) ;
2017-12-17 14:39:20 +00:00
$scope . inSync = false ;
return ;
}
var u = work . pop ( ) ;
$http ( {
url : u ,
method : "GET"
} ) . then ( function ( response ) {
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2017-12-17 14:39:20 +00:00
$scope . done += 1 ;
go ( ) ;
} , function ( response ) {
$scope . done += 1 ;
go ( ) ;
} ) ;
} ;
angular . forEach ( $scope . exercices , function ( ex ) {
if ( $scope . syncFiles )
2021-07-21 21:17:47 +00:00
work . push ( "api/sync/exercices/" + ex . id + "/files" ) ;
2017-12-17 14:39:20 +00:00
if ( $scope . syncHints )
2021-07-21 21:17:47 +00:00
work . push ( "api/sync/exercices/" + ex . id + "/hints" ) ;
2018-09-24 08:00:17 +00:00
if ( $scope . syncFlags )
2021-07-21 21:17:47 +00:00
work . push ( "api/sync/exercices/" + ex . id + "/flags" ) ;
2017-12-17 14:39:20 +00:00
} ) ;
$scope . total = work . length ;
go ( ) ;
} ;
$scope . syncFiles = true ;
$scope . syncHints = true ;
2018-09-24 08:00:17 +00:00
$scope . syncFlags = true ;
2016-01-22 16:37:29 +00:00
} )
2020-01-29 14:57:34 +00:00
. controller ( "ExercicesListController" , function ( $scope , ThemedExercice , $location , $rootScope , $http ) {
$scope . exercices = ThemedExercice . query ( { themeId : $scope . theme . id } ) ;
2018-12-08 20:24:30 +00:00
$scope . fields = [ "title" , "headline" , "issue" ] ;
2016-01-22 16:37:29 +00:00
2016-12-26 00:23:31 +00:00
$scope . show = function ( id ) {
2020-01-29 14:57:34 +00:00
$location . url ( "/themes/" + $scope . theme . id + "/exercices/" + id ) ;
2016-12-26 00:23:31 +00:00
} ;
2018-12-05 04:03:21 +00:00
$scope . inSync = false ;
$scope . syncExo = function ( ) {
$scope . inSync = true ;
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/sync/themes/" + $scope . theme . id + "/exercices" ,
2018-12-05 04:03:21 +00:00
method : "POST"
} ) . then ( function ( response ) {
$scope . inSync = false ;
2020-01-29 14:57:34 +00:00
$scope . exercices = ThemedExercice . query ( { themeId : $scope . theme . id } ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2018-12-05 04:03:21 +00:00
if ( response . data )
2020-05-16 01:53:07 +00:00
$scope . addToast ( 'warning' , 'An error occurs when synchrinizing exercices:' , response . data ) ;
2018-12-05 04:03:21 +00:00
else
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , 'Synchronisation de la liste des exercices terminée avec succès.' ) ;
2018-12-05 04:03:21 +00:00
} , function ( response ) {
$scope . inSync = false ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchrinizing exercices:' , response . data . errmsg ) ;
2018-12-05 04:03:21 +00:00
} ) ;
} ;
2016-12-26 00:23:31 +00:00
} )
2018-12-05 04:03:21 +00:00
. controller ( "ExerciceController" , function ( $scope , $rootScope , Exercice , ThemedExercice , $routeParams , $location , $http ) {
2016-12-27 20:08:36 +00:00
if ( $routeParams . themeId && $routeParams . exerciceId == "new" ) {
$scope . exercice = new ThemedExercice ( ) ;
} else {
$scope . exercice = Exercice . get ( { exerciceId : $routeParams . exerciceId } ) ;
}
2023-04-03 23:49:38 +00:00
$scope . my _ex _num = { } ;
2018-12-09 18:06:29 +00:00
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/themes.json" ,
2018-12-09 18:06:29 +00:00
method : "GET"
} ) . then ( function ( response ) {
2024-03-15 16:46:50 +00:00
$scope . themes = response . data ;
if ( $scope . exercice . id _theme ) {
for ( var k in $scope . themes [ $scope . exercice . id _theme ] . exercices ) {
var exercice = $scope . themes [ $scope . exercice . id _theme ] . exercices [ k ] ;
$scope . my _ex _num [ exercice . id ] = k ;
}
} else {
for ( var k in $scope . themes [ "0" ] . exercices ) {
var exercice = $scope . themes [ "0" ] . exercices [ k ] ;
$scope . my _ex _num [ exercice . id ] = k ;
}
}
2018-12-09 18:06:29 +00:00
} ) ;
2016-12-26 00:23:31 +00:00
$scope . exercices = Exercice . query ( ) ;
2024-03-18 10:26:01 +00:00
$scope . fields = [ "title" , "urlid" , "authors" , "disabled" , "statement" , "headline" , "overview" , "finished" , "depend" , "gain" , "coefficient" , "videoURI" , "image" , "background_color" , "resolution" , "issue" , "issuekind" , "wip" ] ;
2016-12-26 00:23:31 +00:00
2018-12-05 04:03:21 +00:00
$scope . inSync = false ;
$scope . syncExo = function ( ) {
$scope . inSync = true ;
$http ( {
2024-03-15 16:46:50 +00:00
url : $scope . exercice . id _theme ? ( "api/sync/themes/" + $scope . exercice . id _theme + "/exercices/" + $routeParams . exerciceId ) : ( "api/sync/exercices/" + $routeParams . exerciceId ) ,
2018-12-05 04:03:21 +00:00
method : "POST"
} ) . then ( function ( response ) {
$scope . inSync = false ;
$scope . exercice = Exercice . get ( { exerciceId : $routeParams . exerciceId } ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2018-12-05 04:03:21 +00:00
if ( response . data )
2020-05-16 01:53:07 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchronizing exercice:' , response . data ) ;
2018-12-05 04:03:21 +00:00
else
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , "Synchronisation de l'exercice terminée avec succès." ) ;
2018-12-05 04:03:21 +00:00
} , function ( response ) {
$scope . inSync = false ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchronizing exercice:' , response . data . errmsg ) ;
2018-12-05 04:03:21 +00:00
} ) ;
} ;
$scope . deleteExercice = function ( ) {
2018-12-09 23:29:02 +00:00
var tid = $scope . exercice . id _theme ;
2018-12-05 04:03:21 +00:00
this . exercice . $remove ( function ( ) {
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2018-12-09 23:29:02 +00:00
$location . url ( "/themes/" + tid ) ;
2018-12-05 04:03:21 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when trying to delete exercice:' , response . data . errmsg ) ;
2018-12-05 04:03:21 +00:00
} ) ;
}
2016-12-26 00:23:31 +00:00
$scope . saveExercice = function ( ) {
2016-12-27 20:08:36 +00:00
if ( this . exercice . id ) {
this . exercice . $update ( ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2016-12-27 20:08:36 +00:00
} else if ( $routeParams . themeId ) {
this . exercice . $save ( { themeId : $routeParams . themeId } , function ( ) {
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2016-12-27 20:08:36 +00:00
$location . url ( "/themes/" + $scope . exercice . idTheme + "/exercices/" + $scope . exercice . id ) ;
2018-12-05 04:03:21 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when trying to save exercice:' , response . data . errmsg ) ;
2016-12-27 20:08:36 +00:00
} ) ;
}
2016-12-26 00:23:31 +00:00
}
2024-03-17 09:19:35 +00:00
$scope . selectedTeam = "" ;
$scope . validateForTeam = function ( ) {
var flagid = $ ( "#validationModal" ) . data ( "flagid" ) ;
if ( ! flagid ) return ;
var target = {
team _id : parseInt ( $ ( "#tteam" ) . val ( ) . replace ( /number:/ , '' ) ) ,
kind : $ ( "#validationModal" ) . data ( "kind" ) ,
secondary : flagid ,
} ;
$http ( {
url : "api/exercices/" + $scope . exercice . id + "/history.json" ,
method : "PUT" ,
data : target
} ) . then ( function ( response ) {
$rootScope . staticFilesNeedUpdate ++ ;
$ ( "#validationModal" ) . modal ( 'hide' ) ;
$scope . addToast ( 'success' , 'Flag validé avec succès' ) ;
} , function ( response ) {
$scope . addToast ( 'danger' , 'An error occurs when trying to validate flag for team:' , response . data . errmsg ) ;
} ) ;
}
$scope . historyAppend = function ( ) {
var secondary = null ;
if ( $ ( "#historyEvent" ) . val ( ) == "hint" )
secondary = parseInt ( $ ( "#historySecondaryHint" ) . val ( ) . replace ( /number:/ , '' ) ) ;
else if ( $ ( "#historyEvent" ) . val ( ) == "wchoices" || $ ( "#historyEvent" ) . val ( ) == "flag_found" )
secondary = parseInt ( $ ( "#historySecondaryFlag" ) . val ( ) . replace ( /number:/ , '' ) ) ;
else if ( $ ( "#historyEvent" ) . val ( ) == "mcq_found" )
secondary = parseInt ( $ ( "#historySecondaryQuiz" ) . val ( ) . replace ( /number:/ , '' ) ) ;
var target = {
team _id : parseInt ( $ ( "#tteam" ) . val ( ) . replace ( /number:/ , '' ) ) ,
kind : $ ( "#historyEvent" ) . val ( ) ,
secondary : secondary ,
} ;
$http ( {
url : "api/exercices/" + $scope . exercice . id + "/history.json" ,
method : "PUT" ,
data : target
} ) . then ( function ( response ) {
$rootScope . staticFilesNeedUpdate ++ ;
$ ( "#appendHistoryModal" ) . modal ( 'hide' ) ;
$scope . addToast ( 'success' , 'Événement ajouté avec succès' ) ;
$scope . refreshHistory ( ) ;
} , function ( response ) {
$scope . addToast ( 'danger' , 'An error occurs when trying to add event in history:' , response . data . errmsg ) ;
} ) ;
}
2016-12-26 00:23:31 +00:00
} )
2022-06-08 01:40:03 +00:00
. controller ( "SubmissionsStatsController" , function ( $scope , $http , $interval ) {
var refresh = function ( ) {
$http ( {
url : "api/submissions-stats.json" ,
} ) . then ( function ( response ) {
$scope . submissionsstats = response . data ;
} ) ;
}
var myinterval = $interval ( refresh , 15000 ) ;
refresh ( ) ;
$scope . $on ( '$destroy' , function ( ) { $interval . cancel ( myinterval ) ; } ) ;
} )
. controller ( "ValidationsStatsController" , function ( $scope , $http , $interval ) {
var refresh = function ( ) {
$http ( {
url : "api/validations-stats.json" ,
} ) . then ( function ( response ) {
$scope . validationsstats = response . data ;
} ) ;
}
var myinterval = $interval ( refresh , 15000 ) ;
refresh ( ) ;
$scope . $on ( '$destroy' , function ( ) { $interval . cancel ( myinterval ) ; } ) ;
} )
2022-06-01 11:25:58 +00:00
. controller ( "ExercicesStatsController" , function ( $scope , Themes , ExercicesStats ) {
$scope . themes = Themes . get ( ) ;
$scope . exercices = { } ;
ExercicesStats . query ( ) . $promise . then ( function ( exs ) {
exs . forEach ( function ( ex ) {
$scope . exercices [ ex . id _exercice ] = ex ;
} )
} ) ;
2024-03-17 10:43:07 +00:00
$scope . lenExoArray = [ ] ;
$scope . themes . $promise . then ( function ( themes ) {
if ( themes [ '0' ] && themes [ '0' ] . exercices . length ) {
var j = 0 ;
for ( var i = themes [ '0' ] . exercices . length / 10 ; i >= 0 ; i -- ) {
$scope . lenExoArray . push ( j ++ ) ;
}
}
} ) ;
2020-01-29 14:57:34 +00:00
} )
2020-01-28 13:01:13 +00:00
. controller ( "ExerciceStatsController" , function ( $scope , ExerciceStats , $routeParams ) {
$scope . stats = ExerciceStats . get ( { exerciceId : $routeParams . exerciceId } ) ;
} )
2020-01-20 09:41:21 +00:00
. controller ( "ExerciceClaimsController" , function ( $scope , ExerciceClaims , Team , ClaimAssignee , $routeParams , $location ) {
$scope . claims = ExerciceClaims . query ( { exerciceId : $routeParams . exerciceId } ) ;
$scope . assignees = ClaimAssignee . query ( ) ;
$scope . claims . $promise . then ( function ( claims ) {
claims . forEach ( function ( claim , cid ) {
$scope . claims [ cid ] . team = Team . get ( { teamId : claim . id _team } ) ;
} )
} ) ;
$scope . showClosed = false ;
$scope . show = function ( id ) {
$location . url ( "/claims/" + id ) ;
} ;
} )
2018-12-05 04:03:21 +00:00
. controller ( "ExerciceTagsController" , function ( $scope , ExerciceTags , $routeParams , $rootScope ) {
2018-11-18 21:44:23 +00:00
$scope . tags = ExerciceTags . query ( { exerciceId : $routeParams . exerciceId } ) ;
$scope . addTag = function ( ) {
$scope . tags . push ( "" ) ;
}
$scope . deleteTag = function ( ) {
$scope . tags . splice ( $scope . tags . indexOf ( this . tag ) , 1 ) ;
return $scope . saveTags ( ) ;
}
$scope . saveTags = function ( ) {
ExerciceTags . update ( { exerciceId : $routeParams . exerciceId } , this . tags ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2018-11-18 21:44:23 +00:00
}
} )
2019-02-03 21:30:29 +00:00
. controller ( "ExerciceHistoryController" , function ( $scope , ExerciceHistory , $routeParams , $http , $rootScope ) {
2024-03-17 09:19:35 +00:00
$scope . history = [ ] ;
$scope . refreshHistory = function ( ) {
$scope . history = ExerciceHistory . query ( { exerciceId : $routeParams . exerciceId } ) ;
}
$scope . $parent . refreshHistory = $scope . refreshHistory ;
$scope . refreshHistory ( ) ;
2019-07-12 17:17:17 +00:00
$scope . updHistory = function ( ) {
var target = {
team _id : $ ( "#updHistory" ) . data ( "idteam" ) ,
kind : $ ( "#updHistory" ) . data ( "kind" ) ,
time : $ ( "#updHistory" ) . data ( "time" ) ,
secondary : $ ( "#updHistory" ) . data ( "secondary" ) != "" ? $ ( "#updHistory" ) . data ( "secondary" ) : null ,
coeff : parseFloat ( $ ( '#historycoeff' ) . val ( ) ) ,
} ;
if ( target ) {
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/exercices/" + $routeParams . exerciceId + "/history.json" ,
2019-07-12 17:17:17 +00:00
method : "PATCH" ,
data : target
} ) . then ( function ( response ) {
$rootScope . staticFilesNeedUpdate ++ ;
$scope . history = ExerciceHistory . query ( { exerciceId : $routeParams . exerciceId } ) ;
$ ( '#updHistory' ) . modal ( 'hide' ) ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when updating history item: ' , response . data . errmsg ) ;
2019-07-12 17:17:17 +00:00
} ) ;
}
}
2019-02-03 21:30:29 +00:00
$scope . delHistory = function ( row ) {
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/exercices/" + $routeParams . exerciceId + "/history.json" ,
2019-02-03 21:30:29 +00:00
method : "DELETE" ,
data : row
} ) . then ( function ( response ) {
$rootScope . staticFilesNeedUpdate ++ ;
$scope . history = ExerciceHistory . query ( { exerciceId : $routeParams . exerciceId } ) ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when removing history item: ' , response . data . errmsg ) ;
2019-02-03 21:30:29 +00:00
} ) ;
}
} )
2017-12-17 14:39:20 +00:00
. controller ( "ExerciceFilesController" , function ( $scope , ExerciceFile , $routeParams , $rootScope , $http ) {
2016-12-26 00:23:31 +00:00
$scope . files = ExerciceFile . query ( { exerciceId : $routeParams . exerciceId } ) ;
$scope . deleteFile = function ( ) {
2016-12-27 20:08:36 +00:00
this . file . $delete ( function ( ) {
2019-07-21 19:55:36 +00:00
$scope . files = ExerciceFile . query ( { exerciceId : $routeParams . exerciceId } ) ;
2016-12-27 20:08:36 +00:00
} ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2016-12-27 20:08:36 +00:00
return false ;
2016-12-26 00:23:31 +00:00
}
2019-07-21 21:46:23 +00:00
$scope . deleteFileDep = function ( ) {
$http ( {
2021-07-21 21:17:47 +00:00
url : "api//files/" + this . file . id + "/dependancies/" + this . dep . id ,
2019-07-21 21:46:23 +00:00
method : "DELETE"
} ) . then ( function ( response ) {
$scope . files = ExerciceFile . query ( { exerciceId : $routeParams . exerciceId } ) ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when removing file dep:' , response . data . errmsg ) ;
2019-07-21 21:46:23 +00:00
} ) ;
$rootScope . staticFilesNeedUpdate ++ ;
return false ;
}
2016-12-26 00:23:31 +00:00
$scope . saveFile = function ( ) {
this . file . $update ( ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2016-12-26 00:23:31 +00:00
}
2017-12-17 14:39:20 +00:00
$scope . inSync = false ;
$scope . syncFiles = function ( ) {
$scope . inSync = true ;
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/sync/exercices/" + $routeParams . exerciceId + "/files" ,
2018-01-06 14:08:05 +00:00
method : "POST"
2017-12-17 14:39:20 +00:00
} ) . then ( function ( response ) {
$scope . inSync = false ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2017-12-17 14:39:20 +00:00
$scope . files = ExerciceFile . query ( { exerciceId : $routeParams . exerciceId } ) ;
if ( response . data )
2020-05-16 01:53:07 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchronizing flags list:' , response . data ) ;
2017-12-17 14:39:20 +00:00
else
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , "Synchronisation de la liste de fichiers terminée avec succès." ) ;
2017-12-17 14:39:20 +00:00
} , function ( response ) {
$scope . inSync = false ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchronizing flags list:' , response . data . errmsg ) ;
2017-12-17 14:39:20 +00:00
} ) ;
} ;
2016-12-26 00:23:31 +00:00
} )
2017-12-17 14:39:20 +00:00
. controller ( "ExerciceHintsController" , function ( $scope , ExerciceHint , $routeParams , $rootScope , $http ) {
2016-12-26 00:23:31 +00:00
$scope . hints = ExerciceHint . query ( { exerciceId : $routeParams . exerciceId } ) ;
2016-12-27 20:08:36 +00:00
$scope . addHint = function ( ) {
$scope . hints . push ( new ExerciceHint ( ) ) ;
}
2016-12-26 00:23:31 +00:00
$scope . deleteHint = function ( ) {
2016-12-27 20:08:36 +00:00
this . hint . $delete ( function ( ) {
2019-07-21 19:55:36 +00:00
$scope . hints = ExerciceHint . query ( { exerciceId : $routeParams . exerciceId } ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2018-01-07 23:17:46 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when trying to delete hint:' , response . data . errmsg ) ;
2016-12-27 20:08:36 +00:00
} ) ;
2016-12-26 00:23:31 +00:00
}
$scope . saveHint = function ( ) {
2016-12-27 20:08:36 +00:00
if ( this . hint . id ) {
this . hint . $update ( ) ;
} else {
this . hint . $save ( { exerciceId : $routeParams . exerciceId } ) ;
}
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2016-12-26 00:23:31 +00:00
}
2017-12-17 14:39:20 +00:00
$scope . inSync = false ;
$scope . syncHints = function ( ) {
$scope . inSync = true ;
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/sync/exercices/" + $routeParams . exerciceId + "/hints" ,
2018-01-06 14:08:05 +00:00
method : "POST"
2017-12-17 14:39:20 +00:00
} ) . then ( function ( response ) {
$scope . inSync = false ;
$scope . hints = ExerciceHint . query ( { exerciceId : $routeParams . exerciceId } ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2017-12-17 14:39:20 +00:00
if ( response . data )
2020-05-16 01:53:07 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchronizing hints list:' , response . data ) ;
2017-12-17 14:39:20 +00:00
else
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , "Synchronisation de la liste d'indices terminée avec succès." ) ;
2017-12-17 14:39:20 +00:00
} , function ( response ) {
$scope . inSync = false ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchronizing hints list:' , response . data . errmsg ) ;
2017-12-17 14:39:20 +00:00
} ) ;
} ;
2016-12-26 00:23:31 +00:00
} )
2020-01-23 13:23:02 +00:00
. controller ( "ExerciceHintDepsController" , function ( $scope , $routeParams , ExerciceHintDeps ) {
$scope . init = function ( hint ) {
$scope . deps = ExerciceHintDeps . query ( { exerciceId : $routeParams . exerciceId , hintId : hint . id } ) ;
}
} )
2018-09-24 08:00:17 +00:00
. controller ( "ExerciceFlagsController" , function ( $scope , ExerciceFlag , $routeParams , $rootScope , $http ) {
$scope . flags = ExerciceFlag . query ( { exerciceId : $routeParams . exerciceId } ) ;
2016-12-26 00:23:31 +00:00
2020-01-28 13:05:00 +00:00
$scope . flags . $promise . then ( function ( flags ) {
flags . forEach ( function ( flag , fid ) {
flags [ fid ] . values = [ '' ] ;
} ) ;
} ) ;
2019-01-21 12:35:09 +00:00
$scope . changeValue = function ( flag ) {
flag . value = undefined ;
flag . show _raw = true ;
}
2018-09-24 08:00:17 +00:00
$scope . addFlag = function ( ) {
$scope . flags . push ( new ExerciceFlag ( ) ) ;
2016-12-27 20:08:36 +00:00
}
2018-09-24 08:00:17 +00:00
$scope . deleteFlag = function ( ) {
this . flag . $delete ( function ( ) {
2019-07-21 19:55:36 +00:00
$scope . flags = ExerciceFlag . query ( { exerciceId : $routeParams . exerciceId } ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2018-01-07 23:17:46 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when trying to delete flag:' , response . data . errmsg ) ;
2016-12-27 20:08:36 +00:00
} ) ;
2016-12-26 00:23:31 +00:00
}
2018-09-24 08:00:17 +00:00
$scope . saveFlag = function ( ) {
if ( this . flag . id ) {
this . flag . $update ( ) ;
2016-12-27 20:08:36 +00:00
} else {
2018-09-24 08:00:17 +00:00
this . flag . $save ( { exerciceId : $routeParams . exerciceId } ) ;
2016-12-27 20:08:36 +00:00
}
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2016-01-22 16:37:29 +00:00
}
2018-12-08 02:13:16 +00:00
$scope . testFlag = function ( flag ) {
2020-01-28 13:05:00 +00:00
if ( flag . values ) {
var val = flag . value ;
treatFlagKey ( flag ) ;
flag . test _str = flag . value ;
flag . value = val ;
}
2018-12-08 02:13:16 +00:00
if ( flag . test _str ) {
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/exercices/" + $routeParams . exerciceId + "/flags/" + flag . id + "/try" ,
2018-12-08 02:13:16 +00:00
data : { "flag" : flag . test _str } ,
method : "POST"
} ) . then ( function ( response ) {
flag . test _str = "" ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , "Flag Ok !" ) ;
2018-12-08 02:13:16 +00:00
} , function ( response ) {
flag . test _str = "" ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs: ' , response . data . errmsg ) ;
2018-12-08 02:13:16 +00:00
} ) ;
}
}
2017-12-17 14:39:20 +00:00
$scope . inSync = false ;
2018-09-24 08:00:17 +00:00
$scope . syncFlags = function ( ) {
2017-12-17 14:39:20 +00:00
$scope . inSync = true ;
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/sync/exercices/" + $routeParams . exerciceId + "/flags" ,
2018-01-06 14:08:05 +00:00
method : "POST"
2017-12-17 14:39:20 +00:00
} ) . then ( function ( response ) {
$scope . inSync = false ;
2018-09-24 08:00:17 +00:00
$scope . flags = ExerciceFlag . query ( { exerciceId : $routeParams . exerciceId } ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2017-12-17 14:39:20 +00:00
if ( response . data )
2020-05-16 01:53:07 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchronizing flags list:' , response . data ) ;
2017-12-17 14:39:20 +00:00
else
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , "Synchronisation de la liste de drapeaux terminée avec succès." ) ;
2017-12-17 14:39:20 +00:00
} , function ( response ) {
$scope . inSync = false ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when synchronizing flags list:' , response . data . errmsg ) ;
2017-12-17 14:39:20 +00:00
} ) ;
} ;
2016-01-22 16:37:29 +00:00
} )
2020-01-28 13:05:00 +00:00
. controller ( "ExerciceFlagChoicesController" , function ( $scope , ExerciceFlagChoices , $routeParams ) {
$scope . choices = ExerciceFlagChoices . query ( { exerciceId : $routeParams . exerciceId , flagId : $scope . flag . id } )
$scope . flag . wantchoices = function ( ) {
$scope . flag . choices = { } ;
$scope . choices . forEach ( function ( choice ) {
$scope . flag . choices [ choice . value ] = choice . label
} )
}
$scope . choices . $promise . then ( function ( choices ) {
if ( $scope . flag . choices _cost == 0 && choices . length > 0 ) {
$scope . flag . wantchoices ( )
}
} )
$scope . addChoice = function ( ) {
$scope . choices . push ( new ExerciceFlagChoices ( ) )
}
$scope . saveChoice = function ( ) {
if ( this . choice . id )
this . choice . $update ( { exerciceId : $routeParams . exerciceId , flagId : this . flag . id } )
else
this . choice . $save ( { exerciceId : $routeParams . exerciceId , flagId : this . flag . id } )
}
$scope . deleteChoice = function ( ) {
if ( this . choice . id )
this . choice . $delete ( { exerciceId : $routeParams . exerciceId , flagId : this . flag . id } , function ( ) {
$scope . choices = ExerciceFlagChoices . query ( { exerciceId : $routeParams . exerciceId , flagId : $scope . flag . id } )
} )
}
} )
2020-01-23 13:23:02 +00:00
. controller ( "ExerciceFlagDepsController" , function ( $scope , $routeParams , ExerciceFlagDeps ) {
$scope . init = function ( flag ) {
$scope . deps = ExerciceFlagDeps . query ( { exerciceId : $routeParams . exerciceId , flagId : flag . id } ) ;
}
} )
2018-12-05 04:03:21 +00:00
. controller ( "ExerciceMCQFlagsController" , function ( $scope , ExerciceMCQFlag , $routeParams , $rootScope ) {
2018-09-24 08:00:17 +00:00
$scope . quiz = ExerciceMCQFlag . query ( { exerciceId : $routeParams . exerciceId } ) ;
2018-06-24 16:12:26 +00:00
$scope . addQuiz = function ( ) {
2018-09-24 08:00:17 +00:00
$scope . quiz . push ( new ExerciceMCQFlag ( ) ) ;
2018-06-24 16:12:26 +00:00
}
$scope . deleteQuiz = function ( ) {
this . q . $delete ( function ( ) {
2019-07-21 19:55:36 +00:00
$scope . quiz = ExerciceMCQFlag . query ( { exerciceId : $routeParams . exerciceId } ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2018-06-24 16:12:26 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when trying to delete flag:' , response . data . errmsg ) ;
2018-06-24 16:12:26 +00:00
} ) ;
}
$scope . saveQuiz = function ( ) {
if ( this . q . id ) {
this . q . $update ( ) ;
} else {
this . q . $save ( { exerciceId : $routeParams . exerciceId } ) ;
}
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2018-06-24 16:12:26 +00:00
}
$scope . addChoice = function ( ) {
this . quiz [ this . qk ] . entries . push ( { label : "" , response : false } )
}
$scope . deleteChoice = function ( ) {
this . quiz [ this . qk ] . entries . splice ( this . quiz [ this . qk ] . entries . indexOf ( this . choice ) , 1 ) ;
}
} )
2020-01-23 13:23:02 +00:00
. controller ( "ExerciceMCQDepsController" , function ( $scope , $routeParams , ExerciceMCQDeps ) {
$scope . init = function ( flag ) {
$scope . deps = ExerciceMCQDeps . query ( { exerciceId : $routeParams . exerciceId , mcqId : flag . id } ) ;
}
} )
2019-01-21 01:54:27 +00:00
. controller ( "TeamsListController" , function ( $scope , $rootScope , Team , $location , $http ) {
2016-01-13 00:22:54 +00:00
$scope . teams = Team . query ( ) ;
2018-01-21 13:07:44 +00:00
$scope . fields = [ "id" , "name" ] ;
2016-01-13 00:22:54 +00:00
2024-03-19 09:32:20 +00:00
$scope . order = [ ] ;
$scope . teams . $promise . then ( function ( teams ) {
teams . forEach ( function ( team ) {
$scope . order . push ( team . id ) ;
} ) ;
} ) ;
2020-01-29 17:18:25 +00:00
$scope . validateSearch = function ( keyEvent ) {
if ( keyEvent . which === 13 ) {
var myTeam = null ;
$scope . teams . forEach ( function ( team ) {
if ( String ( team . name . toLowerCase ( ) ) . indexOf ( $scope . query . toLowerCase ( ) ) >= 0 ) {
if ( myTeam === null )
myTeam = team ;
else
myTeam = false ;
}
} ) ;
if ( myTeam )
$location . url ( "teams/" + myTeam . id ) ;
}
} ;
2021-09-09 09:20:45 +00:00
$scope . genDexCfg = function ( ) {
$http . post ( "api/dex.yaml" ) . then ( function ( ) {
$http . post ( "api/dex-password.tpl" ) . then ( function ( ) {
$scope . addToast ( 'success' , 'Dex config refreshed.' , "Don't forget to reload/reboot frontend host." ) ;
} , function ( response ) {
$scope . addToast ( 'danger' , 'An error occurs when generating dex password tpl:' , response . data . errmsg ) ;
} ) ;
} , function ( response ) {
$scope . addToast ( 'danger' , 'An error occurs when generating dex config:' , response . data . errmsg ) ;
} ) ;
2024-03-23 17:51:53 +00:00
$http . post ( "api/vouch-proxy.yaml" ) . then ( function ( ) {
2024-03-23 17:51:53 +00:00
$scope . addToast ( 'success' , 'VouchProxy config refreshed.' , "Don't forget to reload/reboot frontend host." ) ;
} , function ( response ) {
$scope . addToast ( 'danger' , 'An error occurs when generating VouchProxy config:' , response . data . errmsg ) ;
} ) ;
2021-09-09 09:20:45 +00:00
}
2019-01-21 01:54:27 +00:00
$scope . desactiveTeams = function ( ) {
2021-07-21 21:17:47 +00:00
$http . post ( "api/disableinactiveteams" ) . then ( function ( ) {
2019-01-21 01:54:27 +00:00
$scope . teams = Team . query ( ) ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when disabling inactive teams:' , response . data . errmsg ) ;
2019-01-21 01:54:27 +00:00
} ) ;
}
2016-01-13 00:22:54 +00:00
$scope . show = function ( id ) {
$location . url ( "/teams/" + id ) ;
} ;
2016-01-22 16:37:29 +00:00
} )
2017-04-02 10:43:48 +00:00
. controller ( "TeamMembersController" , function ( $scope , TeamMember ) {
2017-01-28 18:36:28 +00:00
$scope . fields = [ "firstname" , "lastname" , "nickname" , "company" ] ;
2017-04-02 10:43:48 +00:00
if ( $scope . team != null ) {
$scope . members = TeamMember . query ( { teamId : $scope . team . id } ) ;
2017-01-28 18:36:28 +00:00
2017-04-02 10:43:48 +00:00
$scope . newMember = function ( ) {
$scope . members . push ( new TeamMember ( ) ) ;
}
$scope . saveTeamMembers = function ( ) {
if ( this . team . id ) {
TeamMember . save ( { teamId : this . team . id } , $scope . members ) ;
}
}
$scope . removeMember = function ( member ) {
angular . forEach ( $scope . members , function ( m , k ) {
if ( member == m )
$scope . members . splice ( k , 1 ) ;
} ) ;
}
}
2017-01-28 18:36:28 +00:00
} )
2021-09-09 09:20:45 +00:00
. controller ( "TeamController" , function ( $scope , $rootScope , $location , Team , TeamMember , $routeParams , $http ) {
2017-12-26 22:57:16 +00:00
if ( $scope . team && $scope . team . id )
$routeParams . teamId = $scope . team . id ;
2016-10-13 17:52:54 +00:00
$scope . team = Team . get ( { teamId : $routeParams . teamId } ) ;
2021-09-03 15:23:00 +00:00
$scope . fields = [ "name" , "color" , "external_id" ] ;
2017-01-28 18:36:28 +00:00
$scope . saveTeam = function ( ) {
if ( this . team . id ) {
this . team . $update ( ) ;
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2017-01-28 18:36:28 +00:00
} else {
this . team . $save ( function ( ) {
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2017-01-28 18:36:28 +00:00
$location . url ( "/teams/" + $scope . team . id ) ;
} ) ;
}
}
2021-09-09 09:20:45 +00:00
$scope . resetPasswd = function ( team ) {
$http ( {
url : "api/password" ,
method : "POST"
} ) . then ( function ( response ) {
team . password = response . data . password ;
} ) ;
}
2017-01-28 18:36:28 +00:00
$scope . deleteTeam = function ( ) {
2017-11-10 19:38:31 +00:00
backName = this . team . name ;
2020-03-08 11:48:25 +00:00
this . team . $remove ( function ( ) { $scope . addToast ( 'success' , 'Team ' + backName + ' successfully removed.' ) ; $location . url ( "/teams/" ) ; $rootScope . staticFilesNeedUpdate ++ ; } ,
function ( response ) { $scope . addToast ( 'danger' , 'An error occurs during suppression of the team:' , response . data . errmsg ) ; } ) ;
2017-01-28 18:36:28 +00:00
}
$scope . showStats = function ( ) {
$location . url ( "/teams/" + $scope . team . id + "/stats" ) ;
}
2019-01-17 12:51:44 +00:00
$scope . showScore = function ( ) {
$location . url ( "/teams/" + $scope . team . id + "/score" ) ;
}
2016-10-13 17:52:54 +00:00
} )
2019-02-04 18:59:29 +00:00
. controller ( "TeamCertificatesController" , function ( $scope , $rootScope , TeamCertificate , $routeParams , $http ) {
$scope . certificates = TeamCertificate . query ( { teamId : $routeParams . teamId } ) ;
2019-02-05 00:44:41 +00:00
$scope . certificates . $promise . then ( function ( certificates ) {
certificates . forEach ( function ( certificate , cid ) {
certificate . serial = parseInt ( certificate . id ) . toString ( 16 ) ;
} ) ;
} ) ;
2019-02-04 18:59:29 +00:00
$scope . dissociateCertificate = function ( certificate ) {
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/certs/" + certificate . id ,
2019-02-04 18:59:29 +00:00
method : "PUT" ,
data : {
id _team : null
}
} ) . then ( function ( response ) {
2019-02-05 00:44:41 +00:00
$scope . certificates = TeamCertificate . query ( { teamId : $routeParams . teamId } ) . $promise . then ( function ( certificates ) {
certificates . forEach ( function ( certificate , cid ) {
certificate . serial = parseInt ( certificate . id ) . toString ( 16 ) ;
} ) ;
} ) ;
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'success' , 'Certificate successfully dissociated!' ) ;
2019-02-04 18:59:29 +00:00
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when dissociating certiticate:' , response . data . errmsg ) ;
2019-02-04 18:59:29 +00:00
} ) ;
}
} )
. controller ( "TeamAssociationsController" , function ( $scope , $rootScope , TeamAssociation , $routeParams , $http ) {
$scope . associations = TeamAssociation . query ( { teamId : $routeParams . teamId } ) ;
$scope . form = { "newassoc" : "" } ;
$scope . addAssociation = function ( ) {
if ( $scope . form . newassoc ) {
TeamAssociation . save ( { teamId : $scope . team . id , assoc : $scope . form . newassoc } ) . $promise . then (
function ( ) {
$scope . form . newassoc = "" ;
$scope . associations = TeamAssociation . query ( { teamId : $routeParams . teamId } ) ;
} , function ( response ) {
if ( response . data )
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when creating user association: ' , response . data . errmsg ) ;
2019-02-04 18:59:29 +00:00
} ) ;
}
}
$scope . dropAssociation = function ( assoc ) {
TeamAssociation . delete ( { teamId : $routeParams . teamId , assoc : assoc } ) . $promise . then (
function ( ) {
$scope . associations = TeamAssociation . query ( { teamId : $routeParams . teamId } ) ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when removing user association: ' , response . data . errmsg ) ;
2019-02-04 18:59:29 +00:00
} ) ;
}
} )
2017-12-21 20:25:23 +00:00
. controller ( "TeamHistoryController" , function ( $scope , TeamHistory , $routeParams , $http , $rootScope ) {
2017-11-12 23:57:48 +00:00
$scope . history = TeamHistory . query ( { teamId : $routeParams . teamId } ) ;
2019-07-12 17:17:17 +00:00
$scope . updHistory = function ( ) {
var target = {
team _id : parseInt ( $routeParams . teamId ) ,
kind : $ ( "#updHistory" ) . data ( "kind" ) ,
time : $ ( "#updHistory" ) . data ( "time" ) ,
secondary : $ ( "#updHistory" ) . data ( "secondary" ) != "" ? $ ( "#updHistory" ) . data ( "secondary" ) : null ,
coeff : parseFloat ( $ ( '#historycoeff' ) . val ( ) ) ,
} ;
if ( target ) {
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/exercices/" + $ ( "#updHistory" ) . data ( "primary" ) + "/history.json" ,
2019-07-12 17:17:17 +00:00
method : "PATCH" ,
data : target
} ) . then ( function ( response ) {
$rootScope . staticFilesNeedUpdate ++ ;
$scope . history = TeamHistory . query ( { teamId : $routeParams . teamId } ) ;
$ ( '#updHistory' ) . modal ( 'hide' ) ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when updating history item: ' , response . data . errmsg ) ;
2019-07-12 17:17:17 +00:00
} ) ;
}
}
2017-12-21 20:25:23 +00:00
$scope . delHistory = function ( row ) {
$http ( {
2021-07-21 21:17:47 +00:00
url : "api/teams/" + $routeParams . teamId + "/history.json" ,
2017-12-21 20:25:23 +00:00
method : "DELETE" ,
data : row
} ) . then ( function ( response ) {
2018-12-05 05:54:50 +00:00
$rootScope . staticFilesNeedUpdate ++ ;
2017-12-21 20:25:23 +00:00
$scope . history = TeamHistory . query ( { teamId : $routeParams . teamId } ) ;
} , function ( response ) {
2020-03-08 11:48:25 +00:00
$scope . addToast ( 'danger' , 'An error occurs when removing history item: ' , response . data . errmsg ) ;
2017-12-21 20:25:23 +00:00
} ) ;
}
2017-11-12 23:57:48 +00:00
} )
2019-01-17 12:51:44 +00:00
. controller ( "TeamScoreController" , function ( $scope , TeamScore , TeamMy , Exercice , $routeParams ) {
$scope . scores = TeamScore . query ( { teamId : $routeParams . teamId } ) ;
$scope . my = TeamMy . get ( { teamId : $routeParams . teamId } ) ;
$scope . exercices = Exercice . query ( ) ;
} )
2016-10-13 17:52:54 +00:00
. controller ( "TeamStatsController" , function ( $scope , TeamStats , $routeParams ) {
$scope . teamstats = TeamStats . get ( { teamId : $routeParams . teamId } ) ;
$scope . teamstats . $promise . then ( function ( res ) {
solvedByLevelPie ( "#pieLevels" , res . levels ) ;
2017-01-24 01:17:21 +00:00
var themes = [ ] ;
angular . forEach ( res . themes , function ( theme , tid ) {
themes . push ( theme ) ;
} )
solvedByThemesPie ( "#pieThemes" , themes ) ;
2016-10-13 17:52:54 +00:00
} ) ;
} )
2020-01-29 15:01:11 +00:00
. controller ( "TeamsJSONController" , function ( $scope , Teams ) {
$scope . teams = Teams . get ( ) ;
$scope . teams . $promise . then ( function ( teams ) {
$scope . rank = [ ] ;
Object . keys ( teams ) . forEach ( function ( team ) {
$scope . teams [ team ] . id = team ;
$scope . rank . push ( $scope . teams [ team ] ) ;
} )
} ) ;
} )
2016-10-13 17:52:54 +00:00
. controller ( "TeamExercicesController" , function ( $scope , Teams , Themes , TeamMy , Exercice , $routeParams ) {
$scope . teams = Teams . get ( ) ;
$scope . themes = Themes . get ( ) ;
$scope . exercices = Exercice . query ( ) ;
$scope . my = TeamMy . get ( { teamId : $routeParams . teamId } ) ;
$scope . teams . $promise . then ( function ( res ) {
$scope . nb _teams = 0 ;
$scope . nb _reg _teams = Object . keys ( res ) . length ;
angular . forEach ( res , function ( team , tid ) {
if ( team . rank )
$scope . nb _teams += 1 ;
} , 0 ) ;
} ) ;
$scope . my . $promise . then ( function ( res ) {
$scope . solved _exercices = 0 ;
angular . forEach ( res . exercices , function ( exercice , eid ) {
2017-01-16 12:09:31 +00:00
if ( exercice . solved _rank ) {
2016-10-13 17:52:54 +00:00
$scope . solved _exercices += 1 ;
}
} , 0 ) ;
} ) ;
} )
. controller ( "PresenceController" , function ( $scope , TeamPresence , $routeParams ) {
$scope . presence = TeamPresence . query ( { teamId : $routeParams . teamId } ) ;
$scope . presence . $promise . then ( function ( res ) {
2017-04-02 09:38:40 +00:00
presenceCal ( $scope , "#presenceCal" , res ) ;
2016-10-13 17:52:54 +00:00
} ) ;
} ) ;
function solvedByLevelPie ( location , data ) {
2017-12-17 19:46:11 +00:00
var width = d3 . select ( location ) . node ( ) . getBoundingClientRect ( ) . width - parseInt ( d3 . select ( location ) . style ( "padding-right" ) ) - parseInt ( d3 . select ( location ) . style ( "padding-left" ) ) ,
2016-10-13 17:52:54 +00:00
height = d3 . select ( location ) . node ( ) . getBoundingClientRect ( ) . width - 10 ,
radius = Math . min ( width , height ) / 2 ,
innerRadius = 0.1 * radius ;
var color = d3 . scale . ordinal ( )
. range ( [ "#9E0041" , "#C32F4B" , "#E1514B" , "#F47245" , "#FB9F59" , "#FEC574" , "#FAE38C" , "#EAD195" , "#C7E89E" , "#9CD6A4" , "#6CC4A4" , "#4D9DB4" , "#4776B4" , "#5E4EA1" ] ) ;
var pie = d3 . layout . pie ( )
. sort ( null )
. value ( function ( d ) { return d . width ; } ) ;
var arc = d3 . svg . arc ( )
. innerRadius ( innerRadius )
. outerRadius ( function ( d ) {
return ( radius - innerRadius ) * ( d . data . score / 100.0 ) + innerRadius ;
} ) ;
var outlineArc = d3 . svg . arc ( )
. innerRadius ( innerRadius )
. outerRadius ( radius ) ;
var svg = d3 . select ( location ) . append ( "svg" )
. attr ( "width" , width )
. attr ( "height" , height )
. append ( "g" )
. attr ( "transform" , "translate(" + width / 2 + "," + height / 2 + ")" ) ;
data . forEach ( function ( d ) {
d . score = d . solved * 100 / d . total ;
d . width = d . tries + 1 ;
2016-01-13 00:22:54 +00:00
} ) ;
2016-10-13 17:52:54 +00:00
var path = svg . selectAll ( ".solidArc" )
. data ( pie ( data ) )
. enter ( ) . append ( "path" )
. attr ( "fill" , function ( d ) { return color ( d . data . tip ) ; } )
. attr ( "class" , "solidArc" )
. attr ( "stroke" , "gray" )
. attr ( "d" , arc ) ;
var outerPath = svg . selectAll ( ".outlineArc" )
. data ( pie ( data ) )
. enter ( ) . append ( "path" )
. attr ( "fill" , "none" )
. attr ( "stroke" , "gray" )
. attr ( "class" , "outlineArc" )
. attr ( "d" , outlineArc ) ;
var labelArc = d3 . svg . arc ( )
. outerRadius ( 0.8 * radius )
. innerRadius ( 0.8 * radius ) ;
svg . selectAll ( ".labelArc" )
. data ( pie ( data ) )
. enter ( ) . append ( "text" )
. attr ( "transform" , function ( d ) { return "translate(" + labelArc . centroid ( d ) + ")" ; } )
. attr ( "dy" , ".35em" )
. attr ( "text-anchor" , "middle" )
. text ( function ( d ) { return d . data . tip + ": " + d . data . solved + "/" + d . data . total ; } ) ;
svg . selectAll ( ".label2Arc" )
. data ( pie ( data ) )
. enter ( ) . append ( "text" )
. attr ( "transform" , function ( d ) { return "translate(" + arc . centroid ( d ) + ")" ; } )
. attr ( "dy" , ".35em" )
. attr ( "text-anchor" , "middle" )
. text ( function ( d ) { return d . data . tries ; } ) ;
}
function solvedByThemesPie ( location , data ) {
2017-12-17 19:46:11 +00:00
var width = d3 . select ( location ) . node ( ) . getBoundingClientRect ( ) . width - parseInt ( d3 . select ( location ) . style ( "padding-right" ) ) - parseInt ( d3 . select ( location ) . style ( "padding-left" ) ) ,
2016-10-13 17:52:54 +00:00
height = d3 . select ( location ) . node ( ) . getBoundingClientRect ( ) . width ,
radius = Math . min ( width , height ) / 2 ,
innerRadius = 0.1 * radius ;
var color = d3 . scale . ordinal ( )
. range ( [ "#9E0041" , "#C32F4B" , "#E1514B" , "#F47245" , "#FB9F59" , "#FEC574" , "#FAE38C" , "#EAD195" , "#C7E89E" , "#9CD6A4" , "#6CC4A4" , "#4D9DB4" , "#4776B4" , "#5E4EA1" ] ) ;
var pie = d3 . layout . pie ( )
. sort ( null )
. value ( function ( d ) { return d . width ; } ) ;
var arc = d3 . svg . arc ( )
. innerRadius ( innerRadius )
. outerRadius ( function ( d ) {
return ( radius - innerRadius ) * ( d . data . score / 100.0 ) + innerRadius ;
} ) ;
var outlineArc = d3 . svg . arc ( )
. innerRadius ( innerRadius )
. outerRadius ( radius ) ;
var svg = d3 . select ( location ) . append ( "svg" )
. attr ( "width" , width )
. attr ( "height" , height )
. append ( "g" )
. attr ( "transform" , "translate(" + width / 2 + "," + height / 2 + ")" ) ;
data . forEach ( function ( d ) {
d . score = d . solved * 100 / d . total ;
d . width = d . tries + 0.5 ;
} ) ;
var path = svg . selectAll ( ".solidArc" )
. data ( pie ( data ) )
. enter ( ) . append ( "path" )
. attr ( "fill" , function ( d ) { return color ( d . data . tip ) ; } )
. attr ( "class" , "solidArc" )
. attr ( "stroke" , "gray" )
. attr ( "d" , arc ) ;
var outerPath = svg . selectAll ( ".outlineArc" )
. data ( pie ( data ) )
. enter ( ) . append ( "path" )
. attr ( "fill" , "none" )
. attr ( "stroke" , "gray" )
. attr ( "class" , "outlineArc" )
. attr ( "d" , outlineArc ) ;
svg . selectAll ( ".label2Arc" )
. data ( pie ( data ) )
. enter ( ) . append ( "text" )
. attr ( "transform" , function ( d ) { return "translate(" + arc . centroid ( d ) + ")" ; } )
. attr ( "dy" , ".35em" )
. attr ( "text-anchor" , "middle" )
. text ( function ( d ) { return d . data . solved ; } ) ;
var labelArc = d3 . svg . arc ( )
. outerRadius ( 0.8 * radius )
. innerRadius ( 0.8 * radius ) ;
svg . selectAll ( ".labelArc" )
. data ( pie ( data ) )
. enter ( ) . append ( "text" )
. attr ( "transform" , function ( d ) { return "translate(" + labelArc . centroid ( d ) + ")" ; } )
. attr ( "dy" , ".35em" )
. attr ( "text-anchor" , "middle" )
. text ( function ( d ) { return d . data . tip + ": " + d . data . tries ; } ) ;
}
2017-04-02 09:38:40 +00:00
function presenceCal ( scope , location , data ) {
2016-10-13 17:52:54 +00:00
var width = d3 . select ( location ) . node ( ) . getBoundingClientRect ( ) . width ,
height = 80 ,
cellSize = 17 ; // cell size
var percent = d3 . format ( ".1%" ) ,
format = d3 . time . format ( "%H:%M" ) ;
var color = d3 . scale . quantize ( )
. domain ( [ 0 , 16 ] )
. range ( d3 . range ( 8 ) . map ( function ( d ) { return "q" + d + "-8" ; } ) ) ;
var svg = d3 . select ( location ) . selectAll ( "svg" )
2018-12-08 02:35:52 +00:00
. data ( d3 . range ( scope . settings . start , scope . time . start + ( scope . settings . start % 86400000 + scope . settings . end - scope . settings . start ) , 86400000 ) . map ( function ( t ) { return new Date ( t ) ; } ) )
2016-10-13 17:52:54 +00:00
. enter ( ) . append ( "svg" )
. attr ( "width" , width )
. attr ( "height" , height )
. attr ( "class" , "RdYlGn" )
. append ( "g" )
. attr ( "transform" , "translate(" + ( ( width - cellSize * 24 ) / 2 ) + "," + ( height - cellSize * 4 - 1 ) + ")" ) ;
svg . append ( "text" )
. attr ( "transform" , "translate(-6," + cellSize * 2.6 + ")rotate(-90)" )
. style ( "text-anchor" , "middle" )
2017-04-02 09:38:40 +00:00
. text ( function ( d ) { return d . getDate ( ) + "-" + ( d . getMonth ( ) + 1 ) ; } ) ;
2016-10-13 17:52:54 +00:00
var rect = svg . selectAll ( ".quarter" )
2017-04-02 09:38:40 +00:00
. data ( function ( d ) { return d3 . time . minutes ( new Date ( d . getFullYear ( ) , d . getMonth ( ) , d . getDate ( ) , 0 ) , new Date ( d . getFullYear ( ) , d . getMonth ( ) , d . getDate ( ) , 23 ) , 15 ) ; } )
2016-10-13 17:52:54 +00:00
. enter ( ) . append ( "rect" )
. attr ( "width" , cellSize )
. attr ( "height" , cellSize )
2017-04-02 09:38:40 +00:00
. attr ( "transform" , function ( d ) { return "translate(" + ( d . getHours ( ) * cellSize ) + "," + ( d . getMinutes ( ) / 15 * cellSize ) + ")" ; } )
2018-12-08 02:35:52 +00:00
. attr ( "class" , function ( d ) { if ( d >= scope . settings . start && d < scope . settings . start + scope . settings . end - scope . settings . start ) return color ( data . reduce ( function ( prev , cur ) {
2016-10-13 17:52:54 +00:00
cur = new Date ( cur ) . getTime ( ) ;
dv = d . getTime ( ) ;
return prev + ( ( dv <= cur && cur < dv + 15 * 60000 ) ? 1 : 0 ) ;
} , 0 ) ) ; } ) ;
}