How to interact with a Component's aggregation - javascript

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

Related

Vue-multiselect: How to convert object to array for use in options prop?

I am using vue-multiselect like so:
<multiselect
id="customer_last_name_input"
v-model="value"
:options="activeUserProfiles"
label="lastname"
placeholder="Select or search for an existing customer"
track-by="uid"
:close-on-select="true"
#select="onSelect"
#remove="onRemove"
:loading="isLoading"
:custom-label="customerSelectName"
aria-describedby="searchHelpBlock"
selectLabel=""
>
...that grabs the list of active customers from an Array and then makes them available in a nice select menu.
This works good. However, I need to add another option from another resource (called customerNone) to the options prop and but the data is returned as an Object like so:
{"uid":1,"lastname":"None Given","firstname":"User","email":null,"phone":null...blah}
The vue-multiselect docs state that the :option prop MUST be an Array.
Question: What is the best way for me to handle this in the vue-multiselect component? Here's my attempt to help explain what I am trying to do (not sure if this is the best way to handle it). Unfortunately, my attempt causes a console error (see below):
I am passing a prop down called noCustomer which, if is true, I need to use customerNone profile on :options:
<multiselect
:options="noCustomer ? customerNone : getActiveUserProfiles"
>
here's the error:
Invalid prop: type check failed for prop "options". Expected Array, got Object
Is there a way I can convert the customerNone object to an array of object? Thanks!
You could wrap the customerNone object in brackets at the time that you pass it to the <multiselect> like [customerNone].
This syntax creates a new array on the fly, having 1 element that is the object variable:
<multiselect
:options="noCustomer ? [customerNone] : getActiveUserProfiles"
>
Update for comments
In order to auto-select the generic option when it's available, use a watch on the noCustomer prop to set value whenever noCustomer === true:
watch: {
noCustomer(newValue, oldValue) {
if(newValue) { // Checking that `noCustomer === true`
this.value = this.customerNone;
}
}
}

Load includes on existing model

I'm trying to load includes on an existing model in sequelize. In express we pre check the models to see if they exist in the middleware.
So once we're in the actual "controller" we want to run some includes on that existing model that is passed in.
req.models.item.incude([
{model: Post, as: 'posts'}
])
Is there any way to accomplish this?
EDIT:
I know we can do something like this.
return req.models.item.getThing()
.then(function (thing) {
req.models.item.thing = thing;
return req.models.item;
});
But:
My expansions for includes are a dynamic property that come via url parameters, so they are not know ahead of time.
It I return the above you will not see the "thing" in the response. I need it nicely built as part of the original instance.
Something like a .with('thing', 'other.thing'); notation would be nice. Or in the case of sequelize .with({include: ...}); or .include([{model: ...}]);
If the variable req.models.item is already an Instance but without its other related instances ("includes"), then you could include them using something like the following code:
Item.findAll({
where: req.models.item.where(),
include: [{
model: SomeAssociateModel,
}]
})
.then(function(itemWithAssoc) {
// itemWithAssoc is an Instance for the same DB record as item, but with its associations
});
See here for some documentation. See here for a script demo'ing this.
Update: Given the instance, how do I just get the associated models?
To do this just use the automatically generated "getAssociation" getter functions, e.g.:
function find_associations_of_instance(instance) {
return instance.getDetails();
}
I've updated the script to include this as an example. For more information on these functions, see the SequelizeJS docs.

Ember - how to convert this.get('model') to a js object

I am building an Ember component and it's being passed a model
{{ratings-summary-comp model=model}}
So you can call this model inside an action on the component's js file, like this:
this.get('model')
When I log this in the browser console, it outputs some kind of class:
Class {id: "1", store: Class, container: Container, _internalModel: InternalModel, currentState: Object…}
I want to convert this to a normal JS-object consisting of the model's attributes, so I can call the attributes like this:
model["attribute"]
This is so I can push a whitelist of attributes to an arrary inside the action.
How?
The model is just another Ember Object. You access its properties with get, as in
this.get('model').get(attribute)
And in the case of multiple attributes you can use getProperties:
this.get('model').getProperties('firstAttribute', 'secondAttribute', ....);
If you just need an array of attribute names, you can use Object.keys as suggested in this post on the ember github issues pages.
Running Object.keys(this.get("model")) will give you an array of attribute names.
Here's a JSBin example
Edit - The post uses Ember.keys, but that is now deprecated in favor of Object.keys.

