feat: Update dynamic poll web part to version 1.3.0 with enhanced field mapping and configurable title
- Bump version in package.json to 1.3.0 - Add new properties for field mapping in DynamicPollWebPart.manifest.json - Enhance DynamicPollWebPart.ts to support dynamic field mapping for polls and answers - Implement field loading and default application logic in PollDataService.ts - Update PollTypes.ts to include new interfaces for field mapping - Modify DynamicPollCollection.tsx to display configurable web part title - Update styles in DynamicPoll.module.scss for improved UI - Add localization strings for new properties in en-us.js and de-de.js - Update tests to reflect changes in data structure and functionality - Validate project structure and ensure all new features are accounted for
This commit is contained in:
@@ -34,6 +34,7 @@ try {
|
||||
}
|
||||
|
||||
Ensure-Field -List $polls -InternalName 'Question' -SchemaXml '<Field Type="Text" DisplayName="Question" Name="Question" StaticName="Question" Required="TRUE" />'
|
||||
Ensure-Field -List $polls -InternalName 'PollKey' -SchemaXml '<Field Type="Text" DisplayName="Poll key" Name="PollKey" StaticName="PollKey" Required="FALSE" MaxLength="255" EnforceUniqueValues="TRUE" Indexed="TRUE" />'
|
||||
|
||||
$legacyOptionsField = $null
|
||||
try { $legacyOptionsField = $polls.Fields.GetFieldByInternalName('Options') } catch { }
|
||||
@@ -71,6 +72,13 @@ try {
|
||||
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>'
|
||||
|
||||
foreach ($item in $polls.Items) {
|
||||
if ([string]::IsNullOrWhiteSpace([string]$item['PollKey'])) {
|
||||
$item['PollKey'] = ('Poll-{0}' -f $item.ID)
|
||||
$item.SystemUpdate($false)
|
||||
}
|
||||
}
|
||||
|
||||
$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)
|
||||
@@ -79,10 +87,41 @@ try {
|
||||
$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 'PollKey' -SchemaXml '<Field Type="Text" DisplayName="Poll key" Name="PollKey" StaticName="PollKey" Required="FALSE" MaxLength="255" Indexed="TRUE" />'
|
||||
Ensure-Field -List $answers -InternalName 'UserKey' -SchemaXml '<Field Type="Text" DisplayName="User key" Name="UserKey" StaticName="UserKey" Required="FALSE" MaxLength="255" Indexed="TRUE" />'
|
||||
Ensure-Field -List $answers -InternalName 'Answer' -SchemaXml '<Field Type="Text" DisplayName="Answer" Name="Answer" StaticName="Answer" Required="TRUE" MaxLength="255" />'
|
||||
|
||||
# A lookup cannot be distributed safely through the Content Type Hub because its target list ID
|
||||
# belongs to one site collection. Keep an existing legacy lookup readable, but stop requiring it.
|
||||
$legacyPollField = $null
|
||||
try { $legacyPollField = $answers.Fields.GetFieldByInternalName('Poll') } catch { }
|
||||
if ($legacyPollField -and $legacyPollField.Type -eq [Microsoft.SharePoint.SPFieldType]::Lookup) {
|
||||
$legacyPollField.Required = $false
|
||||
$legacyPollField.ShowInNewForm = $false
|
||||
$legacyPollField.ShowInEditForm = $false
|
||||
$legacyPollField.ShowInDisplayForm = $false
|
||||
$legacyPollField.Update()
|
||||
|
||||
}
|
||||
|
||||
foreach ($answerItem in $answers.Items) {
|
||||
$changed = $false
|
||||
if ($legacyPollField -and $legacyPollField.Type -eq [Microsoft.SharePoint.SPFieldType]::Lookup) {
|
||||
if ([string]::IsNullOrWhiteSpace([string]$answerItem['PollKey']) -and $null -ne $answerItem[$legacyPollField.Id]) {
|
||||
$lookup = New-Object Microsoft.SharePoint.SPFieldLookupValue([string]$answerItem[$legacyPollField.Id])
|
||||
$pollItem = $polls.GetItemById($lookup.LookupId)
|
||||
$answerItem['PollKey'] = [string]$pollItem['PollKey']
|
||||
$changed = $true
|
||||
}
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace([string]$answerItem['UserKey']) -and
|
||||
-not [string]::IsNullOrWhiteSpace([string]$answerItem['Title'])) {
|
||||
$answerItem['UserKey'] = [string]$answerItem['Title']
|
||||
$changed = $true
|
||||
}
|
||||
if ($changed) { $answerItem.SystemUpdate($false) }
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user