Giter Club home page Giter Club logo

widget's Introduction

lifecycle NSF-1928366 Node version

Throughput Annotation Widget

The Throughput Annotation Widget is a lightweight web component that allows web users to view Throughput annotations on a dataset, and to add new annotations after authenticating through ORCID.

Built with the Stencil toolchain, the widget is easy to integrate into Vue, React, and Angular applications, or a static HTML webpage.

Contributors

This project is an open project, and contributions are welcome from any individual. All contributors to this project are bound by a code of conduct. Please review and follow this code of conduct as part of your contribution.

Tips for Contributing

Issues and bug reports are always welcome. Code clean-up, and feature additions can be done either through pull requests to project forks or branches.

All products of the Throughput Annotation Project are licensed under an MIT License unless otherwise noted.

How to use this repository

Developing the widget locally

  1. Install npm.
  2. Clone the repository and run npm install in its root directory.
  3. In src/index.html, set identifier, link, additional-type properties for the data resource to be annotated. Additionally, set orcid-client-id, which is required unless the optional read-only-mode property is set to true.
  4. Run with npm run start.
  5. View the widget in a browser at http://localhost:3333.
  6. Hack away and send us pull requests or issues!

Integrating the widget into an existing application/website

Minimal examples of widget integration into Vue, React, Angular, and static HTML can be found in the examples directory. All examples use read-only-mode.

Register with ORCID

If you plan to use the widget in read-only-mode, skip this step.

To add annotations, widget users must first authenticate through ORCID. We encourage devs to register for the public ORCID API so they can freely manage post-authentication redirects for their site.

Once registered, an ORCID Client ID (e.g. APP-1234567890ABCDEF) will be provided. This is passed to the widget in the orcid-client-id property, described below.

Install the widget

For Vue, React, and Angular applications, install the widget with npm:

npm install throughput-widget

For static HTML pages, import the widget with the following tag:

<script type="module" src="https://unpkg.com/throughput-widget/dist/throughputwidget/throughputwidget.esm.js"></script>

Vue, React, and Angular can use this tag as an alternative to npm.

<throughput-widget\> properties

Once installed, your application will have access to the <throughput-widget> component. It accepts the following properties:

property Required Description
identifier Required re3data identifier for top-level data resource.
link Required Identifies a dataset within the top-level data resource.
additional-type Required Identifies the data type associated with link.
read-only-mode Optional bool (def. false) If true, the "Add Annotation" UI will be hidden.
orcid-client-id Required if read-only-mode=false The ORCID client ID to be used for authentication.

Databases registered within Throughput use the re3data identifier as a UID. For example, the Neotoma Paleoecology Database has a re3data landing page at https://www.re3data.org/repository/r3d100011761, and a UID within Throughput of r3d100011761.

Within an individual database, individual data elements are identified using both an identifier, and an additional-type. These are defined by the database themselves. For example, in a data service that provides access to data at multiple granularity, it might be the case that there is a collectionunit with an identifier 1223, and also a site with the same identifier ID. The use of the additional-type together with the identifier is intended to add flexibility for the data resource in managing and querying annotations.

Vue, React, and Angular each require additional changes to make use of the widget, detailed below.

Vue

In src/main.js, import the widget and tell Vue to ignore the widget element:

import { applyPolyfills, defineCustomElements } from 'throughput-widget/loader';
Vue.config.ignoredElements = ["throughput-widget"];
applyPolyfills().then(() => {
  defineCustomElements();
});

The widget will be added to the .vue template file, as an HTML element. Add the widget to your dataset template, and pass in props. Note the Vue-specific syntax for the link prop. this.dsid is the dataset page's ID.

<throughput-widget
  identifier="[your re3data ID]"
  :link.prop="this.dsid"
  additional-type="[your dataset type]"
  orcid-client-id="[your ORCID client ID]"
/>

NOTE: If the widget is to be run in read-only mode, you can omit the orcid-client-id.

React

In App.js, import the widget:

