fixed issue with test project's invalid references (for web api). Added UmbracoAuthorizedApiController, change the

examine mgmt tools to use web api, got the dashboard displaying all relavent properties for indexers.
This commit is contained in:
Shannon Deminick
2013-02-27 05:24:45 +06:00
parent f7cfa507d7
commit b374dcf2c2
16 changed files with 340 additions and 131 deletions

View File

@@ -13,17 +13,6 @@ namespace Umbraco.Core
public static class UrlHelperExtensions
{
/// <summary>
/// Returns the base path (not including the 'action') of the MVC controller "ExamineManagementController"
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static string GetExamineManagementServicePath(this UrlHelper url)
{
var result = url.Action("Index", "ExamineManagement", new { area = GlobalSettings.UmbracoMvcArea });
return result.TrimEnd("Index").EnsureEndsWith('/');
}
/// <summary>
/// Returns the base path (not including the 'action') of the MVC controller "SaveFileController"
/// </summary>

View File

@@ -68,6 +68,10 @@
<Private>True</Private>
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
@@ -86,12 +90,27 @@
<Private>True</Private>
<HintPath>..\packages\SqlServerCE.4.0.0.0\lib\System.Data.SqlServerCe.Entity.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.4.0.20710.0\lib\net40\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.4.0.20710.0\lib\net40\System.Web.Http.WebHost.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.20710.0\lib\net40\System.Web.Mvc.dll</HintPath>

View File

@@ -5,8 +5,14 @@
<package id="Lucene.Net" version="2.9.4.1" targetFramework="net40" />
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Razor" version="2.0.20715.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net40" />
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
<package id="NUnit" version="2.6.2" targetFramework="net40" />
<package id="RhinoMocks" version="3.6.1" targetFramework="net40" />
<package id="SharpZipLib" version="0.86.0" targetFramework="net40" />

View File

@@ -1975,8 +1975,6 @@
</Content>
<Content Include="Umbraco\Scripting\templates\cshtml\MultinodeTree-picker.cshtml" />
<Content Include="Umbraco\Scripting\templates\cshtml\TwitterFeed.cshtml" />
<Content Include="Umbraco\Views\ExamineManagement\ExamineDetails.cshtml" />
<Content Include="Umbraco\Views\Web.config" />
<None Include="umbraco_client\CodeMirror\js\mode\coffeescript\LICENSE" />
<None Include="umbraco_client\CodeMirror\js\mode\pascal\LICENSE" />
<None Include="umbraco_client\CodeMirror\js\mode\perl\LICENSE" />

View File

@@ -1,10 +0,0 @@
@model Umbraco.Web.Search.ExamineDashboardDetails
<div class="propertypane">
<div class="propertyItem">
<div class="dashboardWrapper">
<h2>Examine Management</h2>
<img src="@(GlobalSettings.ClientPath)/Dashboards/ExamineManagementIco.png" alt="uGoLive" class="dashboardIcon">
</div>
</div>
</div>

View File

@@ -1,55 +0,0 @@
<?xml version="1.0"?>
<configuration>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Umbraco.Web" />
<add namespace="Umbraco.Core" />
<add namespace="Umbraco.Core.Models" />
<add namespace="Umbraco.Web.Mvc" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>

View File

@@ -1,5 +1,7 @@
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ExamineManagement.ascx.cs" Inherits="Umbraco.Web.UI.Umbraco.Dashboard.ExamineManagement" %>
<%@ Import Namespace="Umbraco.Core" %>
<%@ Import Namespace="Umbraco.Web" %>
<%@ Import Namespace="umbraco" %>
<%@ Register TagPrefix="cc1" Namespace="Umbraco.Web.UI.Controls" Assembly="umbraco" %>
<%@ Register TagPrefix="umb" Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" %>
@@ -24,9 +26,89 @@
<div id="examineManagement">
<div data-bind="visible: loading()">
<cc1:ProgressBar runat="server" ID="ProgBar1" Text="Loading..." />
<div class="propertypane">
<div class="propertyItem">
<div class="dashboardWrapper">
<h2>Examine Management</h2>
<img src="<%= GlobalSettings.ClientPath %>/Dashboards/ExamineManagementIco.png" alt="Examine Management" class="dashboardIcon">
<div data-bind="visible: loading()">
<cc1:ProgressBar runat="server" ID="ProgBar1" Text="Loading..." />
</div>
<h3>Indexers</h3>
<div data-bind="foreach: indexerDetails">
<div class="indexer">
<a href="#" data-bind="text: Name, click: toggleProperties"></a>
<table class="propertyPane" data-bind="visible: showProperties">
<tr>
<th>Include node types</th>
<td data-bind="text: IndexCriteria.IncludeNodeTypes"></td>
</tr>
<tr>
<th>Exclude node types</th>
<td data-bind="text: IndexCriteria.ExcludeNodeTypes"></td>
</tr>
<tr data-bind="visible: IndexCriteria.ParentNodeId != null">
<th>Parent node id</th>
<td data-bind="text: IndexCriteria.ParentNodeId"></td>
</tr>
</table>
<div class="propertyPane" data-bind="visible: showProperties">
<strong>System fields</strong>
<table>
<thead>
<tr>
<th>Name</th>
<th>Enable sorting</th>
<th>Type</th>
</tr>
</thead>
<tbody data-bind="foreach: IndexCriteria.StandardFields">
<tr>
<th data-bind="text: Name"></th>
<td data-bind="text: EnableSorting"></td>
<td data-bind="text: Type"></td>
</tr>
</tbody>
</table>
</div>
<div class="propertyPane" data-bind="visible: showProperties">
<strong>User fields</strong>
<table>
<thead>
<tr>
<th>Name</th>
<th>Enable sorting</th>
<th>Type</th>
</tr>
</thead>
<tbody data-bind="foreach: IndexCriteria.UserFields">
<tr>
<th data-bind="text: Name"></th>
<td data-bind="text: EnableSorting"></td>
<td data-bind="text: Type"></td>
</tr>
</tbody>
</table>
</div>
<table class="propertyPane" data-bind="foreach: IndexerProperties, visible: showProperties">
<tr>
<th data-bind="text: key"></th>
<td data-bind="text: value"></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<div data-bind="html: summary"></div>
</div>

View File

@@ -1 +1,23 @@
#examineManagement .indexer {
padding-top: 3px;
}
#examineManagement .propertyPane {
padding: 5px;
}
#examineManagement table th
{
font-weight: bold;
width: 200px;
}
#examineManagement table td {
color: #999;
}
#examineManagement .propertyPane strong
{
color: #f26e20;
padding: 3px;
display: block;
}

