How to create TreeTable with Grouping Header without subitems UI5? - grouping

I'm quite new to UI5 and searched a long time for a solution now, but I couldn't find any, so I hope someone can help me out here.
Given the following example model:
let test = [
{"name":"TestWithSubitems", "subItems":
[{"color": "#ff00ff", "id": -1, "name": "subitem", "isUsed": "true"}]},
{"name":"TestWithoutSubitems", "subItems":[]}]
this.getView().setModel(new JSONModel(test), "test");
I want my treetable to group the items based on the object name.In case there is no subItem like in the "TestWithoutSubitems" object, I want a group header to be shown, that is not expandable.
<t:TreeTable
id="randomId"
class="sapUxAPObjectPageSubSectionAlignContent"
ariaLabelledBy="title"
useGroupMode="true"
groupHeaderProperty='name'
rows="{
path: 'test>/'
}"
visibleRowCount= 'length'
rowSelectionChange=".onSelectionChange"
toggleOpenState=".onToggleState">
<t:columns>
<t:Column>
<m:Text text="{i18n>Configure.Object.Column.Color}" />
<t:template>
<core:Icon src="sap-icon://color-fill" color="(${test>color}"/>
</t:template>
</t:Column>
----other columns not shown to reduce complexity----
</t:columns>
</t:TreeTable>
Currently it looks like this:
I would like it to look like this:
Is there any way to do this?Help is really appreciated :)

Related

Is it possible to add a a variable within a placeholder transform in Visual Studio Code?

I am looking to write an visual studio code user snippet like this:
"Surround With Div": {
"prefix": "sdiv",
"body": ["${1/(.*)/<div class=\"${1}\">${TM_SELECTED_TEXT}<\\/div>/}"],
"description": "Surround With Div"
}
But it does not seem to be working. Is there any way I can make something like this work? Using the variable inside the result of the regex transform?
To clarify for people:
What I was trying to achieve is this:
Select a portion of html document
Type sdiv over it to get the snippet
write something like -> header for the class name...
then when I would hit TAB I would get a div with the class header and the content I first selected inside it
But I realized you can't do something like that...could have done it with $CLIPBOARD but had to copy it first
So I decided to do something a bit different using a keybinding instead.
It is actually more straightforward than it seems. You do not need a transform at all - you can't put a variable like $TM_SELECTED_TEXT or $CLIPBOARD inside a transform anyway.
"Surround With Div": {
"prefix": "sdiv",
"body": [
"<div class=\"${1}\">${TM_SELECTED_TEXT}</div>"],
"description": "Surround With Div"
}

How to query with Loopback JS model string parameter contains in regexp array?

