5656 .paramType {
5757 font-style : italic;
5858 }
59+
60+ .filePrev {
61+ color : # DDDD00 ;
62+ }
63+ .methodPrev {
64+ color : # DDDD00 ;
65+ }
5966 </ style >
6067
6168
6269 < main >
6370
64- < h1 > Classes < select id ="branch " onchange ="setBranch(this.value) "> </ select > </ h1 >
71+ < h1 > Classes < select id ="branch " onchange ="setBranch(this.value) "> </ select > (Compare to Prev Branch: < select id =" prevbranch " onchange =" setPrevBranch(this.value) " > </ select > ) < button onclick =" showChanges() " > Show New/Changes Only </ button > </ h1 >
6572 < div id ="classContainer "> </ div >
6673
6774
6875 < div style ="display: none ">
6976 < div id ="fileTemplate ">
7077 < div >
71- < h2 class ="fileName " onclick ="showClass(event.target) "> </ h2 >
78+ < h2 class ="fileHeader " onclick ="showClass(event.target) "> < span class =" fileName " > </ span > < span class =" filePrev " > </ span > </ h2 >
7279 < div class ="fileContent " style ="display: none "> None</ div >
7380 </ div >
7481 </ div >
@@ -86,6 +93,7 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
8693 < div >
8794 < span class ="methodName "> </ span > (< span class ="methodParams "> </ span > ) -> < span class ="methodReturn "> </ span >
8895 </ div >
96+ < div class ="methodPrev "> </ div >
8997 < div class ="methodDoc "> </ div >
9098 </ div >
9199 </ div >
@@ -100,6 +108,7 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
100108 < script >
101109
102110 let currentBranch = 'master' ;
111+ let prevBranch = '' ;
103112
104113 const container = document . getElementById ( 'classContainer' ) ;
105114 const fileTemplate = document . getElementById ( 'fileTemplate' ) . firstElementChild ;
@@ -143,8 +152,9 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
143152 'void' : [ 'None' ]
144153 } ;
145154
146- let mapDict = { } ;
155+ // let mapDict = {};
147156 let classKeys = [ ] ;
157+ let classKeysPrev = [ ] ;
148158
149159
150160 function showKritaType ( typeItem ) {
@@ -181,15 +191,26 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
181191 . then ( function ( content ) {
182192
183193 let select = document . getElementById ( 'branch' ) ;
194+ let prevselect = document . getElementById ( 'prevbranch' ) ;
195+
196+
184197
185198 content . unshift ( { name :'master' } ) ;
186199
187200 content . forEach ( function ( branch ) {
188201 let opt = document . createElement ( 'option' ) ;
189202 opt . value = branch . name ;
190203 opt . textContent = branch . name ;
204+
205+
206+
207+ prevselect . appendChild ( opt . cloneNode ( true ) ) ;
191208 select . appendChild ( opt ) ;
209+
192210
211+
212+
213+
193214 } ) ;
194215
195216
@@ -203,10 +224,22 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
203224 }
204225 currentBranch = branch ;
205226
227+
228+
206229 init ( ) ;
207230
208231 }
209232
233+ function setPrevBranch ( branch ) {
234+ while ( child = container . firstChild ) {
235+ container . removeChild ( child ) ;
236+ }
237+ prevBranch = branch ;
238+
239+
240+ init ( ) ;
241+ }
242+
210243
211244 function convertType ( vtype , param = true ) {
212245 const keys = Object . keys ( mapTypes ) ;
@@ -242,31 +275,53 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
242275 const url = 'https://invent.kde.org/api/v4/projects/graphics%2Fkrita/repository/files/libs%2Flibkis%2FCMakeLists.txt/raw?ref=' + currentBranch ;
243276
244277 fetch ( url )
245- . then ( function ( response ) { return response . text ( ) } )
278+ . then ( function ( response ) {
279+
280+ if ( currentBranch != prevBranch && prevBranch != '' ) {
281+
282+ return fetch ( 'https://invent.kde.org/api/v4/projects/graphics%2Fkrita/repository/files/libs%2Flibkis%2FCMakeLists.txt/raw?ref=' + prevBranch )
283+ . then ( function ( prevresponse ) { return Promise . all ( [ response . text ( ) , prevresponse . text ( ) ] ) } )
284+
285+ } else {
286+
287+ return response . text ( )
288+ }
289+
290+ } )
246291 . then ( function ( content ) {
247292
293+ if ( ! Array . isArray ( content ) ) content = [ content ]
294+
248295
249296
250297 const regexp = new RegExp ( String . raw `\s*(.+?)\.cpp` , 'g' ) ;
251298 let matchList = [ ] ;
299+ let matchListPrev = [ ] ;
252300 let match ;
253301
254302
255- while ( ( match = regexp . exec ( content ) ) !== null ) {
303+ while ( ( match = regexp . exec ( content [ 0 ] ) ) !== null ) {
256304 if ( match [ 1 ] !== 'LibKisUtils' ) {
257305 matchList . push ( match [ 1 ] ) ;
258306 }
259307 }
260308 classKeys = matchList ;
261- callback ( matchList ) ;
309+ while ( ( match = regexp . exec ( content [ 1 ] ) ) !== null ) {
310+ if ( match [ 1 ] !== 'LibKisUtils' ) {
311+ matchListPrev . push ( match [ 1 ] ) ;
312+ }
313+ }
314+ classKeysPrev = matchListPrev ;
315+
316+ callback ( matchList , matchListPrev ) ;
262317
263318
264319 } ) ;
265320
266321 }
267322
268323 function classData ( className , url , callback ) {
269-
324+ let mapDict2 = { }
270325 fetch ( url )
271326 . then ( function ( response ) { return response . text ( ) } )
272327 . then ( function ( content ) {
@@ -278,13 +333,14 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
278333 const matchFile = content . match ( regexFile ) ;
279334 content = content . replace ( regexFile , '' ) ;
280335
336+
281337
282338 if ( matchFile ) {
283339 const modName = matchFile [ 2 ] ;
284340 let docContent = matchFile [ 1 ] ? matchFile [ 1 ] :'' ;
285341
286342
287- mapDict [ modName ] = { 'doc' : getDoc ( docContent ) , 'methods' :{ } , 'declare' :[ ] , 'parent' :matchFile [ 3 ] } ;
343+ mapDict2 [ modName ] = { 'doc' : getDoc ( docContent ) , 'methods' :{ } , 'declare' :[ ] , 'parent' :matchFile [ 3 ] } ;
288344 let i = 0 ;
289345 //mapDict[modName]['declare']={};
290346 //console.log("cont1",content);
@@ -341,14 +397,14 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
341397 }
342398
343399 if ( methName == modName ) {
344- mapDict [ modName ] [ 'declare' ] . push ( {
400+ mapDict2 [ modName ] [ 'declare' ] . push ( {
345401 'doc' : docMethod ,
346402 'return' : matchMethod . groups . cname ? className :matchMethod . groups . type ,
347403 'params' : params ,
348404 'access' : methodAccess . trim ( )
349405 } ) ;
350406 } else {
351- mapDict [ modName ] [ 'methods' ] [ methName ] = {
407+ mapDict2 [ modName ] [ 'methods' ] [ methName ] = {
352408 'name' : methName ,
353409 'doc' :docMethod ,
354410 'return' : matchMethod . groups . type . trim ( ) ,
@@ -373,7 +429,7 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
373429
374430 //console.log("cont",content);
375431
376- callback ( ) ;
432+ callback ( className , mapDict2 ) ;
377433 }
378434
379435
@@ -387,9 +443,9 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
387443
388444
389445
390- function showClass ( target ) {
446+ function showClass ( target , nohash ) {
391447 if ( target . className != 'fileName' ) return ;
392- fileItem = target . parentNode ;
448+ fileItem = target . parentNode . parentNode ;
393449 console . log ( fileItem . id ) ;
394450
395451 let fileContent = fileItem . getElementsByClassName ( 'fileContent' ) [ 0 ] ;
@@ -398,34 +454,87 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
398454 let child ;
399455
400456 while ( child = fileContent . firstChild ) {
457+
401458 fileContent . removeChild ( child ) ;
402459 }
403460
404-
405- classData ( fileItem . id , 'https://invent.kde.org/api/v4/projects/graphics%2Fkrita/repository/files/libs%2Flibkis%2F' + fileItem . id + '.h/raw?ref=' + currentBranch , function ( ) {
461+
462+ classData ( fileItem . id , 'https://invent.kde.org/api/v4/projects/graphics%2Fkrita/repository/files/libs%2Flibkis%2F' + fileItem . id + '.h/raw?ref=' + currentBranch , async function ( className , data ) {
463+ console . log ( "loaded" , className )
464+ let prevMapDict = { }
465+
466+ if ( prevBranch != '' && currentBranch !== prevBranch && classKeysPrev . indexOf ( className ) !== - 1 ) {
467+ prevMapDict = await new Promise ( function ( resolve ) {
468+ classData ( className , 'https://invent.kde.org/api/v4/projects/graphics%2Fkrita/repository/files/libs%2Flibkis%2F' + className + '.h/raw?ref=' + prevBranch , async function ( prevClass , prevData ) {
469+
470+ resolve ( prevData )
471+
472+ } )
473+
474+ } )
475+
476+
477+ }
478+
406479
480+
481+ let mapDict = data
482+
407483
408484
409485 let classItem = classTemplate . cloneNode ( true ) ;
410486
411- classItem . getElementsByClassName ( 'classDoc' ) [ 0 ] . innerHTML = mapDict [ fileItem . id ] . doc ;
487+ classItem . getElementsByClassName ( 'classDoc' ) [ 0 ] . innerHTML = mapDict [ className ] . doc ;
412488
413- if ( mapDict [ fileItem . id ] . parent !== '' ) classItem . getElementsByClassName ( 'classParent' ) [ 0 ] . innerHTML = 'Inherits from ' + convertType ( mapDict [ fileItem . id ] . parent ) ;
489+ if ( mapDict [ className ] . parent !== '' ) classItem . getElementsByClassName ( 'classParent' ) [ 0 ] . innerHTML = 'Inherits from ' + convertType ( mapDict [ className ] . parent ) ;
414490
415491 fileContent . appendChild ( classItem ) ;
416492
417- methodList = classItem . getElementsByClassName ( 'classMethods' ) [ 0 ] ;
493+ let methodList = classItem . getElementsByClassName ( 'classMethods' ) [ 0 ] ;
494+
418495
419496
420497
421- //console.log('C', mapDict);
422498
423- let methods = mapDict [ fileItem . id ] . methods ;
499+ let methods = mapDict [ className ] . methods ;
500+
424501
425502
426- Object . keys ( methods ) . forEach ( function ( key ) {
503+ Object . keys ( methods ) . sort ( ) . forEach ( function ( key ) {
427504 let methodItem = methodTemplate . cloneNode ( true ) ;
428505
506+ if ( prevMapDict [ className ] ) {
507+ if ( ! prevMapDict [ className ] . methods [ key ] ) {
508+ methodItem . getElementsByClassName ( 'methodPrev' ) [ 0 ] . textContent = "(NEW)"
509+ methodItem . getElementsByClassName ( 'methodPrev' ) [ 0 ] . parentElement . classList . add ( 'newMethod' )
510+ document . getElementById ( className ) . classList . add ( 'changedClass' )
511+ document . getElementById ( className ) . classList . remove ( 'oldClass' )
512+ } else if ( JSON . stringify ( prevMapDict [ className ] . methods [ key ] . params ) != JSON . stringify ( methods [ key ] . params ) ) {
513+
514+
515+ let changeText = "(CHANGED) old = "
516+ prevMapDict [ className ] . methods [ key ] . params . forEach ( function ( param , i ) {
517+ changeText += ( i > 0 ? ', ' :'' ) + param . name + ": "
518+ changeText += convertType ( param . type ) ;
519+
520+ if ( param . optional != '' ) {
521+ changeText += ' = ' + param . optional ;
522+ }
523+
524+
525+ } ) ;
526+
527+ methodItem . getElementsByClassName ( 'methodPrev' ) [ 0 ] . textContent = changeText
528+ methodItem . getElementsByClassName ( 'methodPrev' ) [ 0 ] . parentNode . classList . add ( 'changedMethod' )
529+ document . getElementById ( className ) . classList . add ( 'changedClass' )
530+ document . getElementById ( className ) . classList . remove ( 'oldClass' )
531+ } else {
532+ methodItem . getElementsByClassName ( 'methodPrev' ) [ 0 ] . parentNode . classList . add ( 'oldMethod' )
533+ if ( nohash ) return
534+
535+ }
536+ }
537+
429538 methodItem . getElementsByClassName ( 'methodName' ) [ 0 ] . textContent = methods [ key ] . name ;
430539 methodItem . getElementsByClassName ( 'methodDoc' ) [ 0 ] . innerHTML = methods [ key ] . doc ;
431540 methodItem . getElementsByClassName ( 'methodReturn' ) [ 0 ] . innerHTML = convertType ( methods [ key ] . return , false ) + ( methods [ key ] . return . indexOf ( 'static' ) > - 1 ? ' [static]' :'' ) + ( methods [ key ] . access . indexOf ( 'private' ) > - 1 ? ' [private]' :'' ) ;
@@ -455,22 +564,75 @@ <h2 class="fileName" onclick="showClass(event.target)"></h2>
455564 } ) ;
456565
457566
458- window . location . hash = '#' + fileItem . id ;
567+ if ( prevMapDict [ className ] ) {
568+ Object . keys ( prevMapDict [ className ] . methods ) . forEach ( function ( key ) {
569+ if ( ! mapDict [ className ] . methods [ key ] ) {
570+ let methodItem = methodTemplate . cloneNode ( true ) ;
571+
572+ methodItem . getElementsByClassName ( 'methodPrev' ) [ 0 ] . textContent = "(DEPRECATED)"
573+ methodItem . getElementsByClassName ( 'methodName' ) [ 0 ] . textContent = key ;
574+
575+ methodList . appendChild ( methodItem ) ;
576+ }
577+ } ) ;
578+ }
579+
580+
581+ if ( nohash ) {
582+
583+ if ( document . getElementById ( className ) . classList . contains ( 'oldClass' ) ) document . getElementById ( className ) . style . display = 'none'
584+ } else {
585+ window . location . hash = '#' + className ;
586+ }
459587
460588 } ) ;
461589
462590 }
463591
592+ function showChanges ( ) {
593+ classKeys . forEach ( function ( key ) {
594+ let target = document . getElementById ( key ) . getElementsByClassName ( 'fileName' ) [ 0 ]
595+
596+ showClass ( target , true ) ;
597+
598+ } )
599+
600+
601+ }
602+
464603
465604 function init ( ) {
466- classList ( function ( files ) {
605+ classList ( function ( files , prevFiles ) {
606+
467607 files . sort ( ) . forEach ( function ( file ) {
468608 let fileItem = fileTemplate . cloneNode ( true ) ;
469609 fileItem . id = file ;
470610 fileItem . getElementsByClassName ( 'fileName' ) [ 0 ] . textContent = file ;
471611
612+
613+ if ( prevFiles . length > 0 && prevFiles . indexOf ( file ) == - 1 ) {
614+ fileItem . getElementsByClassName ( 'filePrev' ) [ 0 ] . textContent = " (NEW)" ;
615+ fileItem . getElementsByClassName ( 'fileName' ) [ 0 ] . parentElement . parentElement . classList . add ( 'newClass' )
616+ } else {
617+ fileItem . getElementsByClassName ( 'fileName' ) [ 0 ] . parentElement . parentElement . classList . add ( 'oldClass' )
618+ }
619+
620+
472621 container . appendChild ( fileItem ) ;
473622 } ) ;
623+
624+ prevFiles . sort ( ) . forEach ( function ( file ) {
625+ if ( files . indexOf ( file ) == - 1 ) {
626+ let fileItem = fileTemplate . cloneNode ( true ) ;
627+ fileItem . getElementsByClassName ( 'fileName' ) [ 0 ] . textContent = file ;
628+ fileItem . getElementsByClassName ( 'fileName' ) [ 0 ] . onclick = "" ;
629+ fileItem . getElementsByClassName ( 'filePrev' ) [ 0 ] . textContent = " (DEPRECATED)" ;
630+ container . appendChild ( fileItem ) ;
631+ }
632+ } ) ;
633+
634+
635+
474636 } ) ;
475637 }
476638
0 commit comments