View File

@@ -3,11 +3,21 @@
(function ($) {
Umbraco.Dashboards.ExamineManagement = base2.Base.extend({
//private methods/variables
_opts: null,
_koViewModel: null,
_mapDictionaryToArray: function (dictionary) {
var result = [];
for (var key in dictionary) {
if (dictionary.hasOwnProperty(key)) {
result.push({ key: key, value: dictionary[key] });
}
}
return result;
},
// Constructor
constructor: function (opts) {
// Merge options with default
@@ -20,29 +30,53 @@
init: function () {
var self = this;
//The knockout js view model for the selected item
self._koViewModel = {
summary: ko.observable(""),
loading: ko.observable(false)
indexerDetails: ko.observable(""),
loading: ko.observable(false),
expandIndex: function () {
}
//publishAll: ko.observable(false),
//includeUnpublished: ko.observable(false)
};
ko.applyBindings(self._koViewModel, self._opts.container.get(0));
this.loadSummary();
this.loadDetails();
},
loadSummary: function() {
loadDetails: function () {
var self = this;
self._koViewModel.loading(true);
$.get(self._opts.restServiceLocation + "Index",
function(e) {
$.get(self._opts.restServiceLocation + "GetIndexerDetails",
function (e) {
self._koViewModel.loading(false);
self._koViewModel.summary(e);
}, "html").fail(function(a, b, c) {
for (var item in e) {
//need to re-map the dictionary to an array so we can bind to it
e[item].IndexerProperties = self._mapDictionaryToArray(e[item].IndexerProperties);
//add a showProperties property to the object
e[item].showProperties = ko.observable(false);
//add a toggleProperties method
e[item].toggleProperties = function () {
this.showProperties(!this.showProperties());
};
//change the include/exclude node types to say something different if they are empty
e[item].IndexCriteria.IncludeNodeTypes = e[item].IndexCriteria.IncludeNodeTypes.join();
e[item].IndexCriteria.ExcludeNodeTypes = e[item].IndexCriteria.ExcludeNodeTypes.join();
if (e[item].IndexCriteria.IncludeNodeTypes == "")
e[item].IndexCriteria.IncludeNodeTypes = "Include all";
if (e[item].IndexCriteria.ExcludeNodeTypes == "")
e[item].IndexCriteria.ExcludeNodeTypes = "Exclude none";
//change the Standard and user fields to be an array so we can bind it
//e[item].IndexCriteria.StandardFields = self._mapDictionaryToArray(e[item].IndexerProperties);
}
self._koViewModel.indexerDetails(e);
}).fail(function (a, b, c) {
alert("error: " + b);
});
}

View File

@@ -8,17 +8,15 @@ namespace Umbraco.Web.Search
{
public class ExamineIndexerModel
{
public string Name { get; set; }
public bool SupportsUnpublished { get; set; }
public bool SupportsProtected { get; set; }
public IIndexCriteria IndexCriteria { get; set; }
public ExamineIndexerModel()
{
IndexerProperties = new Dictionary<string, string>();
}
public string Name { get; set; }
public IIndexCriteria IndexCriteria { get; set; }
public IDictionary<string, string> IndexerProperties { get; private set; }
}
/// <summary>
/// Model to use to render the dashboard details
/// </summary>
public class ExamineDashboardDetails
{
public IEnumerable<ExamineIndexerModel> Indexers { get; set; }
}
}

View File

@@ -548,6 +548,7 @@
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="WebApi\UmbracoAuthorizeAttribute.cs" />
<Compile Include="WebApi\UmbracoAuthorizedApiController.cs" />
<Compile Include="WebBootManager.cs" />
<Compile Include="Routing\LegacyRequestInitializer.cs" />
<Compile Include="Mvc\ControllerExtensions.cs" />
@@ -1757,7 +1758,7 @@
</Compile>
<Compile Include="WebServices\BulkPublishController.cs" />
<Compile Include="WebServices\CoreStringsController.cs" />
<Compile Include="WebServices\ExamineManagementController.cs" />
<Compile Include="WebServices\ExamineManagementApiController.cs" />
<Compile Include="WebServices\FolderBrowserService.cs" />
<Compile Include="WebServices\SaveFileController.cs" />
<Content Include="umbraco.presentation\umbracobase\readme.txt" />

View File

@@ -4,6 +4,7 @@ using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
using Umbraco.Web.WebServices;
namespace Umbraco.Web
{
@@ -12,6 +13,17 @@ namespace Umbraco.Web
/// </summary>
public static class UrlHelperExtensions
{
/// <summary>
/// Returns the base path (not including the 'action') of the MVC controller "ExamineManagementController"
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static string GetExamineManagementServicePath(this UrlHelper url)
{
var result = url.GetUmbracoApiService<ExamineManagementApiController>("GetIndexerDetails");
return result.TrimEnd("GetIndexerDetails").EnsureEndsWith('/');
}
/// <summary>
/// Return the Url for a Web Api service
/// </summary>

View File

@@ -0,0 +1,69 @@
using System;
using System.Web;
using System.Web.Http;
using Umbraco.Core.Configuration;
using Umbraco.Web.Security;
using umbraco.BusinessLogic;
namespace Umbraco.Web.WebApi
{
[UmbracoAuthorize]
public abstract class UmbracoAuthorizedApiController : UmbracoApiController
{
private User _user;
private bool _userisValidated = false;
/// <summary>
/// The current user ID
/// </summary>
private int _uid = 0;
/// <summary>
/// The page timeout in seconds.
/// </summary>
private long _timeout = 0;
/// <summary>
/// Returns the currently logged in Umbraco User
/// </summary>
protected User UmbracoUser
{
get
{
if (!_userisValidated) ValidateUser();
return _user;
}
}
private void ValidateUser()
{
if ((WebSecurity.UmbracoUserContextId != ""))
{
_uid = WebSecurity.GetUserId(WebSecurity.UmbracoUserContextId);
_timeout = WebSecurity.GetTimeout(WebSecurity.UmbracoUserContextId);
if (_timeout > DateTime.Now.Ticks)
{
_user = global::umbraco.BusinessLogic.User.GetUser(_uid);
// Check for console access
if (_user.Disabled || (_user.NoConsole && GlobalSettings.RequestIsInUmbracoApplication(HttpContext.Current) && !GlobalSettings.RequestIsLiveEditRedirector(HttpContext.Current)))
{
throw new ArgumentException("You have no priviledges to the umbraco console. Please contact your administrator");
}
_userisValidated = true;
WebSecurity.UpdateLogin(_timeout);
}
else
{
throw new ArgumentException("User has timed out!!");
}
}
else
{
throw new InvalidOperationException("The user has no umbraco contextid - try logging in");
}
}
}
}

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Examine;
using Examine.LuceneEngine.Providers;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Web.Mvc;
using Umbraco.Web.Search;
using Umbraco.Web.WebApi;
namespace Umbraco.Web.WebServices
{
public class ExamineManagementApiController : UmbracoAuthorizedApiController
{
/// <summary>
/// Get the details
/// </summary>
/// <returns></returns>
public IEnumerable<ExamineIndexerModel> GetIndexerDetails()
{
var model = new List<ExamineIndexerModel>(
ExamineManager.Instance.IndexProviderCollection.Select(indexer =>
{
var indexerModel = new ExamineIndexerModel()
{
IndexCriteria = indexer.IndexerData,
Name = indexer.Name
};
var props = TypeHelper.CachedDiscoverableProperties(indexer.GetType(), mustWrite: false)
//ignore these properties
.Where(x => !new[] { "IndexerData", "Description", "WorkingFolder" }.InvariantContains(x.Name))
.OrderBy(x => x.Name);
foreach (var p in props)
{
indexerModel.IndexerProperties.Add(p.Name, p.GetValue(indexer, null).ToString());
}
return indexerModel;
}));
return model;
}
//public IEnumerable<ExamineIndexerModel> GetSearcherDetails()
//{
// var model = new List<ExamineIndexerModel>(
// ExamineManager.Instance.IndexProviderCollection.Select(indexer =>
// {
// var indexerModel = new ExamineIndexerModel()
// {
// IndexCriteria = indexer.IndexerData,
// Name = indexer.Name
// };
// var props = TypeHelper.CachedDiscoverableProperties(indexer.GetType(), mustWrite: false)
// .OrderBy(x => x.Name);
// foreach (var p in props)
// {
// indexerModel.IndexerProperties.Add(p.Name, p.GetValue(indexer, null).ToString());
// }
// return indexerModel;
// }));
// return model;
//}
}
}

View File

@@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Web.Mvc;
namespace Umbraco.Web.WebServices
{
public class ExamineManagementController : UmbracoAuthorizedController
{
/// <summary>
/// Get the details
/// </summary>
/// <returns></returns>
public ActionResult Index()
{
return View("~" + GlobalSettings.Path.EnsureEndsWith('/').EnsureStartsWith('/') + "Views/ExamineManagement/ExamineDetails.cshtml");
}
}
}

View File

@@ -341,7 +341,7 @@ namespace UmbracoExamine
{
if (CanInitialize())
{
return indexSet.ToIndexCriteria(DataService);
return indexSet.ToIndexCriteria(DataService, IndexFieldPolicies);
}
else
{