Exemplo n.º 1
0
        /// <summary>
        ///   The core of the whole system, this method returns the viewModel consumed by the admin panel
        ///   javascript interface
        /// </summary>
        /// <returns></returns>
        public AdminPanelViewModel AdminPanel(string pageId)
        {
            var page = Page.Load(pageId);

            var viewModel = new AdminPanelViewModel(page.ToViewModel());
            viewModel.Pages = Folder.RootFolder.ToViewModel();
            viewModel.Widgets = Plugin.All().ToViewModel();

            var templates = Template.All();
            viewModel.Templates = templates.ToViewModel();
            viewModel.TemplateList = templates.ToDictionary(k => k.Id, v => v.Name).ToList();

            var mediaFolder = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/Media/"));
            if (!mediaFolder.Exists)
                mediaFolder.Create();

            viewModel.MediaFolders = mediaFolder.ToViewModel();

            // scripts for the eyepatch admin window
            var scripts = AdminPanelViewModel.DependentJs;
            // scripts for any plugins in the UI
            scripts.AddRange(Plugin.UserInterfaceJs());
            // scripts for the widgets on the page
            scripts.AddRange(Page.AdminJs(page.Id));
            // css for the eyepatch admin widnow
            var css = AdminPanelViewModel.DependentCss;
            // css for any plugins in the UI
            css.AddRange(Plugin.UserInterfaceCss());
            // css for the widgets on the page
            css.AddRange(Page.AdminCss(page.Id));

            viewModel.Scripts =
                Resources.GetResourcePaths(scripts.Except(Page.Js(page.Id)).ToResourceCollection()).ToList();
            viewModel.Css = Resources.GetResourcePaths(css.Except(Page.Css(page.Id)).ToResourceCollection()).ToList();

            // inspect widgets for their own windows and add to viewmodel
            viewModel.Windows.AddRange(Plugin.UserInterfaceWindows());

            return viewModel;
        }