import { IInitiativeModel , IHubRequestOptions , IModelTemplate , cloneObject , createId , without , normalizeSolutionTemplateItem , propifyString , getProp } from "@esri/hub-common" ; import { getItemResources } from "@esri/arcgis-rest-portal" ; param { object } model param { IHubRequestOptions } hubRequestOptions export function convertInitiativeToTemplate ( model , hubRequestOptions ) { const templateItem = model . item ; const template = ( cloneObject ( model ) as any ) as IModelTemplate ; template . item = normalizeSolutionTemplateItem ( templateItem ) ; delete template . item . url ; delete template . item . extent ; delete template . item . properties . source ; delete template . item . properties . collaborationGroupId ; delete template . item . properties . contentGroupId ; delete template . item . properties . followersGroupId ; delete template . item . properties . groupId ; delete template . data . values . collaborationGroupId ; delete template . data . values . contentGroupId ; delete template . data . values . followersGroupId ; delete template . data . values . followerGroups ; delete template . data . values . openDataGroupId ; template . type = "Hub Initiative Template" ; template . key = `${ propifyString ( model . item . title ) }_${ createId ( "i" ) }` ; template . itemId = model . item . id ; template . item . typeKeywords = without ( template . item . typeKeywords , "hubInitiative" ) ; template . item . typeKeywords . push ( "hubInitiativeTemplate" ) ; if ( getProp ( template , "data.steps" ) && ! getProp ( template , "data.recommendedTemplates" ) ) { template . data . recommendedTemplates = template . data . steps . reduce ( ( acc , step ) => { const stepTmpl = step . templateIds || [ ] ; return acc . concat ( stepTmpl ) ; } , [ ] ) ; } return getItemResources ( template . itemId , hubRequestOptions ) . then ( response => { template . resources = response . resources . map ( ( e ) => e . resource ) ; return template ; } ) ; }