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

Filter studies by group #75

Merged
merged 3 commits into from
Feb 26, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ Queries can use the ``AND`` and ``OR`` keywords to combine queries::

**omero.web.gallery.filter_keys:**
If this is configured then the gallery will allow filtering of Screens and
Projects by Key:Value pairs linked to them, or use ``Name`` to filter by Name.
Projects by Key:Value pairs linked to them, or use ``Name`` to filter by Name
or ``Group`` to filter by Group.
This list defines which Keys the user can choose in the UI.
On selecting a Key, the user will be able to filter by Values typed into
an auto-complete field.
Expand Down
4 changes: 3 additions & 1 deletion omero_gallery/static/gallery/categories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

// Copyright (C) 2019 University of Dundee & Open Microscopy Environment.
// Copyright (C) 2019-2020 University of Dundee & Open Microscopy Environment.
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -63,6 +63,8 @@ $("#maprQuery").keyup(function (event) {

if (configId === 'Name') {
matches = model.getStudiesNames(request.term);
} else if (configId === 'Group') {
matches = model.getStudiesGroups(request.term);
} else {
matches = model.getKeyValueAutoComplete(configId, request.term);
}
Expand Down
24 changes: 23 additions & 1 deletion omero_gallery/static/gallery/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d =

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

// Copyright (C) 2019 University of Dundee & Open Microscopy Environment.
// Copyright (C) 2019-2020 University of Dundee & Open Microscopy Environment.
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -69,6 +69,28 @@ StudiesModel.prototype.getStudiesNames = function getStudiesNames(filterQuery) {
return names;
};

StudiesModel.prototype.getStudiesGroups = function getStudiesGroups(filterQuery) {
var names = [];
this.studies.forEach(function (study) {
var groupName = study['omero:details'].group.Name;

if (names.indexOf(groupName) === -1) {
names.push(groupName);
}
});

if (filterQuery) {
names = names.filter(function (name) {
return name.toLowerCase().indexOf(filterQuery) > -1;
});
}

names.sort(function (a, b) {
return a.toLowerCase() > b.toLowerCase() ? 1 : -1;
});
return names;
};

StudiesModel.prototype.getStudyValue = function getStudyValue(study, key) {
if (!study.mapValues) return;

Expand Down
9 changes: 8 additions & 1 deletion omero_gallery/static/gallery/search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

// Copyright (C) 2019 University of Dundee & Open Microscopy Environment.
// Copyright (C) 2019-2020 University of Dundee & Open Microscopy Environment.
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -255,6 +255,8 @@ $("#maprQuery").keyup(function (event) {

if (configId === 'Name') {
matches = model.getStudiesNames(request.term);
} else if (configId === 'Group') {
matches = model.getStudiesGroups(request.term);
} else {
matches = model.getKeyValueAutoComplete(configId, request.term);
}
Expand Down Expand Up @@ -371,6 +373,11 @@ function filterAndRender() {

if (configId === 'Name') {
return study.Name.toLowerCase().indexOf(toMatch) > -1;
}

if (configId === 'Group') {
var group = study['omero:details'].group;
return group.Name.toLowerCase().indexOf(toMatch) > -1;
} // Filter by Map-Annotation Key-Value


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"images"
],
"author": "OME",
"license": "MIT",
"license": "AGPL-3.0",
"bugs": {
"url": "https://github.com/ome/omero-gallery/issues"
},
Expand Down
4 changes: 3 additions & 1 deletion src/categories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 University of Dundee & Open Microscopy Environment.
// Copyright (C) 2019-2020 University of Dundee & Open Microscopy Environment.
// All rights reserved.

// This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -70,6 +70,8 @@ $("#maprQuery")
let matches;
if (configId === 'Name') {
matches = model.getStudiesNames(request.term);
} else if (configId === 'Group') {
matches = model.getStudiesGroups(request.term);
} else {
matches = model.getKeyValueAutoComplete(configId, request.term);
}
Expand Down
17 changes: 16 additions & 1 deletion src/model.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 University of Dundee & Open Microscopy Environment.
// Copyright (C) 2019-2020 University of Dundee & Open Microscopy Environment.
// All rights reserved.

// This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -50,6 +50,21 @@ StudiesModel.prototype.getStudiesNames = function getStudiesNames(filterQuery) {
return names;
}

StudiesModel.prototype.getStudiesGroups = function getStudiesGroups(filterQuery) {
let names = [];
this.studies.forEach(study => {
var groupName = study['omero:details'].group.Name;
if (names.indexOf(groupName) === -1) {
names.push(groupName);
}
});
if (filterQuery) {
names = names.filter(name => name.toLowerCase().indexOf(filterQuery) > -1);
}
names.sort((a, b) => a.toLowerCase() > b.toLowerCase() ? 1 : -1);
return names;
}

StudiesModel.prototype.getStudyValue = function getStudyValue(study, key) {
if (!study.mapValues) return;
for (let i=0; i<study.mapValues.length; i++){
Expand Down
8 changes: 7 additions & 1 deletion src/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 University of Dundee & Open Microscopy Environment.
// Copyright (C) 2019-2020 University of Dundee & Open Microscopy Environment.
// All rights reserved.

// This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -256,6 +256,8 @@ $("#maprQuery")
let matches;
if (configId === 'Name') {
matches = model.getStudiesNames(request.term);
} else if (configId === 'Group') {
matches = model.getStudiesGroups(request.term);
} else {
matches = model.getKeyValueAutoComplete(configId, request.term);
}
Expand Down Expand Up @@ -366,6 +368,10 @@ function filterAndRender() {
if (configId === 'Name') {
return study.Name.toLowerCase().indexOf(toMatch) > -1;
}
if (configId === 'Group') {
var group = study['omero:details'].group;
return group.Name.toLowerCase().indexOf(toMatch) > -1;
}
// Filter by Map-Annotation Key-Value
let show = false;
if (study.mapValues) {
Expand Down