Git Product home page Git Product logo

xform-uploader's Introduction

xform-uploader

Parse a set of XForms and attachments, and upload them to an odk-aggregate server or osm-p2p + hyperdrive.

Example

var uploader = new Uploader()

uploader.add([
  xmlFile1,
  attachment1,
  attachment2,
  xmlFile2,
  attachment4,
  attachment5
], function (err) {
  console.log(uploader.state())
})

// output:
{
  forms: [
    {
      data: parsedFormAsGeoJSON,
      uploaded: 0 // 0-1 progress uploaded, 1 === upload complete
      attachments: [
        {
          filename: 'originalFilename.jpg',
          mediaId: '1231421531.jpg', // not set on attachments until after upload
          blob: attachment1,
          uploaded: 1
        }, {
          filename: 'originalFilename2.jpg',
          mediaId: null,
          blob: attachment2,
          uploaded: 0
        }
      ]
    }
  ],
  missingAttachments: [
    // A form references this media, but the media itself has not been provided.
    'originalFilename3.jpg'
  ],
  orphanAttachments: [
    // This media was provided, but no form references it.
    'otherFilename.png'
  ]
}

// fires every time the internal state changes
uploader.on('change', function () { console.log(uploader.state()) })

uploader.upload({
  observationUpload: 'http://localhost:4001/obs/create',
  mediaUpload: 'http://localhost:4002/media/jpg'
})

API

var Uploader = require('xform-uploader')
var uploader = new Uploader()

uploader.add(files, done)

Add an array of Files to the uploader. Once complete, the callback done will be called with the form function (err).

uploader.state()

Synchronously return the instantaneous state of the Uploader as an object. It will have the following structure:

{
  forms: [
    {
      data: parsedFormAsGeoJSON,
      uploaded: 0 // 0-1 progress uploaded, 1 === upload complete
      attachments: [
        {
          filename: 'originalFilename.jpg',
          mediaId: '1231421531', // or 'null' until uploaded
          blob: attachment1,
          uploaded: 1
        }, {
          filename: 'originalFilename2.jpg',
          mediaId: null,
          blob: attachment2,
          uploaded: 0
        }
      ]
    }
  ],
  missingAttachments: [
    // A form references this media, but the media itself has not been provided.
    'originalFilename3.jpg'
  ],
  orphanAttachments: [
    // This media was provided, but no form references it.
    'otherFilename.png'
  ]
}

uploader.on('change', function () { ... })

This event is emitted whenever the public-facing state of the Uploader has changed.

uploader.upload(servers, done)

Upload the forms and their attachments to various servers.

servers is an object. Currently the following keys are accepted:

  • observationsUrl: an HTTP URL of a POST endpoint to receive the osm observation data that each form represents.
  • mediaUrl: an HTTP URL of a POST endpoint to receive the media data that each attachment represents.

Inner Modules

This module contains two inner modules: FormSet and XFormSet, which are more general purpose and may useful outside of the context of the outer module, which is just a small amount of glue code.

License

ISC

xform-uploader's People

Contributors

gmaclennan avatar hackergrrl avatar mojodna avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

mojodna

xform-uploader's Issues

Associate missingAttachments w/ forms

It's not currently possible to determine which form is missing an attachment if one is detected.

For now, I'm listing missing attachments separately but am unable to highlight the related form:

image

Retain form filename

XForm filenames aren't available from uploader.status() (or from anything available on the uploader object).

Dates identified as missing attachments

E.g. 2016-05-02T14:46:19.353Z and 2016-05-02T15:07:29.685Z from a.start and a.end in:

<?xml version='1.0' ?>
<Guinee_Sondage_Communautaire_V1-4-3 id="Guinee_Sondage_Communautaire_V1-4-3">
    <a>
        <start>2016-05-02T14:46:19.353Z</start>
        <end>2016-05-02T15:07:29.685Z</end>
        <today>2016-05-02</today>
        <deviceid>redacted</deviceid>
        <subscriberid>redacted</subscriberid>
        <simserial>redacted</simserial><phonenumber/><title/>
        <hh_gps>14.132314 -13.533 398.6 6.2</hh_gps>
        <consent>1</consent>
    </a>
    <b>
        <loc_adm1>guinee_forestiere</loc_adm1>
        <loc_adm2>nzerekore</loc_adm2>
        <loc_adm3>gueckedou</loc_adm3>
        <URBAN_OR_RURAL>2</URBAN_OR_RURAL>
        <loc_adm4>nongoa</loc_adm4>
        <RURAL_SECTEUR>
            <DISTRICT>Nongoa</DISTRICT>
            <SECTEUR_RURAL>Kouakoro</SECTEUR_RURAL>
            <name_village>995</name_village>
            <name_part_village>Nak&#244;</name_part_village>
        </RURAL_SECTEUR>
        <OTHER_DETAILS>redacted</OTHER_DETAILS>
        <rep_names>
            <namerep>redacted</namerep>
            <rep_middle_name>redacted</rep_middle_name>
            <rep_last_name>redacted</rep_last_name>
        </rep_names>
    </b>
    <c>
        <phone>9995</phone>
        <contact_alt>995</contact_alt>
        <shareinfo>1</shareinfo>
    </c>
    <d>
        <hhnum>5</hhnum>
    </d>
    <e>
        <comm_dist>2</comm_dist>
    </e>
    <f>
        <drink_wat>4</drink_wat>
    </f>
    <g>
        <water_time>10</water_time>
    </g>
    <h>
        <toilet>4</toilet>
    </h>
    <i>
        <floor>1</floor>
    </i>
    <k>
        <treat_main>11</treat_main>
    </k>
    <j>
        <treat_name>redacted</treat_name>
    </j>
    <l>
        <treat_loc>1</treat_loc>
    </l>
    <m>
        <treat_time>5</treat_time>
    </m>
    <n>
        <treat_mult>95</treat_mult>
    </n>
    <p>
        <birth_main>14</birth_main>
    </p>
    <o>
        <birth_name>redacted</birth_name>
    </o>
    <q>
        <birth_loc>1</birth_loc>
    </q>
    <r>
        <birth_time>3</birth_time>
    </r>
    <s>
        <birth_mult>14 16</birth_mult>
    </s>
    <meta>
        <instanceID>uuid:0aabd480-22de-439c-8b7e-42fa597cb446</instanceID>
    </meta>
</Guinee_Sondage_Communautaire_V1-4-3>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.