From efa18ea450ec67506fde1363c5bdeb040a7ef29c Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 14 Nov 2016 17:54:06 +0100 Subject: [PATCH] WIP files --- .../BookAStar.Droid/BookAStar.Droid.csproj | 10 +- .../Properties/AndroidManifest.xml | 2 +- BookAStar/BookAStar/App.xaml.cs | 23 +++-- BookAStar/BookAStar/BookAStar.csproj | 95 +++++++++++++------ BookAStar/BookAStar/Constants.cs | 2 +- .../BookAStar/Converters/NotValueConverter.cs | 19 ++++ BookAStar/BookAStar/Data/DataManager.cs | 9 +- .../BookAStar/Data/NonCrUD/RemoteFiles.cs | 50 ++++++++++ BookAStar/BookAStar/Data/RemoteEntity.cs | 36 +++---- BookAStar/BookAStar/Helpers/UserHelpers.cs | 7 +- .../Model/FileSystem/UserDirectoryInfo.cs | 35 +++++++ .../Model/FileSystem/UserFileInfo.cs | 19 ++++ .../Pages/UserProfile/UserFiles.xaml | 35 +++++++ .../Pages/UserProfile/UserFiles.xaml.cs | 34 +++++++ .../UserProfile/DirectoryInfoViewModel.cs | 32 +++++++ 15 files changed, 351 insertions(+), 57 deletions(-) create mode 100644 BookAStar/BookAStar/Converters/NotValueConverter.cs create mode 100644 BookAStar/BookAStar/Data/NonCrUD/RemoteFiles.cs create mode 100644 BookAStar/BookAStar/Model/FileSystem/UserDirectoryInfo.cs create mode 100644 BookAStar/BookAStar/Model/FileSystem/UserFileInfo.cs create mode 100644 BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml create mode 100644 BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml.cs create mode 100644 BookAStar/BookAStar/ViewModels/UserProfile/DirectoryInfoViewModel.cs diff --git a/BookAStar/BookAStar.Droid/BookAStar.Droid.csproj b/BookAStar/BookAStar.Droid/BookAStar.Droid.csproj index 008e1262..66be7693 100644 --- a/BookAStar/BookAStar.Droid/BookAStar.Droid.csproj +++ b/BookAStar/BookAStar.Droid/BookAStar.Droid.csproj @@ -31,7 +31,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;DEV prompt 0 True @@ -162,6 +162,14 @@ ..\..\packages\Xamarin.Controls.SignaturePad.1.4.0\lib\MonoAndroid\SignaturePad.dll True + + ..\..\packages\Xamarin.Controls.SignaturePad.Forms.1.4.0\lib\MonoAndroid\SignaturePad.Forms.dll + True + + + ..\..\packages\Xamarin.Controls.SignaturePad.Forms.1.4.0\lib\MonoAndroid\SignaturePad.Forms.Droid.dll + True + ..\..\packages\SQLite.Net.Core-PCL.3.1.1\lib\portable-win8+net45+wp8+wpa81+MonoAndroid1+MonoTouch1\SQLite.Net.dll diff --git a/BookAStar/BookAStar.Droid/Properties/AndroidManifest.xml b/BookAStar/BookAStar.Droid/Properties/AndroidManifest.xml index ea30fc44..fbc04fe9 100644 --- a/BookAStar/BookAStar.Droid/Properties/AndroidManifest.xml +++ b/BookAStar/BookAStar.Droid/Properties/AndroidManifest.xml @@ -21,7 +21,7 @@ - + diff --git a/BookAStar/BookAStar/App.xaml.cs b/BookAStar/BookAStar/App.xaml.cs index 61652215..a339ede9 100644 --- a/BookAStar/BookAStar/App.xaml.cs +++ b/BookAStar/BookAStar/App.xaml.cs @@ -19,9 +19,12 @@ namespace BookAStar using Model.UI; using Pages; using Plugin.Connectivity; - using ViewModels; using Microsoft.AspNet.SignalR.Client; using Model.Social.Messaging; + using ViewModels.Messaging; + using ViewModels.UserProfile; + using Pages.UserProfile; + using ViewModels.EstimateAndBilling; public partial class App : Application // superclass new in 1.3 { @@ -144,9 +147,9 @@ namespace BookAStar ViewFactory.Register(); ViewFactory.Register(); ViewFactory.Register(); - ConfigManager = new XLabs.Settings.GenericConfigSettingsMgr(s => + ViewFactory.Register(); + ConfigManager = new GenericConfigSettingsMgr(s => MainSettings.AppSettings.GetValueOrDefault(s, MainSettings.SettingsDefault), null); - } ExtendedMasterDetailPage masterDetail; @@ -213,14 +216,20 @@ namespace BookAStar ToolbarItem tiHome = new ToolbarItem() { Text = "Accueil", - Icon = "icon.png" + Icon = "icon.png", + Command = new Command( + () => { NavigationService.NavigateTo(); } + ) }; + ToolbarItem tiPubChat= new ToolbarItem() { Text = "Chat", - Icon = "chat_icon_s.png" + Icon = "chat_icon_s.png", + Command = new Command( + () => { NavigationService.NavigateTo(); } + ) }; - tiPubChat.Clicked += TiPubChat_Clicked; masterDetail.ToolbarItems.Add(tiHome); masterDetail.ToolbarItems.Add(tiSetts); masterDetail.ToolbarItems.Add(tiPubChat); @@ -250,7 +259,7 @@ namespace BookAStar private void TiPubChat_Clicked(object sender, EventArgs e) { - NavigationService.NavigateTo(); + } public static INavigationService NavigationService { protected set; get; } diff --git a/BookAStar/BookAStar/BookAStar.csproj b/BookAStar/BookAStar/BookAStar.csproj index 8e1b2254..b4071ac0 100644 --- a/BookAStar/BookAStar/BookAStar.csproj +++ b/BookAStar/BookAStar/BookAStar.csproj @@ -22,7 +22,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;DEV prompt 4 @@ -48,13 +48,27 @@ + + + + + + + UserFiles.xaml + + + DocSigning.xaml + + + + @@ -82,23 +96,23 @@ - - + + BookQueriesPage.xaml - + BookQueryPage.xaml ChatPage.xaml - + EditBillingLinePage.xaml - + DashboardPage.xaml - + EventDetail.xaml @@ -143,30 +157,33 @@ - + EditEstimatePage.xaml - + HomePage.xaml - - - - - - - - + + + + + + + + - + SearchPage.xaml - + AccountChooserPage.xaml + + MDSigningView.xaml + RatingView.xaml @@ -188,15 +205,15 @@ - + MSBuild:UpdateDesignTimeXaml Designer - + MSBuild:UpdateDesignTimeXaml Designer - + MSBuild:UpdateDesignTimeXaml Designer @@ -239,6 +256,10 @@ ..\..\packages\Xam.Plugins.Settings.2.5.1.0\lib\portable-net45+wp80+win8+wpa81\Plugin.Settings.Abstractions.dll True + + ..\..\packages\Xamarin.Controls.SignaturePad.Forms.1.4.0\lib\portable-net45+win+wp8+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SignaturePad.Forms.dll + True + ..\..\packages\SQLite.Net-PCL.3.1.1\lib\portable-win8+net45+wp8+wpa81+MonoAndroid1+MonoTouch1\SQLite.Net.dll True @@ -301,7 +322,7 @@ - + MSBuild:UpdateDesignTimeXaml Designer @@ -313,25 +334,25 @@ - + MSBuild:UpdateDesignTimeXaml Designer - + MSBuild:UpdateDesignTimeXaml Designer - + MSBuild:UpdateDesignTimeXaml Designer - + MSBuild:UpdateDesignTimeXaml Designer @@ -345,7 +366,7 @@ - + MSBuild:UpdateDesignTimeXaml Designer @@ -383,6 +404,24 @@ + + + MSBuild:UpdateDesignTimeXaml + Designer + + + + + MSBuild:UpdateDesignTimeXaml + Designer + + + + + MSBuild:UpdateDesignTimeXaml + Designer + + diff --git a/BookAStar/BookAStar/Constants.cs b/BookAStar/BookAStar/Constants.cs index 8b6f9d5e..8c4b3c2a 100644 --- a/BookAStar/BookAStar/Constants.cs +++ b/BookAStar/BookAStar/Constants.cs @@ -14,7 +14,7 @@ namespace BookAStar #region Uri #if DEV - public const string YavscHomeUrl = "https://dev.pschneider.fr"; + public const string YavscHomeUrl = "http://dev.pschneider.fr"; #else #if YAVSC public const string YavscHomeUrl = "https://yavsc.pschneider.fr"; diff --git a/BookAStar/BookAStar/Converters/NotValueConverter.cs b/BookAStar/BookAStar/Converters/NotValueConverter.cs new file mode 100644 index 00000000..ef941a61 --- /dev/null +++ b/BookAStar/BookAStar/Converters/NotValueConverter.cs @@ -0,0 +1,19 @@ +using System; +using System.Globalization; +using Xamarin.Forms; + +namespace BookAStar.Converters +{ + public class NotValueConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return object.Equals(value, false); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return object.Equals(value, false); + } + } +} diff --git a/BookAStar/BookAStar/Data/DataManager.cs b/BookAStar/BookAStar/Data/DataManager.cs index 82e676b7..bd3b3c98 100644 --- a/BookAStar/BookAStar/Data/DataManager.cs +++ b/BookAStar/BookAStar/Data/DataManager.cs @@ -4,8 +4,9 @@ using Model.Blog; using Model.Workflow; using Model.UI; - using ViewModels; using Model.Social.Messaging; + using Model.FileSystem; + using ViewModels.EstimateAndBilling; public class DataManager { @@ -13,8 +14,11 @@ public RemoteEntityRO BookQueries { get; set; } public RemoteEntity Estimates { get; set; } public RemoteEntity Blogspot { get; set; } + internal RemoteEntity RemoteFiles { get; set; } + public LocalEntity Contacts { get; set; } internal LocalEntity AppState { get; set; } + /// /// They have no remote exisence ... /// @@ -38,11 +42,13 @@ BookQueries = new RemoteEntityRO("bookquery", q => q.Id); Estimates = new RemoteEntity("estimate", x => x.Id); Blogspot = new RemoteEntity("blog", x=>x.Id); + Contacts = new LocalEntity(c => c.UserId); AppState = new LocalEntity(s => s.Position); EstimationCache = new LocalEntity(e => e.Query.Id); EstimateLinesTemplates = new LocalEntity(l => l.Description); PrivateMessages = new LocalEntity(m=> m.GetHashCode()); + RemoteFiles = new RemoteEntity ("fs", d => d.SubPath); PrivateMessages.Load(); BookQueries.Load(); @@ -52,6 +58,7 @@ AppState.Load(); EstimationCache.Load(); EstimateLinesTemplates.Load(); + RemoteFiles.Load(); } } } diff --git a/BookAStar/BookAStar/Data/NonCrUD/RemoteFiles.cs b/BookAStar/BookAStar/Data/NonCrUD/RemoteFiles.cs new file mode 100644 index 00000000..01878198 --- /dev/null +++ b/BookAStar/BookAStar/Data/NonCrUD/RemoteFiles.cs @@ -0,0 +1,50 @@ + +using Newtonsoft.Json; +using System; + +namespace BookAStar.Data.NonCrUD +{ + using Helpers; + using Model.FileSystem; + + public class RemoteFiles : RemoteEntity + { + public RemoteFiles() : base("fs", d => d) + { + + } + + public override async void Execute(object parameter) + { + BeforeExecute(); + using (var client = UserHelpers.CreateClient()) + { + // Get the whole data + try + { + var subpath = parameter as string; + string path = ControllerUri.AbsolutePath + ((subpath != null) ? "/" + subpath : null); + using (var response = await client.GetAsync(ControllerUri)) + { + if (response.IsSuccessStatusCode) + { + var content = await response.Content.ReadAsStringAsync(); + var di = JsonConvert.DeserializeObject(content); + this.Merge(di); + } + else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) + throw new Exception("Bad request"); + else + throw new Exception("Remote call failed"); + } + } + catch (Exception ex) + { + throw new Exception("Remote call failed", ex); + } + } + } + + + } +} diff --git a/BookAStar/BookAStar/Data/RemoteEntity.cs b/BookAStar/BookAStar/Data/RemoteEntity.cs index 666f594e..96bbb9df 100644 --- a/BookAStar/BookAStar/Data/RemoteEntity.cs +++ b/BookAStar/BookAStar/Data/RemoteEntity.cs @@ -14,11 +14,12 @@ namespace BookAStar.Data public class RemoteEntity : LocalEntity, ICommand where K : IEquatable { - private string _controller; + public string ControllerName { protected set; get; } public event EventHandler CanExecuteChanged; public bool IsExecuting { get; private set; } - private Uri controllerUri; + public Uri ControllerUri { get; protected set; } + public bool CanExecute(object parameter) { return !IsExecuting && (MainSettings.CurrentUser != null); @@ -28,11 +29,11 @@ namespace BookAStar.Data { if (string.IsNullOrWhiteSpace(controllerName)) throw new InvalidOperationException(); - _controller = controllerName; - controllerUri = new Uri(Constants.YavscApiUrl + "/" + _controller); + ControllerName = controllerName; + ControllerUri = new Uri(Constants.YavscApiUrl + "/" + ControllerName); } - private void BeforeExecute() + protected void BeforeExecute() { if (IsExecuting) throw new InvalidOperationException("Already executing"); @@ -45,7 +46,7 @@ namespace BookAStar.Data /// Refresh the collection /// /// - public async void Execute(object parameter) + public virtual async void Execute(object parameter) { BeforeExecute(); using (HttpClient client = UserHelpers.CreateClient()) @@ -53,7 +54,7 @@ namespace BookAStar.Data // Get the whole data try { - using (var response = await client.GetAsync(controllerUri)) + using (var response = await client.GetAsync(ControllerUri)) { if (response.IsSuccessStatusCode) { @@ -77,26 +78,27 @@ namespace BookAStar.Data AfterExecuting(); } - private void AfterExecuting() + protected void AfterExecuting() { IsExecuting = false; if (CanExecuteChanged != null) CanExecuteChanged.Invoke(this, new EventArgs()); } - public async Task Get(K key) + public virtual async Task Get(K key) { var item = LocalGet(key); if (item == null) item = await RemoteGet(key); CurrentItem = item; return CurrentItem; } - private Uri GetUri(K key) + + protected Uri GetUri(K key) { - return new Uri(controllerUri.AbsoluteUri + "/" + key.ToString()); + return new Uri(ControllerUri.AbsoluteUri + "/" + key.ToString()); } - public async Task RemoteGet(K key) + public virtual async Task RemoteGet(K key) { V item = default(V); BeforeExecute(); @@ -121,7 +123,7 @@ namespace BookAStar.Data return item; } - public async void Create(V item) + public virtual async void Create(V item) { BeforeExecute(); @@ -131,13 +133,13 @@ namespace BookAStar.Data HttpContent content = new StringContent( stringContent, Encoding.UTF8, "application/json" ); - using (var response = await client.PostAsync(controllerUri, content)) + using (var response = await client.PostAsync(ControllerUri, content)) { if (!response.IsSuccessStatusCode) { // TODO throw custom exception, and catch to inform user var errcontent = await response.Content.ReadAsStringAsync(); - Debug.WriteLine($"Create failed posting {stringContent} @ {controllerUri.AbsoluteUri}: {errcontent}"); + Debug.WriteLine($"Create failed posting {stringContent} @ {ControllerUri.AbsoluteUri}: {errcontent}"); } else { @@ -152,7 +154,7 @@ namespace BookAStar.Data CurrentItem = item; AfterExecuting(); } - public async void Update(V item) + public virtual async void Update(V item) { BeforeExecute(); @@ -188,7 +190,7 @@ namespace BookAStar.Data AfterExecuting(); } - public async void Delete(K key) + public virtual async void Delete(K key) { BeforeExecute(); var uri = GetUri(key); diff --git a/BookAStar/BookAStar/Helpers/UserHelpers.cs b/BookAStar/BookAStar/Helpers/UserHelpers.cs index 2b28d8e8..5d90042d 100644 --- a/BookAStar/BookAStar/Helpers/UserHelpers.cs +++ b/BookAStar/BookAStar/Helpers/UserHelpers.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.Globalization; using System.IO; using System.Net.Http; @@ -7,8 +8,12 @@ using Xamarin.Forms; namespace BookAStar.Helpers { + using Data.NonCrUD; + using Model.FileSystem; + public static class UserHelpers { + public static ImageSource Avatar(string avatarPath) { var result = avatarPath == null ? diff --git a/BookAStar/BookAStar/Model/FileSystem/UserDirectoryInfo.cs b/BookAStar/BookAStar/Model/FileSystem/UserDirectoryInfo.cs new file mode 100644 index 00000000..396e9364 --- /dev/null +++ b/BookAStar/BookAStar/Model/FileSystem/UserDirectoryInfo.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookAStar.Model.FileSystem +{ + public class FileAddress : IEquatable + { + public string SubPath { get; set; } + public string UserName { get; set; } + + public bool Equals(FileAddress other) + { + if (other == null) return false; + if (other.UserName != UserName) return false; + if (other.SubPath != SubPath) return false; + return true; + } + } + + public class UserDirectoryInfo : FileAddress + { + public UserFileInfo[] Files + { + get; set; + } + + public string[] SubDirectories + { + get; set; + } + } +} diff --git a/BookAStar/BookAStar/Model/FileSystem/UserFileInfo.cs b/BookAStar/BookAStar/Model/FileSystem/UserFileInfo.cs new file mode 100644 index 00000000..45e2257a --- /dev/null +++ b/BookAStar/BookAStar/Model/FileSystem/UserFileInfo.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookAStar.Model.FileSystem +{ + public class UserFileInfo + { + public string Name { get; set; } + + public long Size { get; set; } + + public DateTime CreationTime { get; set; } + + public DateTime LastModified { get; set; } + } +} diff --git a/BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml b/BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml new file mode 100644 index 00000000..84ab893c --- /dev/null +++ b/BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml @@ -0,0 +1,35 @@ + + + \ No newline at end of file diff --git a/BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml.cs b/BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml.cs new file mode 100644 index 00000000..429f02d3 --- /dev/null +++ b/BookAStar/BookAStar/Pages/UserProfile/UserFiles.xaml.cs @@ -0,0 +1,34 @@ +using Xamarin.Forms; + +namespace BookAStar.Pages.UserProfile +{ + using ViewModels.UserProfile; + using Data; + public partial class UserFiles : ContentPage + { + protected DirectoryInfoViewModel model; + + public UserFiles() + { + InitializeComponent(); + + var currentDir = DataManager.Current.RemoteFiles.CurrentItem; + + BindingContext = new DirectoryInfoViewModel(currentDir) + { + RefreshCommand = new Command(() => + { + DataManager.Current.RemoteFiles.Execute(null); + + this.dirlist.EndRefresh(); + this.filelist.EndRefresh(); + }) + }; + } + + protected override void OnBindingContextChanged() + { + base.OnBindingContextChanged(); + } + } +} diff --git a/BookAStar/BookAStar/ViewModels/UserProfile/DirectoryInfoViewModel.cs b/BookAStar/BookAStar/ViewModels/UserProfile/DirectoryInfoViewModel.cs new file mode 100644 index 00000000..595f8a9c --- /dev/null +++ b/BookAStar/BookAStar/ViewModels/UserProfile/DirectoryInfoViewModel.cs @@ -0,0 +1,32 @@ + +using System.Collections.ObjectModel; +using System.Windows.Input; +using XLabs.Forms.Mvvm; + +namespace BookAStar.ViewModels.UserProfile +{ + using Model.FileSystem; + + public class DirectoryInfoViewModel : ViewModel + { + public ObservableString SubPath { get; set; } + public ObservableCollection SubDirectories { get; set; } + public ObservableCollection FileInfo { get; set; } + public ICommand RefreshCommand { get; set; } + public DirectoryInfoViewModel (UserDirectoryInfo model=null) + { + Data.DataManager.Current.RemoteFiles.CollectionChanged += RemoteFiles_CollectionChanged; + + if (model == null) + model = Data.DataManager.Current.RemoteFiles.CurrentItem; + SubDirectories = new ObservableCollection (model.SubDirectories); + SubPath = new ObservableString (model.SubPath); + FileInfo = new ObservableCollection (model.Files); + } + + private void RemoteFiles_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + throw new System.NotImplementedException(); + } + } +}