-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added the ability to test media items against a rule, returning…
… a detailed execution breakdown * chore: Add backend code for rule statistics. Also add an API endpoint to test a single media item * refactor: Add application to rule statistics output name * chore: Add UI modal * chore: UI - button margin * refactor: Fix broken seasons / episodes after rule comparator refactor * refactor: Add a global statistic result indicating if the item matched the complete rule * refactor: add info header * refactor: Added validation for media type & improved info messages * refactor: button caps * refactor: import/export : fetch identifier from id instead of array location * refactor: Responsive monaco editor height * fix(collection): Clicking on the card will now navigate to the details page
- Loading branch information
Showing
28 changed files
with
1,589 additions
and
722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
server/src/modules/rules/constants/constants.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { RuleConstants, RuleType } from './rules.constants'; | ||
|
||
export interface ICustomIdentifier { | ||
type: string; | ||
value: string | number; | ||
} | ||
|
||
@Injectable() | ||
export class RuleConstanstService { | ||
ruleConstants: RuleConstants; | ||
|
||
constructor() { | ||
this.ruleConstants = new RuleConstants(); | ||
} | ||
|
||
public getRuleConstants() { | ||
return this.ruleConstants; | ||
} | ||
|
||
public getValueIdentifier(location: [number, number]) { | ||
const application = this.ruleConstants.applications.find( | ||
(el) => el.id === location[0], | ||
)?.name; | ||
|
||
const rule = this.ruleConstants.applications | ||
.find((el) => el.id === location[0]) | ||
?.props.find((el) => el.id === location[1])?.name; | ||
|
||
return application + '.' + rule; | ||
} | ||
|
||
public getValueHumanName(location: [number, number]) { | ||
return `${this.ruleConstants.applications.find( | ||
(el) => el.id === location[0], | ||
)?.name} - ${this.ruleConstants.applications | ||
.find((el) => el.id === location[0]) | ||
?.props.find((el) => el.id === location[1])?.humanName}`; | ||
} | ||
|
||
public getValueFromIdentifier(identifier: string): [number, number] { | ||
const application = identifier.split('.')[0]; | ||
const rule = identifier.split('.')[1]; | ||
|
||
const applicationConstant = this.ruleConstants.applications.find( | ||
(el) => el.name.toLowerCase() === application.toLowerCase(), | ||
); | ||
|
||
const ruleConstant = applicationConstant.props.find( | ||
(el) => el.name.toLowerCase() === rule.toLowerCase(), | ||
); | ||
return [applicationConstant.id, ruleConstant.id]; | ||
} | ||
|
||
public getCustomValueIdentifier(customValue: { | ||
ruleTypeId: number; | ||
value: string; | ||
}): ICustomIdentifier { | ||
let ruleType: RuleType; | ||
let value: string | number; | ||
switch (customValue.ruleTypeId) { | ||
case 0: | ||
if (+customValue.value % 86400 === 0 && +customValue.value != 0) { | ||
// when it's custom_days, translate to custom_days | ||
ruleType = new RuleType('4', [], 'custom_days'); | ||
value = (+customValue.value / 86400).toString(); | ||
} else { | ||
// otherwise, it's a normal number | ||
ruleType = RuleType.NUMBER; | ||
value = +customValue.value; | ||
} | ||
break; | ||
case 1: | ||
ruleType = RuleType.DATE; | ||
value = customValue.value; | ||
break; | ||
case 2: | ||
ruleType = RuleType.TEXT; | ||
value = customValue.value; | ||
break; | ||
case 3: | ||
ruleType = RuleType.BOOL; | ||
value = customValue.value == '1' ? 'true' : 'false'; | ||
break; | ||
} | ||
|
||
return { type: ruleType.humanName, value: value }; | ||
} | ||
|
||
public getCustomValueFromIdentifier(identifier: ICustomIdentifier): { | ||
ruleTypeId: number; | ||
value: string; | ||
} { | ||
let ruleType: RuleType; | ||
let value: string; | ||
|
||
switch (identifier.type.toUpperCase()) { | ||
case 'NUMBER': | ||
ruleType = RuleType.NUMBER; | ||
value = identifier.value.toString(); | ||
break; | ||
case 'DATE': | ||
ruleType = RuleType.DATE; | ||
value = identifier.value.toString(); | ||
break; | ||
case 'TEXT': | ||
ruleType = RuleType.TEXT; | ||
value = identifier.value.toString(); | ||
break; | ||
case 'BOOLEAN': | ||
ruleType = RuleType.BOOL; | ||
value = identifier.value == 'true' ? '1' : '0'; | ||
break; | ||
case 'BOOL': | ||
ruleType = RuleType.BOOL; | ||
value = identifier.value == 'true' ? '1' : '0'; | ||
break; | ||
case 'CUSTOM_DAYS': | ||
ruleType = RuleType.NUMBER; | ||
value = (+identifier.value * 86400).toString(); | ||
} | ||
|
||
return { | ||
ruleTypeId: +ruleType.toString(), // tostring returns the key | ||
value: value, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.