public ActionResult AddLayerPOST() { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } LayerPart layerPart = _widgetsService.CreateLayer("", "", ""); if (layerPart == null) { return(HttpNotFound()); } var model = Services.ContentManager.UpdateEditor(layerPart, this); if (!ModelState.IsValid) { Services.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.Notifier.Information(T("Your {0} has been created.", layerPart.TypeDefinition.DisplayName)); return(RedirectToAction("Index", "Admin", new { layerId = layerPart.Id })); }
public void MoveWidgetTest() { LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); // same zone widgets WidgetPart widgetPart1 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, Position1, Zone1); WidgetPart widgetPart2 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle2, Position2, Zone1); // different zone widget WidgetPart widgetPart3 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle3, Position3, Zone2); // test 1 - moving first widget up will have no effect Assert.That(_widgetService.MoveWidgetUp(widgetPart1), Is.False); // test 2 - moving first widget down will be successfull Assert.That(_widgetService.MoveWidgetDown(widgetPart1), Is.True); widgetPart1 = _widgetService.GetWidget(widgetPart1.Id); Assert.That(widgetPart1.Position, Is.EqualTo(Position2), "First widget moved to second widget position"); widgetPart2 = _widgetService.GetWidget(widgetPart2.Id); Assert.That(widgetPart2.Position, Is.EqualTo(Position1), "Second widget moved to first widget position"); // test 3 - moving last widget down will have no effect even though there is a widget in another zone with a higher position Assert.That(_widgetService.MoveWidgetDown(widgetPart1), Is.False); widgetPart1 = _widgetService.GetWidget(widgetPart1.Id); Assert.That(widgetPart1.Position, Is.EqualTo(Position2), "Widget remained in the same position"); widgetPart2 = _widgetService.GetWidget(widgetPart2.Id); Assert.That(widgetPart2.Position, Is.EqualTo(Position1), "Widget remained in the same position"); widgetPart3 = _widgetService.GetWidget(widgetPart3.Id); Assert.That(widgetPart3.Position, Is.EqualTo(Position3), "Widget remained in the same position"); }
public ActionResult AddLayerPOST() { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } LayerPart layerPart = _widgetsService.CreateLayer("", "", ""); if (layerPart == null) { return(HttpNotFound()); } var model = Services.ContentManager.UpdateEditor(layerPart, this); if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return(View(model)); } Services.Notifier.Information(T("Your {0} has been created.", layerPart.TypeDefinition.DisplayName)); return(RedirectToAction("Index", "Admin", new { layerId = layerPart.Id })); }
public ActionResult AddLayer(string name, string description, string layerRule) // <- hints for a new layer { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } LayerPart layerPart = Services.ContentManager.New <LayerPart>("Layer"); if (layerPart == null) { return(HttpNotFound()); } dynamic model = Services.ContentManager.BuildEditor(layerPart); // only messing with the hints if they're given if (!string.IsNullOrWhiteSpace(name)) { model.Name = name; } if (!string.IsNullOrWhiteSpace(description)) { model.Description = description; } if (!string.IsNullOrWhiteSpace(layerRule)) { model.LayerRule = layerRule; } // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)model)); }
public ActionResult EditLayerSavePOST(int id, string returnUrl) { if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) { return(new HttpUnauthorizedResult()); } try { LayerPart layerPart = _widgetsService.GetLayer(id); if (layerPart == null) { return(HttpNotFound()); } var model = Services.ContentManager.UpdateEditor(layerPart, this); if (!ModelState.IsValid) { Services.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.Notifier.Information(T("Your {0} has been saved.", layerPart.TypeDefinition.DisplayName)); } catch (Exception exception) { this.Error(exception, T("Editing layer failed: {0}", exception.Message), Logger, Services.Notifier); } return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index"))); }
public ActionResult EditLayerSavePOST(int id, string returnUrl) { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } LayerPart layerPart = _widgetsService.GetLayer(id); if (layerPart == null) { return(HttpNotFound()); } var model = Services.ContentManager.UpdateEditor(layerPart, this); if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return(View(model)); } Services.Notifier.Information(T("Your {0} has been saved.", layerPart.TypeDefinition.DisplayName)); return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index"))); }
public ActionResult AddLayer(string name, string description, string layerRule) // <- hints for a new layer { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } LayerPart layerPart = Services.ContentManager.New <LayerPart>("Layer"); if (layerPart == null) { return(HttpNotFound()); } var model = Services.ContentManager.BuildEditor(layerPart); // only messing with the hints if they're given if (!string.IsNullOrWhiteSpace(name)) { model.Name = name; } if (!string.IsNullOrWhiteSpace(description)) { model.Description = description; } if (!string.IsNullOrWhiteSpace(layerRule)) { model.LayerRule = layerRule; } return(View(model)); }
public ActionResult EditLayerSavePOST(int id, string returnUrl) { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } LayerPart layerPart = _widgetsService.GetLayer(id); if (layerPart == null) { return(HttpNotFound()); } var model = Services.ContentManager.UpdateEditor(layerPart, this); if (!ModelState.IsValid) { Services.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.Notifier.Information(T("Your {0} has been saved.", layerPart.TypeDefinition.DisplayName)); return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index"))); }
public void GetWidgetsTest() { LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); _contentManager.Flush(); IEnumerable <WidgetPart> widgetResults = _widgetService.GetWidgets(); Assert.That(widgetResults.Count(), Is.EqualTo(0)); WidgetPart widgetPart = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, "1", ""); Assert.That(widgetPart, Is.Not.Null); _contentManager.Flush(); widgetResults = _widgetService.GetWidgets(); Assert.That(widgetResults.Count(), Is.EqualTo(1)); Assert.That(widgetResults.First().Id, Is.EqualTo(widgetPart.Id)); _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle2, "2", ""); _contentManager.Flush(); widgetResults = _widgetService.GetWidgets(); Assert.That(widgetResults.Count(), Is.EqualTo(2)); }
public void CreateWidgetTest() { LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); WidgetPart widgetPart = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, "1", ""); Assert.That(widgetPart, Is.Not.Null); Assert.That(widgetPart.LayerPart.Id, Is.EqualTo(layerPart.Id)); }
public LayerPart CreateLayer(string name, string description, string layerRule) { LayerPart layerPart = _contentManager.Create <LayerPart>("Layer", layer => { layer.Name = name; layer.Description = description; layer.LayerRule = layerRule; }); return(layerPart); }
public WidgetPart CreateWidget(int layerId, string widgetType, string title, string position, string zone) { LayerPart layerPart = GetLayer(layerId); WidgetPart widgetPart = _contentManager.Create <WidgetPart>(widgetType, widget => { widget.Title = title; widget.Position = position; widget.Zone = zone; widget.LayerPart = layerPart; }); return(widgetPart); }
public void CreateLayerTest() { IEnumerable <LayerPart> layers = _widgetService.GetLayers(); Assert.That(layers.Count(), Is.EqualTo(0), "No layers yet"); _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); layers = _widgetService.GetLayers(); LayerPart layer = layers.First(); Assert.That(layer.Record.Name, Is.EqualTo(LayerName1)); Assert.That(layer.Record.Description, Is.EqualTo(LayerDescription1)); }
public bool MoveWidgetToLayer(WidgetPart widgetPart, int?layerId) { LayerPart layer = layerId.HasValue ? GetLayer(layerId.Value) : GetLayers().FirstOrDefault(); if (layer != null) { widgetPart.LayerPart = layer; return(true); } return(false); }
public void GetLayersTest() { IEnumerable <LayerPart> layers = _widgetService.GetLayers(); Assert.That(layers.Count(), Is.EqualTo(0)); LayerPart layerPartFirst = _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); layers = _widgetService.GetLayers(); Assert.That(layers.Count(), Is.EqualTo(1)); Assert.That(layers.First().Id, Is.EqualTo(layerPartFirst.Id)); _widgetService.CreateLayer(LayerName2, LayerDescription2, ""); Assert.That(layers.Count(), Is.EqualTo(1)); }
public ActionResult Index(int?layerId) { ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme(); if (currentTheme == null) { Services.Notifier.Error(T("To manage widgets you must have a theme enabled.")); return(RedirectToAction("Index", "Admin", new { area = "Dashboard" })); } IEnumerable <LayerPart> layers = _widgetsService.GetLayers().ToList(); if (!layers.Any()) { Services.Notifier.Error(T("There are no widget layers defined. A layer will need to be added in order to add widgets to any part of the site.")); return(RedirectToAction("AddLayer")); } LayerPart currentLayer = layerId == null ? layers.FirstOrDefault() : layers.FirstOrDefault(layer => layer.Id == layerId); if (currentLayer == null && layerId != null) // Incorrect layer id passed { Services.Notifier.Error(T("Layer not found: {0}", layerId)); return(RedirectToAction("Index")); } IEnumerable <string> allZones = _widgetsService.GetZones(); IEnumerable <string> currentThemesZones = _widgetsService.GetZones(currentTheme); string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id); string zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null; dynamic viewModel = Shape.ViewModel() .CurrentTheme(currentTheme) .CurrentLayer(currentLayer) .Layers(layers) .Widgets(_widgetsService.GetWidgets()) .Zones(currentThemesZones) .OrphanZones(allZones.Except(currentThemesZones)) .OrphanWidgets(_widgetsService.GetOrphanedWidgets()) .ZonePreviewImage(zonePreviewImage); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)viewModel)); }
public ActionResult EditLayer(int id) { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } LayerPart layerPart = _widgetsService.GetLayer(id); if (layerPart == null) { return(HttpNotFound()); } var model = Services.ContentManager.BuildEditor(layerPart); return(View(model)); }
public void GetWidgetTest() { LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); WidgetPart widgetResult = _widgetService.GetWidget(0); Assert.That(widgetResult, Is.Null); WidgetPart widgetPart = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, "1", ""); Assert.That(widgetPart, Is.Not.Null); widgetResult = _widgetService.GetWidget(0); Assert.That(widgetResult, Is.Null, "Still yields null on an invalid identifier"); widgetResult = _widgetService.GetWidget(widgetPart.Id); Assert.That(widgetResult.Id, Is.EqualTo(widgetPart.Id), "Returns correct widget"); }
public void GetLayerWidgetsTest() { LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, ""); // same zone widgets WidgetPart widgetPart1 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, Position1, Zone1); WidgetPart widgetPart2 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle2, Position2, Zone1); // different zone widget _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle3, Position3, Zone2); // test 1 - moving first widget up will have no effect IEnumerable <WidgetPart> layerWidgets = _widgetService.GetWidgets(layerPart.Id); Assert.That(layerWidgets.Count(), Is.EqualTo(2)); Assert.That(layerWidgets.Contains(widgetPart1)); Assert.That(layerWidgets.Contains(widgetPart2)); }
public ActionResult EditLayer(int id) { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } LayerPart layerPart = _widgetsService.GetLayer(id); if (layerPart == null) { return(HttpNotFound()); } dynamic model = Services.ContentManager.BuildEditor(layerPart); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)model)); }
public ActionResult ChooseWidget(int layerId, string zone, string returnUrl) { if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) { return(new HttpUnauthorizedResult()); } if (string.IsNullOrWhiteSpace(zone)) { Services.Notifier.Error(T("Need a zone specified for widget placement.")); return(RedirectToAction("Index")); } IEnumerable <LayerPart> layers = _widgetsService.GetLayers(); if (layers.Count() == 0) { Services.Notifier.Error(T("Layer not found: {0}", layerId)); return(RedirectToAction("Index")); } LayerPart currentLayer = layers.FirstOrDefault(layer => layer.Id == layerId); if (currentLayer == null) // Incorrect layer id passed { Services.Notifier.Error(T("Layer not found: {0}", layerId)); return(RedirectToAction("Index")); } dynamic viewModel = Shape.ViewModel() .CurrentLayer(currentLayer) .Zone(zone) .WidgetTypes(_widgetsService.GetWidgetTypes()) .ReturnUrl(returnUrl); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)viewModel)); }
public ActionResult EditLayer(int id) { if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) { return(new HttpUnauthorizedResult()); } try { LayerPart layerPart = _widgetsService.GetLayer(id); if (layerPart == null) { return(HttpNotFound()); } dynamic model = Services.ContentManager.BuildEditor(layerPart); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)model)); } catch (Exception exception) { this.Error(exception, T("Editing layer failed: {0}", exception.Message), Logger, Services.Notifier); return(RedirectToAction("Index", "Admin")); } }
public ActionResult AddLayer(string name, string description, string layerRule) // <- hints for a new layer { if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel))) { return(new HttpUnauthorizedResult()); } try { LayerPart layerPart = Services.ContentManager.New <LayerPart>("Layer"); if (layerPart == null) { return(HttpNotFound()); } dynamic model = Services.ContentManager.BuildEditor(layerPart); // only messing with the hints if they're given if (!string.IsNullOrWhiteSpace(name)) { model.Name = name; } if (!string.IsNullOrWhiteSpace(description)) { model.Description = description; } if (!string.IsNullOrWhiteSpace(layerRule)) { model.LayerRule = layerRule; } // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)model)); } catch (Exception exception) { this.Error(exception, T("Creating layer failed: {0}", exception.Message), Logger, Services.Notifier); return(RedirectToAction("Index")); } }
public ActionResult ChooseWidget(int layerId, string zone, string returnUrl) { if (!IsAuthorizedToManageWidgets()) { return(new HttpUnauthorizedResult()); } if (string.IsNullOrWhiteSpace(zone)) { Services.Notifier.Error(T("Need a zone specified for widget placement.")); return(RedirectToAction("Index")); } IEnumerable <LayerPart> layers = _widgetsService.GetLayers().OrderBy(x => x.Name).ToList(); if (!layers.Any()) { Services.Notifier.Error(T("Layer not found: {0}", layerId)); return(RedirectToAction("Index")); } LayerPart currentLayer = layers.FirstOrDefault(layer => layer.Id == layerId); if (currentLayer == null) // Incorrect layer id passed { Services.Notifier.Error(T("Layer not found: {0}", layerId)); return(RedirectToAction("Index")); } var viewModel = Shape.ViewModel() .CurrentLayer(currentLayer) .Zone(zone) .WidgetTypes(_widgetsService.GetWidgetTypes()) .ReturnUrl(returnUrl); return(View(viewModel)); }
public ActionResult Index(int?layerId, string culture) { ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme(); if (currentTheme == null) { Services.Notifier.Error(T("To manage widgets you must have a theme enabled.")); return(RedirectToAction("Index", "Admin", new { area = "Dashboard" })); } IEnumerable <LayerPart> layers = _widgetsService.GetLayers().OrderBy(x => x.Name).ToList(); if (!layers.Any()) { Services.Notifier.Error(T("There are no widget layers defined. A layer will need to be added in order to add widgets to any part of the site.")); return(RedirectToAction("AddLayer")); } LayerPart currentLayer = layerId == null // look for the "Default" layer, or take the first if it doesn't exist ? layers.FirstOrDefault(x => x.Name == "Default") ?? layers.FirstOrDefault() : layers.FirstOrDefault(layer => layer.Id == layerId); if (currentLayer == null && layerId != null) // Incorrect layer id passed { Services.Notifier.Error(T("Layer not found: {0}", layerId)); return(RedirectToAction("Index")); } IEnumerable <string> allZones = _widgetsService.GetZones(); IEnumerable <string> currentThemesZones = _widgetsService.GetZones(currentTheme); string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id); string zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null; var widgets = _widgetsService.GetWidgets(); if (!String.IsNullOrWhiteSpace(culture)) { widgets = widgets.Where(x => { if (x.Has <ILocalizableAspect>()) { return(String.Equals(x.As <ILocalizableAspect>().Culture, culture, StringComparison.InvariantCultureIgnoreCase)); } return(false); }).ToList(); } var viewModel = Shape.ViewModel() .CurrentTheme(currentTheme) .CurrentLayer(currentLayer) .CurrentCulture(culture) .Layers(layers) .Widgets(widgets) .Zones(currentThemesZones) .Cultures(_cultureManager.ListCultures()) .OrphanZones(allZones.Except(currentThemesZones)) .OrphanWidgets(_widgetsService.GetOrphanedWidgets()) .ZonePreviewImage(zonePreviewImage); return(View(viewModel)); }