<commit_before>﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.ComponentModel;
using Xamarin.Forms;

using OS2Indberetning.Model;


namespace OS2Indberetning.ViewModel
{
    /// <summary>
    /// Viewmodel that handles the view logic of FinishDrivePage
    /// </summary>
    public class FinishDriveViewModel : XLabs.Forms.Mvvm.ViewModel, INotifyPropertyChanged, IDisposable
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private ObservableCollection<DriveReportCellModel> _driveReport;

        private bool _startHomeCheck;
        private bool _endHomeCheck;
        private string _date;
        private string _username;
        private string _newKm;
        
        private const string PurposeText = "Formål: ";
        private const string OrganisatoriskText = "Organisatorisk placering:";
        private const string TakstText = "Takst";
        private const string EkstraText = "Ekstra Bemærkning:";
        private const string KilometerText = "Antal Km:";

        /// <summary>
        /// Constructor that handles initialization of the viewmodel
        /// </summary>
        public FinishDriveViewModel()
        {
            _driveReport = new ObservableCollection<DriveReportCellModel>();
            NewKm = Definitions.Report.Route.TotalDistance.ToString();

            InitializeCollection();

            Username = Definitions.Report.Profile.FirstName + " " + Definitions.Report.Profile.LastName;
            Date = "Dato: " + Definitions.Report.Date;
            StartHomeCheck = Definitions.Report.StartsAtHome;
            EndHomeCheck = Definitions.Report.EndsAtHome;
            Subscribe();
        }

        /// <summary>
        /// Destructor 
        /// </summary>
        public void Dispose()
        {
            Unsubscribe();
            _driveReport = null;
        }

        /// <summary>
        /// Method that subscribes to nessecary calls
        /// </summary>
        private void Subscribe()
        {
            MessagingCenter.Subscribe<FinishDrivePage>(this, "Upload", (sender) => UploadHandler());
            MessagingCenter.Subscribe<FinishDrivePage>(this, "Delete", HandleDeleteMessage);
            MessagingCenter.Subscribe<FinishDrivePage>(this, "Selected", HandleSelectedMessage);
            MessagingCenter.Subscribe<FinishDrivePage>(this, "Update", (sender) => { HandleUpdateMessage();});
            MessagingCenter.Subscribe<FinishDrivePage>(this, "EndHome",(sender) => { StartHomeCheck = !StartHomeCheck; });
            MessagingCenter.Subscribe<FinishDrivePage>(this, "StartHome", (sender) => { EndHomeCheck = !EndHomeCheck; });
            MessagingCenter.Subscribe<FinishDrivePage>(this, "NewKm", HandleNewKmMessage);
        }

