-
Notifications
You must be signed in to change notification settings - Fork 2
/
qBoSliderPlugin.cs
323 lines (284 loc) · 14.7 KB
/
qBoSliderPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//Copyright 2020 Alexey Prokhorov
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
using Nop.Core;
using Nop.Plugin.Widgets.qBoSlider.Components;
using Nop.Plugin.Widgets.qBoSlider.Domain;
using Nop.Plugin.Widgets.qBoSlider.Service;
using Nop.Services.Cms;
using Nop.Services.Configuration;
using Nop.Services.Media;
using Nop.Services.Security;
using Nop.Services.Stores;
using Nop.Web.Framework.Menu;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Nop.Plugin.Widgets.qBoSlider
{
/// <summary>
/// Base plugin class
/// </summary>
public class qBoSliderPlugin : BaseBaroquePlugin, IWidgetPlugin, IAdminMenuPlugin
{
#region Fields
private readonly IAclService _aclService;
private readonly IGarbageManager _garbageManager;
private readonly IPermissionService _permissionService;
private readonly IPictureService _pictureService;
private readonly ISettingService _settingService;
private readonly ISlideService _slideService;
private readonly IStoreMappingService _storeMappingService;
private readonly IWebHelper _webHelper;
private readonly IWidgetZoneService _widgetZoneService;
private readonly IWidgetZoneSlideService _widgetZoneSlideService;
private readonly IStoreContext _storeContext;
#endregion
#region Constructor
public qBoSliderPlugin(IAclService aclService,
IGarbageManager garbageManager,
IPermissionService permissionService,
IPictureService pictureService,
ISettingService settingService,
ISlideService slideService,
IStoreMappingService storeMappingService,
IWebHelper webHelper,
IWidgetZoneService widgetZoneService,
IWidgetZoneSlideService widgetZoneSlideService,
IStoreContext storeContext)
{
_aclService = aclService;
_garbageManager = garbageManager;
_permissionService = permissionService;
_pictureService = pictureService;
_settingService = settingService;
_slideService = slideService;
_storeMappingService = storeMappingService;
_webHelper = webHelper;
_widgetZoneService = widgetZoneService;
_widgetZoneSlideService = widgetZoneSlideService;
_storeContext = storeContext;
}
#endregion
#region Methods
/// <summary>
/// Gets a configuration page URL
/// </summary>
public override string GetConfigurationPageUrl()
{
return $"{_webHelper.GetStoreLocation()}Admin/qBoConfiguration/Configure";
}
/// <summary>
/// Gets a value indicating whether to hide this plugin on the widget list page in the admin area
/// </summary>
public bool HideInWidgetList => false;
/// <summary>
/// Gets widget zones where this widget should be rendered
/// </summary>
/// <returns>Widget zones</returns>
public async Task<IList<string>> GetWidgetZonesAsync()
{
//get active widget zones system names
var activeWidgetZones = _widgetZoneService.GetWidgetZones().ToList();
activeWidgetZones = await activeWidgetZones
//process only authorized by ACL widget zones
.WhereAwait(async widgetZone => await _aclService.AuthorizeAsync(widgetZone)).ToListAsync();
//prepare of store mapped widget zones
var widgetZoneSystemNames = await activeWidgetZones
.WhereAwait(async widgetZone => await _storeMappingService.AuthorizeAsync(widgetZone))
.Select(x => x.SystemName).Distinct().ToListAsync();
return widgetZoneSystemNames;
}
/// <summary>
/// Gets a name of a view component for displaying widget
/// </summary>
/// <param name="widgetZone">Name of the widget zone</param>
/// <returns>View component name</returns>
public Type GetWidgetViewComponent(string widgetZone)
{
return typeof(PublicInfoComponent);
}
/// <summary>
/// Manage sitemap. You can use "SystemName" of menu items to manage existing sitemap or add a new menu item.
/// </summary>
/// <param name="rootNode">Root node of the sitemap.</param>
public async Task ManageSiteMapAsync(SiteMapNode rootNode)
{
//do nothing if customer can't manage plugins
if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageWidgets))
return;
//do nothing if menu item not found
var thirdPartPluginsNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName.Equals("Third party plugins", StringComparison.InvariantCultureIgnoreCase));
if (thirdPartPluginsNode == null)
return;
var pluginNode = new SiteMapNode()
{
SystemName = "Baroque-qboSlider",
Title = this.PluginDescriptor.FriendlyName,
IconClass = "far fa-dot-circle",
Visible = true,
ChildNodes = new List<SiteMapNode>()
{
new SiteMapNode()
{
SystemName = "Baroque-qBoSlider-WidgetZone",
Title = "Widget zones",
ControllerName ="qBoWidgetZone",
ActionName = "List",
IconClass = "far fa-circle",
Visible = true
},
new SiteMapNode()
{
SystemName = "Baroque-qBoSlider-Slide",
Title = "Slides",
ControllerName ="qBoSlide",
ActionName = "List",
IconClass = "far fa-circle",
Visible = true
},
new SiteMapNode()
{
SystemName = "Baroque-qBoSlider-Configuration",
Title = "Configuration",
ControllerName ="qBoConfiguration",
ActionName = "Configure",
IconClass = "far fa-circle",
Visible = true
}
}
};
thirdPartPluginsNode.ChildNodes.Add(pluginNode);
}
/// <summary>
/// Install plugin
/// </summary>
public override async Task InstallAsync()
{
//settings
var settings = new qBoSliderSettings
{
};
await _settingService.SaveSettingAsync(settings);
var widgetZone = new WidgetZone()
{
AutoPlay = true,
AutoPlayInterval = 3000,
SlideDuration = 500,
MinDragOffsetToSlide = 20,
MinSlideWidgetZoneWidth = 200,
MaxSlideWidgetZoneWidth = 1920,
SliderAlignmentId = 5,
SlideSpacing = 0,
BulletNavigationDisplayingTypeId = 2,
ArrowNavigationDisplayingTypeId = 1,
Name = "Main homepage slider",
SystemName = "home_page_top",
Published = true
};
await _widgetZoneService.InsertWidgetZoneAsync(widgetZone);
//install simple data
//get sample pictures path
var sampleImagesPath = CommonHelper.DefaultFileProvider.MapPath("~/Plugins/Widgets.qBoSlider/Content/sample-images/");
var picture1Id = (await _pictureService.InsertPictureAsync(File.ReadAllBytes(string.Format("{0}banner1.jpg", sampleImagesPath)), "image/pjpeg", "qboslide-1")).Id;
var slide1 = new Slide()
{
Name = "New comfort mouse",
Description = "<div style='color: #111; margin-top: 5%; margin-left: 5%; font-size: 16pt; font-family: arial,helvetica,sans-serif;'>" +
"<p style='margin: 0px;'><span style='font-family: tahoma,arial,helvetica,sans-serif;'><strong>NEW COMFORT MOUSE<br /></strong></span></p>" +
"<p style='margin-top: 10px; margin-bottom: 0px;'><span style='font-size: 12pt; font-family: tahoma,arial,helvetica,sans-serif;'><strong>CHOOSE FROM HUNDREDS<br /></strong></span></p>" +
"<p style='margin-top: 5px; margin-bottom: 0px;'><span style='font-size: 12pt; font-family: tahoma,arial,helvetica,sans-serif;'><strong>OF MODELS</strong></span></p>" +
"<p style='margin-top: 25px; color: #44b4f4; font-weight: bold;'><span style='font-size: 15pt; font-family: tahoma,arial,helvetica,sans-serif;'>FROM ONLY $59.00</span></p>" +
"<p style='margin-top: 10px;'><span style='font-size: 10pt; padding: 5px 10px; background: none repeat scroll 0% 0% #44b4f4; color: #ffffff; border-radius: 5px; font-family: tahoma,arial,helvetica,sans-serif;'><strong>SHOP NOW</strong></span></p></div>",
PictureId = picture1Id,
Published = true
};
await _slideService.InsertSlideAsync(slide1);
var picture2Id = (await _pictureService.InsertPictureAsync(File.ReadAllBytes(string.Format("{0}banner2.jpg", sampleImagesPath)), "image/pjpeg", "qboslide-2")).Id;
var slide2 = new Slide()
{
Name = "HD PRO WEBCAM H320",
Description = "<div style='color: #111; margin-top: 5%; margin-left: 5%; font-size: 16pt; font-family: arial,helvetica,sans-serif;'>" +
"<p style='margin: 0px;'><span style='font-family: tahoma,arial,helvetica,sans-serif;'><strong>HD PRO WEBCAM H320<br /></strong></span></p>" +
"<p style='margin-top: 10px; margin-bottom: 0px;'><span style='font-size: 12pt; font-family: tahoma,arial,helvetica,sans-serif;'><strong>720P FOR TRUE HD-QUALITY<br />VIDEO CHAT<br /></strong></span></p>" +
"<p style='margin-top: 25px; color: #44b4f4; font-weight: bold;'><span style='font-size: 15pt; font-family: tahoma,arial,helvetica,sans-serif;'>ONLY $79.00</span></p>" +
"<p style='margin-top: 10px;'><span style='font-size: 10pt; padding: 5px 10px; background: none repeat scroll 0% 0% #44b4f4; color: #ffffff; border-radius: 5px; font-family: tahoma,arial,helvetica,sans-serif;'><strong>SHOP NOW</strong></span></p></div>",
PictureId = picture2Id,
Published = true,
};
await _slideService.InsertSlideAsync(slide2);
var picture3Id = (await _pictureService.InsertPictureAsync(File.ReadAllBytes(string.Format("{0}banner3.jpg", sampleImagesPath)), "image/pjpeg", "qboslide-3")).Id;
var slide3 = new Slide()
{
Name = "Compact camera SP120",
Description = "<div style='color: #111; margin-top: 5%; margin-left: 5%; font-size: 16pt; font-family: arial,helvetica,sans-serif;'>" +
"<p style='margin: 0px;'><span style='font-family: tahoma,arial,helvetica,sans-serif;'><strong>COMPACT CAMERA SP120</strong></span></p>" +
"<p style='margin-top: 10px; margin-bottom: 0px;'><span style='font-size: 12pt; font-family: tahoma,arial,helvetica,sans-serif;'><strong>20X WIDE ZOOM, 2.5 LCD, </strong></span></p>" +
"<p style='margin-top: 5px; margin-bottom: 0px;'><span style='font-size: 12pt; font-family: tahoma,arial,helvetica,sans-serif;'><strong>720P HD VIDEO</strong></span></p>" +
"<p style='margin-top: 25px; color: #44b4f4; font-weight: bold;'><span style='font-size: 15pt; font-family: tahoma,arial,helvetica,sans-serif;'>ONLY $159.00</span></p>" +
"<p style='margin-top: 10px;'><span style='font-size: 10pt; padding: 5px 10px; background: none repeat scroll 0% 0% #44b4f4; color: #ffffff; border-radius: 5px; font-family: tahoma,arial,helvetica,sans-serif;'><strong>SHOP NOW</strong></span></p>" +
"</div>",
PictureId = picture3Id,
Published = true
};
await _slideService.InsertSlideAsync(slide3);
await _widgetZoneSlideService.InsertWidgetZoneSlideAsync(new WidgetZoneSlide()
{
SlideId = slide1.Id,
WidgetZoneId = widgetZone.Id,
DisplayOrder = 0
});
await _widgetZoneSlideService.InsertWidgetZoneSlideAsync(new WidgetZoneSlide()
{
SlideId = slide2.Id,
WidgetZoneId = widgetZone.Id,
DisplayOrder = 5
});
await _widgetZoneSlideService.InsertWidgetZoneSlideAsync(new WidgetZoneSlide()
{
SlideId = slide3.Id,
WidgetZoneId = widgetZone.Id,
DisplayOrder = 10
});
await base.InstallAsync();
}
/// <summary>
/// Uninstall plugin
/// </summary>
public override async Task UninstallAsync()
{
var allSlides = await _slideService.GetAllSlidesAsync(storeId: _storeContext.GetCurrentStore().Id);
//delete slide localization resources and pictures
foreach (var slide in allSlides)
{
await _garbageManager.DeleteSlidePictureAsync(slide);
await _garbageManager.DeleteSlideLocalizedValuesAsync(slide);
}
//settings
await _settingService.DeleteSettingAsync<qBoSliderSettings>();
await base.UninstallAsync();
}
/// <summary>
/// Exesutes plugin upgrade, if current vershion not equals already installed vershion
/// </summary>
/// <param name="currentVersion">Installed plugin version</param>
/// <param name="targetVersion">Actual plugin version from plugin descriptior file 'plugin.json'</param>
/// <returns></returns>
public override async Task UpdateAsync(string currentVersion, string targetVersion)
{
//install not existing localization values
//DO NOT update already existing values
await InstallLocalizationAsync(false);
}
#endregion
}
}