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

Partly update fields with PATCH requests #2445

Merged
merged 4 commits into from
Nov 19, 2020
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

-
- PATCH requests from cvat-core submit only changed fields (<https://github.com/openvinotoolkit/cvat/pull/2445>)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion cvat-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-core",
"version": "3.9.0",
"version": "3.9.1",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "babel.config.js",
"scripts": {
Expand Down
92 changes: 82 additions & 10 deletions cvat-core/src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,11 @@
task: undefined,
};

let updatedFields = {
assignee: false,
status: false,
};

for (const property in data) {
if (Object.prototype.hasOwnProperty.call(data, property)) {
if (property in initialData) {
Expand Down Expand Up @@ -715,6 +720,7 @@
if (assignee !== null && !(assignee instanceof User)) {
throw new ArgumentError('Value must be a user instance');
}
updatedFields.assignee = true;
data.assignee = assignee;
},
},
Expand Down Expand Up @@ -743,6 +749,7 @@
);
}

updatedFields.status = true;
data.status = status;
},
},
Expand Down Expand Up @@ -776,6 +783,12 @@
task: {
get: () => data.task,
},
__updatedFields: {
get: () => updatedFields,
set: (fields) => {
updatedFields = fields;
},
},
}),
);

Expand Down Expand Up @@ -879,6 +892,13 @@
use_cache: undefined,
};

let updatedFields = {
name: false,
assignee: false,
bug_tracker: false,
labels: false,
};

for (const property in data) {
if (Object.prototype.hasOwnProperty.call(data, property) && property in initialData) {
data[property] = initialData[property];
Expand Down Expand Up @@ -948,6 +968,7 @@
if (!value.trim().length) {
throw new ArgumentError('Value must not be empty');
}
updatedFields.name = true;
data.name = value;
},
},
Expand Down Expand Up @@ -1006,6 +1027,7 @@
if (assignee !== null && !(assignee instanceof User)) {
throw new ArgumentError('Value must be a user instance');
}
updatedFields.assignee = true;
data.assignee = assignee;
},
},
Expand Down Expand Up @@ -1039,6 +1061,7 @@
bugTracker: {
get: () => data.bug_tracker,
set: (tracker) => {
updatedFields.bug_tracker = true;
data.bug_tracker = tracker;
},
},
Expand Down Expand Up @@ -1145,6 +1168,7 @@
}
}

updatedFields.labels = true;
data.labels = [...labels];
},
},
Expand Down Expand Up @@ -1311,6 +1335,12 @@
dataChunkType: {
get: () => data.data_compressed_chunk_type,
},
__updatedFields: {
get: () => updatedFields,
set: (fields) => {
updatedFields = fields;
},
},
}),
);

Expand Down Expand Up @@ -1443,12 +1473,30 @@
Job.prototype.save.implementation = async function () {
// TODO: Add ability to change an assignee
if (this.id) {
const jobData = {
status: this.status,
assignee_id: this.assignee ? this.assignee.id : null,
};
const jobData = {};

for (const [field, isUpdated] of Object.entries(this.__updatedFields)) {
if (isUpdated) {
switch (field) {
case 'status':
jobData.status = this.status;
break;
case 'assignee':
jobData.assignee_id = this.assignee ? this.assignee.id : null;
break;
default:
break;
}
}
}

await serverProxy.jobs.saveJob(this.id, jobData);

this.__updatedFields = {
status: false,
assignee: false,
};

return this;
}

Expand Down Expand Up @@ -1653,14 +1701,38 @@
// TODO: Add ability to change an owner and an assignee
if (typeof this.id !== 'undefined') {
// If the task has been already created, we update it
const taskData = {
assignee_id: this.assignee ? this.assignee.id : null,
name: this.name,
bug_tracker: this.bugTracker,
labels: [...this.labels.map((el) => el.toJSON())],
};
const taskData = {};

for (const [field, isUpdated] of Object.entries(this.__updatedFields)) {
if (isUpdated) {
switch (field) {
case 'assignee':
taskData.assignee_id = this.assignee ? this.assignee.id : null;
break;
case 'name':
taskData.name = this.name;
break;
case 'bug_tracker':
taskData.bug_tracker = this.bugTracker;
break;
case 'labels':
taskData.labels = [...this.labels.map((el) => el.toJSON())];
break;
default:
break;
}
}
}

await serverProxy.tasks.saveTask(this.id, taskData);

this.updatedFields = {
assignee: false,
name: false,
bugTracker: false,
labels: false,
};

return this;
}

Expand Down