Skip to content

Commit

Permalink
UI review changes updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeyasri-Murugan committed Dec 5, 2024
1 parent 54350c9 commit 9a72b6c
Show file tree
Hide file tree
Showing 7 changed files with 507 additions and 216 deletions.
17 changes: 9 additions & 8 deletions AIDataForm/AIDataForm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.0.0" />
<PackageReference Update="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.0.0" />
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.1-preview.1.24570.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Syncfusion.Maui.AIAssistView" Version="*" />
Expand All @@ -71,12 +72,12 @@
</ItemGroup>

<ItemGroup>
<MauiXaml Update="DataFormDesktopUI.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="DataFormMobileUI.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="DataFormDesktopUI.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="DataFormMobileUI.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
150 changes: 107 additions & 43 deletions AIDataForm/Behavior/DataFormAssistViewBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class DataFormAssistViewBehavior : Behavior<SfAIAssistView>
private string[] OfflineFormSuggestions =
[
"Contact Form",
"Feedback Form"
"Feedback Form",
"Employment Details"
];

/// <summary>
Expand All @@ -31,7 +32,14 @@ public class DataFormAssistViewBehavior : Behavior<SfAIAssistView>
[
"Add Email",
"Remove Last Item",
"Change Tittle as User Details",
"Change Title as User Details",
];

private string[] EmployeeDetailsActions =
[
"Employee ID",
"Remove Last detail",
"Change Title as Employee registration",
];

/// <summary>
Expand All @@ -40,7 +48,7 @@ public class DataFormAssistViewBehavior : Behavior<SfAIAssistView>
private string[] FeedbackFormActions =
[
"Remove Product Version",
"Change Tittle as Feedback Form",
"Change Title as Feedback Form",
];

/// <summary>
Expand Down Expand Up @@ -122,8 +130,6 @@ protected override void OnAttachedTo(SfAIAssistView assistView)
this.assistView = assistView;
animation = new Animation();

UpdateVisibility();

if (this.assistView != null)
{
this.assistView.Request += this.OnAssistViewRequest;
Expand Down Expand Up @@ -154,6 +160,7 @@ protected override void OnAttachedTo(SfAIAssistView assistView)
{
Entry.TextChanged += Entry_TextChanged;
}

}

private void Entry_TextChanged(object? sender, TextChangedEventArgs e)
Expand All @@ -170,27 +177,6 @@ private void Entry_TextChanged(object? sender, TextChangedEventArgs e)
}
}
}
private void UpdateVisibility()
{
if (this.DataFormGeneratorModel != null)
{
if (azureOpenAIBaseService.IsCredentialValid)
{
this.DataFormGeneratorModel.ShowInputView = true;
this.DataFormGeneratorModel.ShowDataForm = false;
this.DataFormGeneratorModel!.Messages.Clear();
}
else
{
this.DataFormGeneratorModel.ShowInputView = false;
this.DataFormGeneratorModel.ShowDataForm = true;

AssistItemSuggestion assistItemSuggestion = this.GetSubjectSuggestion();
AssistItem assistItem = new AssistItem() { Text = "You are in offline mode. Please select one of the forms below.", Suggestion = assistItemSuggestion, ShowAssistItemFooter = false };
this.DataFormGeneratorModel!.Messages.Add(assistItem);
}
}
}

private async void StartAnimation()
{
Expand All @@ -214,13 +200,8 @@ private void RefreshButton_Clicked(object? sender, EventArgs e)
if (this.DataFormGeneratorModel != null)
{
this.DataFormGeneratorModel.Messages.Clear();

if (!azureOpenAIBaseService.IsCredentialValid)
{
AssistItemSuggestion assistItemSuggestion = this.GetSubjectSuggestion();
AssistItem assistItem = new AssistItem() { Text = "You are in offline mode. Please select one of the forms below.", Suggestion = assistItemSuggestion, ShowAssistItemFooter = false };
this.DataFormGeneratorModel!.Messages.Add(assistItem);
}
this.DataFormGeneratorModel.ShowInputView = true;
this.DataFormGeneratorModel.ShowDataForm = false;
}
}

