@@ -5,11 +5,14 @@ import {newLogEvent, newWizardEvent, Wizard} from "../foundation.js";
5
5
import { CompasSclDataService , SDS_NAMESPACE } from "../compas-services/CompasSclDataService.js" ;
6
6
import { createLogEvent } from "../compas-services/foundation.js" ;
7
7
import { getTypeFromDocName , updateDocumentInOpenSCD } from "../compas/foundation.js" ;
8
- import { getOpenScdElement , styles } from './foundation.js' ;
8
+ import { getElementByName , getOpenScdElement , styles } from './foundation.js' ;
9
9
import { addVersionToCompasWizard } from "../compas/CompasUploadVersion.js" ;
10
+ import { compareWizard } from "../compas/CompasCompareDialog.js" ;
10
11
11
12
/** An editor [[`plugin`]] for selecting the `Substation` section. */
12
13
export default class CompasVersionsPlugin extends LitElement {
14
+ @property ( )
15
+ doc ! : XMLDocument ;
13
16
@property ( { type : String } )
14
17
docId ! : string ;
15
18
@property ( { type : String } )
@@ -30,32 +33,82 @@ export default class CompasVersionsPlugin extends LitElement {
30
33
const type = getTypeFromDocName ( this . docName ) ;
31
34
CompasSclDataService ( ) . listVersions ( type , this . docId )
32
35
. then ( xmlResponse => {
33
- this . scls = Array . from ( xmlResponse . querySelectorAll ( 'Item' ) ?? [ ] )
36
+ this . scls = Array . from ( xmlResponse . querySelectorAll ( 'Item' ) ?? [ ] ) ;
34
37
} ) ;
35
38
}
36
39
37
40
confirmDeleteCompas ( ) : void {
38
- this . dispatchEvent ( newWizardEvent ( confirmDeleteCompasWizard ( this . docName , this . docId ) ) )
41
+ this . dispatchEvent ( newWizardEvent ( confirmDeleteCompasWizard ( this . docName , this . docId ) ) ) ;
39
42
}
40
43
41
44
addVersionCompasToCompas ( ) : void {
42
- this . dispatchEvent ( newWizardEvent ( addVersionToCompasWizard ( { docId : this . docId , docName : this . docName } ) ) )
45
+ this . dispatchEvent ( newWizardEvent ( addVersionToCompasWizard ( { docId : this . docId , docName : this . docName } ) ) ) ;
43
46
}
44
47
45
48
confirmRestoreVersionCompas ( version : string ) : void {
46
- this . dispatchEvent ( newWizardEvent ( confirmRestoreVersionCompasWizard ( this . docName , this . docId , version ) ) )
49
+ this . dispatchEvent ( newWizardEvent ( confirmRestoreVersionCompasWizard ( this . docName , this . docId , version ) ) ) ;
47
50
}
48
51
49
52
confirmDeleteVersionCompas ( version : string ) : void {
50
- this . dispatchEvent ( newWizardEvent ( confirmDeleteVersionCompasWizard ( this . docName , this . docId , version ) ) )
53
+ this . dispatchEvent ( newWizardEvent ( confirmDeleteVersionCompasWizard ( this . docName , this . docId , version ) ) ) ;
54
+ }
55
+
56
+ private getSelectedVersions ( ) : Array < string > {
57
+ const selectedVersions : Array < string > = [ ] ;
58
+ this . shadowRoot ! . querySelectorAll ( 'mwc-checkbox' )
59
+ . forEach ( checkbox => {
60
+ if ( checkbox . checked ) {
61
+ selectedVersions . push ( checkbox . value ) ;
62
+ }
63
+ } ) ;
64
+ return selectedVersions ;
65
+ }
66
+
67
+ async compareCurrentVersion ( ) : Promise < void > {
68
+ const selectedVersions = this . getSelectedVersions ( ) ;
69
+ if ( selectedVersions . length === 1 ) {
70
+ const rightVersion = selectedVersions [ 0 ] ;
71
+
72
+ const leftScl = this . doc . documentElement ;
73
+ const rightScl = await this . getVersion ( rightVersion ) ;
74
+
75
+ this . dispatchEvent ( newWizardEvent (
76
+ compareWizard ( leftScl , rightScl ,
77
+ { title : get ( 'compas.compare.title' , { leftVersion : 'current' , rightVersion : rightVersion } ) } ) ) ) ;
78
+ } else {
79
+ this . dispatchEvent ( newWizardEvent (
80
+ showMessageWizard ( get ( "compas.versions.selectOneVersionsTitle" ) ,
81
+ get ( "compas.versions.selectOneVersionsMessage" , { size : selectedVersions . length } ) ) ) ) ;
82
+ }
51
83
}
52
84
53
- private getElementbyName ( parent : Element , namespace : string , tagName : string ) : Element | null {
54
- const elements = parent . getElementsByTagNameNS ( namespace , tagName ) ;
55
- if ( elements . length > 0 ) {
56
- return elements . item ( 0 ) ;
85
+ async compareVersions ( ) : Promise < void > {
86
+ const selectedVersions = this . getSelectedVersions ( ) ;
87
+ if ( selectedVersions . length === 2 ) {
88
+ const leftVersion = selectedVersions [ 0 ] ;
89
+ const rightVersion = selectedVersions [ 1 ] ;
90
+
91
+ const leftScl = await this . getVersion ( leftVersion ) ;
92
+ const rightScl = await this . getVersion ( rightVersion ) ;
93
+
94
+ this . dispatchEvent ( newWizardEvent (
95
+ compareWizard ( leftScl , rightScl ,
96
+ { title : get ( 'compas.compare.title' , { leftVersion : leftVersion , rightVersion : rightVersion } ) } ) ) ) ;
97
+ } else {
98
+ this . dispatchEvent ( newWizardEvent (
99
+ showMessageWizard ( get ( "compas.versions.selectTwoVersionsTitle" ) ,
100
+ get ( "compas.versions.selectTwoVersionsMessage" , { size : selectedVersions . length } ) ) ) ) ;
57
101
}
58
- return null ;
102
+ }
103
+
104
+ private async getVersion ( version : string ) {
105
+ const type = getTypeFromDocName ( this . docName ) ;
106
+ return await CompasSclDataService ( ) . getSclDocumentVersion ( type , this . docId , version )
107
+ . then ( response => {
108
+ const sclData = response . querySelectorAll ( "SclData" ) . item ( 0 ) . textContent ;
109
+ const sclDocument = new DOMParser ( ) . parseFromString ( sclData ?? '' , 'application/xml' ) ;
110
+ return Promise . resolve ( sclDocument . documentElement ) ;
111
+ } ) ;
59
112
}
60
113
61
114
render ( ) : TemplateResult {
@@ -74,31 +127,41 @@ export default class CompasVersionsPlugin extends LitElement {
74
127
</ mwc-list > `
75
128
}
76
129
return html `
77
- < div id ="containerCompasVersions ">
78
- < section tabindex ="0 ">
79
- < h1 >
80
- ${ translate ( 'compas.versions.title' ) }
81
- < mwc-icon-button icon ="note_add "
130
+ < h1 >
131
+ < nav >
132
+ < abbr title ="${ translate ( 'compas.versions.addVersionButton' ) } ">
133
+ < mwc-icon-button icon ="playlist_add "
82
134
@click =${ ( ) => {
83
135
this . addVersionCompasToCompas ( ) ;
84
136
} } > </ mwc-icon-button >
137
+ </ abbr >
138
+ </ nav >
139
+ < nav >
140
+ < abbr title ="${ translate ( 'compas.versions.deleteProjectButton' ) } ">
85
141
< mwc-icon-button icon ="delete_forever "
86
142
@click =${ ( ) => {
87
143
this . confirmDeleteCompas ( ) ;
88
144
} } > </ mwc-icon-button >
89
- </ h1 >
145
+ </ abbr >
146
+ </ nav >
147
+ </ h1 >
148
+ < div id ="containerCompasVersions ">
149
+ < section tabindex ="0 ">
150
+ < h1 > ${ translate ( 'compas.versions.title' ) } </ h1 >
90
151
< mwc-list >
91
152
${ this . scls . map ( ( item , index , items ) => {
92
- let element = this . getElementbyName ( item , SDS_NAMESPACE , "Name" ) ;
153
+ let element = getElementByName ( item , SDS_NAMESPACE , "Name" ) ;
93
154
if ( element === null ) {
94
- element = this . getElementbyName ( item , SDS_NAMESPACE , "Id" ) ;
155
+ element = getElementByName ( item , SDS_NAMESPACE , "Id" ) ;
95
156
}
96
157
const name = element ! . textContent ?? '' ;
97
- const version = this . getElementbyName ( item , SDS_NAMESPACE , "Version" ) ! . textContent ?? '' ;
158
+ const version = getElementByName ( item , SDS_NAMESPACE , "Version" ) ! . textContent ?? '' ;
98
159
if ( items . length - 1 === index ) {
99
- return html `< mwc-list-item tabindex ="0 " graphic ="control ">
160
+ return html `< mwc-list-item tabindex ="0 "
161
+ graphic ="control ">
100
162
${ name } (${ version } )
101
- < span slot ="graphic " style ="width: 90px ">
163
+ < span slot ="graphic ">
164
+ < mwc-checkbox value ="${ version } "> </ mwc-checkbox >
102
165
< mwc-icon @click =${ ( ) => {
103
166
this . confirmRestoreVersionCompas ( version ) ;
104
167
} } > restore</ mwc-icon >
@@ -108,7 +171,8 @@ export default class CompasVersionsPlugin extends LitElement {
108
171
return html `< mwc-list-item tabindex ="0 "
109
172
graphic ="control ">
110
173
${ name } (${ version } )
111
- < span slot ="graphic " style ="width: 90px ">
174
+ < span slot ="graphic ">
175
+ < mwc-checkbox value ="${ version } "> </ mwc-checkbox >
112
176
< mwc-icon @click =${ ( ) => {
113
177
this . confirmRestoreVersionCompas ( version ) ;
114
178
} } > restore</ mwc-icon >
@@ -120,6 +184,14 @@ export default class CompasVersionsPlugin extends LitElement {
120
184
} ) }
121
185
</ mwc-list >
122
186
</ section >
187
+ < mwc-fab extended
188
+ icon ="compare "
189
+ label ="${ translate ( 'compas.versions.compareButton' ) } "
190
+ @click =${ this . compareVersions } > </ mwc-fab >
191
+ < mwc-fab extended
192
+ icon ="compare "
193
+ label ="${ translate ( 'compas.versions.compareCurrentButton' ) } "
194
+ @click =${ this . compareCurrentVersion } > </ mwc-fab >
123
195
</ div > `
124
196
}
125
197
@@ -130,8 +202,22 @@ export default class CompasVersionsPlugin extends LitElement {
130
202
width: 100vw;
131
203
}
132
204
205
+ h1 > nav,
206
+ h1 > abbr > mwc-icon-button {
207
+ float: right;
208
+ }
209
+
210
+ abbr {
211
+ text-decoration: none;
212
+ border-bottom: none;
213
+ }
214
+
215
+ [mwc-list-item] {
216
+ --mdc-list-item-graphic-size: 60px;
217
+ --mdc-list-item-graphic-margin: 40px;
218
+ }
219
+
133
220
#containerCompasVersions {
134
- display: grid;
135
221
padding: 8px 12px 16px;
136
222
box-sizing: border-box;
137
223
grid-template-columns: repeat(auto-fit, minmax(400px, auto));
@@ -268,3 +354,13 @@ function confirmDeleteVersionCompasWizard(docName: string, docId: string, versio
268
354
] ;
269
355
}
270
356
357
+ function showMessageWizard ( title : string , message : string ) : Wizard {
358
+ return [
359
+ {
360
+ title : title ,
361
+ content : [
362
+ html `< span > ${ message } </ span > ` ,
363
+ ] ,
364
+ } ,
365
+ ] ;
366
+ }
0 commit comments