Refactored filtering (groups / status / type)

- standard listing close to completion (missing item actions)
- enabled tracking by default on install
This commit is contained in:
Jonathan Labreuille
2016-06-09 11:50:13 +02:00
parent ecf15d53d9
commit cd412894c6
3 changed files with 135 additions and 42 deletions

View File

@ -75,11 +75,6 @@ var columns = [
name: 'statistics', name: 'statistics',
label: MailPoet.I18n.t('statistics') label: MailPoet.I18n.t('statistics')
}, },
{
name: 'created_at',
label: MailPoet.I18n.t('createdOn'),
sortable: true
},
{ {
name: 'updated_at', name: 'updated_at',
label: MailPoet.I18n.t('lastModifiedOn'), label: MailPoet.I18n.t('lastModifiedOn'),
@ -266,7 +261,9 @@ const NewsletterListStandard = React.createClass({
<div> <div>
<td className={ rowClasses }> <td className={ rowClasses }>
<strong> <strong>
<a>{ newsletter.subject }</a> <a href={ `?page=mailpoet-newsletter-editor&id=${ newsletter.id }` }>
{ newsletter.subject }
</a>
</strong> </strong>
{ actions } { actions }
</td> </td>
@ -279,9 +276,6 @@ const NewsletterListStandard = React.createClass({
<td className="column" data-colname={ MailPoet.I18n.t('statistics') }> <td className="column" data-colname={ MailPoet.I18n.t('statistics') }>
{ this.renderStatistics(newsletter) } { this.renderStatistics(newsletter) }
</td> </td>
<td className="column-date" data-colname={ MailPoet.I18n.t('createdOn') }>
<abbr>{ MailPoet.Date.format(newsletter.created_at) }</abbr>
</td>
<td className="column-date" data-colname={ MailPoet.I18n.t('lastModifiedOn') }> <td className="column-date" data-colname={ MailPoet.I18n.t('lastModifiedOn') }>
<abbr>{ MailPoet.Date.format(newsletter.updated_at) }</abbr> <abbr>{ MailPoet.Date.format(newsletter.updated_at) }</abbr>
</td> </td>

View File

@ -10,8 +10,14 @@ class Newsletter extends Model {
const TYPE_WELCOME = 'welcome'; const TYPE_WELCOME = 'welcome';
const TYPE_NOTIFICATION = 'notification'; const TYPE_NOTIFICATION = 'notification';
// standard newsletters
const STATUS_DRAFT = 'draft'; const STATUS_DRAFT = 'draft';
const STATUS_SCHEDULED = 'scheduled';
const STATUS_SENDING = 'sending';
const STATUS_SENT = 'sent'; const STATUS_SENT = 'sent';
// automatic newsletters status
const STATUS_ACTIVE = 'active';
function __construct() { function __construct() {
parent::__construct(); parent::__construct();
@ -34,6 +40,30 @@ class Newsletter extends Model {
return parent::save(); return parent::save();
} }
function duplicate($data = array()) {
$data = $this->asArray();
unset($data['id']);
$duplicate = self::create();
$duplicate->hydrate($data);
$duplicate->set_expr('created_at', 'NOW()');
$duplicate->set_expr('updated_at', 'NOW()');
$duplicate->set_expr('deleted_at', 'NULL');
// reset status
$duplicate->set('status', self::STATUS_DRAFT);
// duplicate segments linked (if need be)
// duplicate options (if need be)
if($duplicate->save()) {
return $duplicate;
} else {
return false;
}
}
function asArray() { function asArray() {
$model = parent::asArray(); $model = parent::asArray();
@ -202,63 +232,129 @@ class Newsletter extends Model {
} }
static function groups($data = array()) { static function groups($data = array()) {
return array( $type = isset($data['tab']) ? $data['tab'] : self::TYPE_STANDARD;
$groups = array(
array( array(
'name' => 'all', 'name' => 'all',
'label' => __('All'), 'label' => __('All'),
'count' => Newsletter::getPublished()->where('type', $data['tab'])->count() 'count' => Newsletter::getPublished()
), ->filter('filterType', $type)
array( ->count()
'name' => self::STATUS_DRAFT,
'label' => __('Draft'),
'count' => Newsletter::filter('filterDraft', $data)->count()
),
array(
'name' => self::STATUS_SENT,
'label' => __('Sent'),
'count' => Newsletter::filter('filterSent', $data)->count()
),
array(
'name' => 'trash',
'label' => __('Trash'),
'count' => Newsletter::getTrashed()->where('type', $data['tab'])->count()
) )
); );
switch($type) {
case self::TYPE_STANDARD:
$groups = array_merge($groups, array(
array(
'name' => self::STATUS_DRAFT,
'label' => __('Draft'),
'count' => Newsletter::getPublished()
->filter('filterType', $type)
->filter('filterStatus', self::STATUS_DRAFT)
->count()
),
array(
'name' => self::STATUS_SCHEDULED,
'label' => __('Scheduled'),
'count' => Newsletter::getPublished()
->filter('filterType', $type)
->filter('filterStatus', self::STATUS_SCHEDULED)
->count()
),
array(
'name' => self::STATUS_SENDING,
'label' => __('Sending'),
'count' => Newsletter::getPublished()
->filter('filterType', $type)
->filter('filterStatus', self::STATUS_SENDING)
->count()
),
array(
'name' => self::STATUS_SENT,
'label' => __('Sent'),
'count' => Newsletter::getPublished()
->filter('filterType', $type)
->filter('filterStatus', self::STATUS_SENT)
->count()
)
));
break;
case self::TYPE_WELCOME:
$groups = array_merge($groups, array(
array(
'name' => self::STATUS_DRAFT,
'label' => __('Not active'),
'count' => Newsletter::filter('filterType', $type)
->filter('filterStatus', self::STATUS_DRAFT)
->count()
),
array(
'name' => self::STATUS_ACTIVE,
'label' => __('Active'),
'count' => Newsletter::filter('filterType', $type)
->filter('filterStatus', self::STATUS_ACTIVE)
->count()
)
));
break;
case self::TYPE_NOTIFICATION:
break;
}
$groups[] = array(
'name' => 'trash',
'label' => __('Trash'),
'count' => Newsletter::getTrashed()
->filter('filterType', $type)
->count()
);
return $groups;
} }
static function groupBy($orm, $data = array()) { static function groupBy($orm, $data = array()) {
$type = (!empty($data['type'])) ? $data['type'] : false;
$group = (!empty($data['group'])) ? $data['group'] : 'all'; $group = (!empty($data['group'])) ? $data['group'] : 'all';
switch($group) { switch($group) {
case self::STATUS_DRAFT: case self::STATUS_DRAFT:
$orm->filter('filterDraft', $data); case self::STATUS_SCHEDULED:
break; case self::STATUS_SENDING:
case self::STATUS_SENT: case self::STATUS_SENT:
$orm->filter('filterSent', $data); case self::STATUS_ACTIVE:
$orm
->whereNull('deleted_at')
->filter('filterType', $type)
->filter('filterStatus', $group);
break; break;
case 'trash': case 'trash':
$orm->whereNotNull('deleted_at'); $orm->whereNotNull('deleted_at');
break; break;
default: default:
$orm->whereNull('deleted_at'); $orm->whereNull('deleted_at');
} }
return $orm; return $orm;
} }
static function filterDraft($orm, $data = array()) { static function filterStatus($orm, $status = false) {
$type = isset($data['tab']) ? $data['tab'] : self::TYPE_STANDARD; if($status !== false) {
$orm->where('status', $status);
return $orm }
->where('type', $type) return $orm;
->where('status', self::STATUS_DRAFT);
} }
static function filterSent($orm, $data = array()) { static function filterType($orm, $type = false) {
$type = isset($data['tab']) ? $data['tab'] : self::TYPE_STANDARD; if($type !== false) {
$orm->where('type', $type);
return $orm }
->where('type', $type) return $orm;
->where('status', self::STATUS_SENT);
} }
static function listingQuery($data = array()) { static function listingQuery($data = array()) {

View File

@ -41,7 +41,10 @@ class Setting extends Model {
'signup_confirmation' => array( 'signup_confirmation' => array(
'enabled' => true, 'enabled' => true,
'subject' => sprintf(__('Confirm your subscription to %1$s'), get_option('blogname')), 'subject' => sprintf(__('Confirm your subscription to %1$s'), get_option('blogname')),
'body' => __("Hello!\n\nHurray! You've subscribed to our site.\n\nPlease confirm your subscription to the list(s): [lists_to_confirm] by clicking the link below: \n\n[activation_link]Click here to confirm your subscription.[/activation_link]\n\nThank you,\n\nThe team!") 'body' => __("Hello!\n\nHurray! You've subscribed to our site.\n\nPlease confirm your subscription to the list(s): [lists_to_confirm] by clicking the link below: \n\n[activation_link]Click here to confirm your subscription.[/activation_link]\n\nThank you,\n\nThe Team")
),
'tracking' => array(
'enabled' => true
) )
); );
} }