Merge branch 'frontend-dashboards-with-login' into 'master'

Frontend dashboards with login

See merge request saburly/wiaas/new-wiaas!9
This commit was merged in pull request #9.
This commit is contained in:
Almira
2018-08-08 16:24:38 +00:00
32 changed files with 219 additions and 67 deletions

View File

@@ -65,4 +65,4 @@ COPY docker/php/.htaccess /var/www/html/
RUN chown -R www-data:www-data /var/www/html
CMD /init-scripts/setup.sh
CMD /init-scripts/setup.sh

13
backend/.htaccess Normal file
View File

@@ -0,0 +1,13 @@
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
</IfModule>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# END WordPress

View File

@@ -51,10 +51,10 @@ class Wiass_REST_Delivery_Process_API {
foreach ($entries as $entry) {
$step = gravity_flow()->get_step( $entry['workflow_step'] );
$data[] = array(
'idOrder' => $entry['wiaas_delivery_order_id'],
'orderNumber' => $entry['wiaas_delivery_order_id'],
'order_id' => $entry['wiaas_delivery_order_id'],
'order_number' => $entry['wiaas_delivery_order_id'],
'status' => $entry['workflow_final_status'],
'stepAction' => $step->get_name(),
'step_action' => $step->get_name(),
);
}

View File

@@ -7,7 +7,8 @@ class Wiaas_DB_Update {
private static $db_updates = array(
'20180728222206' => 'wiaas_db_update_enable_product_by_user_role',
'20180801222206' => 'wiaas_db_update_setup_gravity',
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms'
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
'20180807222206' => 'wiaas_db_update_setup_customer_capabilities'
);
public static function execute() {

View File

@@ -159,4 +159,4 @@ class Wiaas_Delivery_Process {
}
}
add_action( 'gravityflow_loaded', array('Wiaas_Delivery_Process', 'init') );
add_action( 'gravityflow_loaded', array('Wiaas_Delivery_Process', 'init') );

View File

@@ -76,4 +76,11 @@ function wiaas_db_update_add_delivery_process_forms() {
}
do_action('gform_forms_post_import', $created_forms);
}
function wiaas_db_update_setup_customer_capabilities() {
$customer_role = get_role('customer');
$customer_role->add_cap('read_private_shop_orders');
$customer_role->add_cap('read_shop_order');
}

View File

@@ -246,4 +246,4 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
return absint($value);
}
}
}

View File

@@ -42,14 +42,14 @@ class Wiass_REST_Delivery_Process_Api_Test extends Wiaas_Unit_Test_Case {
$this->assertTrue(is_array($pending_step));
$this->assertArrayHasKey('idOrder', $pending_step);
$this->assertArrayHasKey('orderNumber', $pending_step);
$this->assertArrayHasKey('order_id', $pending_step);
$this->assertArrayHasKey('order_number', $pending_step);
$this->assertArrayHasKey('status', $pending_step);
$this->assertArrayHasKey('stepAction', $pending_step);
$this->assertArrayHasKey('step_action', $pending_step);
$this->assertEquals($pending_step['idOrder'], $this->order_id);
$this->assertEquals($pending_step['orderNumber'], $this->order_id);
$this->assertEquals($pending_step['order_id'], $this->order_id);
$this->assertEquals($pending_step['order_number'], $this->order_id);
$this->assertEquals($pending_step['status'], 'pending');
$this->assertNotEmpty($pending_step['stepAction']);
$this->assertNotEmpty($pending_step['step_action']);
}
}

View File

