|
@@ -23,9 +23,7 @@ namespace HyperCube.Pages
|
|
|
public int ID { get; set; }
|
|
|
|
|
|
AccountModel _currentAccount;
|
|
|
- Survey _survey = new();
|
|
|
-
|
|
|
- List<KeyValuePair<int, SurveyItem>> _sortedItems = new(); /// wrap for items sorting
|
|
|
+ Survey _survey = new();
|
|
|
|
|
|
ModalInfo _modalInfo;
|
|
|
|
|
@@ -33,86 +31,8 @@ namespace HyperCube.Pages
|
|
|
{
|
|
|
_currentAccount = await GetCurrentAcc();
|
|
|
|
|
|
- if (ID > 0)
|
|
|
- {
|
|
|
- var surveys = await MySQLConnector.Instance().SQLSelectComplex($"SELECT * FROM surveys WHERE id={ID}");
|
|
|
- if (surveys.Count > 0)
|
|
|
- {
|
|
|
- _survey = new()
|
|
|
- {
|
|
|
- EvenID = Convert.ToInt32(surveys[0]["eventid"]),
|
|
|
- ID = Convert.ToInt32(surveys[0]["id"]),
|
|
|
- Name = Convert.ToString(surveys[0]["name"]),
|
|
|
- Description = Convert.ToString(surveys[0]["description"]),
|
|
|
- DateCreated = Convert.ToDateTime(surveys[0]["date_created"]),
|
|
|
- DateUpdated = Convert.ToDateTime(surveys[0]["date_updated"]),
|
|
|
- CreatorID = Convert.ToString(surveys[0]["creatorid"]),
|
|
|
- IsNew = false
|
|
|
- };
|
|
|
- Console.WriteLine($"SurveyEditor. load survey id: {_survey.ID}, name: {_survey.Name}");
|
|
|
- }
|
|
|
-
|
|
|
- SurveyItem item;
|
|
|
- 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");
|
|
|
- if (surveyItems.Count > 0)
|
|
|
- {
|
|
|
- Console.WriteLine($"surveyItems.Count={surveyItems.Count}");
|
|
|
-
|
|
|
- foreach (var i in surveyItems)
|
|
|
- {
|
|
|
- item = new()
|
|
|
- {
|
|
|
- ID = Convert.ToInt32(i["id"]),
|
|
|
- SurveyID = Convert.ToInt32(i["surveyid"]),
|
|
|
- DateCreated = Convert.ToDateTime(i["date_created"]),
|
|
|
- DateUpdated = Convert.ToDateTime(i["date_updated"]),
|
|
|
- CreatorID = Convert.ToString(i["creatorid"]),
|
|
|
- Text = Convert.ToString(i["itemtext"]),
|
|
|
- //Position = Convert.ToInt32(i["position"]),
|
|
|
- Position = itemPosition++,
|
|
|
- Required = Convert.ToBoolean(i["required"]),
|
|
|
- IsNew = false
|
|
|
- };
|
|
|
- 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");
|
|
|
- if (surveyItemOption.Count > 0)
|
|
|
- {
|
|
|
- Console.WriteLine($"surveyItemOption.Count={surveyItemOption.Count}");
|
|
|
-
|
|
|
- foreach (var o in surveyItemOption)
|
|
|
- {
|
|
|
- option = new()
|
|
|
- {
|
|
|
- ID = Convert.ToInt32(o["id"]),
|
|
|
- ItemID = Convert.ToInt32(o["itemid"]),
|
|
|
- DateCreated = Convert.ToDateTime(o["date_created"]),
|
|
|
- DateUpdated = Convert.ToDateTime(o["date_updated"]),
|
|
|
- CreatorID = Convert.ToString(o["creatorid"]),
|
|
|
- Text = Convert.ToString(o["optiontext"]),
|
|
|
- //Position = Convert.ToInt32(o["position"]),
|
|
|
- Position = optionPosition++,
|
|
|
- Rate1 = Convert.ToInt32(o["rate1"]),
|
|
|
- Rate2 = Convert.ToInt32(o["rate2"]),
|
|
|
- Rate3 = Convert.ToInt32(o["rate3"]),
|
|
|
- Rate4 = Convert.ToInt32(o["rate4"]),
|
|
|
- IsNew = false
|
|
|
- };
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- _survey.SurveyItems.Add(item.ID, item);
|
|
|
- SortOptions(item.ID);
|
|
|
- }
|
|
|
- SortItems();
|
|
|
- }
|
|
|
- }
|
|
|
+ if (ID > 0)
|
|
|
+ await _survey.LoadByID(ID);
|
|
|
}
|
|
|
|
|
|
void NewSurvey() => NavigationManager.NavigateTo("surveyeditor", true);
|
|
@@ -120,37 +40,37 @@ namespace HyperCube.Pages
|
|
|
void AddNewItem()
|
|
|
{
|
|
|
_survey.AddNewItem(_currentAccount.UUID);
|
|
|
- SortItems();
|
|
|
+ _survey.SortItems();
|
|
|
}
|
|
|
|
|
|
void ItemMove(int itemID, int step)
|
|
|
{
|
|
|
_survey.MoveItem(itemID, step);
|
|
|
- SortItems();
|
|
|
+ _survey.SortItems();
|
|
|
}
|
|
|
|
|
|
void ItemDelete(int itemID)
|
|
|
{
|
|
|
_survey.DeleteItem(itemID);
|
|
|
- SortItems();
|
|
|
+ _survey.SortItems();
|
|
|
}
|
|
|
|
|
|
void AddNewOption(int itemID)
|
|
|
{
|
|
|
_survey.SurveyItems[itemID].AddNewOption(_currentAccount.UUID);
|
|
|
- SortOptions(itemID);
|
|
|
+ _survey.SurveyItems[itemID].SortOptions();
|
|
|
}
|
|
|
|
|
|
void OptionMove(int itemID, int optionID, int step)
|
|
|
{
|
|
|
_survey.SurveyItems[itemID].MoveItem(optionID, step);
|
|
|
- SortOptions(itemID);
|
|
|
+ _survey.SurveyItems[itemID].SortOptions();
|
|
|
}
|
|
|
|
|
|
void OptionDelete(int itemID, int optionID)
|
|
|
{
|
|
|
_survey.SurveyItems[itemID].DeleteOption(optionID);
|
|
|
- SortOptions(itemID);
|
|
|
+ _survey.SurveyItems[itemID].SortOptions();
|
|
|
}
|
|
|
|
|
|
async Task SaveSurvey()
|
|
@@ -159,20 +79,6 @@ namespace HyperCube.Pages
|
|
|
_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)
|
|
|
- {
|
|
|
- int optionPosition = 1;
|
|
|
- _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()
|
|
|
{
|
|
|
Console.WriteLine($"SurveyEditor GetCurrentAcc");
|