src_js/iconolab-bundle/src/components/mergetool/MergeTool.vue
author ymh <ymh.work@gmail.com>
Wed, 06 Jun 2018 16:21:54 +0200
changeset 539 08e2513dbc2f
parent 156 e1e14766f608
permissions -rw-r--r--
Upgrade webpack to 4, upgrade vue.js, and some style changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     1
<script>
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
     2
import Typeahead from "../typeahead/Typeahead.vue";
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
     3
import DiffViewer from "../diffviewer/diffviewer.vue";
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     4
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     5
export default {
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
     6
  data() {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
     7
    return {};
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
     8
  },
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     9
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    10
  components: {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    11
    Typeahead: Typeahead,
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    12
    diffviewer: DiffViewer
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    13
  },
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    14
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    15
  mounted() {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    16
    this.targetKeyMap = {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    17
      title: "proposal-title",
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    18
      desc: "proposal-description",
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    19
      frag: "proposal-fragment"
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    20
    };
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    21
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    22
    this.targetFieldTypeMap = {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    23
      title: "input",
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    24
      desc: "input",
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    25
      frag: "frag"
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    26
    };
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    27
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    28
    this.originalValues = {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    29
      title: "",
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    30
      desc: "",
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    31
      frag: ""
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    32
    };
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    33
  },
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    34
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    35
  methods: {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    36
    pickProposition: function(event, sourceId, targetKey) {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    37
      var value = "";
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    38
      var source = document.getElementById(sourceId);
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    39
      var targetField = this.$refs[this.targetKeyMap[targetKey]];
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    40
      var targetType = this.targetFieldTypeMap[targetKey];
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    41
      if (!targetType) {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    42
        throw new Error("A target type must be provided...");
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    43
      }
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    44
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    45
      if (targetType === "input") {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    46
        value = targetField.value;
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    47
        targetField.value = source.value;
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    48
      }
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    49
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    50
      if (targetType === "frag") {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    51
        value = targetField.getAttribute("d");
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    52
        var sourceValue = source.getAttribute("d");
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    53
        var targetPathType = targetField.getAttribute("data-path-type");
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    54
        targetField.setAttribute("d", sourceValue);
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    55
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    56
        var pathType = source.getAttribute("data-path-type");
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    57
        pathType = pathType || "FREE";
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    58
        var fragmentField = this.$refs["fragment-field"];
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    59
        fragmentField.value = sourceValue + ";" + pathType;
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    60
      }
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    61
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    62
      this.preserveOriginalValue(targetKey, value);
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    63
    },
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    64
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    65
    pickTag: function(event, refTag) {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    66
      var source = this.$refs[refTag];
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    67
      var target = this.$refs["proposal-tags"];
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    68
      this.preserveOriginalValue("proposal-tags", target.tags);
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    69
      target.setTags(source.tags, true);
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    70
    },
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    71
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    72
    preserveOriginalValue: function(key, value) {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    73
      if (!this.originalValues[key]) {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    74
        this.originalValues[key] = value;
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    75
      }
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    76
    },
156
e1e14766f608 adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 146
diff changeset
    77
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    78
    showDiffviewer: function(refId, sourceId, targetKey) {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    79
      var sourceField = document.getElementById(sourceId);
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    80
      var targetField = this.$refs[this.targetKeyMap[targetKey]];
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    81
      var targetType = this.targetFieldTypeMap[targetKey];
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    82
      var diffViewer = this.$refs[refId];
156
e1e14766f608 adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 146
diff changeset
    83
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    84
      if (!diffViewer) {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    85
        throw new Error("The DiffViewer can't be found for " + targetKey);
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    86
      }
156
e1e14766f608 adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 146
diff changeset
    87
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    88
      if (targetType === "input") {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    89
        diffViewer.showTextDiff(sourceField.value, targetField.value);
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    90
      }
156
e1e14766f608 adding diffviewer to merging view
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 146
diff changeset
    91
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    92
      if (targetKey === "tag") {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    93
        var source = this.$refs[sourceId];
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    94
        var target = this.$refs["proposal-tags"];
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    95
        if (source.tags.length !== 0 && target.tags.length !== 0) {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    96
          diffViewer.showTagDiff(source.tags, target.tags);
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    97
        }
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    98
      }
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
    99
      /* frag */
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   100
      if (targetKey === "frag") {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   101
        var originalPath = targetField.getAttribute("d");
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   102
        var modifiedPath = sourceField.getAttribute("d");
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   103
        diffViewer.showFragmentDiff(originalPath, modifiedPath);
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   104
      }
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
   105
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   106
      diffViewer.show();
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   107
    },
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   108
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   109
    hightlightSource: function(source) {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   110
      source.className += "highlight";
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   111
    },
146
f912b591e1c1 new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
   112
539
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   113
    save: function() {
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   114
      alert("this is it ... ");
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   115
    }
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   116
  }
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   117
};
08e2513dbc2f Upgrade webpack to 4, upgrade vue.js, and some style changes
ymh <ymh.work@gmail.com>
parents: 156
diff changeset
   118
</script>