Skip to content

Commit fe0a6ca

Browse files
committed
!410 - Add widgets to components.
1 parent f3c42f3 commit fe0a6ca

File tree

9 files changed

+329
-11
lines changed

9 files changed

+329
-11
lines changed

apps/Core/Components/Devtools/Modules/ModulesComponent.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ public function viewAction()
266266
}
267267
}
268268

269+
if (isset($module['widgets']) && is_array($module['widgets'])) {
270+
$this->view->moduleWidgets = $module['widgets'] = Json::encode($module['widgets']);
271+
} else {
272+
$this->view->moduleWidgets = $module['widgets'] = Json::encode([]);
273+
}
269274
if (is_array($module['settings'])) {
270275
$this->view->moduleSettings = $module['settings'] = Json::encode($module['settings']);
271276
}

apps/Core/Packages/Devtools/Modules/DevtoolsModules.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ protected function updateModuleJson($data)
295295
}
296296

297297
$jsonContent["settings"] = $data["settings"];
298-
298+
if ($data['module_type'] === 'components') {
299+
$jsonContent["widgets"] = $data["widgets"];
300+
}
299301
$jsonContent = Json::encode($jsonContent, JSON_UNESCAPED_SLASHES);
300302

301303
$jsonContent = str_replace('\\"', '"', $jsonContent);

apps/Core/Views/Default/html/devtools/modules/module.html

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,13 @@
764764
'tabTitle' : 'Menu',
765765
'tabInclude' : 'modules/module/menu'
766766
]
767+
],
768+
[
769+
'widgets' :
770+
[
771+
'tabTitle' : 'Widgets',
772+
'tabInclude' : 'modules/module/widgets'
773+
]
767774
])
768775
%}
769776
{% endif %}
@@ -839,6 +846,10 @@
839846
dataCollectionSectionForm['vars']['moduleDependencies'] = JSON.parse('{{moduleDependencies}}');
840847
dataCollectionSectionForm['vars']['moduleId'] = '{{moduleId}}';
841848

849+
if (dataCollectionSectionForm['vars']['module_type'] === 'components') {
850+
dataCollectionSectionForm['vars']['moduleWidgets'] = JSON.parse('{{moduleWidgets}}');
851+
}
852+
842853
if (dataCollectionSectionForm['vars']['moduleId'] == '0') {
843854
dataCollectionSectionForm['vars']['moduleSettings'] = { };
844855
if (dataCollectionSectionForm['vars']['module_type'] === 'views') {
@@ -1254,7 +1265,6 @@
12541265
}
12551266
});
12561267

