Add Dynamic Poll Web Part with core functionality and styling
- Initialize Gulp build process with gulpfile.js - Create package.json for project dependencies and scripts - Add TypeScript declarations for SCSS modules - Implement DynamicPollWebPart with property pane configuration - Create PollDataService for SharePoint list interactions - Develop core polling logic in PollCore.ts - Define types for polls and answers in PollTypes.ts - Create React components for DynamicPoll UI - Add localization support for English and German - Implement unit tests for core polling functionality - Set up TypeScript and TSLint configurations
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$SiteUrl,
|
||||
|
||||
[string]$PollListTitle = 'Polls',
|
||||
|
||||
[string]$AnswerListTitle = 'Poll Answers'
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Ensure-Field {
|
||||
param(
|
||||
[Microsoft.SharePoint.SPList]$List,
|
||||
[string]$InternalName,
|
||||
[string]$SchemaXml
|
||||
)
|
||||
|
||||
if (-not $List.Fields.ContainsField($InternalName)) {
|
||||
[void]$List.Fields.AddFieldAsXml($SchemaXml, $true, [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldInternalNameHint)
|
||||
$List.Update()
|
||||
}
|
||||
}
|
||||
|
||||
$web = Get-SPWeb -Identity $SiteUrl
|
||||
try {
|
||||
$polls = $web.Lists.TryGetList($PollListTitle)
|
||||
if (-not $polls) {
|
||||
$listId = $web.Lists.Add($PollListTitle, 'Questions and options for the Dynamic Poll web part.', [Microsoft.SharePoint.SPListTemplateType]::GenericList)
|
||||
$polls = $web.Lists[$listId]
|
||||
$polls.OnQuickLaunch = $true
|
||||
$polls.Update()
|
||||
}
|
||||
|
||||
Ensure-Field -List $polls -InternalName 'Question' -SchemaXml '<Field Type="Text" DisplayName="Question" Name="Question" StaticName="Question" Required="TRUE" />'
|
||||
Ensure-Field -List $polls -InternalName 'Options' -SchemaXml '<Field Type="MultiChoice" DisplayName="Options" Name="Options" StaticName="Options" Required="TRUE" FillInChoice="TRUE"><CHOICES><CHOICE>Option 1</CHOICE><CHOICE>Option 2</CHOICE></CHOICES></Field>'
|
||||
Ensure-Field -List $polls -InternalName 'StartDate' -SchemaXml '<Field Type="DateTime" DisplayName="Start date" Name="StartDate" StaticName="StartDate" Format="DateTime" />'
|
||||
Ensure-Field -List $polls -InternalName 'EndDate' -SchemaXml '<Field Type="DateTime" DisplayName="End date" Name="EndDate" StaticName="EndDate" Format="DateTime" />'
|
||||
Ensure-Field -List $polls -InternalName 'IsActive' -SchemaXml '<Field Type="Boolean" DisplayName="Active" Name="IsActive" StaticName="IsActive"><Default>0</Default></Field>'
|
||||
|
||||
$answers = $web.Lists.TryGetList($AnswerListTitle)
|
||||
if (-not $answers) {
|
||||
$listId = $web.Lists.Add($AnswerListTitle, 'Votes submitted through the Dynamic Poll web part.', [Microsoft.SharePoint.SPListTemplateType]::GenericList)
|
||||
$answers = $web.Lists[$listId]
|
||||
$answers.OnQuickLaunch = $false
|
||||
$answers.Update()
|
||||
}
|
||||
|
||||
$pollListId = $polls.ID.ToString('B')
|
||||
Ensure-Field -List $answers -InternalName 'Poll' -SchemaXml (('<Field Type="Lookup" DisplayName="Poll" Name="Poll" StaticName="Poll" List="{0}" ShowField="Title" Required="TRUE" />' -f $pollListId))
|
||||
Ensure-Field -List $answers -InternalName 'Answer' -SchemaXml '<Field Type="Text" DisplayName="Answer" Name="Answer" StaticName="Answer" Required="TRUE" MaxLength="255" />'
|
||||
|
||||
Write-Host ('Dynamic Poll lists are ready at {0}' -f $web.Url) -ForegroundColor Green
|
||||
Write-Host ('Poll list: {0} ({1})' -f $polls.Title, $polls.ID)
|
||||
Write-Host ('Answer list: {0} ({1})' -f $answers.Title, $answers.ID)
|
||||
}
|
||||
finally {
|
||||
if ($web) { $web.Dispose() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user