public ActionResult Config(string pageName, string queryName, string queryId, [ModelBinder(typeof(BindingTypeAwareModelBinder))] object config) { var manager = new SavedTabQueryManager(); ITabQuery query = null; SavedTabQuery savedQuery = null; if (!String.IsNullOrEmpty(queryId)) { savedQuery = manager.Find(pageName, new Guid(queryId)); query = TabQueries.GetQuery(savedQuery.QueryName); } else { savedQuery = new SavedTabQuery(queryName); query = TabQueries.GetQuery(queryName); } savedQuery.DisplayName = Request.Form["DisplayName"]; if (query.ConfigType != null) { savedQuery.Config = config; } if (!String.IsNullOrEmpty(queryId)) { manager.Update(pageName, savedQuery); } else { manager.Add(pageName, savedQuery); } return(Json(savedQuery)); }
public ActionResult Config(string pageName, string queryId, string queryName) { var manager = new SavedTabQueryManager(); ITabQuery query = null; SavedTabQuery savedQuery = null; if (!String.IsNullOrEmpty(queryId)) { savedQuery = manager.Find(pageName, new Guid(queryId)); query = TabQueries.GetQuery(savedQuery.QueryName); if (savedQuery.Config == null && query.ConfigType != null) { savedQuery.Config = Activator.CreateInstance(query.ConfigType); } } else { query = TabQueries.GetQuery(queryName); savedQuery = new SavedTabQuery(queryName); if (query.ConfigType != null) { savedQuery.Config = Activator.CreateInstance(query.ConfigType); } } ViewBag.Query = query; return(PartialView(savedQuery)); }
public static SavedTabQuery CreateFrom(ITabQuery query, string displayName = null) { return(new SavedTabQuery(query.Name) { DisplayName = displayName, Config = query.ConfigType == null ? null : Activator.CreateInstance(query.ConfigType) }); }
public static SavedTabQuery CreateFrom(ITabQuery query, string displayName = null) { return new SavedTabQuery(query.Name) { DisplayName = displayName, Config = query.ConfigType == null ? null : Activator.CreateInstance(query.ConfigType) }; }
public IEnumerable<ITabResult> GetTabResults(IClient client, ITabQuery query) { IEnumerable<ITabResult> results = new Collection<ITabResult>(); if (client != null && client.Users != null) { results = results.Concat(this.GetLogResults(client, query)); results = results.Concat(this.GetVisibleUsersResults(client, query)); results = results.Concat(this.GetAllUsersResults(client, query)); } return results.Distinct(); }
public ITabResult GetTabResults(ITabQuery query) { IEnumerable<ITabResult> results = new Collection<ITabResult>(); foreach(ITabHandler handler in this.tabHandlers){ IEnumerable<ITabResult> handlerMatches = handler.GetTabResults(this.client, query); if (handlerMatches != null && handlerMatches.Count() > 0) { results = results.Concat(handlerMatches); } } return results.FirstOrDefault(); }
public static TabQueryModel CreateTabQueryModel(this CommerceController controller, string pageName, ITabQuery defaultQuery, string defaultQueryDisplayName = "All") { var manager = new SavedTabQueryManager(); var model = new TabQueryModel { PageName = pageName, SavedQueries = manager.FindAll(pageName).ToList(), AvailableQueries = TabQueries.GetQueries(controller.ControllerContext).ToList() }; // Ensure default if (model.SavedQueries.Count == 0) { var savedQuery = SavedTabQuery.CreateFrom(defaultQuery, "All"); manager.Add(model.PageName, savedQuery); model.SavedQueries.Add(savedQuery); } var queryId = controller.Request.QueryString["queryId"]; if (String.IsNullOrEmpty(queryId)) { model.CurrentQuery = model.SavedQueries.FirstOrDefault(); } else { model.CurrentQuery = manager.Find(model.PageName, new Guid(queryId)); } var query = model.AvailableQueries.Find(q => q.Name == model.CurrentQuery.QueryName); var search = controller.Request.QueryString["search"]; var page = 1; if (!String.IsNullOrEmpty(controller.Request.QueryString["page"])) { page = Convert.ToInt32(controller.Request.QueryString["page"]); } var pageSize = 50; if (!String.IsNullOrEmpty(controller.Request.QueryString["pageSize"])) { pageSize = Convert.ToInt32(controller.Request.QueryString["pageSize"]); } model.CurrentQueryResult = query.Execute(new QueryContext(controller.CurrentInstance, search, page - 1, pageSize, model.CurrentQuery.Config)) .ToPagedList(); return model; }
private IEnumerable<ITabResult> GetVisibleUsersResults(IClient client, ITabQuery query) { var nickname = query.Keyword.ToLowerInvariant(); return client.Users .Where(user => user.IsUserVisible && user.Nickname.ToLowerInvariant().StartsWith(nickname) && user.Nickname != user.Network.LocalUser.Nickname ) .Select(match => { var text = query.ReplaceKeyword(match.Nickname); return new TabResult { Text = text, Channel = match.Channels.FirstOrDefault(), //TODO change this to the last channel the user spoke in CursorIndex = query.GetCursorIndexAtEndOfKeyword(text) }; } ); }
public IEnumerable<ITabResult> GetTabResults(Models.IClient client, ITabQuery query) { string keyword = query.Keyword.ToLowerInvariant(); return client.Channels .Where(channel => channel.Name.ToLowerInvariant().StartsWith(keyword)) .Select(match => { var text = query.ReplaceKeyword(match.Name); return new TabResult { Text = text, SelectedText = !text.Contains(' ') ? new Range { LowerBound = 0, UpperBound = text.Length } : null, Channel = match, CursorIndex = query.GetCursorIndexAtEndOfKeyword(text), }; } ); }
public IEnumerable<ITabResult> GetTabResults(IClient client, ITabQuery query) { string firstWord = query.Text.Split(' ').First(); if (!string.IsNullOrWhiteSpace(firstWord) && firstWord.StartsWith("/") && firstWord.Count() > 1 && (firstWord.Count() >= query.CursorLocation)) { string commandText = firstWord.Substring(1).ToUpperInvariant(); IEnumerable<string> matchedCommands = this.availableCommands.Where(command => command.ToUpperInvariant().StartsWith(commandText)); return matchedCommands.Select(match => { var text = query.ReplaceKeyword(match.ToLowerInvariant()); return new TabResult { Text = text, CursorIndex = query.GetCursorIndexAtEndOfKeyword(text), }; } ); } return new Collection<ITabResult>(); }
private IEnumerable<ITabResult> GetLogResults(IClient client, ITabQuery query) { var nickname = query.Keyword.ToLowerInvariant(); return client.Log .Where(entry => entry.IsUserVisible && entry is IUserEvent) .Select(entry => entry as IUserEvent) .Where(entry => entry.Network.LocalUser.Nickname != entry.User.Nickname && entry.User.Nickname.ToLowerInvariant().StartsWith(nickname)) .OrderBy(match => match.ReceivedAt) .Select(match => { var text = query.ReplaceKeyword(match.User.Nickname); return new TabResult { Text = text, Channel = match.Source as IChannel, CursorIndex = query.GetCursorIndexAtEndOfKeyword(text) }; } ); }
public static TabQueryModel CreateTabQueryModel(this CommerceController controller, string pageName, ITabQuery defaultQuery, string defaultQueryDisplayName = "All") { var manager = new SavedTabQueryManager(); var model = new TabQueryModel { PageName = pageName, SavedQueries = manager.FindAll(pageName).ToList(), AvailableQueries = TabQueries.GetQueries(controller.ControllerContext).ToList() }; // Ensure default if (model.SavedQueries.Count == 0) { var savedQuery = SavedTabQuery.CreateFrom(defaultQuery, "All"); manager.Add(model.PageName, savedQuery); model.SavedQueries.Add(savedQuery); } var queryId = controller.Request.QueryString["queryId"]; if (String.IsNullOrEmpty(queryId)) { model.CurrentQuery = model.SavedQueries.FirstOrDefault(); } else { model.CurrentQuery = manager.Find(model.PageName, new Guid(queryId)); } var query = model.AvailableQueries.Find(q => q.Name == model.CurrentQuery.QueryName); var search = controller.Request.QueryString["search"]; var page = 1; if (!String.IsNullOrEmpty(controller.Request.QueryString["page"])) { page = Convert.ToInt32(controller.Request.QueryString["page"]); } var pageSize = 50; if (!String.IsNullOrEmpty(controller.Request.QueryString["pageSize"])) { pageSize = Convert.ToInt32(controller.Request.QueryString["pageSize"]); } model.CurrentQueryResult = query.Execute(new QueryContext(controller.CurrentInstance, search, page - 1, pageSize, model.CurrentQuery.Config)) .ToPagedList(); return(model); }