Skip to content

Commit

Permalink
Support distinctImages parameter when fetching last opened images
Browse files Browse the repository at this point in the history
  • Loading branch information
eburtin committed Nov 30, 2018
1 parent 4eda579 commit 0819142
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
19 changes: 11 additions & 8 deletions src/collections/image-instance-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ export default class ImageInstanceCollection extends Collection {
/**
* @static Fetch last opened image instances
*
* @param {number} [project] Identifier of project to consider (/!\ requires user parameter to be set)
* @param {number} [user] Identifier of user to consider (/!\ requires project parameter to be set)
* @param {number} [max=0] The maximum number of items to retrieve
* @param {number} [offset=0] The offset
* @param {number} [project] Identifier of project to consider (/!\ requires user parameter to be set)
* @param {number} [user] Identifier of user to consider (/!\ requires project parameter to be set)
* @param {boolean} [distinctImages] If true, the result will include distinct images
* @param {number} [max=0] The maximum number of items to retrieve
* @param {number} [offset=0] The offset
*
* @returns {Array<{id: Number, date: String, thumb: String, instanceFilename: String, project: Number}>}
* The last opened images
* @returns {Array<{id: Number, date: String, thumb: String, instanceFilename: String, project: Number}>
* | Array<{created: String, user: Number, image: Number, time: Number, imageThumb: String,
* imageName: String, countCreatedAnnotations: Number, project: Number}>}
* The last opened images (second format used iff project and user are specified)
*/
static async fetchLastOpened({project, user, max=0, offset=0}={}) {
static async fetchLastOpened({project, user, distinctImages=true, max=0, offset=0}={}) {
let uri = project != null ? `project/${project}/user/${user}/imageconsultation.json`
: "imageinstance/method/lastopened.json";
let {data} = await Cytomine.instance.api.get(`${uri}?max=${max}&offset=${offset}`);
let {data} = await Cytomine.instance.api.get(`${uri}?max=${max}&offset=${offset}&distinctImages=${distinctImages}`);
return data.collection;
}

Expand Down
23 changes: 19 additions & 4 deletions tests/test-image-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ describe("ImageInstance", function() {
let imageInstance = null;
let id = 0;

let idUser;

before(async function() {
await utils.connect();

let currentUser = await User.fetchCurrent();
idUser = currentUser.id;

({id: baseImage} = await utils.getAbstractImage());
let projectInstance = await utils.getProject();
project = projectInstance.id;
Expand Down Expand Up @@ -75,7 +81,6 @@ describe("ImageInstance", function() {

describe("Specific operations", function() {
let imageSource;
let idUser;

let dataDescription = utils.randomString();

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

before(async function() {
let currentUser = await User.fetchCurrent();
idUser = currentUser.id;

imageSource = await utils.getImageInstance({baseImage});

await new Description({data: dataDescription}, imageSource).save();
Expand Down Expand Up @@ -236,6 +238,19 @@ describe("ImageInstance", function() {
});
});

it("Fetch last opened in project", async function() {
let collection = await ImageInstanceCollection.fetchLastOpened({
project: project,
user: idUser,
max: nbImageInstances
});
expect(collection).to.have.lengthOf(nbImageInstances);
let listId = collection.map(item => item.image);
imageInstances.forEach(image => {
expect(listId).to.include(image.id);
});
});

it("Fetch light version", async function() {
let collection = await ImageInstanceCollection.fetchAllLight();
expect(collection).to.have.lengthOf.at.least(nbImageInstances);
Expand Down

0 comments on commit 0819142

Please sign in to comment.