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

User search field #2370

Merged
merged 12 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ability to upload prepared meta information along with a video when creating a task (<https://github.com/openvinotoolkit/cvat/pull/2217>)
- Optional chaining plugin for cvat-canvas and cvat-ui (<https://github.com/openvinotoolkit/cvat/pull/2249>)
- MOTS png mask format support (<https://github.com/openvinotoolkit/cvat/pull/2198>)
- User search field for assignee fields (<https://github.com/openvinotoolkit/cvat/pull/2370>)

### Changed

Expand Down
1 change: 1 addition & 0 deletions cvat-core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module.exports = {
env: {
amd: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eslint warn about require usage without that flag.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just set node to true

node: false,
browser: true,
es6: true,
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.8.1",
"version": "3.9.0",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "babel.config.js",
"scripts": {
Expand Down
37 changes: 12 additions & 25 deletions cvat-core/src/api-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,6 @@
const { ArgumentError } = require('./exceptions');
const { Task } = require('./session');

function attachUsers(task, users) {
if (task.assignee !== null) {
[task.assignee] = users.filter((user) => user.id === task.assignee);
}

for (const segment of task.segments) {
for (const job of segment.jobs) {
if (job.assignee !== null) {
[job.assignee] = users.filter((user) => user.id === job.assignee);
}
}
}

if (task.owner !== null) {
[task.owner] = users.filter((user) => user.id === task.owner);
}

return task;
}

function implementAPI(cvat) {
cvat.plugins.list.implementation = PluginRegistry.list;
cvat.plugins.register.implementation = PluginRegistry.register.bind(cvat);
Expand Down Expand Up @@ -122,15 +102,24 @@

cvat.users.get.implementation = async (filter) => {
checkFilter(filter, {
id: isInteger,
self: isBoolean,
search: isString,
limit: isInteger,
});

let users = null;
if ('self' in filter && filter.self) {
users = await serverProxy.users.getSelf();
users = [users];
} else {
users = await serverProxy.users.getUsers();
const searchParams = {};
for (const key in filter) {
if (filter[key] && key !== 'self') {
searchParams[key] = filter[key];
}
}
users = await serverProxy.users.getUsers(new URLSearchParams(searchParams).toString());
}

users = users.map((user) => new User(user));
Expand Down Expand Up @@ -163,8 +152,7 @@

// If task was found by its id, then create task instance and get Job instance from it
if (tasks !== null && tasks.length) {
const users = (await serverProxy.users.getUsers()).map((userData) => new User(userData));
const task = new Task(attachUsers(tasks[0], users));
const task = new Task(tasks[0]);

return filter.jobID ? task.jobs.filter((job) => job.id === filter.jobID) : task.jobs;
}
Expand Down Expand Up @@ -203,9 +191,8 @@
}
}

const users = (await serverProxy.users.getUsers()).map((userData) => new User(userData));
const tasksData = await serverProxy.tasks.getTasks(searchParams.toString());
const tasks = tasksData.map((task) => attachUsers(task, users)).map((task) => new Task(task));
const tasks = tasksData.map((task) => new Task(task));

tasks.count = tasksData.count;

Expand Down
14 changes: 4 additions & 10 deletions cvat-core/src/server-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,20 +500,14 @@
}
}

async function getUsers(id = null) {
async function getUsers(filter = 'page_size=all') {
const { backendAPI } = config;

let response = null;
try {
if (id === null) {
response = await Axios.get(`${backendAPI}/users?page_size=all`, {
proxy: config.proxy,
});
} else {
response = await Axios.get(`${backendAPI}/users/${id}`, {
proxy: config.proxy,
});
}
response = await Axios.get(`${backendAPI}/users?${filter}`, {
proxy: config.proxy,
});
} catch (errorData) {
throw generateError(errorData);
}
Expand Down
9 changes: 7 additions & 2 deletions cvat-core/src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@
}
}

if (data.assignee) data.assignee = new User(data.assignee);

Object.defineProperties(
this,
Object.freeze({
Expand Down Expand Up @@ -883,6 +885,9 @@
}
}

if (data.assignee) data.assignee = new User(data.assignee);
if (data.owner) data.owner = new User(data.owner);

data.labels = [];
data.jobs = [];
data.files = Object.freeze({
Expand Down Expand Up @@ -1440,7 +1445,7 @@
if (this.id) {
const jobData = {
status: this.status,
assignee: this.assignee ? this.assignee.id : null,
assignee_id: this.assignee ? this.assignee.id : null,
};

await serverProxy.jobs.saveJob(this.id, jobData);
Expand Down Expand Up @@ -1649,7 +1654,7 @@
if (typeof this.id !== 'undefined') {
// If the task has been already created, we update it
const taskData = {
assignee: this.assignee ? this.assignee.id : null,
assignee_id: this.assignee ? this.assignee.id : null,
name: this.name,
bug_tracker: this.bugTracker,
labels: [...this.labels.map((el) => el.toJSON())],
Expand Down
36 changes: 30 additions & 6 deletions cvat-core/tests/mocks/dummy-data.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ const tasksDummyData = {
name: 'Test',
size: 1,
mode: 'annotation',
owner: 1,
owner: {
url: 'http://localhost:7000/api/v1/users/1',
id: 1,
username: 'admin',
},
assignee: null,
bug_tracker: '',
created_date: '2019-09-05T11:59:22.987942Z',
Expand Down Expand Up @@ -194,7 +198,11 @@ const tasksDummyData = {
name: 'Image Task',
size: 9,
mode: 'annotation',
owner: 1,
owner: {
url: 'http://localhost:7000/api/v1/users/1',
id: 1,
username: 'admin',
},
assignee: null,
bug_tracker: '',
created_date: '2019-06-18T13:05:08.941304+03:00',
Expand Down Expand Up @@ -239,7 +247,11 @@ const tasksDummyData = {
name: 'Video Task',
size: 5002,
mode: 'interpolation',
owner: 1,
owner: {
url: 'http://localhost:7000/api/v1/users/1',
id: 1,
username: 'admin',
},
assignee: null,
bug_tracker: '',
created_date: '2019-06-21T16:34:49.199691+03:00',
Expand Down Expand Up @@ -558,7 +570,11 @@ const tasksDummyData = {
name: 'Test Task',
size: 5002,
mode: 'interpolation',
owner: 2,
owner: {
url: 'http://localhost:7000/api/v1/users/2',
id: 2,
username: 'bsekache',
},
assignee: null,
bug_tracker: '',
created_date: '2019-05-16T13:08:00.621747+03:00',
Expand Down Expand Up @@ -767,7 +783,11 @@ const tasksDummyData = {
name: 'Video',
size: 75,
mode: 'interpolation',
owner: 1,
owner: {
url: 'http://localhost:7000/api/v1/users/1',
id: 1,
username: 'admin',
},
assignee: null,
bug_tracker: '',
created_date: '2019-05-15T11:40:19.487999+03:00',
Expand Down Expand Up @@ -964,7 +984,11 @@ const tasksDummyData = {
name: 'Labels Set',
size: 9,
mode: 'annotation',
owner: 1,
owner: {
url: 'http://localhost:7000/api/v1/users/1',
id: 1,
username: 'admin',
},
assignee: null,
bug_tracker: 'http://bugtracker.com/issue12345',
created_date: '2019-05-13T15:35:29.871003+03:00',
Expand Down
13 changes: 8 additions & 5 deletions cvat-core/tests/mocks/server-proxy.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class ServerProxy {
const object = tasksDummyData.results.filter((task) => task.id === id)[0];
for (const prop in taskData) {
if (
Object.prototype.hasOwnProperty.call(taskData, prop) &&
Object.prototype.hasOwnProperty.call(object, prop)
Object.prototype.hasOwnProperty.call(taskData, prop)
&& Object.prototype.hasOwnProperty.call(object, prop)
) {
object[prop] = taskData[prop];
}
Expand All @@ -110,7 +110,10 @@ class ServerProxy {
name: taskData.name,
size: 5000,
mode: 'interpolation',
owner: 2,
owner: {
id: 2,
username: 'bsekache',
},
assignee: null,
bug_tracker: taskData.bug_tracker,
created_date: '2019-05-16T13:08:00.621747+03:00',
Expand Down Expand Up @@ -175,8 +178,8 @@ class ServerProxy {

for (const prop in jobData) {
if (
Object.prototype.hasOwnProperty.call(jobData, prop) &&
Object.prototype.hasOwnProperty.call(object, prop)
Object.prototype.hasOwnProperty.call(jobData, prop)
&& Object.prototype.hasOwnProperty.call(object, prop)
) {
object[prop] = jobData[prop];
}
Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/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-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.9.14",
"version": "1.10.0",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
36 changes: 0 additions & 36 deletions cvat-ui/src/actions/users-actions.ts

This file was deleted.

Loading