@@ -83,146 +83,6 @@ export const mainCard = {
8383 mapTooltip . value = tooltip ;
8484 } ;
8585
86- const URLquery = { ...route . query } ;
87- const removeQueryFromRouter = ( key ) => {
88- delete URLquery [ key ] ;
89- message . warning ( 'URL contém valor inválido para filtragem' )
90- router . replace ( { query : URLquery } ) ;
91- }
92-
93- const setStateFromUrl = ( ) => {
94- const formState = store . state . content . form
95- const routeArgs = { ...route . query } ;
96- const routerResult = { } ;
97- const routerResultTabs = { } ;
98-
99- if ( ! Object . keys ( routeArgs ) . length ) {
100- return ;
101- }
102-
103- for ( const [ key , value ] of Object . entries ( routeArgs ) ) {
104- if ( key === "sickImmunizer" ) {
105- if ( value . includes ( "," ) ) {
106- const values = value . split ( "," )
107- const sicks = formState [ "sicks" ] . map ( el => el . value )
108- const immunizers = formState [ "immunizers" ] . map ( el => el . value )
109- if (
110- values . every ( val => sicks . includes ( val ) ) ||
111- values . every ( val => immunizers . includes ( val ) )
112- ) {
113- routerResult [ key ] = values ;
114- } else {
115- removeQueryFromRouter ( key ) ;
116- }
117- } else if (
118- formState [ "sicks" ] . some ( el => el . value === value ) ||
119- formState [ "immunizers" ] . some ( el => el . value === value )
120- ) {
121- routerResult [ key ] = value ;
122- } else {
123- removeQueryFromRouter ( key ) ;
124- }
125- } else if ( key === "city" ) {
126- // TODO: define if cities will be in URL state
127- // const values = value.split(",")
128- // const cities = formState["cities"].map(el => el.value)
129- // if (values.every(val => cities.includes(val))) {
130- // routerResult[key] = values;
131- // } else {
132- // removeQueryFromRouter(key);
133- // }
134- } else if ( key === "local" ) {
135- const values = value . split ( "," )
136- const locals = formState [ "locals" ] . map ( el => el . value )
137- if ( values . every ( val => locals . includes ( val ) ) ) {
138- routerResult [ key ] = values ;
139- } else {
140- removeQueryFromRouter ( key ) ;
141- }
142- } else if ( key === "granularity" ) {
143- formState [ "granularities" ] . some ( el => el . value === value ) ?
144- routerResult [ key ] = value : removeQueryFromRouter ( key ) ;
145- } else if ( key === "dose" ) {
146- formState [ "doses" ] . some ( el => el . value === value ) ?
147- routerResult [ key ] = value : removeQueryFromRouter ( key ) ;
148- } else if ( key === "type" ) {
149- formState [ "types" ] . some ( el => el . value === value ) ?
150- routerResult [ key ] = value : removeQueryFromRouter ( key ) ;
151- } else if ( key === "tab" ) {
152- [ "map" , "chart" , "table" ] . some ( el => el === value ) ?
153- routerResultTabs [ key ] = value : removeQueryFromRouter ( key ) ;
154- } else if ( key === "tabBy" ) {
155- [ "immunizers" , "sicks" ] . some ( el => el === value ) ?
156- routerResultTabs [ key ] = value : removeQueryFromRouter ( key ) ;
157- } else if ( [ "periodStart" , "periodEnd" ] . includes ( key ) ) {
158- const resultValue = Number ( value )
159- formState [ "years" ] . some ( el => el . value === resultValue ) ?
160- routerResult [ key ] = resultValue : removeQueryFromRouter ( key ) ;
161- } else if ( key === "period" ) {
162- routerResult [ key ] = Number ( value ) ;
163- } else if ( value . includes ( "," ) ) {
164- routerResult [ key ] = value . split ( "," ) ;
165- } else {
166- routerResult [ key ] = value ?? null ;
167- }
168- }
169-
170- store . commit ( "content/UPDATE_FROM_URL" , {
171- tab : routerResultTabs ?. tab ? routerResultTabs . tab : "map" ,
172- tabBy : routerResultTabs ?. tabBy ? routerResultTabs . tabBy : "sicks" ,
173- form : { ...routerResult } ,
174- } ) ;
175- } ;
176-
177- const setUrlFromState = ( ) => {
178- const routeArgs = { ...route . query } ;
179- let stateResult = formatToApi ( {
180- form : { ...store . state . content . form } ,
181- tab : store . state . content . tab !== "map" ? store . state . content . tab : undefined ,
182- tabBy : store . state . content . tabBy !== "sicks" ? store . state . content . tabBy : undefined ,
183- } ) ;
184- if ( Array . isArray ( stateResult . sickImmunizer ) && stateResult . sickImmunizer . length ) {
185- stateResult . sickImmunizer = [ ...stateResult ?. sickImmunizer ] . join ( "," ) ;
186- }
187- if ( Array . isArray ( stateResult . local ) && stateResult . local . length ) {
188- stateResult . local = [ ...stateResult ?. local ] . join ( "," ) ;
189- }
190- // TODO: define if cities will be in URL state
191- // if (Array.isArray(stateResult.city) && stateResult.city.length) {
192- // stateResult.city = [...stateResult?.city].join(",");
193- // }
194- delete stateResult . city
195-
196- if ( ! JSON . stringify ( routeArgs ) == JSON . stringify ( stateResult ) ) {
197- return ;
198- }
199-
200- return router . replace ( { query : stateResult } ) ;
201- }
202-
203- watch ( ( ) => {
204- const form = store . state . content . form ;
205- return [
206- form . dose ,
207- form . granularity ,
208- form . granularity ,
209- form . local ,
210- form . period ,
211- form . periodEnd ,
212- form . periodStart ,
213- form . sickImmunizer ,
214- form . type ,
215- // TODO: define if cities will be in URL state
216- // form.city,
217- store . state . content . tab ,
218- store . state . content . tabBy
219- ]
220- } ,
221- async ( ) => {
222- setUrlFromState ( ) ;
223- }
224- )
225-
22686 onMounted ( async ( ) => {
22787 getWindowWidth ( ) ;
22888 await store . dispatch ( "content/updateFormSelect" ) ;
0 commit comments