@@ -10,15 +10,18 @@ import {
1010import { posix , resolve } from 'path' ;
1111import { Metadata } from './edtMetadataInterfaces' ;
1212import { ProgressLocation , window } from 'vscode' ;
13+ import { NodeWithIdTreeDataProvider } from '../metadataView' ;
1314
1415export class Edt {
1516 private xmlPath : vscode . Uri ;
17+ private dataProvider : NodeWithIdTreeDataProvider ;
1618
17- constructor ( xmlPath : vscode . Uri ) {
19+ constructor ( xmlPath : vscode . Uri , dataProvider : NodeWithIdTreeDataProvider ) {
1820 this . xmlPath = xmlPath ;
21+ this . dataProvider = dataProvider ;
1922 }
2023
21- createTreeElements ( root : TreeItem ) {
24+ createTreeElements ( root : TreeItem , subsystemFilter : string [ ] ) {
2225 window . withProgress ( {
2326 location : ProgressLocation . Notification ,
2427 title : "Происходит загрузка конфигурации" ,
@@ -54,6 +57,10 @@ export class Edt {
5457 const subTree : TreeItem [ ] = [ ...treeItem ?. children ?? [ ] ] ;
5558
5659 for ( const [ indexOfObjects , obj ] of objects . entries ( ) ) {
60+ if ( subsystemFilter . length && subsystemFilter . indexOf ( obj ) === - 1 ) {
61+ continue ;
62+ }
63+
5764 count ++ ;
5865
5966 if ( count % Math . round ( total / 100 ) === 0 ) {
@@ -74,10 +81,59 @@ export class Edt {
7481
7582 treeItem ! . children = subTree ;
7683 }
84+
85+ this . dataProvider . update ( ) ;
7786 }
7887 }
7988 console . timeEnd ( 'edtDownload' ) ;
80- } ) ; // WithProgress
89+
90+ if ( subsystemFilter . length ) {
91+ // Нумераторы и последовательности в документах
92+ if ( root . children ! [ 3 ] . children ! [ 1 ] . children ?. length === 0 ) {
93+ root . children ! [ 3 ] . children ?. splice ( 1 , 1 ) ;
94+ }
95+ if ( root . children ! [ 3 ] . children ! [ 0 ] . children ?. length === 0 ) {
96+ root . children ! [ 3 ] . children ?. splice ( 0 , 1 ) ;
97+ }
98+
99+ // Очищаю пустые элементы
100+ const indexesToDelete : number [ ] = [ ] ;
101+ root . children ?. forEach ( ( ch , index ) => {
102+ if ( ! ch . children || ch . children . length === 0 ) {
103+ indexesToDelete . push ( index ) ;
104+ }
105+ } ) ;
106+ indexesToDelete . sort ( ( a , b ) => b - a ) ;
107+ indexesToDelete . forEach ( ( d ) => root . children ?. splice ( d , 1 ) ) ;
108+
109+ // Отдельно очищаю раздел "Общие"
110+ indexesToDelete . splice ( 0 ) ;
111+ root . children ! [ 0 ] . children ?. forEach ( ( ch , index ) => {
112+ if ( ! ch . children || ch . children . length === 0 ) {
113+ indexesToDelete . push ( index ) ;
114+ }
115+ } ) ;
116+ indexesToDelete . sort ( ( a , b ) => b - a ) ;
117+ indexesToDelete . forEach ( ( d ) => root . children ! [ 0 ] . children ?. splice ( d , 1 ) ) ;
118+
119+ // Ненужные вложенные подсистемы
120+ this . removeSubSystems ( root . children ! [ 0 ] . children ! [ 0 ] , subsystemFilter ) ;
121+ this . dataProvider . update ( ) ;
122+ }
123+ } , ) ; // WithProgress
124+ }
125+
126+ removeSubSystems ( subsystemsTreeItem : TreeItem , subsystemFilter : string [ ] ) {
127+ const indexesToDelete : number [ ] = [ ] ;
128+ subsystemsTreeItem . children ?. forEach ( ( ch , index ) => {
129+ if ( subsystemFilter . indexOf ( `Subsystem.${ ch . label } ` ) === - 1 ) {
130+ indexesToDelete . push ( index ) ;
131+ } else {
132+ this . removeSubSystems ( ch , subsystemFilter ) ;
133+ }
134+ } ) ;
135+ indexesToDelete . sort ( ( a , b ) => b - a ) ;
136+ indexesToDelete . forEach ( ( d ) => subsystemsTreeItem . children ?. splice ( d , 1 ) ) ;
81137 }
82138
83139 async createElement ( rootPath : string , objName : string ) {
@@ -116,16 +172,23 @@ export class Edt {
116172 const treeItemPath = `${ treeItemIdSlash } ${ CreatePath ( objectPath ) } ` ;
117173
118174 switch ( objName . split ( '.' ) [ 0 ] ) {
119- case 'Subsystem' :
175+ case 'Subsystem' : {
176+ const { chilldren, content } = this . getSubsystemChildren (
177+ elementObject ,
178+ folderUri ,
179+ posix . join ( rootPath , objectPath )
180+ ) ;
181+
120182 return GetTreeItem ( treeItemId , elementName ?? objName , {
121183 icon : 'subsystem' ,
122- children : this . getSubsystemChildren (
123- elementObject ,
124- folderUri ,
125- posix . join ( rootPath , objectPath )
126- ) ,
184+ context : `subsystem_ ${ rootPath } ` ,
185+ children : chilldren ,
186+ command : 'metadataViewer.filterBySubsystem' ,
187+ commandTitle : 'Filter by subsystem' ,
188+ commandArguments : content ,
127189 configType : 'edt'
128190 } ) ;
191+ }
129192 case 'CommonModule' :
130193 return GetTreeItem ( treeItemId , elementName ?? objName , {
131194 icon : 'commonModule' , context : 'module' , path : treeItemPath ,
@@ -310,8 +373,19 @@ export class Edt {
310373 return null ;
311374 }
312375
313- getSubsystemChildren ( obj : any , folderUri : vscode . Uri , path : string ) : TreeItem [ ] | undefined {
376+ getSubsystemChildren ( obj : any , folderUri : vscode . Uri , path : string ) : { chilldren : TreeItem [ ] | undefined , content : string [ ] } {
314377 const subtreeItems : TreeItem [ ] = [ ] ;
378+ // добавляю к фильтру сами подсистемы с иерархией
379+ const subsystemContent : string [ ] = [
380+ ...path . slice ( path . indexOf ( 'Subsystem' ) ) . replace ( / S u b s y s t e m s \/ / g, 'Subsystem.' ) . split ( '/' )
381+ ] ;
382+ const rootPath = path . slice ( 0 , path . indexOf ( 'Subsystem' ) - 1 ) ;
383+
384+ if ( obj . content && obj . content . length > 0 ) {
385+ for ( const content of obj . content ) {
386+ subsystemContent . push ( content ) ;
387+ }
388+ }
315389
316390 if ( obj . subsystems && obj . subsystems . length > 0 ) {
317391 for ( const subsystem of obj . subsystems ) {
@@ -333,15 +407,22 @@ export class Edt {
333407 const elementObject = element [ Object . keys ( element ) [ 1 ] ] ;
334408 const elementName = elementObject . name ;
335409
336- subtreeItems . push ( GetTreeItem ( `${ subPath } /${ elementObject . $_uuid } ` , elementName ?? subsystem , {
337- icon : 'subsystem' , children : this . getSubsystemChildren ( elementObject , folderUri , subPath ) ,
410+ const { chilldren, content } = this . getSubsystemChildren ( elementObject , folderUri , subPath ) ;
411+
412+ subtreeItems . push ( GetTreeItem ( `${ rootPath } /${ elementObject . $_uuid } ` , elementName ?? subsystem , {
413+ icon : 'subsystem' ,
414+ context : `subsystem_${ rootPath } ` ,
415+ children : chilldren ,
416+ command : 'metadataViewer.filterBySubsystem' ,
417+ commandTitle : 'Filter by subsystem' ,
418+ commandArguments : content ,
338419 configType : 'edt'
339420 } ) ) ;
340421 } ) ;
341422 }
342423 }
343424
344- return subtreeItems ;
425+ return { chilldren : subtreeItems , content : subsystemContent } ;
345426 }
346427
347428 fillObjectItemsByMetadata ( idPrefix : string , metadataType : string , metadata : Metadata ) {
0 commit comments