import { IInitiativeModel } from "@esri/hub-common" ; import { getProp , cloneObject } from "@esri/hub-common" ; protected param { IInitiativeModel } model param { string } portalUrl returns { IInitiativeModel } export function applyInitialSchema ( model , portalUrl ? ) { const curVersion = getProp ( model , "item.properties.schemaVersion" ) ; if ( ! curVersion || curVersion < 1 ) { const clone = cloneObject ( model ) as IInitiativeModel ; if ( ! clone . data . values ) { clone . data . values = { } ; } if ( ! clone . item . properties ) { clone . item . properties = { } ; } clone . item . properties . schemaVersion = 1.0 ; let isTemplate = false ; if ( clone . item . typeKeywords ) { isTemplate = clone . item . typeKeywords . indexOf ( "hubInitiativeTemplate" ) >= 0 ; } const hasParent = ! ! clone . data . source ; if ( hasParent && clone . item . properties . source !== clone . data . source ) { clone . item . properties . source = clone . data . source ; } if ( clone . data . configurationSettings ) { const config = cloneObject ( clone . data . configurationSettings ) ; delete clone . data . configurationSettings ; const stepCategory = config . find ( ( el ) => { return el . category === "Steps" ; } ) ; clone . data . values . steps = stepCategory . fields . map ( ( entry ) => { return entry . fieldName ; } ) ; stepCategory . fields . forEach ( ( entry ) => { if ( ! clone . data . values [ entry . fieldName ] ) { clone . data . values [ entry . fieldName ] = { } ; } clone . data . values [ entry . fieldName ] . title = entry . label ; clone . data . values [ entry . fieldName ] . description = entry . tooltip ; clone . data . values [ entry . fieldName ] . id = entry . fieldName ; if ( clone . data . values [ entry . fieldName ] . items ) { if ( isTemplate ) { clone . data . values [ entry . fieldName ] . templates = clone . data . values [ entry . fieldName ] . items ; delete clone . data . values [ entry . fieldName ] . items ; } } else { clone . data . values [ entry . fieldName ] . items = [ ] ; clone . data . values [ entry . fieldName ] . templates = [ ] ; } } ) ; } return clone ; } else { return model ; } }