Code coverage report for code/data/migrations/01_base.coffee

Statements: 100% (16 / 16)      Branches: 50% (1 / 2)      Functions: 100% (7 / 7)      Lines: 100% (14 / 14)      Ignored: none     

All files » code/data/migrations/ » 01_base.coffee
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      1           1 1 1 1     1 2       1 1                 1 1 2               1                   1  
# FORMAT BEFORE THIS TRANSFORM: in serialized-test-data-0.1.coffee
# FORMAT AFTER THIS TRANSFORM:  in serialized-test-data-1.0.coffee
 
migration =
  version: 1.0
  description: "The initial migrations from old mysystem style file format."
  date: "2015-08-12"
 
  doUpdate: (data) ->
    @updateNodes(data)
    @updateLinks(data)
    @updatePalette(data)
    data
 
  updateNodes: (data) ->
    data.nodes = _.map (data.nodes or []), (node) ->
      key: node.key
      data: node
 
  updateLinks: (data) ->
    data.links = _.map (data.links or []), (link) ->
      sourceNode: link.sourceNodeKey
      targetNode: link.targetNodeKey
      sourceTerminal: link.sourceTerminal
      targetTerminal: link.targetTerminal
      title: link.title
      color: link.color
 
  updatePalette: (data) ->
    # don't do anything if a palette is already defined
    Eunless data.palette
      data.palette = _.map data.nodes, (node) ->
        image: node.data.image
        key: node.data.image  # TODO truncate this?
        title: node.data.title
        metadata:
          title: node.data.title
          source: "external"
          link: null
          license: "public domain"
      data.palette.push
        title: "",
        image: "img/nodes/blank.png"
        key: "img/nodes/blank.png"
        metadata:
          source: "internal",
          title: "Blank",
          link: null,
          license: "public domain"
 
module.exports = _.mixin migration, require './migration-mixin'