fixed total count and filtering + basic tab implementation in React
This commit is contained in:
@@ -540,6 +540,7 @@ define(
|
|||||||
|
|
||||||
var data = params || {};
|
var data = params || {};
|
||||||
data.listing = {
|
data.listing = {
|
||||||
|
tab: (this.props.tab) ? this.props.tab : '',
|
||||||
offset: 0,
|
offset: 0,
|
||||||
limit: 0,
|
limit: 0,
|
||||||
filter: this.state.filter,
|
filter: this.state.filter,
|
||||||
|
@@ -250,13 +250,6 @@ define(
|
|||||||
return segment.name
|
return segment.name
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
var statistics_column =
|
|
||||||
(!mailpoet_settings.tracking || !mailpoet_settings.tracking.enabled) ?
|
|
||||||
false :
|
|
||||||
<td className="column {statistics_class}" data-colname={ MailPoet.I18n.t('statistics') }>
|
|
||||||
{ this.renderStatistics(newsletter) }
|
|
||||||
</td>;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<td className={ rowClasses }>
|
<td className={ rowClasses }>
|
||||||
@@ -271,7 +264,9 @@ define(
|
|||||||
<td className="column" data-colname={ MailPoet.I18n.t('lists') }>
|
<td className="column" data-colname={ MailPoet.I18n.t('lists') }>
|
||||||
{ segments }
|
{ segments }
|
||||||
</td>
|
</td>
|
||||||
{ statistics_column }
|
<td className="column" data-colname={ MailPoet.I18n.t('statistics') }>
|
||||||
|
{ this.renderStatistics(newsletter) }
|
||||||
|
</td>
|
||||||
<td className="column-date" data-colname={ MailPoet.I18n.t('createdOn') }>
|
<td className="column-date" data-colname={ MailPoet.I18n.t('createdOn') }>
|
||||||
<abbr>{ MailPoet.Date.format(newsletter.created_at) }</abbr>
|
<abbr>{ MailPoet.Date.format(newsletter.created_at) }</abbr>
|
||||||
</td>
|
</td>
|
||||||
@@ -282,15 +277,24 @@ define(
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
if (!mailpoet_settings.tracking || !mailpoet_settings.tracking.enabled) {
|
|
||||||
columns = _.without(columns, _.findWhere(columns, {name: 'statistics'}));
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1 className="title">
|
<h1 className="title">
|
||||||
{MailPoet.I18n.t('pageTitle')} <Link className="page-title-action" to="/new">{MailPoet.I18n.t('new')}</Link>
|
{MailPoet.I18n.t('pageTitle')} <Link className="page-title-action" to="/new">{MailPoet.I18n.t('new')}</Link>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
<h2 className="nav-tab-wrapper">
|
||||||
|
<Link to="/standard" className="nav-tab nav-tab-active">
|
||||||
|
{ MailPoet.I18n.t('tabStandardTitle') }
|
||||||
|
</Link>
|
||||||
|
<Link to="/welcome" className="nav-tab">
|
||||||
|
{ MailPoet.I18n.t('tabWelcomeTitle') }
|
||||||
|
</Link>
|
||||||
|
<Link to="/notification" className="nav-tab">
|
||||||
|
{ MailPoet.I18n.t('tabNotificationTitle') }
|
||||||
|
</Link>
|
||||||
|
</h2>
|
||||||
|
|
||||||
<Listing
|
<Listing
|
||||||
limit={ mailpoet_listing_per_page }
|
limit={ mailpoet_listing_per_page }
|
||||||
params={ this.props.params }
|
params={ this.props.params }
|
||||||
|
@@ -25,13 +25,21 @@ if(container) {
|
|||||||
<Router history={ history }>
|
<Router history={ history }>
|
||||||
<Route path="/" component={ App }>
|
<Route path="/" component={ App }>
|
||||||
<IndexRoute component={ NewsletterList } />
|
<IndexRoute component={ NewsletterList } />
|
||||||
|
{/* New newsletters */}
|
||||||
<Route path="new" component={ NewsletterTypes } />
|
<Route path="new" component={ NewsletterTypes } />
|
||||||
<Route name="standard" path="new/standard" component={ NewsletterStandard } />
|
<Route name="new/standard" path="new/standard" component={ NewsletterStandard } />
|
||||||
<Route name="welcome" path="new/welcome" component={ NewsletterWelcome } />
|
<Route name="new/welcome" path="new/welcome" component={ NewsletterWelcome } />
|
||||||
<Route name="notification" path="new/notification" component={ NewsletterNotification } />
|
<Route name="new/notification" path="new/notification" component={ NewsletterNotification } />
|
||||||
|
{/* Form: template selection */}
|
||||||
<Route name="template" path="template/:id" component={ NewsletterTemplates } />
|
<Route name="template" path="template/:id" component={ NewsletterTemplates } />
|
||||||
<Route path="send/:id" component={ NewsletterSend } />
|
{/* Listing: tabs */}
|
||||||
|
<Route name="listing/standard" path="standard" component={ NewsletterList } />
|
||||||
|
<Route name="listing/welcome" path="welcome" component={ NewsletterList } />
|
||||||
|
<Route name="listing/notification" path="notification" component={ NewsletterList } />
|
||||||
|
{/* Listing: filtering */}
|
||||||
<Route path="filter[:filter]" component={ NewsletterList } />
|
<Route path="filter[:filter]" component={ NewsletterList } />
|
||||||
|
{/* Form: sending options */}
|
||||||
|
<Route path="send/:id" component={ NewsletterSend } />
|
||||||
<Route path="*" component={ NewsletterList } />
|
<Route path="*" component={ NewsletterList } />
|
||||||
</Route>
|
</Route>
|
||||||
</Router>
|
</Router>
|
||||||
|
@@ -66,10 +66,21 @@ class Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSelection() {
|
function getSelection() {
|
||||||
if(!empty($this->data['selection'])) {
|
if(method_exists($this->model_class, 'listingQuery')) {
|
||||||
$this->model->whereIn($this->table_name.'.id', $this->data['selection']);
|
$custom_query = call_user_func_array(
|
||||||
|
array($this->model_class, 'listingQuery'),
|
||||||
|
array($this->data)
|
||||||
|
);
|
||||||
|
if(!empty($this->data['selection'])) {
|
||||||
|
$custom_query->whereIn($this->table_name.'.id', $this->data['selection']);
|
||||||
|
}
|
||||||
|
return $custom_query;
|
||||||
|
} else {
|
||||||
|
if(!empty($this->data['selection'])) {
|
||||||
|
$this->model->whereIn($this->table_name.'.id', $this->data['selection']);
|
||||||
|
}
|
||||||
|
return $this->model;
|
||||||
}
|
}
|
||||||
return $this->model;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectionIds() {
|
function getSelectionIds() {
|
||||||
@@ -101,6 +112,8 @@ class Handler {
|
|||||||
array($this->data)
|
array($this->data)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$count = $custom_query->count();
|
||||||
|
|
||||||
$items = $custom_query
|
$items = $custom_query
|
||||||
->offset($this->data['offset'])
|
->offset($this->data['offset'])
|
||||||
->limit($this->data['limit'])
|
->limit($this->data['limit'])
|
||||||
@@ -108,19 +121,19 @@ class Handler {
|
|||||||
$this->table_name.'.'.$this->data['sort_by']
|
$this->table_name.'.'.$this->data['sort_by']
|
||||||
)
|
)
|
||||||
->findMany();
|
->findMany();
|
||||||
$count = $custom_query->count();
|
|
||||||
} else {
|
} else {
|
||||||
$this->setFilter();
|
$this->setFilter();
|
||||||
$this->setGroup();
|
$this->setGroup();
|
||||||
$this->setSearch();
|
$this->setSearch();
|
||||||
$this->setOrder();
|
$this->setOrder();
|
||||||
|
|
||||||
|
$count = $this->model->count();
|
||||||
|
|
||||||
$items = $this->model
|
$items = $this->model
|
||||||
->offset($this->data['offset'])
|
->offset($this->data['offset'])
|
||||||
->limit($this->data['limit'])
|
->limit($this->data['limit'])
|
||||||
->findMany();
|
->findMany();
|
||||||
|
|
||||||
$count = $this->model->count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -162,13 +162,13 @@ class Newsletter extends Model {
|
|||||||
return $filters;
|
return $filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function filterBy($orm, $filters = null) {
|
static function filterBy($orm, $data = array()) {
|
||||||
if(!empty($filters)) {
|
if(!empty($data['filter'])) {
|
||||||
foreach($filters as $key => $value) {
|
foreach($data['filter'] as $key => $value) {
|
||||||
if($key === 'segment') {
|
if($key === 'segment') {
|
||||||
$segment = Segment::findOne($value);
|
$segment = Segment::findOne($value);
|
||||||
if($segment !== false) {
|
if($segment !== false) {
|
||||||
$orm = $segment->newsletters();
|
$orm = $segment->newsletters()->where('type', $data['tab']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ class Newsletter extends Model {
|
|||||||
|
|
||||||
static function listingQuery($data = array()) {
|
static function listingQuery($data = array()) {
|
||||||
return self::where('type', $data['tab'])
|
return self::where('type', $data['tab'])
|
||||||
->filter('filterBy', $data['filter'])
|
->filter('filterBy', $data)
|
||||||
->filter('groupBy', $data['group'])
|
->filter('groupBy', $data['group'])
|
||||||
->filter('search', $data['search']);
|
->filter('search', $data['search']);
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,11 @@
|
|||||||
<% block translations %>
|
<% block translations %>
|
||||||
<%= localize({
|
<%= localize({
|
||||||
'pageTitle': __('Newsletters'),
|
'pageTitle': __('Newsletters'),
|
||||||
|
|
||||||
|
'tabStandardTitle': __('Newsletters'),
|
||||||
|
'tabWelcomeTitle': __('Welcome emails'),
|
||||||
|
'tabNotificationTitle': __('Post notifications'),
|
||||||
|
|
||||||
'searchLabel': __('Search'),
|
'searchLabel': __('Search'),
|
||||||
'loadingItems': __('Loading newsletters...'),
|
'loadingItems': __('Loading newsletters...'),
|
||||||
'noItemsFound': __('No newsletters found.'),
|
'noItemsFound': __('No newsletters found.'),
|
||||||
|
Reference in New Issue
Block a user