@@ -1297,8 +1297,19 @@ function initScoreboardSubmissions() {
12971297 } ) ;
12981298}
12991299
1300+ const enableButton = ( btn , url ) => {
1301+ btn . href = url ;
1302+ btn . classList . remove ( 'disabled' ) ;
1303+ btn . ariaDisabled = false ;
1304+ } ;
1305+
1306+ const disableButton = ( btn ) => {
1307+ btn . classList . add ( 'disabled' ) ;
1308+ btn . ariaDisabled = true ;
1309+ }
1310+
13001311const editors = [ ] ;
1301- function initDiffEditor ( editorId ) {
1312+ function initDiffEditor ( editorId , deletedFiles ) {
13021313 const wrapper = $ ( `#${ editorId } -wrapper` ) ;
13031314
13041315 const initialTag = getDiffTag ( ) ;
@@ -1332,14 +1343,14 @@ function initDiffEditor(editorId) {
13321343 if ( rank ) {
13331344 let url = new URL ( download . href ) ;
13341345 url . searchParams . set ( "fetch" , rank ) ;
1335- download . href = url ;
1346+ enableButton ( download , url ) ;
13361347
13371348 url = new URL ( edit . href ) ;
13381349 url . searchParams . set ( "rank" , rank ) ;
1339- edit . href = url ;
1350+ enableButton ( edit , url ) ;
13401351 } else {
1341- download . href = "#" ;
1342- edit . href = "#" ;
1352+ disableButton ( download ) ;
1353+ disableButton ( edit ) ;
13431354 }
13441355 } ;
13451356 wrapper . find ( ".nav" ) . on ( 'show.bs.tab' , ( e ) => {
@@ -1358,37 +1369,6 @@ function initDiffEditor(editorId) {
13581369 let s = select [ 0 ] ;
13591370 return s . options [ s . selectedIndex ] . value ;
13601371 } ,
1361- 'updateIcon' : ( rank , icon ) => {
1362- const element = wrapper . find ( ".nav-link[data-rank]" ) [ rank ] . querySelector ( '.fa-fw' ) ;
1363- element . className = 'fas fa-fw fa-' + icon ;
1364- } ,
1365- 'renamedFrom' : ( rank , oldName ) => {
1366- const navItem = wrapper . find ( ".nav-link[data-rank]" ) [ rank ] ;
1367- let renamedFromName = navItem . querySelector ( '.renamed' ) ;
1368- let arrow = navItem . querySelector ( '.fa-arrow-right' ) ;
1369- if ( oldName === undefined ) {
1370- if ( renamedFromName ) {
1371- navItem . removeChild ( renamedFromName ) ;
1372- }
1373- if ( arrow ) {
1374- navItem . removeChild ( arrow ) ;
1375- }
1376- return ;
1377- }
1378-
1379- if ( ! renamedFromName ) {
1380- renamedFromName = document . createElement ( 'span' ) ;
1381- renamedFromName . className = 'renamed' ;
1382- navItem . insertBefore ( renamedFromName , navItem . childNodes [ 1 ] ) ;
1383- }
1384- renamedFromName . innerText = ` ${ oldName } ` ;
1385-
1386- if ( ! arrow ) {
1387- arrow = document . createElement ( 'i' ) ;
1388- arrow . className = 'fas fa-arrow-right' ;
1389- navItem . insertBefore ( arrow , navItem . childNodes [ 2 ] ) ;
1390- }
1391- } ,
13921372 'onDiffModeChange' : ( f ) => {
13931373 radios . change ( ( e ) => {
13941374 const diffMode = e . target . value ;
@@ -1397,8 +1377,8 @@ function initDiffEditor(editorId) {
13971377 } ,
13981378 'onDiffSelectChange' : ( f ) => {
13991379 select . change ( ( e ) => {
1400- const submitId = e . target . value ;
1401- const noDiff = submitId === "" ;
1380+ const noDiff = e . target . value === "" ;
1381+ const submitId = parseInt ( e . target . value ) ;
14021382 f ( submitId , noDiff ) ;
14031383 } ) ;
14041384 }
@@ -1420,15 +1400,14 @@ function initDiffEditor(editorId) {
14201400 if ( selected && selected . dataset . tag ) {
14211401 setDiffTag ( selected . dataset . tag ) ;
14221402 }
1423-
1424- // TODO: add tab panes for deleted source files.
14251403 } ;
1426- updateSelect ( select [ 0 ] . value , select [ 0 ] . value === "" ) ;
1404+ updateSelect ( parseInt ( select [ 0 ] . value ) , select [ 0 ] . value === "" ) ;
14271405 editor . onDiffSelectChange ( updateSelect ) ;
14281406}
14291407
14301408function initDiffEditorTab ( editorId , diffId , rank , models , modifiedModel ) {
14311409 const empty = monaco . editor . getModel ( monaco . Uri . file ( "empty" ) ) ?? monaco . editor . createModel ( "" , undefined , monaco . Uri . file ( "empty" ) ) ;
1410+ const navItem = document . getElementById ( `${ diffId } -link` ) ;
14321411
14331412 const diffEditor = monaco . editor . createDiffEditor (
14341413 document . getElementById ( diffId ) , {
@@ -1450,19 +1429,52 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
14501429 } ;
14511430 editors [ editorId ] . onDiffModeChange ( updateMode ) ;
14521431
1432+ const renamedFrom = ( oldName ) => {
1433+ let renamedFromName = navItem . querySelector ( '.renamed' ) ;
1434+ let arrow = navItem . querySelector ( '.fa-arrow-right' ) ;
1435+ if ( oldName === undefined ) {
1436+ if ( renamedFromName ) {
1437+ navItem . removeChild ( renamedFromName ) ;
1438+ }
1439+ if ( arrow ) {
1440+ navItem . removeChild ( arrow ) ;
1441+ }
1442+ return ;
1443+ }
1444+
1445+ if ( ! renamedFromName ) {
1446+ renamedFromName = document . createElement ( 'span' ) ;
1447+ renamedFromName . className = 'renamed' ;
1448+ navItem . insertBefore ( renamedFromName , navItem . childNodes [ 1 ] ) ;
1449+ }
1450+ renamedFromName . innerText = ` ${ oldName } ` ;
1451+
1452+ if ( ! arrow ) {
1453+ arrow = document . createElement ( 'i' ) ;
1454+ arrow . className = 'fas fa-arrow-right' ;
1455+ navItem . insertBefore ( arrow , navItem . childNodes [ 2 ] ) ;
1456+ }
1457+ } ;
1458+
14531459 const updateSelect = ( submitId , noDiff ) => {
1460+ const exists = submitId in models ;
1461+ if ( rank === undefined ) {
1462+ document . getElementById ( diffId ) . parentElement . style . display = exists ? 'block' : 'none' ;
1463+ navItem . style . display = exists ? 'block' : 'none' ;
1464+ if ( ! exists ) return ;
1465+ }
1466+
14541467 const model = models [ submitId ] ??= { 'model' : empty } ;
14551468 if ( ! noDiff ) {
14561469 if ( ! model [ 'model' ] ) {
1457- // TODO: show source code instead of diff to empty file?
14581470 model [ 'model' ] = monaco . editor . createModel ( model [ 'source' ] , undefined , monaco . Uri . file ( "test/" + submitId + "/" + model [ 'filename' ] ) ) ;
14591471 }
14601472 }
14611473
14621474 if ( noDiff || ! model [ 'renamedFrom' ] ) {
1463- editors [ editorId ] . renamedFrom ( rank , undefined ) ;
1475+ renamedFrom ( undefined ) ;
14641476 } else {
1465- editors [ editorId ] . renamedFrom ( rank , model [ 'renamedFrom' ] ) ;
1477+ renamedFrom ( model [ 'renamedFrom' ] ) ;
14661478 }
14671479
14681480 diffEditor . updateOptions ( {
@@ -1496,19 +1508,24 @@ function initDiffEditorTab(editorId, diffId, rank, models, modifiedModel) {
14961508 updateSelect ( editors [ editorId ] . getDiffSelection ( ) , editors [ editorId ] . getDiffSelection ( ) === "" ) ;
14971509
14981510 const updateIcon = ( ) => {
1511+ if ( rank === undefined ) return ;
1512+ const update = ( icon ) => {
1513+ const element = navItem . querySelector ( '.fa-fw' ) ;
1514+ element . className = 'fas fa-fw fa-' + icon ;
1515+ } ;
14991516 const noDiff = editors [ editorId ] . getDiffSelection ( ) === "" ;
15001517 if ( noDiff ) {
1501- editors [ editorId ] . updateIcon ( rank , 'file' ) ;
1518+ update ( 'file' ) ;
15021519 return ;
15031520 }
15041521
15051522 const lineChanges = diffEditor . getLineChanges ( ) ;
15061523 if ( diffEditor . getModel ( ) . original == empty ) {
1507- editors [ editorId ] . updateIcon ( rank , 'file-circle-plus' ) ;
1524+ update ( 'file-circle-plus' ) ;
15081525 } else if ( lineChanges !== null && lineChanges . length > 0 ) {
1509- editors [ editorId ] . updateIcon ( rank , 'file-circle-exclamation' ) ;
1526+ update ( 'file-circle-exclamation' ) ;
15101527 } else {
1511- editors [ editorId ] . updateIcon ( rank , 'file-circle-check' ) ;
1528+ update ( 'file-circle-check' ) ;
15121529 }
15131530 }
15141531 diffEditor . onDidUpdateDiff ( updateIcon ) ;
0 commit comments