import * as React from 'react' ; import * as ReactDom from 'react-dom' ; import { Environment , EnvironmentType , Version } from '@microsoft/sp-core-library' ; import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base" ; import { IPropertyPaneConfiguration , PropertyPaneToggle } from "@microsoft/sp-property-pane" ; import IMyTimeAwayWebPartProps from './IMyTimeAwayWebPartProps' ; import { sp } from '../../pnp-preset' ; import { MyTimeAwayContainer , IMyTimeAwayContainerProps , IMyTimeAwayDataProvider , SharePointDataProvider , MockDataProvider , TimeAwayManager , Constants } from '../../libraries/index' ; export default class MyTimeAwayWebPart extends BaseClientSideWebPart < IMyTimeAwayWebPartProps > { private _isInitialized : boolean = false ; private _dataProvider : IMyTimeAwayDataProvider ; protected async onInit ( ) { sp . setup ( this . context ) ; this . context . statusRenderer . displayLoadingIndicator ( this . domElement , "Loading List" ) ; if ( Environment . type === EnvironmentType . Local ) { this . _dataProvider = new MockDataProvider ( this . context , Constants . TimeAwayListTitle , this . properties . normalWeekToggleField , Constants . Default_TimePeriod ) ; this . _isInitialized = true ; this . context . statusRenderer . clearLoadingIndicator ( this . domElement ) ; return super . onInit ( ) ; } else { this . _dataProvider = new SharePointDataProvider ( Constants . TimeAwayListTitle , this . properties . normalWeekToggleField , Constants . Default_TimePeriod ) ; return TimeAwayManager . checkSPListTimeAway ( this . context ) . then ( ( prop ) => { this . _isInitialized = prop . contentlistExists == true ; return super . onInit ( ) ; } , ( er ) => { return super . onInit ( ) ; } ) ; } } public render ( ) { const element = React . createElement ( MyTimeAwayContainer , { dataProvider : this . _dataProvider , period : Constants . Default_TimePeriod , context : this . context , isInitialized : this . _isInitialized } ) ; ReactDom . render ( element , this . domElement ) ; } protected get dataVersion ( ) : Version { return Version . parse ( '1.0' ) ; } protected getPropertyPaneConfiguration ( ) { return { pages : [ { groups : [ { groupFields : [ PropertyPaneToggle ( 'normalWeekToggleField' , { label : 'Use 5 day weeks' } ) ] } ] } ] } ; } protected onPropertyPaneFieldChanged ( propertyPath , oldValue , newValue ) { if ( propertyPath === 'normalWeekToggleField' ) { this . _dataProvider . updateWeekType ( newValue ) ; } super . onPropertyPaneFieldChanged ( propertyPath , oldValue , newValue ) ; } }