|
7 | 7 |
|
8 | 8 | namespace Cloudinary\UI\Component; |
9 | 9 |
|
10 | | -use function Cloudinary\get_plugin_instance; |
11 | | - |
12 | 10 | /** |
13 | 11 | * Sync Component to hold data. |
14 | 12 | * |
15 | 13 | * @package Cloudinary\UI |
16 | 14 | */ |
17 | 15 | class Sync extends Text { |
18 | 16 |
|
| 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 | + |
19 | 24 | /** |
20 | 25 | * Filter the input parts structure. |
21 | 26 | * |
22 | 27 | * @param array $struct The array structure. |
23 | 28 | * |
24 | 29 | * @return array |
25 | 30 | */ |
26 | | - protected function input( $struct ) { |
| 31 | + protected function status( $struct ) { |
27 | 32 |
|
28 | 33 | $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 | + |
41 | 59 | $struct['children']['message'] = $message; |
| 60 | + } |
| 61 | + |
| 62 | + return $struct; |
| 63 | + } |
42 | 64 |
|
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; |
44 | 76 | } |
45 | 77 |
|
46 | 78 | $struct['element'] = 'a'; |
47 | 79 | $href = $this->setting->find_setting( 'sync_media' )->get_component()->get_url(); |
48 | 80 | $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' ); |
57 | 81 |
|
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' ) ); |
65 | 85 |
|
| 86 | + } else { |
66 | 87 | $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;'; |
68 | 90 | } |
69 | | - |
| 91 | + $struct['attributes']['class'][] = 'button'; |
70 | 92 | if ( 'off' === $this->setting->find_setting( 'auto_sync' )->get_value() ) { |
71 | 93 | $struct['attributes']['disabled'] = 'disabled'; |
72 | 94 | } else { |
@@ -118,6 +140,10 @@ protected function tooltip( $struct ) { |
118 | 140 | * @return int |
119 | 141 | */ |
120 | 142 | protected function count_to_sync() { |
| 143 | + static $count; |
| 144 | + if ( ! is_null( $count ) ) { |
| 145 | + return $count; |
| 146 | + } |
121 | 147 | $params = array( |
122 | 148 | 'post_type' => 'attachment', |
123 | 149 | 'post_status' => 'inherit', |
|
0 commit comments