/// <summary> /// Gets properties and inherited properties from parent doctype. /// </summary> /// <param name="inheritedFromDocType"></param> /// <returns></returns> private HashSet<DocumentTypeProperty> GetInheritedProperties(DocumentTypeEditorModel inheritedFromDocType) { var inheritedProps = new HashSet<DocumentTypeProperty>(inheritedFromDocType.Properties); //foreach (var t in inheritedFromDocType.InheritedProperties) //{ // inheritedProps.Add(t); //} return inheritedProps; }
/// <summary> /// Gets tabs and inherited tabs from parent doctype. /// </summary> /// <param name="inheritedFromDocType"></param> /// <returns></returns> private HashSet<Tab> GetInheritedTabs(DocumentTypeEditorModel inheritedFromDocType) { var inheritedTabs = new HashSet<Tab>(inheritedFromDocType.DefinedTabs); //foreach (var t in inheritedFromDocType.InheritedTabs) //{ // inheritedTabs.Add(t); //} return inheritedTabs; }
/// <summary> /// Create properties from xml /// </summary> /// <param name="docTypeXml"></param> /// <param name="docType"></param> /// <returns></returns> private new HashSet<DocumentTypeProperty> CreateProperties(XElement docTypeXml, DocumentTypeEditorModel docType) { var properties = new HashSet<DocumentTypeProperty>(); properties.Add(CreateNodeName(docType)); properties.Add(CreateSelectedTemplate(docType)); var propsXml = docTypeXml.Descendants("property"); foreach (var xElement in propsXml) { var name = xElement.Attribute("Name").Value; var alias = xElement.Attribute("Alias").Value; var dataTypeAlias = xElement.Element("DataTypeAlias").Value; var sortOrder = int.Parse(xElement.Attribute("SortOrder").Value); var tabAlias = xElement.Attribute("TabAlias").Value; LogHelper.Error<UmbracoXmlImportHelper>(String.Format("the data type alias was {0}", dataTypeAlias), new Exception()); var dataType = _dataTypes.First(x => x.Alias == dataTypeAlias); // TODO: property is not in tab...possibly need object initializer? var p = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), dataType) { Name = name, Alias = alias, // TabId = docType.DefinedTabs.Single(x => x.Alias == tabAlias).Id, SortOrder = sortOrder }; properties.Add(p); } return properties; }
/// <summary> /// Creates selected template property /// </summary> /// <param name="docType"></param> /// <returns></returns> private DocumentTypeProperty CreateSelectedTemplate(DocumentTypeEditorModel docType) { var selectedTemplateAttributeType = _attributeTypeRegistry.GetAttributeType(SelectedTemplateAttributeType.AliasValue); _selectedTemplateDataType = new DataType( selectedTemplateAttributeType.Id, selectedTemplateAttributeType.Name, selectedTemplateAttributeType.Alias, _propertyEditorFactory.GetPropertyEditor(new Guid(CorePluginConstants.SelectedTemplatePropertyEditorId)).Value, string.Empty); var dtp = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _selectedTemplateDataType); dtp.Name = "Selected template"; dtp.Alias = SelectedTemplateAttributeDefinition.AliasValue; //dtp.TabId = docType.DefinedTabs.Where(x => x.Alias == _generalGroup.Alias).Single().Id; dtp.TabId = docType.DefinedTabs.Single(x => x.Alias == FixedGroupDefinitions.GeneralGroup.Alias).Id; dtp.SortOrder = 0; return dtp; }
/// <summary> /// Creates doctype from xml /// </summary> /// <param name="docTypeXml"> </param> /// <param name="generateTabs"> </param> /// <param name="providerGroupRoot"> </param> /// <returns></returns> private DocumentTypeEditorModel CreateDocType(XElement docTypeXml, Func<IEnumerable<Tab>> generateTabs, Uri providerGroupRoot) { //var docType = new DocumentTypeEditorModel(HiveId.ConvertIntToGuid(id)); var docType = new DocumentTypeEditorModel(new HiveId(Guid.NewGuid())); docType.Name = docTypeXml.Attribute("Name").Value; docType.Alias = docTypeXml.Attribute("Alias").Value; docType.Description = docTypeXml.Element("Description").Value; docType.Icon = docTypeXml.Element("Icon").Value; docType.Thumbnail = docTypeXml.Element("Thumbnail").Value; docType.AllowedTemplates = GetAllowedTemplates(docTypeXml); docType.DefaultTemplateId = docTypeXml.Element("DefaultTemplate").Value == string.Empty ? HiveId.Empty : _templates.Single(x => x.Name == docTypeXml.Element("DefaultTemplate").Value).Id; var tabs = generateTabs.Invoke().ToList(); tabs.AddRange(GetTabs(docTypeXml)); docType.DefinedTabs = new HashSet<Tab>(tabs); docType.IsAbstract = bool.Parse(docTypeXml.Element("IsAbstract").Value); // get properties docType.Properties = CreateProperties(docTypeXml, docType); return docType; }
/// <summary> /// Creates Node Name property /// </summary> /// <param name="docType"></param> /// <returns></returns> private DocumentTypeProperty CreateNodeName(DocumentTypeEditorModel docType) { var nodeNameAttributeType = _attributeTypeRegistry.GetAttributeType(NodeNameAttributeType.AliasValue); _nodeNameDataType = new DataType( nodeNameAttributeType.Id, nodeNameAttributeType.Name, nodeNameAttributeType.Alias, _propertyEditorFactory.GetPropertyEditor(new Guid(CorePluginConstants.NodeNamePropertyEditorId)).Value, string.Empty); var dtp = new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _nodeNameDataType); dtp.Name = "Node Name"; dtp.Alias = NodeNameAttributeDefinition.AliasValue; dtp.TabId = docType.DefinedTabs.Single(x => x.Alias == FixedGroupDefinitions.GeneralGroup.Alias).Id; dtp.SortOrder = 0; return dtp; }
/// <summary> /// Create selected template content property. /// </summary> /// <param name="docType"></param> /// <param name="selectedTemplateId"> </param> /// <returns></returns> private ContentProperty CreateSelectedTemplateContentProperty(DocumentTypeEditorModel docType, HiveId selectedTemplateId) { var prop = new ContentProperty((HiveId)Guid.NewGuid(), docType.Properties.Single(x => x.Alias == SelectedTemplateAttributeDefinition.AliasValue), selectedTemplateId.IsNullValueOrEmpty() ? new Dictionary<string, object>() : new Dictionary<string, object> { { "TemplateId", selectedTemplateId.ToString() } }) { Name = SelectedTemplateAttributeDefinition.AliasValue, Alias = SelectedTemplateAttributeDefinition.AliasValue, TabId = docType.DefinedTabs.Single(x => x.Alias == FixedGroupDefinitions.GeneralGroup.Alias).Id }; return prop; }
/// <summary> /// Create selected template content property. /// </summary> /// <param name="docType"></param> /// <param name="node"></param> /// <returns></returns> private ContentProperty CreateNodeNameContentProperty(DocumentTypeEditorModel docType, XElement nodeXml) { var prop = new ContentProperty((HiveId)Guid.NewGuid(), docType.Properties.Single(x => x.Alias == NodeNameAttributeDefinition.AliasValue), new Dictionary<string, object> { { "Name", (string)nodeXml.Attribute("nodeName") } }) { Name = NodeNameAttributeDefinition.AliasValue, Alias = NodeNameAttributeDefinition.AliasValue, TabId = docType.DefinedTabs.Single(x => x.Alias == FixedGroupDefinitions.GeneralGroup.Alias).Id }; return prop; }
/// <summary> /// /// </summary> /// <param name="docType"></param> /// <param name="templateId"> </param> /// <param name="x"></param> /// <returns></returns> private ContentEditorModel CreateContentNodeFromXml(DocumentTypeEditorModel docType, HiveId templateId, XElement x) { var parentId = x.Attribute("parentID"); var contentNode = new ContentEditorModel(HiveId.ConvertIntToGuid((int)x.Attribute("id"))) { Name = (string)x.Attribute("nodeName"), DocumentTypeId = docType == null ? HiveId.Empty : docType.Id, DocumentTypeName = docType == null ? "" : docType.Name, DocumentTypeAlias = docType == null ? "" : docType.Alias, ParentId = parentId != null ? HiveId.ConvertIntToGuid((int)parentId) : HiveId.Empty, //assign the properties Properties = GetNodeProperties(x, templateId) }; return contentNode; }
private DocumentTypeProperty CreateSelectedTemplateId(DocumentTypeEditorModel docType) { return new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _selectedTemplateDataType) { Name = "Selected template", Alias = SelectedTemplateAttributeDefinition.AliasValue, TabId = docType.DefinedTabs.Where(x => x.Alias == _generalGroup.Alias).Single().Id, SortOrder = 0 }; }
private void InitDocTypes() { Func<Tab[]> generateTabs = () => new[] { new Tab {Id = HiveId.ConvertIntToGuid(++_tabIdCounter), Alias = "tab1", Name = "Some Content", SortOrder = 0}, new Tab {Id = HiveId.ConvertIntToGuid(++_tabIdCounter), Alias = "tab2", Name = "A second test tab", SortOrder = 1}, new Tab {Id = HiveId.ConvertIntToGuid(++_tabIdCounter), Alias = "tab3", Name = "Other info", SortOrder = 2}, //add the general tab new Tab { Id = HiveId.ConvertIntToGuid(++_tabIdCounter), Alias = _generalGroup.Alias, Name = _generalGroup.Name, SortOrder = _generalGroup.Ordinal } }; var providerGroupRoot = new Uri("content://"); var homePage = new DocumentTypeEditorModel(HiveId.ConvertIntToGuid(1045)) { Name = "Home Page", Description = "Represents a home page node", Icon = "doc.gif", Thumbnail = "folder.png", Alias = "homePage", AllowedTemplates = new List<SelectListItem>(new[] { _templates.First() }.Select(x => new SelectListItem {Selected = true, Text = x.Name, Value = x.Id.ToString()})), DefaultTemplateId = _templates.First().Id, DefinedTabs = new HashSet<Tab>(generateTabs.Invoke()), InheritFrom = new[]{ new HierarchicalSelectListItem { Selected = true, Value = FixedHiveIds.ContentRootSchema.ToString() } }, AllowedChildren = new[] { new SelectListItem { Selected = true, Value = HiveId.ConvertIntToGuid(providerGroupRoot, "nhibernate", 1046).ToString() }, new SelectListItem { Selected = true, Value = HiveId.ConvertIntToGuid(providerGroupRoot, "nhibernate", 2000).ToString() } } }; homePage.Properties = new HashSet<DocumentTypeProperty>(new[] { CreateNodeName(homePage), CreateSelectedTemplateId(homePage), new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[0]) { Name = "Body Text", Alias = "bodyText", TabId = homePage.DefinedTabs.ElementAt(0).Id, SortOrder = 0 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "Site Name", Alias = "siteName", TabId = homePage.DefinedTabs.ElementAt(1).Id, SortOrder = 1 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "Site Description", Alias = "siteDescription", TabId = homePage.DefinedTabs.ElementAt(1).Id, SortOrder = 2 }, }); var contentPage = new DocumentTypeEditorModel(HiveId.ConvertIntToGuid(1046)) { Name = "Content Page", Description = "A page for content", Icon = "doc4.gif", Thumbnail = "doc.png", Alias = "contentPage", AllowedTemplates = new List<SelectListItem>(new[] { _templates.ElementAt(1) }.Select(x => new SelectListItem { Selected = true, Text = x.Name, Value = x.Id.ToString() })), DefaultTemplateId = _templates.ElementAt(1).Id, DefinedTabs = new HashSet<Tab>(generateTabs.Invoke()), InheritFrom = new[]{ new HierarchicalSelectListItem { Selected = true, Value = FixedHiveIds.ContentRootSchema.ToString() } }, AllowedChildren = new[] { new SelectListItem { Selected = true, Value = HiveId.ConvertIntToGuid(providerGroupRoot, "nhibernate", 1046).ToString() } } }; contentPage.Properties = new HashSet<DocumentTypeProperty>(new[] { CreateNodeName(contentPage), CreateSelectedTemplateId(contentPage), new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[0]) { Name = "Body Text", Alias = "bodyText", TabId = contentPage.DefinedTabs.ElementAt(0).Id, SortOrder = 0 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "Umbraco Hide in Nav", Alias = "umbracoNaviHide", TabId = contentPage.DefinedTabs.ElementAt(1).Id, SortOrder = 4 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[2]) { Name = "Color Swatch Picker", Alias = "colorSwatchPicker", TabId = contentPage.DefinedTabs.ElementAt(0).Id, SortOrder = 5 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[3]) { Name = "Tags", Alias = "tags", TabId = contentPage.DefinedTabs.ElementAt(0).Id, SortOrder = 5 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[4]) { Name = "Textbox", Alias = "textBox", TabId = contentPage.DefinedTabs.ElementAt(0).Id, SortOrder = 5 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "New tree", Alias = "newTree", TabId = contentPage.DefinedTabs.ElementAt(0).Id, SortOrder = 5 } }); var faq = new DocumentTypeEditorModel(HiveId.ConvertIntToGuid(1055)) { Name = "Faq", Description = "A Faqs container", Icon = "doc4.gif", Thumbnail = "doc.png", Alias = "Faq", AllowedTemplates = new List<SelectListItem>(new[] {_templates.ElementAt(2)}.Select(x => new SelectListItem {Selected = true, Text = x.Name, Value = x.Id.ToString()})), DefaultTemplateId = _templates.ElementAt(2).Id, DefinedTabs = new HashSet<Tab>(generateTabs.Invoke()), InheritFrom = new[]{ new HierarchicalSelectListItem { Selected = true, Value = FixedHiveIds.ContentRootSchema.ToString() } }, AllowedChildren = new[] { new SelectListItem { Selected = true, Value = HiveId.ConvertIntToGuid(providerGroupRoot, "nhibernate", 1056).ToString() } } }; faq.Properties = new HashSet<DocumentTypeProperty>(new[] { CreateNodeName(faq), CreateSelectedTemplateId(faq), new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[0]) { Name = "Body Text", Alias = "bodyText", TabId = faq.DefinedTabs.ElementAt(0).Id, SortOrder = 0 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "Umbraco Hide in Nav", Alias = "umbracoNaviHide", TabId = faq.DefinedTabs.ElementAt(1).Id, SortOrder = 4 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "Show Form", Alias = "ShowForm", TabId = faq.DefinedTabs.ElementAt(0).Id, SortOrder = 5 }, }); var faqCategory = new DocumentTypeEditorModel(HiveId.ConvertIntToGuid(1056)) { Name = "Faq Category", Description = "An Faq category", Icon = "doc4.gif", Thumbnail = "doc.png", Alias = "FaqCategory", //AllowedTemplates = new List<SelectListItem>(new[] { _templates.ElementAt(3) }.Select(x => new SelectListItem { Selected = true, Text = x.Name, Value = x.Id.ToString() })), //DefaultTemplateId = _templates.ElementAt(3).Id, DefinedTabs = new HashSet<Tab>(generateTabs.Invoke()), InheritFrom = new[]{ new HierarchicalSelectListItem { Selected = true, Value = FixedHiveIds.ContentRootSchema.ToString() } }, AllowedChildren = new[] { new SelectListItem { Selected = true, Value = HiveId.ConvertIntToGuid(providerGroupRoot, "nhibernate", 1057).ToString() } } }; faqCategory.Properties = new HashSet<DocumentTypeProperty>(new[] { CreateNodeName(faqCategory), CreateSelectedTemplateId(faqCategory), new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[0]) { Name = "Body Text", Alias = "bodyText", TabId = faqCategory.DefinedTabs.ElementAt(0).Id, SortOrder = 0 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "Umbraco Hide in Nav", Alias = "umbracoNaviHide", TabId = faqCategory.DefinedTabs.ElementAt(1).Id, SortOrder = 4 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "Show Form", Alias = "ShowForm", TabId = faqCategory.DefinedTabs.ElementAt(0).Id, SortOrder = 5 }, }); var faqQuestion = new DocumentTypeEditorModel(HiveId.ConvertIntToGuid(1057)) { Name = "Faq Question", Description = "An Faq question", Icon = "doc4.gif", Thumbnail = "doc.png", Alias = "FaqQuestion", //AllowedTemplates = new List<SelectListItem>(new[] { _templates.ElementAt(4) }.Select(x => new SelectListItem { Selected = true, Text = x.Name, Value = x.Id.ToString() })), //DefaultTemplateId = _templates.ElementAt(4).Id, DefinedTabs = new HashSet<Tab>(generateTabs.Invoke()), InheritFrom = new[]{ new HierarchicalSelectListItem { Selected = true, Value = FixedHiveIds.ContentRootSchema.ToString() } }, }; faqQuestion.Properties = new HashSet<DocumentTypeProperty>(new[] { CreateNodeName(faqQuestion), CreateSelectedTemplateId(faqQuestion), new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[0]) { Name = "Body Text", Alias = "bodyText", TabId = faqQuestion.DefinedTabs.ElementAt(0).Id, SortOrder = 0 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "Question Text", Alias = "questionText", TabId = faqQuestion.DefinedTabs.ElementAt(1).Id, SortOrder = 1 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "Umbraco Hide in Nav", Alias = "umbracoNaviHide", TabId = faqQuestion.DefinedTabs.ElementAt(1).Id, SortOrder = 4 }, }); var booksPage = new DocumentTypeEditorModel(HiveId.ConvertIntToGuid(2000)) { Name = "Books Page", Description = "List of usefull books", Icon = "doc4.gif", Thumbnail = "doc.png", Alias = "BooksPage", AllowedTemplates = new List<SelectListItem>(new[] { _templates.ElementAt(5) }.Select(x => new SelectListItem { Selected = true, Text = x.Name, Value = x.Id.ToString() })), DefaultTemplateId = _templates.ElementAt(5).Id, DefinedTabs = new HashSet<Tab>(new[] { new Tab {Id = HiveId.ConvertIntToGuid(++_tabIdCounter), Alias = "content", Name = "Content", SortOrder = 0}, new Tab { Id = HiveId.ConvertIntToGuid(++_tabIdCounter), Alias = _generalGroup.Alias, Name = _generalGroup.Name, SortOrder = _generalGroup.Ordinal } }), InheritFrom = new[]{ new HierarchicalSelectListItem { Selected = true, Value = FixedHiveIds.ContentRootSchema.ToString() } }, AllowedChildren = new[] { new SelectListItem { Selected = true, Value = HiveId.ConvertIntToGuid(providerGroupRoot, "nhibernate", 2001).ToString() } } }; booksPage.Properties = new HashSet<DocumentTypeProperty>(new[] { CreateNodeName(booksPage), CreateSelectedTemplateId(booksPage) }); var bookPage = new DocumentTypeEditorModel(HiveId.ConvertIntToGuid(2001)) { Name = "Book Page", Description = "An individual book", Icon = "doc4.gif", Thumbnail = "doc.png", Alias = "BookPage", AllowedTemplates = new List<SelectListItem>(new[] { _templates.ElementAt(6) }.Select(x => new SelectListItem { Selected = true, Text = x.Name, Value = x.Id.ToString() })), DefaultTemplateId = _templates.ElementAt(6).Id, DefinedTabs = new HashSet<Tab>(new[] { new Tab { Id = HiveId.ConvertIntToGuid(++_tabIdCounter), Alias = "content", Name = "Content", SortOrder = 0}, new Tab { Id = HiveId.ConvertIntToGuid(++_tabIdCounter), Alias = _generalGroup.Alias, Name = _generalGroup.Name, SortOrder = _generalGroup.Ordinal } }), InheritFrom = new[]{ new HierarchicalSelectListItem { Selected = true, Value = FixedHiveIds.ContentRootSchema.ToString() } }, }; bookPage.Properties = new HashSet<DocumentTypeProperty>(new[] { CreateNodeName(bookPage), CreateSelectedTemplateId(bookPage), new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[0]) { Name = "Description", Alias = "bodyText", TabId = bookPage.DefinedTabs.ElementAt(0).Id, SortOrder = 0 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[1]) { Name = "Publisher", Alias = "publisher", TabId = bookPage.DefinedTabs.ElementAt(0).Id, SortOrder = 0 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[6]) { Name = "Number of Pages", Alias = "numberOfPages", TabId = bookPage.DefinedTabs.ElementAt(0).Id, SortOrder = 0 }, new DocumentTypeProperty(new HiveId(Guid.NewGuid()), _dataTypes[7]) { Name = "Image", Alias = "image", TabId = bookPage.DefinedTabs.ElementAt(0).Id, SortOrder = 0 } }); _docTypes = new List<DocumentTypeEditorModel> { homePage, contentPage, faq, faqCategory, faqQuestion, booksPage, bookPage }; }