Example #1
0
		public override object GetData(ITabContext context)
		{
			var request = context.GetRequestContext<HttpContextBase>();
			var mobile = request.Request["n0"] == null ? request.GetOverriddenBrowser().IsMobileDevice :
				request.Request["n0"].StartsWith("Mobile", StringComparison.Ordinal);
			var stateDisplayInfo = new StateDisplayInfo();
			if (StateContext.State != null)
			{
				stateDisplayInfo.Page = GetCurrentPage(context, mobile);
				stateDisplayInfo.Route = GetCurrentRoute(mobile);
				stateDisplayInfo.Theme = GetCurrentTheme(context, mobile);
				stateDisplayInfo.Masters = GetCurrentMasters(context, mobile);
			}
			return Canvas.Arrange(stateDisplayInfo, GetNavigationLinks(context));
		}
Example #2
0
		internal static CanvasData Arrange(StateDisplayInfo stateDisplayInfo, Dictionary<string, List<NavigationLinkModel>> links)
		{
			var transitionModels = new List<TransitionModel>();
			var stateModels = new List<StateModel>();
			var stateX = Left;
			var stateY = Top;
			var crumbs = StateController.Crumbs.Select((c, i) => new { Crumb = c, Index = i })
				.ToDictionary(c => c.Crumb.State, c => new { Crumb = c.Crumb, c.Index });
			foreach (Dialog dialog in StateInfoConfig.Dialogs)
			{
				stateX = Left;
				var depths = CalculateDepths(dialog, transitionModels);
				foreach (State state in dialog.States)
				{
					var stateModel = new StateModel(state);
					stateModels.Add(stateModel);
					stateModel.X = stateX;
					stateModel.Y = stateY;
					stateModel.H = StateHeight;
					stateModel.Page = state.Page;
					stateModel.Controller = state.Attributes["controller"];
					stateModel.ApiController = state.Attributes["apiController"];
					stateModel.Action = state.Attributes["action"];
					stateModel.Route = state.Route;
					stateModel.Theme = state.Theme;
					stateModel.Masters = state.Masters.ToList();
					if (links.ContainsKey(state.Id))
						stateModel.NavigationLinks = links[state.Id];
					if (state == StateContext.State)
					{
						stateModel.Current = state == StateContext.State;
						stateModel.Data = StateContext.Data;
						stateModel.Page = stateDisplayInfo.Page;
						stateModel.Route = stateDisplayInfo.Route;
						stateModel.Theme = stateDisplayInfo.Theme;
						stateModel.Masters = stateDisplayInfo.Masters;
					}
					stateModel.Previous = state == StateContext.PreviousState;
					stateModel.Back = 0;
					if (crumbs.ContainsKey(state))
					{
						stateModel.Back = crumbs.Count - crumbs[state].Index;
						stateModel.Data = crumbs[state].Crumb.Data;
					}
					if (stateModel.Data == null)
					{
						stateModel.Data = new NavigationData();
						foreach (string key in stateModel.State.Defaults.Keys)
							stateModel.Data[key] = stateModel.State.Defaults[key];
					}
					stateModel.W = ProcessTransitions(stateModel, transitionModels);
					stateX += stateModel.W + StateSeparation;
				}
				stateY += Top + StateHeight + depths.Count * TransitionStepHeight + FontSize;
			}
			var selected = stateModels.FirstOrDefault(s => s.Current) ?? new StateModel(new State());
			var selectedDialogTrans = transitionModels.Where(t => t.Transition.Parent.Parent == selected.State.Parent).DefaultIfEmpty();
			var lastState = stateModels.Last();
			return new CanvasData
			{
				States = stateModels,
				Transitions = transitionModels,
				X = Math.Min(0, Width - Math.Min(selected.X + selected.W + Left, selected.X + Width - Left)),
				Y = Math.Min(0, Height - Math.Min(Math.Max(selected.Y + selected.H, selectedDialogTrans.Max(t => t != null ? t.Y + t.H : 0)) + PaddingY + FontSize, selected.Y + Height - Top)),
				W = Math.Max(Width, stateModels.Max(s => s.X + s.W) + Left),
				H = Math.Max(Height, Math.Max(lastState.Y + lastState.H, transitionModels.DefaultIfEmpty().Max(t => t != null ? t.Y + t.H : 0)) + PaddingY + FontSize)
			};
		}