コード例 #1
0
        /// <summary>
        /// Provides a view of features packages that have recently bee updated in the repository group.
        /// Return the three most recently updated packages in the group.
        /// </summary>
        public ActionResult BrowsePackages()
        {
            log.DebugFormat("Controller action requested");

            var searchParameters = new PackageSearchParameters();

            searchParameters.Groups.Add(SettingsHelper.GetCatalogGroup());

            // Set up the pagination
            Pager pager = new Pager(1, SettingsHelper.GetSearchResultsPerPage());

            searchParameters.Offset = pager.RecordOffset;
            searchParameters.Limit  = pager.RecordsPerPage;

            PackageSearchResultsModel model = new PackageSearchResultsModel();

            model.SearchParameters = searchParameters;
            model.SearchResults    = CkanHelper.GetClient().SearchPackages <Package>(searchParameters, new CacheSettings(SettingsHelper.GetSearchResultsCacheDuration()));
            SettingsHelper.FilterTitles(model.SearchResults.Results);
            model.Pager = pager;

            // Set the number of records to be paged
            pager.RecordCount = model.SearchResults.Count;

            // Render the view
            return(View(model));
        }
コード例 #2
0
        public static List <SiteMapUrl> GetSiteMapUrls(ControllerContext context)
        {
            var urlSet = new List <SiteMapUrl>();

            // Populate the URL set
            var packages = CkanHelper.GetAllPackages();

            // Get the base url
            UrlHelper helper = new UrlHelper(context.RequestContext);

            var request = context.RequestContext.HttpContext.Request;

            // TODO: Allow this to overridden in settings to support a reverse proxy
            var baseUrl = SettingsHelper.GetSeoSiteMapBaseUrl();

            if (String.IsNullOrEmpty(baseUrl))
            {
                baseUrl = request.Url.GetLeftPart(UriPartial.Authority) + request.ApplicationPath;
            }
            var baseUri = new Uri(baseUrl);

            AddHomepageToSiteMap(urlSet, packages, baseUri);

            AddPackagesToSiteMap(urlSet, packages, helper, baseUri);

            return(urlSet);
        }
コード例 #3
0
        /// <summary>
        /// Provides a view of the top 10 tags in the repository group
        /// </summary>
        public ActionResult PopularTags()
        {
            log.DebugFormat("Controller action requested");

            // Get the tag limit
            int tagLimit = SettingsHelper.GetHomePopularTagsLimit();

            // Collect the results
            List <Tag> tags = CkanHelper.GetAllTags(tagLimit);

            // Compute the tag scale
            tags = TagHelper.ComputeTagScale(tags);

            // Render the view
            return(View(tags));
        }
コード例 #4
0
        public ActionResult Clear(string token, string id)
        {
            CheckToken(token);

            CkanClient client = CkanHelper.GetClient();

            if (String.IsNullOrEmpty(id))
            {
                client.ClearCache();
            }
            else
            {
                client.ClearCache(id);
            }

            return(RedirectToAction("Index", new { token = token }));
        }
コード例 #5
0
        public ActionResult Index(string package)
        {
            log.DebugFormat("Controller action requested for package {0}", package);

            Package packageFound = CkanHelper.GetClient().GetPackage(package, new CacheSettings(SettingsHelper.GetPackageCacheDuration()));

            SettingsHelper.FilterTitle(packageFound);
            TagHelper.FilterTags(packageFound.Tags);

            if (package != null)
            {
                this.ConfigureBreadCrumbs(packageFound);
                this.ConfigureMetaTags(packageFound);
            }

            return(View(packageFound));
        }
コード例 #6
0
        /// <summary>
        /// Provides a view of features packages in the repository group.  Featured
        /// packages are those that are tagged with "featured".
        /// </summary>
        public ActionResult FeaturedPackages()
        {
            log.DebugFormat("Controller action requested");

            // Create the CKAN search parameters
            var searchParameters = new PackageSearchParameters();

            searchParameters.Groups.Add(SettingsHelper.GetCatalogGroup());
            searchParameters.Limit = SettingsHelper.GetHomeFeaturedPackageLimit();
            searchParameters.Tags.Add(SettingsHelper.GetHomeFeaturedPackagesTag());

            // Collect the results
            PackageSearchResponse <Package> results = CkanHelper.GetClient().SearchPackages <Package>(searchParameters, new CacheSettings(SettingsHelper.GetFeaturedPackagesCacheDuration()));

            SettingsHelper.FilterTitles(results.Results);

            // Render the view
            return(View(results));
        }
