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

Editing the schedule #770

Merged
merged 43 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ccf5b89
Create popup component to edit or delete events
Angatupyry Sep 12, 2023
534de7c
Create popup component to edit or delete events
Angatupyry Sep 12, 2023
60b07b9
Adding popup to edit events
Angatupyry Sep 12, 2023
27d4776
Enable or disable cells
Angatupyry Sep 12, 2023
daf83dc
Add schedule and openSchedulepopup props
Angatupyry Sep 12, 2023
64515e2
Open create task form in edit event
Angatupyry Sep 12, 2023
59b64ee
Update entire schedule
Angatupyry Sep 12, 2023
76494c6
Update entire schedule
Angatupyry Sep 12, 2023
522635e
Fix endpoint to receive task request
Angatupyry Sep 13, 2023
d86eff9
Remove unnecesary function and rename props
Angatupyry Sep 13, 2023
b174b60
Create hooks to reuse function
Angatupyry Sep 13, 2023
1e68ea0
Editing entire schedule
Angatupyry Sep 13, 2023
951fe7f
Using custom hook
Angatupyry Sep 13, 2023
60cfa28
Repeated functions sends to utils file
Angatupyry Sep 13, 2023
2729310
Create method to handle editing single event
Angatupyry Sep 13, 2023
47656b5
Add utils file to be more cleaner
Angatupyry Sep 13, 2023
282be5d
Setting on or never depending of the schedule value
Angatupyry Sep 13, 2023
bc7cb0b
Editing single event
Angatupyry Sep 13, 2023
736c16a
Create a custom hook to get username
Angatupyry Sep 13, 2023
46f7d56
Use custom hook to get usernmae
Angatupyry Sep 13, 2023
5d41ee3
Disabling cells without events
Angatupyry Sep 13, 2023
633e708
Add test for new component
Angatupyry Sep 13, 2023
1185e26
Test created
Angatupyry Sep 13, 2023
7c9de06
Order status according to meaning and use ref instead of state to set…
Angatupyry Sep 14, 2023
c24b3f1
End of day using insted of end of minutes in until date
Angatupyry Sep 14, 2023
0df73ce
Set current state when click onSubmit button
Angatupyry Sep 14, 2023
621b1c8
Refresh events after sending submit and after close create task form
Angatupyry Sep 14, 2023
0c687b7
Fix bug editing entire events
Angatupyry Sep 14, 2023
91af618
Setting except dates as empty in editing mode
Angatupyry Sep 14, 2023
4ba26f1
Separete scheduled component and tasks
Angatupyry Sep 14, 2023
9eb135a
Add explanation comment in new route
Angatupyry Sep 14, 2023
9173dc1
Default cursor in cells without events
Angatupyry Sep 15, 2023
c6f3e13
Using the same terminology between edit and delete.
Angatupyry Sep 18, 2023
775af1a
Rename file name to be more descriptive
Angatupyry Sep 18, 2023
7978bba
Change name of Radio group
Angatupyry Sep 18, 2023
707eb5e
Move function from utils to task/utils since it is related to just tasks
Angatupyry Sep 18, 2023
c035417
Rename component name to be more descriptive
Angatupyry Sep 18, 2023
006c636
Fix test accoriing to changes on the component
Angatupyry Sep 18, 2023
644583b
Delete unnecesary props
Angatupyry Sep 18, 2023
cfb4a26
Rename props to be more descriptive
Angatupyry Sep 18, 2023
c8ea919
Some minor changes to be more descriptive and clear
Angatupyry Sep 18, 2023
6bdb546
Make comments a little more descriptive, instead of pseudocode.
Angatupyry Sep 18, 2023
37610d6
Add at time in schedule interface to set the time correctly
Angatupyry Sep 19, 2023
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
142 changes: 142 additions & 0 deletions packages/api-client/lib/openapi/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8431,6 +8431,69 @@ export const TasksApiAxiosParamCreator = function (configuration?: Configuration
...options.headers,
};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary Update Schedule Task
* @param {number} taskId
* @param {PostScheduledTaskRequest} postScheduledTaskRequest
* @param {string} [exceptDate]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
updateScheduleTaskScheduledTasksTaskIdUpdatePost: async (
taskId: number,
postScheduledTaskRequest: PostScheduledTaskRequest,
exceptDate?: string,
options: AxiosRequestConfig = {},
): Promise<RequestArgs> => {
// verify required parameter 'taskId' is not null or undefined
assertParamExists('updateScheduleTaskScheduledTasksTaskIdUpdatePost', 'taskId', taskId);
// verify required parameter 'postScheduledTaskRequest' is not null or undefined
assertParamExists(
'updateScheduleTaskScheduledTasksTaskIdUpdatePost',
'postScheduledTaskRequest',
postScheduledTaskRequest,
);
const localVarPath = `/scheduled_tasks/{task_id}/update`.replace(
`{${'task_id'}}`,
encodeURIComponent(String(taskId)),
);
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (exceptDate !== undefined) {
localVarQueryParameter['except_date'] =
(exceptDate as any) instanceof Date ? (exceptDate as any).toISOString() : exceptDate;
}

localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {
...localVarHeaderParameter,
...headersFromBaseOptions,
...options.headers,
};
localVarRequestOptions.data = serializeDataIfNeeded(
postScheduledTaskRequest,
localVarRequestOptions,
configuration,
);

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
Expand Down Expand Up @@ -8891,6 +8954,35 @@ export const TasksApiFp = function (configuration?: Configuration) {
);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @summary Update Schedule Task
* @param {number} taskId
* @param {PostScheduledTaskRequest} postScheduledTaskRequest
* @param {string} [exceptDate]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async updateScheduleTaskScheduledTasksTaskIdUpdatePost(
taskId: number,
postScheduledTaskRequest: PostScheduledTaskRequest,
exceptDate?: string,
options?: AxiosRequestConfig,
): Promise<
(
axios?: AxiosInstance,
basePath?: string,
) => AxiosPromise<ApiServerModelsTortoiseModelsScheduledTaskScheduledTask>
> {
const localVarAxiosArgs =
await localVarAxiosParamCreator.updateScheduleTaskScheduledTasksTaskIdUpdatePost(
taskId,
postScheduledTaskRequest,
exceptDate,
options,
);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
};
};

