Ghost/ghost/admin/app/models/member.js
Sanne de Vries ffe0f84700 Added open-rate column and ordering to the members list (#1790)
closes https://github.com/TryGhost/Ghost/issues/12421

- added `emailOpenRate` property to member model
- added open-rate column to the members list
  - hidden when email analytics is disabled
- added `{{feature "flag"}}` helper so feature flags can be checked in templates without injecting the feature service into the backing class
- added `order` query param to the members controller/route and wired it into the data fetching routine
- added order dropdown to the filter bar with "Newest" (default) and "Open rate" as the two options
  - whole dropdown is hidden if email analytics is disabled

Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
2020-12-08 19:23:57 +00:00

43 lines
1.4 KiB
JavaScript

import Model, {attr, hasMany} from '@ember-data/model';
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
export default Model.extend(ValidationEngine, {
validationType: 'member',
name: attr('string'),
email: attr('string'),
note: attr('string'),
createdAtUTC: attr('moment-utc'),
stripe: attr('member-subscription'),
subscribed: attr('boolean', {defaultValue: true}),
labels: hasMany('label', {embedded: 'always', async: false}),
comped: attr('boolean', {defaultValue: false}),
geolocation: attr('json-string'),
emailOpenRate: attr('number'),
ghostPaths: service(),
ajax: service(),
// remove client-generated labels, which have `id: null`.
// Ember Data won't recognize/update them automatically
// when returned from the server with ids.
// https://github.com/emberjs/data/issues/1829
updateLabels() {
let labels = this.labels;
let oldLabels = labels.filterBy('id', null);
labels.removeObjects(oldLabels);
oldLabels.invoke('deleteRecord');
},
fetchSigninUrl: task(function* () {
let url = this.get('ghostPaths.url').api('members', this.get('id'), 'signin_urls');
let response = yield this.ajax.request(url);
return response.member_signin_urls[0];
}).drop()
});