@@ -15,28 +15,65 @@ import '@material/mwc-list';
15
15
import '@material/mwc-list/mwc-list-item' ;
16
16
import '@material/mwc-list/mwc-check-list-item' ;
17
17
18
+ import { MultiSelectedEvent } from '@material/mwc-list/mwc-list-foundation' ;
19
+
18
20
import {
19
21
newLogEvent ,
20
22
newOpenDocEvent ,
21
23
newWizardEvent ,
22
24
Wizard ,
23
25
} from '../foundation.js' ;
24
- import { MultiSelectedEvent } from '@material/mwc-list/mwc-list- foundation' ;
26
+ import { renderDiff } from '../ foundation/compare.js ' ;
25
27
26
28
import {
27
29
CompasSclDataService ,
28
30
SDS_NAMESPACE ,
29
31
} from '../compas-services/CompasSclDataService.js' ;
30
32
import { createLogEvent } from '../compas-services/foundation.js' ;
31
33
import {
34
+ compareVersions ,
32
35
getTypeFromDocName ,
33
36
updateDocumentInOpenSCD ,
34
37
} from '../compas/foundation.js' ;
35
38
import { addVersionToCompasWizard } from '../compas/CompasUploadVersion.js' ;
36
- import { compareWizard } from '../compas/CompasCompareDialog.js' ;
37
39
import { getElementByName , styles } from './foundation.js' ;
38
40
import { wizards } from '../wizards/wizard-library.js' ;
39
41
42
+ interface CompareOptions {
43
+ title : string ;
44
+ }
45
+
46
+ function compareWizard (
47
+ plugin : Element ,
48
+ oldElement : Element ,
49
+ newElement : Element ,
50
+ options : CompareOptions
51
+ ) : Wizard {
52
+ function renderDialogContent ( ) : TemplateResult {
53
+ return html ` ${ renderDiff ( newElement , oldElement ) ??
54
+ html `${ translate ( 'compas.compare.noDiff' ) } ` } `;
55
+ }
56
+
57
+ function close ( ) {
58
+ return function ( ) {
59
+ plugin . dispatchEvent ( newWizardEvent ( ) ) ;
60
+ return [ ] ;
61
+ } ;
62
+ }
63
+
64
+ return [
65
+ {
66
+ title : options . title ,
67
+ secondary : {
68
+ icon : '' ,
69
+ label : get ( 'close' ) ,
70
+ action : close ( ) ,
71
+ } ,
72
+ content : [ renderDialogContent ( ) ] ,
73
+ } ,
74
+ ] ;
75
+ }
76
+
40
77
/** An editor [[`plugin`]] for selecting the `Substation` section. */
41
78
export default class CompasVersionsPlugin extends LitElement {
42
79
@property ( )
@@ -244,15 +281,15 @@ export default class CompasVersionsPlugin extends LitElement {
244
281
const selectedVersions = this . getSelectedVersions ( ) ;
245
282
if ( selectedVersions . length === 1 ) {
246
283
const oldVersion = selectedVersions [ 0 ] ;
284
+
247
285
const oldScl = await this . getVersion ( oldVersion ) ;
248
286
const newScl = this . doc . documentElement ;
249
287
250
288
this . dispatchEvent (
251
289
newWizardEvent (
252
290
compareWizard ( this , oldScl , newScl , {
253
- title : get ( 'compas.compare.title ' , {
291
+ title : get ( 'compas.compare.titleCurrent ' , {
254
292
oldVersion : oldVersion ,
255
- newVersion : 'current' ,
256
293
} ) ,
257
294
} )
258
295
)
@@ -274,8 +311,9 @@ export default class CompasVersionsPlugin extends LitElement {
274
311
async compareVersions ( ) : Promise < void > {
275
312
const selectedVersions = this . getSelectedVersions ( ) ;
276
313
if ( selectedVersions . length === 2 ) {
277
- const oldVersion = selectedVersions [ 0 ] ;
278
- const newVersion = selectedVersions [ 1 ] ;
314
+ const sortedVersions = selectedVersions . slice ( ) . sort ( compareVersions ) ;
315
+ const oldVersion = sortedVersions [ 0 ] ;
316
+ const newVersion = sortedVersions [ 1 ] ;
279
317
280
318
const oldScl = await this . getVersion ( oldVersion ) ;
281
319
const newScl = await this . getVersion ( newVersion ) ;
0 commit comments