@@ -1305,8 +1305,19 @@ function initScoreboardSubmissions() {
13051305 } ) ;
13061306}
13071307
1308+ const enableButton = ( btn , url ) => {
1309+ btn . href = url ;
1310+ btn . classList . remove ( 'disabled' ) ;
1311+ btn . ariaDisabled = false ;
1312+ } ;
1313+
1314+ const disableButton = ( btn ) => {
1315+ btn . classList . add ( 'disabled' ) ;
1316+ btn . ariaDisabled = true ;
1317+ }
1318+
13081319const editors = [ ] ;
1309- function initDiffEditor ( editorId ) {
1320+ function initDiffEditor ( editorId , deletedFiles ) {
13101321 const wrapper = $ ( `#${ editorId } -wrapper` ) ;
13111322
13121323 const initialTag = getDiffTag ( ) ;
@@ -1339,14 +1350,14 @@ function initDiffEditor(editorId) {
13391350 if ( rank ) {
13401351 let url = new URL ( download . href ) ;
13411352 url . searchParams . set ( "fetch" , rank ) ;
1342- download . href = url ;
1353+ enableButton ( download , url ) ;
13431354
13441355 url = new URL ( edit . href ) ;
13451356 url . searchParams . set ( "rank" , rank ) ;
1346- edit . href = url ;
1357+ enableButton ( edit , url ) ;
13471358 } else {
1348- download . href = "#" ;
1349- edit . href = "#" ;
1359+ disableButton ( download ) ;
1360+ disableButton ( edit ) ;
13501361 }
13511362 } ;
13521363 wrapper . find ( ".nav" ) . on ( 'show.bs.tab' , ( e ) => {
@@ -1365,37 +1376,6 @@ function initDiffEditor(editorId) {
13651376 let s = select [ 0 ] ;
13661377 return s . options [ s . selectedIndex ] . value ;
13671378 } ,
1368- 'updateIcon' : ( rank , icon ) => {
1369- const element = wrapper . find ( ".nav-link[data-rank]" ) [ rank ] . querySelector ( '.fa-fw' ) ;
1370- element . className = 'fas fa-fw fa-' + icon ;
1371- } ,
1372- 'renamedFrom' : ( rank , oldName ) => {
1373- const navItem = wrapper . find ( ".nav-link[data-rank]" ) [ rank ] ;
1374- let renamed = navItem . querySelector ( '.renamed' ) ;
1375- let arrow = navItem . querySelector ( '.fa-arrow-right' ) ;
1376- if ( oldName === undefined ) {
1377- if ( renamed ) {
1378- navItem . removeChild ( renamed ) ;
1379- }
1380- if ( arrow ) {
1381- navItem . removeChild ( arrow ) ;
1382- }
1383- return ;
1384- }
1385-
1386- if ( ! renamed ) {
1387- renamed = document . createElement ( 'span' ) ;
1388- renamed . className = 'renamed' ;
1389- navItem . insertBefore ( renamed , navItem . childNodes [ 1 ] ) ;
1390- }
1391- renamed . innerText = ` ${ oldName } ` ;
1392-
1393- if ( ! arrow ) {
1394- arrow = document . createElement ( 'i' ) ;
1395- arrow . className = 'fas fa-arrow-right' ;
1396- navItem . insertBefore ( arrow , navItem . childNodes [ 2 ] ) ;
1397- }
1398- } ,
13991379 'onDiffModeChange' : ( f ) => {
14001380 radios . change ( ( e ) => {
14011381 const diffMode = e . target . value ;
@@ -1404,8 +1384,8 @@ function initDiffEditor(editorId) {
14041384 } ,
14051385 'onDiffSelectChange' : ( f ) => {
14061386 select . change ( ( e ) => {
1407- const submitId = e . target . value ;
1408- const noDiff = submitId === "" ;
1387+ const noDiff = e . target . value === "" ;
1388+ const submitId = parseInt ( e . target . value ) ;
14091389 f ( submitId , noDiff ) ;
14101390 } ) ;
14111391 }
@@ -1427,15 +1407,14 @@ function initDiffEditor(editorId) {
14271407 if ( selected && selected . dataset . tag ) {
14281408 setDiffTag ( selected . dataset . tag ) ;
14291409 }
1430-
1431- // TODO: add tab panes for deleted source files.
14321410 } ;
1433- updateSelect ( select [ 0 ] . value , select [ 0 ] . value === "" ) ;
1411+ updateSelect ( parseInt ( select [ 0 ] . value ) , select [ 0 ] . value === "" ) ;
14341412 editor . onDiffSelectChange ( updateSelect ) ;
14351413}
14361414
14371415function initDiffEditorTab ( editorId , diffId , rank , models , modifiedModel ) {
14381416 const empty = monaco . editor . getModel ( monaco . Uri . file ( "empty" ) ) ?? monaco . editor . createModel ( "" , undefined , monaco . Uri . file ( "empty" ) ) ;
1417+ const navItem = document . getElementById ( `${ diffId } -link` ) ;
14391418
14401419 const diffEditor = monaco . editor . createDiffEditor (
14411420 document . getElementById ( diffId ) , {
@@ -1457,19 +1436,52 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
14571436 } ;
14581437 editors [ editorId ] . onDiffModeChange ( updateMode ) ;
14591438
1439+ const renamedFrom = ( oldName ) => {
1440+ let renamed = navItem . querySelector ( '.renamed' ) ;
1441+ let arrow = navItem . querySelector ( '.fa-arrow-right' ) ;
1442+ if ( oldName === undefined ) {
1443+ if ( renamed ) {
1444+ navItem . removeChild ( renamed ) ;
1445+ }
1446+ if ( arrow ) {
1447+ navItem . removeChild ( arrow ) ;
1448+ }
1449+ return ;
1450+ }
1451+
1452+ if ( ! renamed ) {
1453+ renamed = document . createElement ( 'span' ) ;
1454+ renamed . className = 'renamed' ;
1455+ navItem . insertBefore ( renamed , navItem . childNodes [ 1 ] ) ;
1456+ }
1457+ renamed . innerText = ` ${ oldName } ` ;
1458+
1459+ if ( ! arrow ) {
1460+ arrow = document . createElement ( 'i' ) ;
1461+ arrow . className = 'fas fa-arrow-right' ;
1462+ navItem . insertBefore ( arrow , navItem . childNodes [ 2 ] ) ;
1463+ }
1464+ } ;
1465+
14601466 const updateSelect = ( submitId , noDiff ) => {
1467+ const exists = submitId in models ;
1468+ if ( rank === undefined ) {
1469+ document . getElementById ( diffId ) . parentElement . style . display = exists ? 'block' : 'none' ;
1470+ navItem . style . display = exists ? 'block' : 'none' ;
1471+ if ( ! exists ) return ;
1472+ }
1473+
14611474 const model = models [ submitId ] ??= { 'model' : empty } ;
14621475 if ( ! noDiff ) {
14631476 if ( ! model [ 'model' ] ) {
1464- // TODO: show source code instead of diff to empty file?
14651477 model [ 'model' ] = monaco . editor . createModel ( model [ 'source' ] , undefined , monaco . Uri . file ( "test/" + submitId + "/" + model [ 'filename' ] ) ) ;
14661478 }
14671479 }
14681480
14691481 if ( noDiff || ! model [ 'renamedFrom' ] ) {
1470- editors [ editorId ] . renamedFrom ( rank , undefined ) ;
1482+ renamedFrom ( undefined ) ;
14711483 } else {
1472- editors [ editorId ] . renamedFrom ( rank , model [ 'renamedFrom' ] ) ;
1484+ renamedFrom ( model [ 'renamedFrom' ] ) ;
14731485 }
14741486
14751487 diffEditor . updateOptions ( {
@@ -1503,19 +1515,24 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
15031515 updateSelect ( editors [ editorId ] . getDiffSelection ( ) , editors [ editorId ] . getDiffSelection ( ) === "" ) ;
15041516
15051517 const updateIcon = ( ) => {
1518+ if ( rank === undefined ) return ;
1519+ const update = ( icon ) => {
1520+ const element = navItem . querySelector ( '.fa-fw' ) ;
1521+ element . className = 'fas fa-fw fa-' + icon ;
1522+ } ;
15061523 const noDiff = editors [ editorId ] . getDiffSelection ( ) === "" ;
15071524 if ( noDiff ) {
1508- editors [ editorId ] . updateIcon ( rank , 'file' ) ;
1525+ update ( 'file' ) ;
15091526 return ;
15101527 }
15111528
15121529 const lineChanges = diffEditor . getLineChanges ( ) ;
15131530 if ( diffEditor . getModel ( ) . original == empty ) {
1514- editors [ editorId ] . updateIcon ( rank , 'file-circle-plus' ) ;
1531+ update ( 'file-circle-plus' ) ;
15151532 } else if ( lineChanges !== null && lineChanges . length > 0 ) {
1516- editors [ editorId ] . updateIcon ( rank , 'file-circle-exclamation' ) ;
1533+ update ( 'file-circle-exclamation' ) ;
15171534 } else {
1518- editors [ editorId ] . updateIcon ( rank , 'file-circle-check' ) ;
1535+ update ( 'file-circle-check' ) ;
15191536 }
15201537 }
15211538 diffEditor . onDidUpdateDiff ( updateIcon ) ;
0 commit comments