2010-07-18 12:36:02 -07:00
|
|
|
using System;
|
2010-07-06 18:56:55 -07:00
|
|
|
using System.Linq;
|
2010-07-04 14:14:15 -07:00
|
|
|
using System.Web.Mvc;
|
|
|
|
using Orchard.Environment.Extensions;
|
2010-07-06 18:56:55 -07:00
|
|
|
using Orchard.Localization;
|
2010-07-22 22:09:34 -07:00
|
|
|
using Orchard.Packaging.Services;
|
|
|
|
using Orchard.Packaging.ViewModels;
|
2010-07-04 14:14:15 -07:00
|
|
|
using Orchard.Themes;
|
|
|
|
using Orchard.UI.Admin;
|
2010-07-06 18:56:55 -07:00
|
|
|
using Orchard.UI.Notify;
|
2010-07-04 14:14:15 -07:00
|
|
|
|
2010-07-22 22:09:34 -07:00
|
|
|
namespace Orchard.Packaging.Controllers {
|
|
|
|
[OrchardFeature("Gallery")]
|
2010-07-11 15:41:16 -07:00
|
|
|
[Themed, Admin]
|
2010-07-22 23:00:00 -07:00
|
|
|
public class GalleryController : Controller {
|
2010-07-06 18:56:55 -07:00
|
|
|
private readonly IPackageManager _packageManager;
|
2010-07-18 13:09:45 -07:00
|
|
|
private readonly IPackagingSourceManager _packagingSourceManager;
|
2010-07-06 18:56:55 -07:00
|
|
|
private readonly IExtensionManager _extensionManager;
|
|
|
|
private readonly INotifier _notifier;
|
2010-07-04 14:14:15 -07:00
|
|
|
|
2010-07-22 23:00:00 -07:00
|
|
|
public GalleryController(
|
2010-07-06 18:56:55 -07:00
|
|
|
IPackageManager packageManager,
|
2010-07-18 13:09:45 -07:00
|
|
|
IPackagingSourceManager packagingSourceManager,
|
2010-07-06 18:56:55 -07:00
|
|
|
IExtensionManager extensionManager,
|
|
|
|
INotifier notifier) {
|
|
|
|
_packageManager = packageManager;
|
2010-07-18 13:09:45 -07:00
|
|
|
_packagingSourceManager = packagingSourceManager;
|
2010-07-06 18:56:55 -07:00
|
|
|
_extensionManager = extensionManager;
|
|
|
|
_notifier = notifier;
|
|
|
|
T = NullLocalizer.Instance;
|
2010-07-04 14:14:15 -07:00
|
|
|
}
|
|
|
|
|
2010-07-06 18:56:55 -07:00
|
|
|
Localizer T { get; set; }
|
|
|
|
|
2010-07-04 14:14:15 -07:00
|
|
|
public ActionResult Index() {
|
2010-07-23 16:37:25 -07:00
|
|
|
return Modules(Guid.Empty);
|
2010-07-04 14:14:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult Sources() {
|
2010-07-06 18:56:55 -07:00
|
|
|
return View("Sources", new PackagingSourcesViewModel {
|
2010-07-18 13:09:45 -07:00
|
|
|
Sources = _packagingSourceManager.GetSources(),
|
2010-07-04 14:14:15 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-07-23 16:37:25 -07:00
|
|
|
public ActionResult Remove(Guid id) {
|
|
|
|
_packagingSourceManager.RemoveSource(id);
|
|
|
|
_notifier.Information(T("The feed has been removed successfully."));
|
2010-07-06 18:56:55 -07:00
|
|
|
Update();
|
|
|
|
return RedirectToAction("Sources");
|
|
|
|
}
|
|
|
|
|
2010-07-23 16:37:25 -07:00
|
|
|
public ActionResult AddSource() {
|
|
|
|
return View(new PackagingAddSourceViewModel());
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult AddSourceViewResult(PackagingAddSourceViewModel model) {
|
|
|
|
return View("AddSource", model);
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public ActionResult AddSource(string title, string url) {
|
|
|
|
try {
|
|
|
|
if ( !String.IsNullOrEmpty(url) ) {
|
|
|
|
if (!url.StartsWith("http")) {
|
|
|
|
ModelState.AddModelError("Url", T("The Url is a valid").Text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( String.IsNullOrWhiteSpace(url)) {
|
|
|
|
ModelState.AddModelError("Url", T("Url is required").Text);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( String.IsNullOrWhiteSpace(title) ) {
|
|
|
|
ModelState.AddModelError("Url", T("Title is required").Text);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !ModelState.IsValid )
|
|
|
|
return AddSourceViewResult(new PackagingAddSourceViewModel(){Title = title, Url = url});
|
|
|
|
|
|
|
|
_packagingSourceManager.AddSource(new PackagingSource { Id = Guid.NewGuid(), FeedUrl = url, FeedTitle = title });
|
|
|
|
_notifier.Information(T("The feed has been added successfully."));
|
|
|
|
Update();
|
|
|
|
return RedirectToAction("Sources");
|
|
|
|
}
|
|
|
|
catch ( Exception exception ) {
|
|
|
|
_notifier.Error(T("Adding feed failed: {0}", exception.Message));
|
|
|
|
return AddSourceViewResult(new PackagingAddSourceViewModel() { Title = title, Url = url });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ActionResult Modules(Guid? sourceId) {
|
|
|
|
var selectedSource = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault();
|
2010-07-06 18:56:55 -07:00
|
|
|
|
|
|
|
return View("Modules", new PackagingModulesViewModel {
|
2010-07-23 16:37:25 -07:00
|
|
|
Modules = _packagingSourceManager.GetModuleList(selectedSource),
|
|
|
|
Sources = _packagingSourceManager.GetSources().OrderBy(s => s.FeedTitle),
|
|
|
|
SelectedSource = selectedSource
|
2010-07-06 18:56:55 -07:00
|
|
|
});
|
2010-07-04 14:14:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult Update() {
|
2010-07-18 13:09:45 -07:00
|
|
|
_packagingSourceManager.UpdateLists();
|
2010-07-06 18:56:55 -07:00
|
|
|
_notifier.Information(T("List of available modules and themes is updated."));
|
2010-07-04 14:14:15 -07:00
|
|
|
return RedirectToAction("Index");
|
|
|
|
}
|
|
|
|
|
2010-07-06 18:56:55 -07:00
|
|
|
public ActionResult Harvest(string extensionName, string feedUrl) {
|
|
|
|
return View("Harvest", new PackagingHarvestViewModel {
|
|
|
|
ExtensionName = extensionName,
|
|
|
|
FeedUrl = feedUrl,
|
2010-07-18 13:09:45 -07:00
|
|
|
Sources = _packagingSourceManager.GetSources(),
|
2010-07-06 18:56:55 -07:00
|
|
|
Extensions = _extensionManager.AvailableExtensions()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public ActionResult Harvest(PackagingHarvestViewModel model) {
|
2010-07-18 13:09:45 -07:00
|
|
|
model.Sources = _packagingSourceManager.GetSources();
|
2010-07-06 18:56:55 -07:00
|
|
|
model.Extensions = _extensionManager.AvailableExtensions();
|
|
|
|
|
|
|
|
var packageData = _packageManager.Harvest(model.ExtensionName);
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(model.FeedUrl)) {
|
|
|
|
return new DownloadStreamResult(
|
|
|
|
packageData.ExtensionName + "-" + packageData.ExtensionVersion + ".zip",
|
|
|
|
"application/x-package",
|
|
|
|
packageData.PackageStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!model.Sources.Any(src => src.FeedUrl == model.FeedUrl)) {
|
|
|
|
ModelState.AddModelError("FeedUrl", T("May only push directly to one of the configured sources.").ToString());
|
|
|
|
return View("Harvest", model);
|
|
|
|
}
|
|
|
|
|
|
|
|
_packageManager.Push(packageData, model.FeedUrl);
|
|
|
|
_notifier.Information(T("Harvested {0} and published onto {1}", model.ExtensionName, model.FeedUrl));
|
|
|
|
|
|
|
|
Update();
|
|
|
|
|
|
|
|
return RedirectToAction("Harvest", new { model.ExtensionName, model.FeedUrl });
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionResult Install(string syndicationId) {
|
|
|
|
var packageData = _packageManager.Download(syndicationId);
|
2010-07-18 13:09:45 -07:00
|
|
|
_packageManager.Install(packageData.PackageStream);
|
2010-07-06 18:56:55 -07:00
|
|
|
_notifier.Information(T("Installed module"));
|
|
|
|
return RedirectToAction("Modules");
|
|
|
|
}
|
|
|
|
}
|
2010-07-04 14:14:15 -07:00
|
|
|
}
|