I tried to query Loopback js Model using "inq" (mongo $in) syntax
like this:
let itemNames = [/test/i, /test2/i];
app.models.skill.find({where: {name: {inq: itemNames}}}, ....
But loopback is changing regexp to strings.
loopback sends strings like
{ name: { $in: [ "/test/i", "/test2/i" ] } }
expected to work like described here:
https://docs.mongodb.com/manual/reference/operator/query/in/#use-the-in-operator-with-a-regular-expression
Can you suggest a fix or a workaround for this (but I can't patch loopback itself it is a business requirement)
Loopback accepted my changes,
https://github.com/strongloop/loopback-datasource-juggler/pull/1279
so it should be possible to use regexps like in mongo.
You may create inq item like this:
let itemNames = [new RegExp('/test/i'), new RegExp('/test2/i')];
It worked for me.

Return join table attributes in incluce with loopback

I've got a data structure fairly similar to the one described on the Loopback HasManyThrough documentation page.
For a given Physician (e.g. id 2), I would like to get all their patients with an appointment AND their appointment date.
I can do a GET operation like this:
GET /physicians/2
with the filter header { "include" : {"relation":"patients"} }
And I do get the physician, and the list of patients, but I lose the appointmentDate of the relation.
Or, I can do a GET operation on the relation table like the documentation shows:
GET /appointments
with the filter header { "include" : {"relation":"patient"}, "where":{"physicianId":2}} }
And I get the the appointments, with the date and the patient embedded, but not the physician details.
I can't seem to be able to combine the two.
Is there a way to get the whole data with one query?
The data would be something like this:
[
"name" : "Dr John",
"appointments" : [ {
"appointmentDate": "2014-06-01",
"patient": {
"name": "Jane Smith",
"id": 1
}
}]
]
One way hack I found is to define the relation twice. Once as a HasManyThrough and once as a HasMany to the appointments table, then I can do something like this:
GET /physicians/2
with the filter header { "include" : {"relation":"appointments","scope":{"include":["patient"]} } }
But that doesn't seem right, or could maybe lead to odd behaviours with the duplicated relation.. but maybe I'm paranoid.
You could include both models
GET /appointments
{ "include": ["patient", "physician"], "where": { "physicianId":2 } }
You will get quite a lot of duplicate data though (details of physician with id 2). I believe, that HasManyThrough relation model was initially not supposed to carry any extra data and therefore, it has some limitations. Here is a related github issue.

Create / Update multiple objects from one API response

all new jsfiddle: http://jsfiddle.net/vJxvc/2/
Currently, i query an api that will return JSON like this. The API cannot be changed for now, which is why I need to work around that.
[
{"timestamp":1406111961, "values":[1236.181, 1157.695, 698.231]},
{"timestamp":1406111970, "values":[1273.455, 1153.577, 693.591]}
]
(could be a lot more lines, of course)
As you can see, each line has a timestamp and then an array of values. My problem is, that i would actually like to transpose that. Looking at the first line alone:
{"timestamp":1406111961, "values":[1236.181, 1157.695, 698.231]}
It contains a few measurements taken at the same time. This would need to become this in my ember project:
{
"sensor_id": 1, // can be derived from the array index
"timestamp": 1406111961,
"value": 1236.181
},
{
"sensor_id": 2,
"timestamp": 1406111961,
"value": 1157.695
},
{
"sensor_id": 3,
"timestamp": 1406111961,
"value": 698.231
}
And those values would have to be pushed into the respective sensor models.
The transformation itself is trivial, but i have no idea where i would put it in ember and how i could alter many ember models at the same time.
you could make your model an array and override the normalize method on your adapter. The normalize method is where you do the transformation, and since your json is an array, an Ember.Array as a model would work.
I am not a ember pro but looking at the manual I would think of something like this:
a = [
{"timestamp":1406111961, "values":[1236.181, 1157.695, 698.231]},
{"timestamp":1406111970, "values":[1273.455, 1153.577, 693.591]}
];
b = [];
a.forEach(function(item) {
item.values.forEach(function(value, sensor_id) {
b.push({
sensor_id: sensor_id,
timestamp: item.timestamp,
value: value
});
});
});
console.log(b);
Example http://jsfiddle.net/kRUV4/
Update
Just saw your jsfiddle... You can geht the store like this: How to get Ember Data's "store" from anywhere in the application so that I can do store.find()?

Proper design of REST-powered list in Ember.js

I'm having difficulty wrapping my head around the following:
There's a view that displays the list of items
I take the list of items from the backend via RESTful interface in JSON using ember-data and hand-crafted adapter
In my view I do something like this:
{{#collection contentBinding="App.recentAdditionsController"}}
...
{{/collection}}
App.recentAdditionsController is defined like this:
App.recentAdditionsController = Em.ArrayController.create({
refresh: function(query) {
var items = App.store.findAll(App.Item);
this.set('content', items);
}
});
And... this doesn't work. The reason being App.store.findAll() returning ModelArray which is much like ArrayController itself.
I saw people doing something like this:
App.recentAdditions = App.store.findAll(App.Item);
I could imagine doing it like that, but how would I refresh the list at will (checking if there's anything new).
Hope all is clear more or less.
I've verified that you can use a ModelArray inside an ArrayController. Here's a jsFiddle example: http://jsfiddle.net/ebryn/VkKX2/
"Now the question is how to make the list update itself if there are new objects in the backend?"
Use App.Model.filter to keep your recordArray in sync. Add the query hash when the filter is invoked to ensure than an initial query was made.
model: ->
App.Model.filter {page: 1}, (data) ->
data
edit: Just saw how old the question was, but leaving it here in case it helps someone.