Skip to content

Commit 5b146f7

Browse files
author
Christian Blanquera
committed
added stars format, fixed textlist, textarealist, wysiwyglist
1 parent 0e786f6 commit 5b146f7

File tree

8 files changed

+150
-43
lines changed

8 files changed

+150
-43
lines changed

src/Fieldset.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ public function getJsonFieldNames()
173173
'files',
174174
'images',
175175
'tag',
176-
'texts',
177-
'textareas',
178-
'wysiwygs',
176+
'textlist',
177+
'textarealist',
178+
'wysiwyglist',
179179
'meta',
180180
'checkboxes',
181181
'multirange',

src/Model/Formatter.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public function formatData(array $data)
7070
$data[$name] = json_encode($data[$name]);
7171
break;
7272
case 'tag':
73-
case 'texts':
74-
case 'textareas':
75-
case 'wysiwygs':
73+
case 'textlist':
74+
case 'textarealist':
75+
case 'wysiwyglist':
7676
case 'meta':
7777
case 'checkboxes':
7878
case 'multirange':

src/Model/template/format/detail.html

+54
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,60 @@
3535
{{#when config.format '===' 'yes'}}
3636
{{#if this}}Yes{{else}}No{{/if}}
3737
{{/when}}
38+
{{#when config.format '===' 'stars'}}
39+
<span class="rating text-yellow">
40+
{{#when this '==' 0.5}}
41+
<i class="fas fa-star-half"></i>
42+
{{/when}}
43+
{{#when this '==' 1}}
44+
<i class="fas fa-star"></i>
45+
{{/when}}
46+
{{#when this '==' 1.5}}
47+
<i class="fas fa-star"></i>
48+
<i class="fas fa-star-half"></i>
49+
{{/when}}
50+
{{#when this '==' 2}}
51+
<i class="fas fa-star"></i>
52+
<i class="fas fa-star"></i>
53+
{{/when}}
54+
{{#when this '==' 2.5}}
55+
<i class="fas fa-star"></i>
56+
<i class="fas fa-star"></i>
57+
<i class="fas fa-star-half"></i>
58+
{{/when}}
59+
{{#when this '==' 3}}
60+
<i class="fas fa-star"></i>
61+
<i class="fas fa-star"></i>
62+
<i class="fas fa-star"></i>
63+
{{/when}}
64+
{{#when this '==' 3.5}}
65+
<i class="fas fa-star"></i>
66+
<i class="fas fa-star"></i>
67+
<i class="fas fa-star"></i>
68+
<i class="fas fa-star-half"></i>
69+
{{/when}}
70+
{{#when this '==' 4}}
71+
<i class="fas fa-star"></i>
72+
<i class="fas fa-star"></i>
73+
<i class="fas fa-star"></i>
74+
<i class="fas fa-star"></i>
75+
{{/when}}
76+
{{#when this '==' 4.5}}
77+
<i class="fas fa-star"></i>
78+
<i class="fas fa-star"></i>
79+
<i class="fas fa-star"></i>
80+
<i class="fas fa-star"></i>
81+
<i class="fas fa-star-half"></i>
82+
{{/when}}
83+
{{#when this '>=' 5}}
84+
<i class="fas fa-star"></i>
85+
<i class="fas fa-star"></i>
86+
<i class="fas fa-star"></i>
87+
<i class="fas fa-star"></i>
88+
<i class="fas fa-star"></i>
89+
{{/when}}
90+
</span>
91+
{{/when}}
3892
{{#when config.format '===' 'date'}}
3993
{{#if this}}
4094
{{date this config.parameters}}

src/Model/template/format/field.html

+3-25
Original file line numberDiff line numberDiff line change
@@ -931,37 +931,15 @@
931931
{{/each}}
932932
</tbody>
933933
</table>
934-
<a
935-
class="field-add btn btn-success"
934+
<a
935+
class="field-add btn btn-success"
936936
href="javascript:void(0)"
937937
data-do="table-field-add"
938938
data-on="click"
939939
>
940940
<i class="fas fa-plus"></i>
941941
<span>{{_ 'Add Row'}}</span>
942942
</a>
943-
944-
<script type="text/x-template" id="table-field-template">
945-
<tr>
946-
<td>
947-
<a
948-
class="btn btn-danger remove"
949-
data-do="table-field-remove"
950-
data-on="click"
951-
href="javascript:void(0)"
952-
>
953-
<i class="fas fa-times"></i>
954-
</a>
955-
</td>
956-
<td class="input-template">
957-
<input
958-
class="input-column form-control"
959-
type="text"
960-
name="{NAME}[{INDEX}][{COLUMN}]"
961-
/>
962-
</td>
963-
</tr>
964-
</script>
965943
</div>
966944
{{/when}}
967945
{{#when config.type '===' 'multirange'}}
@@ -988,4 +966,4 @@
988966
{{@key}}="{{this}}"
989967
{{/each}}
990968
>{{{json_encode this}}}</textarea>
991-
{{/when}}
969+
{{/when}}

src/Model/template/format/list.html

+54
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,60 @@
3535
{{#when config.format '===' 'yes'}}
3636
{{#if this}}Yes{{else}}No{{/if}}
3737
{{/when}}
38+
{{#when config.format '===' 'stars'}}
39+
<span class="rating text-yellow">
40+
{{#when this '==' 0.5}}
41+
<i class="fas fa-star-half"></i>
42+
{{/when}}
43+
{{#when this '==' 1}}
44+
<i class="fas fa-star"></i>
45+
{{/when}}
46+
{{#when this '==' 1.5}}
47+
<i class="fas fa-star"></i>
48+
<i class="fas fa-star-half"></i>
49+
{{/when}}
50+
{{#when this '==' 2}}
51+
<i class="fas fa-star"></i>
52+
<i class="fas fa-star"></i>
53+
{{/when}}
54+
{{#when this '==' 2.5}}
55+
<i class="fas fa-star"></i>
56+
<i class="fas fa-star"></i>
57+
<i class="fas fa-star-half"></i>
58+
{{/when}}
59+
{{#when this '==' 3}}
60+
<i class="fas fa-star"></i>
61+
<i class="fas fa-star"></i>
62+
<i class="fas fa-star"></i>
63+
{{/when}}
64+
{{#when this '==' 3.5}}
65+
<i class="fas fa-star"></i>
66+
<i class="fas fa-star"></i>
67+
<i class="fas fa-star"></i>
68+
<i class="fas fa-star-half"></i>
69+
{{/when}}
70+
{{#when this '==' 4}}
71+
<i class="fas fa-star"></i>
72+
<i class="fas fa-star"></i>
73+
<i class="fas fa-star"></i>
74+
<i class="fas fa-star"></i>
75+
{{/when}}
76+
{{#when this '==' 4.5}}
77+
<i class="fas fa-star"></i>
78+
<i class="fas fa-star"></i>
79+
<i class="fas fa-star"></i>
80+
<i class="fas fa-star"></i>
81+
<i class="fas fa-star-half"></i>
82+
{{/when}}
83+
{{#when this '>=' 5}}
84+
<i class="fas fa-star"></i>
85+
<i class="fas fa-star"></i>
86+
<i class="fas fa-star"></i>
87+
<i class="fas fa-star"></i>
88+
<i class="fas fa-star"></i>
89+
{{/when}}
90+
</span>
91+
{{/when}}
3892
{{#when config.format '===' 'date'}}
3993
{{#if this}}
4094
{{date this config.parameters}}

src/Schema.php

+21-6
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,17 @@ public function toSql()
462462
$numbers = explode('.', '' . $field['field']['attributes']['max']);
463463
$format['length'] = strlen($numbers[0]);
464464
}
465+
466+
//if there's a step and there's a decimal
467+
if (isset($field['field']['attributes']['step'])
468+
&& strpos('' . $field['field']['attributes']['step'], '.') !== false
469+
) {
470+
$format['type'] = 'FLOAT';
471+
}
472+
}
473+
465474
//if it's a float
466-
} else if ($format['type'] === 'FLOAT') {
475+
if ($format['type'] === 'FLOAT') {
467476
$integers = $decimals = 0;
468477
//if there's a max
469478
if (isset($field['field']['attributes']['max'])
@@ -472,7 +481,10 @@ public function toSql()
472481
//determine the initial integer and decimal
473482
$numbers = explode('.', '' . $field['field']['attributes']['max']);
474483
$integers = strlen($numbers[0]);
475-
$decimals = strlen($numbers[1]);
484+
485+
if (isset($numbers[1])) {
486+
$decimals = strlen($numbers[1]);
487+
}
476488
}
477489

478490
//if there's a step
@@ -482,7 +494,10 @@ public function toSql()
482494
$numbers = explode('.', '' . $field['field']['attributes']['step']);
483495
//choose the larger of each integer and decimal
484496
$integers = max($integers, strlen($numbers[0]));
485-
$decimals = max($decimals, strlen($numbers[1]));
497+
498+
if (isset($numbers[1])) {
499+
$decimals = max($decimals, strlen($numbers[1]));
500+
}
486501
}
487502

488503
//if decimals is still 0
@@ -664,13 +679,13 @@ public function toSql()
664679
'tag' => [
665680
'type' => 'JSON'
666681
],
667-
'texts' => [
682+
'textlist' => [
668683
'type' => 'JSON'
669684
],
670-
'textareas' => [
685+
'textarealist' => [
671686
'type' => 'JSON'
672687
],
673-
'wysiwygs' => [
688+
'wysiwyglist' => [
674689
'type' => 'JSON'
675690
],
676691
'meta' => [

src/Schema/template/options/_format.html

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
>
5555
Yes/No
5656
</option>
57+
<option
58+
value="stars"
59+
{{#when format '===' 'stars'}}selected{{/when}}
60+
>
61+
Star Rating
62+
</option>
5763
</optgroup>
5864
<optgroup class="filter-group-date" label="Date Filters">
5965
<option

src/Schema/template/options/_type.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -310,24 +310,24 @@
310310
<option
311311
data-fieldset="attributes"
312312
data-format="json"
313-
value="texts"
314-
{{#when field.type '===' 'texts'}}selected{{/when}}
313+
value="textlist"
314+
{{#when field.type '===' 'textlist'}}selected{{/when}}
315315
>
316316
Text List Fieldset
317317
</option>
318318
<option
319319
data-fieldset="attributes"
320320
data-format="json"
321-
value="textareas"
322-
{{#when field.type '===' 'textareas'}}selected{{/when}}
321+
value="textarealist"
322+
{{#when field.type '===' 'textarealist'}}selected{{/when}}
323323
>
324324
Textarea List Fieldset
325325
</option>
326326
<option
327327
data-fieldset="attributes"
328328
data-format="json"
329-
value="wysiwygs"
330-
{{#when field.type '===' 'wysiwygs'}}selected{{/when}}
329+
value="wysiwyglist"
330+
{{#when field.type '===' 'wysiwyglist'}}selected{{/when}}
331331
>
332332
WYSIWYG List Fieldset
333333
</option>

0 commit comments

Comments
 (0)