Prechádzať zdrojové kódy

First level of ratings and reviews

Eric Reed 11 rokov pred
rodič
commit
63554bde5b

+ 1 - 0
MediaBrowser.Api/MediaBrowser.Api.csproj

@@ -85,6 +85,7 @@
     <Compile Include="LocalizationService.cs" />
     <Compile Include="MoviesService.cs" />
     <Compile Include="NotificationsService.cs" />
+    <Compile Include="PackageReviewService.cs" />
     <Compile Include="PackageService.cs" />
     <Compile Include="Playback\Hls\AudioHlsService.cs" />
     <Compile Include="Playback\Hls\BaseHlsService.cs" />

+ 80 - 0
MediaBrowser.Api/PackageReviewService.cs

@@ -0,0 +1,80 @@
+using System.Collections.Generic;
+using System.Globalization;
+using System.Threading;
+using System.Threading.Tasks;
+using MediaBrowser.Common.Constants;
+using MediaBrowser.Common.Net;
+using ServiceStack.ServiceHost;
+
+namespace MediaBrowser.Api
+{
+    /// <summary>
+    /// Class InstallPackage
+    /// </summary>
+    [Route("/PackageReviews/{Id}", "POST")]
+    [Api(("Creates or updates a package review"))]
+    public class CreateReviewRequest : IReturnVoid
+    {
+        /// <summary>
+        /// Gets or sets the Id.
+        /// </summary>
+        /// <value>The Id.</value>
+        [ApiMember(Name = "Id", Description = "Package Id", IsRequired = true, DataType = "int", ParameterType = "path", Verb = "POST")]
+        public int Id { get; set; }
+
+        /// <summary>
+        /// Gets or sets the rating.
+        /// </summary>
+        /// <value>The review.</value>
+        [ApiMember(Name = "Rating", Description = "The rating value (1-5)", IsRequired = true, DataType = "int", ParameterType = "query", Verb = "POST")]
+        public int Rating { get; set; }
+
+        /// <summary>
+        /// Gets or sets the recommend value.
+        /// </summary>
+        /// <value>Whether or not this review recommends this item.</value>
+        [ApiMember(Name = "Recommend", Description = "Whether or not this review recommends this item", IsRequired = true, DataType = "bool", ParameterType = "query", Verb = "POST")]
+        public bool Recommend { get; set; }
+
+        /// <summary>
+        /// Gets or sets the title.
+        /// </summary>
+        /// <value>The title.</value>
+        [ApiMember(Name = "Title", Description = "Optional short description of review.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
+        public string Title { get; set; }
+
+        /// <summary>
+        /// Gets or sets the full review.
+        /// </summary>
+        /// <value>The full review.</value>
+        [ApiMember(Name = "Review", Description = "Optional full review.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
+        public string Review { get; set; }
+    }
+
+
+    public class PackageReviewService : BaseApiService
+    {
+        private readonly IHttpClient _httpClient;
+        private readonly INetworkManager _netManager;
+
+        public PackageReviewService(IHttpClient client, INetworkManager net)
+        {
+            _httpClient = client;
+            _netManager = net;
+        }
+
+        public void Post(CreateReviewRequest request)
+        {
+            var review = new Dictionary<string, string>
+                             { { "id", request.Id.ToString(CultureInfo.InvariantCulture) },
+                               { "mac", _netManager.GetMacAddress() },
+                               { "rating", request.Rating.ToString(CultureInfo.InvariantCulture) },
+                               { "recommend", request.Recommend.ToString() },
+                               { "title", request.Title },
+                               { "review", request.Review },
+                             };
+
+            Task.WaitAll(_httpClient.Post(Constants.MbAdminUrl + "/service/packageReview/update", review, CancellationToken.None));
+        }
+    }
+}

+ 37 - 0
MediaBrowser.Model/Entities/PackageReviewInfo.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Model.Entities
+{
+    public class PackageReviewInfo
+    {
+        /// <summary>
+        /// The package id (database key) for this review
+        /// </summary>
+        public int id { get; set; }
+
+        /// <summary>
+        /// The rating value
+        /// </summary>
+        public int rating { get; set; }
+
+        /// <summary>
+        /// Whether or not this review recommends this item
+        /// </summary>
+        public bool recommend { get; set; }
+
+        /// <summary>
+        /// A short description of the review
+        /// </summary>
+        public string title { get; set; }
+
+        /// <summary>
+        /// A full review
+        /// </summary>
+        public string review { get; set; }
+
+    }
+}

+ 1 - 0
MediaBrowser.Model/MediaBrowser.Model.csproj

@@ -59,6 +59,7 @@
     <Compile Include="Dto\ItemByNameCounts.cs" />
     <Compile Include="Dto\ItemCounts.cs" />
     <Compile Include="Dto\ItemIndex.cs" />
+    <Compile Include="Entities\PackageReviewInfo.cs" />
     <Compile Include="LiveTv\EpgFullInfo.cs" />
     <Compile Include="LiveTv\EpgInfo.cs" />
     <Compile Include="Providers\ImageProviderInfo.cs" />

+ 18 - 0
MediaBrowser.Model/Updates/PackageInfo.cs

@@ -117,6 +117,24 @@ namespace MediaBrowser.Model.Updates
         /// <value>The name.</value>
         public string guid { get; set; }
 
+        /// <summary>
+        /// Gets or sets the total number of machines who have checked registration for this package (if premium).
+        /// </summary>
+        /// <value>The total hits.</value>
+        public int totalHits { get; set; }
+
+        /// <summary>
+        /// Gets or sets the total number of ratings for this package.
+        /// </summary>
+        /// <value>The total ratings.</value>
+        public int totalRatings { get; set; }
+
+        /// <summary>
+        /// Gets or sets the average rating for this package .
+        /// </summary>
+        /// <value>The rating.</value>
+        public float avgRating { get; set; }
+
         /// <summary>
         /// Gets or sets whether or not this package is registered.
         /// </summary>

+ 1 - 1
MediaBrowser.WebDashboard/Api/DashboardService.cs

@@ -453,7 +453,7 @@ namespace MediaBrowser.WebDashboard.Api
                                       "extensions.js",
                                       "site.js",
                                       "librarybrowser.js",
-
+                                      "ratingdialog.js",
                                       "aboutpage.js",
                                       "allusersettings.js",
                                       "alphapicker.js",

+ 10 - 0
MediaBrowser.WebDashboard/ApiClient.js

@@ -3569,6 +3569,16 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
                 url: url
             });
         };
+
+        self.createPackageReview = function(review) {
+
+            var url = self.getUrl("PackageReviews/" + review.id, review);
+
+            return self.ajax({
+                type: "POST",
+                url: url,
+            });
+        };
     }
 
 }(jQuery, navigator, window.JSON, window.WebSocket, setTimeout, window);

+ 3 - 0
MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj

@@ -332,6 +332,9 @@
     <Content Include="dashboard-ui\gamesystems.html">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
+    <Content Include="dashboard-ui\scripts\ratingdialog.js">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
     <Content Include="dashboard-ui\scripts\episodes.js">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>