|
|
@@ -0,0 +1,65 @@
|
|
|
+import { ContentLink } from "./content-link";
|
|
|
+import { ContentParams } from "./content-params";
|
|
|
+
|
|
|
+export class ContentItem {
|
|
|
+
|
|
|
+ public data: ContentParams;
|
|
|
+ private id: string;
|
|
|
+ private type: string;
|
|
|
+
|
|
|
+ private myTagsWithoutAll: string[];
|
|
|
+ private allLinks: ContentLink[];
|
|
|
+ private userLinks: ContentLink[];
|
|
|
+ private systemLinks: ContentLink[];
|
|
|
+ private repliable: boolean;
|
|
|
+
|
|
|
+ private price?: number;
|
|
|
+ private priceFormatted?: string;
|
|
|
+ private fromTarget?: string;
|
|
|
+ private toTarget?: string;
|
|
|
+ private fromContactId?: string;
|
|
|
+ private toContactId?: string;
|
|
|
+ private media?: string;
|
|
|
+
|
|
|
+ constructor(props: ContentParams) {
|
|
|
+ this.data = props;
|
|
|
+ this.id = props.id;
|
|
|
+ this.type = props.type;
|
|
|
+
|
|
|
+ if (props.myTags) {
|
|
|
+ this.myTagsWithoutAll = props.myTags.filter(x => x !== 'all');
|
|
|
+ } else {
|
|
|
+ this.myTagsWithoutAll = [];
|
|
|
+ }
|
|
|
+ if (props.price != null && !isNaN(Number(props.price))) {
|
|
|
+ this.price = Number(props.price);
|
|
|
+ this.priceFormatted = this.formatCents(this.price);
|
|
|
+ }
|
|
|
+ this.allLinks = props.links;
|
|
|
+ this.userLinks = props.links.filter(x => !x.rel.startsWith('.'));
|
|
|
+ this.systemLinks = props.links.filter(x => x.rel.startsWith('.'));
|
|
|
+
|
|
|
+ this.fromTarget = props.links.filter(x => x.rel === '.from').map(x => x.target)[0];
|
|
|
+ this.toTarget = props.links.filter(x => x.rel === '.to').map(x => x.target)[0];
|
|
|
+ this.fromContactId = props.links.filter(x => x.rel === '.from-contact-id').map(x => x.target)[0];
|
|
|
+ this.toContactId = props.links.filter(x => x.rel === '.to-contact-id').map(x => x.target)[0];
|
|
|
+ this.media = props.links.filter(x => x.rel === '.media').map(x => x.target)[0];
|
|
|
+ if (this.fromTarget && this.toTarget && this.media) {
|
|
|
+ this.repliable = true;
|
|
|
+ } else {
|
|
|
+ this.repliable = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private formatCents(price: number) {
|
|
|
+ if (price == null || price === 0) {
|
|
|
+ return 'free';
|
|
|
+ }
|
|
|
+ let dollars = `${price / 100}`;
|
|
|
+ if (dollars.match(/\..$/)) {
|
|
|
+ dollars += '0';
|
|
|
+ }
|
|
|
+ return '$' + dollars;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|