content-item.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. class ContentItem {
  4. constructor(hash, props) {
  5. this.data = props;
  6. this.hash = hash;
  7. this.type = props.type;
  8. this.title = props.title;
  9. this.text = props.text;
  10. if (props.myTags) {
  11. this.myTagsWithoutAll = props.myTags.filter(x => x !== 'all');
  12. }
  13. else {
  14. this.myTagsWithoutAll = [];
  15. }
  16. if (props.price != null && !isNaN(Number(props.price))) {
  17. this.price = Number(props.price);
  18. this.priceFormatted = this.formatCents(this.price);
  19. }
  20. this.allLinks = props.links || [];
  21. this.userLinks = this.allLinks.filter(x => !x.rel.startsWith('.'));
  22. this.systemLinks = this.allLinks.filter(x => x.rel.startsWith('.'));
  23. this.fromTarget = this.allLinks.filter(x => x.rel === '.from').map(x => x.target)[0];
  24. this.toTarget = this.allLinks.filter(x => x.rel === '.to').map(x => x.target)[0];
  25. this.fromContactId = this.allLinks.filter(x => x.rel === '.from-contact-id').map(x => x.target)[0];
  26. this.toContactId = this.allLinks.filter(x => x.rel === '.to-contact-id').map(x => x.target)[0];
  27. this.media = this.allLinks.filter(x => x.rel === '.media').map(x => x.target)[0];
  28. this.relTargets = this.allLinks.reduce((accum, link) => {
  29. accum[link.rel] = link.target;
  30. return accum;
  31. }, {});
  32. if (this.fromTarget && this.toTarget && this.media) {
  33. this.repliable = true;
  34. }
  35. else {
  36. this.repliable = false;
  37. }
  38. }
  39. formatCents(price) {
  40. if (price == null || price === 0) {
  41. return 'free';
  42. }
  43. let dollars = `${price / 100}`;
  44. if (dollars.match(/\..$/)) {
  45. dollars += '0';
  46. }
  47. return '$' + dollars;
  48. }
  49. }
  50. exports.ContentItem = ContentItem;
  51. //# sourceMappingURL=content-item.js.map