コード例 #7
0
        //
        // GET: /Cache/
        public ActionResult Index(string token)
        {
            CheckToken(token);

            CkanClient client      = CkanHelper.GetClient();
            var        cachedItems = client.GetCachedRequests();

            // Set up the breadcrumbs for this action
            var breadCrumbs = new BreadCrumbs();

            breadCrumbs.Add(new BreadCrumb(SettingsHelper.GetCatalogBreadcrumbsBaseLabel(), "Index", "Home"));
            breadCrumbs.Add(new BreadCrumb("Admin"));
            breadCrumbs.Add(new BreadCrumb("Cache"));
            ViewData["BreadCrumbs"] = breadCrumbs;

            // Disable analytics on admin pages
            ViewData["DisableAnalytics"] = true;

            return(View(cachedItems));
        }
コード例 #8
0
        /// <summary>
        /// Provides a view of features packages that have recently bee updated in the repository group.
        /// Return the three most recently updated packages in the group.
        /// </summary>
        public ActionResult RecentlyUpdated()
        {
            log.DebugFormat("Controller action requested");

            // Create the CKAN search parameters
            var searchParameters = new PackageSearchParameters();

            searchParameters.Groups.Add(SettingsHelper.GetCatalogGroup());

            // Collect the results
            List <Package> packages = CkanHelper.GetAllPackages();

            // Sort by date and take the top 3
            packages = (from package in packages
                        orderby package.MetadataModified
                        descending
                        select package)
                       .Take(3)
                       .ToList();

            SettingsHelper.FilterTitles(packages);

            // Update the results to the top 3
            PackageSearchResponse <Package> response = new PackageSearchResponse <Package>();

            response.Results = packages;
            response.Count   = packages.Count;

            // Populate the model
            PackageSearchResultsModel model = new PackageSearchResultsModel();

            model.SearchResults = response;

            // Render the view
            return(View(model));
        }
コード例 #9
0
        //
        // GET: /Suggestion/

        public JsonResult Index(string prefix)
        {
            List <string> results = CkanHelper.GetPackageSearchSuggestions(prefix);

            return(Json(results, "text/json", JsonRequestBehavior.AllowGet));
        }
コード例 #10
0
        public ActionResult Index(string q, int?page, string order_by, string tag, string mode)
        {
            log.DebugFormat("Controller action requested");

            this.ConfigureBreadCrumbs(q, tag);

            // Create the CKAN search parameters
            var searchParameters = new PackageSearchParameters();

            searchParameters.AggregateTagCounts = true;
            searchParameters.Query = q;
            searchParameters.Groups.Add(SettingsHelper.GetCatalogGroup());

            // Ordering
            if (!String.IsNullOrEmpty(order_by))
            {
                searchParameters.OrderBy = order_by;
            }

            // Tag
            if (!String.IsNullOrEmpty(tag))
            {
                searchParameters.Tags.Add(tag);
            }

            // Build the view model for the results
            PackageSearchResultsModel model = new PackageSearchResultsModel();
            Pager pager = null;

            if (mode == "table")
            {
                model.DisplayMode       = ResultsDisplayMode.Table;
                searchParameters.Offset = 0;
                // TODO: In the table mode all results are currently returned and paginated client side.
                // This isn't scalable so this will need looked at in the future (AJAX pagination maybe?)
                searchParameters.Limit = CkanHelper.GetPackageCount();
            }
            else // mode == list (default)
            {
                // Set up the pagination
                int pageNumber = 1;
                if (page != null)
                {
                    pageNumber = (int)page;
                }

                pager = new Pager(pageNumber, SettingsHelper.GetSearchResultsPerPage());

                searchParameters.Offset = pager.RecordOffset;
                searchParameters.Limit  = pager.RecordsPerPage;
            }

            // Execute the search
            model.SearchParameters = searchParameters;
            model.SearchResults    = CkanHelper.GetClient().SearchPackages <Package>(searchParameters, new CacheSettings(SettingsHelper.GetSearchResultsCacheDuration()));

            // Filter the titles
            SettingsHelper.FilterTitles(model.SearchResults.Results);

            // Filter the tags
            model.SearchResults.Tags = TagHelper.FilterTags(model.SearchResults.Tags);

            // Set the pager if we are using it
            if (pager != null)
            {
                // Set the number of records to be paged
                pager.RecordCount = model.SearchResults.Count;

                // Add the pager to the model
                model.Pager = pager;
            }

            // Render the view
            return(View(model));
        }
コード例 #11
0
 /// <summary>
 /// Provides a view of the top 10 tags in the repository group
 /// </summary>
 public ActionResult PackageCount()
 {
     return(Content(CkanHelper.GetPackageCount().ToString()));
 }