content-item.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.date) {
  11. this.date = new Date(props.date);
  12. }
  13. else {
  14. this.date = new Date();
  15. }
  16. if (props.myTags) {
  17. this.myTagsWithoutAll = props.myTags.filter(x => x !== 'all');
  18. }
  19. else {
  20. this.myTagsWithoutAll = [];
  21. }
  22. if (props.price != null && !isNaN(Number(props.price))) {
  23. this.price = Number(props.price);
  24. this.priceFormatted = this.formatCents(this.price);
  25. }
  26. this.allLinks = props.links || [];
  27. this.userLinks = this.allLinks.filter(x => !x.rel.startsWith('.'));
  28. this.systemLinks = this.allLinks.filter(x => x.rel.startsWith('.'));
  29. this.fromTarget = this.allLinks.filter(x => x.rel === '.from').map(x => x.target)[0];
  30. this.toTarget = this.allLinks.filter(x => x.rel === '.to').map(x => x.target)[0];
  31. this.fromContactId = this.allLinks.filter(x => x.rel === '.from-contact-id').map(x => x.target)[0];
  32. this.toContactId = this.allLinks.filter(x => x.rel === '.to-contact-id').map(x => x.target)[0];
  33. this.media = this.allLinks.filter(x => x.rel === '.media').map(x => x.target)[0];
  34. this.relTarget = this.allLinks.reduce((accum, link) => {
  35. accum[link.rel] = link.target;
  36. return accum;
  37. }, {});
  38. if (this.fromTarget && this.toTarget && this.media) {
  39. this.repliable = true;
  40. }
  41. else {
  42. this.repliable = false;
  43. }
  44. }
  45. formatCents(price) {
  46. if (price == null || price === 0) {
  47. return 'free';
  48. }
  49. let dollars = `${price / 100}`;
  50. if (dollars.match(/\..$/)) {
  51. dollars += '0';
  52. }
  53. return '$' + dollars;
  54. }
  55. }
  56. exports.ContentItem = ContentItem;
  57. //# sourceMappingURL=content-item.js.map