I'm desperately looking to render this object programmatically, so I can work with it with handlebars.js, when I try to pass a property as it is of now, I do get an error about the fact that handlebars can process only "own" properties.
The object looks like this, I'm not able to use the (i guess getters?) properties with (...)
FrameNode {id: '555:42'}
id: "555:42"
absoluteBoundingBox: (...)
absoluteRenderBounds: (...)
absoluteTransform: (...)
attachedConnectors: (...)
backgroundStyleId: (...)
backgrounds: (...)
blendMode: (...)
bottomLeftRadius: (...)
bottomRightRadius: (...)
children: (...)
clipsContent: (...)
componentPropertyReferences: (...)
constrainProportions: (...)
constraints: (...)
cornerRadius: (...)
cornerSmoothing: (...)
counterAxisAlignItems: (...)
counterAxisSizingMode: (...)
dashPattern: (...)
Is it even possible to invoke these programmatically?
I tried really everything, but nothing seemed to work. It might just be my lack of knowledge though.
Related
I'm setting up swagger document in my small Nest.js app according to this documentation: https://docs.nestjs.com/recipes/swagger
How do I setup dto to correctly show schema in swagger? To be more specific, nested types. It shows only top level keys. If one of the keys is of type of something, it shows it just as empty object. Here is what I mean:
dto:
export class HealthCheckDataDto {
serverStatus: {} // dont have it typed yet;
dbStatus: MongoConnectionStateT;
}
swagger:
[
{
"serverStatus": {},
"dbStatus": {}
}
]
expected result in swagger example value:
[
{
"serverStatus": {},
"dbStatus": {
"isOnline": true,
"msg": "string"
}
}
]
This is the function:
#ApiResponse({ status: 200, description: 'blabla', type: [HealthCheckDataDto] })
#ApiResponse({ status: 500, description: 'blabla, but bad', type: [HealthCheckDataDto] })
#Get('/api/healthcheck')
healthCheckApp(#Res() res: Response<HealthCheckDataDto>) {
// check HCs and setup status code
const healthCheck: HealthCheckI = this.healthcheckService.getFullHealthCheck();
const statusCode = (healthCheck.dbStatus.isOnline) ? HttpStatus.OK : HttpStatus.INTERNAL_SERVER_ERROR;
// return that response
res.status(statusCode).json(healthCheck);
}
What I tried:
When I replaced type for exact params in dto, it shows it properly in swagger.
I did cross-check of dto against interface, where I added wrong field into 'isOnline' and it finds it and marks it, that it isnt good.
Schema is displayed in swagger, but also only top level, not the typed part. So its not just example value.
Checked Stack Overflow; found two related threads, but neither one solved it. One suggested to manually create sub-dtos instead of types. Well... I better not do that.
I'm doing something wrong, or missed something in documentation. Or maybe parser of that swagger module is unable to extract type/interface when generating json.
I missed one spot in NestJS Documentation: Generics and interfaces:
Since TypeScript does not store metadata about generics or interfaces,
when you use them in your DTOs, SwaggerModule may not be able to
properly generate model definitions at runtime.
Well, it makes sense.
In some specific scenarios (e.g. deeply nested arrays, matrices), you
may want to describe your type by hand.
So, the final setup that works for me is following
Create DTO without types, but matches type/interface structure just like in 'expected result' in the original question
request/response should be typed with dto, eg Result<SomeDto>
when you handle data in that function, type it with interface/type, not dto and you have crosscheck.
Like this data are valid, swagger is properly generated. For additional swagger informations, use decorators directly in DTO.
You can show types in Swagger automatically using the OpenAPI CLI plugin.
Add:
"compilerOptions": {
"plugins": ["#nestjs/swagger"]
}
to nest-cli.json, and add:
import { ApiProperty, ApiBody } from '#nestjs/swagger';
to each of your DTOs, and the plugin will automagically annotate and document your schemas!
According to the documentation from
types and parameters
you just have to use either
#Body(), #Query(), #Param()
then the swagger module will automatically populate things for you. this also requires that you update your nest-cli.json file to
{
"collection": "#nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"plugins": ["#nestjs/swagger/plugin"]
}
}
then all things should be done and generated for you.
just a heads up,if this doesn't automatically show them or show the schema to be empty, then you deocorate at least one entry of your dto with #ApiProperty() then refresh the page. this will get things done.
Having an object similar to:
const data = {
tasks: {
projects: [
name:'Project Name',
filters: [
{
name:'First Project Filter',
checked:false,
onChange:(event) => {
console.log(this.checked)
}
},
...
],
...
],
...
},
...
}
The problem at hand is how to reference the checked property without drilling through the entire object.
In the case above, it throws an error because this is undefined, so referencing this.checked is invalid.
I could extract from the event data properties so that I can get the
whole reference such as tasks.projects[0].filters[0].checked, but I
am wondering if an easier method is available.
The ideal solution would be a way to reference the surrounding properties of the function without traversing the entire object. Surely the function has a way to know that it is inside of an object so maybe something like parent().checked ?
If relative: I am using node.js and react to use this object to render a filtered sidebar that works with context to filter the data-set. I don't think that is relative as this seems like a pure JavaScript OOP situation.
I am using the npm version of Simple Schema. I have a schema defined like this:
const PageSchema = new SimpleSchema({
organizationId: String,
title: String,
published: Boolean,
slug: String,
content: {
type: Object,
optional: true
}
})
The 'content' value is meant to contain data exported from Draft JS using Draft's convertToRaw function. However, when I clean the data using Simple Schema, the content key/value gets completely removed from the object. No errors are thrown, it just quietly deletes that node.
I certainly did not expect a side-effect like this. Is there something I'm not understanding about Simple Schema's 'Object' type? Does it expect me to serialize an object as JSON first, or something? Or maybe there is something about the object literal exported by Draft JS that it doesn't like...?
Or is it possible Draft JS is doing something in its object export that Simple Schema finds unorthodox? Is this a Draft JS problem or a Simple Schema problem?
Here's a console.log of the data before cleaning:
{ organizationId: 'JEsvMiJeTgexkAuzH',
title: 'Test Title',
published: true,
slug: 'test-title',
content: { entityMap: {}, blocks: [ [Object] ] } }
And here's what it looks like after the cleaning:
{ organizationId: 'JEsvMiJeTgexkAuzH',
title: 'Test Title',
published: true,
slug: 'test-title' }
Any pointers/help would be greatly appreciated! I have not attempted to use object literals as values before when working with meteor data, so I'm sure there's just some fundamental thing I'm missing.
UPDATE: I tried inserting the data without calling clean() first, and this actually works just fine. However, this is, of course, a far-from-ideal workaround. But it does tell me there isn't anything about the data that Mongo or meteor collections object to.
I figured it out, and it's just that I somehow missed something very significant in the Simple Schema documentation:
If you have a key with type Object, the properties of the object will
be validated as well, so you must define all allowed properties in the
schema. If this is not possible or you don't care to validate the
object's properties, use the blackbox: true option to skip validation
for everything within the object.
Until such time as I determine the keys and contents I expect consistently from Draft JS, I am just setting blackbox to true for that value, like so, since I am basically okay with trusting Draft JS to provide the correct object keys:
const PageSchema = new SimpleSchema({
organizationId: String,
title: String,
published: Boolean,
slug: String,
content: {
type: Object,
blackbox: true,
optional: true
}
})
This solved my problem, and now the node containing the Draft JS exported content object is not deleted on calling Simple Schema clean.
I've configured an aggregation for my Component. It looks like this:
aggregations : {
busyDialog : {
type: "sap.m.BusyDialog",
multiple: false
}
}
So, the aggregation is called "busyDialog" and can contain objects of the type "sap.m.BusyDialog".
I'm also able to get the object with its settings via my.ui5.namespace.Component.getMetadata().getAggregations().busyDialog
However, I'm not sure what's the best way to add an item to it or access an already added control in the aggregation. Are there any methods like "addbusyDialog" or something?
Was following this:
http://help.sap.com/saphelp_hanaplatform/helpdata/en/01/87ea5e2eff4166b0453b9dcc8fc64f/content.htm?fullscreen=true
OpenUI5 automatically generates the following methods for aggregations where multiple is false (where item is the name of the aggregation):
setItem(oItem)
getItem()
destroyItem()
And it creates these methods where multiple is true:
addItem(oItem)
insertItem(oItem, iIndex)
getItems()
indexOfItem(oItem)
removeItem(vItem) // item or index of item
removeAllItems()
destroyItems()
To answer your specific question, the best way to manipulate your busyDialog aggregation is to use these generated methods:
myComponent.setBusyDialog(oBusyDialog);
myComponent.getBusyDialog();
myComponent.destroyBusyDialog();
Source: https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.base.ManagedObject.html
I have a relationship setup between my user object and my usergame object.
The relationship appears to be setup correctly, i can access usergames through a user object.
However, when I create a new usergame object, the user object does not update.
Could someone offer me a solution to this?
Relationship is setup like so:
class App.Models.User extends Backbone.RelationalModel
urlRoot: '/user'
relations: [
type: Backbone.HasMany
key: 'user_games'
relatedModel: 'App.Models.UserGame'
includeInJSON: true
collectionType: 'App.Collections.UserGames'
reverseRelation:
key: 'user'
]
From the documentation:
Q: (Reverse) relations or submodels don't seem to be initialized
properly (and I'm using CoffeeScript!)
A: You're probably using the syntax class MyModel extends
Backbone.RelationalModel instead of MyModel =
Backbone.RelationalModel.extend. This has advantages in CoffeeScript,
but it also means that Backbone.Model.extend will not get called.
Instead, CoffeeScript generates piece of code that would normally
achieve roughly the same. However, extend is also the method that
Backbone-relational overrides to set up relations and other things as
you're defining your Backbone.RelationalModel subclass.
That’s a shame, as I like Coffeescript’s extend syntax. Try it without, as explained in the documentation?