Advertisement
Guest User

Untitled

a guest
Sep 4th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         gantt.createDataProcessor((mode: 'task' | 'link', taskState: string, data: Task | Link, _rowId: unknown) => {
  2.             switch (mode) {
  3.                 case 'link': {
  4.                     switch (taskState) {
  5.                         case 'create':
  6.                             this.api.linkCreate(data as Link)
  7.                                 .then(result => {
  8.                                     console.log('created link: ', result);
  9.                                     gantt.changeLinkId(data.id as string, result.id as string);
  10.                                 })
  11.                                 .catch(error => {
  12.                                     gantt.undo();
  13.                                     this.displayError(error);
  14.                                 });
  15.                             break;
  16.                         case 'delete':
  17.                             this.api.linkRemove(data.id as string)
  18.                                 .then(_result => void 0)
  19.                                 .catch(error => {
  20.                                     gantt.undo();
  21.                                     this.displayError(error);
  22.                                 });
  23.                             break;
  24.                         case 'update':
  25.                             this.api.linkUpdate(data as Link)
  26.                                 .then(result => {
  27.                                     gantt.changeLinkId(data.id as string, result.id as string);
  28.                                 })
  29.                                 .catch(error => {
  30.                                     gantt.undo();
  31.                                     this.displayError(error);
  32.                                 });
  33.                             break;
  34.                     }
  35.                     break;
  36.                 }
  37.                 case 'task': {
  38.                     switch (taskState) {
  39.                         case 'create':
  40.                             this.api.taskCreate(data as Task)
  41.                                 .then(result => {
  42.                                     console.log('created task: ', result);
  43.                                     gantt.changeTaskId(data.id as string, result.id as string);
  44.                                 })
  45.                                 .catch(error => {
  46.                                     gantt.undo();
  47.                                     this.displayError(error);
  48.                                 });
  49.                             break;
  50.                         case 'delete':
  51.                             this.api.taskRemove(data.id as string)
  52.                                 .then(_result => void 0)
  53.                                 .catch(error => {
  54.                                     gantt.undo();
  55.                                     this.displayError(error);
  56.                                 });
  57.                             break;
  58.                         case 'update':
  59.                             this.api.taskUpdate(data as Task)
  60.                                 .then(_result => void 0)
  61.                                 .catch(error => {
  62.                                     gantt.undo();
  63.                                     this.displayError(error);
  64.                                 });
  65.                             break;
  66.                     }
  67.                     break;
  68.                 }
  69.                 default: {
  70.  
  71.                     throw new Error('Unsupported mode');
  72.                 }
  73.             }
  74.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement