Skip to content

Commit 214e428

Browse files
committed
cleanup component
1 parent ac54971 commit 214e428

File tree

1 file changed

+59
-33
lines changed

1 file changed

+59
-33
lines changed

php/ui/component/class-sync.php

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,88 @@
77

88
namespace Cloudinary\UI\Component;
99

10-
use function Cloudinary\get_plugin_instance;
11-
1210
/**
1311
* Sync Component to hold data.
1412
*
1513
* @package Cloudinary\UI
1614
*/
1715
class Sync extends Text {
1816

17+
/**
18+
* Holds the components build blueprint.
19+
*
20+
* @var string
21+
*/
22+
protected $blueprint = 'wrap|icon/|div|label|title|tooltip/|/title|/label|/div|status/|action/|/wrap';
23+
1924
/**
2025
* Filter the input parts structure.
2126
*
2227
* @param array $struct The array structure.
2328
*
2429
* @return array
2530
*/
26-
protected function input( $struct ) {
31+
protected function status( $struct ) {
2732

2833
$to_sync = $this->count_to_sync();
29-
if ( empty( $to_sync ) ) {
30-
31-
$message = $this->get_part( 'span' );
32-
$message['content'] = __( 'All assets are synced', 'cloudinary' );
33-
34-
$struct['element'] = 'div';
35-
$struct['attributes']['class'] = array(
36-
'notification',
37-
'notification-success',
38-
'dashicons-before',
39-
'dashicons-yes-alt',
40-
);
34+
35+
$struct['attributes']['class'] = array(
36+
'notification',
37+
'dashicons-before',
38+
);
39+
40+
if ( empty( $to_sync ) || $this->setting->get_param( 'queue' )->is_enabled() ) {
41+
$struct['element'] = 'div';
42+
43+
// Set basis.
44+
$state = 'notification-success';
45+
$icon = 'dashicons-yes-alt';
46+
$state_text = __( 'All assets are synced', 'cloudinary' );
47+
48+
if ( $this->setting->get_param( 'queue' )->is_enabled() ) {
49+
$state = 'notification-syncing';
50+
$icon = 'dashicons-update';
51+
$state_text = __( 'Syncing now', 'cloudinary' );
52+
}
53+
54+
$message = $this->get_part( 'span' );
55+
$message['content'] = $state_text;
56+
$struct['attributes']['class'][] = $state;
57+
$struct['attributes']['class'][] = $icon;
58+
4159
$struct['children']['message'] = $message;
60+
}
61+
62+
return $struct;
63+
}
4264

43-
return $struct;
65+
/**
66+
* Filter the action part structure.
67+
*
68+
* @param array $struct The array structure.
69+
*
70+
* @return array
71+
*/
72+
protected function action( $struct ) {
73+
74+
if ( empty( $this->count_to_sync() ) ) {
75+
return null;
4476
}
4577

4678
$struct['element'] = 'a';
4779
$href = $this->setting->find_setting( 'sync_media' )->get_component()->get_url();
4880
$args = array();
49-
if ( ! $this->setting->get_param( 'queue' )->is_enabled() ) {
50-
$args['enable-bulk'] = true;
51-
$struct['content'] = $this->setting->get_param( 'enable_text', __( 'Sync Now', 'cloudinary' ) );
52-
$struct['attributes']['class'][] = 'button';
53-
} else {
54-
55-
$message = $this->get_part( 'span' );
56-
$message['content'] = __( 'Syncing now', 'cloudinary' );
5781

58-
$struct['attributes']['class'] = array(
59-
'notification',
60-
'notification-syncing',
61-
'dashicons-before',
62-
'dashicons-update',
63-
);
64-
$struct['children']['message'] = $message;
82+
if ( ! $this->setting->get_param( 'queue' )->is_enabled() ) {
83+
$args['enable-bulk'] = true;
84+
$struct['content'] = $this->setting->get_param( 'enable_text', __( 'Sync Now', 'cloudinary' ) );
6585

86+
} else {
6687
$args['disable-bulk'] = true;
67-
$struct['attributes']['title'] = $this->setting->get_param( 'disable_text', __( 'Stop Sync', 'cloudinary' ) );
88+
$struct['content'] = $this->setting->get_param( 'disable_text', __( 'Stop Sync', 'cloudinary' ) );
89+
$struct['attributes']['style'] = 'margin:21px;';
6890
}
69-
91+
$struct['attributes']['class'][] = 'button';
7092
if ( 'off' === $this->setting->find_setting( 'auto_sync' )->get_value() ) {
7193
$struct['attributes']['disabled'] = 'disabled';
7294
} else {
@@ -118,6 +140,10 @@ protected function tooltip( $struct ) {
118140
* @return int
119141
*/
120142
protected function count_to_sync() {
143+
static $count;
144+
if ( ! is_null( $count ) ) {
145+
return $count;
146+
}
121147
$params = array(
122148
'post_type' => 'attachment',
123149
'post_status' => 'inherit',

0 commit comments

Comments
 (0)