@@ -108,7 +108,8 @@ export default {
108108 },
109109
110110 async mounted () {
111- await this .getWorkspace ();
111+ await this .getWorkspaceInfo ();
112+ await this .getWorkspaceData ();
112113 if (this .geojson ) {
113114 this .$refs .map .setupMeta ();
114115 this .$refs .map .setupMapbox ();
@@ -135,31 +136,17 @@ export default {
135136 },
136137
137138 methods: {
138- async getWorkspace () {
139- const result = await this .$apollo .query ({
140- query: gql ` query getworkspace ($wshash : ID ! , $hash : ID ! ) {
141- workspace (id : $wshash ) {
142- id
143- pk
144- title
145- description
146- snapshots {
139+ async getWorkspaceInfo () {
140+ let workspaceInfo = this .$store .getters .WorkspaceInfoByHash (this .wshash );
141+
142+ if (! workspaceInfo) {
143+ const result = await this .$apollo .query ({
144+ query: gql ` query getworkspace ($wshash : ID ! , $hash : ID ! ) {
145+ workspace (id : $wshash ) {
147146 id
148147 pk
149148 title
150- topic
151- screenshot
152- thumbnail
153- }
154- }
155-
156- snapshot (id : $hash ) {
157- id
158- pk
159- data
160- municipality {
161- bfsNumber
162- fullname
149+ description
163150 snapshots {
164151 id
165152 pk
@@ -169,6 +156,65 @@ export default {
169156 thumbnail
170157 }
171158 }
159+
160+ snapshot (id : $hash ) {
161+ id
162+ pk
163+ municipality {
164+ bfsNumber
165+ fullname
166+ snapshots {
167+ id
168+ pk
169+ title
170+ topic
171+ screenshot
172+ thumbnail
173+ }
174+ }
175+ }
176+ }` ,
177+ variables: {
178+ wshash: btoa (` WorkspaceNode:${ this .wshash } ` ),
179+ hash: btoa (` SnapshotNode:${ this .hash } ` )
180+ }
181+ }).catch ((error ) => {
182+ this .errorsettings = { type: ' netwokerror' , open: true , error };
183+ });
184+ if (result) {
185+ if (result .data .hasOwnProperty (' workspace' ) && result .data .workspace ) {
186+ workspaceInfo = result .data ;
187+ this .$store .commit (' addWorkspaceInfo' , { hash: this .wshash , value: workspaceInfo });
188+ } else {
189+ this .$router .push ({ name: ' home' });
190+ }
191+ }
192+ }
193+ const workspace = workspaceInfo .workspace ;
194+ const snapshot = workspaceInfo .snapshot ;
195+ if (! workspace .snapshots .map (s => s .pk ).includes (snapshot .pk )) {
196+ this .$router .push ({ name: ' home' });
197+ }
198+ this .municipalityName = snapshot .municipality .fullname ;
199+ this .snapshotsWorkspace = workspace .snapshots ;
200+ this .title = workspace .title ;
201+ this .description = workspace .description ;
202+ this .$store .commit (' setBfsnumber' , snapshot .municipality .bfsNumber );
203+ this .$store .commit (' setBfsname' , snapshot .municipality .fullname );
204+ },
205+
206+ async getWorkspaceData () {
207+ const result = await this .$apollo .query ({
208+ query: gql ` query getworkspace ($wshash : ID ! , $hash : ID ! ) {
209+ workspace (id : $wshash ) {
210+ id
211+ pk
212+ title
213+ }
214+ snapshot (id : $hash ) {
215+ id
216+ pk
217+ data
172218 }
173219 }` ,
174220 variables: {
@@ -180,18 +226,7 @@ export default {
180226 });
181227 if (result) {
182228 if (result .data .hasOwnProperty (' workspace' ) && result .data .workspace ) {
183- const workspace = result .data .workspace ;
184- const snapshot = result .data .snapshot ;
185- if (! workspace .snapshots .map (s => s .pk ).includes (snapshot .pk )) {
186- this .$router .push ({ name: ' home' });
187- }
188- this .geojson = snapshot .data ;
189- this .municipalityName = snapshot .municipality .fullname ;
190- this .snapshotsWorkspace = workspace .snapshots ;
191- this .title = workspace .title ;
192- this .description = workspace .description ;
193- this .$store .commit (' setBfsnumber' , snapshot .municipality .bfsNumber );
194- this .$store .commit (' setBfsname' , snapshot .municipality .fullname );
229+ this .geojson = result .data .snapshot .data ;
195230 } else {
196231 this .$router .push ({ name: ' home' });
197232 }
0 commit comments