Expand Down Expand Up @@ -279,14 +260,24 @@ protected override void OnDetachingFrom(SfAIAssistView assistView)
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The event args.</param>
private void OnCreateButtonClicked(object? sender, EventArgs e)
private async void OnCreateButtonClicked(object? sender, EventArgs e)
{
UpdateBusyIndicator(true);

if (azureOpenAIBaseService.IsCredentialValid)
if (Entry != null && DataFormGeneratorModel != null && DataFormGeneratorModel.FormTitle != null)
{
this.GetDataFormFromAI(this.Entry!.Text);
if (azureOpenAIBaseService.IsCredentialValid)
{
this.GetDataFormFromAI(this.Entry.Text);
}
else
{
await CreateOfflineDataForm(this.DataFormGeneratorModel.FormTitle);
DataFormGeneratorModel.ShowInputView = false;
DataFormGeneratorModel.ShowDataForm = true;
}
}

}

/// <summary>
Expand All @@ -307,14 +298,39 @@ private async void OnAssistViewRequest(object? sender, RequestEventArgs e)
await CreateOfflineDataForm(requestText);
}

private async Task CreateOfflineDataForm(string requestText)
internal async Task CreateOfflineDataForm(string requestText)
{
if (requestText == this.OfflineFormSuggestions[2])
{
offlineForm = "Employee Details";
this.InitializeOfflineEmployeeDetails();
this.ChangeDataFormTitle(this.OfflineFormSuggestions[2]);
await this.AddMessageWithDelayAsync("You are in offline mode. Please select your action below...", this.GetEmployeeDetailsSuggestion());
}
else if (requestText == this.EmployeeDetailsActions[0])
{
this.DataForm!.Items.Add(new DataFormTextItem() { FieldName = "Employee Id", Keyboard = Keyboard.Text });
await this.AddMessageWithDelayAsync("The Employee id editor added successfully.");
await this.AddMessageWithDelayAsync("Do you want to edit..?", this.GetYesOrNoSuggestions());
}
else if (requestText == this.EmployeeDetailsActions[1])
{
this.DataForm!.Items.RemoveAt(this.DataForm!.Items.Count - 1);
await this.AddMessageWithDelayAsync("The last item removed successfully.");
await AddMessageWithDelayAsync("Do you want to edit..?", this.GetYesOrNoSuggestions());
}
else if (requestText == this.EmployeeDetailsActions[2])
{
this.ChangeDataFormTitle("Employee Registration");
await this.AddMessageWithDelayAsync("The title has changed successfully.");
await this.AddMessageWithDelayAsync("Do you want to edit..?", this.GetYesOrNoSuggestions());
}
if (requestText == this.OfflineFormSuggestions[0])
{
offlineForm = "ConatctForm";
this.InitializeOfflineContactDataForm();
this.ChangeDataFormTitle(this.OfflineFormSuggestions[0]);
await this.AddMessageWithDelayAsync("Please select your action below...", this.GetContactFormSuggestion());
await this.AddMessageWithDelayAsync("You are in offline mode. Please select your action below...", this.GetContactFormSuggestion());
}
else if (requestText == this.ContactFormActions[0])
{
Expand All @@ -339,7 +355,7 @@ private async Task CreateOfflineDataForm(string requestText)
offlineForm = "FeedbackForm";
this.InitializeOfflineFeedbackDataForm();
this.ChangeDataFormTitle("Product feedback");
await this.AddMessageWithDelayAsync("Please select your action below...", this.GetFeedbackFormSuggestion());
await this.AddMessageWithDelayAsync("You are in offline mode. Please select your action below...", this.GetFeedbackFormSuggestion());
}
else if (requestText == this.FeedbackFormActions[0])
{
Expand All @@ -364,20 +380,30 @@ private async Task CreateOfflineDataForm(string requestText)
{
await this.AddMessageWithDelayAsync("Please select any of the action below...", this.GetFeedbackFormSuggestion());
}
else
else if (offlineForm == "ConatctForm")
{
await this.AddMessageWithDelayAsync("Please select any of the action below...", this.GetContactFormSuggestion());
}
else
{
await this.AddMessageWithDelayAsync("Please select any of the action below...", this.GetEmployeeDetailsSuggestion());
}

}
else if (requestText == this.YesOrNoSuggestions[1])
{
await this.AddMessageWithDelayAsync("Thank you..!");
}
else if (requestText == this.YesOrNoSuggestions[2])
{
await this.AddMessageWithDelayAsync("You are offline. Please select any other form...");
await this.AddMessageWithDelayAsync("Please select any of the forms below...", this.GetSubjectSuggestion());
if (this.DataFormGeneratorModel != null)
{
this.DataFormGeneratorModel.Messages.Clear();
this.DataFormGeneratorModel.ShowDataForm = false;
this.DataFormGeneratorModel.ShowInputView = true;
}
}
UpdateBusyIndicator(false);
}

