Skip to content
Snippets Groups Projects
Select Git revision
  • d28b5febad2ca9f0ebd84b9cad7a9eee5ab6a275
  • mui5-tetras-main-stable default protected
  • mui5-tetras-main-old-stable
  • preprod protected
  • 75-dernieres-ameliorations-avant-workshop-du-7-02
  • wip-fix-xywh
  • wip-positionement-annot
  • wip-surface-transformer
  • uploads-file
  • 69-la-video-demare-quand-on-fait-glisser-le-slider-et-le-clic-creer-un-decalage-entre-le-player
  • 61-recettage-des-outils-d-annotation
  • gestion_multiple_ouverture_pannel_annotation
  • autorisation_un_pannel_annotation
  • autorisation_un_pannel_edition_annotation
  • récupération_temps_video
  • save-shapes-and-position
  • fix-error-create-annotation-pannel
  • time-saving-on-annotation
  • tetras-main protected
  • fix-poc-mirador
  • tetras-antho-test
21 results

WebAnnotation.js

Blame
  • Loïs Poujade's avatar
    Loïs Poujade authored
    - to webanno format: "id" property need to be image address
    - reorder keys for linter
    - show image in edition form if existing
    - add minimal test
    d28b5feb
    History
    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;
      }
    }