import { applyPolyfills, defineCustomElements } from 'throughput-widget/loader';
applyPolyfills().then(() => {
  defineCustomElements();
});

Add the widget to your dataset template, and pass in props. Note the React-specific syntax for the link prop. dsid is the dataset page's ID.

<throughput-widget
  identifier="[your re3data ID]"
  link={dsid}
  additional-type="[your dataset type]"
  orcid-client-id="[your ORCID client ID]"
/>

Angular

In app.module.ts, add CUSTOM_ELEMENTS_SCHEMA to the imports from @angular/core, then include it in AppModule's schemas list. Repeat for other modules that use the widget.

// ...
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; // import CUSTOM_ELEMENTS_SCHEMA

@NgModule({
  // ...
  schemas: [CUSTOM_ELEMENTS_SCHEMA] // add CUSTOM_ELEMENTS_SCHEMA to AppModule and other modules using the widget
})
export class AppModule { }

In main.ts, import and call defineCustomElements():

// ...
import { defineCustomElements } from 'throughput-widget/loader';

// ...
defineCustomElements();

Add the widget to your dataset template, and pass in props. Note the Angular-specific syntax for the link prop. dsid is the dataset page's ID.

<throughput-widget
  identifier="[your re3data ID]"
  link="{{ dsid }}"
  additional-type="[your dataset type]"
  orcid-client-id="[your ORCID client ID]"
></throughput-widget>

Static HTML

Add the imported <throughput-widget> tag to your dataset page(s):

<throughput-widget
  identifier="[your re3data ID]"
  link="[your dataset ID]"
  additional-type="[your dataset type]"
  orcid-client-id="[your ORCID client ID]"
></throughput-widget>

Styling Options

There are several CSS variables available for styling.

These currently include:

--badge-background-color
--badge-border-color
--badge-font-color
--modal-background-color
--modal-font-color
--modal-card-color
--widget-font-family

They can be added to your site's CSS like so:

throughput-widget {
  --badge-background-color: red; 
}

Data Requirements

The widget pulls annotations from the Throughput Annotation Database using the Annotation API. Annotations are added by individuals, or through scripted workflows and are searchable using the API.

Key Outputs

Once a user authenticates through ORCID, the widget can be used to annotate a dataset. These annotations are maintained on Throughput, but can be accessed by any individual.

Metrics

This project is to be evaluated using the following metrics:

  • COMPLETE -- Active npm registry page.
  • Download activity for the npm module
  • Number of data services using the Throughput widget
  • Number of annotations added using the widget

NPM

widget's People

Contributors

shane98c avatar simongoring avatar sorghumking avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

widget's Issues

Unable to edit an annotation

After creating an annotation, there appears to be no way for the creator to edit the annotation for correction.

Annotations should be editable by the creator to correct or remove the annotation.

Two widgets on one page send the same network request even with different parameters.

It looks like if you have two instances of the widget on a single page they both send the request as structured by the first instance. So on the Neotoma pages I have two instances, one for sites, the other for datasets:

        <b-col>
          <div>
            <h4>Site Annotations</h4>
          </div>
          <div> 
            <throughput-widget
              read-only-mode="true"
              identifier="r3d100011761" 
              :link.prop="items.siteid" 
              additional-type="site"
              orcid-client-id="APP-OKAEGWFY7MEOK4HE">
            </throughput-widget>
          </div>
        </b-col>
        <b-col>
        <div><h4>Dataset Annotations</h4></div><div>
          <throughput-widget
          read-only-mode="false"
          identifier="r3d100011761" 
          :link.prop="this.dsid" 
          additional-type="dataset"
          orcid-client-id="APP-OKAEGWFY7MEOK4HE"></throughput-widget>
        </div>
        </b-col>

But, when I inspect the content and the network calls, they're both calling:

https://throughputdb.com/api/ccdrs/annotations?dbid=r3d100011761&additionalType=site&id=2268&limit=9999

Which is the site call.
You can see it in action on the active landing pages: data.neotomadb.org/2348

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.