Skip to content

Commit ab6fb17

Browse files
committed
Optimize edit preview
1 parent a84a44e commit ab6fb17

File tree

8 files changed

+248
-72
lines changed

8 files changed

+248
-72
lines changed

css/cloudinary.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/asset-edit.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

php/assets/class-rest-assets.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ public function rest_save_asset( $request ) {
123123
$text_overlay = $request->get_param( 'textOverlay' );
124124

125125
if ( isset( $text_overlay ) && array_key_exists( 'transformation', (array) $text_overlay ) ) {
126-
$result = $this->save_transformation_type( $attachment_id, $text_overlay['transformation'], $type, 'text_overlay' );
126+
$result = $this->save_transformation_type( $attachment_id, $text_overlay['transformation'], $type, 'text_overlay', $text_overlay );
127127
$return = array_merge( $return, $result );
128128
}
129129

130130
// Save image overlay even if empty (allow clearing).
131131
$image_overlay = $request->get_param( 'imageOverlay' );
132132

133133
if ( isset( $image_overlay ) && array_key_exists( 'transformation', (array) $image_overlay ) ) {
134-
$result = $this->save_transformation_type( $attachment_id, $image_overlay['transformation'], $type, 'image_overlay' );
134+
$result = $this->save_transformation_type( $attachment_id, $image_overlay['transformation'], $type, 'image_overlay', $image_overlay );
135135
$return = array_merge( $return, $result );
136136
}
137137

@@ -145,27 +145,32 @@ public function rest_save_asset( $request ) {
145145
* @param string $transformation Transformation string.
146146
* @param string $type Resource type.
147147
* @param string $save_type Type to save (transformations, text_overlay, image_overlay).
148+
* @param array $full_data Full data for the transformation type.
148149
* @return array
149150
*/
150-
protected function save_transformation_type( $attachment_id, $transformation, $type, $save_type ) {
151+
protected function save_transformation_type( $attachment_id, $transformation, $type, $save_type, $full_data = null ) {
151152
$media = $this->assets->media;
152153
$transformation_array = $media->get_transformations_from_string( $transformation, $type );
153154
$cleaned = Api::generate_transformation_string( $transformation_array, $type );
154155

156+
if ( ! empty( $full_data ) ) {
157+
$full_data['transformation'] = $cleaned;
158+
}
159+
155160
switch ( $save_type ) {
156161
case 'transformations':
157162
Relate::update_transformations( $attachment_id, $cleaned );
158163
break;
159164
case 'text_overlay':
160-
break;
161165
case 'image_overlay':
166+
Relate::update_transformations_overlay( $attachment_id, $full_data, $save_type );
162167
break;
163168
}
164169

165170
$result = array( $save_type => $cleaned );
166171

167172
if ( $cleaned !== $transformation ) {
168-
$result['note'] = __( 'Some transformations were invalid and were removed.', 'cloudinary' );
173+
$result['note'] = __( 'There are incorrect transformations, please set correct ones.', 'cloudinary' );
169174
}
170175

171176
return $result;

php/class-relate.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ public static function update_transformations( $attachment_id, $transformations
9393
$relationship->save();
9494
}
9595

96+
/**
97+
* Update transformations for an asset.
98+
*
99+
* @param int $attachment_id The attachment ID.
100+
* @param array|null $overlay_data The overlay transformations.
101+
* @param string $save_type The type of overlay.
102+
*/
103+
public static function update_transformations_overlay( $attachment_id, $overlay_data, $save_type ) {
104+
$relationship = Relationship::get_relationship( $attachment_id );
105+
106+
if ( ! in_array( $save_type, array( 'text_overlay', 'image_overlay' ), true ) ) {
107+
return;
108+
}
109+
110+
$relationship->$save_type = json_encode( $overlay_data );
111+
$relationship->save();
112+
}
113+
96114
/**
97115
* Get the transformations for an asset.
98116
*

src/css/_variables.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ $color-cld-description: rgba(0, 0, 1, 0.5);
1818
$color-cld-dark-description: rgba(0, 0, 1, 0.75);
1919
$color-cld-coral: #ff5050;
2020
$color-grey-background: #f1f1f1;
21+
$color-transformations-blue: #51a3ff;
22+
$color-transformations-yellow: #f2d864;
23+
$color-transformations-cyan: #54c8db;
24+
$color-transformations-background: #262c35;
2125

2226
/** Sizes */
2327
$content-width: 870px;

src/css/components/_edit_overlay.scss

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,48 @@
9090
.cld-ui-suffix {
9191
margin-left: 0;
9292
}
93+
94+
.cld-ui-preview {
95+
box-sizing: border-box;
96+
}
9397
}
9498

99+
#asset-preview-transformation-string {
100+
box-sizing: border-box;
101+
display: block;
102+
max-width: 100%;
103+
overflow-wrap: normal;
104+
word-break: break-all;
105+
background: $color-transformations-background;
106+
padding: 10px;
107+
108+
text-decoration: none;
109+
110+
&:hover {
111+
span {
112+
text-decoration: underline;
113+
}
114+
}
115+
116+
.string-preview {
117+
&-base {
118+
word-break: break-all;
119+
}
120+
121+
&-transformations {
122+
color: $color-white;
123+
}
124+
125+
&-image-overlay {
126+
color: $color-transformations-blue;
127+
}
128+
129+
&-text-overlay {
130+
color: $color-transformations-cyan;
131+
}
132+
133+
&-public-id {
134+
color: $color-transformations-yellow;
135+
}
136+
}
137+
}

0 commit comments

Comments
 (0)