mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Add clone methods to all criterion classes (#5109)
This commit is contained in:
@@ -89,14 +89,7 @@ export abstract class Criterion<V extends CriterionValue> {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public clone(): Criterion<V> {
|
||||
const newCriterion = new (this.constructor as new (
|
||||
type: CriterionOption,
|
||||
value: V
|
||||
) => Criterion<V>)(this.criterionOption, this.value);
|
||||
newCriterion.modifier = this.modifier;
|
||||
return newCriterion;
|
||||
}
|
||||
public abstract clone(): Criterion<V>;
|
||||
|
||||
public static getModifierLabel(intl: IntlShape, modifier: CriterionModifier) {
|
||||
const modifierMessageID = modifierMessageIDs[modifier];
|
||||
@@ -519,6 +512,13 @@ export class StringCriterion extends Criterion<string> {
|
||||
super(type, "");
|
||||
}
|
||||
|
||||
public clone() {
|
||||
const newCriterion = new StringCriterion(this.criterionOption);
|
||||
newCriterion.modifier = this.modifier;
|
||||
newCriterion.value = this.value;
|
||||
return newCriterion;
|
||||
}
|
||||
|
||||
protected getLabelValue(_intl: IntlShape) {
|
||||
return this.value;
|
||||
}
|
||||
@@ -714,6 +714,17 @@ export function createMandatoryNumberCriterionOption(
|
||||
}
|
||||
|
||||
export class NumberCriterion extends Criterion<INumberValue> {
|
||||
constructor(type: CriterionOption) {
|
||||
super(type, { value: undefined, value2: undefined });
|
||||
}
|
||||
|
||||
public clone() {
|
||||
const newCriterion = new NumberCriterion(this.criterionOption);
|
||||
newCriterion.modifier = this.modifier;
|
||||
newCriterion.value = { ...this.value };
|
||||
return newCriterion;
|
||||
}
|
||||
|
||||
public get value(): INumberValue {
|
||||
return this._value;
|
||||
}
|
||||
@@ -772,10 +783,6 @@ export class NumberCriterion extends Criterion<INumberValue> {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
constructor(type: CriterionOption) {
|
||||
super(type, { value: undefined, value2: undefined });
|
||||
}
|
||||
}
|
||||
|
||||
export class DurationCriterionOption extends MandatoryNumberCriterionOption {
|
||||
@@ -796,6 +803,13 @@ export class DurationCriterion extends Criterion<INumberValue> {
|
||||
super(type, { value: undefined, value2: undefined });
|
||||
}
|
||||
|
||||
public clone() {
|
||||
const newCriterion = new DurationCriterion(this.criterionOption);
|
||||
newCriterion.modifier = this.modifier;
|
||||
newCriterion.value = { ...this.value };
|
||||
return newCriterion;
|
||||
}
|
||||
|
||||
public toCriterionInput(): IntCriterionInput {
|
||||
return {
|
||||
modifier: this.modifier,
|
||||
@@ -869,6 +883,17 @@ export function createDateCriterionOption(value: CriterionType) {
|
||||
}
|
||||
|
||||
export class DateCriterion extends Criterion<IDateValue> {
|
||||
constructor(type: CriterionOption) {
|
||||
super(type, { value: "", value2: undefined });
|
||||
}
|
||||
|
||||
public clone() {
|
||||
const newCriterion = new DateCriterion(this.criterionOption);
|
||||
newCriterion.modifier = this.modifier;
|
||||
newCriterion.value = { ...this.value };
|
||||
return newCriterion;
|
||||
}
|
||||
|
||||
public encodeValue() {
|
||||
return {
|
||||
value: this.value.value,
|
||||
@@ -915,10 +940,6 @@ export class DateCriterion extends Criterion<IDateValue> {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
constructor(type: CriterionOption) {
|
||||
super(type, { value: "", value2: undefined });
|
||||
}
|
||||
}
|
||||
|
||||
export class TimestampCriterionOption extends CriterionOption {
|
||||
@@ -968,6 +989,17 @@ export function createMandatoryTimestampCriterionOption(value: CriterionType) {
|
||||
}
|
||||
|
||||
export class TimestampCriterion extends Criterion<ITimestampValue> {
|
||||
constructor(type: CriterionOption) {
|
||||
super(type, { value: "", value2: undefined });
|
||||
}
|
||||
|
||||
public clone() {
|
||||
const newCriterion = new TimestampCriterion(this.criterionOption);
|
||||
newCriterion.modifier = this.modifier;
|
||||
newCriterion.value = { ...this.value };
|
||||
return newCriterion;
|
||||
}
|
||||
|
||||
public encodeValue() {
|
||||
return {
|
||||
value: this.value?.value,
|
||||
@@ -1025,8 +1057,4 @@ export class TimestampCriterion extends Criterion<ITimestampValue> {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
constructor(type: CriterionOption) {
|
||||
super(type, { value: "", value2: undefined });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@ export class PerformersCriterion extends Criterion<ILabeledValueListValue> {
|
||||
super(PerformersCriterionOption, { items: [], excluded: [] });
|
||||
}
|
||||
|
||||
public clone() {
|
||||
const newCriterion = new PerformersCriterion();
|
||||
newCriterion.modifier = this.modifier;
|
||||
newCriterion.value = { ...this.value };
|
||||
return newCriterion;
|
||||
}
|
||||
|
||||
override get modifier(): CriterionModifier {
|
||||
return this._modifier;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,13 @@ export class PhashCriterion extends Criterion<IPhashDistanceValue> {
|
||||
super(PhashCriterionOption, { value: "", distance: 0 });
|
||||
}
|
||||
|
||||
public clone() {
|
||||
const newCriterion = new PhashCriterion();
|
||||
newCriterion.modifier = this.modifier;
|
||||
newCriterion.value = { ...this.value };
|
||||
return newCriterion;
|
||||
}
|
||||
|
||||
protected getLabelValue() {
|
||||
const { value, distance } = this.value;
|
||||
if (
|
||||
|
||||
@@ -40,6 +40,18 @@ export const RatingCriterionOption = new CriterionOption({
|
||||
export class RatingCriterion extends Criterion<INumberValue> {
|
||||
ratingSystem: RatingSystemOptions;
|
||||
|
||||
constructor(ratingSystem: RatingSystemOptions) {
|
||||
super(RatingCriterionOption, { value: 0, value2: undefined });
|
||||
this.ratingSystem = ratingSystem;
|
||||
}
|
||||
|
||||
public clone() {
|
||||
const newCriterion = new RatingCriterion(this.ratingSystem);
|
||||
newCriterion.modifier = this.modifier;
|
||||
newCriterion.value = { ...this.value };
|
||||
return newCriterion;
|
||||
}
|
||||
|
||||
public get value(): INumberValue {
|
||||
return this._value;
|
||||
}
|
||||
@@ -76,9 +88,4 @@ export class RatingCriterion extends Criterion<INumberValue> {
|
||||
return `${convertToRatingFormat(value, this.ratingSystem) ?? 0}`;
|
||||
}
|
||||
}
|
||||
|
||||
constructor(ratingSystem: RatingSystemOptions) {
|
||||
super(RatingCriterionOption, { value: 0, value2: undefined });
|
||||
this.ratingSystem = ratingSystem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,13 @@ export class StashIDCriterion extends Criterion<IStashIDValue> {
|
||||
});
|
||||
}
|
||||
|
||||
public clone() {
|
||||
const newCriterion = new StashIDCriterion();
|
||||
newCriterion.modifier = this.modifier;
|
||||
newCriterion.value = { ...this.value };
|
||||
return newCriterion;
|
||||
}
|
||||
|
||||
public get value(): IStashIDValue {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user