Expand Down Expand Up @@ -9271,6 +9363,30 @@ export const TasksApiFactory = function (
)
.then((request) => request(axios, basePath));
},
/**
*
* @summary Update Schedule Task
* @param {number} taskId
* @param {PostScheduledTaskRequest} postScheduledTaskRequest
* @param {string} [exceptDate]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
updateScheduleTaskScheduledTasksTaskIdUpdatePost(
taskId: number,
postScheduledTaskRequest: PostScheduledTaskRequest,
exceptDate?: string,
options?: any,
): AxiosPromise<ApiServerModelsTortoiseModelsScheduledTaskScheduledTask> {
return localVarFp
.updateScheduleTaskScheduledTasksTaskIdUpdatePost(
taskId,
postScheduledTaskRequest,
exceptDate,
options,
)
.then((request) => request(axios, basePath));
},
};
};

Expand Down Expand Up @@ -9680,4 +9796,30 @@ export class TasksApi extends BaseAPI {
)
.then((request) => request(this.axios, this.basePath));
}

/**
*
* @summary Update Schedule Task
* @param {number} taskId
* @param {PostScheduledTaskRequest} postScheduledTaskRequest
* @param {string} [exceptDate]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof TasksApi
*/
public updateScheduleTaskScheduledTasksTaskIdUpdatePost(
taskId: number,
postScheduledTaskRequest: PostScheduledTaskRequest,
exceptDate?: string,
options?: AxiosRequestConfig,
) {
return TasksApiFp(this.configuration)
.updateScheduleTaskScheduledTasksTaskIdUpdatePost(
taskId,
postScheduledTaskRequest,
exceptDate,
options,
)
.then((request) => request(this.axios, this.basePath));
}
}
2 changes: 1 addition & 1 deletion packages/api-client/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { version as rmfModelVer } from 'rmf-models';

