Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 0819142

Browse files
author
eburtin
committed
Support distinctImages parameter when fetching last opened images
1 parent 4eda579 commit 0819142

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/collections/image-instance-collection.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,21 @@ export default class ImageInstanceCollection extends Collection {
2222
/**
2323
* @static Fetch last opened image instances
2424
*
25-
* @param {number} [project] Identifier of project to consider (/!\ requires user parameter to be set)
26-
* @param {number} [user] Identifier of user to consider (/!\ requires project parameter to be set)
27-
* @param {number} [max=0] The maximum number of items to retrieve
28-
* @param {number} [offset=0] The offset
25+
* @param {number} [project] Identifier of project to consider (/!\ requires user parameter to be set)
26+
* @param {number} [user] Identifier of user to consider (/!\ requires project parameter to be set)
27+
* @param {boolean} [distinctImages] If true, the result will include distinct images
28+
* @param {number} [max=0] The maximum number of items to retrieve
29+
* @param {number} [offset=0] The offset
2930
*
30-
* @returns {Array<{id: Number, date: String, thumb: String, instanceFilename: String, project: Number}>}
31-
* The last opened images
31+
* @returns {Array<{id: Number, date: String, thumb: String, instanceFilename: String, project: Number}>
32+
* | Array<{created: String, user: Number, image: Number, time: Number, imageThumb: String,
33+
* imageName: String, countCreatedAnnotations: Number, project: Number}>}
34+
* The last opened images (second format used iff project and user are specified)
3235
*/
33-
static async fetchLastOpened({project, user, max=0, offset=0}={}) {
36+
static async fetchLastOpened({project, user, distinctImages=true, max=0, offset=0}={}) {
3437
let uri = project != null ? `project/${project}/user/${user}/imageconsultation.json`
3538
: "imageinstance/method/lastopened.json";
36-
let {data} = await Cytomine.instance.api.get(`${uri}?max=${max}&offset=${offset}`);
39+
let {data} = await Cytomine.instance.api.get(`${uri}?max=${max}&offset=${offset}&distinctImages=${distinctImages}`);
3740
return data.collection;
3841
}
3942

tests/test-image-instance.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ describe("ImageInstance", function() {
1010
let imageInstance = null;
1111
let id = 0;
1212

13+
let idUser;
14+
1315
before(async function() {
1416
await utils.connect();
17+
18+
let currentUser = await User.fetchCurrent();
19+
idUser = currentUser.id;
20+
1521
({id: baseImage} = await utils.getAbstractImage());
1622
let projectInstance = await utils.getProject();
1723
project = projectInstance.id;
@@ -75,7 +81,6 @@ describe("ImageInstance", function() {
7581

7682
describe("Specific operations", function() {
7783
let imageSource;
78-
let idUser;
7984

8085
let dataDescription = utils.randomString();
8186

@@ -87,9 +92,6 @@ describe("ImageInstance", function() {
8792
let location = "POLYGON((10 10, 20 10, 20 20, 10 20, 10 10), (16 16, 18 16, 18 18, 16 18, 16 16))";
8893

8994
before(async function() {
90-
let currentUser = await User.fetchCurrent();
91-
idUser = currentUser.id;
92-
9395
imageSource = await utils.getImageInstance({baseImage});
9496

9597
await new Description({data: dataDescription}, imageSource).save();
@@ -236,6 +238,19 @@ describe("ImageInstance", function() {
236238
});
237239
});
238240

241+
it("Fetch last opened in project", async function() {
242+
let collection = await ImageInstanceCollection.fetchLastOpened({
243+
project: project,
244+
user: idUser,
245+
max: nbImageInstances
246+
});
247+
expect(collection).to.have.lengthOf(nbImageInstances);
248+
let listId = collection.map(item => item.image);
249+
imageInstances.forEach(image => {
250+
expect(listId).to.include(image.id);
251+
});
252+
});
253+
239254
it("Fetch light version", async function() {
240255
let collection = await ImageInstanceCollection.fetchAllLight();
241256
expect(collection).to.have.lengthOf.at.least(nbImageInstances);

0 commit comments

Comments
 (0)