Skip to content
Snippets Groups Projects
Select Git revision
  • 66d56ca1c50d1394594c39bd585d0c6294741b05
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

WorkspaceMenu.js

Blame
  • WebAnnotation.js 2.19 KiB
    /** */
    export default class WebAnnotation {
      /** */
      constructor({
        canvasId, id, fragsel, image, body, tags, svg, manifestId,
      }) {
        this.id = id;
        this.canvasId = canvasId;
        this.fragsel = fragsel;
        this.body = body;
        this.tags = tags;
        this.svg = svg;
        this.image = image;
        this.manifestId = manifestId;
      }
    
      /** */
      toJson() {
        return {
          body: this.createBody(),
          id: this.id,
          motivation: 'commenting',
          target: this.target(),
          type: 'Annotation',
        };
      }
    
      /** */
      createBody() {
        let bodies = [];
    
        if (this.body && this.body.value !== '') {
          const textBody = {
            type: 'TextualBody',
            value: this.body.value,
          };
          bodies.push(textBody);
        }
    
        // TODO correct WebAnnotation format
        if (this.image) {
          const imgBody = { type: 'Image' };
          Object.assign(imgBody, this.image);
          imgBody.id = imgBody.url;
          bodies.push(imgBody);
        }
    
        if (this.tags) {
          bodies = bodies.concat(this.tags.map((tag) => ({
            purpose: 'tagging',
            type: 'TextualBody',
            value: tag,
          })));
        }
        if (bodies.length === 1) {
          return bodies[0];
        }
        return bodies;
      }
    
      /** Fill target object with selectors (if any), else returns target url */
      target() {
        if (!this.svg
          && (!this.fragsel || !Object.values(this.fragsel).find((e) => e !== null))) {
          return this.canvasId;
        }
        const target = { source: this.source() };
        const selectors = [];
        if (this.svg) {
          selectors.push({
            type: 'SvgSelector',
            value: this.svg,
          });
        }
        if (this.fragsel) {
          selectors.push({
            type: 'FragmentSelector',
            value: Object.entries(this.fragsel)
              .filter((kv) => kv[1])
              .map((kv) => `${kv[0]}=${kv[1]}`)
              .join('&'),
          });
        }
        target.selector = selectors.length === 1 ? selectors[0] : selectors;
        return target;
      }
    
      /** */
      source() {
        let source = this.canvasId;
        if (this.manifest) {
          source = {
            id: this.canvasId,
            partOf: {
              id: this.manifest.id,
              type: 'Manifest',
            },
            type: 'Canvas',
          };
        }
        return source;
      }
    }