Selaa lähdekoodia

survey engine&editor part4

ganahrhr 2 vuotta sitten
vanhempi
commit
3a326d7b01
3 muutettua tiedostoa jossa 18 lisäystä ja 13 poistoa
  1. 2 1
      Models/Survey.cs
  2. 1 1
      Pages/SurveyEditor.razor
  3. 15 11
      Pages/SurveyEditor.razor.cs

+ 2 - 1
Models/Survey.cs

@@ -32,7 +32,7 @@ namespace HyperCube.Models
             else
             {
                 stringSQL = $"UPDATE surveys " +
-                    $"SET eventid={EvenID}, name='{Name}', description='{Description}', deleted={Convert.ToInt32(IsDeleted)} " +
+                    $"SET eventid={EvenID}, name='{Name}', description='{Description}', deleted={Convert.ToInt32(IsDeleted)},  date_updated='{DateTime.Now:yyyy-MM-dd HH:mm:ss}' " +
                     $"WHERE id={ID}";
             }
 
@@ -172,6 +172,7 @@ namespace HyperCube.Models
         public DateTime DateUpdated { get; set; }
         public bool Required { get; set; } = true;
         public Dictionary<int, SurveyItemOption> SurveyItemOptions { get; set; } = new();
+        public List<KeyValuePair<int, SurveyItemOption>> SurveyItemOptionsSorted { get; set; } = new(); /// wrap for sorting
         public int AnswerID { get; set; } /// SurveyItemOption selected ID
         public bool IsNew { get; set; } = true;
         public bool IsDeleted { get; set; } = false;

+ 1 - 1
Pages/SurveyEditor.razor

@@ -36,7 +36,7 @@
                     <InputTextArea type="text" @bind-Value="item.Value.Text" placeholder="Введете текст вопроса" />
                 </div>
                 <div style="margin-left:20px">
-                    @foreach (var option in item.Value.SurveyItemOptions)
+                    @foreach (var option in item.Value.SurveyItemOptionsSorted)
                     {
                         if (!option.Value.IsDeleted)
                         {

+ 15 - 11
Pages/SurveyEditor.razor.cs

@@ -25,8 +25,7 @@ namespace HyperCube.Pages
         AccountModel _currentAccount;
         Survey _survey = new();
 
-        List<KeyValuePair<int, SurveyItem>> _sortedItems = new(); /// wrap for items sorting
-        List<KeyValuePair<int, SurveyItemOption>> _sortedOptions = new(); /// wrap for options sorting
+        List<KeyValuePair<int, SurveyItem>> _sortedItems = new(); /// wrap for items sorting        
 
         ModalInfo _modalInfo;
 
@@ -116,12 +115,14 @@ namespace HyperCube.Pages
             }
         }
 
-        void AddNewItem() => _survey.AddNewItem(_currentAccount.UUID);
-
-        void AddNewOption(int ItemID) => _survey.SurveyItems[ItemID].AddNewOption(_currentAccount.UUID);
-
         void NewSurvey() => NavigationManager.NavigateTo("surveyeditor", true);
 
+        void AddNewItem()
+        {
+            _survey.AddNewItem(_currentAccount.UUID);
+            SortItems();
+        }
+
         void ItemMove(int itemID, int step)
         {
             _survey.MoveItem(itemID, step);
@@ -132,6 +133,12 @@ namespace HyperCube.Pages
         {
             _survey.DeleteItem(itemID);
             SortItems();
+        }
+
+        void AddNewOption(int itemID)
+        {
+            _survey.SurveyItems[itemID].AddNewOption(_currentAccount.UUID);
+            SortOptions(itemID);
         } 
 
         void OptionMove(int itemID, int optionID, int step)
@@ -161,12 +168,9 @@ namespace HyperCube.Pages
 
         void SortOptions(int itemID)
         {
-            //Console.WriteLine($"SortOptions, itemID:{itemID}, SurveyItems.Count:{_survey.SurveyItems.Count}.");
-            //Console.WriteLine($"SurveyItemOptions.Count:{_survey.SurveyItems[itemID].SurveyItemOptions.Count}.");
-
             int optionPosition = 1;
-            _sortedOptions = _survey.SurveyItems[itemID].SurveyItemOptions.OrderBy(i => i.Value.Position).ToList();
-            foreach (var item in _sortedOptions) { item.Value.Position = optionPosition++; }
+            _survey.SurveyItems[itemID].SurveyItemOptionsSorted = _survey.SurveyItems[itemID].SurveyItemOptions.OrderBy(i => i.Value.Position).ToList();
+            foreach (var item in _survey.SurveyItems[itemID].SurveyItemOptionsSorted) { item.Value.Position = optionPosition++; }
         }
 
         async Task<AccountModel> GetCurrentAcc()