Skip to content

Commit

Permalink
Fix linting errors in EMLAnnotations
Browse files Browse the repository at this point in the history
Issue #2542
  • Loading branch information
robyngit committed Oct 15, 2024
1 parent 586c019 commit 0ac3cce
Showing 1 changed file with 37 additions and 52 deletions.
89 changes: 37 additions & 52 deletions src/js/collections/metadata/eml/EMLAnnotations.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,60 @@
"use strict";

define([
"jquery",
"underscore",
"backbone",
"models/metadata/eml211/EMLAnnotation",
], function ($, _, Backbone, EMLAnnotation) {
define(["underscore", "backbone", "models/metadata/eml211/EMLAnnotation"], (
_,
Backbone,
EMLAnnotation,
) => {
/**
* @class EMLAnnotations
* @classdesc A collection of EMLAnnotations.
* @classcategory Collections/Metadata/EML
* @since 2.19.0
* @extends Backbone.Collection
* @augments Backbone.Collection
*/
var EMLAnnotations = Backbone.Collection.extend(
const EMLAnnotations = Backbone.Collection.extend(
/** @lends EMLAnnotations.prototype */
{
/**
* The reference to the model class that this collection is made of.
* @type EMLAnnotation
* @since 2.19.0
*/
/** @inheritdoc */
model: EMLAnnotation,

/**
* Checks if this collection already has an annotation for the same property URI.
* @param {EMLAnnotation} annotation The EMLAnnotation to compare against the annotations already in this collection.
* @returns {Boolean} Returns true is this collection already has an annotation for this property.
* @since 2.19.0
* Checks if this collection already has an annotation for the same
* property URI.
* @param {EMLAnnotation} annotation The EMLAnnotation to compare against
* the annotations already in this collection.
* @returns {boolean} Returns true is this collection already has an
* annotation for this property.
*/
hasDuplicateOf: function (annotation) {
try {
//If there is at least one model in this collection and there is a propertyURI set on the given model,
if (this.length && annotation.get("propertyURI")) {
//Return whether or not there is a duplicate
let properties = this.pluck("propertyURI");
return properties.includes(annotation.get("propertyURI"));
}
//If this collection is empty or the propertyURI is falsey, return false
else {
return false;
}
} catch (e) {
console.error("Could not check for a duplicate annotation: ", e);
return false;
hasDuplicateOf(annotation) {
// If there is at least one model in this collection and there is a
// propertyURI set on the given model,
if (this.length && annotation.get("propertyURI")) {
// Return whether or not there is a duplicate
const properties = this.pluck("propertyURI");
return properties.includes(annotation.get("propertyURI"));
}
// If this collection is empty or the propertyURI is falsey, return
// false
return false;
},

/**
* Removes the EMLAnnotation from this collection that has the same propertyURI as the given annotation.
* Then adds the given annotation to the collection. If no duplicate is found, the given annotation is still added
* to the collection.
* @param {EMLAnnotation} annotation
* @since 2.19.0
* Removes the EMLAnnotation from this collection that has the same
* propertyURI as the given annotation. Then adds the given annotation to
* the collection. If no duplicate is found, the given annotation is still
* added to the collection.
* @param {EMLAnnotation} annotation The EMLAnnotation to replace
* duplicates with.
*/
replaceDuplicateWith: function (annotation) {
try {
if (this.length && annotation.get("propertyURI")) {
let duplicates = this.findWhere({
propertyURI: annotation.get("propertyURI"),
});
this.remove(duplicates);
}

this.add(annotation);
} catch (e) {
console.error(
"Could not replace the EMLAnnotation in the collection: ",
e,
);
replaceDuplicateWith(annotation) {
if (this.length && annotation.get("propertyURI")) {
const duplicates = this.findWhere({
propertyURI: annotation.get("propertyURI"),
});
this.remove(duplicates);
}
this.add(annotation);
},
},
);
Expand Down

0 comments on commit 0ac3cce

Please sign in to comment.