|
@@ -25,6 +25,9 @@ namespace HyperCube.Pages
|
|
AccountModel _currentAccount;
|
|
AccountModel _currentAccount;
|
|
Survey _survey = new();
|
|
Survey _survey = new();
|
|
|
|
|
|
|
|
+ List<KeyValuePair<int, SurveyItem>> _sortedItems = new(); /// wrap for items sorting
|
|
|
|
+ List<KeyValuePair<int, SurveyItemOption>> _sortedOptions = new(); /// wrap for options sorting
|
|
|
|
+
|
|
ModalInfo _modalInfo;
|
|
ModalInfo _modalInfo;
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
protected override async Task OnInitializedAsync()
|
|
@@ -51,11 +54,15 @@ namespace HyperCube.Pages
|
|
}
|
|
}
|
|
|
|
|
|
SurveyItem item;
|
|
SurveyItem item;
|
|
- SurveyItemOption option;
|
|
|
|
|
|
+ SurveyItemOption option;
|
|
|
|
+ int itemPosition = 1;
|
|
|
|
+ int optionPosition = 1;
|
|
|
|
|
|
var surveyItems = await MySQLConnector.Instance().SQLSelectComplex($"SELECT * FROM surveyitems WHERE surveyid={_survey.ID} AND deleted<>1 ORDER BY position");
|
|
var surveyItems = await MySQLConnector.Instance().SQLSelectComplex($"SELECT * FROM surveyitems WHERE surveyid={_survey.ID} AND deleted<>1 ORDER BY position");
|
|
if (surveyItems.Count > 0)
|
|
if (surveyItems.Count > 0)
|
|
{
|
|
{
|
|
|
|
+ Console.WriteLine($"surveyItems.Count={surveyItems.Count}");
|
|
|
|
+
|
|
foreach (var i in surveyItems)
|
|
foreach (var i in surveyItems)
|
|
{
|
|
{
|
|
item = new()
|
|
item = new()
|
|
@@ -66,15 +73,18 @@ namespace HyperCube.Pages
|
|
DateUpdated = Convert.ToDateTime(i["date_updated"]),
|
|
DateUpdated = Convert.ToDateTime(i["date_updated"]),
|
|
CreatorID = Convert.ToString(i["creatorid"]),
|
|
CreatorID = Convert.ToString(i["creatorid"]),
|
|
Text = Convert.ToString(i["itemtext"]),
|
|
Text = Convert.ToString(i["itemtext"]),
|
|
- Position = Convert.ToInt32(i["position"]),
|
|
|
|
|
|
+ //Position = Convert.ToInt32(i["position"]),
|
|
|
|
+ Position = itemPosition++,
|
|
Required = Convert.ToBoolean(i["required"]),
|
|
Required = Convert.ToBoolean(i["required"]),
|
|
IsNew = false
|
|
IsNew = false
|
|
};
|
|
};
|
|
- Console.WriteLine($"SurveyEditor. load survey items id: {item.ID}, position: {item.Position}, name: {item.Text}");
|
|
|
|
|
|
+ Console.WriteLine($"SurveyEditor. load survey [{item.SurveyID}] item id: {item.ID}, position: {item.Position}, name: {item.Text}");
|
|
|
|
|
|
var surveyItemOption = await MySQLConnector.Instance().SQLSelectComplex($"SELECT * FROM surveyitemoptions WHERE itemid={item.ID} AND deleted<>1 ORDER BY position");
|
|
var surveyItemOption = await MySQLConnector.Instance().SQLSelectComplex($"SELECT * FROM surveyitemoptions WHERE itemid={item.ID} AND deleted<>1 ORDER BY position");
|
|
if (surveyItemOption.Count > 0)
|
|
if (surveyItemOption.Count > 0)
|
|
{
|
|
{
|
|
|
|
+ Console.WriteLine($"surveyItemOption.Count={surveyItemOption.Count}");
|
|
|
|
+
|
|
foreach (var o in surveyItemOption)
|
|
foreach (var o in surveyItemOption)
|
|
{
|
|
{
|
|
option = new()
|
|
option = new()
|
|
@@ -85,21 +95,24 @@ namespace HyperCube.Pages
|
|
DateUpdated = Convert.ToDateTime(o["date_updated"]),
|
|
DateUpdated = Convert.ToDateTime(o["date_updated"]),
|
|
CreatorID = Convert.ToString(o["creatorid"]),
|
|
CreatorID = Convert.ToString(o["creatorid"]),
|
|
Text = Convert.ToString(o["optiontext"]),
|
|
Text = Convert.ToString(o["optiontext"]),
|
|
- Position = Convert.ToInt32(o["position"]),
|
|
|
|
|
|
+ //Position = Convert.ToInt32(o["position"]),
|
|
|
|
+ Position = optionPosition++,
|
|
Rate1 = Convert.ToInt32(o["rate1"]),
|
|
Rate1 = Convert.ToInt32(o["rate1"]),
|
|
Rate2 = Convert.ToInt32(o["rate2"]),
|
|
Rate2 = Convert.ToInt32(o["rate2"]),
|
|
Rate3 = Convert.ToInt32(o["rate3"]),
|
|
Rate3 = Convert.ToInt32(o["rate3"]),
|
|
Rate4 = Convert.ToInt32(o["rate4"]),
|
|
Rate4 = Convert.ToInt32(o["rate4"]),
|
|
IsNew = false
|
|
IsNew = false
|
|
};
|
|
};
|
|
- Console.WriteLine($"SurveyEditor. load survey item option id: {option.ID}, position: {option.Position}, name: {option.Text}.");
|
|
|
|
|
|
+ Console.WriteLine($"SurveyEditor. load survey [{item.SurveyID}] item [{item.ID}] option id: {option.ID}, position: {option.Position}, name: {option.Text}.");
|
|
|
|
|
|
item.SurveyItemOptions.Add(option.ID, option);
|
|
item.SurveyItemOptions.Add(option.ID, option);
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
_survey.SurveyItems.Add(item.ID, item);
|
|
_survey.SurveyItems.Add(item.ID, item);
|
|
|
|
+ SortOptions(item.ID);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ SortItems();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -112,20 +125,25 @@ namespace HyperCube.Pages
|
|
void ItemMove(int itemID, int step)
|
|
void ItemMove(int itemID, int step)
|
|
{
|
|
{
|
|
_survey.MoveItem(itemID, step);
|
|
_survey.MoveItem(itemID, step);
|
|
|
|
+ SortItems();
|
|
}
|
|
}
|
|
|
|
|
|
void ItemDelete(int itemID)
|
|
void ItemDelete(int itemID)
|
|
{
|
|
{
|
|
_survey.DeleteItem(itemID);
|
|
_survey.DeleteItem(itemID);
|
|
- //StateHasChanged();
|
|
|
|
- }
|
|
|
|
|
|
+ SortItems();
|
|
|
|
+ }
|
|
|
|
|
|
- void OptionMove()
|
|
|
|
|
|
+ void OptionMove(int itemID, int optionID, int step)
|
|
{
|
|
{
|
|
|
|
+ _survey.SurveyItems[itemID].MoveItem(optionID, step);
|
|
|
|
+ SortOptions(itemID);
|
|
}
|
|
}
|
|
|
|
|
|
- void OptionDelete()
|
|
|
|
|
|
+ void OptionDelete(int itemID, int optionID)
|
|
{
|
|
{
|
|
|
|
+ _survey.SurveyItems[itemID].DeleteOption(optionID);
|
|
|
|
+ SortOptions(itemID);
|
|
}
|
|
}
|
|
|
|
|
|
async Task SaveSurvey()
|
|
async Task SaveSurvey()
|
|
@@ -134,6 +152,23 @@ namespace HyperCube.Pages
|
|
_modalInfo.Open("Опрос сохранен.");
|
|
_modalInfo.Open("Опрос сохранен.");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ void SortItems()
|
|
|
|
+ {
|
|
|
|
+ int itemPosition = 1;
|
|
|
|
+ _sortedItems = _survey.SurveyItems.OrderBy(i => i.Value.Position).ToList();
|
|
|
|
+ foreach (var item in _sortedItems) { item.Value.Position = itemPosition++; }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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++; }
|
|
|
|
+ }
|
|
|
|
+
|
|
async Task<AccountModel> GetCurrentAcc()
|
|
async Task<AccountModel> GetCurrentAcc()
|
|
{
|
|
{
|
|
Console.WriteLine($"SurveyEditor GetCurrentAcc");
|
|
Console.WriteLine($"SurveyEditor GetCurrentAcc");
|