ray1
(Ray Offiah)
March 11, 2018, 6:50pm
#1
Hi there.
I’m trying out a responsive front end using Polymer, and I’m still trying to make sense of the docs.
I want to display a table of data that belongs to the currently logged on user.
How do I retrieve the login details of the user, so I can pass them to a cuba-query to retrieve the data.
I tried using the cuba-user-info tag from here:
but that just displayed the user details. I guess what I need is to get those details out into a variable I can pass to the other component.
tsarev
(Daniil Tsaryov)
March 12, 2018, 6:04am
#2
Hi, @ray1
I think that the following snippet will help you:
foo: function () {
// "app" - is the instance of "cuba-app" component
this.app.getUserInfo().then(function (userInfo) {
// use userInfo later
this.userInfo = userInfo;
}.bind(this));
}
Regards,
Daniil.
ray1
(Ray Offiah)
March 12, 2018, 9:30am
#3
Thanks, I was on the right lines then.
But what I was looking for was to set this up as a Polymer component call so that I could use the result somewhere else.
<cuba-user-info user-info="{{user}}">
</cuba-user-info>
<cuba-query id="assignment-data" params='{user: [[user.login]]}'
entity-name="peer$Assignment" data="{{entities}}" view="_local" loading="{{dataLoading}}" limit="10" provide-count="true" count="{{entitiesCount}}">
</cuba-query>
ray1
(Ray Offiah)
March 13, 2018, 10:19am
#4
Okay, I think I got it. This seems to do the trick:
<script>
class CubaUserInfo extends Polymer.mixinBehaviors([CubaAppAwareBehavior], Polymer.Element) {
static get is() { return 'cuba-user-info'}
static get properties() {
return {
userInfo: {
type: Object,
notify: true,
}
}
}
ready () {
super.ready();
this.app.getUserInfo().then(function (userInfo) {
this.userInfo = userInfo
}.bind(this))
}
}
customElements.define(CubaUserInfo.is, CubaUserInfo)
</script>
Hope that helps someone else running into the same problem.
1 Like