private void InitializeOfflineContactDataForm()
Expand All @@ -401,6 +427,24 @@ private void InitializeOfflineContactDataForm()
}
}

private void InitializeOfflineEmployeeDetails()
{
ObservableCollection<DataFormViewItem> dataFormViewItems = new ObservableCollection<DataFormViewItem>
{
new DataFormTextItem() { FieldName = "FirstName", LabelText = "First Name" },
new DataFormTextItem() { FieldName = "LastName", LabelText="Last Name" },
new DataFormTextItem() { FieldName = "Designation", },
new DataFormTextItem() { FieldName = "Experience", },
new DataFormTextItem() { FieldName = "Mobile", },
};
this.DataForm!.Items = dataFormViewItems;
if (this.DataFormGeneratorModel != null)
{
this.DataFormGeneratorModel.ShowSubmitButton = true;
this.DataFormGeneratorModel.ShowOfflineLabel = false;
}
}

private void InitializeOfflineFeedbackDataForm()
{
ObservableCollection<DataFormViewItem> dataFormViewItems = new ObservableCollection<DataFormViewItem>
Expand Down Expand Up @@ -485,6 +529,19 @@ private AssistItemSuggestion GetContactFormSuggestion()
return chatSubjectSuggestions;
}

private AssistItemSuggestion GetEmployeeDetailsSuggestion()
{
var chatSubjectSuggestions = new AssistItemSuggestion();
var contactSuggestions = new ObservableCollection<ISuggestion>
{
new AssistSuggestion() { Text = EmployeeDetailsActions[0] },
new AssistSuggestion() { Text = EmployeeDetailsActions[1] },
new AssistSuggestion() { Text = EmployeeDetailsActions[2] }
};
chatSubjectSuggestions.Items = contactSuggestions;
return chatSubjectSuggestions;
}

private AssistItemSuggestion GetFeedbackFormSuggestion()
{
var chatSubjectSuggestions = new AssistItemSuggestion();
Expand Down Expand Up @@ -538,7 +595,14 @@ internal async void GetDataFormFromAI(string userPrompt)
if (response == string.Empty)
{
UpdateBusyIndicator(false);
await App.Current.MainPage.DisplayAlert("", "Please enter valid inputs.", "OK");
if (Application.Current != null)
{
var mainWindow = Application.Current.Windows.FirstOrDefault();
if (mainWindow != null && mainWindow.Page != null)
{
await mainWindow.Page.DisplayAlert("", "Please enter valid inputs.", "OK");
}
}
}
else if (response == "New Form")
{
Expand Down
Loading

0 comments on commit 9a72b6c

Please sign in to comment.