Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: guard against missing data elements by using lodash.get #19

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/Localization/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,12 @@
"contact": "Contact",
"cityStateZip": "Illinois 60601, USA",
"allRightsReserved": "All rights reserved."
},
"Article": {
"noTitleValue": "(Article has no title)",
"noTeaserValue": "(Article has no teaser image)",
"noSummaryValue": "No summary filled",
"noBodyCopyValue" : "No body copy element filled",
"noPostDateValue": "No post date filled"
}
}
8 changes: 8 additions & 0 deletions src/Localization/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,13 @@
"contact": "Contacto",
"cityStateZip": "Illinois 60601, EE.UU.",
"allRightsReserved": "Todos los derechos reservados."
},
"Article": {
"noTitleValue": "(El artículo no tiene título)",
"noTeaserValue": "(El artículo no tiene imagen teaser)",
"noSummaryValue": "Sin resumen lleno",
"noBodyCopyValue" : "Ningún elemento body copy lleno",
"noPostDateValue": "Ningún elemento post date lleno"
}

}
33 changes: 20 additions & 13 deletions src/components/Article.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,36 @@
<div class="row">
<div class="article-detail-image col-md-push-2 col-md-8">
<img
v-if="articleData.imageLink"
:alt="articleData.title"
class="img-responsive"
:src="articleData.imageLink"
:title="articleData.title"
/>
<span
v-else
class="img-responsive"
>{{ $t('Article.noTeaserValue') }}</span>
</div>
</div>
<div class="row">
<RichTextElement
v-if="articleData.bodyCopyElement.getHtml()"
styleClass="article-detail-content"
:element="articleData.bodyCopyElement"
/>
<span class="article-detail-content">{{ $t('Article.noBodyCopyValue')}}</span>
</div>
</article>
</div>
</template>

<script>
import { ArticleStore } from '../Stores/Article'
import { ArticleStore } from '../Stores/Article';
import dateFormat from 'dateformat';
import { dateFormats } from '../Utilities/LanguageCodes'
import RichTextElement from './RichTextElement.vue'
import { dateFormats } from '../Utilities/LanguageCodes';
import RichTextElement from './RichTextElement.vue';
import _ from 'lodash';

export default {
name: 'Article',
Expand All @@ -45,13 +53,13 @@ export default {
article: null,
}),
computed: {
articleData: function(){
return ({
title: this.article.title.value,
imageLink: this.article.teaserImage.value[0].url,
postDate: this.formatDate(this.article.postDate.value),
bodyCopyElement: this.article.bodyCopy,
})
articleData: function() {
return {
title: _.get(this.article, 'title.value') || this.$t('Article.noTitleValue'),
imageLink: _.get(this.article, 'teaserImage.value[0].url'),
postDate: this.formatDate(_.get(this.article, 'postDate.value')),
bodyCopyElement: _.get(this.article, 'bodyCopy') || this.$t('Article.noBodyCopyValue')
};
}
},
watch: {
Expand All @@ -62,7 +70,7 @@ export default {
},
methods: {
formatDate: function(value){
return dateFormat(value, 'dddd, mmmm d, yyyy');
return value ? dateFormat(value, 'dddd, mmmm d, yyyy') : this.$t('Article.noPostDateValue');
},
onChange: function(){
this.article = ArticleStore.getArticle(this.$route.params.articleId, this.language);
Expand All @@ -86,7 +94,6 @@ export default {
},
components: {
RichTextElement
},

}
}
</script>
18 changes: 12 additions & 6 deletions src/components/Articles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
<div class="article-tile">
<router-link :to="article.link">
<img
v-if="article.imageLink"
:alt="'Article ' + article.title"
class="article-tile-image"
:src="article.imageLink"
:title="'Article ' + article.title"
/>
<span
v-else
class="article-tile-image"
>{{ $t('Article.noTeaserValue') }}</span>
</router-link>
<div class="article-tile-date">
{{article.postDate}}
Expand All @@ -39,6 +44,7 @@
import dateFormat from 'dateformat';
import { ArticleStore } from '../Stores/Article';
import { dateFormats } from '../Utilities/LanguageCodes';
import _ from 'lodash';

export default {
name: 'Articles',
Expand All @@ -50,11 +56,11 @@ export default {
computed: {
articlesData: function() {
return this.articles.map(article => ({
title: article.title.value,
imageLink: article.teaserImage.value[0].url,
postDate: this.formatDate(article.postDate.value),
summary: article.summary.value,
link: `/${this.language}/articles/${article.system.id}`
title: _.get(article, 'title.value') || this.$t('Article.noTitleValue'),
imageLink: _.get(article, 'teaserImage.value[0].url'),
link: `/${this.language}/articles/${_.get(article, 'system.id')}`,
postDate: this.formatDate(_.get(article, 'postDate.value')),
summary: _.get(article, 'summary.value') || this.$t('Article.noSummaryValue')
}));
}
},
Expand All @@ -66,7 +72,7 @@ export default {
},
methods: {
formatDate: function(value) {
return dateFormat(value, 'mmmm d');
return value ? dateFormat(value, 'mmmm d') : this.$t('Article.noPostDateValue');
},
onChange: function() {
this.articles = ArticleStore.getArticles(
Expand Down
19 changes: 15 additions & 4 deletions src/components/LatestArticles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
<div class="col-md-12 col-lg-6">
<router-link :to="articlesData[0].link">
<img
v-if="articlesData.imageLink"
Simply007 marked this conversation as resolved.
Show resolved Hide resolved
v-bind:alt="articlesData[0].title"
class="article-tile-image"
v-bind:src="articlesData[0].imageLink"
v-bind:title="articlesData[0].title"
/>
<span
v-else
class="article-tile-image"
>{{ $t('Article.noTeaserValue') }}</span>
</router-link>
</div>
<div class="col-md-12 col-lg-6">
Expand All @@ -42,11 +47,16 @@
<div class="article-tile">
<router-link :to="article.link">
<img
v-if="article.imageLink"
v-bind:alt="'Article' + article.title"
class="article-tile-image"
v-bind:src="article.imageLink"
v-bind:title="'Article' + article.title"
/>
<span
v-else
class="article-tile-image"
>{{ $t('Article.noTeaserValue') }}</span>
</router-link>
<div class="article-tile-date">
{{article.postDate}}
Expand All @@ -68,6 +78,7 @@
import { ArticleStore } from '../Stores/Article'
import dateFormat from 'dateformat'
import { dateFormats } from '../Utilities/LanguageCodes'
import _ from 'lodash';

export default {
name: 'latest-articles',
Expand All @@ -79,9 +90,9 @@ export default {
computed: {
articlesData: function(){
return this.articles.map(article => ({
imageLink : article.teaserImage.value[0].url,
postDate : this.formatDate(article.postDate.value),
summary : article.summary.value,
imageLink: _.get(article, 'teaserImage.value[0].url'),
postDate : this.formatDate(_.get(article, 'postDate.value')),
summary : _.get(article, 'summary.value') || this.$t('Article.noSummaryValue'),
link : `/${this.language}/articles/${article.system.id}`,
}))
}
Expand All @@ -94,7 +105,7 @@ export default {
},
methods: {
formatDate: function(value){
return dateFormat(value, 'mmmm d');
return value ? dateFormat(value, 'mmmm d') : this.$t('Article.noPostDateValue');
},
onChange: function(){
this.articles = ArticleStore.getArticles(this.articleCount, this.language);
Expand Down
5 changes: 5 additions & 0 deletions vue.cli.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
configureWebpack: {
devtool: 'source-map'
}
}