Skip to content

Commit

Permalink
Implemented new version of slider plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak committed Oct 8, 2018
1 parent 9b43d8c commit 571aba0
Show file tree
Hide file tree
Showing 30 changed files with 1,360 additions and 626 deletions.
10 changes: 10 additions & 0 deletions Grand.Web/Views/Shared/_ColumnsTwo.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
@RenderSection("Breadcrumb")
}
}

@if (!string.IsNullOrEmpty(currentCategoryId))
{
@await Component.InvokeAsync("Widget", new { widgetZone = "home_page_category", additionalData = Model.Id })
}
@if (!string.IsNullOrEmpty(currentManufacturerId))
{
@await Component.InvokeAsync("Widget", new { widgetZone = "home_page_manufacturer", additionalData = Model.Id })
}

<div class="d-lg-flex d-grid flex-md-row mx-0">

<div class="col-lg-3 col-md-12 generalLeftSide pl-0">
Expand Down
100 changes: 41 additions & 59 deletions Plugins/Grand.Plugin.Widgets.Slider/Components/Slider.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Grand.Core;
using Grand.Core.Caching;
using Grand.Plugin.Widgets.Slider.Infrastructure.Cache;
using Grand.Plugin.Widgets.Slider.Models;
using Grand.Services.Configuration;
using Grand.Services.Localization;
using Grand.Services.Media;
using Grand.Services.Stores;
using System.Linq;
using Grand.Plugin.Widgets.Slider.Services;
using Grand.Plugin.Widgets.Slider.Domain;
using System.Collections.Generic;

namespace Grand.Plugin.Widgets.Slider.ViewComponents
{
[ViewComponent(Name = "Grand.Plugin.Widgets.Slider")]
public class SliderViewComponent : ViewComponent
{
private readonly IWorkContext _workContext;
private readonly IStoreContext _storeContext;
private readonly IStoreService _storeService;
private readonly IPictureService _pictureService;
private readonly ISettingService _settingService;
private readonly ICacheManager _cacheManager;
private readonly ILocalizationService _localizationService;
private readonly ISliderService _sliderService;

public SliderViewComponent(IWorkContext workContext,
IStoreContext storeContext,
IStoreService storeService,
public const string PICTURE_URL_MODEL_KEY = "Grand.plugins.widgets.slider.pictureurl-{0}";

public SliderViewComponent(
IPictureService pictureService,
ISettingService settingService,
ICacheManager cacheManager,
ILocalizationService localizationService)
ISliderService sliderService)
{
this._workContext = workContext;
this._storeContext = storeContext;
this._storeService = storeService;
this._pictureService = pictureService;
this._settingService = settingService;
this._cacheManager = cacheManager;
this._localizationService = localizationService;
this._sliderService = sliderService;
}

protected string GetPictureUrl(string pictureId)
{

string cacheKey = string.Format(ModelCacheEventConsumer.PICTURE_URL_MODEL_KEY, pictureId);
string cacheKey = string.Format(PICTURE_URL_MODEL_KEY, pictureId);
return _cacheManager.Get(cacheKey, () =>
{
var url = _pictureService.GetPictureUrl(pictureId, showDefaultPicture: false);
Expand All @@ -54,52 +43,45 @@ protected string GetPictureUrl(string pictureId)
});
}

public IViewComponentResult Invoke(string widgetZone, object additionalData = null)
protected void PrepareModel(IList<PictureSlider> sliders, PublicInfoModel model)
{

var sliderSettings = _settingService.LoadSetting<SliderSettings>(_storeContext.CurrentStore.Id);

var model = new PublicInfoModel();
model.Slide.Add(new PublicInfoModel.Slider()
int i = 1;
foreach (var item in sliders)
{
PictureUrl = GetPictureUrl(sliderSettings.Picture1Id),
Text = sliderSettings.Text1,
Link = sliderSettings.Link1,
CssClass = "active",
});
model.Slide.Add(new PublicInfoModel.Slider()
{
Link = item.Link,
PictureUrl = GetPictureUrl(item.PictureId),
Name = item.GetLocalized(x => x.Name),
Description = item.GetLocalized(x => x.Description),
CssClass = i == 1 ? "active" : ""
});
i++;
}

model.Slide.Add(new PublicInfoModel.Slider()
{
PictureUrl = GetPictureUrl(sliderSettings.Picture2Id),
Text = sliderSettings.Text2,
Link = sliderSettings.Link2,
CssClass = "",
});
}

model.Slide.Add(new PublicInfoModel.Slider()
{
PictureUrl = GetPictureUrl(sliderSettings.Picture3Id),
Text = sliderSettings.Text3,
Link = sliderSettings.Link3,
CssClass = "",
});
public IViewComponentResult Invoke(string widgetZone, object additionalData = null)
{

model.Slide.Add(new PublicInfoModel.Slider()
var model = new PublicInfoModel();
if (widgetZone == SliderDefaults.WidgetZoneHomePage)
{
PictureUrl = GetPictureUrl(sliderSettings.Picture4Id),
Text = sliderSettings.Text4,
Link = sliderSettings.Link4,
CssClass = "",
});

model.Slide.Add(new PublicInfoModel.Slider()
var slides = _sliderService.GetPictureSliders(SliderType.HomePage);
PrepareModel(slides, model);
}
if (widgetZone == SliderDefaults.WidgetZoneCategoryPage)
{
PictureUrl = GetPictureUrl(sliderSettings.Picture5Id),
Text = sliderSettings.Text5,
Link = sliderSettings.Link5,
});
var slides = _sliderService.GetPictureSliders(SliderType.Category, additionalData.ToString());
PrepareModel(slides, model);
}
if (widgetZone == SliderDefaults.WidgetZoneManufacturerPage)
{
var slides = _sliderService.GetPictureSliders(SliderType.Manufacturer, additionalData.ToString());
PrepareModel(slides, model);
}

if(model.Slide.Where(x=> string.IsNullOrEmpty(x.PictureUrl)).Count() ==0 )
if (!model.Slide.Any())
return Content("");

return View("/Plugins/Widgets.Slider/Views/PublicInfo.cshtml", model);
Expand Down
Loading

0 comments on commit 571aba0

Please sign in to comment.