|
@@ -0,0 +1,170 @@
|
|
|
|
+using Microsoft.AspNetCore.Components;
|
|
|
|
+using Microsoft.AspNetCore.Components.Authorization;
|
|
|
|
+using Microsoft.AspNetCore.Identity;
|
|
|
|
+using System;
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using System.Linq;
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
+using HyperCube.Models;
|
|
|
|
+using Console = HyperCube.Utils.AdvConsole;
|
|
|
|
+
|
|
|
|
+namespace HyperCube.Pages
|
|
|
|
+{
|
|
|
|
+ public partial class SurveyEditor : ComponentBase
|
|
|
|
+ {
|
|
|
|
+ [Inject]
|
|
|
|
+ NavigationManager NavigationManager { get; set; }
|
|
|
|
+ [Inject]
|
|
|
|
+ AuthenticationStateProvider AuthenticationStateProvider { get; set; }
|
|
|
|
+ [Inject]
|
|
|
|
+ UserManager<IdentityUser> UserManager { get; set; }
|
|
|
|
+
|
|
|
|
+ [Parameter]
|
|
|
|
+ public int ID { get; set; }
|
|
|
|
+
|
|
|
|
+ AccountModel _currentAccount;
|
|
|
|
+ Survey _survey = new();
|
|
|
|
+
|
|
|
|
+ protected override async Task OnInitializedAsync()
|
|
|
|
+ {
|
|
|
|
+ _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;
|
|
|
|
+
|
|
|
|
+ var surveyItems = await MySQLConnector.Instance().SQLSelectComplex($"SELECT * FROM surveyitems WHERE surveyid={_survey.ID} ORDER BY position");
|
|
|
|
+ if (surveyItems.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ 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"]),
|
|
|
|
+ Required = Convert.ToBoolean(i["required"]),
|
|
|
|
+ IsNew = false
|
|
|
|
+ };
|
|
|
|
+ Console.WriteLine($"SurveyEditor. load survey items id: {item.ID}, position: {item.Position}, name: {item.Text}");
|
|
|
|
+
|
|
|
|
+ var surveyItemOption = await MySQLConnector.Instance().SQLSelectComplex($"SELECT * FROM surveyitemoptions WHERE itemid={item.ID} ORDER BY position");
|
|
|
|
+ if (surveyItemOption.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ 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"]),
|
|
|
|
+ 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 option id: {option.ID}, position: {option.Position}, name: {option.Text}.");
|
|
|
|
+
|
|
|
|
+ item.SurveyItemOptions.Add(option.ID, option);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ _survey.SurveyItems.Add(item.ID, item);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void AddNewItem() => _survey.AddNewItem(_currentAccount.UUID);
|
|
|
|
+
|
|
|
|
+ void AddNewOption(int ItemID) => _survey.SurveyItems[ItemID].AddNewOption(_currentAccount.UUID);
|
|
|
|
+
|
|
|
|
+ void NewSurvey()
|
|
|
|
+ {
|
|
|
|
+ NavigationManager.NavigateTo("surveyeditor", true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void ItemMoveUp()
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void ItemMoveDown()
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void ItemDelete()
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void OptionMoveUp()
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void OptionMoveDown()
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void OptionDelete()
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async Task SaveSurvey()
|
|
|
|
+ {
|
|
|
|
+ await _survey.Save(_currentAccount.UUID);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async Task<AccountModel> GetCurrentAcc()
|
|
|
|
+ {
|
|
|
|
+ Console.WriteLine($"SurveyEditor GetCurrentAcc");
|
|
|
|
+
|
|
|
|
+ if (_currentAccount == null)
|
|
|
|
+ {
|
|
|
|
+ var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
|
|
+ var user = authState.User;
|
|
|
|
+
|
|
|
|
+ if (user.Identity.IsAuthenticated)
|
|
|
|
+ {
|
|
|
|
+ var currentUser = await UserManager.GetUserAsync(user);
|
|
|
|
+ var acc = AccountModel.Find(currentUser.Id);
|
|
|
|
+ if (acc != null)
|
|
|
|
+ {
|
|
|
|
+ _currentAccount = AccountModel.Loaded[currentUser.Id];
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, AccountModel> accounts = await MySQLConnector.Instance().SQLSelectASPUsers();
|
|
|
|
+ if (accounts.ContainsKey(currentUser.Id))
|
|
|
|
+ _currentAccount = accounts[currentUser.Id];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return _currentAccount;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|