export const version = {
rmfModels: rmfModelVer,
rmfServer: 'c8c43e395caae7ccc858008b7663d30914b2cc62',
rmfServer: '60cfa28fb26433cb33254ba1522fc00466fe7146',
openapiGenerator: '6.2.1',
};
47 changes: 47 additions & 0 deletions packages/api-client/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,53 @@ export default {
},
},
},
'/scheduled_tasks/{task_id}/update': {
post: {
tags: ['Tasks'],
summary: 'Update Schedule Task',
operationId: 'update_schedule_task_scheduled_tasks__task_id__update_post',
parameters: [
{
required: true,
schema: { title: 'Task Id', type: 'integer' },
name: 'task_id',
in: 'path',
},
{
required: false,
schema: { title: 'Except Date', type: 'string', format: 'date-time' },
name: 'except_date',
in: 'query',
},
],
requestBody: {
content: {
'application/json': {
schema: { $ref: '#/components/schemas/PostScheduledTaskRequest' },
},
},
required: true,
},
responses: {
'201': {
description: 'Successful Response',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/api_server.models.tortoise_models.scheduled_task.ScheduledTask',
},
},
},
},
'422': {
description: 'Validation Error',
content: {
'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } },
},
},
},
},
},
'/favorite_tasks': {
get: {
tags: ['Tasks'],
Expand Down
77 changes: 77 additions & 0 deletions packages/api-server/api_server/routes/tasks/scheduled_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
from datetime import datetime
from typing import Optional

import schedule
import tortoise.transactions
Expand Down Expand Up @@ -159,6 +160,82 @@ async def del_scheduled_tasks_event(
await schedule_task(task, task_repo)


@router.post(
"/{task_id}/update", status_code=201, response_model=ttm.ScheduledTaskPydantic
)
async def update_schedule_task(
task_id: int,
scheduled_task_request: PostScheduledTaskRequest,
except_date: Optional[datetime] = None,
task_repo: TaskRepository = Depends(task_repo_dep),
):
try:
task = await get_scheduled_task(task_id)
if task is None:
raise HTTPException(404)
# If "except_date" is provided, it means a single event is being updated.
# In this case, we perform the following steps:
# 1. Add the "except_date" to the list of exception dates for the task.
# 2. Clear all existing schedules associated with the task.
# 3. Create a new scheduled task with the requested data from the schedule form.

async with tortoise.transactions.in_transaction():
if except_date:
Angatupyry marked this conversation as resolved.
Show resolved Hide resolved
task.except_dates.append(datetime_to_date_format(except_date))
await task.save()

for sche in task.schedules:
schedule.clear(sche.get_id())

await schedule_task(task, task_repo)

scheduled_task = await ttm.ScheduledTask.create(
task_request=scheduled_task_request.task_request.json(
exclude_none=True
),
created_by=task.created_by,
)
schedules = [
ttm.ScheduledTaskSchedule(scheduled_task=scheduled_task, **x.dict())
for x in scheduled_task_request.schedules
]
await ttm.ScheduledTaskSchedule.bulk_create(schedules)

await schedule_task(scheduled_task, task_repo)
else:
# If "except_date" is not provided, it means the entire series is being updated.
# In this case, we perform the following steps:
# 1. Update the task with the requested data from the schedule form and clear exception dates.
# 2. Clear all existing schedules associated with the task.
# 3. Delete all existing schedules associated with the task.
# 4. Create new schedules based on the requested data.
task.update_from_dict(
{
"task_request": scheduled_task_request.task_request.json(
exclude_none=True
),
"except_dates": [],
}
)

for sche in task.schedules:
schedule.clear(sche.get_id())
for sche in task.schedules:
await sche.delete()

await task.save()
schedules = [
ttm.ScheduledTaskSchedule(scheduled_task=task, **x.dict())
for x in scheduled_task_request.schedules
]

await ttm.ScheduledTaskSchedule.bulk_create(schedules)

await schedule_task(task, task_repo)
except schedule.ScheduleError as e:
raise HTTPException(422, str(e)) from e


@router.delete("/{task_id}")
async def del_scheduled_tasks(task_id: int):
async with tortoise.transactions.in_transaction():
Expand Down
Loading
Loading