Skip to content

Commit

Permalink
record items of all type can be hidden via flag, centralized contacts…
Browse files Browse the repository at this point in the history
… sorting into phone model so that we can maintain proper sort order
  • Loading branch information
ericbai committed Feb 14, 2019
1 parent 26eb630 commit c26dafa
Show file tree
Hide file tree
Showing 30 changed files with 555 additions and 376 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "es5",
}
25 changes: 13 additions & 12 deletions app/components/infinite-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
computed: { equal: eq },
run,
run: { scheduleOnce, next, once, throttle, later, cancel },
RSVP: { Promise }
RSVP: { Promise },
} = Ember;

export default Ember.Component.extend({
Expand Down Expand Up @@ -55,7 +55,7 @@ export default Ember.Component.extend({
'_isLoading:loading',
'_isDone:done',
'_isRefreshing:refreshing',
'_isPulling:pulling'
'_isPulling:pulling',
],
classNames: 'infinite-scroll',

Expand Down Expand Up @@ -96,8 +96,9 @@ export default Ember.Component.extend({
actions: {
loadMore: this.loadMoreIfNeeded.bind(this, true),
resetPosition: () => scheduleOnce('afterRender', this, this._restorePosition, true, true),
restorePosition: () => scheduleOnce('afterRender', this, this._restorePosition, false, true)
}
restorePosition: () =>
scheduleOnce('afterRender', this, this._restorePosition, false, true),
},
};
}),
_isUp: eq('direction', 'up'),
Expand Down Expand Up @@ -176,7 +177,7 @@ export default Ember.Component.extend({
_isDisplaying: false,
_isPulling: false,
_items: [],
_prevData: this.get('data')
_prevData: this.get('data'),
});
this._resetPull();
this.incrementProperty('_version');
Expand Down Expand Up @@ -217,7 +218,7 @@ export default Ember.Component.extend({
this.setProperties({
_previousClientHeight: container.clientHeight,
_previousScrollHeight: container.scrollHeight,
_previousScrollTop: container.scrollTop
_previousScrollTop: container.scrollTop,
});
},
_restorePosition(shouldReset = false, userTriggered = false) {
Expand Down Expand Up @@ -345,12 +346,12 @@ export default Ember.Component.extend({
if (this.get('_isUp')) {
$refreshing.css({
top: '',
bottom: `${position}px`
bottom: `${position}px`,
});
} else {
$refreshing.css({
bottom: '',
top: `${position}px`
top: `${position}px`,
});
}
$refreshing.fadeIn();
Expand All @@ -366,7 +367,7 @@ export default Ember.Component.extend({
prop = `translateY(${overscroll * direction}px)`;
$container.css({
transform: prop,
'-webkit-transform': prop
'-webkit-transform': prop,
});
},
_resetPull: function() {
Expand All @@ -375,7 +376,7 @@ export default Ember.Component.extend({
this.set('_pullNow', null);
this.get('_$container').css({
transform: '',
'-webkit-transform': ''
'-webkit-transform': '',
});
this.get('_$refreshing').hide();
},
Expand All @@ -398,7 +399,7 @@ export default Ember.Component.extend({
if (versionWhenCalled === this.get('_version')) {
this.setProperties({
_isLoading: false,
_hasError: !isSuccess
_hasError: !isSuccess,
});
}
};
Expand Down Expand Up @@ -463,5 +464,5 @@ export default Ember.Component.extend({
});
});
});
}
},
});
12 changes: 4 additions & 8 deletions app/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import Ember from 'ember';
const { computed, get } = Ember;

export default Ember.Controller.extend({
// see main.contacts controller for explanation of _transitioning
_transitioning: false,
// alias the filter property of main for displaying active menu items
filter: 'all',
// store contacts on mainController so we can add new contacts for display
contacts: computed.alias('stateManager.owner.phone.content.contacts'),
// displaying active menu items
filter: computed.alias('stateManager.owner.phone.content.contactsFilter'),

appMessageEndpoint: computed(function() {
return get(config, 'appMessage.messageEndpoint');
Expand All @@ -21,6 +17,6 @@ export default Ember.Controller.extend({
actions: {
closeAppUpdateMessage() {
this.set('shouldShowAppMessage', false);
}
}
},
},
});
131 changes: 50 additions & 81 deletions app/controllers/main/contacts.js
Original file line number Diff line number Diff line change
@@ -1,98 +1,67 @@
import Ember from 'ember';
import * as TextUtils from 'textup-frontend/utils/text';

const { computed: { alias }, run } = Ember;
const { computed } = Ember;

export default Ember.Controller.extend({
mainController: Ember.inject.controller('main'),

queryParams: ['filter'],
// alias the filter property of main for displaying active menu items
filter: alias('mainController.filter'),
// store contacts on mainController so we can add new contacts for display
contacts: alias('mainController.contacts'),
// contacts array on mainController is an alias of the owner's contacts
// so when we are switching to admin, we are changing owner and switching to
// an owner that doesn't have contacts becuase owner is now an organization
_transitioning: alias('mainController._transitioning'),

numContacts: '--',
filter: null,
tag: null,
contactsList: null,

// Computed properties
// -------------------

statuses: Ember.computed('filter', function() {
return this._translateFilter(this.get('filter'));
phone: computed.alias('stateManager.owner.phone.content'),
filterName: computed('phone.contactsFilter', function() {
return TextUtils.capitalize(this.get('phone.contactsFilter'));
}),

// Observers
// ---------

filterContactsByStatus: Ember.on(
'init',
Ember.observer('contacts', function() {
const contacts = this.get('contacts');
if (!contacts) {
return;
}
const statuses = this.get('statuses'),
hasStatus = contacts.filter(cont => cont.isAnyStatus(statuses));
// set contacts to with new array to trigger rebuild of infinite scroll
this.set('contacts', hasStatus);
})
),

actions: {
refresh: function() {
const contacts = this.get('contacts');
return this._loadMore().then(results => {
run(() => {
contacts.clear();
contacts.pushObjects(results.toArray());
});
});
},
loadMore: function() {
const contacts = this.get('contacts');
return this._loadMore(contacts.length).then(results => {
contacts.pushObjects(results.toArray());
});
setup(newTag = null) {
const contactsList = this.get('contactsList');
if (contactsList) {
contactsList.actions.resetPosition();
}
if (newTag && newTag.get('constructor.modelName') === this.get('constants.MODEL.TAG')) {
this.set('tag', newTag);
} else {
this.set('tag', null);
}
this.get('phone').clearContacts();
},

_loadMore: function(offset = 0) {
doRefreshContacts() {
const phone = this.get('phone');
phone.clearContacts();
this.doLoadMoreContacts();
},

doLoadMoreContacts() {
return new Ember.RSVP.Promise((resolve, reject) => {
if (this.get('_transitioning')) {
return resolve();
}
const query = Object.create(null),
team = this.get('stateManager.ownerAsTeam'),
tag = this.get('tag');
// build query
query.max = 20;
query.status = this.get('statuses');
query.offset = offset;
if (tag) {
// one or the other, can't be both
query.tagId = tag.get('id');
delete query.status;
} else if (team) {
query.teamId = team.get('id');
const team = this.get('stateManager.ownerAsTeam'),
tag = this.get('tag'),
phone = this.get('phone');
// if we are in the middle of transitioning to admin, then we no longer have a phone on owner
if (phone) {
const query = {
max: 20,
status: phone.get('contactStatuses'),
offset: phone.get('contacts.length'),
};
if (tag) {
query.tagId = tag.get('id');
delete query.status; // ignore filter if viewing a tag
}
if (team) {
query.teamId = team.get('id');
}
this.get('store')
.query('contact', query)
.then(results => {
phone.set('totalNumContacts', results.get('meta.total'));
phone.addContacts(results.toArray());
resolve();
}, this.get('dataService').buildErrorHandler(reject));
} else {
resolve();
}
// execute query
this.store.query('contact', query).then(results => {
this.set('numContacts', results.get('meta.total'));
resolve(results);
}, this.get('dataService').buildErrorHandler(reject));
});
},
_translateFilter: function(filter) {
const options = {
all: ['unread', 'active'],
unread: ['unread'],
archived: ['archived'],
blocked: ['blocked']
};
return filter ? options[filter.toLowerCase()] : options['all'];
}
});
28 changes: 14 additions & 14 deletions app/controllers/main/contacts/many.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Ember from 'ember';

const { filterBy, empty, alias } = Ember.computed;
const { computed } = Ember;

export default Ember.Controller.extend({
contactsController: Ember.inject.controller('main.contacts'),
phone: computed.alias('stateManager.owner.phone.content'),

// routes that want to use this controller but do not reuse the
// contacts controller can override these properties
selected: filterBy('contactsController.contacts', 'isSelected', true),
allContacts: alias('contactsController.contacts'),
selected: computed.filterBy('phone.contacts', 'isSelected', true),
allContacts: computed.alias('phone.contacts'),

// can message when no shared with me select OR all
// of the shared with me selected are DELEGATE permission
Expand All @@ -18,16 +18,16 @@ export default Ember.Controller.extend({
this.get('sharedWithMeSelected').every(contact => contact.get('isSharedDelegate'))
);
}),
sharedWithMeSelected: filterBy('selected', 'isShared', true),
noSharedWithMeSelected: empty('sharedWithMeSelected'),
sharedWithMeSelected: computed.filterBy('selected', 'isShared', true),
noSharedWithMeSelected: computed.empty('sharedWithMeSelected'),

actions: {
selectAll: function() {
selectAll() {
this.get('allContacts').forEach(contact => {
contact.set('isSelected', true);
});
},
selectAllMyContacts: function() {
selectAllMyContacts() {
this.get('allContacts').forEach(contact => {
if (contact.get('isShared')) {
contact.set('isSelected', false);
Expand All @@ -36,29 +36,29 @@ export default Ember.Controller.extend({
}
});
},
deselect: function(contact) {
deselect(contact) {
contact.set('isSelected', false);
Ember.run.next(this, function() {
if (this.get('selected.length') === 0) {
this._exitMany();
}
});
},
leave: function() {
leave() {
this._deselectAll();
this._exitMany();
}
},
},

// Helpers
// -------

_deselectAll: function() {
_deselectAll() {
this.get('selected').forEach(contact => {
contact.set('isSelected', false);
});
},
_exitMany: function() {
_exitMany() {
this.transitionToRoute(this.get('backRouteName'));
}
},
});
18 changes: 5 additions & 13 deletions app/controllers/main/search.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import Ember from 'ember';

const {
alias
} = Ember.computed;

export default Ember.Controller.extend({
queryParams: ['searchQuery'],
searchQuery: null, // actual search query that is stored in browser history

_searchQuery: null, // local copy of search query associated with the input
queryParams: ['searchQuery'],
searchQuery: null, // actual search query that is stored in browser history

searchResults: [],
numResults: '--',
_searchQuery: null, // local copy of search query associated with the input

// if we are transitioning to a new search term, we don't want to resolve
// search for the old search term
_transitioning: alias('mainController._transitioning'),
searchResults: [],
numResults: '--',
});
6 changes: 3 additions & 3 deletions app/helpers/capitalize.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Ember from 'ember';
import { capitalize as doCapitalize } from '../utils/text';
import * as TextUtils from 'textup-frontend/utils/text';

export function capitalize([word, numToCap] /*, hash*/) {
return doCapitalize(word, numToCap);
export function capitalize([word, numToCap]) {
return TextUtils.capitalize(word, numToCap);
}

export default Ember.Helper.helper(capitalize);
Loading

0 comments on commit c26dafa

Please sign in to comment.