import { getProp , cloneObject } from "@esri/hub-common" ; import { IInitiativeModel } from "@esri/hub-common" ; param model param portalUrl protected export function upgradeToOneDotOne ( model , portalUrl ? ) { const curVersion = getProp ( model , "item.properties.schemaVersion" ) ; if ( curVersion < 1.1 ) { const clone = cloneObject ( model ) as IInitiativeModel ; clone . item . properties . schemaVersion = 1.1 ; addDefaultResources ( clone , portalUrl ) ; if ( ! clone . data . values . bannerImage ) { clone . data . values . bannerImage = { source : "bannerImage" , display : { position : { x : "50%" , y : "10%" } } } ; } return clone ; } else { return model ; } } protected param { IInitiativeModel } model param { string } portalUrl returns { IInitiativeModel } export function addDefaultResources ( model , portalUrl ? ) { if ( ! model . data . assets ) { model . data . assets = [ { id : "bannerImage" , url : getResourceUrl ( model . item . id , "detail-image.jpg" , portalUrl ) , properties : { type : "resource" , fileName : "detail-image.jpg" , mimeType : "image/jepg" } , license : { type : "none" } } , { id : "iconDark" , url : getResourceUrl ( model . item . id , "icon-dark.png" , portalUrl ) , properties : { type : "resource" , fileName : "icon-dark.png" , mimeType : "image/png" } , license : { type : "none" } } , { id : "iconLight" , url : getResourceUrl ( model . item . id , "icon-light.png" , portalUrl ) , properties : { type : "resource" , fileName : "icon-light.png" , mimeType : "image/png" } , license : { type : "none" } } ] ; } return model ; } protected param { string } itemId param { string } resourceName param { string } portal param { string } folder returns { string } export function getResourceUrl ( itemId , resourceName , portal ? , folder ? ) { const portalUrl = portal || "https://www.arcgis.com/sharing/rest" ; let url = `${ portalUrl }/content/items/${ itemId }/resources` ; if ( folder ) { url = `${ url }/${ folder }/${ resourceName }` ; } else { url = `${ url }/${ resourceName }` ; } return url ; }