mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-19 03:27:29 +02:00
Version 3.0.338
This commit is contained in:
parent
573fe77e12
commit
0468955d49
751 changed files with 62747 additions and 60672 deletions
|
@ -12,142 +12,142 @@ using TINK.ViewModel.MiniSurvey.Question;
|
|||
|
||||
namespace TINK.ViewModel.MiniSurvey
|
||||
{
|
||||
public class MiniSurveyViewModel : ObservableCollection<IMiniSurveyQuestion>
|
||||
{
|
||||
/// <summary> Delegate to retrieve connected state. </summary>
|
||||
protected Func<bool> IsConnectedDelegate { get; }
|
||||
public class MiniSurveyViewModel : ObservableCollection<IMiniSurveyQuestion>
|
||||
{
|
||||
/// <summary> Delegate to retrieve connected state. </summary>
|
||||
protected Func<bool> IsConnectedDelegate { get; }
|
||||
|
||||
/// <summary> Provides a connector object.</summary>
|
||||
private Func<bool, IConnector> ConnectorFactory { get; }
|
||||
/// <summary> Provides a connector object.</summary>
|
||||
private Func<bool, IConnector> ConnectorFactory { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
private IViewService ViewService { get; }
|
||||
/// <summary>
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
private IViewService ViewService { get; }
|
||||
|
||||
private MiniSurveyModel MiniSurvey { get; }
|
||||
private MiniSurveyModel MiniSurvey { get; }
|
||||
|
||||
/// <summary> Constructs mini survey view model.</summary>
|
||||
/// <param name="connectorFactory">Connects system to copri for purposes of requesting a bike/ cancel request.</param>
|
||||
/// <param name="viewService">Interface to actuate methodes on GUI.</param>
|
||||
public MiniSurveyViewModel(
|
||||
Func<bool> isConnectedDelegate,
|
||||
Func<bool, IConnector> connectorFactory,
|
||||
IViewService viewService)
|
||||
{
|
||||
IsConnectedDelegate = isConnectedDelegate
|
||||
?? throw new ArgumentException($"Can not instantiate {nameof(MiniSurveyViewModel)}-object. No connector available.");
|
||||
/// <summary> Constructs mini survey view model.</summary>
|
||||
/// <param name="connectorFactory">Connects system to copri for purposes of requesting a bike/ cancel request.</param>
|
||||
/// <param name="viewService">Interface to actuate methodes on GUI.</param>
|
||||
public MiniSurveyViewModel(
|
||||
Func<bool> isConnectedDelegate,
|
||||
Func<bool, IConnector> connectorFactory,
|
||||
IViewService viewService)
|
||||
{
|
||||
IsConnectedDelegate = isConnectedDelegate
|
||||
?? throw new ArgumentException($"Can not instantiate {nameof(MiniSurveyViewModel)}-object. No connector available.");
|
||||
|
||||
ConnectorFactory = connectorFactory
|
||||
?? throw new ArgumentException($"Can not instantiate {nameof(MiniSurveyViewModel)}-object. No connector available.");
|
||||
ConnectorFactory = connectorFactory
|
||||
?? throw new ArgumentException($"Can not instantiate {nameof(MiniSurveyViewModel)}-object. No connector available.");
|
||||
|
||||
ViewService = viewService
|
||||
?? throw new ArgumentException($"Can not instantiate {nameof(MiniSurveyViewModel)}-object. No view available.");
|
||||
ViewService = viewService
|
||||
?? throw new ArgumentException($"Can not instantiate {nameof(MiniSurveyViewModel)}-object. No view available.");
|
||||
|
||||
MiniSurvey = new MiniSurveyModel
|
||||
{
|
||||
Title = "Bitte unterstützen Sie unsere Begleitforschung",
|
||||
Subtitle = "Ihre drei Antworten werden anonym gespeichert.",
|
||||
Footer = "Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"
|
||||
};
|
||||
MiniSurvey = new MiniSurveyModel
|
||||
{
|
||||
Title = "Bitte unterstützen Sie unsere Begleitforschung",
|
||||
Subtitle = "Ihre drei Antworten werden anonym gespeichert.",
|
||||
Footer = "Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"
|
||||
};
|
||||
|
||||
MiniSurvey.Questions.Add(
|
||||
"q1",
|
||||
new QuestionModel
|
||||
{
|
||||
Text = "1. Was war der Hauptzweck dieser Ausleihe?",
|
||||
Type = MiniSurveyModel.Type.SingleAnswer
|
||||
});
|
||||
MiniSurvey.Questions.Add(
|
||||
"q1",
|
||||
new QuestionModel
|
||||
{
|
||||
Text = "1. Was war der Hauptzweck dieser Ausleihe?",
|
||||
Type = MiniSurveyModel.Type.SingleAnswer
|
||||
});
|
||||
|
||||
MiniSurvey.Questions.Add(
|
||||
"q2",
|
||||
new QuestionModel
|
||||
{
|
||||
Text = "2. Welches Verkehrsmittel hätten Sie ansonsten benutzt?",
|
||||
Type = MiniSurveyModel.Type.SingleAnswer
|
||||
});
|
||||
MiniSurvey.Questions.Add(
|
||||
"q2",
|
||||
new QuestionModel
|
||||
{
|
||||
Text = "2. Welches Verkehrsmittel hätten Sie ansonsten benutzt?",
|
||||
Type = MiniSurveyModel.Type.SingleAnswer
|
||||
});
|
||||
|
||||
MiniSurvey.Questions.Add(
|
||||
"q3",
|
||||
new QuestionModel
|
||||
{
|
||||
Text = "3. Haben Sie Anmerkungen oder Anregungen?",
|
||||
Type = MiniSurveyModel.Type.CustomText
|
||||
});
|
||||
MiniSurvey.Questions.Add(
|
||||
"q3",
|
||||
new QuestionModel
|
||||
{
|
||||
Text = "3. Haben Sie Anmerkungen oder Anregungen?",
|
||||
Type = MiniSurveyModel.Type.CustomText
|
||||
});
|
||||
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt1", "a. Einkauf");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt2", "b. Kinderbeförderung");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt3", "c. Lastentransport");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt4", "d. Freizeit");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt5", "e. Ausprobieren");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt6", "f. Sonstiges");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt1", "a. Einkauf");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt2", "b. Kinderbeförderung");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt3", "c. Lastentransport");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt4", "d. Freizeit");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt5", "e. Ausprobieren");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt6", "f. Sonstiges");
|
||||
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt1", "a. Auto");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt2", "b. Motorrad oder Motorroller");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt3", "c. Bus oder Bahn");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt4", "d. Eigenes Fahrrad");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt5", "e. Zu Fuß");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt6", "f. Keines (ich hätte die Fahrt sonst nicht gemacht)");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt1", "a. Auto");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt2", "b. Motorrad oder Motorroller");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt3", "c. Bus oder Bahn");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt4", "d. Eigenes Fahrrad");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt5", "e. Zu Fuß");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt6", "f. Keines (ich hätte die Fahrt sonst nicht gemacht)");
|
||||
|
||||
Title = MiniSurvey.Title;
|
||||
Subtitle = MiniSurvey.Subtitle;
|
||||
Footer = MiniSurvey.Footer;
|
||||
Title = MiniSurvey.Title;
|
||||
Subtitle = MiniSurvey.Subtitle;
|
||||
Footer = MiniSurvey.Footer;
|
||||
|
||||
foreach (var question in MiniSurvey.Questions)
|
||||
{
|
||||
switch (question.Value.Type)
|
||||
{
|
||||
case MiniSurveyModel.Type.SingleAnswer:
|
||||
Add(new CheckOneViewModel(
|
||||
new KeyValuePair<string, string>(question.Key, question.Value.Text),
|
||||
question.Value.PossibleAnswers));
|
||||
break;
|
||||
foreach (var question in MiniSurvey.Questions)
|
||||
{
|
||||
switch (question.Value.Type)
|
||||
{
|
||||
case MiniSurveyModel.Type.SingleAnswer:
|
||||
Add(new CheckOneViewModel(
|
||||
new KeyValuePair<string, string>(question.Key, question.Value.Text),
|
||||
question.Value.PossibleAnswers));
|
||||
break;
|
||||
|
||||
case MiniSurveyModel.Type.CustomText:
|
||||
Add(new FreeTextViewModel(new KeyValuePair<string, string>(question.Key, question.Value.Text)));
|
||||
break;
|
||||
case MiniSurveyModel.Type.CustomText:
|
||||
Add(new FreeTextViewModel(new KeyValuePair<string, string>(question.Key, question.Value.Text)));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Title { get; set; }
|
||||
public string Title { get; set; }
|
||||
|
||||
public string Subtitle { get; set; }
|
||||
public string Subtitle { get; set; }
|
||||
|
||||
public string Footer { get; set; }
|
||||
public string Footer { get; set; }
|
||||
|
||||
/// <summary> Processes request to perform a copri action (reserve bike and cancel reservation). </summary>
|
||||
public System.Windows.Input.ICommand OnButtonClicked => new Xamarin.Forms.Command(async () =>
|
||||
{
|
||||
Log.ForContext<MiniSurveyViewModel>().Information($"User result {this[0].Answer.Value}, {this[1].Answer.Value}");
|
||||
/// <summary> Processes request to perform a copri action (reserve bike and cancel reservation). </summary>
|
||||
public System.Windows.Input.ICommand OnButtonClicked => new Xamarin.Forms.Command(async () =>
|
||||
{
|
||||
Log.ForContext<MiniSurveyViewModel>().Information($"User result {this[0].Answer.Value}, {this[1].Answer.Value}");
|
||||
|
||||
var isConnected = IsConnectedDelegate();
|
||||
try
|
||||
{
|
||||
await ConnectorFactory(isConnected).Command.DoSubmitMiniSurvey(this.ToDictionary(x => x.Question.Key, x => x.Answer.Key));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
if (exception is ResponseException copriException)
|
||||
{
|
||||
// Copri server is not reachable.
|
||||
Log.ForContext<MiniSurveyViewModel>().Information("Submitting mini survay answer failed. COPRI returned an error.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.ForContext<MiniSurveyViewModel>().Error("Submitting mini survay answer failed. {@l_oException}", exception);
|
||||
}
|
||||
var isConnected = IsConnectedDelegate();
|
||||
try
|
||||
{
|
||||
await ConnectorFactory(isConnected).Command.DoSubmitMiniSurvey(this.ToDictionary(x => x.Question.Key, x => x.Answer.Key));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
if (exception is ResponseException copriException)
|
||||
{
|
||||
// Copri server is not reachable.
|
||||
Log.ForContext<MiniSurveyViewModel>().Information("Submitting mini survay answer failed. COPRI returned an error.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.ForContext<MiniSurveyViewModel>().Error("Submitting mini survay answer failed. {@l_oException}", exception);
|
||||
}
|
||||
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.ErrorReturnSubmitFeedbackTitle,
|
||||
AppResources.ErrorReturnSubmitFeedbackMessage,
|
||||
AppResources.MessageAnswerOk);
|
||||
}
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.ErrorReturnSubmitFeedbackTitle,
|
||||
AppResources.ErrorReturnSubmitFeedbackMessage,
|
||||
AppResources.MessageAnswerOk);
|
||||
}
|
||||
|
||||
await ViewService.PopModalAsync();
|
||||
});
|
||||
}
|
||||
await ViewService.PopModalAsync();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,43 +3,43 @@ using System.Linq;
|
|||
|
||||
namespace TINK.ViewModel.MiniSurvey.Question
|
||||
{
|
||||
public class CheckOneViewModel : IMiniSurveyQuestion
|
||||
{
|
||||
/// <summary> Constructs object. </summary>
|
||||
/// <param name="question">Holds the question with key asked to user.</param>
|
||||
/// <param name="answers">Holds the list of possible answers with their option keys.</param>
|
||||
public CheckOneViewModel(
|
||||
KeyValuePair<string, string> question,
|
||||
Dictionary<string, string> answers)
|
||||
{
|
||||
Question = question;
|
||||
Answers = answers ?? new Dictionary<string, string>();
|
||||
}
|
||||
public class CheckOneViewModel : IMiniSurveyQuestion
|
||||
{
|
||||
/// <summary> Constructs object. </summary>
|
||||
/// <param name="question">Holds the question with key asked to user.</param>
|
||||
/// <param name="answers">Holds the list of possible answers with their option keys.</param>
|
||||
public CheckOneViewModel(
|
||||
KeyValuePair<string, string> question,
|
||||
Dictionary<string, string> answers)
|
||||
{
|
||||
Question = question;
|
||||
Answers = answers ?? new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
/// <summary> Holds the question with key asked to user. </summary>
|
||||
public KeyValuePair<string, string> Question { get; }
|
||||
/// <summary> Holds the question with key asked to user. </summary>
|
||||
public KeyValuePair<string, string> Question { get; }
|
||||
|
||||
/// <summary> Holds the question with key asked to user exposed to GUI. </summary>
|
||||
public string QuestionText => Question.Value;
|
||||
/// <summary> Holds the question with key asked to user exposed to GUI. </summary>
|
||||
public string QuestionText => Question.Value;
|
||||
|
||||
/// <summary> Holds the list of possible answers with their option keys. </summary>
|
||||
public Dictionary<string, string> Answers { get; }
|
||||
/// <summary> Holds the list of possible answers with their option keys. </summary>
|
||||
public Dictionary<string, string> Answers { get; }
|
||||
|
||||
/// <summary> Holds the list of possible answers exposed to GUI. </summary>
|
||||
public IEnumerable<string> AnswersText
|
||||
{
|
||||
get => Answers.Select(x => x.Value).ToList();
|
||||
set => AnswersText = Answers.Select(x => x.Value).ToList();
|
||||
}
|
||||
/// <summary> Holds the list of possible answers exposed to GUI. </summary>
|
||||
public IEnumerable<string> AnswersText
|
||||
{
|
||||
get => Answers.Select(x => x.Value).ToList();
|
||||
set => AnswersText = Answers.Select(x => x.Value).ToList();
|
||||
}
|
||||
|
||||
/// <summary> Holds the users selected answer (one of answers) with its option key. </summary>
|
||||
public KeyValuePair<string, string> Answer { get; private set; }
|
||||
/// <summary> Holds the users selected answer (one of answers) with its option key. </summary>
|
||||
public KeyValuePair<string, string> Answer { get; private set; }
|
||||
|
||||
/// <summary> Holds the users selected answer (one of answers) in GUI. </summary>
|
||||
public string AnswerText
|
||||
{
|
||||
get => Answer.Value;
|
||||
set => Answer = Answers.FirstOrDefault(x => x.Value == value);
|
||||
}
|
||||
}
|
||||
/// <summary> Holds the users selected answer (one of answers) in GUI. </summary>
|
||||
public string AnswerText
|
||||
{
|
||||
get => Answer.Value;
|
||||
set => Answer = Answers.FirstOrDefault(x => x.Value == value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,31 +2,31 @@
|
|||
|
||||
namespace TINK.ViewModel.MiniSurvey.Question
|
||||
{
|
||||
public class FreeTextViewModel : IMiniSurveyQuestion
|
||||
{
|
||||
/// <summary> Constructs object. </summary>
|
||||
/// <param name="question">Holds the question with key asked to user.</param>
|
||||
/// <param name="answers">Holds the list of possible answers with their option keys.</param>
|
||||
public FreeTextViewModel(
|
||||
KeyValuePair<string, string> question)
|
||||
{
|
||||
Question = question;
|
||||
}
|
||||
public class FreeTextViewModel : IMiniSurveyQuestion
|
||||
{
|
||||
/// <summary> Constructs object. </summary>
|
||||
/// <param name="question">Holds the question with key asked to user.</param>
|
||||
/// <param name="answers">Holds the list of possible answers with their option keys.</param>
|
||||
public FreeTextViewModel(
|
||||
KeyValuePair<string, string> question)
|
||||
{
|
||||
Question = question;
|
||||
}
|
||||
|
||||
/// <summary> Holds the question with key asked to user. </summary>
|
||||
public KeyValuePair<string, string> Question { get; }
|
||||
/// <summary> Holds the question with key asked to user. </summary>
|
||||
public KeyValuePair<string, string> Question { get; }
|
||||
|
||||
/// <summary> Holds the question with key asked to user exposed to GUI. </summary>
|
||||
public string QuestionText => Question.Value;
|
||||
/// <summary> Holds the question with key asked to user exposed to GUI. </summary>
|
||||
public string QuestionText => Question.Value;
|
||||
|
||||
/// <summary> Holds the users selected answer with its option key. </summary>
|
||||
public KeyValuePair<string, string> Answer { get; private set; }
|
||||
/// <summary> Holds the users selected answer with its option key. </summary>
|
||||
public KeyValuePair<string, string> Answer { get; private set; }
|
||||
|
||||
/// <summary> Holds the list of possible answers exposed to GUI. </summary>
|
||||
public string AnswerText
|
||||
{
|
||||
get => null;
|
||||
set => Answer = new KeyValuePair<string, string>(value, null);
|
||||
}
|
||||
}
|
||||
/// <summary> Holds the list of possible answers exposed to GUI. </summary>
|
||||
public string AnswerText
|
||||
{
|
||||
get => null;
|
||||
set => Answer = new KeyValuePair<string, string>(value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace TINK.ViewModel.MiniSurvey.Question
|
||||
{
|
||||
public interface IMiniSurveyQuestion
|
||||
{
|
||||
/// <summary> Holds the question with key asked to user. </summary>
|
||||
KeyValuePair<string, string> Question { get; }
|
||||
public interface IMiniSurveyQuestion
|
||||
{
|
||||
/// <summary> Holds the question with key asked to user. </summary>
|
||||
KeyValuePair<string, string> Question { get; }
|
||||
|
||||
/// <summary> Holds the users selected answer with its option key. </summary>
|
||||
KeyValuePair<string, string> Answer { get; }
|
||||
}
|
||||
/// <summary> Holds the users selected answer with its option key. </summary>
|
||||
KeyValuePair<string, string> Answer { get; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue