diff --git a/AIDataForm/AIDataForm.csproj b/AIDataForm/AIDataForm.csproj
index 9c9194b..7159340 100644
--- a/AIDataForm/AIDataForm.csproj
+++ b/AIDataForm/AIDataForm.csproj
@@ -59,8 +59,9 @@
-
-
+
+
+
@@ -71,12 +72,12 @@
-
- MSBuild:Compile
-
-
- MSBuild:Compile
-
+
+ MSBuild:Compile
+
+
+ MSBuild:Compile
+
diff --git a/AIDataForm/Behavior/DataFormAssistViewBehavior.cs b/AIDataForm/Behavior/DataFormAssistViewBehavior.cs
index 81144f3..ad3cfbf 100644
--- a/AIDataForm/Behavior/DataFormAssistViewBehavior.cs
+++ b/AIDataForm/Behavior/DataFormAssistViewBehavior.cs
@@ -21,7 +21,8 @@ public class DataFormAssistViewBehavior : Behavior
private string[] OfflineFormSuggestions =
[
"Contact Form",
- "Feedback Form"
+ "Feedback Form",
+ "Employment Details"
];
///
@@ -31,7 +32,14 @@ public class DataFormAssistViewBehavior : Behavior
[
"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",
];
///
@@ -40,7 +48,7 @@ public class DataFormAssistViewBehavior : Behavior
private string[] FeedbackFormActions =
[
"Remove Product Version",
- "Change Tittle as Feedback Form",
+ "Change Title as Feedback Form",
];
///
@@ -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;
@@ -154,6 +160,7 @@ protected override void OnAttachedTo(SfAIAssistView assistView)
{
Entry.TextChanged += Entry_TextChanged;
}
+
}
private void Entry_TextChanged(object? sender, TextChangedEventArgs e)
@@ -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()
{
@@ -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;
}
}
@@ -279,14 +260,24 @@ protected override void OnDetachingFrom(SfAIAssistView assistView)
///
/// The sender.
/// The event args.
- 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;
+ }
}
+
}
///
@@ -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])
{
@@ -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])
{
@@ -364,10 +380,15 @@ 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])
{
@@ -375,9 +396,14 @@ private async Task CreateOfflineDataForm(string requestText)
}
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()
@@ -401,6 +427,24 @@ private void InitializeOfflineContactDataForm()
}
}
+ private void InitializeOfflineEmployeeDetails()
+ {
+ ObservableCollection dataFormViewItems = new ObservableCollection
+ {
+ 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 dataFormViewItems = new ObservableCollection
@@ -485,6 +529,19 @@ private AssistItemSuggestion GetContactFormSuggestion()
return chatSubjectSuggestions;
}
+ private AssistItemSuggestion GetEmployeeDetailsSuggestion()
+ {
+ var chatSubjectSuggestions = new AssistItemSuggestion();
+ var contactSuggestions = new ObservableCollection
+ {
+ 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();
@@ -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")
{
diff --git a/AIDataForm/DataFormDesktopUI.xaml b/AIDataForm/DataFormDesktopUI.xaml
index 0a4491d..3a4bc7f 100644
--- a/AIDataForm/DataFormDesktopUI.xaml
+++ b/AIDataForm/DataFormDesktopUI.xaml
@@ -8,104 +8,218 @@
xmlns:aiassistview="clr-namespace:Syncfusion.Maui.AIAssistView;assembly=Syncfusion.Maui.AIAssistView"
x:Class="AIDataForm.DataFormDesktopUI">
-
+
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+ FontAttributes="Bold" VerticalTextAlignment="Center"
+ HorizontalTextAlignment="Center"/>
+ Text="The Azure API key or endpoint is missing or incorrect. Please verify your credentials. Alternatively, you can continue using offline data. AI assistance is available for offline data form creation."/>
+ Grid.RowSpan="1"
+ Grid.Row="1"
+ ValidationMode="PropertyChanged"
+ LayoutType="TextInputLayout"
+ HorizontalOptions="Center">
+ FocusedStroke="{DynamicResource SfDataFormFocusedEditorStroke}"/>
-
+
-
+
-
-
+
+
+ Grid.Column="0"
+ FontSize="16"
+ FontFamily="Roboto-Medium"
+ Padding="16,0,0,0" VerticalTextAlignment="Center"
+ FontAttributes="Bold"
+ VerticalOptions="Center"/>
+
-
+
-
+
@@ -130,9 +244,9 @@
+ x:Name="busyIndicator"
+ IsRunning="False"
+ AnimationType="Cupertino" />
diff --git a/AIDataForm/DataFormDesktopUI.xaml.cs b/AIDataForm/DataFormDesktopUI.xaml.cs
index ca24d17..1caefb0 100644
--- a/AIDataForm/DataFormDesktopUI.xaml.cs
+++ b/AIDataForm/DataFormDesktopUI.xaml.cs
@@ -6,4 +6,16 @@ public DataFormDesktopUI()
{
InitializeComponent();
}
+
+ private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
+ {
+ var templateItem = (sender as Border)?.BindingContext as TemplateItem;
+ var bindingContext = this.ParentGrid.BindingContext as DataFormGeneratorModel;
+
+ if (templateItem != null && bindingContext != null)
+ {
+ entry.Text = templateItem.Description;
+ bindingContext.FormTitle = templateItem.Title;
+ }
+ }
}
diff --git a/AIDataForm/DataFormMobileUI.xaml b/AIDataForm/DataFormMobileUI.xaml
index eec19a8..cacecc8 100644
--- a/AIDataForm/DataFormMobileUI.xaml
+++ b/AIDataForm/DataFormMobileUI.xaml
@@ -10,122 +10,161 @@
xmlns:buttons="clr-namespace:Syncfusion.Maui.Buttons;assembly=Syncfusion.Maui.Buttons"
xmlns:aiassistview="clr-namespace:Syncfusion.Maui.AIAssistView;assembly=Syncfusion.Maui.AIAssistView">
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
+
+ FontAttributes="Bold" VerticalTextAlignment="Center"
+ HorizontalTextAlignment="Center"/>
+ Grid.RowSpan="1"
+ Grid.Row="1" AutoGenerateItems="False"
+ ValidationMode="PropertyChanged"
+ LayoutType="TextInputLayout"
+ HorizontalOptions="Center">
+ IsVisible="{Binding ShowSubmitButton}"
+ Grid.Row="3"
+ Text="Save"
+ CornerRadius="20"
+ FontSize="16"
+ Margin="20, 0, 20, 0"/>
-
-
-
-
+
+
+
+
+ Grid.Column="0"
+ FontSize="16"
+ FontFamily="Roboto-Medium"
+ Padding="16,0,0,0"
+ FontAttributes="Bold"
+ VerticalOptions="Center" />
-
+
-
+
-
+
+
+
+
+ x:Name="busyIndicator"
+ IsRunning="False"
+ AnimationType="Cupertino" />
diff --git a/AIDataForm/DataFormMobileUI.xaml.cs b/AIDataForm/DataFormMobileUI.xaml.cs
index 8f22f3f..ca5412f 100644
--- a/AIDataForm/DataFormMobileUI.xaml.cs
+++ b/AIDataForm/DataFormMobileUI.xaml.cs
@@ -6,4 +6,17 @@ public DataFormMobileUI()
{
InitializeComponent();
}
+
+ private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
+ {
+ var templateItem = (sender as Border)?.BindingContext as TemplateItem;
+ var bindingContext = this.ParentGrid.BindingContext as DataFormGeneratorModel;
+
+ if (templateItem != null && bindingContext != null)
+ {
+ entry.Text = templateItem.Description;
+ bindingContext.FormTitle = templateItem.Title;
+ }
+ }
+
}
\ No newline at end of file
diff --git a/AIDataForm/Model/DataFormGeneratorModel.cs b/AIDataForm/Model/DataFormGeneratorModel.cs
index ae4cfa0..c7403a3 100644
--- a/AIDataForm/Model/DataFormGeneratorModel.cs
+++ b/AIDataForm/Model/DataFormGeneratorModel.cs
@@ -11,20 +11,42 @@ namespace AIDataForm
///
public class DataFormGeneratorModel : INotifyPropertyChanged
{
- private bool showDataForm , showAssistView, showSubmitButton, showInputView, showOfflineLabel;
-
+ private bool showDataForm, showAssistView, showSubmitButton, showInputView, showOfflineLabel;
+
+ ///
+ /// Gets or sets the template title
+ ///
+ internal string? FormTitle { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
public DataFormGeneratorModel()
{
showInputView = true;
showOfflineLabel = true;
+
+ // Initialize Templates collection with sample data
+ Templates = new ObservableCollection
+ {
+ new TemplateItem { Font="\ue763", Title = "Contact Form", Description = "Create a form to capture user details." },
+ new TemplateItem { Font="\ue761", Title = "Employment Details", Description = "Create a form to capture employment details." },
+ new TemplateItem { Font="\ue73a", Title = "Feedback Form", Description = "Create a form to receive client feedback." }
+ };
}
+
+ ///
+ /// Gets or sets the collection of templates.
+ ///
+ public ObservableCollection Templates { get; set; }
+
///
/// Gets or sets the collection of messages of a conversation.
///
public ObservableCollection Messages { get; set; } = new ObservableCollection();
-
+
///
- /// Gets or sets the show header.
+ /// Gets or sets a value indicating whether the data form is visible.
///
public bool ShowDataForm
{
@@ -82,15 +104,23 @@ public bool ShowOfflineLabel
public event PropertyChangedEventHandler? PropertyChanged;
///
- /// Occurs when property is changed.
+ /// Occurs when a property is changed.
///
- /// changed property name
+ /// The name of the changed property.
public void RaisePropertyChanged(string propName)
{
- if (this.PropertyChanged != null)
- {
- this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
- }
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
+
+ }
+
+ ///
+ /// Represents a template item with title and description.
+ ///
+ public class TemplateItem
+ {
+ public string? Font { get; set; }
+ public string? Title { get; set; }
+ public string? Description { get; set; }
}
}