forked from Crystal-Modeling/tasklist-theia-glsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlms-tasklist-reconnect-edge-handler.ts
51 lines (45 loc) · 2.13 KB
/
lms-tasklist-reconnect-edge-handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Logger, OperationHandler, ReconnectEdgeOperation } from '@eclipse-glsp/server-node';
import { inject, injectable } from 'inversify';
import type * as lms from 'src/lms/model';
import { TaskListLmsClient } from '../lms/client/tasklist-lms-client';
import { TaskListModelState } from '../model/tasklist-model-state';
@injectable()
export class TaskListReconnectEdgeHandler implements OperationHandler {
readonly operationType = ReconnectEdgeOperation.KIND;
@inject(Logger)
protected logger: Logger;
@inject(TaskListModelState)
protected readonly modelState: TaskListModelState;
@inject(TaskListLmsClient)
protected readonly lmsClient: TaskListLmsClient;
execute(operation: ReconnectEdgeOperation): void {
console.debug('Applying edge reconnection. Operation:', operation);
const index = this.modelState.index;
const transition = index.findTransition(operation.edgeElementId);
if (!transition) {
throw new Error(`Transition for edge ID ${operation.edgeElementId} not found`);
}
const modification: lms.Modification<lms.Transition> = { id: transition.id };
if (transition.sourceTaskId !== operation.sourceElementId) {
const source = index.findTask(operation.sourceElementId);
if (!source) {
throw new Error(`Task for source ID ${operation.sourceElementId} not found`);
}
modification.sourceTaskId = source.id;
// transition.sourceTaskId = source.id;
}
if (transition.targetTaskId !== operation.targetElementId) {
const target = index.findTask(operation.targetElementId);
if (!target) {
throw new Error(`Task for target ID ${operation.targetElementId} not found`);
}
modification.targetTaskId = target.id;
// transition.targetTaskId = target.id;
}
if (modification.sourceTaskId || modification.targetTaskId) {
this.lmsClient.updateTransition(this.modelState.taskList.id, modification);
} else {
this.logger.info('Transition is not changed');
}
}
}