- Blogs: Create needed the tag aspect, also removing forms from individual aspect editors.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043112
This commit is contained in:
suhacan
2009-12-03 21:55:14 +00:00
parent fb128c4415
commit 3b145f93da
9 changed files with 61 additions and 24 deletions

View File

@@ -1,4 +1,5 @@
using Orchard.Core.Settings.Models;
using System.Linq;
using Orchard.Core.Settings.Models;
using Orchard.Core.Settings.Records;
using Orchard.Data;
using Orchard.Logging;
@@ -23,7 +24,7 @@ namespace Orchard.Core.Settings.Services {
public ISite GetSiteSettings() {
string applicationName = HttpContext.Current.Request.ApplicationPath;
SiteSettingsRecord record = _siteSettingsRepository.Get(x => x.SiteUrl == applicationName);
SiteSettingsRecord record = _siteSettingsRepository.Fetch(x => x.SiteUrl == applicationName).FirstOrDefault();
if (record == null) {
ISite site = _contentManager.Create<SiteSettings>("site", item => {
item.Record.SiteUrl = applicationName;

View File

@@ -70,7 +70,7 @@ namespace Orchard.Blogs.Controllers {
if (blog == null)
return new NotFoundResult();
return View(new CreateBlogPostViewModel { Blog = blog });
return View(new CreateBlogPostViewModel { Blog = blog, ItemView = _contentManager.GetEditors(_contentManager.New("blogpost"), null) });
}
[HttpPost]
@@ -84,10 +84,13 @@ namespace Orchard.Blogs.Controllers {
if (blog == null)
return new NotFoundResult();
if (!ModelState.IsValid)
if (ModelState.IsValid == false) {
model.ItemView = _contentManager.UpdateEditors(_contentManager.New("blogpost"), null, this);
return View(model);
}
BlogPost blogPost = _blogPostService.Create(model.ToCreateBlogPostParams(blog));
model.ItemView = _contentManager.UpdateEditors(blogPost, null, this);
//TEMP: (erikpo) ensure information has committed for this record
var session = _sessionLocator.For(typeof(BlogPostRecord));
@@ -136,8 +139,7 @@ namespace Orchard.Blogs.Controllers {
model.ItemView = _contentManager.UpdateEditors(model.Post.ContentItem, null, this);
IValueProvider values = input.ToValueProvider();
if (!TryUpdateModel(model, values))
return View(model);
TryUpdateModel(model, values);
_notifier.Information(T("Blog post information updated"));

View File

@@ -1,5 +1,4 @@
using System;
using System.Web.Routing;
using Orchard.Core.Common.Models;
using Orchard.Models;
using Orchard.Security;

View File

@@ -1,6 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations;
using Orchard.Blogs.Models;
using Orchard.Models.ViewModels;
using Orchard.Mvc.ViewModels;
namespace Orchard.Blogs.ViewModels {
@@ -18,5 +19,7 @@ namespace Orchard.Blogs.ViewModels {
public string Slug { get; set; }
public DateTime? Published { get; set; }
public ItemEditorViewModel ItemView { get; set; }
}
}

View File

@@ -9,5 +9,13 @@
<%using (Html.BeginForm()) { %>
<%= Html.ValidationSummary() %>
<%= Html.EditorForModel() %>
<%foreach (var editor in Model.ItemView.Editors) { %>
<%-- TODO: why is Body in editors? --%>
<%-- TODO: because any content type using the body editor doesn't need
to re-implement the rich editor, media extensions, format filter chain selection, etc --%>
<% if (!String.Equals(editor.Prefix, "Body")) { %>
<%=Html.EditorFor(m=>editor.Model, editor.TemplateName, editor.Prefix) %>
<% } %>
<%} %>
<% } %>
<% Html.Include("AdminFoot"); %>

View File

@@ -9,13 +9,13 @@
<%=Html.ValidationSummary() %>
<%=Html.EditorForModel() %>
<fieldset><input class="button" type="submit" value="Save" /></fieldset>
<% } %>
<%foreach (var editor in Model.ItemView.Editors) { %>
<%foreach (var editor in Model.ItemView.Editors) { %>
<%-- TODO: why is Body in editors? --%>
<%-- TODO: because any content type using the body editor doesn't need
to re-implement the rich editor, media extensions, format filter chain selection, etc --%>
<% if (!String.Equals(editor.Prefix, "Body")) { %>
<%=Html.EditorFor(m=>editor.Model, editor.TemplateName, editor.Prefix) %>
<% } %>
<%} %>
<% if (!String.Equals(editor.Prefix, "Body")) { %>
<%=Html.EditorFor(m=>editor.Model, editor.TemplateName, editor.Prefix) %>
<% } %>
<%} %>
<% } %>
<% Html.Include("AdminFoot"); %>

View File

@@ -1,5 +1,6 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<HasComments>" %>
<%@ Import Namespace="Orchard.Comments.Models"%>
<% if (Model.ContentItem.Id != 0) { %>
<h3><%= Model.Comments.Count() %> Comments</h3>
<ol>
<% foreach (var comment in Model.Comments) {%>
@@ -21,3 +22,4 @@
<% } else { %>
<%= Html.ActionLink("Close Comments for this content", "Close", new { Area="Orchard.Comments", Controller="Admin", returnUrl = Context.Request.Url, commentedItemId = Model.ContentItem.Id })%>
<% } %> | <%=Html.ActionLink("Go to comments management for this post", "Details", new {Area="Orchard.Comments", Controller="Admin", id = Model.ContentItem.Id, returnUrl = Context.Request.Url}) %>
<% } %>

View File

@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Data;
using Orchard.Models;
using Orchard.Models.Driver;
using Orchard.Models.ViewModels;
using Orchard.Tags.Services;
namespace Orchard.Tags.Models {
public class HasTags : ContentPart {
@@ -19,10 +21,12 @@ namespace Orchard.Tags.Models {
public class HasTagsProvider : ContentProvider {
private readonly IRepository<Tag> _tagsRepository;
private readonly IRepository<TagsContentItems> _tagsContentItemsRepository;
private readonly ITagService _tagService;
public HasTagsProvider(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository) {
public HasTagsProvider(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository, ITagService tagService) {
_tagsRepository = tagsRepository;
_tagsContentItemsRepository = tagsContentItemsRepository;
_tagService = tagService;
Filters.Add(new ActivatingFilter<HasTags>("sandboxpage"));
Filters.Add(new ActivatingFilter<HasTags>("blogpost"));
@@ -43,6 +47,12 @@ namespace Orchard.Tags.Models {
if (context.ContentItem.Has<HasTags>() == false) {
return;
}
TagsViewModel viewModel = new TagsViewModel();
context.Updater.TryUpdateModel(viewModel, String.Empty, null, null);
List<string> tagNames = ParseCommaSeparatedTagNames(viewModel.Tags);
_tagService.UpdateTagsForContentItem(context.ContentItem.Id, tagNames);
context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasTags>()));
}
@@ -59,5 +69,23 @@ namespace Orchard.Tags.Models {
tags.CurrentTags.Add(tag);
}
}
private static List<string> ParseCommaSeparatedTagNames(string tags) {
if (String.IsNullOrEmpty(tags)) {
return new List<string>();
}
IEnumerable<string> tagNames = tags.Split(',');
List<string> sanitizedTagNames = new List<string>();
foreach (var tagName in tagNames) {
if (!String.IsNullOrEmpty(tagName)) {
sanitizedTagNames.Add(tagName);
}
}
return sanitizedTagNames;
}
public class TagsViewModel {
public string Tags { get; set; }
}
}
}

View File

@@ -2,12 +2,8 @@
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Tags.Models"%>
<h3>Tags</h3>
<% Html.BeginForm("Update", "Home", new { area = "Orchard.Tags" }); %>
<%= Html.ValidationSummary() %>
<div class="yui-g">
<h2 class="separator">Edit Tags</h2>
<%= Html.Hidden("TaggedContentId", Model.ContentItem.Id) %>
<%= Html.Hidden("ReturnUrl", Context.Request.Url) %>
<h2 class="separator">Edit Tags</h2>
<%
string tags = "";
foreach (var tag in Model.CurrentTags) {
@@ -16,9 +12,7 @@
} %>
<ol>
<li>
<input id="tags" class="inputText inputTextLarge" name="tags" type="text" value="<%=tags %>" />
<input type="submit" class="button" name="submit.Add" value="Add" />
<input id="Tags" class="inputText inputTextLarge" name="Tags" type="text" value="<%=tags %>" />
</li>
</ol>
</div>
<% Html.EndForm(); %>
</div>