Merge pull request #218 from mailpoet/listings_bugfix

Listings bugfixes & Welcome page
This commit is contained in:
Marco
2015-11-13 16:01:23 +01:00
13 changed files with 79 additions and 101 deletions

View File

@@ -96,7 +96,7 @@ class RoboFile extends \Robo\Tasks {
function testUnit($file = null) {
$this->loadEnv();
$this->_exec('vendor/bin/codecept build');
$this->_exec('vendor/bin/codecept run unit -f '.(($file) ? $file : ''));
$this->_exec('vendor/bin/codecept run unit '.(($file) ? $file : ''));
}
function testJavascript() {

View File

@@ -90,15 +90,15 @@ define(
if(response.result === true) {
if(this.props.onSuccess !== undefined) {
this.props.onSuccess()
this.props.onSuccess();
} else {
this.history.pushState(null, '/')
}
if(this.props.params.id !== undefined) {
this.props.messages['updated']();
this.props.messages.onUpdate();
} else {
this.props.messages['created']();
this.props.messages.onCreate();
}
} else {
if(response.result === false) {

View File

@@ -1,57 +0,0 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { Router, History } from 'react-router'
import MailPoet from 'mailpoet'
import Form from 'form/form.jsx'
const fields = [
{
name: 'name',
label: 'Name',
type: 'text'
},
{
name: 'segments',
label: 'Lists',
type: 'selection',
endpoint: 'segments',
multiple: true
}
]
const messages = {
updated: function() {
MailPoet.Notice.success('Form successfully updated!');
},
created: function() {
MailPoet.Notice.success('Form successfully added!');
}
}
const FormForm = React.createClass({
mixins: [
History
],
render() {
return (
<div>
<h2 className="title">
Form <a
href="javascript:;"
className="add-new-h2"
onClick={ this.history.goBack }
>Back to list</a>
</h2>
<Form
endpoint="forms"
fields={ fields }
params={ this.props.params }
messages={ messages }
onSuccess={ this.history.goBack } />
</div>
);
}
});
module.exports = FormForm

View File

@@ -2,7 +2,6 @@ import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Route, IndexRoute } from 'react-router'
import FormList from 'forms/list.jsx'
import FormForm from 'forms/form.jsx'
import createHashHistory from 'history/lib/createHashHistory'
let history = createHashHistory({ queryKey: false })
@@ -20,8 +19,6 @@ if(container) {
<Router history={ history }>
<Route path="/" component={ App }>
<IndexRoute component={ FormList } />
<Route path="new" component={ FormForm } />
<Route path="edit/:id" component={ FormForm } />
<Route path="*" component={ FormList } />
</Route>
</Router>

View File

@@ -85,7 +85,12 @@ function(
Select bulk action
</label>
<select ref="action" value={ this.state.action } onChange={this.handleChangeAction}>
<select
name="bulk_actions"
ref="action"
value={ this.state.action }
onChange={this.handleChangeAction}
>
<option value="">Bulk Actions</option>
{ this.props.bulk_actions.map(function(action, index) {
return (

View File

@@ -11,7 +11,7 @@ define(['react', 'classnames'], function(React, classNames) {
column.is_primary = (index === 0);
column.sorted = (this.props.sort_by === column.name)
? this.props.sort_order
: 'asc';
: 'desc';
return (
<ListingColumn
onSort={this.props.onSort}
@@ -32,6 +32,7 @@ define(['react', 'classnames'], function(React, classNames) {
</label>
<input
type="checkbox"
name="select_all"
ref="toggle"
checked={ this.props.selection }
onChange={ this.handleSelectItems } />

View File

@@ -26,10 +26,10 @@ define(
];
var messages = {
updated: function() {
onUpdate: function() {
MailPoet.Notice.success('Segment successfully updated!');
},
created: function() {
onCreate: function() {
MailPoet.Notice.success('Segment successfully added!');
}
};
@@ -54,7 +54,7 @@ define(
fields={ fields }
params={ this.props.params }
messages={ messages }
onSuccess={ this.history.goBack } />
/>
</div>
);
}

View File

@@ -52,10 +52,10 @@ define(
];
var messages = {
updated: function() {
onUpdate: function() {
MailPoet.Notice.success('Subscriber successfully updated!');
},
created: function() {
onCreate: function() {
MailPoet.Notice.success('Subscriber successfully added!');
}
};
@@ -82,7 +82,7 @@ define(
fields={ fields }
params={ this.props.params }
messages={ messages }
onSuccess={ this.history.goBack } />
/>
</div>
);
}

View File

@@ -34,7 +34,7 @@ class Menu {
'MailPoet',
'manage_options',
'mailpoet',
array($this, 'home'),
array($this, 'welcome'),
$this->assets_url . '/img/menu_icon.png',
30
);
@@ -100,6 +100,7 @@ class Menu {
function registered_pages() {
global $_registered_pages;
$pages = array(
'mailpoet-welcome' => array($this, 'welcome'),
'mailpoet-form-editor' => array($this, 'formEditor'),
'mailpoet-newsletter-editor' => array($this, 'newletterEditor')
);
@@ -117,26 +118,16 @@ class Menu {
echo $this->renderer->render('index.html', $data);
}
function welcome() {
$data = array(
'settings' => Setting::getAll(),
'current_user' => wp_get_current_user()
);
echo $this->renderer->render('welcome.html', $data);
}
function settings() {
// flags (available features on WP install)
$flags = array();
if(is_multisite()) {
// get multisite registration option
$registration = apply_filters(
'wpmu_registration_enabled',
get_site_option('registration', 'all')
);
// check if users can register
$flags['registration_enabled'] =
!(in_array($registration, array('none', 'blog')));
} else {
// check if users can register
$flags['registration_enabled'] =
(bool)get_option('users_can_register', false);
}
$settings = Setting::getAll();
// dkim: check if public/private keys have been generated
@@ -158,7 +149,7 @@ class Menu {
'settings' => $settings,
'segments' => Segment::getPublished()->findArray(),
'pages' => Pages::getAll(),
'flags' => $flags,
'flags' => $this->_getFlags(),
'charsets' => Charsets::getAll(),
'current_user' => wp_get_current_user(),
'permissions' => Permissions::getAll(),
@@ -171,6 +162,29 @@ class Menu {
echo $this->renderer->render('settings.html', $data);
}
private function _getFlags() {
// flags (available features on WP install)
$flags = array();
if(is_multisite()) {
// get multisite registration option
$registration = apply_filters(
'wpmu_registration_enabled',
get_site_option('registration', 'all')
);
// check if users can register
$flags['registration_enabled'] =
!(in_array($registration, array('none', 'blog')));
} else {
// check if users can register
$flags['registration_enabled'] =
(bool)get_option('users_can_register', false);
}
return $flags;
}
function subscribers() {
$data = array();

View File

@@ -4,17 +4,17 @@ namespace MailPoet\Settings;
class Pages {
static function getAll() {
$mailpoet_pages = get_posts(array(
$mailpoet_pages = \get_posts(array(
'post_type' => 'mailpoet_page'
));
$pages = array();
foreach(array_merge($mailpoet_pages, get_pages()) as $page) {
foreach(array_merge($mailpoet_pages, \get_pages()) as $page) {
$pages[] = array(
'id' => $page->ID,
'title' => $page->post_title,
'preview_url' => get_permalink($page->ID),
'edit_url' => get_edit_post_link($page->ID)
'preview_url' => \get_permalink($page->ID),
'edit_url' => \get_edit_post_link($page->ID)
);
}

View File

@@ -1,9 +1,10 @@
<?php
$console = new \Codeception\Lib\Console\Output([]);
$wp_load_file = getenv('WP_TEST_PATH').'/wp-load.php';
require_once($wp_load_file);
$console->writeln('Loading WP core...');
require_once(getenv('WP_TEST_PATH') . '/wp-load.php');
$console = new \Codeception\Lib\Console\Output([]);
$console->writeln('Loading WP core... ('.$wp_load_file.')');
$console->writeln('Cleaning up database...');
$models = array(

View File

@@ -171,5 +171,9 @@ class SegmentCest {
->deleteMany();
ORM::forTable(SubscriberSegment::$_table)
->deleteMany();
ORM::forTable(Newsletter::$_table)
->deleteMany();
ORM::forTable(NewsletterSegment::$_table)
->deleteMany();
}
}

13
views/welcome.html Normal file
View File

@@ -0,0 +1,13 @@
<% extends 'layout.html' %>
<% block content %>
<div id="mailpoet_welcome">
<h2><%= __('Welcome welcome welcome!') %></h2>
<h3>Settings:</h3>
<%= dump(settings) %>
<h3>Current user:</h3>
<%= dump(current_user) %>
</div>
<% endblock %>