@@ -2,6 +2,7 @@ import {html, render, nothing} from 'lit-html';
22import { LayerTreeFolder } from "../modules/LayerTree/LayerTreeFolder" ;
33import { WMSCapabilities } from "ol/format" ;
44import { LayerTreeLayer } from "../modules/LayerTree/LayerTreeLayer" ;
5+ import { LayerTreeProject } from "../modules/LayerTree/LayerTreeProject" ;
56
67/**
78 * Class representing the layer store.
@@ -44,22 +45,23 @@ export class LayerStore extends HTMLElement {
4445 */
4546 folderTemplate ( element ) {
4647 //Check if the folder will have to load children from a project.
47- let tagLazy = element . isLazy ( ) ? "lazy" : "" ;
48-
49- let icoSpan ;
50-
51- //Check if the folder is loading, opened or closed.
52- if ( element . isLoading ( ) ) {
53- icoSpan = "fa-spinner fa-pulse" ;
54- } else {
55- icoSpan = element . isOpened ( ) ? "fa-folder-open" : "fa-folder" ;
56- }
57-
58- //Check if the folder is failed to load children.
59- //It occurs when the project can't be loaded.
60- if ( element . isFailed ( ) ) {
61- icoSpan = "fa-window-close" ;
62- tagLazy = "failed" ;
48+ let icoSpan = element . isOpened ( ) ? "fa-folder-open" : "fa-folder" ;
49+ let tagLazy = "" ;
50+
51+ if ( element instanceof LayerTreeProject ) {
52+ tagLazy = element . isLazy ( ) ? "lazy" : "" ;
53+
54+ //Check if the folder is loading, opened or closed.
55+ if ( element . isLoading ( ) ) {
56+ icoSpan = "fa-spinner fa-pulse" ;
57+ } else if ( element . isFailed ( ) ) {
58+ //Check if the folder is failed to load children.
59+ //It occurs when the project can't be loaded.
60+ icoSpan = "fa-window-close" ;
61+ tagLazy = "failed" ;
62+ } else {
63+ icoSpan = "project" ;
64+ }
6365 }
6466
6567 //Template of a folder.
@@ -162,35 +164,49 @@ export class LayerStore extends HTMLElement {
162164 * Action when a folder is clicked.
163165 * It can open or close the folder.
164166 * It can decide to load the project and put children in the folder.
165- * @param {LayerTreeFolder } element The folder clicked.
167+ * @param {LayerTreeFolder|LayerTreeProject } element The folder clicked.
166168 * @param {Event } e Event occurring.
167169 */
168170 async action ( element , e ) {
169- if ( element . isLazy ( ) ) {
171+ const handleLazyLoading = async ( ) => {
170172 element . setLoading ( true ) ;
171173 this . render ( ) ;
172- //Prevent from multiple request
174+
175+ // Prevent multiple requests
173176 element . setLazy ( false ) ;
174177 e . target . closest ( '.lazy' ) . children [ 0 ] . className = "layer-store-folder fas fa-spinner fa-pulse" ;
175- //After loaded
176- let child = await this . loadTree ( element ) ;
177- element . setLazy ( false ) ;
178+
179+ // Load folder content
180+ let children = await this . loadTree ( element ) ;
178181 element . setLoading ( false ) ;
179- if ( child . length > 0 ) {
180- child . forEach ( ( el ) => {
181- el . repository = element . getRepository ( ) ;
182- el . project = element . getProject ( ) ;
183- } ) ;
184- element . createChildren ( child ) ;
182+
183+ if ( children . length > 0 ) {
184+ updateChildrenAttributes ( children , element ) ;
185+ element . createChildren ( children ) ;
185186 element . changeStatusFolder ( ) ;
186187 } else {
187188 element . setFailed ( ) ;
188189 }
190+ } ;
191+
192+ const updateChildrenAttributes = ( children , element ) => {
193+ children . forEach ( ( child ) => {
194+ child . repository = element . getRepository ( ) ;
195+ child . project = element . getProject ( ) ;
196+ } ) ;
197+ } ;
198+
199+ if ( element instanceof LayerTreeProject ) {
200+ if ( element . isLazy ( ) ) {
201+ await handleLazyLoading ( ) ;
202+ } else {
203+ element . changeStatusFolder ( ) ;
204+ }
189205 } else {
190206 element . changeStatusFolder ( ) ;
191207 }
192- this . render ( ) ;
193208
209+ this . render ( ) ;
194210 } ;
195211
196212 /**
0 commit comments