diff --git a/.editorconfig b/.editorconfig index 22ba22b..bd766cd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,10 +1,10 @@ -root = true - -[*] +root = true + +[*] charset = utf-8 -end_of_line = lf -tab_width = 4 -indent_style = tab +end_of_line = lf +tab_width = 4 +indent_style = tab indent_size = 4 insert_final_newline = true trim_trailing_whitespace = true @@ -12,7 +12,7 @@ trim_trailing_whitespace = true [*.txt] trim_trailing_whitespace = false -[*.{md,json,yml}] +[*.{md,json,yml}] trim_trailing_whitespace = false indent_style = space indent_size = 2 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 93f1361..3abe3d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -node_modules -npm-debug.log +node_modules +npm-debug.log diff --git a/LICENSE b/LICENSE index 4d70343..27caba4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2018 Eoxia - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2018 Eoxia + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 1a96557..ed1a620 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# Ethos-DashBoard -Ethos-DashBoard allow a simple and fast control of your ETHOS mining farms +# Ethos-DashBoard +Ethos-DashBoard allow a simple and fast control of your ETHOS mining farms diff --git a/core/asset/css/scss/_variables.scss b/core/asset/css/scss/_variables.scss index f9d501e..74d45c9 100644 --- a/core/asset/css/scss/_variables.scss +++ b/core/asset/css/scss/_variables.scss @@ -1,9 +1,9 @@ -/** - * Les couleurs principales pour l'exemple de la page "Hello World". - * - * @since 0.1.0 - * @version 0.1.0 - */ - -$main-color: #389af6; -$second-color: rgba(0,0,0,0.6); +/** + * Les couleurs principales pour l'exemple de la page "Hello World". + * + * @since 0.1.0 + * @version 0.1.0 + */ + +$main-color: #389af6; +$second-color: rgba(0,0,0,0.6); diff --git a/core/asset/css/scss/style.scss b/core/asset/css/scss/style.scss index e9cf313..2f69a1e 100644 --- a/core/asset/css/scss/style.scss +++ b/core/asset/css/scss/style.scss @@ -1,12 +1,12 @@ -/** - * CSS générer par GULP grâce à la cmd "npm-start". - * - * Toute modification sur un fichier *.scss lance la compilation de tous les *.scss vers ce fichier. - * - * @since 0.1.0 - * @version 0.1.0 - */ - +/** + * CSS générer par GULP grâce à la cmd "npm-start". + * + * Toute modification sur un fichier *.scss lance la compilation de tous les *.scss vers ce fichier. + * + * @since 0.1.0 + * @version 0.1.0 + */ + @import "variables"; svg.fa-copy { diff --git a/core/asset/css/style.css b/core/asset/css/style.css index ebeb761..114db72 100644 --- a/core/asset/css/style.css +++ b/core/asset/css/style.css @@ -1,17 +1,17 @@ @charset "UTF-8"; -/** - * CSS générer par GULP grâce à la cmd "npm-start". - * - * Toute modification sur un fichier *.scss lance la compilation de tous les *.scss vers ce fichier. - * - * @since 0.1.0 - * @version 0.1.0 +/** + * CSS générer par GULP grâce à la cmd "npm-start". + * + * Toute modification sur un fichier *.scss lance la compilation de tous les *.scss vers ce fichier. + * + * @since 0.1.0 + * @version 0.1.0 */ -/** - * Les couleurs principales pour l'exemple de la page "Hello World". - * - * @since 0.1.0 - * @version 0.1.0 +/** + * Les couleurs principales pour l'exemple de la page "Hello World". + * + * @since 0.1.0 + * @version 0.1.0 */ svg.fa-copy { display: block; diff --git a/core/asset/js/backend.min.js b/core/asset/js/backend.min.js index 1f79115..80588cd 100644 --- a/core/asset/js/backend.min.js +++ b/core/asset/js/backend.min.js @@ -1,9 +1,9 @@ -/** - * Ce fichier "init.js" est obligatoire et son nom est très important pour faire fonctionné la lib JS de EO-Framework. - * - * @since 0.1.0 - */ -window.eoxiaJS.ethosDashboard = {}; +/** + * Ce fichier "init.js" est obligatoire et son nom est très important pour faire fonctionné la lib JS de EO-Framework. + * + * @since 0.1.0 + */ +window.eoxiaJS.ethosDashboard = {}; /** * Initialise l'objet "accident" ainsi que la méthode "init" obligatoire pour la bibliothèque EoxiaJS. @@ -18,6 +18,12 @@ window.eoxiaJS.ethosDashboard.RIG.init = function() { window.eoxiaJS.ethosDashboard.RIG.copyToClipboard( jQuery( this ).closest( '.acf-input' ).find( 'input[type="text"]' )[0] ); jQuery( this ).closest( '.acf-input' ).find( 'input[type="text"]' ).attr( 'disabled', 'disabled' ); } ); + + if ( jQuery( "body.post-type-rig .wp-heading-inline" ).text() !== 'Edit Post' ) { + jQuery( "body.post-type-rig .wrap .page-title-action").after('Regenerate TXT'); + } + + jQuery( document ).on( 'modal-opened', '.modal-regenerate-txt', window.eoxiaJS.ethosDashboard.RIG.modalOpened ); }; @@ -70,4 +76,37 @@ window.eoxiaJS.ethosDashboard.RIG.copyToClipboard = function(elem) { target.textContent = ""; } return succeed; -} +}; + +window.eoxiaJS.ethosDashboard.RIG.modalOpened = function( triggeredElement ) { + var data = { + action: 'regenerate_txt', + _wpnonce: jQuery( '.modal-regenerate-txt li.active:first' ).data( 'nonce' ), + ids: jQuery( '.modal-regenerate-txt li.active:first' ).data( 'ids' ), + number_error: jQuery( '.modal-regenerate-txt .number-error' ).val(), + number_success: jQuery( '.modal-regenerate-txt .number-success' ).val(), + total: jQuery( '.modal-regenerate-txt .total' ).val() + }; + + window.eoxiaJS.request.send( triggeredElement, data, function( element, response ) { + jQuery( '.modal-regenerate-txt li.active:first' ).find( 'img' ).remove(); + jQuery( '.modal-regenerate-txt li.active:first' ).append( '' ); + jQuery( '.modal-regenerate-txt li.active:first' ).removeClass( 'active' ); + + jQuery( '.modal-regenerate-txt .number-error' ).val( response.data.number_error ); + jQuery( '.modal-regenerate-txt .number-success' ).val( response.data.number_success ); + + for ( var key in response.data.error_message ) { + jQuery( '.modal-regenerate-txt li span[data-id="' + key + '"]' ).css( 'color', 'red' ); + jQuery( '.modal-regenerate-txt .log' ).append( '
  • ' + response.data.error_message[key] + '
  • ' ); + } + + if ( jQuery( '.modal-regenerate-txt li.active' ).length > 0 ) { + window.eoxiaJS.ethosDashboard.RIG.modalOpened( triggeredElement ); + } else { + jQuery( '.modal-regenerate-txt' ).removeClass( 'modal-force-display' ); + + jQuery( '.modal-regenerate-txt .log' ).append( '
  • ' + response.data.final_message + '
  • ' ); + } + } ); +}; diff --git a/core/asset/js/init.js b/core/asset/js/init.js index 2f9db52..fa72b49 100644 --- a/core/asset/js/init.js +++ b/core/asset/js/init.js @@ -1,6 +1,6 @@ -/** - * Ce fichier "init.js" est obligatoire et son nom est très important pour faire fonctionné la lib JS de EO-Framework. - * - * @since 0.1.0 - */ -window.eoxiaJS.ethosDashboard = {}; +/** + * Ce fichier "init.js" est obligatoire et son nom est très important pour faire fonctionné la lib JS de EO-Framework. + * + * @since 0.1.0 + */ +window.eoxiaJS.ethosDashboard = {}; diff --git a/core/asset/json/group_5b43270fefc28.json b/core/asset/json/group_5b43270fefc28.json index 1058c4e..7aa390d 100644 --- a/core/asset/json/group_5b43270fefc28.json +++ b/core/asset/json/group_5b43270fefc28.json @@ -56,28 +56,6 @@ "append": "", "maxlength": 8 }, - { - "key": "field_5b44c76b2be67", - "label": "Rig Group", - "name": "rig_category", - "type": "taxonomy", - "instructions": "", - "required": 1, - "conditional_logic": 0, - "wrapper": { - "width": "", - "class": "", - "id": "" - }, - "taxonomy": "rig_taxonomy", - "field_type": "radio", - "allow_null": 0, - "add_term": 1, - "save_terms": 0, - "load_terms": 0, - "return_format": "id", - "multiple": 0 - }, { "key": "field_5b43741a3a5e5", "label": ".txt file link", @@ -273,5 +251,5 @@ "hide_on_screen": "", "active": 1, "description": "", - "modified": 1532095611 + "modified": 1534768585 } \ No newline at end of file diff --git a/core/core.config.json b/core/core.config.json index 409db66..d307622 100644 --- a/core/core.config.json +++ b/core/core.config.json @@ -1,14 +1,14 @@ -{ - "name": "Core", - "slug": "core", - "version": "0.1.0", - "description": "Main files of my_plugin", - "path": "core/", - "dependencies": { +{ + "name": "Core", + "slug": "core", + "version": "0.1.0", + "description": "Main files of my_plugin", + "path": "core/", + "dependencies": { "class": {}, "util": {}, "helper": {}, "action": {}, "filter": {} - } -} + } +} diff --git a/ethos-dashboard.config.json b/ethos-dashboard.config.json index a72c13d..5ea3a1a 100644 --- a/ethos-dashboard.config.json +++ b/ethos-dashboard.config.json @@ -1,12 +1,12 @@ -{ - "name": "ethos-dashboard", - "slug": "ethos-dashboard", - "modules": [ +{ + "name": "ethos-dashboard", + "slug": "ethos-dashboard", + "modules": [ "core/core.config.json", "modules/rig/rig.config.json", "modules/rig-category/rig-category.config.json", "modules/wallet/wallet.config.json" - ], - "version": "0.1.0", - "folder_meta_key": "_ethos_dashboard_folder" -} + ], + "version": "0.2.0", + "folder_meta_key": "_ethos_dashboard_folder" +} diff --git a/ethos-dashboard.php b/ethos-dashboard.php index c2386ec..41fcd43 100644 --- a/ethos-dashboard.php +++ b/ethos-dashboard.php @@ -3,7 +3,7 @@ * Plugin Name: ethos-dashboard * Plugin URI: http://www.eoxia.com * Description: Handle ethos config - * Version: 0.1.0 + * Version: 0.2.0 * Author: Eoxia * Author URI: http://www.eoxia.com * License: AGPLv3 diff --git a/gulpfile.js b/gulpfile.js index 303562f..477daa4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,60 +1,60 @@ -/** - * GULP - * - * @since 0.1.0 - * @version 0.1.0 - */ - -var gulp = require('gulp'); -var please = require('gulp-pleeease'); -var watch = require('gulp-watch'); -var plumber = require('gulp-plumber'); -var rename = require("gulp-rename"); -var cssnano = require('gulp-cssnano'); -var concat = require('gulp-concat'); -var glob = require("glob"); -var uglify = require('gulp-uglify'); -var sass = require('gulp-sass'); - -var paths = { - all_js: ['core/asset/js/init.js', '**/*.backend.js'], - scss_backend:[ 'core/asset/css/scss/**/*.scss', 'core/asset/css/' ] -}; - -gulp.task('js', function() { - return gulp.src(paths.all_js) - .pipe(concat('backend.min.js')) - .pipe(gulp.dest('core/asset/js/')) -}); - - -gulp.task('build_scss_backend', function() { - gulp.src(paths.scss_backend[0]) - .pipe( sass().on( 'error', sass.logError ) ) - .pipe(please({ - minifier: false, - autoprefixer: {"browsers": ["last 40 versions", "ios 6", "ie 9"]}, - pseudoElements: true, - sass: true - })) - .pipe( gulp.dest( paths.scss_backend[1] ) ); -}); - -gulp.task('build_scss_backend_min', function() { - gulp.src(paths.scss_backend[0]) - .pipe( sass().on( 'error', sass.logError ) ) - .pipe(please({ - minifier: true, - autoprefixer: {"browsers": ["last 40 versions", "ios 6", "ie 9"]}, - pseudoElements: true, - sass: true, - out: 'style.min.css' - })) - .pipe( gulp.dest( paths.scss_backend[1] ) ); -}); - -gulp.task('default', function() { - gulp.watch(paths.all_js, ["js"]); - gulp.watch(paths.scss_backend[0], ["build_scss_backend"]); - gulp.watch(paths.scss_backend[0], ["build_scss_backend_min"]); -}); +/** + * GULP + * + * @since 0.1.0 + * @version 0.1.0 + */ + +var gulp = require('gulp'); +var please = require('gulp-pleeease'); +var watch = require('gulp-watch'); +var plumber = require('gulp-plumber'); +var rename = require("gulp-rename"); +var cssnano = require('gulp-cssnano'); +var concat = require('gulp-concat'); +var glob = require("glob"); +var uglify = require('gulp-uglify'); +var sass = require('gulp-sass'); + +var paths = { + all_js: ['core/asset/js/init.js', '**/*.backend.js'], + scss_backend:[ 'core/asset/css/scss/**/*.scss', 'core/asset/css/' ] +}; + +gulp.task('js', function() { + return gulp.src(paths.all_js) + .pipe(concat('backend.min.js')) + .pipe(gulp.dest('core/asset/js/')) +}); + + +gulp.task('build_scss_backend', function() { + gulp.src(paths.scss_backend[0]) + .pipe( sass().on( 'error', sass.logError ) ) + .pipe(please({ + minifier: false, + autoprefixer: {"browsers": ["last 40 versions", "ios 6", "ie 9"]}, + pseudoElements: true, + sass: true + })) + .pipe( gulp.dest( paths.scss_backend[1] ) ); +}); + +gulp.task('build_scss_backend_min', function() { + gulp.src(paths.scss_backend[0]) + .pipe( sass().on( 'error', sass.logError ) ) + .pipe(please({ + minifier: true, + autoprefixer: {"browsers": ["last 40 versions", "ios 6", "ie 9"]}, + pseudoElements: true, + sass: true, + out: 'style.min.css' + })) + .pipe( gulp.dest( paths.scss_backend[1] ) ); +}); + +gulp.task('default', function() { + gulp.watch(paths.all_js, ["js"]); + gulp.watch(paths.scss_backend[0], ["build_scss_backend"]); + gulp.watch(paths.scss_backend[0], ["build_scss_backend_min"]); +}); diff --git a/modules/rig-category/action/class-rig-category-action.php b/modules/rig-category/action/class-rig-category-action.php index 29f330b..bbeed76 100644 --- a/modules/rig-category/action/class-rig-category-action.php +++ b/modules/rig-category/action/class-rig-category-action.php @@ -28,7 +28,7 @@ public function __construct() { add_action( 'admin_menu', array( $this, 'callback_admin_menu' ) ); - add_action( 'edited_terms', array( $this, 'callback_edit_terms'), 10, 2 ); + add_action( 'edited_terms', array( $this, 'callback_edit_terms' ), 10, 2 ); } /** @@ -50,9 +50,6 @@ public function callback_init() { 'show_ui' => true, 'show_in_menu' => 'ethos-dashboard', 'show_admin_column' => true, - 'show_in_nav_menus' => true, - 'show_tagcloud' => true, - 'meta_box_cb' => false, ); register_taxonomy( Rig_Category_Class::g()->taxonomy, array( 'rig' ), $args ); diff --git a/modules/rig-category/filter/class-rig-category-filter.php b/modules/rig-category/filter/class-rig-category-filter.php new file mode 100644 index 0000000..04e4538 --- /dev/null +++ b/modules/rig-category/filter/class-rig-category-filter.php @@ -0,0 +1,70 @@ + + * @copyright (c) 2018 Eoxia + * @license MIT + * @package Ethos_Dashboard\Filters + * @since 0.2.0 + */ + +namespace ethos_dashboard; + +defined( 'ABSPATH' ) || exit; + +/** + * Rig Category Filter class. + */ +class Rig_Category_Filter { + + /** + * Constructeur. + * + * @since 0.2.0 + */ + public function __construct() { + add_filter( 'manage_edit-rig_taxonomy_columns', array( $this, 'callback_taxonomy_columns' ) ); + add_filter( 'manage_rig_taxonomy_custom_column', array( $this, 'callback_taxonomy_custom_column' ), 10, 3 ); + } + + /** + * Supprimes les colones descriptions et slug. + * Ajoutes la colone "Wallet". + * + * @since 0.2.0 + * + * @param array $columns Les colonnes à modifier. + * @return array Les nouvelles colonnes. + */ + public function callback_taxonomy_columns( $columns ) { + if ( isset( $columns['description'] ) ) { + unset( $columns['description'] ); + } + + if ( isset( $columns['slug'] ) ) { + unset( $columns['slug'] ); + } + + $columns['wallet'] = __( 'Wallet', 'ethos-dashboard' ); + + return $columns; + } + + public function callback_taxonomy_custom_column( $column, $column_name, $term_id ) { + switch ( $column_name ) { + case 'wallet': + $id = Rig_Category_Class::g()->taxonomy . '_' . $term_id; + $wallet_id = get_field( 'wallet_id', $id ); + + if ( ! empty( $wallet_id ) ) { + echo get_the_title( $wallet_id ); + } else { + _e( 'No wallet associated', 'ethos-dashboard' ); + } + break; + } + } +} + +new Rig_Category_Filter(); diff --git a/modules/rig-category/rig-category.config.json b/modules/rig-category/rig-category.config.json index c7353a1..76180e9 100644 --- a/modules/rig-category/rig-category.config.json +++ b/modules/rig-category/rig-category.config.json @@ -5,6 +5,7 @@ "path": "modules/rig-category", "dependencies": { "action": {}, - "class": {} + "class": {}, + "filter": {} } } diff --git a/modules/rig/action/class-rig-action.php b/modules/rig/action/class-rig-action.php index ec78822..d06f7a3 100644 --- a/modules/rig/action/class-rig-action.php +++ b/modules/rig/action/class-rig-action.php @@ -26,7 +26,13 @@ class Rig_Action { public function __construct() { add_action( 'init', array( $this, 'callback_init' ) ); add_action( 'save_post', array( $this, 'callback_save_post' ), 20, 3 ); + + add_action( 'add_meta_boxes_rig', array( $this, 'callback_meta_boxes' ) ); + add_action( 'acf/render_field', array( $this, 'callback_link_txt' ), 21, 1 ); + + add_action( 'wp_ajax_load_modal_regenerate', array( $this, 'callback_load_modal_regenerate' ) ); + add_action( 'wp_ajax_regenerate_txt', array( $this, 'callback_regenerate_txt' ) ); } /** @@ -35,7 +41,6 @@ public function __construct() { * @version 0.1.0 */ public function callback_init() { - $labels = array( 'name' => _x( 'Rigs', 'Post Type General Name', 'ethos-dashboard' ), 'singular_name' => _x( 'Rig', 'Post Type Singular Name', 'ethos-dashboard' ), @@ -76,15 +81,19 @@ public function callback_init() { */ public function callback_save_post( $post_id, $post, $update ) { if ( 'rig' === $post->post_type && $update ) { - $category = get_term( get_field( 'rig_category', $post_id ), Rig_Category_Class::g()->taxonomy ); + $categories = wp_get_post_terms( $post->ID, Rig_Category_Class::g()->taxonomy ); - $category->acf = Rig_Category_Class::g()->get_fields( $category->term_id ); - $wallet = Wallet_Class::g()->get_fields( $category->acf['wallet_id'] ); - $rig = Rig_Class::g()->get_fields( $post_id ); + if ( ! empty( $categories[0] ) ) { + $category = $categories[0]; - unset( $category->acf['wallet_id'] ); + $category->acf = Rig_Category_Class::g()->get_fields( $category->term_id ); + $wallet = Wallet_Class::g()->get_fields( $category->acf['wallet_id'] ); + $rig = Rig_Class::g()->get_fields( $post_id ); - Rig_Class::g()->generate( $post_id, $rig, $wallet, $category->acf ); + unset( $category->acf['wallet_id'] ); + + Rig_Class::g()->generate( $post_id, $rig, $wallet, $category->acf ); + } } } @@ -101,6 +110,187 @@ public function callback_link_txt( $field ) { echo ''; } } + + /** + * Ajoutes la metabox permettant de préviualiser le résultat du fichier .txt. + * + * @since 0.2.0 + */ + public function callback_meta_boxes() { + add_meta_box( 'rig-preview-txt', __( 'Preview TXT', 'ethos-dashboard' ), array( $this, 'render_preview_txt' ), 'rig', 'side' ); + } + + /** + * Gestion du rendu de la metabox. + * + * @since 0.2.0 + */ + public function render_preview_txt() { + $post_id = get_the_ID(); + $txt_path = get_post_meta( $post_id, 'path_txt', true ); + $errors = get_post_meta( $post_id, 'errors', true ); + + if ( ! empty( $errors ) ) { + echo '
    ';
    +			_e( 'Preview is not available.', 'ethos-dashboard' );
    +			echo PHP_EOL;
    +			printf(  __( 'This rig contains %d errors: ', 'ethos-dashboard' ), count( $errors ) );
    +			echo PHP_EOL;
    +			echo esc_html( join( $errors, PHP_EOL ) );
    +			echo '
    '; + } else { + if ( file_exists( $txt_path ) ) { + $content = file_get_contents( $txt_path ); + echo '
    ';
    +				echo esc_html( $content );
    +				echo '
    '; + } else { + _e( 'Preview is not available. Publish or Update your rig setting.', 'ethos-dashboard' ); + } + } + } + + /** + * Charges la vue de la modal pour la génération des fichiers TXT. + * Prépares des données pour la vue. Groupes dans un tableau les rigs 20 + * par 20. Construit un fullname qui correspond au post_title des 20 rigs. + * + * @since 0.2.0 + */ + public function callback_load_modal_regenerate() { + $i = 0; + + $rigs = get_posts( array( + 'post_type' => 'rig', + 'posts_per_page' => -1, + ) ); + + $group_rigs = array(); + $tmp_rigs_array = array(); + $fullname = ''; + $ids = ''; + + while ( $i < \eoxia\Config_Util::$init['ethos-dashboard']->rig->generate_mass_number ) { + if ( empty( $rigs[ $i ] ) ) { + $fullname = substr( $fullname, 0, -2 ); + $ids = substr( $ids, 0, -1 ); + + $group_rigs[] = array( + 'rigs' => $tmp_rigs_array, + 'fullname' => $fullname, + 'ids' => $ids, + ); + // Break the loop if no rig found. + break; + } + + $tmp_rigs_array[] = $rigs[ $i ]; + $fullname .= '' . $rigs[ $i ]->post_title . ', '; + $ids .= $rigs[ $i ]->ID .','; + + + if ( $i / \eoxia\Config_Util::$init['ethos-dashboard']->rig->generate_mass_number === 1 || $i >= count( $rigs ) ) { + $fullname = substr( $fullname, 0, -2 ); + $ids = substr( $ids, 0, -1 ); + + $group_rigs[] = array( + 'rigs' => $tmp_rigs_array, + 'fullname' => $fullname, + 'ids' => $ids, + ); + + $tmp_rigs_array = array(); + } + + if ( $i >= count( $rigs ) ) { + break; + } + + $i++; + } + + ob_start(); + \eoxia\View_Util::exec( 'ethos-dashboard', 'rig', 'modal-list', array( + 'group_rigs' => $group_rigs, + 'total' => $i, + ) ); + $view = ob_get_clean(); + + wp_send_json_success( array( + 'view' => $view, + ) ); + } + + /** + * Regnères en masses les TXT de tous les rigs. + * + * @since 0.2.0 + */ + public function callback_regenerate_txt() { + check_ajax_referer( 'regenerate_txt' ); + + $ids = ! empty( $_POST['ids'] ) ? sanitize_text_field( $_POST['ids'] ) : ''; + $number_error = ! empty( $_POST['number_error'] ) ? (int) $_POST['number_error'] : 0; + $number_success = ! empty( $_POST['number_success'] ) ? (int) $_POST['number_success'] : 0; + $total = ! empty( $_POST['total'] ) ? (int) $_POST['total'] : 0; + + if ( empty( $ids ) ) { + wp_send_json_error(); + } + + $ids = explode( ',', $ids ); + + $error_message = array(); + + if ( ! empty( $ids ) ) { + foreach ( $ids as $id ) { + $categories = wp_get_post_terms( $id, Rig_Category_Class::g()->taxonomy ); + + if ( ! empty( $categories[0] ) ) { + $category = $categories[0]; + + $category->acf = Rig_Category_Class::g()->get_fields( $category->term_id ); + $wallet = Wallet_Class::g()->get_fields( $category->acf['wallet_id'] ); + $rig = Rig_Class::g()->get_fields( $id ); + + unset( $category->acf['wallet_id'] ); + + $state = Rig_Class::g()->generate( $id, $rig, $wallet, $category->acf ); + if ( true === $state ) { + $number_success++; + } else { + $number_error++; + $rig = get_post( $id ); + $link = '' . __( 'Fix it', 'ethos-dashboard' ) . ''; + + $error_message[ $id ] = sprintf( __( 'Unable to generate the txt file of the rig: %s, %s
    Errors:
    %s', 'ethos-dashboard' ), $rig->post_title, $link, join( $state, '
    ' ) ); + } + } else { + $number_error++; + $rig = get_post( $id ); + $link = '' . __( 'Fix it', 'ethos-dashboard' ) . ''; + + $error_message[ $id ] = sprintf( __( 'Unable to generate the txt file of the rig: %s, no group rig was found on it. %s', 'ethos-dashboard' ), $rig->post_title, $link ); + } + } + } + + $final_message = ''; + + if ( $number_error + $number_success >= $total ) { + $error = sprintf( _n( '%d error', '%d errors', $number_error, 'ethos-dashboard' ), number_format_i18n( $number_error ) ); + $success = sprintf( _n( '%d success', '%d successes', $number_success, 'ethos-dashboard' ), number_format_i18n( $number_success ) ); + $final_message = sprintf( __( 'Generation is complete with %s and %s on a total of %d rigs' ), $error, $success, $total ); + } + + wp_send_json_success( array( + 'number_error' => $number_error, + 'number_success' => $number_success, + 'total' => $total, + 'error_message' => $error_message, + 'final_message' => $final_message, + ) ); + } } new Rig_Action(); diff --git a/modules/rig/asset/js/rig.backend.js b/modules/rig/asset/js/rig.backend.js index 9158b85..85ced88 100644 --- a/modules/rig/asset/js/rig.backend.js +++ b/modules/rig/asset/js/rig.backend.js @@ -11,6 +11,12 @@ window.eoxiaJS.ethosDashboard.RIG.init = function() { window.eoxiaJS.ethosDashboard.RIG.copyToClipboard( jQuery( this ).closest( '.acf-input' ).find( 'input[type="text"]' )[0] ); jQuery( this ).closest( '.acf-input' ).find( 'input[type="text"]' ).attr( 'disabled', 'disabled' ); } ); + + if ( jQuery( "body.post-type-rig .wp-heading-inline" ).text() !== 'Edit Post' ) { + jQuery( "body.post-type-rig .wrap .page-title-action").after('Regenerate TXT'); + } + + jQuery( document ).on( 'modal-opened', '.modal-regenerate-txt', window.eoxiaJS.ethosDashboard.RIG.modalOpened ); }; @@ -63,4 +69,37 @@ window.eoxiaJS.ethosDashboard.RIG.copyToClipboard = function(elem) { target.textContent = ""; } return succeed; -} +}; + +window.eoxiaJS.ethosDashboard.RIG.modalOpened = function( triggeredElement ) { + var data = { + action: 'regenerate_txt', + _wpnonce: jQuery( '.modal-regenerate-txt li.active:first' ).data( 'nonce' ), + ids: jQuery( '.modal-regenerate-txt li.active:first' ).data( 'ids' ), + number_error: jQuery( '.modal-regenerate-txt .number-error' ).val(), + number_success: jQuery( '.modal-regenerate-txt .number-success' ).val(), + total: jQuery( '.modal-regenerate-txt .total' ).val() + }; + + window.eoxiaJS.request.send( triggeredElement, data, function( element, response ) { + jQuery( '.modal-regenerate-txt li.active:first' ).find( 'img' ).remove(); + jQuery( '.modal-regenerate-txt li.active:first' ).append( '' ); + jQuery( '.modal-regenerate-txt li.active:first' ).removeClass( 'active' ); + + jQuery( '.modal-regenerate-txt .number-error' ).val( response.data.number_error ); + jQuery( '.modal-regenerate-txt .number-success' ).val( response.data.number_success ); + + for ( var key in response.data.error_message ) { + jQuery( '.modal-regenerate-txt li span[data-id="' + key + '"]' ).css( 'color', 'red' ); + jQuery( '.modal-regenerate-txt .log' ).append( '
  • ' + response.data.error_message[key] + '
  • ' ); + } + + if ( jQuery( '.modal-regenerate-txt li.active' ).length > 0 ) { + window.eoxiaJS.ethosDashboard.RIG.modalOpened( triggeredElement ); + } else { + jQuery( '.modal-regenerate-txt' ).removeClass( 'modal-force-display' ); + + jQuery( '.modal-regenerate-txt .log' ).append( '
  • ' + response.data.final_message + '
  • ' ); + } + } ); +}; diff --git a/modules/rig/class/class-rig.php b/modules/rig/class/class-rig.php index 3474848..76bc6ca 100644 --- a/modules/rig/class/class-rig.php +++ b/modules/rig/class/class-rig.php @@ -18,12 +18,35 @@ */ class Rig_Class extends \eoxia\Singleton_Util { + /** + * Les slug des données à enregistrer en base de donnée après traitement. + * + * @since 0.2.0 + * @access public + * @var array $displayed_column_data Les slug des données à enregistrer + * en base de donnée après traitement. + */ + public $displayed_column_data = array( 'proxywallet', 'poolemail', 'proxypool1' ); + + /** + * Les messages d'erreurs reliée au donnée. + * + * @since 0.2.0 + * @access private + * @var array $data_errors_message Les messages d'erreurs reliée au donnée. + */ + private $data_errors_message; + /** * Constructor. * * @since 0.1.0 */ - protected function construct() {} + protected function construct() { + $this->data_errors_message['proxywallet'] = __( 'Wallet not found', 'ethos-dashboard' ); + $this->data_errors_message['poolemail'] = __( 'Poolemail not found', 'ethos-dashboard' ); + $this->data_errors_message['proxypool1'] = __( 'Proxypool1 not found', 'ethos-dashboard' ); + } /** * Récupères les champs du rig selon $post_id. @@ -60,38 +83,58 @@ public function generate( $id, $rig_data, $wallet_data, $category_data ) { $data = array_merge( $wallet_data, $category_data, $rig_data ); $data = $this->order_data( $data ); - $upload_path = Core_Util::g()->get_upload_path(); + $errors = array(); - $output = ''; - if ( ! empty( $data ) ) { - foreach ( $data as $key => $value ) { - if ( ! empty( $value ) ) { - $output .= $key . ' ' . $value . " -"; - } + foreach ( $this->data_errors_message as $key => $error_message ) { + if ( empty( $data[ $key ] ) ) { + $errors[] = $error_message; } } - $uploads = wp_upload_dir(); + if ( 0 === count( $errors ) ) { + $upload_path = Core_Util::g()->get_upload_path(); - $full_url = get_post_meta( $id, 'lien_txt', true ); + $output = ''; + if ( ! empty( $data ) ) { + foreach ( $data as $key => $value ) { + if ( ! empty( $value ) ) { + $output .= $key . ' ' . $value . PHP_EOL; + } + } + } - if ( ! empty( $full_url ) ) { - $full_path = str_replace( '\\', '/', str_replace( $uploads['baseurl'] , $uploads['basedir'], $full_url ) ); - } else { - $full_path = $upload_path . Core_Util::g()->random_str( 64 ) . '.txt'; - } + $uploads = wp_upload_dir(); + + $full_url = get_post_meta( $id, 'lien_txt', true ); + $full_url = get_post_meta( $id, 'path_txt', true ); - if ( $file = fopen( $full_path, 'w+' ) ) { - if ( fputs( $file, $output ) ) { - \eoxia\LOG_Util::log( 'Update file ' . $full_path . '
    ' . $output, 'ethos-dashboard' ); + if ( ! empty( $full_url ) ) { + $full_path = str_replace( '\\', '/', str_replace( $uploads['baseurl'], $uploads['basedir'], $full_url ) ); + } else { + $full_path = $upload_path . Core_Util::g()->random_str( 64 ) . '.txt'; } - fclose( $file ); + if ( $file = fopen( $full_path, 'w+' ) ) { + if ( fputs( $file, $output ) ) { + \eoxia\LOG_Util::log( 'Update file ' . $full_path . '
    ' . $output, 'ethos-dashboard' ); + } + fclose( $file ); + + $url = str_replace( str_replace( '\\', '/', $uploads['basedir'] ), $uploads['baseurl'], $full_path ); - $url = str_replace( str_replace( '\\', '/', $uploads['basedir'] ), $uploads['baseurl'], $full_path ); + $column_data = $this->process_column_data( $data ); + $title_column_data = array_merge( $data, $column_data ); - update_post_meta( $id, 'lien_txt', $url ); + update_post_meta( $id, 'column_data', $column_data ); + update_post_meta( $id, 'title_column_data', $title_column_data ); + update_post_meta( $id, 'lien_txt', $url ); + update_post_meta( $id, 'path_txt', $full_path ); + delete_post_meta( $id, 'errors' ); + return true; + } + } else { + update_post_meta( $id, 'errors', $errors ); + return $errors; } } @@ -123,6 +166,38 @@ public function order_data( $data ) { return $sorted_array; } + + /** + * Traites les trois données principaux pour les colonnes. Effaces certaines + * parties des données. + * + * @since 0.2.0 + * + * @param array $data Les données à modifier. + * @return array Les données modifiées. + */ + private function process_column_data( $data ) { + $founded_data = array(); + + if ( ! empty( $data ) ) { + foreach ( $data as $key => $value ) { + if ( in_array( $key, $this->displayed_column_data, true ) ) { + $founded_data[ $key ] = $value; + } + } + } + + $founded_data['proxywallet'] = 'wallet .....' . substr( $founded_data['proxywallet'], strlen( $founded_data['proxywallet'] ) - 3, 3 ); + + // Process poolemail: Récupères les deux premières lettres et le deux dernières lettres. + $poolemail_begin = substr( $founded_data['poolemail'], 0, 2 ); + $poolemail_end = substr( $founded_data['poolemail'], strlen( $founded_data['poolemail'] ) - 5, 5 ); + + $founded_data['poolemail'] = 'poolemail ' . $poolemail_begin . '...@...' . $poolemail_end; + $founded_data['proxypool1'] = 'proxypool1 ' . $founded_data['proxypool1']; + + return $founded_data; + } } Rig_Class::g(); diff --git a/modules/rig/filter/class-rig-filter.php b/modules/rig/filter/class-rig-filter.php index 635d204..d06004b 100644 --- a/modules/rig/filter/class-rig-filter.php +++ b/modules/rig/filter/class-rig-filter.php @@ -26,6 +26,9 @@ class Rig_Filter { */ public function __construct() { add_filter( 'acf/load_field/name=lien_txt', array( $this, 'disable_acf_load_field' ) ); + + add_filter( 'manage_rig_posts_columns', array( $this, 'callback_rig_posts_columns' ) ); + add_filter( 'manage_rig_posts_custom_column', array( $this, 'callback_rig_posts_custom_column' ), 10, 2 ); } /** @@ -41,6 +44,103 @@ public function disable_acf_load_field( $field ) { $field['disabled'] = 1; return $field; } + + /** + * Ajoutes les colones "Generate date" et "Preview TXT". + * + * @since 0.2.0 + * + * @param array $columns Les colonnes à rajouter. + * + * @return array Les colonnes à rajouter. + */ + public function callback_rig_posts_columns( $columns ) { + $columns['generate_date'] = __( 'Generate date file', 'ethos-dashboard' ); + $columns['preview_txt'] = __( 'Preview TXT', 'ethos-dashboard' ); + $columns['link_txt'] = __( 'TXT link', 'ethos-dashboard' ); + return $columns; + } + + /** + * Le contenu des colonnes par post. + * + * @since 0.2.0 + * + * @param string $column Le slug de la colonne. + * @param integer $post_id L'ID du post. + */ + public function callback_rig_posts_custom_column( $column, $post_id ) { + $output = ''; + + switch ( $column ) { + case 'generate_date': + $path_txt = get_post_meta( $post_id, 'path_txt', true ); + + if ( file_exists( $path_txt ) ) { + $timestamp = filemtime( $path_txt ); + $date = date( 'Y/m/d', $timestamp ); + $full_date = date( 'Y/m/d g:m:s a', $timestamp ); + $output = __( 'Last Modified' ); + $output .= '
    ' . $date . ''; + echo $output; + } else { + _e( 'File not generated yet', 'ethos-dashboard' ); + } + break; + case 'preview_txt': + $txt_url = get_post_meta( $post_id, 'lien_txt', true ); + $displayed_data = get_post_meta( $post_id, 'column_data', true ); + $full_data = get_post_meta( $post_id, 'title_column_data', true ); + $errors = get_post_meta( $post_id, 'errors', true ); + $output_title = ''; + + + if ( ! empty( $errors ) ) { + echo '
    ';
    +					_e( 'Preview is not available.', 'ethos-dashboard' );
    +					echo PHP_EOL;
    +					printf(  __( 'This rig contains %d errors: ', 'ethos-dashboard' ), count( $errors ) );
    +					echo PHP_EOL;
    +					echo esc_html( join( $errors, PHP_EOL ) );
    +					echo '
    '; + } else { + + if ( ! empty( $displayed_data ) ) { + + if ( ! empty( $full_data ) ) { + foreach ( $full_data as $key => $value ) { + if ( ! empty( $value ) ) { + if ( ! in_array( $key, Rig_Class::g()->displayed_column_data, true ) ) { + $output_title .= $key . ' '; + } + + $output_title .= $value . PHP_EOL; + } + } + } + + $output = '' . join( $displayed_data, PHP_EOL ) . ''; + echo '
    ';
    +						echo $output;
    +						echo '
    '; + } else { + _e( 'Preview not available.', 'ethos-dashboard' ); + } + } + break; + case 'link_txt': + $txt_url = get_post_meta( $post_id, 'lien_txt', true ); + $errors = get_post_meta( $post_id, 'errors', true ); + + if ( empty( $errors ) ) { + printf( __( '%s', 'ethos-dashboard' ), $txt_url, substr( $txt_url, 0, 20 ) . '...' . substr( $txt_url, strlen( $txt_url ) - 20, strlen( $txt_url ) - 5 ) ); + } else { + _e( 'Unable to retrieve txt link', 'ethos-dashboard' ); + } + break; + } + + } } new Rig_Filter(); diff --git a/modules/rig/rig.config.json b/modules/rig/rig.config.json index 9d9a510..4ac7946 100644 --- a/modules/rig/rig.config.json +++ b/modules/rig/rig.config.json @@ -7,5 +7,6 @@ "action": {}, "class": {}, "filter": {} - } + }, + "generate_mass_number": 20 } diff --git a/modules/rig/view/index.php b/modules/rig/view/index.php new file mode 100644 index 0000000..e69de29 diff --git a/modules/rig/view/modal-list.view.php b/modules/rig/view/modal-list.view.php new file mode 100644 index 0000000..b980e04 --- /dev/null +++ b/modules/rig/view/modal-list.view.php @@ -0,0 +1,46 @@ + + * @copyright (c) 2018 Eoxia . + * + * @license MIT + * + * @package Ethos_Dashboard\Templates + * + * @since 0.2.0 + */ + +namespace ethos_dashboard; + +defined( 'ABSPATH' ) || exit; ?> + + + + + +
      + +
    • + array( + 'data-id' => array() + ), + ) ); ?> + <?php echo esc_attr( 'Chargement...' ); ?> +
    • + +
    + +

    + +
      diff --git a/package.json b/package.json index 0237c74..2dfe4f7 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,24 @@ -{ - "name": "submodule-gulp", - "version": "0.1.0", - "description": "Submodule et GULP", - "main": "gulpfile.js", - "scripts": { - "install": "git submodule init && git submodule update --remote --recursive --force", - "update": "npm install", - "start": "node node_modules/gulp/bin/gulp.js" - }, - "author": "Eoxia team", - "license": "GPLv3", - "devDependencies": { - "gulp": "^3.9.1", - "gulp-pleeease": "^2.0.2", - "gulp-plumber": "^1.1.0", - "gulp-watch": "^4.3.5", - "gulp-cssnano": "^2.1.2", - "gulp-rename": "^1.2.2", - "gulp-sass": "latest", - "gulp-concat": "latest", - "gulp-uglify": "latest" - } -} +{ + "name": "submodule-gulp", + "version": "0.1.0", + "description": "Submodule et GULP", + "main": "gulpfile.js", + "scripts": { + "install": "git submodule init && git submodule update --remote --recursive --force", + "update": "npm install", + "start": "node node_modules/gulp/bin/gulp.js" + }, + "author": "Eoxia team", + "license": "GPLv3", + "devDependencies": { + "gulp": "^3.9.1", + "gulp-pleeease": "^2.0.2", + "gulp-plumber": "^1.1.0", + "gulp-watch": "^4.3.5", + "gulp-cssnano": "^2.1.2", + "gulp-rename": "^1.2.2", + "gulp-sass": "latest", + "gulp-concat": "latest", + "gulp-uglify": "latest" + } +}