Skip to content

Commit

Permalink
Merge pull request #1203 from opencv/bs/sync_unsaved_changes
Browse files Browse the repository at this point in the history
Sync unsaved changes
  • Loading branch information
ActiveChooN authored Feb 26, 2020
2 parents 22b6821 + a5a62f0 commit c0b9bb8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
16 changes: 8 additions & 8 deletions cvat-core/src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@
return result;
},

async hasUnsavedChanges() {
const result = await PluginRegistry
.apiWrapper.call(this, prototype.annotations.hasUnsavedChanges);
return result;
},

async merge(objectStates) {
const result = await PluginRegistry
.apiWrapper.call(this, prototype.annotations.merge, objectStates);
Expand All @@ -107,6 +101,12 @@
.apiWrapper.call(this, prototype.annotations.exportDataset, format);
return result;
},

hasUnsavedChanges() {
const result = prototype.annotations
.hasUnsavedChanges.implementation.call(this);
return result;
},
},
writable: true,
}),
Expand Down Expand Up @@ -381,14 +381,14 @@
* @async
*/
/**
* Indicate if there are any changes in
* Method indicates if there are any changes in
* annotations which haven't been saved on a server
* </br><b> This function cannot be wrapped with a plugin </b>
* @method hasUnsavedChanges
* @memberof Session.annotations
* @returns {boolean}
* @throws {module:API.cvat.exceptions.PluginError}
* @instance
* @async
*/
/**
* Export as a dataset.
Expand Down
44 changes: 22 additions & 22 deletions cvat-core/tests/api/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ describe('Feature: save annotations', () => {
label: task.labels[0],
});

expect(await task.annotations.hasUnsavedChanges()).toBe(false);
expect(task.annotations.hasUnsavedChanges()).toBe(false);
await task.annotations.put([state]);
expect(await task.annotations.hasUnsavedChanges()).toBe(true);
expect(task.annotations.hasUnsavedChanges()).toBe(true);
await task.annotations.save();
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
expect(task.annotations.hasUnsavedChanges()).toBe(false);
annotations = await task.annotations.get(0);
expect(annotations).toHaveLength(length + 1);
});
Expand All @@ -311,23 +311,23 @@ describe('Feature: save annotations', () => {
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
const annotations = await task.annotations.get(0);

expect(await task.annotations.hasUnsavedChanges()).toBe(false);
expect(task.annotations.hasUnsavedChanges()).toBe(false);
annotations[0].occluded = true;
await annotations[0].save();
expect(await task.annotations.hasUnsavedChanges()).toBe(true);
expect(task.annotations.hasUnsavedChanges()).toBe(true);
await task.annotations.save();
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
expect(task.annotations.hasUnsavedChanges()).toBe(false);
});

test('delete & save annotations for a task', async () => {
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
const annotations = await task.annotations.get(0);

expect(await task.annotations.hasUnsavedChanges()).toBe(false);
expect(task.annotations.hasUnsavedChanges()).toBe(false);
await annotations[0].delete();
expect(await task.annotations.hasUnsavedChanges()).toBe(true);
expect(task.annotations.hasUnsavedChanges()).toBe(true);
await task.annotations.save();
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
expect(task.annotations.hasUnsavedChanges()).toBe(false);
});

test('create & save annotations for a job', async () => {
Expand All @@ -343,11 +343,11 @@ describe('Feature: save annotations', () => {
label: job.task.labels[0],
});

expect(await job.annotations.hasUnsavedChanges()).toBe(false);
expect(job.annotations.hasUnsavedChanges()).toBe(false);
await job.annotations.put([state]);
expect(await job.annotations.hasUnsavedChanges()).toBe(true);
expect(job.annotations.hasUnsavedChanges()).toBe(true);
await job.annotations.save();
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
expect(job.annotations.hasUnsavedChanges()).toBe(false);
annotations = await job.annotations.get(0);
expect(annotations).toHaveLength(length + 1);
});
Expand All @@ -356,23 +356,23 @@ describe('Feature: save annotations', () => {
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
const annotations = await job.annotations.get(0);

expect(await job.annotations.hasUnsavedChanges()).toBe(false);
expect(job.annotations.hasUnsavedChanges()).toBe(false);
annotations[0].points = [0, 100, 200, 300];
await annotations[0].save();
expect(await job.annotations.hasUnsavedChanges()).toBe(true);
expect(job.annotations.hasUnsavedChanges()).toBe(true);
await job.annotations.save();
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
expect(job.annotations.hasUnsavedChanges()).toBe(false);
});

test('delete & save annotations for a job', async () => {
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
const annotations = await job.annotations.get(0);

expect(await job.annotations.hasUnsavedChanges()).toBe(false);
expect(job.annotations.hasUnsavedChanges()).toBe(false);
await annotations[0].delete();
expect(await job.annotations.hasUnsavedChanges()).toBe(true);
expect(job.annotations.hasUnsavedChanges()).toBe(true);
await job.annotations.save();
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
expect(job.annotations.hasUnsavedChanges()).toBe(false);
});

test('delete & save annotations for a job when there are a track and a shape with the same id', async () => {
Expand Down Expand Up @@ -613,11 +613,11 @@ describe('Feature: clear annotations', () => {
expect(annotations.length).not.toBe(0);
annotations[0].occluded = true;
await annotations[0].save();
expect(await task.annotations.hasUnsavedChanges()).toBe(true);
expect(task.annotations.hasUnsavedChanges()).toBe(true);
await task.annotations.clear(true);
annotations = await task.annotations.get(0);
expect(annotations.length).not.toBe(0);
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
expect(task.annotations.hasUnsavedChanges()).toBe(false);
});

test('clear annotations with reload in a job', async () => {
Expand All @@ -626,11 +626,11 @@ describe('Feature: clear annotations', () => {
expect(annotations.length).not.toBe(0);
annotations[0].occluded = true;
await annotations[0].save();
expect(await job.annotations.hasUnsavedChanges()).toBe(true);
expect(job.annotations.hasUnsavedChanges()).toBe(true);
await job.annotations.clear(true);
annotations = await job.annotations.get(0);
expect(annotations.length).not.toBe(0);
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
expect(job.annotations.hasUnsavedChanges()).toBe(false);
});

test('clear annotations with bad reload parameter', async () => {
Expand Down

0 comments on commit c0b9bb8

Please sign in to comment.