-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin_setup.php
executable file
·285 lines (237 loc) · 9.26 KB
/
plugin_setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
width
<?
function returnIfExists($json, $setting) {
if ($json == null) {
return "";
}
if (array_key_exists($setting, $json)) {
return $json[$setting];
}
return "";
}
function convertAndGetSettings() {
global $settings;
$cfgFile = $settings['configDirectory'] . "/plugin.fpp-osc.json";
if (file_exists($cfgFile)) {
$j = file_get_contents($cfgFile);
$json = json_decode($j, true);
return $json;
}
$j = "{\"port\": 9000, \"events\": [] }";
return json_decode($j, true);
}
$pluginJson = convertAndGetSettings();
?>
<div id="global" class="settings">
<legend>Open Sound Control Config</legend>
<script>
allowMultisyncCommands = true;
function ConditionTypeChanged(item) {
var val = $(item).find('.conditionSelect').val();
if (val === 'ALWAYS') {
$(item).find(".conditionTypeSelect").hide();
$(item).find(".conditionText").hide();
} else {
$(item).find(".conditionTypeSelect").show();
$(item).find(".conditionText").show();
}
}
function AddOption(value, text, current) {
var o = "<option value='" + value + "'";
var realVal = $('<textarea />').html(value).text();
if (value == current || realVal == current)
o += " selected";
o += ">" + text + "</option>";
return o;
}
function RemoveCondition(item) {
if ($(item).parent().find('tr').length == 1)
return;
$(item).remove();
}
function AddCondition(row, condition, compare, text) {
var rows = $(row).find('.conditions > tr').length;
var c = "<tr>";
if (rows == 0)
c += "<td><button class='circularButton circularButton-vsm circularButton-sm circularButton-visible circularAddButton' onClick='AddCondition($(this).parent().parent().parent().parent(), \"ALWAYS\", \"\", \"\");'>Add</button></td>";
else
c += "<td><button class='circularButton circularButton-vsm circularButton-sm circularButton-visible circularDeleteButton' onClick='RemoveCondition($(this).parent().parent());'>Delete</button></td>";
c += "<td><select class='conditionSelect' onChange='ConditionTypeChanged($(this).parent());'>";
c += AddOption('ALWAYS', 'Always', condition);
c += AddOption('p1', 'Param1', condition);
c += AddOption('p2', 'Param2', condition);
c += AddOption('p3', 'Param3', condition);
c += AddOption('p4', 'Param4', condition);
c += AddOption('p5', 'Param5', condition);
c += "</select>";
c += "<select class='conditionTypeSelect' style='display:none;'>";
c += AddOption('=', '=', compare);
c += AddOption('!=', '!=', compare);
c += AddOption('<', '<', compare);
c += AddOption('<=', '<=', compare);
c += AddOption('>', '>', compare);
c += AddOption('>=', '>=', compare);
c += AddOption('contains', 'Contains', compare);
c += AddOption('iscontainedin', 'Is In', compare);
c += "</select>";
c += "<input type='text' size='12' maxlength='30' class='conditionText' style='display:none;' value='" + text + "'>";
c += "</td></tr>";
$(row).find('.conditions').append(c);
ConditionTypeChanged($(row).find('.conditions > tr').last());
}
var uniqueId = 1;
function AddOSC() {
var id = $("#oscEventTableBody > tr").length + 1;
var html = "<tr class='fppTableRow";
if (id % 2 != 0) {
html += " oddRow'";
}
html += "'><td class='center' valign='middle'><div class='rowGrip'><i class='rowGripIcon fpp-icon-grip'></i></div></td>";
html += "<td><input type='text' size='25' maxlength='50' class='desc'><span style='display: none;' class='uniqueId'>" + uniqueId + "</span></td>";
html += "<td><input type='text' size='30' maxlength='50' class='path'></td>";
html += "<td><table><tbody class='conditions'></tbody></table>";
html += "</td><td><table class='fppTable' border=0 id='tableOSCCommand_" + uniqueId +"'>";
html += "<tr><td>Command:</td><td><select class='osccommand' id='osccommand" + uniqueId + "' onChange='CommandSelectChanged(\"osccommand" + uniqueId + "\", \"tableOSCCommand_" + uniqueId + "\" , false, PrintArgsInputsForEditable);'><option value=''></option></select></td></tr>";
html += "</table></td></tr>";
$("#oscEventTableBody").append(html);
LoadCommandList($('#osccommand' + uniqueId));
newRow = $('#oscEventTableBody > tr').last();
$('#oscEventTableBody > tr').removeClass('selectedEntry');
DisableButtonClass('deleteEventButton');
uniqueId++;
return newRow;
}
function RemoveOSC() {
if ($('#oscEventTableBody').find('.selectedEntry').length) {
$('#oscEventTableBody').find('.selectedEntry').remove();
}
DisableButtonClass('deleteEventButton');
}
var oscConfig = <? echo json_encode($pluginJson, JSON_PRETTY_PRINT); ?>;
function SaveOSCConfig(config) {
var data = JSON.stringify(config);
$.ajax({
type: "POST",
url: 'api/configfile/plugin.fpp-osc.json',
dataType: 'json',
async: false,
data: data,
processData: false,
contentType: 'application/json',
success: function (data) {
SetRestartFlag(2);
}
});
}
function SaveEvent(row) {
var desc = $(row).find('.desc').val();
var path = $(row).find('.path').val();
var conditions = [];
$(row).find('.conditions > tr').each(function() {
var cond = $(this).find('.conditionSelect').val();
var condType = $(this).find('.conditionTypeSelect').val();
var condText = $(this).find('.conditionText').val();
var condition = {};
condition.condition = cond;
condition.conditionCompare = condType;
condition.conditionText = condText;
conditions.push(condition);
});
var id = $(row).find('.uniqueId').html();
var json = {
"description": desc,
"path": path,
"conditions": conditions
};
CommandToJSON('osccommand' + id, 'tableOSCCommand_' + id, json, true);
return json;
}
function SaveOSC() {
var port = parseInt($("#portSpin").val());
oscConfig = { "port": port, "events": []};
var i = 0;
$("#oscEventTableBody > tr").each(function() {
oscConfig["events"][i++] = SaveEvent(this);
});
SaveOSCConfig(oscConfig);
}
function RefreshLastMessages() {
$.get('api/plugin-apis/OSC/Last', function (data) {
$("#lastMessages").text(data);
}
);
}
$(document).ready(function() {
$('#oscEventTableBody').sortable({
update: function(event, ui) {
},
item: '> tr',
scroll: true
}).disableSelection();
$('#oscEventTableBody').on('mousedown', 'tr', function(event,ui){
$('#oscEventTableBody tr').removeClass('selectedEntry');
$(this).addClass('selectedEntry');
EnableButtonClass('deleteEventButton');
});
});
</script>
<div class="row">
<div class="col-auto mr-auto">
<div class="row">
<div class="col-auto">
Listen Port: <input type='number' id='portSpin' min='1' max='65535' size='10' value='<? echo $pluginJson["port"] ?>'></input>
</div>
</div>
<div class="row">
<div class="col-auto">
<input type="button" value="Save" class="buttons genericButton" onclick="SaveOSC();">
<input type="button" value="Add" class="buttons genericButton" onclick="AddCondition(AddOSC(), 'ALWAYS', '', '');">
<input id="delButton" type="button" value="Delete" class="deleteEventButton disableButtons genericButton" onclick="RemoveOSC();">
</div>
</div>
<div class="row">
<div class="col-auto">
<div class='fppTableWrapper'>
<div class='fppTableContents'>
<table class="fppSelectableRowTable" id="oscEventTable" width='100%'>
<thead><tr class="fppTableHeader"><th>#</th><th>Description</th><th>Path</th><th>Conditions</th><th>Command</th></tr></thead>
<tbody id='oscEventTableBody' class="ui-sortable">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="col-auto">
<div>
<div class="row">
<div class="col">
Last Messages: <input type="button" value="Refresh" class="buttons" onclick="RefreshLastMessages();">
</div>
</div>
<div class="row">
<div class="col">
<pre id="lastMessages" style='min-width:150px; margin:1px;min-height:300px;'></pre>
</div>
</div>
</div>
</div>
</div>
<script>
$.each(oscConfig["events"], function( key, val ) {
var row = AddOSC();
$(row).find('.desc').val(val["description"]);
$(row).find('.path').val(val["path"]);
for (var i = 0; i < val['conditions'].length; i++) {
AddCondition(row,
val['conditions'][i]['condition'],
val['conditions'][i]['conditionCompare'],
val['conditions'][i]['conditionText']);
}
var id = parseInt($(row).find('.uniqueId').html());
PopulateExistingCommand(val, 'osccommand' + id, 'tableOSCCommand_' + id, false, PrintArgsInputsForEditable);
});
RefreshLastMessages();
</script>
</div>