{ "version": 3, "sources": ["apps/partner-center-client/src/app/core/wordpress-content.service.ts"], "sourcesContent": ["import { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { Environment, EnvironmentService } from '@galaxy/core';\nimport { BehaviorSubject, Observable } from 'rxjs';\nimport { map } from 'rxjs/operators';\n\n/*\nWordpressContentService loads data from a WebsitePro site defined by the URL set in loadContent.\nUsually the account that hosts this site is on partner VCOR, Account Group ID AG-NP378DRWL2 or AG-J7CT2Z8R.\n\nThe site uses two plugins to create ad metadata: Meta Box and MB Rest API.\n\nTo create, update, or remove a field from the metadata, edit the Meta Box plugin and locate `meta-box/inc/functions.php`.\nAt the bottom of this file, the metaboxes are defined and can be edited to your liking.\nAdditional documentation for field definition can be found at https://metabox.io/docs/define-fields/\n */\n\nexport interface WordpressContentItem {\n id: string;\n bgColor: string;\n bgImage?: string;\n titleHtml?: string;\n descTextHtml: string;\n primaryButtonLink: string;\n primaryButtonText: string;\n}\n\n@Injectable({ providedIn: 'root' })\nexport class WordpressContentService {\n contentSubject = new BehaviorSubject(null);\n\n constructor(\n private http: HttpClient,\n private environmentService: EnvironmentService,\n ) {}\n\n get content(): Observable {\n return this.contentSubject.asObservable();\n }\n\n loadContent(contentUrl?: string): void {\n const env = this.environmentService.getEnvironment();\n this.contentSubject.next(null);\n if (!contentUrl) {\n contentUrl = this.getProductAdsListUrl(env);\n }\n this.http\n .get(contentUrl)\n .pipe(\n map((res) => {\n return res.map((contentData) => this.toContent(contentData));\n }),\n )\n .subscribe((ads) => this.contentSubject.next(ads));\n }\n\n private getProductAdsListUrl(env: Environment) {\n return `https://${\n env === Environment.PROD ? 'product-ads.websitepro.hosting' : 'product-ads.websitepro-staging.com'\n }/wp-json/wp/v2/posts?_embed=1&status=publish&categories=1`;\n }\n\n private toContent(data: any): WordpressContentItem {\n const item = {} as WordpressContentItem;\n if (data.title) {\n item.titleHtml = data.title.rendered;\n }\n if (data.content) {\n item.descTextHtml = data.content.rendered;\n }\n if (data.meta_box) {\n item.id = data.meta_box.id;\n item.bgColor = data.meta_box.color;\n item.primaryButtonText = data.meta_box.buttonText;\n item.primaryButtonLink = data.meta_box.buttonLink;\n }\n /* tslint:disable:no-string-literal */\n if (data._embedded['wp:featuredmedia'] && data._embedded['wp:featuredmedia'].length) {\n item.bgImage = data._embedded['wp:featuredmedia'][0].source_url;\n }\n return item;\n }\n}\n"], "mappings": "iJA4BA,IAAaA,GAAuB,IAAA,CAA9B,IAAOA,EAAP,MAAOA,CAAuB,CAGlCC,YACUC,EACAC,EAAsC,CADtC,KAAAD,KAAAA,EACA,KAAAC,mBAAAA,EAJV,KAAAC,eAAiB,IAAIC,EAAwC,IAAI,CAK9D,CAEH,IAAIC,SAAO,CACT,OAAO,KAAKF,eAAeG,aAAY,CACzC,CAEAC,YAAYC,EAAmB,CAC7B,IAAMC,EAAM,KAAKP,mBAAmBQ,eAAc,EAClD,KAAKP,eAAeQ,KAAK,IAAI,EACxBH,IACHA,EAAa,KAAKI,qBAAqBH,CAAG,GAE5C,KAAKR,KACFY,IAAWL,CAAU,EACrBM,KACCC,EAAKC,GACIA,EAAID,IAAKE,GAAgB,KAAKC,UAAUD,CAAW,CAAC,CAC5D,CAAC,EAEHE,UAAWC,GAAQ,KAAKjB,eAAeQ,KAAKS,CAAG,CAAC,CACrD,CAEQR,qBAAqBH,EAAgB,CAC3C,MAAO,WACLA,IAAQY,EAAYC,KAAO,iCAAmC,oCAChE,2DACF,CAEQJ,UAAUK,EAAS,CACzB,IAAMC,EAAO,CAAA,EACb,OAAID,EAAKE,QACPD,EAAKE,UAAYH,EAAKE,MAAME,UAE1BJ,EAAKlB,UACPmB,EAAKI,aAAeL,EAAKlB,QAAQsB,UAE/BJ,EAAKM,WACPL,EAAKM,GAAKP,EAAKM,SAASC,GACxBN,EAAKO,QAAUR,EAAKM,SAASG,MAC7BR,EAAKS,kBAAoBV,EAAKM,SAASK,WACvCV,EAAKW,kBAAoBZ,EAAKM,SAASO,YAGrCb,EAAKc,UAAU,kBAAkB,GAAKd,EAAKc,UAAU,kBAAkB,EAAEC,SAC3Ed,EAAKe,QAAUhB,EAAKc,UAAU,kBAAkB,EAAE,CAAC,EAAEG,YAEhDhB,CACT,yCArDWzB,GAAuB0C,EAAAC,CAAA,EAAAD,EAAAE,CAAA,CAAA,CAAA,wBAAvB5C,EAAuB6C,QAAvB7C,EAAuB8C,UAAAC,WADV,MAAM,CAAA,EAC1B,IAAO/C,EAAPgD,SAAOhD,CAAuB,GAAA", "names": ["WordpressContentService", "constructor", "http", "environmentService", "contentSubject", "BehaviorSubject", "content", "asObservable", "loadContent", "contentUrl", "env", "getEnvironment", "next", "getProductAdsListUrl", "get", "pipe", "map", "res", "contentData", "toContent", "subscribe", "ads", "Environment", "PROD", "data", "item", "title", "titleHtml", "rendered", "descTextHtml", "meta_box", "id", "bgColor", "color", "primaryButtonText", "buttonText", "primaryButtonLink", "buttonLink", "_embedded", "length", "bgImage", "source_url", "\u0275\u0275inject", "HttpClient", "EnvironmentService", "factory", "\u0275fac", "providedIn", "_WordpressContentService"] }