WebStorm autocompletion based on custom schema json files - javascript

I have some json schema files describing the structure of my objects. Here is an example:
{
"$schema" : "https://json-schema.org/draft/2019-09/schema",
"$ref" : "#/$defs/AdaugaPersoana",
"$defs" : {
"AdaugaPersoana" : {
"type" : "object",
"properties" : {
"id" : {
"type" : "string"
},
"numeComplet" : {
"$ref" : "#/$defs/NumeComplet"
},
"stare" : {
"$ref" : "#/$defs/Stare"
}
}
},
"NumeComplet" : {
"type" : "object",
"properties" : {
"nume" : {
"type" : "string"
},
"prenume" : {
"type" : "string"
},
"factory()" : {
"type" : "string"
}
},
"required" : [ "nume" ]
},
"Stare" : {
"type" : "string",
"enum" : [ "ACTIVAT", "DEACTIVAT" ]
}
}
}
Is there any way that WebStorm can use this schema to autocomplete when using a JavaScript variable?
Example JS code:
/** #type AdaugaPersoana */
const someVar = {};
someVar.numeComplet.nume //this should be autocompleted

Related

How to filter out text fields in a complex query?

I've got a lot of doc filters on my UI (date ranges, checkboxes, input fields), so the query is generated dynamically - that's why I decided to create a boolean query, and push everything to must array. This is the example of my request:
const {
body: {
hits
}
} = await esclient.search({
from: filterQuery.page || 0,
size: filterQuery.limit || 1000,
index,
body: query
});
Checkboxes (I used additional bool.should inside must array) and date range work perfectly, but term/match filtering is not working at all:
{
"query": {
"bool": {
"must": [
{"match": { "issueNumber": "TEST-10" }}
]
}
}
}
The query above gives me all the documents from the index that contains "TEST" (with their scores), if I change match to term - it returns an empty array.
As my field is of a type 'text', I've also tried filter query - ES still gives all the documents with 'TEST' word:
{
"query": {
"bool": {
"must": [
{
"bool": {
"filter": {
"match": {"issueNumber": "TEST-10"}
}
}
}
]
}
}
}
This is how my hit looks like:
{
"_index" : "test_elastic",
"_type" : "_doc",
"_id" : "bj213hj2gghg213",
"_score" : 0.0,
"_source" : {
"date" : "2019-11-26T13:27:01.586Z",
"country" : "US",
"issueNumber" : "TEST-10",
}
Can someone give me input on how to filter the docs properly in complex query?
This is the structure of my index:
{
"test_elasticsearch" : {
"aliases" : { },
"mappings" : {
"properties" : {
"country" : {
"type" : "text"
},
"date" : {
"type" : "date"
},
"issueNumber" : {
"type" : "text"
}
}
},
"settings" : {
"index" : {
"creation_date" : "1574759226800",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "PTDsdadasd-ERERER",
"version" : {
"created" : "7040299"
},
"provided_name" : "logs"
}
}
}
}
Ok, the problem is that your issueNumber field has not the right type, it should be keyword instead of text if your goal is to make exact searches on it. Same for country. Modify your mapping like this:
"properties" : {
"country" : {
"type" : "keyword"
},
"date" : {
"type" : "date"
},
"issueNumber" : {
"type" : "keyword"
}
}
Then reindex your data and your queries will work.

Mongoose / MongoDB query .find() any int > 0?

So I have a mongoose schema that looks like this.
var info = new mongoose.Schema(
{ '123': { available: { type: 'String' }, onOrder: { type: 'String' } },
'456': { available: { type: 'String' }, onOrder: { type: 'String' } },
'789': { available: { type: 'String' }, onOrder: { type: 'String' } }
});
I'm looking to find and number in the available field that is > 0. Only some of these will be filled at any given time. The "empty" String will always be filled with a number value of "0.00000000" if not some integer in it.
I'm looking for a query that will go through and find and string that isn't 0.00000000 or can convert the strings to integers then can find anything > 0.
I feel like my first thought of finding them based on strings is kinda hacky in a way and I'm looking for a more permanent way of retrieving numbers from a Database like this.
I've Attempted to accomplish this with $in already but I'm not able to get it to work.
you can do this in two ways, 1. $regexp 2. $where
$regexp
check all the string contents are numbers [0-9], and start with non zero or zero or dot followed by 0-9
regexp would be /^[1-9][0-9]|[.0][1-9]/
$where
use parseFloat check it's greater than zero
{ $where: function() { return parseFloat(this[123].available) > 0 } }
collection
> db.info.find()
{ "_id" : ObjectId("5a5edabdfee4c182f509f3ea"), "123" : { "available" : "0.00000000", "onOrder" : { "type" : "xyz" } } }
{ "_id" : ObjectId("5a5edabdfee4c182f509f3eb"), "123" : { "available" : "0.00000010", "onOrder" : { "type" : "xyz" } } }
{ "_id" : ObjectId("5a5edabdfee4c182f509f3ec"), "123" : { "available" : "100000000", "onOrder" : { "type" : "xyz" } } }
{ "_id" : ObjectId("5a5edabdfee4c182f509f3ed"), "123" : { "available" : "abc", "onOrder" : { "type" : "xyz" } } }
>
find with $regexp
> db.info.find( { "123.available" : /^[1-9][0-9]|[.0][1-9]/ } );
{ "_id" : ObjectId("5a5edabdfee4c182f509f3eb"), "123" : { "available" : "0.00000010", "onOrder" : { "type" : "xyz" } } }
{ "_id" : ObjectId("5a5edabdfee4c182f509f3ec"), "123" : { "available" : "100000000", "onOrder" : { "type" : "xyz" } } }
>
find with $where
> db.info.find( { $where: function() { return parseFloat(this[123].available) > 0 } } );
{ "_id" : ObjectId("5a5edabdfee4c182f509f3eb"), "123" : { "available" : "0.00000010", "onOrder" : { "type" : "xyz" } } }
{ "_id" : ObjectId("5a5edabdfee4c182f509f3ec"), "123" : { "available" : "100000000", "onOrder" : { "type" : "xyz" } } }
>
>

Meteor.js Data storage SimpleSchema object type: [array]

I would like to add some article attachments and these attachments that were associated with the article
Hi I have created schema data in a form:
Docs = new SimpleSchema({
fileName: {
type: String,
label: "Tytuł załącznika",
optional: true
},
fileId: {
type: String,
label: "Nazwa pliku",
autoform: {
afFieldInput: {
type: "cfs-file",
placeholder: 'Prosze dodaj załącznika...',
collection: "files"
}
},
optional: true
}
});
Schemas.Wydarzenie = new SimpleSchema({
...
docs:{
type: [Docs],
label: "Załączniki",
},
...
});
The package aldeed:autoform can save files in the array that is associated with the article by _id.
The data stored in the database schema for the Schemas.Wydarzenie:
{
"_id" : "re4RyFScYEAmSEnGB",
"docs" : [ {
"fileName" : "fsdfsdfsdfs f df fsf",
"fileId" : "mkEjjc5zjQW2Fdzuu"
}, {
"fileName" : "khjkhjkhkhjkhjj",
"fileId" : "YvtbaFT3e7EwgZwrf"
}
]
}
The data stored in the database schema for the "Docs":
{
"_id" : "mkEjjc5zjQW2Fdzuu",
"original" : {
"name" : "kazimierz.pdf",
"updatedAt" : ISODate("2015-10-13T11:46:37.370Z"),
"size" : 64098, "type" : "application/pdf"
},
"uploadedAt" : ISODate("2016-02-09T06:46:08.910Z"),
"copies" : {
"files" : {
"name" : "kazimierz.pdf",
"type" : "application/pdf",
"size" : 64098,
"key" : "files-mkEjjc5zjQW2Fdzuu-kazimierz.pdf",
"updatedAt" : ISODate("2016-02-09T06:46:08Z"),
"createdAt" : ISODate("2016-02-09T06:46:08Z")
}
}
}
{
"_id" : "YvtbaFT3e7EwgZwrf",
"original" : {
"name" : "porąbka.pdf",
"updatedAt" : ISODate("2015-10-13T11:46:42.075Z"),
"size" : 72654,
"type" : "application/pdf"
},
"uploadedAt" : ISODate("2016-02-09T06:46:09.208Z"),
"copies" : {
"files" : {
"name" : "porąbka.pdf",
"type" : "application/pdf",
"size" : 72654,
"key" : "files-YvtbaFT3e7EwgZwrf-porąbka.pdf",
"updatedAt" : ISODate("2016-02-09T06:46:09Z"),
"createdAt" : ISODate("2016-02-09T06:46:09Z")
}
}
}
You are reset higher data schema can be used without installing a package aldeed:autoform.
If so can someone explain to me how to go about it.

FS.Collection instance returning undefined when using find()

I'm somewhat new at web development so I apologize if I am using FSCollection incorrectly.
I have a FS.Collection instance that takes in audio files
LectureAudio = new FS.Collection("lectureAudio", {
stores: [new FS.Store.FileSystem("lectureAudio", {
path:"~/digicog/audioUpload",
filter: {
allow: {
contentTypes: ['audio/*'],
extensions: ['mp3', 'wav', 'MP3', 'WAV']
}
}
})]
});
And I am using an input file element to insert audio files into collection.
Template.audioControl.events({
'change #lecAudioPath': function (event) {
var files = document.getElementById("lecAudioPath").files;
if(files.length != 0){
var lecName = Router.current().params._id;
var audioFile = new FS.File(files[0]);
audioFile.metadata = {LectureId: lecName};
LectureAudio.insert(audioFile);
}
}
});
However when I type in LectureAudio.find().fetch() in the console for testing, I get empty brackets [ ].
Even though when I check my mongo database using:
>db.getCollection("cfs.lectureAudio.filerecord").find()
I see that my collection is populated.
{ "_id" : "wwyQtZZNwicbheCch", "copies" : { "lectureAudio" : { "name" : "fWnQyQpEWSXRDeuJq.mp3" } }, "original" : { "name" : "test1.mp3", "updatedAt" : ISODate("2013-08-16T16:07:40Z"), "size" : 8087475, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T06:05:53.589Z") }
{ "_id" : "3rBbFfnGAT3Z8Bkti", "copies" : { "lectureAudio" : { "name" : "Efn235HcCyGrm5TPx.mp3" } }, "original" : { "name" : "test2.mp3", "updatedAt" : ISODate("2013-08-16T16:07:52Z"), "size" : 8806339, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T06:17:06.234Z") }
{ "_id" : "RJ7LLH7XhgG2PnP9g", "copies" : { "lectureAudio" : { "name" : "fWnQyQpEWSXRDeuJq.mp3" } }, "original" : { "name" : "test3.mp3", "updatedAt" : ISODate("2013-08-16T16:07:52Z"), "size" : 8806339, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T06:18:30.454Z") }
{ "_id" : "9YY33kFFbP7oBMjmr", "copies" : { "lectureAudio" : { "name" : "y7KQmq3ReqcP7Pzyw.mp3" } }, "original" : { "name" : "test4.mp3", "updatedAt" : ISODate("2013-08-16T16:07:40Z"), "size" : 8087475, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T20:50:21.226Z") }
How do I get the collection to show?
You probably forgot to publish and subscribe to the collection.
On the server:
Meteor.publish('lecture_audio', function () {
return LectureAudio.find();
}
And on client:
Meteor.subscribe('lecture_audio');
More info in the docs here

jstree - adding child nodes which themselves contain children

I have some code in which I need the ability to add child nodes to a jstree which themselves contain children. The below code adds a 'child2' node correctly to 'child1' but ignores the child3 data. Any help much appreciated. Code follows:
<html>
<head>
<script type="text/javascript" src="http://static.jstree.com/v.1.0rc2/jquery.js"></script>
<script type="text/javascript" src="http://static.jstree.com/v.1.0rc2/jquery.jstree.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(function () {
$("#tree").jstree({
"json_data" : {
"data" : [
{
"data" : "parent",
"attr" : { "id" : "root.id" },
"children" : [ { "data" : "child1",
"attr" : { "id" : "child1.id" },
"children" : [ ] }
]
},
]
},
"plugins" : [ "themes", "json_data", "crrm" ]
});
});
$("#add").click(function() {
$("#tree").jstree("create", $("#child1\\.id"), "inside",
{ "data" : "child2", "attr" : { "id" : "child2.id" },
"children" : [ { "data" : "child3", "attr" : { "id" : "child3.id" }, "children": [ ] } ] },
function() { alert("added"); }, true);
});
});
</script>
</head>
<body>
<div id="tree" name="tree"></div>
<input type="button" id="add" value="add" />
</body>
</html>
First off, that's not valid json with the last comma inside the last bracket. Take that off:
[
{
"data" : "parent",
"attr" : {
"id" : "root.id"
},
"children" : [
{
"data" : "child1",
"attr" : {
"id" : "child1.id"
},
"children" : [ ]
}
]
}
]
Also, as of version 3.0 or perhaps before you can simply just insert a new node with json. Recursion is no longer needed.
I created json like so, which creates a folder called income and puts many text children underneath it but also those could be folders just like the parent with more content. See my function below which inserts this folder into the parent with all it's children:
{
"text" : "Income",
"id" : "_folder_income",
"state" : {
"opened" : true
},
"children" : [
{
"text" : "$125,000 - $150,000",
"state" : {
"selected" : true
},
"icon" : "jstree-file",
"id" : "6017897162332"
},
{
"text" : "$150,000 - $250,000",
"state" : {
"selected" : false
},
"icon" : "jstree-file",
"id" : "6017897374132"
},
{
"text" : "$250,000 - $350,000",
"state" : {
"selected" : false
},
"icon" : "jstree-file",
"id" : "6017897397132"
},
{
"text" : "$350,000 - $500,000",
"state" : {
"selected" : false
},
"icon" : "jstree-file",
"id" : "6017897416732"
},
{
"text" : "Over $500,000",
"state" : {
"selected" : false
},
"icon" : "jstree-file",
"id" : "6017897439932"
},
{
"text" : "$30,000 - $40,000",
"state" : {
"selected" : false
},
"icon" : "jstree-file",
"id" : "6018510070532"
},
{
"text" : "$100,000 - $125,000",
"state" : {
"selected" : false
},
"icon" : "jstree-file",
"id" : "6018510083132"
},
{
"text" : "$40,000 - $50,000",
"state" : {
"selected" : false
},
"icon" : "jstree-file",
"id" : "6018510087532"
},
{
"text" : "$75,000 - $100,000",
"state" : {
"selected" : false
},
"icon" : "jstree-file",
"id" : "6018510100332"
},
{
"text" : "$50,000 - $75,000",
"state" : {
"selected" : false
},
"icon" : "jstree-file",
"id" : "6018510122932"
}
]
}
This same json could also be used to fill a parent folder on tree instance:
/**
* inserts a new node (json object returned from url) into an existing node (parentNodeId), for the div ud in jsTreeName which is
* an instanced jstree.
* #param string jsTreeName {name of an instanced tree}
* #param string url {returns json}
* #param string parentNodeId {string of the parent node id}
*/
function insertUrlIntoNode(jsTreeName, url, parentNodeId) {
var nodeTree = getSynchronousJson(url);
var tree = $('#'+jsTreeName).jstree(true);
tree.deselect_all();
var sel = tree.create_node(parentNodeId, nodeTree);
//tree.deselect_all();
//tree.select_node(sel); //optionally you could select the new node after insersion
}
As far as I can see from the source, "create" function doesn't support creating multi-level tree at once. The method that gets called doesn't use and check the children attribute on passed data.
You need to do it yourself, something like that :
var recursivelyCreate = function (node, parentNodeId) {
tree.jstree("create", $("#"+parentNodeId), "inside", node, function() {}, true);
if(node.children){
$.each(node.children, function(i, child){
recursivelyCreate(child, node.attr.id);
});
}
};
recursivelyCreate(rootNodeYouWantToInsert,nodeParentId);

Categories

Resources