Skip to content

Commit

Permalink
Merge pull request #1991 from uProxy/sort-by-offline
Browse files Browse the repository at this point in the history
Sort instances by whether or not they are online
  • Loading branch information
jpevarnek committed Nov 3, 2015
2 parents 70040c8 + 7558295 commit f1fa624
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/generic_ui/polymer/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@
{{ "TRYING_TO_CONNECT" | $$({ name: contact.name || contact.userId }) }}
</p>
</div>
<template repeat='{{ instance in contact.offeringInstances }}' vertical layout>
<template repeat='{{ instance in sortedInstances }}' vertical layout>
<uproxy-instance
user='{{ contact }}'
userName='{{ contact.name }}'
instance='{{ instance }}'
network='{{contact.network}}'>
on-instance-changed='{{ offeringInstancesChanged }}'>
</uproxy-instance>
</template>
</div>
Expand Down
11 changes: 10 additions & 1 deletion src/generic_ui/polymer/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import user = require('../scripts/user');
import _ = require('lodash');

Polymer({
created: function() {
this.offeringInstancesChanged = _.throttle(this.offeringInstancesChanged.bind(this), 100);
},
contact: {
// Must adhere to the typescript interface UI.User.
name: 'unknown'
Expand Down Expand Up @@ -105,13 +108,19 @@ Polymer({
this.hideOnlineStatus = true;
}
},
offeringInstancesChanged: function() {
// instanceId arbitrarily chosen
this.sortedInstances = _.sortByOrder(this.contact.offeringInstances,
['isOnline', 'instanceId'], ['desc', 'asc']);
},
observe: {
'contact.isSharingWithMe': 'fireChanged',
'contact.isGettingFromMe': 'fireChanged',
'contact.isOnline': 'fireChanged',
/* handle expand/collapse changes from ui.ts, toggle() handles other cases */
'contact.getExpanded': 'getExpandedChanged',
'contact.shareExpanded': 'shareExpandedChanged'
'contact.shareExpanded': 'shareExpandedChanged',
'contact.offeringInstances': 'offeringInstancesChanged',
},
computed: {
'isExpanded': '(mode === ui_constants.Mode.GET && contact.getExpanded) || (mode === ui_constants.Mode.SHARE && contact.shareExpanded)'
Expand Down
2 changes: 1 addition & 1 deletion src/generic_ui/polymer/instance.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<link rel='import' href='../../bower/core-icons/core-icons.html'>
<link rel="import" href="button.html">

<polymer-element name='uproxy-instance' attributes='user, instance, network'>
<polymer-element name='uproxy-instance' attributes='userName, instance'>
<template>
<style>
#wrapper.offline {
Expand Down
10 changes: 8 additions & 2 deletions src/generic_ui/polymer/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Polymer({
},
start: function() {
if (!this.instance.isOnline) {
this.ui.toastMessage = ui.i18n_t("FRIEND_OFFLINE", { name: this.user.name });
this.ui.toastMessage = ui.i18n_t("FRIEND_OFFLINE", { name: this.userName });
return;
}

Expand All @@ -36,5 +36,11 @@ Polymer({
ui.stopUsingProxy();
}
ui.stopGettingFromInstance(this.instance.instanceId);
}
},
fireChanged: function() {
this.fire('instance-changed');
},
observe: {
'instance.isOnline': 'fireChanged',
},
});
2 changes: 1 addition & 1 deletion src/generic_ui/polymer/roster-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Polymer({
contactsChanged: function() {
var property = (this.mode == ui_constants.Mode.GET) ? 'isSharingWithMe' : 'isGettingFromMe';
// TODO add typing for this to DefinitelyTyped
this.sortedContacts = (<any>_).sortByOrder(this.contacts, [property, 'isOnline'], [false, false]);
this.sortedContacts = _.sortByOrder(this.contacts, [property, 'isOnline'], ['desc', 'desc']);
},
});

0 comments on commit f1fa624

Please sign in to comment.