I'm working on a Flowchart editor and I want the ui.inspector to edit labels on links.
I did the following:
function createInspector(cellView) {
if (!inspector || inspector.options.cellView !== cellView) {
if (inspector) {
inspector.remove();
}
inspector = new joint.ui.Inspector({
inputs: {
labels:
attrs: {
text:{
text: { type: 'textarea', group: 'Labels', label: 'Label', index: 2 },
}
}
},
},
},
groups: {
labels:[ { label: 'Labels', index: 1 },
}],
cellView: cellView
});
$('#inspector-holder-create').html(inspector.render().el);
}
}
paper.on('cell:pointerdown', function(cellView) {
createInspector(cellView);
});
However, when I edit a link it shows in the JSON output:
"labels": {
"0": {
"attrs": {
"text": {
"text": "Text I entered"
}
}
}
},
but doesn't actually render on the link in the stencil.
I think the problem is with the { "0": part the inspector adds. I want to remove that and replace with it [ ] so the output will be
labels: [
{ attrs: { text: { text: 'label' } } }
]
What should I do ??
It is possible to define Inspector inputs with paths.
'labels/0/attrs/text/text': {
type: 'text',
group: 'Text',
index: 1,
label: 'Label'
}
Or as a combination of attributes nesting and paths.
'labels/0/attrs': {
text: {
text: {
type: 'text',
group: 'Text',
index: 1,
label: 'Label'
},
fontSize: {
type: 'number',
group: 'Text',
index: 2,
label: 'Font Size'
}
}
}
This is valid for Rappid v2.4.0+.
inspector = new joint.ui.Inspector({
inputs: {
'labels': [
{attrs: {
text: {
text: {
type: 'text',
group: 'someGroup',
index: 1,
label: "Label"
}
}
}}
]
}});
Related
I am using Node.js 16.17 and Express.
Forgive me if this is answered elsewhere, if a solution exists elsewhere, please point me in that direction.
On my server side, I have an array with objects with properties and their values. I want to be able to remove specific text/string from the property values.
What I Have
I currently have an array with objects (and sometimes arrays and object nested within):
DataArray =
[
{
page: {
results: [
{
id: '1234',
title: 'TextIWantA **(Text) I Dont Want**',
children: {
page: {
results: [
{
id: '5678',
title: 'ChildA TextIWant **(Text I) Dont Want**',
},
{
id: '9101',
title: 'ChildB TextIWant **(Text I) Dont Want**',
children: {
page: {
results: [
{
id: 'abcd',
title: 'GrandchildA TextIWant **(Text I (Dont) Want**',
}
]
}
}
},
],
},
},
},
{
id: '1121',
title: 'TextIWantB **(Text) I Dont Want**',
}
]
}
}
]
I am able to flatten this structure with this function:
function flatten(arr) {
const flattened = []
for (const { children, ...element } of arr) {
flattened.push(element)
if (children) {
flattened.push(...flatten(children.page.results))
}
}
return flattened;
}
const flat = [{ page: { results: flatten(DataArray[0].page.results) } }]
console.log(flat[0].page.results)
The returned data is:
[
{ id: '1234', 'page', title: 'TextIWantA **(Text) I Dont Want**' },
{ id: '5678', 'page', title: 'ChildA TextIWant **(Text I) Dont Want**' },
{ id: '9101', 'page', title: 'ChildB TextIWant **(Text I) Dont Want**' },
{ id: 'abcd', 'page', title: 'GrandchildA TextIWant **(Text I (Dont) Want**' },
{ id: '1121', 'page', title: 'TextIWantB **(Text) I Dont Want**' }
]
I am making an assumption that I have to change my text to a string in order to replace it then parse it again to turn back into an object. I'm happy to learn my assumption is true or incorrect, if incorrect, how to fix to be able to remove text.
So if I try to do a replace using the following, 1) it does not work and 2) it does not differentiate for the different text to remove (perhaps I just run multiple/different replaces/filters?):
const veryFlat = flat;
var veryFlatData = veryFlat.map(function(x){return x.toString().replace(/ **(Text) I Dont Want**/g, '');});
var removedTextData= JSON.parse(veryFlatData);
console.log(removedTextData);
Desired Result
I want to be able to remove all of the variances of Text I Dont Want, so the end result would look like (of now it will be flattened as seen above)
DataArray =
[
{
page: {
results: [
{
id: '1234',
title: 'TextIWantA',
children: {
page: {
results: [
{
id: '5678',
title: 'ChildA TextIWant',
},
{
id: '9101',
title: 'ChildB TextIWant',
children: {
page: {
results: [
{
id: 'abcd',
title: 'GrandchildA TextIWant',
}
]
}
}
},
],
},
},
},
{
id: '1121',
title: 'TextIWantB',
}
]
}
}
]
Each title is unique and I don't seem able to find anything to even say I've tried this or that.
I don't want to use .startswith or .length or .index and would prefer to avoid regex, and the example above using .replace doesn't seem to work.
How do I reach into these property values and rip out the text I don't want?
Thank you for any help you can provide.
I'm having some trouble creating a model that describes the object that I want to store in mongoDB.
This is the object:
simple: [
{
label: 'Satisfied customers',
children: [
{
label: 'Good food',
children: [
{ label: 'Quality ingredients' },
{ label: 'Good recipe' }
]
},
{
label: 'Good service (disabled node)',
children: [
{ label: 'Prompt attention' },
{ label: 'Professional waiter' }
]
},
{
label: 'Pleasant surroundings',
children: [
{ label: 'Happy atmosphere' },
{ label: 'Good table presentation' },
{ label: 'Pleasing decor' }
]
}
]
}
]
This is data that is input to a QTree: https://quasar.dev/vue-components/tree
I want to model this but this object can in theory expand indefinitely as each child can have children of it's own and so on. Is there a way to do this nicely in a Mongoose Schema? My search so far turned up empty.
Here is what I have now:
simple: [{
_id: false,
label: String,
children: [{
_id: false,
label: String,
}]
}]
I can ofcourse choose to limit the depth to a certain amount (say 5) and put that amount of nesting in my schema, but I'm trying to find a more elegant solution so that I dont have to do that.
I want tree structure in my Categories table.
So I tried this:
Categories model looks like:
import * as Sequelize from 'sequelize';
export default class CategoriesModel extends Sequelize.Model {
static init(sequelize, DataTypes) {
return super.init({
name: {
type: DataTypes.STRING,
},
}, {
modelName: 'categories',
sequelize,
});
}
}
association in my CategoriesModel class looks like:
static associate({ Categories }) {
this.nestedCategories = this.hasMany(Categories, {
as: 'nestedCategories',
foreignKey: 'parentId',
});
}
and when i tried to insert rows, for example:
sequelize.sync({ force: true }).then(() => {
models.Categories.create({
name: 'parent',
nestedCategories: [
{
name: 'child 1',
},
{
name: 'child 2',
nestedCategories: [
{
name: 'child 3',
}
],
},
],
}, {
include: [models.Categories.nestedCategories]
}).then(cat => {
console.log(cat.toJSON());
})
});
result is:
{
id: 1,
name: 'parent',
nestedCategories:
[ { id: 2,
name: 'child 1',
parentId: 1,
updatedAt: 2019-02-05T08:39:45.655Z,
createdAt: 2019-02-05T08:39:45.655Z },
{ id: 3,
name: 'child 2',
parentId: 1,
updatedAt: 2019-02-05T08:39:45.657Z,
createdAt: 2019-02-05T08:39:45.657Z } ],
updatedAt: 2019-02-05T08:39:45.624Z,
createdAt: 2019-02-05T08:39:45.624Z,
parentId: null
}
child 3 does not inserted in a table.
I dont understand what i'm doing wrong...
You need to specify one include per nested category in order to make your request parsed correctly.
Here I made a function to do this recursively based on model you want to create:
function buildIncludeRecursive(model, includeTemplate) {
const include = Object.assign({}, includeTemplate);
let currInclude = include;
let currModel = model;
while(currModel[includeTemplate.as]){
currInclude.include = [Object.assign({}, includeTemplate)];
currInclude = currInclude.includes[0];
currModel = currModel[includeTemplate.as];
}
return include;
}
const model = {
name: 'parent',
nestedCategories: [
{ name: 'child 1' },
{
name: 'child 2',
nestedCategories: [
{ name: 'child 3' }
]
},
],
};
const includeTemplate = {
model: models.Categories,
as: 'nestedCategories'
};
model.categories.create(model, {
include: buildIncludeRecursive(model, includeTemplate)
});
Here's what your include is gonna be in this case:
{
model: models.Categories,
as: 'nestedCategories',
include: [
{
model: models.Categories,
as: 'nestedCategories'
}
]
}
I made an index "user-name" with a custom made analyzer called 'autocomplete':
client.indices.create({
index: 'user-name',
type: 'text',
settings: {
analysis: {
filter: {
autocomplete_filter: {
type: 'edge-ngram',
min_gram: 1,
max_gram: 20
}
},
analyzer: {
autocomplete: {
type: 'custom',
tokenizer: 'standard',
filter: [
'lowercase',
'autocomplete_filter'
]
}
}
}
}
}
Then I try to reference this custom made analyzer by trying to use it in a mapping:
client.indices.putMapping({
index: 'user-name',
type: 'text',
body: {
properties: {
name: {
type: 'string',
analyzer: 'autocomplete',
search_analyzer: 'standard'
}
}
}
})
but then I get this error: "reason": "analyzer [autocomplete] not found for field [name]". Why isn't my autocomplete analyzer being detected? Thanks.
You're almost there. You simply need to put the index settings inside the body parameter:
client.indices.create({
index: 'user-name',
type: 'text',
body: {
settings: {
analysis: {
filter: {
autocomplete_filter: {
type: 'edge-ngram',
min_gram: 1,
max_gram: 20
}
},
analyzer: {
autocomplete: {
type: 'custom',
tokenizer: 'standard',
filter: [
'lowercase',
'autocomplete_filter'
]
}
}
}
}
}
}
my array list is below:
this.array_of_name = ko.observableArray([
{ name: 'All Ways' },
{ name: 'Brand Cars' },
{ name: 'Carrom' },
{ name: 'Ginger' },
{ name: 'Honey' },
{ name: 'Jar Jar' },
{ name: 'Bert' },
{ name: 'Kitjar' },
{ name: 'Denise' },
{ name: 'Numeric' },
{ name: 'Length' },
{ name: 'Orange' },
{ name: 'Panasonic' },
{ name: 'Rabbit' },
{ name: 'Tarzan' },
{ name: 'USA' },
{ name: 'Yield' },
{ name: 'Zen' }
]);
i want to remove all items from it using javascript or knockout.
And also want to add search functionality using javascript or knockout.
var newArray = [];
var a=["a","b","c"];
for(var i=0;i<a.length;i++)
if(a[i]!=="a") newArray.push(a[i]);
Or another approach
removeAll = function(ary, elem) {
return ary.filter(function(e) { return e != elem });
}
to make empty, just assign empty array to your variable.
ex: this.array_of_name = ko.observableArray([]);