Przeglądaj źródła

adedd tag to links.

Juan Carlos 4 lat temu
rodzic
commit
4ddf376d47
1 zmienionych plików z 52 dodań i 51 usunięć
  1. 52 51
      marktplatz/templates/marktplatz/product_detail.html

+ 52 - 51
marktplatz/templates/marktplatz/product_detail.html

@@ -288,13 +288,12 @@
 					<h5 class="mediumkur">Mehr über das Projekt</h5>
 					<h5 class="mediumkur">Mehr über das Projekt</h5>
 					<p>Posts tagged {{ object.name|slugify }}</p>
 					<p>Posts tagged {{ object.name|slugify }}</p>
 					<br />
 					<br />
-					<ul class="" id="blog-post-demo" >
-
+					<ul class="" id="blog-posts-container" >
 					<blog-post
 					<blog-post
-					  v-for="post in posts"
-					  v-bind:key="post.id"
-					  v-bind:title="post.title"
-					  v-bind:link="post.link"
+						v-for="post in posts"
+						v-bind:key="post.id"
+						v-bind:title="post.title"
+						v-bind:link="post.link"
 					></blog-post>
 					></blog-post>
 					</ul>
 					</ul>
 
 
@@ -392,78 +391,80 @@
 {% compress js  %}
 {% compress js  %}
 
 
 <script>
 <script>
+	$(document).ready(function($) {
 
 
+		axios.get('https://blog.gemeinschaffen.com/wp-json/wp/v2/tags').then(resp => {
 
 
-$(document).ready(function($) {
-
-	 axios.get('https://blog.gemeinschaffen.com/wp-json/wp/v2/tags').then(resp => {
-
- 		queryData(resp);
+			queryData(resp);
 
 
- 	});
-
-	function queryData(resp) {
-
-		var q = jsonQuery('[*slug=gemeinschaffen]', {
-		// var q = jsonQuery('[*slug={{ object.name|slugify }}]', {
-			data: resp.data
 		});
 		});
 
 
+		function queryData(resp) {
 
 
-		if (!q.value.length ){
-
-			return;
+			var requests = []
 
 
-		}
-
-		tagsurl = "https://blog.gemeinschaffen.com/wp-json/wp/v2/posts?tags=" + q.value[0].id;
-
-		axios.get(tagsurl).then(resp => {
+			var projTag = jsonQuery('[*slug={{ object.name|slugify }}]', {
+				data: resp.data
+			});
 
 
-			if (!resp.data.length ){
+			var postsTag = jsonQuery('[*slug=gemeinschaffen]', {
+				data: resp.data
+			});
 
 
+			if (!projTag.value.length && !postsTag.value.length) {
 				return;
 				return;
+			}
 
 
+			if (projTag.value.length) {
+				url = "https://blog.gemeinschaffen.com/wp-json/wp/v2/posts?tags=" + projTag.value[0].id;
+				requests.push(axios.get(url));
 			}
 			}
 
 
-			generateLinks(resp);
+			if (postsTag.value.length) {
+				url = "https://blog.gemeinschaffen.com/wp-json/wp/v2/posts?tags=" + postsTag.value[0].id
+				requests.push(axios.get(url));
+			}
 
 
+			axios.all(requests).then(axios.spread(function(...responses) {
+				rpost = []
+				for (index = 0; index < responses.length; index++) {
+					rpost = rpost.concat(responses[index].data);
+				}
 
 
-		});
+				if (rpost.length) {
+					generateLinks(rpost);
+				}
 
 
-	}
 
 
 
 
+			}));
+
+
+		}
 
 
-	function generateLinks(resp) {
+		function generateLinks(resp) {
 
 
-		Vue.component('blog-post', {
-		 props: ['title', 'link'],
-		 delimiters: ['<%', '%>'],
-		 template: `
+			Vue.component('blog-post', {
+				props: ['title', 'link'],
+				delimiters: ['<%', '%>'],
+				template: `
 		 <li>
 		 <li>
 			 <a title="link-title" :href="link" target="_blank" v-html="title.rendered"></a>
 			 <a title="link-title" :href="link" target="_blank" v-html="title.rendered"></a>
 		 </li>`
 		 </li>`
-	 })
-
-	 new Vue({
-
-		 el: '#blog-post-demo',
-		 delimiters: ['<%', '%>'],
-		 data: {
-			 posts: resp.data
-		 }
-	 })
-
-	}
-
+			})
 
 
+			new Vue({
 
 
+				el: '#blog-posts-container',
+				delimiters: ['<%', '%>'],
+				data: {
+					posts: resp
+				}
+			})
 
 
- }); // document ready
-
-
+		}
 
 
+	}); // document ready
 </script>
 </script>
 {% endcompress %}
 {% endcompress %}