1257-
12581268
$('#{{componentId}}-{{sectionId}}-generate-settings').off();
12591269
$('#{{componentId}}-{{sectionId}}-generate-settings').click(function() {
12601270
if ($($('#{{componentId}}-{{sectionId}}-module_type').find(':selected')[0]).val() === 'components' ||
@@ -1318,6 +1328,107 @@
13181328
'placeholder' : 'SELECT PACKAGE',
13191329
'allowClear' : true
13201330
},
1331+
'{{componentId}}-{{sectionId}}-widget-name' : { },
1332+
'{{componentId}}-{{sectionId}}-widget-method' : { },
1333+
'{{componentId}}-{{sectionId}}-multiple' : { },
1334+
'{{componentId}}-{{sectionId}}-max-multiple' : { },
1335+
'{{componentId}}-{{sectionId}}-widget-settings' : { },
1336+
'{{componentId}}-{{sectionId}}-widgets' : {
1337+
afterInit: function() {
1338+
function prettyfyJson() {
1339+
$('#{{componentId}}-{{sectionId}}-widgets')
1340+
.val(JSON.stringify(dataCollectionSectionForm['vars']['moduleWidgets'], null, 4));
1341+
}
1342+
prettyfyJson();
1343+
1344+
function reset() {
1345+
$('#{{componentId}}-{{sectionId}}-widget-name').val('');
1346+
$('#{{componentId}}-{{sectionId}}-widget-method').val('');
1347+
$("#multiple-no").prop('checked', true);
1348+
$('#{{componentId}}-{{sectionId}}-max-multiple').val('');
1349+
$('#{{componentId}}-{{sectionId}}-max-multiple').attr('disabled', true);
1350+
$('#{{componentId}}-{{sectionId}}-widget-settings').val('');
1351+
}
1352+
1353+
$('#{{componentId}}-{{sectionId}}-multiple').off();
1354+
$('#{{componentId}}-{{sectionId}}-multiple').click(function() {
1355+
if ($(this).find('input[type=radio]:checked').data('value') == 'multiple-yes') {
1356+
$('#{{componentId}}-{{sectionId}}-max-multiple').attr('disabled', false);
1357+
} else if ($(this).find('input[type=radio]:checked').data('value') == 'multiple-no') {
1358+
$('#{{componentId}}-{{sectionId}}-max-multiple').val('');
1359+
$('#{{componentId}}-{{sectionId}}-max-multiple').attr('disabled', true);
1360+
}
1361+
});
1362+
1363+
$('#{{componentId}}-{{sectionId}}-widget-add, ' +
1364+
'#{{componentId}}-{{sectionId}}-widget-remove').click(function(e) {
1365+
e.preventDefault();
1366+
1367+
if ($('#{{componentId}}-{{sectionId}}-widget-name').val() === '') {
1368+
$('#{{componentId}}-{{sectionId}}-widget-name').addClass('is-invalid');
1369+
$('#{{componentId}}-{{sectionId}}-widget-name').focus(function() {
1370+
$(this).removeClass('is-invalid');
1371+
});
1372+
} else if ($('#{{componentId}}-{{sectionId}}-widget-method').val() === '') {
1373+
$('#{{componentId}}-{{sectionId}}-widget-method').addClass('is-invalid');
1374+
$('#{{componentId}}-{{sectionId}}-widget-method').focus(function() {
1375+
$(this).removeClass('is-invalid');
1376+
});
1377+
} else if ($('#{{componentId}}-{{sectionId}}-max-multiple').attr('disabled') !== 'disabled' &&
1378+
$('#{{componentId}}-{{sectionId}}-max-multiple').val() === ''
1379+
) {
1380+
$('#{{componentId}}-{{sectionId}}-max-multiple').addClass('is-invalid');
1381+
$('#{{componentId}}-{{sectionId}}-max-multiple').focus(function() {
1382+
$(this).removeClass('is-invalid');
1383+
});
1384+
} else {
1385+
if (dataCollectionSectionForm['vars']['moduleWidgets'].length > 0) {
1386+
$(dataCollectionSectionForm['vars']['moduleWidgets']).each(function(index, widget) {
1387+
if (widget['method'] === $('#{{componentId}}-{{sectionId}}-widget-method').val()) {
1388+
dataCollectionSectionForm['vars']['moduleWidgets'].splice(index);
1389+
}
1390+
});
1391+
1392+
if ($(this)[0].id !== '{{componentId}}-{{sectionId}}-widget-remove') {
1393+
addWidget();
1394+
}
1395+
} else {
1396+
if ($(this)[0].id !== '{{componentId}}-{{sectionId}}-widget-remove') {
1397+
addWidget();
1398+
} else {
1399+
return false;
1400+
}
1401+
}
1402+
}
1403+
1404+
reset();
1405+
prettyfyJson();
1406+
});
1407+
1408+
function addWidget() {
1409+
var multiple = false;
1410+
var settings = { };
1411+
1412+
if ($('#{{componentId}}-{{sectionId}}-multiple').find('input[type=radio]:checked').data('value') == 'multiple-yes') {
1413+
multiple = true;
1414+
}
1415+
1416+
if ($('#{{componentId}}-{{sectionId}}-widget-settings').val() !== '') {
1417+
settings = $('#{{componentId}}-{{sectionId}}-widget-settings').val();
1418+
}
1419+
1420+
dataCollectionSectionForm['vars']['moduleWidgets'].push(
1421+
{
1422+
'name' : $('#{{componentId}}-{{sectionId}}-widget-name').val(),
1423+
'method' : $('#{{componentId}}-{{sectionId}}-widget-method').val(),
1424+
'multiple' : multiple,
1425+
'max_multiple' : $('#{{componentId}}-{{sectionId}}-max-multiple').val(),
1426+
'settings' : settings
1427+
}
1428+
);
1429+
}
1430+
}
1431+
},
13211432
'{{componentId}}-{{sectionId}}-settings-keys' : {
13221433
placeholder: "SELECT SETTING TO MODIFY OR ADD",
13231434
afterInit: function() {
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
{% if module['id'] is defined and module['widgets'] is defined %}
2+
{% set widgets = module['widgets'] %}
3+
{% set moduleWidgets = module['widgets'] %}
4+
{% else %}
5+
{% set widgets = moduleWidgets %}
6+
{% endif %}
7+
<div class="row">
8+
<div class="col">
9+
{{adminltetags.useTag('fields',
10+
[
11+
'component' : component,
12+
'componentName' : componentName,
13+
'componentId' : componentId,
14+
'sectionId' : sectionId,
15+
'fieldId' : 'widget-name',
16+
'fieldLabel' : 'Widget Name',
17+
'fieldType' : 'input',
18+
'fieldHelp' : true,
19+
'fieldHelpTooltipContent' : 'Widget Name Example: World Clock',
20+
'fieldRequired' : true,
21+
'fieldBazScan' : true,
22+
'fieldDataInputMinLength' : 1,
23+
'fieldDataInputMaxLength' : 100,
24+
'fieldValue' : ''
25+
]
26+
)}}
27+
</div>
28+
<div class="col">
29+
{{adminltetags.useTag('fields',
30+
[
31+
'component' : component,
32+
'componentName' : componentName,
33+
'componentId' : componentId,
34+
'sectionId' : sectionId,
35+
'fieldId' : 'widget-method',
36+
'fieldLabel' : 'Widget Method',
37+
'fieldType' : 'input',
38+
'fieldHelp' : true,
39+
'fieldHelpTooltipContent' : 'Widget Method Example: worldClock',
40+
'fieldRequired' : true,
41+
'fieldBazScan' : true,
42+
'fieldDataInputMinLength' : 1,
43+
'fieldDataInputMaxLength' : 50,
44+
'fieldValue' : ''
45+
]
46+
)}}
47+
</div>
48+
</div>
49+
<div class="row">
50+
<div class="col">
51+
{{adminltetags.useTag('fields',
52+
[
53+
'component' : component,
54+
'componentName' : componentName,
55+
'componentId' : componentId,
56+
'sectionId' : sectionId,
57+
'fieldId' : 'multiple',
58+
'fieldLabel' : 'Multple Widget Instance',
59+
'fieldType' : 'radio',
60+
'fieldHelp' : true,
61+
'fieldHelpTooltipContent' : 'Multiple instances of the this widget.',
62+
'fieldRequired' : true,
63+
'fieldBazJstreeSearch' : true,
64+
'fieldBazPostOnCreate' : false,
65+
'fieldBazPostOnUpdate' : false,
66+
'fieldBazScan' : true,
67+
'fieldRadioPlacementType' : 'horizontal',
68+
'fieldRadioButtons' :
69+
[
70+
'multiple-no' :
71+
[
72+
'title' : 'NO',
73+
'dataValue' : 'multiple-no'
74+
],
75+
'multiple-yes' :
76+
[
77+
'title' : 'YES',
78+
'dataValue' : 'multiple-yes'
79+
]
80+
],
81+
'fieldRadioChecked' : 'multiple-no'
82+
]
83+
)}}
84+
</div>
85+
<div class="col">
86+
{{adminltetags.useTag('fields',
87+
[
88+
'component' : component,
89+
'componentName' : componentName,
90+
'componentId' : componentId,
91+
'sectionId' : sectionId,
92+
'fieldId' : 'max-multiple',
93+
'fieldLabel' : 'Max Multiple Count',
94+
'fieldType' : 'input',
95+
'fieldInputTypeTextFilter' : 'positiveInt',
96+
'fieldHelp' : true,
97+
'fieldHelpTooltipContent' : 'Max multiple count',
98+
'fieldRequired' : true,
99+
'fieldDisabled' : true,
100+
'fieldBazScan' : true,
101+
'fieldBazJstreeSearch' : true,
102+
'fieldDataInputMaxLength' : 2,
103+
'fieldDataInputMinNumber' : 1,
104+
'fieldDataInputMaxNumber' : 10,
105+
'fieldValue' : ''
106+
]
107+
)}}
108+
</div>
109+
</div>
110+
<div class="row">
111+
<div class="col">
112+
{{adminltetags.useTag('fields',
113+
[
114+
'component' : component,
115+
'componentName' : componentName,
116+
'componentId' : componentId,
117+
'sectionId' : sectionId,
118+
'fieldId' : 'widget-settings',
119+
'fieldLabel' : 'Widget Settings',
120+
'fieldType' : 'textarea',
121+
'fieldDataMaxLength' : 4096,
122+
'fieldHelp' : true,
123+
'fieldHelpTooltipContent' : 'Settings of the widget. JSON Format',
124+
'fieldRequired' : false,
125+
'fieldBazScan' : true,
126+
'fieldBazPostOnCreate' : true,
127+
'fieldBazPostOnUpdate' : true,
128+
'fieldDataInputMaxLength' : 4096,
129+
'fieldTextareaRows' : 5,
130+
'fieldValue' : ''
131+
]
132+
)}}
133+
</div>
134+
</div>
135+
<div class="row">
136+
<div class="col">
137+
{{adminltetags.useTag('buttons',
138+
[
139+
'component' : component,
140+
'componentName' : componentName,
141+
'componentId' : componentId,
142+
'sectionId' : sectionId,
143+
'buttonType' : 'button',
144+
'buttons' :
145+
[
146+
'widget-remove' : [
147+
'title' : 'Remove',
148+
'size' : 'xs',
149+
'type' : 'danger',
150+
'icon' : 'trash'
151+
],
152+
'widget-add' : [
153+
'title' : 'Add',
154+
'size' : 'xs',
155+
'type' : 'primary',
156+
'icon' : 'plus',
157+
'position' : 'right'
158+
]
159+
]
160+
]
161+
)}}
162+
</div>
163+
</div>
164+
<hr>
165+
<div class="row">
166+
<div class="col">
167+
{{adminltetags.useTag('fields',
168+
[
169+
'component' : component,
170+
'componentName' : componentName,
171+
'componentId' : componentId,
172+
'sectionId' : sectionId,
173+
'fieldId' : 'widgets',
174+
'fieldLabel' : 'Widgets',
175+
'fieldType' : 'textarea',
176+
'fieldDataMaxLength' : 10000,
177+
'fieldHelp' : true,
178+
'fieldHelpTooltipContent' : 'Widgets settings of the module. JSON Format',
179+
'fieldRequired' : false,
180+
'fieldBazScan' : true,
181+
'fieldBazPostOnCreate' : true,
182+
'fieldBazPostOnUpdate' : true,
183+
'fieldDataInputMaxLength' : 10000,
184+
'fieldTextareaRows' : 15,
185+
'fieldValue' : widgets
186+
]
187+
)}}
188+
</div>
189+
</div>

system/Base/Installer/Packages/Setup/Register/Modules/Component.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function register($db, $componentFile, $menuId)
3333
'dependencies' =>
3434
isset($componentFile['dependencies']) ?
3535
Json::encode($componentFile['dependencies']) :
36-
null,
36+
Json::encode([]),
3737
'menu' =>
3838
isset($componentFile['menu']) ?
3939
Json::encode($componentFile['menu']) :
@@ -50,7 +50,11 @@ public function register($db, $componentFile, $menuId)
5050
'settings' =>
5151
isset($componentFile['settings']) ?
5252
Json::encode($componentFile['settings']) :
53-
null,
53+
Json::encode([]),
54+
'widgets' =>
55+
isset($componentFile['widgets']) ?
56+
Json::encode($componentFile['widgets']) :
57+
Json::encode([]),
5458
'updated_by' => 0
5559
]
5660
);

system/Base/Installer/Packages/Setup/Register/Modules/Middleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public function register($db, $middlewareFile)
3131
'settings' =>
3232
isset($middlewareFile['settings']) ?
3333
Json::encode($middlewareFile['settings']) :
34-
null,
34+
Json::encode([]),
3535
'dependencies' =>
3636
isset($middlewareFile['dependencies']) ?
3737
Json::encode($middlewareFile['dependencies']) :
38-
null,
38+
Json::encode([]),
3939
'apps' => $apps,
4040
'api_id' => 1,
4141
'installed' => 1,

0 commit comments

Comments
 (0)