Implementing Backbone.Subset.js in Backbone.js to filter Models from a parent Collection

In this stackoverflow post i read about filtering backbone collections and using subsets.
One answer (by sled) recommends using backbone.subset.js (usage example).
I could not find any further resources on backbone.subset.js and I failed implementing it into my project.
It seems like backbone.subset.js is the perfect solution for what i'm trying to achieve.
(Having one "parent" collection that holds all models at all times, and depending on user input filtering the relevant models from the parent collection into a backbone.subset collection.)
My "parent" collection, holding all tasks:
var TasksAll = Backbone.Collection.extend({
url: '/tasks', // the REST url to retrieve collection data
model: Task // the models of which the collection consists of
});
var allTasks = new TasksAll();
Now i want to create a subset collection for e.g. tasks where task.status = 0:
var TasksTrash = new Backbone.Subset({
superset: allTasks,
filter: function(Task) {
return Task.isTrash();
}
});
var trashTasks = new TasksTrash();
Whereas inside the Task model, the method "isTrash" returns true if:
this.get('status') == 0
a) Are there any more resources on backbone.subset.js?
b) How do I implement above scenario?
c) Can I pass 'superset' and 'filter' options as params to the Backbone.Subset init function?
d) I looked into the backbone.subset.js code, when I 'reset' my parent Collection my subset Collections should be updated straight away, right?
PS: I'm fairly new to Backbone. Thanks for your help.
Looking at the source for backbone-subset, it looks as though there is a pre-initialization hook which you could utilize in order to make the 'sieve' or filter available as an option or argument:
https://github.com/masylum/Backbone.Subset/blob/master/backbone.subset.js#L50
As for providing parent as an argument, there is an outstanding patch to add that exact functionality:
https://github.com/masylum/Backbone.Subset/pull/5
With it, you can pass in parent as an option, if it is not an option the library will fall back to looking for it on the object Prototype

Filtering for detail records in dojo

I have a page with a dijit.Tree, and a dojox.grid.EnhancedGrid both hooked up to some hierarchical data in an ItemFileWriteStore. When the user clicks on an item in the tree, I want to be able to show only the immediate children of that item in the grid, along with their attributes. This is a rather common pattern in database applications, but I can't find any examples of this, or perhaps I'm looking in the wrong place.
Looking at the grid docs, I see a setQuery method on the DataGrid. However, looking at the query syntax for ItemFileReadStore, I don't see anything that would let me specify to fetch only the children of a given item. Is there something I'm missing, is there another way to do this?
Using dojo 1.5.
(Edited for clarity)
Well, since no one answered, I came up with my own solution. I figured that this should be something that should have been built in to the DataStore framework, so I found an appropriate method in ItemFileReadStore to hook into, and extended it to add some query options to allow detail queries.
The following code adds two available QueryOptions arguments (parentItem, parentAttribute) which specify a parent item and a parent attribute for detail drill-down queries. They aren't compatible with the 'deep' option as the expected result of a combination of those two isn't clear.
dojo.extend(dojo.data.ItemFileReadStore, {
_getItemsArray: function(/*object?*/queryOptions) {
if (queryOptions) {
if (queryOptions.deep && queryOptions.parentItem) {
throw "Invalid query: a drill-down search can not be 'deep'"
}
if (queryOptions.deep) {
return this._arrayOfAllItems;
}
if (queryOptions.parentItem) {
if (!queryOptions.parentAttribute) {
throw "Invalid query: an attribute is required for drill-down searches.";
}
return this.getValues(queryOptions.parentItem,queryOptions.parentAttribute);
}
}
return this._arrayOfTopLevelItems;
}
});
The above code is available for anyone to use.

Categories

Resources