        /// <summary>
        /// Method that handles all unsubscribing
        /// </summary>
        private void Unsubscribe()
        {
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "Upload");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "Delete");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "Selected");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "Update");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "EndHome");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "StartHome");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "NewKm");
        }

        /// <summary>
        /// Method that handles initialization of the observerable collection
        /// </summary>
        private void InitializeCollection()
        {
            _driveReport.Clear();
            DriveReportList.Clear();

            _driveReport.Add(new DriveReportCellModel
            {
                Name = PurposeText,
                Description = Definitions.Report.Purpose,
            });
            _driveReport.Add(new DriveReportCellModel
            {
                Name = OrganisatoriskText,
                Description = Definitions.Report.Profile.Employments.FirstOrDefault(x => x.Id == Definitions.Report.EmploymentId).EmploymentPosition,
            });
            _driveReport.Add(new DriveReportCellModel
            {
                Name = TakstText,
                Description = Definitions.Report.Rate.Description,
            });
            _driveReport.Add(new DriveReportCellModel
            {
                Name = EkstraText,
                Description = Definitions.Report.ManualEntryRemark,
            });<commit_msg>When Remark field is left empty, we now send "Ingen kommentar angivet" to the server.<commit_after>﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.ComponentModel;
using Xamarin.Forms;

using OS2Indberetning.Model;


namespace OS2Indberetning.ViewModel
{
    /// <summary>
    /// Viewmodel that handles the view logic of FinishDrivePage
    /// </summary>
    public class FinishDriveViewModel : XLabs.Forms.Mvvm.ViewModel, INotifyPropertyChanged, IDisposable
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private ObservableCollection<DriveReportCellModel> _driveReport;

        private bool _startHomeCheck;
        private bool _endHomeCheck;
        private string _date;
        private string _username;
        private string _newKm;
        
        private const string PurposeText = "Formål: ";
        private const string OrganisatoriskText = "Organisatorisk placering:";
        private const string TakstText = "Takst";
        private const string EkstraText = "Ekstra Bemærkning:";
        private const string KilometerText = "Antal Km:";

        /// <summary>
        /// Constructor that handles initialization of the viewmodel
        /// </summary>
        public FinishDriveViewModel()
        {
            _driveReport = new ObservableCollection<DriveReportCellModel>();
            NewKm = Definitions.Report.Route.TotalDistance.ToString();

            InitializeCollection();

            Username = Definitions.Report.Profile.FirstName + " " + Definitions.Report.Profile.LastName;
            Date = "Dato: " + Definitions.Report.Date;
            StartHomeCheck = Definitions.Report.StartsAtHome;
            EndHomeCheck = Definitions.Report.EndsAtHome;
            Subscribe();
        }

        /// <summary>
        /// Destructor 
        /// </summary>
        public void Dispose()
        {
            Unsubscribe();
            _driveReport = null;
        }

        /// <summary>
        /// Method that subscribes to nessecary calls
        /// </summary>
        private void Subscribe()
        {
            MessagingCenter.Subscribe<FinishDrivePage>(this, "Upload", (sender) => UploadHandler());
            MessagingCenter.Subscribe<FinishDrivePage>(this, "Delete", HandleDeleteMessage);
            MessagingCenter.Subscribe<FinishDrivePage>(this, "Selected", HandleSelectedMessage);
            MessagingCenter.Subscribe<FinishDrivePage>(this, "Update", (sender) => { HandleUpdateMessage();});
            MessagingCenter.Subscribe<FinishDrivePage>(this, "EndHome",(sender) => { StartHomeCheck = !StartHomeCheck; });
            MessagingCenter.Subscribe<FinishDrivePage>(this, "StartHome", (sender) => { EndHomeCheck = !EndHomeCheck; });
            MessagingCenter.Subscribe<FinishDrivePage>(this, "NewKm", HandleNewKmMessage);
        }

        /// <summary>
        /// Method that handles all unsubscribing
        /// </summary>
        private void Unsubscribe()
        {
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "Upload");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "Delete");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "Selected");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "Update");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "EndHome");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "StartHome");
            MessagingCenter.Unsubscribe<FinishDrivePage>(this, "NewKm");
        }

        /// <summary>
        /// Method that handles initialization of the observerable collection
        /// </summary>
        private void InitializeCollection()
        {
            if (String.IsNullOrEmpty(Definitions.Report.ManualEntryRemark))
            {
                Definitions.Report.ManualEntryRemark = "Ingen kommentar angivet";
            }
            _driveReport.Clear();
            DriveReportList.Clear();

            _driveReport.Add(new DriveReportCellModel
            {
                Name = PurposeText,
                Description = Definitions.Report.Purpose,
            });
            _driveReport.Add(new DriveReportCellModel
            {
                Name = OrganisatoriskText,
                Description = Definitions.Report.Profile.Employments.FirstOrDefault(x => x.Id == Definitions.Report.EmploymentId).EmploymentPosition,
            });
            _driveReport.Add(new DriveReportCellModel
            {
                Name = TakstText,
                Description = Definitions.Report.Rate.Description,
            });
            _driveReport.Add(new DriveReportCellModel
            {
                Name = EkstraText,
                Description = Definitions.Report.ManualEntryRemark,
            });
{'fraction_non_alphanumeric': 0.09817987152034262, 'fraction_numerical': 0.00042826552462526765, 'mean_word_length': 2.305378627034678, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2554496', 'n_tokens_mistral': 2421, 'n_tokens_neox': 2297, 'n_words': 458}