Skip to content

Commit

Permalink
Fix project sidebar filter and drop some extraneous code
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiascarf committed Jun 14, 2024
1 parent 41aa498 commit d546aaf
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 144 deletions.
27 changes: 0 additions & 27 deletions _layouts/organization.html

This file was deleted.

27 changes: 0 additions & 27 deletions _layouts/sources.html

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/dist/bundle.js

Large diffs are not rendered by default.

68 changes: 0 additions & 68 deletions scripts/src/components/datasets-list.js

This file was deleted.

6 changes: 3 additions & 3 deletions scripts/src/components/rdl-datasets-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Usage:
* <div data-component="datasets-list">
* <div data-component="rdl-datasets-list">
* <h3 class="datasets-count" data-hook="datasets-count"></h3>
* <input type="text" data-hook="search-query" placeholder="Search..." class="form-control">
* <div data-hook="datasets-items"></div>
Expand Down Expand Up @@ -30,8 +30,8 @@ export default class {
}

// Filter datasets and render in items container
const paramFilters = pick(opts.params, ['category', 'geo_coverage', 'geo_scale', 'license_display'])
const attributeFilters = pick(opts.el.data(), ['category', 'geo_coverage', 'geo_scale', 'license_display'])
const paramFilters = pick(opts.params, ['category', 'geo_coverage', 'geo_scale', 'license_display','project'])
const attributeFilters = pick(opts.el.data(), ['category', 'geo_coverage', 'geo_scale', 'license_display','project'])
const filters = createDatasetFilters(defaults(paramFilters, attributeFilters))

const filteredDatasets = filter(opts.datasets, filters)
Expand Down
17 changes: 2 additions & 15 deletions scripts/src/components/rdl-project-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,8 @@ function prep_project(project, params, datasetsForProject) {
export default class {
constructor (opts) {
const projects = this._projectsWithCount(opts.datasets, opts.params)
var consolidated = []
projects.forEach(function(l) {
const idx = consolidated.findIndex(x => x.title === l.title)
if (idx == -1) {
consolidated.push(l)
} else {
consolidated[idx].count += l.count
consolidated[idx].unfilteredCount += l.unfilteredCount
}
})

const projectsMarkup = consolidated.sort((a,b) => {
const projectsMarkup = projects.sort((a,b) => {
// ignore upper and lowercase
const titleA = a.title.toUpperCase();
const titleB = b.title.toUpperCase();
Expand All @@ -48,10 +38,7 @@ export default class {
return chain(datasets)
.groupBy('project')
.flatMap(function (datasetsForProject, project) {
var projects = project.split(",")
var collated = projects.map(c => prep_project(c, params, datasetsForProject))

return collated
return prep_project(project, params, datasetsForProject)
})
.orderBy('unfilteredCount', 'desc')
.value()
Expand Down
4 changes: 1 addition & 3 deletions scripts/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import {omit} from 'lodash'

import UserModel from './models/user'
import Navigation from './components/navigation'
import DatasetsList from './components/datasets-list'
import RDLDatasetsList from './components/rdl-datasets-list'
import CategoriesFilter from './components/categories-filter'
import RDLCountryFilter from './components/rdl-country-filter'
import RDLLicenseFilter from './components/rdl-license-filter'
import RDLProjectFilter from './components/rdl-project-filter'
import RDLGeographicalScaleFilter from './components/rdl-geographical-scale-filter'
import DatasetDisplay from './components/dataset-display'
import RDLDatasetDisplay from './components/rdl-datasets-display'
import ViewSwitcher from './components/view-switcher'
import ThemeGallery from './components/theme-gallery'
import {queryByComponent, setParams} from './util'
import RDLProjectFilter from './components/rdl-project-filter'

const params = $.deparam(window.location.search.substr(1))

Expand All @@ -42,7 +41,6 @@ const components = [
{tag: 'rdl-dataset-display', class: RDLDatasetDisplay},
{tag: 'view-switcher', class: ViewSwitcher},
{tag: 'theme-gallery', class: ThemeGallery},
{tag: 'datasets-list', class: DatasetsList, usesDatasets: true},
{tag: 'rdl-datasets-list', class: RDLDatasetsList, usesDatasets: true},
{tag: 'categories-filter', class: CategoriesFilter, usesDatasets: true},
{tag: 'rdl-country-filter', class: RDLCountryFilter, usesDatasets: true},
Expand Down
3 changes: 3 additions & 0 deletions scripts/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export function createDatasetFilters (filters) {
if (filters.license_display) {
conditions.push(dataset.license_display && slugify(dataset.license_display).indexOf(filters.license_display) !== -1)
}
if (filters.project) {
conditions.push(dataset.project && slugify(dataset.project).indexOf(filters.project) !== -1)
}

return conditions.every(function (value) { return !! value })
}
Expand Down

0 comments on commit d546aaf

Please sign in to comment.