@@ -47,6 +47,7 @@
"wpackagist-plugin/mailchimp-for-woocommerce": "2.1.7",
"wpackagist-plugin/woocommerce-gateway-paypal-express-checkout": "1.5.6",
"wpackagist-plugin/jwt-authentication-for-wp-rest-api": "1.2.4",
"wpackagist-plugin/capability-manager-enhanced": "1.5.9",
"3rdparty/gravityforms": "*",
"3rdparty/gravityflow": "*"
@@ -75,6 +76,7 @@
"wp plugin activate jwt-authentication-for-wp-rest-api",
"wp plugin activate gravityforms",
"wp plugin activate gravityflow",
"wp plugin activate capability-manager-enhanced",
"wp plugin activate wiaas"
],
"update-db": [

24
backend/composer.lock generated
View File

@@ -1,10 +1,10 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "16aac868dbf84d6c3cf7c41703e9085f",
"content-hash": "dca54e67b0185da192f5260baa4c162e",
"packages": [
{
"name": "3rdparty/gravityflow",
@@ -437,6 +437,26 @@
"type": "wordpress-plugin",
"homepage": "https://wordpress.org/plugins/akismet/"
},
{
"name": "wpackagist-plugin/capability-manager-enhanced",
"version": "1.5.9",
"source": {
"type": "svn",
"url": "https://plugins.svn.wordpress.org/capability-manager-enhanced/",
"reference": "trunk"
},
"dist": {
"type": "zip",
"url": "https://downloads.wordpress.org/plugin/capability-manager-enhanced.zip?timestamp=1532180189",
"reference": null,
"shasum": null
},
"require": {
"composer/installers": "~1.0"
},
"type": "wordpress-plugin",
"homepage": "https://wordpress.org/plugins/capability-manager-enhanced/"
},
{
"name": "wpackagist-plugin/groups",
"version": "2.3.1",

View File

@@ -23,16 +23,6 @@ if (file_exists($env_config)) {
require_once $env_config;
}
/**
* Stops redirect loop on login page
*/
define('FORCE_SSL_ADMIN', true);
// in some setups HTTP_X_FORWARDED_PROTO might contain
// a comma-separated list e.g. http,https
// so check for https existence
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';
/**
* URLs
*/

View File

@@ -5,3 +5,13 @@ define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', false);
/** Disable all file modifications including updates and update notifications */
define('DISALLOW_FILE_MODS', true);
/**
* Stops redirect loop on login page
*/
define('FORCE_SSL_ADMIN', true);
// in some setups HTTP_X_FORWARDED_PROTO might contain
// a comma-separated list e.g. http,https
// so check for https existence
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';

View File

@@ -5,3 +5,13 @@ define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', false);
/** Disable all file modifications including updates and update notifications */
define('DISALLOW_FILE_MODS', true);
/**
* Stops redirect loop on login page
*/
define('FORCE_SSL_ADMIN', true);
// in some setups HTTP_X_FORWARDED_PROTO might contain
// a comma-separated list e.g. http,https
// so check for https existence
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';

View File

@@ -1,9 +1,9 @@
<?php
/**
* Do not edit this file. Edit the config files found in the config/ dir instead.
* This file is required in the root directory so WordPress can find it.
* WP is hardcoded to look in its own directory or one directory up for wp-config.php.
*/
require_once(__DIR__ . '/vendor/autoload.php');
require_once(__DIR__ . '/config/application.php');
require_once(ABSPATH . 'wp-settings.php');
<?php
/**
* Do not edit this file. Edit the config files found in the config/ dir instead.
* This file is required in the root directory so WordPress can find it.
* WP is hardcoded to look in its own directory or one directory up for wp-config.php.
*/
require_once(__DIR__ . '/vendor/autoload.php');
require_once(__DIR__ . '/config/application.php');
require_once(ABSPATH . 'wp-settings.php');

View File

@@ -24,4 +24,4 @@ WP_SECURE_AUTH_SALT=generate_me
WP_LOGGED_IN_SALT=generate_me
WP_NONCE_SALT=generate_me
WP_JWT_AUTH_SECRET_KEY=generate_me
WP_JWT_AUTH_SECRET_KEY=generate_me

View File

@@ -1,4 +1,5 @@
FROM php:7.0-apache
ARG API_URL
ENV REACT_APP_API_URL ${API_URL}

View File

@@ -57,6 +57,9 @@ export const receiveCustomerDetails = (json) => ({
export const fetchCartCount = () => {
return dispatch => {
dispatch(requestShopCartCount());
//TODO : fetch cart count from woocommerce (requires plugin)
dispatch(receiveShopCartCount(0));
/*
return client.fetch({url: `${API_SERVER}/cart/api/getCartCount`}).then(response => {
if (typeof response.data !== 'undefined' && 'cartItemsCount' in response.data) {
dispatch(receiveShopCartCount(response.data.cartItemsCount));
@@ -64,6 +67,7 @@ export const fetchCartCount = () => {
}).catch(error => {
client.onError(error, dispatch);
});
*/
}
}

View File

@@ -1,7 +1,4 @@
import {API_SERVER} from '../../config';
import HtmlClient from '../../helpers/HtmlClient';
import {REQUEST_GADGETS, RECIEVE_GADGETS} from '../../constants/dashboardConstants';
const htmlClient = new HtmlClient();
const requestGadgets = () => ({type: REQUEST_GADGETS});
const recieveGadgets = (json) => ({
@@ -12,6 +9,19 @@ const recieveGadgets = (json) => ({
export const fetchGadgets = () => {
return dispatch => {
dispatch(requestGadgets());
//TODO : check how to solve gadgets, don't use hardcoded values
const gadgets = [
{
name: 'CustomerOrderCentral',
idGadget: 0,
},
{
name: 'CustomerNextActions',
idGadget: 1,
}
]
dispatch(recieveGadgets(gadgets));
/*
return htmlClient.fetch({
url: `${API_SERVER}/dashboards/api/getMyDashboard`
})
@@ -23,5 +33,6 @@ export const fetchGadgets = () => {
.catch(error => {
htmlClient.onError(error, dispatch);
});
*/
}
}

View File

@@ -1,6 +1,7 @@
import {API_SERVER} from '../../config';
import HtmlClient from '../../helpers/HtmlClient';
import {REQUEST_NEXT_ACTIONS, RECIEVE_NEXT_ACTIONS} from '../../constants/dashboardConstants';
import { API_SERVER } from '../../config';
import HtmlClient from '../../helpers/HtmlClient';
const client = new HtmlClient();
export const requestNextActions = () => ({
@@ -18,11 +19,11 @@ export const fetchNextActions = () => {
return dispatch => {
dispatch(requestNextActions());
return client.fetch({
url: `${API_SERVER}/dashboards/api/getNextActionsInfo`
url: `${API_SERVER}/wp-json/wiaas/next-delivery-steps`
})
.then(response => dispatch(recieveNextActions(response.data)))
.catch(error => {
client.onError(error, dispatch);
});
});
}
}

View File

@@ -4,6 +4,8 @@ import {
REQUEST_ORDERS,
RECEIVE_ORDERS
} from '../../constants/dashboardConstants';
import {fromWCOrder} from '../../helpers/OrderHelper';
import { MAX_ORDER_COUNT } from '../../constants/ordersConstants';
const htmlClient = new HtmlClient();
export const requestOrders = () => ({
@@ -21,13 +23,12 @@ export const fetchOrders = (viewAllOrders) => {
return dispatch => {
dispatch(requestOrders());
return htmlClient.fetch({
url: `${API_SERVER}/dashboards/api/getOrderCentralInfo`,
method: 'post',
data: {
viewAllOrders
}
url: `${API_SERVER}/wp-json/wc/v2/orders?per_page=${MAX_ORDER_COUNT}`,
method: 'get',
})
.then(response => {
dispatch(recieveOrders(response.data.map(wcOrder => fromWCOrder(wcOrder))));
})
.then(response => dispatch(recieveOrders(response.data)))
.catch(error => {
htmlClient.onError(error, dispatch);
});

View File

@@ -161,6 +161,68 @@ const validateRefreshToken = () => {
export const getModules = () => {
return dispatch => {
dispatch(requestModules());
//TODO : check how to solve modules, don't hardocde values
const modules={
modules:{
modules:[
{
id:"19",
isInMenu:"0",
menuName:"Cart",
name:"Cart",
url:"cart",
},
{
id:"14",
isInMenu:"0",
menuName:"ProfileSettings",
name:"ProfileSettings",
url:"profileSettings",
},
{
id:"23",
isInMenu:"0",
menuName:"OrderProjects",
name:"OrderProjects",
url:"orderProjects",
},
{
id:"15",
isInMenu:"0",
menuName:"Terms",
name:"Terms",
url:"terms",
},
{
id:"1",
isInMenu:"1",
menuName:"Overview",
name:"Dashboards",
url:"dashboards",
},
{
id:"18",
isInMenu:"1",
menuName:"Co-Market",
name:"CoMarket",
url:"co-market",
}
],
subModules:{
"co-market":[
{
menuName:"Orders",
name:"Orders",
url:"orders",
moduleUrl:"co-market",
}
]
}
}
}
dispatch(recieveModules(modules));
/*
return htmlClient.fetch({
url: `${API_SERVER}/login/api/getModules`,
})
@@ -170,6 +232,7 @@ export const getModules = () => {
.catch(error => {
htmlClient.onError(error, dispatch);
});
*/
}
}

View File

@@ -3,5 +3,6 @@ const API_VERSION = 'v2';
const API_SERVER_BASE = process.env.REACT_APP_API_URL;
const API_SERVER = API_SERVER_BASE;
const API_SERVER_LOGIN = API_SERVER + "/wp-admin";
export {API_SERVER_BASE, API_SERVER, APPLICATION_NAME}
export {API_SERVER_BASE, API_SERVER, APPLICATION_NAME, API_SERVER_LOGIN}

View File

@@ -1,4 +1,4 @@
import {API_SERVER_BASE} from '../config.js';
import {API_SERVER_LOGIN} from '../config.js';
const MODULE = 'AUTH_';
@@ -36,7 +36,7 @@ export const loginMessages = {
CHANGE_LATER: 'You can change your password in 5 minutes!',
INVALID_REFRESH_TOKEN: 'Your session has expired!',
EXPIRED_SESSION : 'Your session has expired!',
INVALID_USER_TYPE: 'Users with other roles than "customer" must use this url for login: ' + API_SERVER_BASE,
INVALID_USER_TYPE: 'Users with other roles than "customer" must use this url for login: ' + API_SERVER_LOGIN,
INVALID_CHANGE_TOKEN: 'Invalid change token value!',
PASSWORDS_MISSING: 'Password can not be empty',
WRONG_USERNAME: 'Invalid username!',

View File

@@ -30,10 +30,10 @@ export const dashboardTexts = {
},
statuses: {
open: 'Open',
'in-progress': 'In Progress',
production: 'Production',
processing: 'In Progress',
completed: 'Production',
'end-of-life': 'End Of Life',
canceled: 'Canceled',
cancelled: 'Cancelled',
'not-accepted': 'Not Accepted',
invalid: 'Invalid',
pending: 'Pending'

View File

@@ -207,3 +207,5 @@ export const orderTexts = {
PLACED_BY: 'Placed by'
}
};
export const MAX_ORDER_COUNT = 5;

View File

@@ -36,8 +36,8 @@
background: $not-accepted-status-color;
}
.in-progress {
background: $in-progress-status-color;
.processing {
background: $processing-status-color;
}
.next-action-details{

View File

@@ -31,15 +31,15 @@
background: $open-status-color;
}
.in-progress {
background: $in-progress-status-color;
.processing {
background: $processing-status-color;
}
.line-open {
border-left: 3px $open-status-color solid;
}
.line-in-progress {
border-left: 3px $in-progress-status-color solid;
.line-processing {
border-left: 3px $processing-status-color solid;
}
}

View File

@@ -10,10 +10,10 @@ class NextActionItem extends Component {
return (
<Row className="next-actions-row">
<Col xl="8">
{nextAction.stepAction}
{nextAction.step_action}
</Col>
<Col xl="4">
<Link to={'orders/'+ nextAction.idOrder}>
<Link to={'orders/'+ nextAction.order_id}>
<div className={'next-actions-status ' + nextAction.status}>{dashboardTexts.statuses[nextAction.status]}</div>
</Link>
</Col>

View File

@@ -14,7 +14,7 @@ class NextActionsList extends Component {
{
nextActions &&
nextActions.map((nextAction, index) =>
<NextActionItem key={'action-' + nextAction.orderNumber + index} nextAction={nextAction}/>
<NextActionItem key={'action-' + nextAction.order_number + index} nextAction={nextAction}/>
)
}
</WiaasTableBody>

View File

@@ -12,9 +12,9 @@ class OrderItem extends Component {
<WiaasTableRow className={'order-central-row line-' + order.status}>
<WiaasTableCol header="#">
<i className="fa fa-list-alt package-photo" aria-hidden="true" />
<div className="orderNumber">{order.orderNumber}</div>
<div className="orderNumber">{order.number}</div>
</WiaasTableCol>
<WiaasTableCol header={dashboardTexts.tableHeaders.ORDER_DATE}>{order.orderDate}</WiaasTableCol>
<WiaasTableCol header={dashboardTexts.tableHeaders.ORDER_DATE}>{order.dateCreated}</WiaasTableCol>
{
isViewAllOrdersChecked &&
<WiaasTableCol header={dashboardTexts.tableHeaders.PLACED_BY}>{order.placedBy}</WiaasTableCol>
@@ -25,7 +25,7 @@ class OrderItem extends Component {
<WiaasTableCol header={dashboardTexts.tableHeaders.STATUS}>
<div className={'status-icon ' + order.status}></div>{dashboardTexts.statuses[order.status]}
</WiaasTableCol>
<WiaasTableCol><Link to={'orders/'+ order.idOrder}><Button className="wiaas-button">{dashboardTexts.buttons.DETAILS}</Button></Link></WiaasTableCol>
<WiaasTableCol><Link to={'orders/'+ order.id}><Button className="wiaas-button">{dashboardTexts.buttons.DETAILS}</Button></Link></WiaasTableCol>
</WiaasTableRow>
);
}

View File

@@ -46,7 +46,7 @@ class OrdersList extends Component {
{
orders &&
orders.map((order, index) =>
<OrderItem key={'order-' + order.orderNumber} order={order} isViewAllOrdersChecked={isViewAllOrdersChecked}/>
<OrderItem key={'order-' + order.number} order={order} isViewAllOrdersChecked={isViewAllOrdersChecked}/>
)
}
</WiaasTableBody>

View File

@@ -0,0 +1,15 @@
import moment from 'moment';
export const fromWCOrder = (order) => {
return {
id: order.id,
number: order.number,
dateCreated: moment(order.date_created).format("Do MMM, YYYY"),
reference: 'reference field',
assignedTo: 'assigned to',
fixedPrice: order.total,
recurringPrice: 0,
status: order.status,
currency: order.currency
}
}