James Restall: Contrib mobile bug and fix found. No codeplex project found

Topics: General, Writing modules
Jun 5, 2012 at 2:02 PM

Currenlty i've installed the Contrib mobile module and fixed an bug but can't find any codeplex project or any other site where this project is maintained. So a call to James Restall. Please contact me or copy paste the following null ref fix:

var groups = _deviceGroupService.Get(VersionOptions.Latest);
group.Position = groups.Any() ? groups.Max(x => x.Position) + 1 : 0;

 

 

 

Aug 27, 2012 at 9:57 PM
Edited Aug 27, 2012 at 9:57 PM

Hey, just tried the module and it looks promising, however, I get the following error when creating a device group upon clicking the save button: 

An unhandled exception has occurred and the request was terminated. Please refresh the page. If the error persists, go back

Sequence contains no elements

System.InvalidOperationException: Sequence contains no elements at System.Linq.Enumerable.Max(IEnumerable`1 source) at Contrib.Mobile.Controllers.ThemesAdminController.CreatePOST() at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

The fix you mentioned up there, is that the fix fir this error? If so, where do I add apply this fix?

Aug 27, 2012 at 10:06 PM

found it. It's in the \Modules\Contrib.Mobile\Controllers\ThemesAdminController.cs line 78

[HttpPost, ActionName("Create")]
public ActionResult CreatePOST()
{
    if (!Services.Authorizer.Authorize(Permissions.ManageMobileThemes, T("Cannot manage mobile themes")))
        return new HttpUnauthorizedResult();
 
    var group = Services.ContentManager.New<DeviceGroupPart>("DeviceGroup");
    group.Enabled = true;
    // OLD CODE: group.Position = _deviceGroupService.Get(VersionOptions.Latest).Max(x => x.Position) + 1;
    var groups = _deviceGroupService.Get(VersionOptions.Latest);
    group.Position = groups.Any() ? groups.Max(x => x.Position) + 1 : 0;
 
    Services.ContentManager.Create(group, VersionOptions.Draft);
    dynamic model = Services.ContentManager.UpdateEditor(group, this);
 
    if (!ModelState.IsValid)
    {
        _transactionManager.Cancel();
        // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
        return View((object)model);
    }
 
    Services.ContentManager.Publish(group.ContentItem);
 
    return Redirect("List");
}
Oct 27, 2012 at 5:41 PM

Glad you've found it. Unfortunately the author never contacted me and I can't find where's hosted the source. That's really a shame because the module is very nice!

Oct 27, 2012 at 5:52 PM

Really nice module, Znowman, thank's a lot!

Oct 27, 2012 at 6:30 PM

module is indeed nice.

I'm using the following query to filter out phones as tablet render the site quiet well:

isMobileDevice(true) && is_tablet(false) 

My next orchard site however is based on a bootstrap theme, started from a them from wrapbootstrap.com. Hereby I avoid 2 different theme's for desktop or mobile

Every step I go further in the development I evaluate if it still looks good on different form factors. So far so good and it just sounds better to have one theme for all devices.

Oct 28, 2012 at 10:17 AM

Yes in some scenario's is a responsive theme a nice solution but in some circumstances it's not enough. For example when you want totally different content (without loading unused data) or structure.

Mar 1 at 10:29 PM
Hi all,

Sorry for the very late reply, I've only just been made aware of this. I've added the code at https://github.com/jrestall/Orchard.Mobile.Contrib and added vegard as a collaborator which should help ensure the module gets any bug fixes and enhancements going forward.

The module was done as an entry to the orchard module competition, it could do with a lot of tidy up, but I hope this will at least get you going for now.

Cheers,
James