-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
233 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
const subCondSchema = { | ||
iconlib: "spectre", | ||
theme: "html", | ||
// The schema for the editor | ||
schema: { | ||
additionalProperties: false, | ||
title: "Condition", | ||
$ref: "#/definitions/cond", | ||
definitions: { | ||
cond: { | ||
type: "object", | ||
id: "cond", | ||
defaultProperties: [ | ||
"not", | ||
], | ||
minProperties: 2, | ||
maxProperties: 2, | ||
properties: { | ||
not: { | ||
title: "Not", | ||
id: "not", | ||
type: "boolean", | ||
format: "checkbox", | ||
default: false, | ||
required: true, | ||
}, | ||
gc: { | ||
title: "Group", | ||
type: "object", | ||
id: "gc", | ||
defaultProperties: ["logic", "group"], | ||
properties: { | ||
logic: { | ||
title: "Logic", | ||
id: "logic", | ||
type: "integer", | ||
enum: [0, 1, 2], | ||
options: { | ||
enum_titles: ["And", "Or", "Xor"], | ||
}, | ||
required: true, | ||
}, | ||
group: { | ||
title: "Conditions", | ||
id: "group", | ||
type: "array", | ||
items: { | ||
title: "Condition", | ||
$ref: "#/definitions/cond", | ||
}, | ||
required: true, | ||
minItems: 2, | ||
maxItems: 10, | ||
} | ||
}, | ||
additionalProperties: false, | ||
}, | ||
nc: { | ||
title: "Number", | ||
type: "object", | ||
id: "nc", | ||
defaultProperties: ["key", "op", "val"], | ||
properties: { | ||
key: { | ||
title: "Attribute", | ||
id: "key", | ||
type: "string", | ||
required: true, | ||
minLength: 1, | ||
maxLength: 20, | ||
pattern: "^[a-z0-9]+$", | ||
options: { | ||
inputAttributes: { | ||
placeholder: "e.g. price, revenue, time, ...", | ||
}, | ||
}, | ||
}, | ||
op: { | ||
title: "Operator", | ||
id: "op", | ||
type: "integer", | ||
enum: [1, 2, 3, 4, 5], | ||
default: 3, | ||
options: { | ||
enum_titles: [">", "≥", "=", "≤", "<"], | ||
}, | ||
required: true, | ||
}, | ||
val: { | ||
title: "Value", | ||
id: "val", | ||
type: "number", | ||
required: true, | ||
} | ||
}, | ||
additionalProperties: false, | ||
}, | ||
tc: { | ||
title: "Text", | ||
type: "object", | ||
id: "tc", | ||
defaultProperties: ["key", "term", "exact"], | ||
properties: { | ||
key: { | ||
title: "Attribute", | ||
id: "key", | ||
type: "string", | ||
required: false, | ||
minLength: 0, | ||
maxLength: 20, | ||
pattern: "^[a-z0-9]*$", | ||
options: { | ||
inputAttributes: { | ||
placeholder: "e.g. language, source, title, ...", | ||
} | ||
}, | ||
}, | ||
term: { | ||
title: "Any of words", | ||
id: "term", | ||
type: "string", | ||
required: true, | ||
options: { | ||
inputAttributes: { | ||
placeholder: "e.g. Tesla, iPhone, ...", | ||
} | ||
}, | ||
}, | ||
exact: { | ||
title: "Exact Match", | ||
id: "exact", | ||
type: "boolean", | ||
format: "checkbox", | ||
default: false, | ||
required: true, | ||
} | ||
}, | ||
additionalProperties: false, | ||
}, | ||
} | ||
}, | ||
} | ||
} | ||
}; |
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,38 @@ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="theme-color" content="#0ed3ff"> | ||
|
||
<title>Awakari App</title> | ||
|
||
<script src="https://telegram.org/js/telegram-web-app.js"></script> | ||
|
||
<link rel="stylesheet" href="spectre-icons.min.css"> | ||
<link href="tailwind.output.css" rel="stylesheet"> | ||
<link rel="stylesheet" href="style.css"> | ||
|
||
<script src="jsoneditor.min.js"></script> | ||
<script src="sub-cond-schema.js"></script> | ||
|
||
</head> | ||
<body onload="loadSubscription()"> | ||
|
||
<div id="sub_new" class="flex-1 flex flex-col w-[320px] mx-auto" style="display: flex"> | ||
<p class="py-2 text-md">View or edit the subscription's matching condition:</p> | ||
<form class="space-y-2"> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div id="sub_cond_editor"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="sub-details.js"></script> | ||
</form> | ||
<p class="py-2 text-xs">Id: <pre id="subId"></pre></p> | ||
</div> | ||
|
||
</body> | ||
</html> |
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,47 @@ | ||
// Initialize the editor | ||
const editor = new JSONEditor(document.getElementById("sub_cond_editor"), subCondSchema); | ||
|
||
// Hook up the validation indicator to update its | ||
// status whenever the editor changes | ||
editor.on('change', function () { | ||
// Get an array of errors from the validator | ||
const errors = editor.validate(); | ||
// Not valid | ||
if (errors.length) { | ||
console.log(errors); | ||
} | ||
}); | ||
|
||
function loadSubscription() { | ||
// | ||
const urlParams = new URLSearchParams(window.location.search); | ||
const id = urlParams.get("id"); | ||
document.getElementById("subId").innerHTML = urlParams.get("id"); | ||
// | ||
let authToken = sessionStorage.getItem("authToken"); | ||
let userId = sessionStorage.getItem("userId"); | ||
let optsReq = { | ||
method: "GET", | ||
headers: { | ||
"Authorization": `Bearer ${authToken}`, | ||
"X-Awakari-Group-Id": defaultGroupId, | ||
"X-Awakari-User-Id": userId, | ||
}, | ||
cache: "default", | ||
} | ||
fetch(`/v1/sub/${id}`, optsReq) | ||
.then(resp => { | ||
if (!resp.ok) { | ||
throw new Error(`Request failed with status: ${resp.status}`); | ||
} | ||
return resp.json(); | ||
}) | ||
.then(data => { | ||
if (data != null) { | ||
editor.setValue(data.cond); | ||
} | ||
}) | ||
.catch(err => { | ||
alert(err); | ||
}); | ||
} |
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