Finding space used by tables in Microsoft SQL Server 2008
Great post by Eric Phan on reenabling the contextual menu for adding views to MVC projects in Visual Studio 2010.
I'm running Orchard 1.1, hopefully this has been fixed in 1.2. Will have to find the ticket and do a pull request if not.
I like the way Posterous displays the 'edit' button (also 'delete' et al) when you hover over a particular post. Facebook does this too. It removes an otherwise incidental button and reduces the amount of noise (SNR wise) of the page. It's not much but it helps. To achieve the same effect in Orchard, we'll need jQuery. You can put this in your theme's Layout.cshtml file or include a separate javascript file like I do.
Layout.cshtml:
//Include jQuery and our javascript file from the theme's Scripts directory
Script.Require("jQuery").AtHead();
Script.Include("MyTheme.js").AtHead();
MyTheme.js:
$().ready(function () {
$('.zone').hover(
function () {
$(this).find('div.manage-actions').css('visibility', 'visible');
},
function () {
$(this).find('div.manage-actions').css('visibility', 'hidden');
}
);
});
MyTheme.css
div.manage-actions
{
visibility:hidden;
}
We're setting the visibility as hidden instead of using the jQuery .hide() and .show() methods because this will remove the element's block style and move the page structure around. It gives a jolting effect and isn't pleasant.
In my attempt to reinstall a third party Orchard module, I inadvertedly hosed my test site. It's working fine, but I can't install Szmyd's contest winning Advanced Menu module or remove it completely. It's a very complex module which extends a few core Orchard components and makes it quite tricky to remove all traces in the database. I then thought I'd reinstall my modules by starting off with a fresh copy of Orchard. Which brings me to the point of the post...
How can you unbind the application from the database into thinking it needs reinstalling?
The answer turned out quite simple.
Rename the App_Data directory (say, to App_Data_old).
It would help to rename the old SQL Server database as well. We can do this in one swoop with P/SQL
ALTER DATABASE [Orchard] SET SINGLE_USER WITH ROLLBACK IMMEDIATE ALTER DATABASE [Orchard] MODIFY NAME = [Orchard_Old] ALTER DATABASE [Orchard_Old] SET MULTI_USER WITH ROLLBACK IMMEDIATE
Make sure you recreate your database (if you haven't deleted the old one, you'll need to assign the new one different MDF and LDF filenames) and give db_owner rights back to your database user.
For instance, mine in script form is
USE [Orchard] GO CREATE USER [OrchardUser] FOR LOGIN [OrchardUser] GO USE [Orchard] GO EXEC sp_addrolemember N'db_owner', N'OrchardUser' GO
Tada! This way we can leave our modules where they are without having to download them again (albeit no settings).
Does anyone know of a better way to automate this process? Likewise, a way to uninstall a module? In my opinion, the latter is a much needed feature.
Based on this StackOverflow question, you'd think it would be easy to render a partial view to string. Why would we want to do this? The MVC app I'm coding is very custom (outside of Microsoft's cosy MVC jQuery space) and I'm handling the form POSTs myself. I want to do a server side function, and display contextual results and do some jQuery magic as well. I want both a view to render, and some json variables to act upon. Typically, the code in the link works fine. In Orchard however, not so much.
Orchard has it's own rendering engine so it handles things a bit differently. If it doesn't have a theme (I'm calling my controllers directly not via contenttypes/shapes what have you), regardless if I've tagged the controller or method with the [Themed] attribute, it won't render the view because it can't find it. Stepping through Orchard code I found out that if there is a theme (orchardServices.WorkContext.CurrentTheme) it works, and if it's null, even though it's been attributed with [Themed], it fails. Funnily enough, the site theme service's method GetSiteTheme returns a theme. See the code below to see what I've hacked together to mitigate this quirk.
public static string RenderPartialView(this Controller controller, string viewName, object model, IOrchardServices orchardServices, ISiteThemeService _siteThemeService) {
if (string.IsNullOrEmpty(viewName))
viewName = controller.ControllerContext.RouteData.GetRequiredString("action");
controller.ViewData.Model = model;
using (var sw = new StringWriter()) {
//can't find view file otherwise :(
if (orchardServices.WorkContext.CurrentTheme == null) {
var t = _siteThemeService.GetSiteTheme();
orchardServices.WorkContext.CurrentTheme = t;
}
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
var viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
viewResult.View.Render(viewContext, sw);
return sw.GetStringBuilder().ToString();
}
}
I haven't had a blog in ... never. Exposing my mind sounds daunting and hazardous to my self image, but I must persevere . I'll try and make it look visually palatable, and post stuff as it comes to mind. Still not sure whether to have this as a code based blog or personal or both. I've had too many "AHA!" moments today dealing with work that I have to share them somewhere. I also got my invite to Forrst approved which is nice! Not sure what I'll be doing there though. It's 3:45pm, just scrambled all braincells to get a demo out, and it's finally time for lunch.