/// <summary> /// Get the possible patterns for a new url of the given type /// </summary> /// <param name="datatype">Type as its name as a string</param> /// <returns>The patterns as JSON</returns> public IActionResult TypePatterns(string datatype) { Type type = ContentTypeHierarchy.GetContentType(datatype); var patterns = RouteData.GetTemplatePatterns(type); return(Json(patterns)); }
/// <summary> /// Get the possible patterns for a new url of the given type /// </summary> /// <param name="datatype">Type as its name as a string</param> /// <returns>The patterns as JSON</returns> public ActionResult TypePatterns(string datatype) { Type type = ContentTypeHierarchy.GetContentType(datatype); var patterns = ContentMap.Instance.GetUrlPatterns(type); return(Json(patterns, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Get markup to refresh an individual item on the List page /// </summary> /// <param name="datatype">Type of the item</param> /// <param name="id">Id of the item</param> /// <returns>Markup for the item</returns> public ActionResult GetItem(string datatype, string id) { ViewData.Add("UrlPermission", LyniconSecurityManager.Current.CurrentUserInRole(Lynicon.Membership.User.EditorRole)); Type type = ContentTypeHierarchy.GetContentType(datatype); var summ = Collator.Instance.Get <Summary>(new ItemId(type, id)); return(PartialView("ItemListSummary", summ)); }
/// <summary> /// Constructs an address from a serialized string form (created via .ToString()) /// </summary> /// <param name="serialized">the serialized string</param> public Address(string serialized) { this.Type = ContentTypeHierarchy.GetContentType(serialized.UpTo(":")); foreach (string kvpStr in serialized.After(":").Split('&')) { this.Add(HttpUtility.UrlDecode(kvpStr.UpTo("=")), HttpUtility.UrlDecode(kvpStr.After("="))); } }
//public IEnumerable<string> GetUrls(object item) //{ // Type type = item.GetType(); // if (type == typeof(ContentItem)) // type = ContentTypeHierarchy.GetContentType((item as ContentItem).DataType); // var routes = RouteTable.Routes // .OfType<Route>() // .Where(r => r.GetType().IsGenericType // && r.GetType().GetGenericTypeDefinition() == typeof(DataRoute<>) // && r.GetType().GetGenericArguments()[0] == type); // foreach (var route in routes) // { // var urls = GetUrls(route, item); // foreach (string url in urls) // yield return url; // } //} //public List<string> GetUrls(Route route, object item) //{ // return Registered(route.GetType().GetGenericArguments()[0]).GetUrls(route, item); //} public Dictionary <string, string> GetAddress(object item) { Type type = item.GetType(); if (item is ContentItem) { type = ContentTypeHierarchy.GetContentType(((ContentItem)item).DataType); } return(Registered(type).GetAddress(item)); }
/// <summary> /// Get markup to show all the items of a type in a paged box on the List page /// </summary> /// <param name="datatype">The data type</param> /// <returns>Markup of the paged box listing the items</returns> public ActionResult GetPage(string datatype) { ViewData.Add("UrlPermission", LyniconSecurityManager.Current.CurrentUserInRole(Lynicon.Membership.User.EditorRole)); ViewData.Add("DelPermission", LyniconSecurityManager.Current.CurrentUserInRole(Lynicon.Membership.User.AdminRole)); Type type = ContentTypeHierarchy.GetContentType(datatype); Type containerType = Collator.Instance.ContainerType(type); // invoke Collator.Instance.GetList<Summary, type>(new Type[] { type }, RouteData).ToArray(); var summs = (IEnumerable <Summary>)ReflectionX.InvokeGenericMethod(Collator.Instance, "GetList", new Type[] { typeof(Summary), containerType }, new Type[] { type }, RouteData); var data = summs.ToArray(); return(PartialView("ItemPage", data)); }
public IActionResult RefQuery(string query, string listId, string allowedVsn) { var types = listId.Split('_').Select(cn => ContentTypeHierarchy.GetContentType(cn)).ToList(); bool showType = types.Count > 1; var qWords = query.ToLower().Split(new char [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); ItemVersion maskVsn = null; ItemVersion currMaskedVsn = null; bool versioned = false; if (!string.IsNullOrEmpty(allowedVsn)) { maskVsn = new ItemVersion(allowedVsn); ItemVersion curr = sys.Versions.CurrentVersion; ItemVersion vsn = curr.Superimpose(maskVsn); currMaskedVsn = curr.Mask(maskVsn); sys.Versions.PushState(VersioningMode.Specific, vsn); versioned = true; } try { var cachedTypes = types.Where(t => Cache.IsTotalCached(LyniconModuleManager.Instance, t, true)).ToList(); var uncachedTypes = types.Except(cachedTypes).ToList(); var items = Enumerable.Range(0, 1).Select(n => new { label = "", value = "" }).ToList(); items.Clear(); if (uncachedTypes.Count > 0) { // TO DO add attribute for containers specifying which field or fields to scan for title, add code to create query to scan here } if (cachedTypes.Count > 0) { items.AddRange(Collator.Instance.Get <Summary, Summary>(cachedTypes, iq => iq.Where(s => qWords.All(w => ((s.Title ?? "").ToLower() + " " + s.Type.Name.ToLower()).Contains(w))).Take(30)) .Select(summ => new { label = summ.Title + (showType ? " (" + LyniconUi.ContentClassDisplayName(summ.Type) + ")" : "") + (versioned && !currMaskedVsn.ContainedBy(summ.Version.Mask(maskVsn)) ? " [" + sys.Versions.DisplayVersion(summ.Version.Mask(maskVsn)).Select(dv => dv.Text).Join(" ") + "]" : ""), value = versioned ? summ.ItemVersionedId.Mask(maskVsn).ToString() : summ.ItemId.ToString() }) .OrderBy(s => s.label)); } return(Json(new { items })); } finally { if (versioned) { sys.Versions.PopState(); } } }
/// <summary> /// Construct an ItemId by deserializing it from a string (created via .ToString()) /// </summary> /// <param name="s">Serialized ItemId</param> public ItemId(string s) { if (string.IsNullOrEmpty(s) || !s.Contains(":")) { throw new ArgumentException("Serialized ItemId in wrong format: " + (s ?? "NULL")); } string[] parts = s.Split(':'); var idStr = parts[0].Trim(); var typeStr = parts[1].Trim(); if (string.IsNullOrEmpty(idStr) || string.IsNullOrEmpty(typeStr)) { throw new ArgumentException("Serialized ItemId in wrong format: " + (s ?? "NULL")); } this.Id = idStr; this.Type = ContentTypeHierarchy.GetContentType(typeStr); }
/// <summary> /// Construct an ItemId by deserializing it from a string (created via .ToString()) /// </summary> /// <param name="s">Serialized ItemId</param> public ItemId(string s) { if (string.IsNullOrEmpty(s) || !s.Contains(":")) { return; } string[] parts = s.Split(':'); var idStr = parts[0].Trim(); var typeStr = parts[1].Trim(); if (string.IsNullOrEmpty(idStr) || string.IsNullOrEmpty(typeStr)) { return; } this.Id = idStr; this.Type = ContentTypeHierarchy.GetContentType(typeStr); }
public IActionResult Rename(string dataType, string path, bool pathInSummary, string newPath, bool newPathInSummary, bool?isDelete) { Type contentType = ContentTypeHierarchy.GetContentType(dataType); if (contentType == null) { return(Content("No such type, remember to add 'Content' where necessary")); } int propMissing = 0; int updated = 0; // create a new ContentRepository so we can bypass any block to writing caused by existing data problems // on the global data api var repo = new ContentRepository(new CoreDataSourceFactory(LyniconSystem.Instance)); repo.BypassChangeProblems = true; foreach (ContentItem ci in repo.Get <ContentItem>(contentType, new Type[] { contentType }, iq => iq)) { JObject jObjFrom; if (pathInSummary) { jObjFrom = JObject.Parse(ci.Summary ?? "{}"); } else { jObjFrom = JObject.Parse(ci.Content ?? "{}"); } JObject jObjTo = null; bool doDelete = isDelete ?? false; bool wasComputed = false; if (!doDelete) { if (newPathInSummary) { jObjTo = JObject.Parse(ci.Summary ?? "{}"); } else { jObjTo = JObject.Parse(ci.Content ?? "{}"); } jObjTo.CopyPropertyFrom(newPath, jObjFrom, path); JProperty prop = jObjTo.PropertyByPath(path); // try to deserialize in case its a computed property if (!pathInSummary && newPathInSummary && prop == null) { object content = jObjFrom.ToObject(contentType); object val = ReflectionX.GetPropertyValueByPath(content, path); if (val != null) { string pName = newPath.Contains(".") ? newPath.LastAfter(".") : newPath; jObjTo.AddAtPath(newPath, new JProperty(pName, val)); wasComputed = true; } } if (pathInSummary == newPathInSummary) { if (prop != null) { prop.Remove(); updated++; } else { propMissing++; } } } if (pathInSummary != newPathInSummary || doDelete) // we need to update both summary and content { // remove the old path JProperty prop = jObjFrom.PropertyByPath(path); if (prop != null) { prop.Remove(); updated++; if (pathInSummary) { ci.Summary = jObjFrom.ToString(); } else { ci.Content = jObjFrom.ToString(); } } else if (wasComputed) { updated++; } else { propMissing++; } } if (!doDelete) { if (newPathInSummary) { ci.Summary = jObjTo.ToString(); } else { ci.Content = jObjTo.ToString(); } } repo.Set(new List <object> { ci }, new Dictionary <string, object>()); } return(Content(string.Format("{0} updated {1} had property missing", updated, propMissing))); }
/// <summary> /// Constructs an address from a serialized string form (created via .ToString()) /// </summary> /// <param name="serialized">the serialized string</param> public Address(string serialized) : base(FromSerialized(serialized)) { this.Type = ContentTypeHierarchy.GetContentType(serialized.UpTo(":")); }