Skip to content

Commit

Permalink
Implements #31, adds date comparitors
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkrins committed Apr 16, 2024
1 parent a700c2c commit 92f54e5
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 22 deletions.
6 changes: 3 additions & 3 deletions client/src/components/Connectors/Connectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { modals } from '@mantine/modals';

function findDependencies(schema: Schema, value: string) {
for (const rule of (schema.rules||[])) {
if (rule.primary === value) return `schema '${schema.name}'`;
if (rule.primary === value) return `schema ${schema.name}, primary`;
for (const secondary of (rule.secondaries||[])) {
if (secondary.primary === value) return `schema '${schema.name}'`;
if (secondary.primary === value) return `schema ${schema.name}, secondary `;
}
}
for (const connector of (schema.connectors||[])) {
if (connector.proxy === value) return `connector '${connector.name}'`;
if (connector.proxy === value) return `connector ${connector.name}, proxy`;
}
}

Expand Down
5 changes: 3 additions & 2 deletions client/src/components/Rules/Editor/Conditions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActionIcon, Box, Button, Grid, Group, Menu, Select, Text, TextInput, To
import { UseFormReturnType } from "@mantine/form";
import { IconChevronDown, IconGripVertical, IconTrash, IconCodeAsterix, IconDots, IconCopy } from "@tabler/icons-react";
import { useContext } from "react";
import { availableConditions, mathOperators, stringOperators } from "../../../modules/common";
import { availableConditions, mathOperators, stringOperators, dateOperators } from "../../../modules/common";
import SelectConnector from "../../Common/SelectConnector";
import SchemaContext from "../../../providers/SchemaContext2";
import useTemplater from "../../../hooks/useTemplater";
Expand Down Expand Up @@ -138,7 +138,7 @@ export default function Conditions( { form, label, action, allow = [] }: {form:
<Grid.Col c="dimmed" span="content">
{condition.label}
</Grid.Col>}
{(c.type==='string'||c.type==='math'||c.type==='file')?
{(c.type==='string'||c.type==='math'||c.type==='file'||c.type==='date')?
<Grid.Col span="auto">
<TextInput placeholder='Key'
{...templateProps(form, `conditions.${index}.key`)}
Expand All @@ -158,6 +158,7 @@ export default function Conditions( { form, label, action, allow = [] }: {form:
checkIconPosition="right"
data={ {
string: stringOperators,
date: dateOperators,
math: mathOperators,
group: groupOperators,
ou: ouOperators,
Expand Down
15 changes: 14 additions & 1 deletion client/src/modules/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IconArrowBarToRight, IconBinaryTree2, IconCirclesRelation, IconCloudUpload, IconCopy, IconEqualNot, IconFile, IconFileText, IconFileTypeCsv, IconFileTypeDocx, IconFileTypeXls, IconFileZip, IconFolder, IconFolderShare, IconKey, IconLock, IconLockOpen, IconMathFunction, IconPencil, IconPhoto, IconPlus, IconSchool, IconTemplate, IconTerminal, IconTrash, IconUserQuestion, IconUsersGroup, TablerIconsProps } from '@tabler/icons-react';
import { IconArrowBarToRight, IconBinaryTree2, IconCalendar, IconCirclesRelation, IconCloudUpload, IconCopy, IconEqualNot, IconFile, IconFileText, IconFileTypeCsv, IconFileTypeDocx, IconFileTypeXls, IconFileZip, IconFolder, IconFolderShare, IconKey, IconLock, IconLockOpen, IconMathFunction, IconPencil, IconPhoto, IconPlus, IconSchool, IconTemplate, IconTerminal, IconTrash, IconUserQuestion, IconUsersGroup, TablerIconsProps } from '@tabler/icons-react';
import { IconUserPlus, IconFileTypePdf, IconPrinter } from '@tabler/icons-react';
import EnableUser from '../components/Rules/Editor/Operations/DirEnableUser';
import CreateUser from '../components/Rules/Editor/Operations/DirCreateUser';
Expand Down Expand Up @@ -60,6 +60,13 @@ export const mathOperators = [
{ label: '<= Lesser Than, Or Equal To', value: '<=' },
]

export const dateOperators = [
{ label: '== Equal To', value: 'date.==' },
{ label: '!= Not Equal To', value: 'date.!=' },
{ label: 'After', value: 'date.>' },
{ label: 'Before', value: 'date.<' },
]

export const availableConditions: {
label: string,
id: string,
Expand All @@ -85,6 +92,12 @@ export const availableConditions: {
Icon: IconFile,
color: "lime",
},
{
label: "Date Constraint",
id: 'date',
Icon: IconCalendar,
color: "red",
},
{
label: "Status",
id: 'status',
Expand Down
2 changes: 1 addition & 1 deletion client/src/typings/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface Doc {
}

interface Condition {
type: 'string' | 'math' | 'group' | 'ou' | 'file';
type: string;
key: string;
operator: string;
value: string;
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"adm-zip": "^0.5.12",
"axios": "^1.6.8",
"croner": "^8.0.2",
"dayjs": "^1.11.10",
"fastify": "^4.26.2",
"fastify-cors": "^6.1.0",
"fastify-multer": "^2.0.3",
Expand Down Expand Up @@ -39,6 +40,7 @@
"yaml": "^2.4.1"
},
"devDependencies": {
"@fastify/type-provider-json-schema-to-ts": "^3.0.0",
"@types/adm-zip": "^0.5.5",
"@types/fs-extra": "^11.0.4",
"@types/handlebars": "^4.1.0",
Expand All @@ -50,7 +52,6 @@
"@types/tough-cookie": "^4.0.5",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"@fastify/type-provider-json-schema-to-ts": "^3.0.0",
"eslint": "^8.56.0",
"npm-run-all": "^4.1.5",
"tsx": "^4.7.2",
Expand Down
5 changes: 5 additions & 0 deletions server/src/components/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Doc } from "../db/models.js";
import winston from 'winston';
import fs from 'fs-extra';
import { FastifyInstance } from "fastify";
import dayjs from "dayjs";
import { xError } from "../modules/common.js";
import { Rule, Schema } from "./models.js";
import { schemas } from "../routes/schema.js";
Expand Down Expand Up @@ -129,6 +130,10 @@ async function compare(key: string, value: string, operator: string, connections
case '<=': return Number(key) <= Number(value);
case 'file.exists': return fs.existsSync(key);
case 'file.notexists': return !fs.existsSync(key);
case 'date.==': return (dayjs(key).isSame(dayjs(value)));
case 'date.!=': return !(dayjs(key).isSame(dayjs(value)));
case 'date.>': return (dayjs(key).isAfter(dayjs(value)));
case 'date.<': return (dayjs(key).isBefore(dayjs(value)));
default: return false;
}
}
Expand Down
29 changes: 15 additions & 14 deletions server/src/components/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export default async function connect(schema: Schema, connectorName: string, con
for (const row of rows){
if (keyed[row[id]]) continue;
keyed[caseSen?row[id]:row[id].toLowerCase()] = row;
rows.push(row);
}
connection = { rows, keyed, provider }; break;
}
Expand Down Expand Up @@ -328,38 +327,40 @@ export class STMC extends ProviderBase {
}
}


interface folder {
name: string,
type: string,
size: string,
created: string,
modified: string,
accessed: string,
[k: string]: string,
}
export interface FOLDEROptions extends Provider {
name: string;
path: string;
}
export class FOLDER extends ProviderBase {
public name: string;
private path: string;
public contents: {
name: string,
type: string,
size: string,
created: string,
modified: string,
accessed: string,
[k: string]: string,
}[] = [];
public contents: folder[] = [];
constructor(options: FOLDEROptions) {
super(options);
this.name = options.name;
this.path = options.path;
this.contents = (fs.readdirSync(this.path)||[]).map(name=> {
for (const name of fs.readdirSync(this.path)){
const stats = fs.statSync(`${this.path}/${name}`);
const type = stats.isFile() ? 'file' : stats.isDirectory() ? 'directory' : 'unknown';
return {
this.contents.push({
name,
type,
size: String(stats.blksize),
created: String(stats.ctime),
modified: String(stats.mtime),
accessed: String(stats.atime),
}
});
})
}
}
async validate(): Promise<true> {
if (!this.path || !fs.existsSync(this.path)) throw new xError("Path does not exist.", "path");
Expand Down

0 comments on commit 92f54e5

Please sign in to comment.