2019-04-18 14:10:56 -04:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
2019-06-05 15:52:52 -04:00
|
|
|
router: Ember.inject.service(),
|
|
|
|
|
|
|
|
currentCategoryId: Ember.computed.or(
|
|
|
|
"router.currentRoute.attributes.category.id",
|
|
|
|
"router.currentRoute.parent.attributes.category_id"
|
|
|
|
),
|
|
|
|
|
2019-06-05 17:00:47 -04:00
|
|
|
currentCategorySlug: Ember.computed.or(
|
|
|
|
"router.currentRoute.attributes.category.slug",
|
|
|
|
"router.currentRoute.parent.attributes.category.slug"
|
|
|
|
),
|
|
|
|
|
2019-06-14 14:44:09 -04:00
|
|
|
@computed(
|
|
|
|
"router.currentRoute.parent.attributes.tags",
|
|
|
|
"router.currentRoute.attributes.__type",
|
|
|
|
"router.currentRoute.attributes.id"
|
|
|
|
)
|
|
|
|
currentTags(tagsArray, type, tag) {
|
|
|
|
if (tagsArray) {
|
|
|
|
return tagsArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "tag" && tag) {
|
|
|
|
return [tag];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
@computed("currentUser.groups")
|
|
|
|
showToGroups(groups) {
|
2019-04-18 14:10:56 -04:00
|
|
|
const currentUser = Discourse.User.current();
|
|
|
|
|
|
|
|
if (
|
|
|
|
!currentUser ||
|
|
|
|
!groups ||
|
|
|
|
!this.siteSettings.no_ads_for_groups ||
|
|
|
|
this.siteSettings.no_ads_for_groups.length === 0
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-08 11:01:01 -04:00
|
|
|
const groupNames = groups.map(g => g.name.toLowerCase());
|
2019-05-08 11:22:21 -04:00
|
|
|
const noAdsGroupNames = this.siteSettings.no_ads_for_groups
|
|
|
|
.split("|")
|
|
|
|
.map(g => g.toLowerCase());
|
2019-04-18 14:10:56 -04:00
|
|
|
|
2019-05-08 11:01:01 -04:00
|
|
|
return !groupNames.any(g => noAdsGroupNames.includes(g));
|
2019-04-18 17:52:59 -04:00
|
|
|
},
|
|
|
|
|
2019-06-14 14:44:09 -04:00
|
|
|
@computed("currentCategoryId", "currentTags")
|
|
|
|
showOnCurrentPage(categoryId, currentTags) {
|
2019-06-05 15:52:52 -04:00
|
|
|
return (
|
2019-06-14 14:44:09 -04:00
|
|
|
(!categoryId ||
|
|
|
|
!this.siteSettings.no_ads_for_categories ||
|
|
|
|
!this.siteSettings.no_ads_for_categories
|
|
|
|
.split("|")
|
|
|
|
.includes(categoryId.toString())) &&
|
|
|
|
(!currentTags ||
|
|
|
|
!this.siteSettings.no_ads_for_tags ||
|
|
|
|
Ember.isEmpty(
|
|
|
|
this.siteSettings.no_ads_for_tags
|
|
|
|
.split("|")
|
|
|
|
.filter(tag => currentTags.includes(tag))
|
|
|
|
))
|
2019-06-05 15:52:52 -04:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
isNthPost(n) {
|
|
|
|
if (n && n > 0) {
|
|
|
|
return this.get("postNumber") % n === 0;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-18 14:10:56 -04:00
|
|
|
}
|
|
|
|
});
|