Beispiel #1
0
        private LocalizationResourceViewModel PrepareViewModel(bool showMenu)
        {
            var availableLanguagesQuery = new AvailableLanguages.Query();
            var languages    = availableLanguagesQuery.Execute();
            var allResources = GetAllResources();

            var user    = HttpContext.User;
            var isAdmin = user.Identity.IsAuthenticated && UiConfigurationContext.Current.AuthorizedAdminRoles.Any(r => user.IsInRole(r));

            var isTreeView = Request.Cookies[_viewCcookieName]?.Value == "tree";

            var result = new LocalizationResourceViewModel(allResources, languages, GetSelectedLanguages())
            {
                ShowMenu   = showMenu,
                AdminMode  = isAdmin,
                IsTreeView = isTreeView
            };

            // build tree
            var builder = new ResourceTreeBuilder();
            var sorter  = new ResourceTreeSorter();

            result.Tree = sorter.Sort(builder.BuildTree(allResources));

            return(result);
        }
        private LocalizationResourceViewModel PrepareViewModel(bool showMenu)
        {
            var availableLanguagesQuery = new AvailableLanguages.Query {
                IncludeInvariant = _showInvariantCulture
            };
            var languages    = availableLanguagesQuery.Execute();
            var allResources = GetAllResources();

            var user    = HttpContext.User;
            var isAdmin = user.Identity.IsAuthenticated &&
                          UiConfigurationContext.Current.AuthorizedAdminRoles.Any(r => user.IsInRole(r));

            // cookies override default view from config
            var isTreeView = UiConfigurationContext.Current.DefaultView == ResourceListView.Tree;

            if (Request.Cookies[_viewCookieName] != null)
            {
                isTreeView = UiConfigurationContext.Current.IsTableViewDisabled ||
                             Request.Cookies[_viewCookieName]?.Value == "tree";
            }

            var result = new LocalizationResourceViewModel(allResources, languages, GetSelectedLanguages(), _maxLength)
            {
                ShowMenu           = showMenu,
                AdminMode          = isAdmin,
                IsTreeView         = isTreeView,
                IsTreeViewEnabled  = !UiConfigurationContext.Current.IsTreeViewDisabled,
                IsTableViewEnabled = !UiConfigurationContext.Current.IsTableViewDisabled,
                IsRemoveTranslationButtonDisabled = UiConfigurationContext.Current.DisableRemoveTranslationButton,
                IsDeleteButtonVisible             = !UiConfigurationContext.Current.HideDeleteButton
            };

            // build tree
            var builder = new ResourceTreeBuilder();
            var sorter  = new ResourceTreeSorter();

            result.Tree = sorter.Sort(builder.BuildTree(allResources, ConfigurationContext.Current.EnableLegacyMode()));

            return(result);
        }