using Server_Dashboard.Views.DashboardPages.ModuleCRUD;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
using Server_Dashboard_Socket;
namespace Server_Dashboard {
///
/// View Model for the Dashboard
///
class DashboardViewModel : BaseViewModel {
#region Private Values
private readonly DashboardModuleViewModel dmvm = new DashboardModuleViewModel();
#endregion
#region Properties
//The Username displayed defaults to Username
private string userName = "Username";
public string UserName {
get { return userName; }
set {
if(userName != value)
userName = value;
OnPropertyChanged(nameof(userName));
}
}
//List that contains every Module
private ObservableCollection modules;
public ObservableCollection Modules {
get { return modules; }
set {
if(value != modules)
modules = value;
OnPropertyChanged(nameof(modules));
}
}
#endregion
#region Constructor
public DashboardViewModel() {
//Creates a new echo server, remove b4 release
EchoServer echoServer = new EchoServer();
echoServer.Start();
//Command inits
OpenLinkCommand = new RelayCommand(OpenLink);
OpenNewModuleWindowCommand = new RelayCommand(OpenNewModuleWindow);
CreateModuleCommand = new RelayCommand(CreateModule);
//Sets the local module to the dashboardviewmodule modules
Modules = dmvm.Modules;
}
#endregion
#region ICommands
public ICommand OpenLinkCommand { get; set; }
public ICommand OpenNewModuleWindowCommand { get; set; }
public ICommand CreateModuleCommand { get; set; }
#endregion
#region Commands
///
/// Opens a given link in the default browser
///
/// The Link to be opened e.g. https://github.com/Crylia/Server-Dashboard
private void OpenLink(object param) {
Process.Start(new ProcessStartInfo((string)param) { UseShellExecute = true });
}
///
/// Creates a new window to create a new Module
///
/// Nothing
private void OpenNewModuleWindow(object param) {
//Creates a new CreateModulePopup and sets this view model as datacontext
CreateModulePopup cmp = new CreateModulePopup {
DataContext = this
};
//Opens it in the middle of the screen, setting the parent window as owner causes the
//application to crash when NOT in debug mode(???)
cmp.WindowStartupLocation = WindowStartupLocation.CenterScreen;
cmp.ShowDialog();
}
///
/// No function yes
///
/// Nothing
private void CreateModule(object param) {
}
#endregion
}
}