File size: 1,787 Bytes
a7060a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { getParent, types } from "mobx-state-tree";
import Utilities from "../utils";

/**
 * Model for HTTP Basic Authorization
 */
const AuthStore = types.model({
  enable: types.optional(types.boolean, false),
  username: types.string,
  password: types.string,
  to: types.string,
});

/**
 * Task Store
 */
const TaskStore = types
  .model("Task", {
    id: types.maybeNull(types.number),
    load: types.optional(types.boolean, false),
    auth: types.maybeNull(AuthStore),
    agreement: types.maybeNull(types.number),
    /**
     * Data of task, may contain an object but in App Store will be transformed into string
     * MST doesn't support processing of dynamic objects with unkown keys value
     */
    data: types.maybeNull(types.string),
    /**
     * Source field contains full task data as JSON string (LSE-only)
     * Includes annotators array with review statuses
     */
    source: types.optional(types.maybeNull(types.string), null),
    queue: types.optional(types.maybeNull(types.string), null),
    /**
     * Whether this task can be skipped. Defaults to true if undefined.
     */
    allow_skip: types.optional(types.maybeNull(types.boolean), true),
  })
  .views((self) => ({
    get app() {
      return getParent(self);
    },

    /**
     * Return JSON with task data
     * @returns {object}
     */
    get dataObj() {
      const data = (() => {
        if (Utilities.Checkers.isStringJSON(self.data)) {
          return JSON.parse(self.data);
        }
        if (typeof self.data === "object") {
          return self.data;
        }
        return null;
      })();

      // Add source field if available
      if (data && self.source) {
        data.source = self.source;
      }

      return data;
    },
  }));

export default TaskStore;