Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check only the uncollapsed resources at first on dataset view #1246

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Current (in progress)

- Nothing yet
- Check only the uncollapsed resources at first on dataset view [#1246](https://github.com/opendatateam/udata/pull/1246)

## 1.2.2 (2017-10-26)

Expand Down
8 changes: 8 additions & 0 deletions docs/adapting-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ Whether or not discussions should be enabled on posts

The default page size for post listing

## Datasets configuration

### DATASET_MAX_RESOURCES_UNCOLLAPSED

**default** `6`

Max number of resources to display uncollapsed in dataset view.


## Example configuration file

Expand Down
6 changes: 6 additions & 0 deletions js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ export const tiles_config = {subdomains: 'abcd', attribution: tiles_attributions
*/
export const tags = {MIN_LENGTH: 3, MAX_LENGTH: 32};

/**
* Max number of resources to display uncollapsed in dataset view
*/
export const dataset_max_resources_uncollapsed = _jsonMeta('dataset-max-resources-uncollapsed');


export default {
user,
Expand All @@ -181,4 +186,5 @@ export default {
tiles_attributions,
tiles_url,
tiles_config,
dataset_max_resources_uncollapsed,
};
18 changes: 16 additions & 2 deletions js/front/dataset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ new Vue({
new Velocity(e.target, {height: 0, opacity: 0}, {complete(els) {
els[0].remove();
}});
this.checkResourcesCollapsed();
},

/**
Expand Down Expand Up @@ -139,11 +140,24 @@ new Vue({
},

/**
* Asynchronously check all resources status
* Asynchronously check non-collapsed resources status
*/
checkResources() {
if (config.check_urls) {
this.dataset.resources.forEach(this.checkResource);
this.dataset.resources
.slice(0, config.dataset_max_resources_uncollapsed)
.forEach(this.checkResource);
}
},

/**
* Asynchronously check collapsed resources status
*/
checkResourcesCollapsed() {
if (config.check_urls) {
this.dataset.resources
.slice(config.dataset_max_resources_uncollapsed)
.forEach(this.checkResource);
}
},

Expand Down
5 changes: 5 additions & 0 deletions udata/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ class Defaults(object):
# Default pagination size on listing
POST_DEFAULT_PAGINATION = 20

# Dataset settings
###########################################################################
# Max number of resources to display uncollapsed in dataset view
DATASET_MAX_RESOURCES_UNCOLLAPSED = 6


class Testing(object):
'''Sane values for testing. Should be applied as override'''
Expand Down
3 changes: 1 addition & 2 deletions udata/templates/dataset/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ <h2>{{ dataset.title }}</h2>
<div class="list-group resources-list">
<h3>{{ _('Resources') }}</h3>

{# TODO: extract max_resources conf #}
{% set max_resources = 6 %}
{% set max_resources = config.DATASET_MAX_RESOURCES_UNCOLLAPSED %}
{% for resource in dataset.resources %}
{% if loop.index0 == max_resources %}
<div id="collapsed-resources" class="collapse">
Expand Down
2 changes: 1 addition & 1 deletion udata/templates/macros/metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<meta name="check-urls" content="{{ config.LINKCHECKING_ENABLED|tojson }}" />
<meta name="check-urls-cache-duration" content="{{ config.LINKCHECKING_CACHE_DURATION }}" />
<meta name="territory-enabled" content="{{ 'true' if config.ACTIVATE_TERRITORIES else 'false' }}">

<meta name="delete-me-enabled" content="{{ 'true' if config.DELETE_ME else 'false' }}">
<meta name="dataset-max-resources-uncollapsed" content="{{ config.DATASET_MAX_RESOURCES_UNCOLLAPSED }}">

{% if json_ld %}
<script id="json_ld" type="application/ld+json">{{ json_ld|safe }}</script>
Expand Down