From 2b07e6aaf82b32a300273e91b808b57ea2292c20 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 26 Jul 2013 21:15:55 -0400 Subject: [PATCH] separate display preferences per client --- MediaBrowser.Api/DisplayPreferencesService.cs | 16 ++++++- .../Entities/CollectionFolder.cs | 2 +- MediaBrowser.Controller/Entities/Folder.cs | 2 +- .../IDisplayPreferencesRepository.cs | 8 +++- MediaBrowser.Model/ApiClient/IApiClient.cs | 6 ++- ...MediaBrowser.Server.Implementations.csproj | 10 ++-- .../SqliteDisplayPreferencesRepository.cs | 27 +++++++---- .../packages.config | 2 +- .../LibraryExplorer.xaml.cs | 46 +++++++++---------- .../MediaBrowser.ServerApplication.csproj | 9 ++-- .../packages.config | 2 +- Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 14 files changed, 86 insertions(+), 54 deletions(-) diff --git a/MediaBrowser.Api/DisplayPreferencesService.cs b/MediaBrowser.Api/DisplayPreferencesService.cs index fea34ec19a..870c62ccd6 100644 --- a/MediaBrowser.Api/DisplayPreferencesService.cs +++ b/MediaBrowser.Api/DisplayPreferencesService.cs @@ -21,6 +21,12 @@ namespace MediaBrowser.Api /// The id. [ApiMember(Name = "DisplayPreferencesId", Description = "DisplayPreferences Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] public Guid DisplayPreferencesId { get; set; } + + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] + public Guid UserId { get; set; } + + [ApiMember(Name = "Client", Description = "Client", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] + public string Client { get; set; } } [Route("/DisplayPreferences/{Id}", "GET")] @@ -33,6 +39,12 @@ namespace MediaBrowser.Api /// The id. [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public Guid Id { get; set; } + + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public Guid UserId { get; set; } + + [ApiMember(Name = "Client", Description = "Client", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public string Client { get; set; } } /// @@ -66,7 +78,7 @@ namespace MediaBrowser.Api /// The request. public object Get(GetDisplayPreferences request) { - var result = _displayPreferencesManager.GetDisplayPreferences(request.Id); + var result = _displayPreferencesManager.GetDisplayPreferences(request.Id, request.UserId, request.Client); return ToOptimizedResult(result); } @@ -80,7 +92,7 @@ namespace MediaBrowser.Api // Serialize to json and then back so that the core doesn't see the request dto type var displayPreferences = _jsonSerializer.DeserializeFromString(_jsonSerializer.SerializeToString(request)); - var task = _displayPreferencesManager.SaveDisplayPreferences(displayPreferences, CancellationToken.None); + var task = _displayPreferencesManager.SaveDisplayPreferences(displayPreferences, request.UserId, request.Client, CancellationToken.None); Task.WaitAll(task); } diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs index 507b6df8a8..7d7d60ae53 100644 --- a/MediaBrowser.Controller/Entities/CollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs @@ -35,7 +35,7 @@ namespace MediaBrowser.Controller.Entities /// Allow different display preferences for each collection folder /// /// The display prefs id. - protected override Guid DisplayPreferencesId + public override Guid DisplayPreferencesId { get { diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 3a5cd1b40b..03c1364de0 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -72,7 +72,7 @@ namespace MediaBrowser.Controller.Entities /// /// The display prefs id. [IgnoreDataMember] - protected virtual Guid DisplayPreferencesId + public virtual Guid DisplayPreferencesId { get { diff --git a/MediaBrowser.Controller/Persistence/IDisplayPreferencesRepository.cs b/MediaBrowser.Controller/Persistence/IDisplayPreferencesRepository.cs index ecd8c1136d..4e56932eca 100644 --- a/MediaBrowser.Controller/Persistence/IDisplayPreferencesRepository.cs +++ b/MediaBrowser.Controller/Persistence/IDisplayPreferencesRepository.cs @@ -20,16 +20,20 @@ namespace MediaBrowser.Controller.Persistence /// Saves display preferences for an item /// /// The display preferences. + /// The user id. + /// The client. /// The cancellation token. /// Task. - Task SaveDisplayPreferences(DisplayPreferences displayPreferences, + Task SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid userId, string client, CancellationToken cancellationToken); /// /// Gets the display preferences. /// /// The display preferences id. + /// The user id. + /// The client. /// Task{DisplayPreferences}. - DisplayPreferences GetDisplayPreferences(Guid displayPreferencesId); + DisplayPreferences GetDisplayPreferences(Guid displayPreferencesId, Guid userId, string client); } } diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs index c22ca74e7e..d9a7b9bc4c 100644 --- a/MediaBrowser.Model/ApiClient/IApiClient.cs +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -477,8 +477,10 @@ namespace MediaBrowser.Model.ApiClient /// Gets the display preferences. /// /// The id. + /// The user id. + /// The client. /// Task{BaseItemDto}. - Task GetDisplayPreferencesAsync(string id); + Task GetDisplayPreferencesAsync(string id, string userId, string client); /// /// Updates display preferences for a user @@ -487,7 +489,7 @@ namespace MediaBrowser.Model.ApiClient /// The display preferences. /// Task{DisplayPreferences}. /// userId - Task UpdateDisplayPreferencesAsync(DisplayPreferences displayPreferences); + Task UpdateDisplayPreferencesAsync(DisplayPreferences displayPreferences, string userId, string client); /// /// Posts a set of data to a url, and deserializes the return stream into T diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index e58369df14..294a7f41c5 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -82,11 +82,13 @@ - - ..\packages\System.Data.SQLite.x86.1.0.86.0\lib\net45\System.Data.SQLite.dll + + False + ..\packages\System.Data.SQLite.x86.1.0.87.0\lib\net45\System.Data.SQLite.dll - - ..\packages\System.Data.SQLite.x86.1.0.86.0\lib\net45\System.Data.SQLite.Linq.dll + + False + ..\packages\System.Data.SQLite.x86.1.0.87.0\lib\net45\System.Data.SQLite.Linq.dll ..\packages\Rx-Core.2.1.30214.0\lib\Net45\System.Reactive.Core.dll diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteDisplayPreferencesRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteDisplayPreferencesRepository.cs index 7a984fc002..8cd618d210 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteDisplayPreferencesRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteDisplayPreferencesRepository.cs @@ -85,9 +85,8 @@ namespace MediaBrowser.Server.Implementations.Persistence string[] queries = { - "create table if not exists displaypreferences (id GUID, data BLOB)", - "create unique index if not exists displaypreferencesindex on displaypreferences (id)", - "create table if not exists schema_version (table_name primary key, version)", + "create table if not exists userdisplaypreferences (id GUID, userId GUID, client text, data BLOB)", + "create unique index if not exists userdisplaypreferencesindex on userdisplaypreferences (id, userId, client)", //pragmas "pragma temp_store = memory" }; @@ -99,10 +98,12 @@ namespace MediaBrowser.Server.Implementations.Persistence /// Save the display preferences associated with an item in the repo /// /// The display preferences. + /// The user id. + /// The client. /// The cancellation token. /// Task. /// item - public async Task SaveDisplayPreferences(DisplayPreferences displayPreferences, CancellationToken cancellationToken) + public async Task SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid userId, string client, CancellationToken cancellationToken) { if (displayPreferences == null) { @@ -131,9 +132,11 @@ namespace MediaBrowser.Server.Implementations.Persistence using (var cmd = _connection.CreateCommand()) { - cmd.CommandText = "replace into displaypreferences (id, data) values (@1, @2)"; + cmd.CommandText = "replace into userdisplaypreferences (id, userid, client, data) values (@1, @2, @3, @4)"; cmd.AddParam("@1", displayPreferences.Id); - cmd.AddParam("@2", serialized); + cmd.AddParam("@2", userId); + cmd.AddParam("@3", client); + cmd.AddParam("@4", serialized); cmd.Transaction = transaction; @@ -177,9 +180,11 @@ namespace MediaBrowser.Server.Implementations.Persistence /// Gets the display preferences. /// /// The display preferences id. + /// The user id. + /// The client. /// Task{DisplayPreferences}. /// item - public DisplayPreferences GetDisplayPreferences(Guid displayPreferencesId) + public DisplayPreferences GetDisplayPreferences(Guid displayPreferencesId, Guid userId, string client) { if (displayPreferencesId == Guid.Empty) { @@ -187,11 +192,17 @@ namespace MediaBrowser.Server.Implementations.Persistence } var cmd = _connection.CreateCommand(); - cmd.CommandText = "select data from displaypreferences where id = @id"; + cmd.CommandText = "select data from userdisplaypreferences where id = @id and userId=@userId and client=@client"; var idParam = cmd.Parameters.Add("@id", DbType.Guid); idParam.Value = displayPreferencesId; + var userIdParam = cmd.Parameters.Add("@userId", DbType.Guid); + userIdParam.Value = userId; + + var clientParam = cmd.Parameters.Add("@client", DbType.String); + clientParam.Value = client; + using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow)) { if (reader.Read()) diff --git a/MediaBrowser.Server.Implementations/packages.config b/MediaBrowser.Server.Implementations/packages.config index 974c4c9bc3..b9868a4d31 100644 --- a/MediaBrowser.Server.Implementations/packages.config +++ b/MediaBrowser.Server.Implementations/packages.config @@ -14,5 +14,5 @@ - + \ No newline at end of file diff --git a/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs b/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs index 6dabd85af2..84e8ce55fc 100644 --- a/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs +++ b/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs @@ -61,7 +61,7 @@ namespace MediaBrowser.ServerApplication lblVersion.Content = "Version: " + appHost.ApplicationVersion; foreach (var user in userManager.Users) ddlProfile.Items.Add(user); - ddlProfile.Items.Insert(0,new User {Name = "Physical"}); + ddlProfile.Items.Insert(0, new User { Name = "Physical" }); ddlProfile.SelectedIndex = 0; ddlIndexBy.Visibility = ddlSortBy.Visibility = lblIndexBy.Visibility = lblSortBy.Visibility = Visibility.Hidden; @@ -94,22 +94,22 @@ namespace MediaBrowser.ServerApplication children = OrderByName(children, CurrentUser); foreach (Folder folder in children) - { + { - var currentFolder = folder; - Task.Factory.StartNew(() => - { - var prefs = ddlProfile.SelectedItem != null ? _displayPreferencesManager.GetDisplayPreferences(currentFolder.GetDisplayPreferencesId((ddlProfile.SelectedItem as User).Id)) ?? new DisplayPreferences { SortBy = ItemSortBy.SortName } : new DisplayPreferences { SortBy = ItemSortBy.SortName }; - var node = new TreeViewItem { Tag = currentFolder }; - - var subChildren = currentFolder.GetChildren(CurrentUser, true, prefs.IndexBy); - subChildren = OrderByName(subChildren, CurrentUser); - AddChildren(node, subChildren, CurrentUser); - node.Header = currentFolder.Name + " (" + - node.Items.Count + ")"; - tvwLibrary.Items.Add(node); - }, CancellationToken.None, TaskCreationOptions.None, ui); - } + var currentFolder = folder; + Task.Factory.StartNew(() => + { + var prefs = ddlProfile.SelectedItem != null ? _displayPreferencesManager.GetDisplayPreferences(currentFolder.GetDisplayPreferencesId((ddlProfile.SelectedItem as User).Id), (ddlProfile.SelectedItem as User).Id, "LibraryExplorer") ?? new DisplayPreferences { SortBy = ItemSortBy.SortName } : new DisplayPreferences { SortBy = ItemSortBy.SortName }; + var node = new TreeViewItem { Tag = currentFolder }; + + var subChildren = currentFolder.GetChildren(CurrentUser, true, prefs.IndexBy); + subChildren = OrderByName(subChildren, CurrentUser); + AddChildren(node, subChildren, CurrentUser); + node.Header = currentFolder.Name + " (" + + node.Items.Count + ")"; + tvwLibrary.Items.Add(node); + }, CancellationToken.None, TaskCreationOptions.None, ui); + } }); lblLoading.Visibility = Visibility.Hidden; Cursor = Cursors.Arrow; @@ -148,11 +148,11 @@ namespace MediaBrowser.ServerApplication { foreach (var item in children) { - var node = new TreeViewItem { Tag = item }; + var node = new TreeViewItem { Tag = item }; var subFolder = item as Folder; if (subFolder != null) { - var prefs = _displayPreferencesManager.GetDisplayPreferences(subFolder.GetDisplayPreferencesId(user.Id)); + var prefs = _displayPreferencesManager.GetDisplayPreferences(subFolder.GetDisplayPreferencesId(user.Id), user.Id, "LibraryExplorer"); AddChildren(node, OrderBy(subFolder.GetChildren(user, true), user, prefs.SortBy), user); node.Header = item.Name + " (" + node.Items.Count + ")"; @@ -185,7 +185,7 @@ namespace MediaBrowser.ServerApplication lblIndexBy.Visibility = ddlIndexBy.Visibility = ddlSortBy.Visibility = lblSortBy.Visibility = Visibility.Visible; ddlIndexBy.ItemsSource = folder.IndexByOptionStrings; - ddlSortBy.ItemsSource = new [] + ddlSortBy.ItemsSource = new[] { ItemSortBy.SortName, ItemSortBy.Album, @@ -200,7 +200,7 @@ namespace MediaBrowser.ServerApplication ItemSortBy.Runtime }; - var prefs = _displayPreferencesManager.GetDisplayPreferences(folder.GetDisplayPreferencesId((ddlProfile.SelectedItem as User).Id)); + var prefs = _displayPreferencesManager.GetDisplayPreferences(folder.GetDisplayPreferencesId((ddlProfile.SelectedItem as User).Id), (ddlProfile.SelectedItem as User).Id, "LibraryExplorer"); ddlIndexBy.SelectedItem = prefs != null ? prefs.IndexBy ?? LocalizedStrings.Instance.GetString("NoneDispPref") @@ -359,7 +359,7 @@ namespace MediaBrowser.ServerApplication var folder = treeItem != null ? treeItem.Tag as Folder : null; - var prefs = folder != null ? _displayPreferencesManager.GetDisplayPreferences(folder.GetDisplayPreferencesId(CurrentUser.Id)) : new DisplayPreferences { SortBy = ItemSortBy.SortName }; + var prefs = folder != null ? _displayPreferencesManager.GetDisplayPreferences(folder.GetDisplayPreferencesId(CurrentUser.Id), CurrentUser.Id, "LibraryExplorer") : new DisplayPreferences { SortBy = ItemSortBy.SortName }; if (folder != null && prefs.IndexBy != ddlIndexBy.SelectedItem as string) { //grab UI context so we can update within the below task @@ -400,7 +400,7 @@ namespace MediaBrowser.ServerApplication var folder = treeItem != null ? treeItem.Tag as Folder : null; - var prefs = folder != null ? _displayPreferencesManager.GetDisplayPreferences(folder.GetDisplayPreferencesId(CurrentUser.Id)) : new DisplayPreferences(); + var prefs = folder != null ? _displayPreferencesManager.GetDisplayPreferences(folder.GetDisplayPreferencesId(CurrentUser.Id), CurrentUser.Id, "LibraryExplorer") : new DisplayPreferences(); if (folder != null && prefs.SortBy != ddlSortBy.SelectedItem as string) { //grab UI context so we can update within the below task @@ -605,7 +605,7 @@ namespace MediaBrowser.ServerApplication uri = new Uri("pack://application:,,,/Resources/Images/series.png"); else if (item is BoxSet) uri = new Uri("pack://application:,,,/Resources/Images/boxset.png"); - else + else uri = new Uri("pack://application:,,,/Resources/Images/folder.png"); return new BitmapImage(uri); diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index 4ca3480b4c..29ae97a476 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -172,12 +172,13 @@ - + False - ..\packages\System.Data.SQLite.x86.1.0.86.0\lib\net45\System.Data.SQLite.dll + ..\packages\System.Data.SQLite.x86.1.0.87.0\lib\net45\System.Data.SQLite.dll - - ..\packages\System.Data.SQLite.x86.1.0.86.0\lib\net45\System.Data.SQLite.Linq.dll + + False + ..\packages\System.Data.SQLite.x86.1.0.87.0\lib\net45\System.Data.SQLite.Linq.dll diff --git a/MediaBrowser.ServerApplication/packages.config b/MediaBrowser.ServerApplication/packages.config index beb60007bd..d0166b959c 100644 --- a/MediaBrowser.ServerApplication/packages.config +++ b/MediaBrowser.ServerApplication/packages.config @@ -12,5 +12,5 @@ - + \ No newline at end of file diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index c061a9f998..3c95e48812 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.156 + 3.0.157 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 5da04194d8..588d22d11c 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.156 + 3.0.157 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 3cd52216ff..7e83a39497 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.156 + 3.0.157 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +