Skip to content

Commit 550d746

Browse files
hiroMTBarturoc
authored andcommitted
Feature add template dropdown to frontend PG (#206)
1 parent 50a0ee2 commit 550d746

File tree

4 files changed

+267
-7
lines changed

4 files changed

+267
-7
lines changed

frontend/app.js

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var fs = require('fs');
88

99

1010
var platforms;
11+
var templates;
1112

1213
// var platforms = {
1314
// "osx": "OS X (Xcode)",
@@ -204,9 +205,83 @@ ipc.on('setPlatforms', function(arg) {
204205
});
205206

206207

208+
ipc.on('setTemplates', function(arg) {
209+
console.log("----------------");
210+
console.log("got set templates");
211+
console.log(arg);
212+
213+
templates = arg;
214+
215+
var select = document.getElementById("templateList");
216+
var option, i;
217+
for (var i in templates) {
218+
console.log(i);
219+
var myClass = 'template';
220+
221+
$('<div/>', {
222+
"class": 'item',
223+
"data-value": i
224+
}).html(templates[i]).appendTo(select);
225+
}
226+
227+
console.log(select);
228+
229+
// start the template drop down.
230+
$('#templatesDropdown')
231+
.dropdown({
232+
allowAdditions: false,
233+
fullTextSearch: 'exact',
234+
match: "text",
235+
maxSelections: 1
236+
});
237+
238+
// // set the template to default
239+
//$('#templatesDropdown').dropdown('set exactly', defaultSettings['defaultTemplate']);
240+
241+
// Multi
242+
var select = document.getElementById("templateListMulti");
243+
var option, i;
244+
for (var i in templates) {
245+
var myClass = 'template';
246+
247+
$('<div/>', {
248+
"class": 'item',
249+
"data-value": i
250+
}).html(templates[i]).appendTo(select);
251+
}
252+
253+
// start the platform drop down.
254+
$('#templatesDropdownMulti')
255+
.dropdown({
256+
allowAdditions: false,
257+
maxSelections: 1
258+
});
259+
260+
// // set the template to default
261+
//$('#templatesDropdownMulti').dropdown('set exactly', defaultSettings['defaultTemplate']);
262+
});
263+
207264

265+
ipc.on('enableTemplate', function (arg) {
208266

267+
console.log('enableTemplate');
268+
let items = arg.bMulti === false ? $('#templatesDropdown .menu .item') : $('#templatesDropdownMulti .menu .item');
209269

270+
// enable all first
271+
for (let i = 0; i < items.length; i++) {
272+
let item = $(items[i]);
273+
item.removeClass("disabled");
274+
}
275+
276+
for (let template of arg.invalidTemplateList) {
277+
for (let i = 0; i < items.length; i++) {
278+
let item = $(items[i]);
279+
if (item.attr('data-value') === template) {
280+
item.addClass("disabled");
281+
}
282+
}
283+
}
284+
});
210285

211286
//-------------------------------------------
212287
// select the list of addons and notify if some aren't installed
@@ -606,6 +681,7 @@ function setup() {
606681

607682
// show default platform in GUI
608683
$("#defaultPlatform").html(defaultSettings['defaultPlatform']);
684+
//$("#defaultTemplate").html(defaultSettings['defaultTemplate']);
609685

610686
// Enable tooltips
611687
//$("[data-toggle='tooltip']").tooltip();
@@ -654,6 +730,29 @@ function setup() {
654730
$(this).removeClass("accept deny");
655731
});
656732

733+
734+
// reflesh template dropdown list depends on selected platforms
735+
$("#platformsDropdown").on('change', function () {
736+
let selectedPlatforms = $("#platformsDropdown input").val();
737+
let selectedPlatformArray = selectedPlatforms.trim().split(',');
738+
let arg = {
739+
ofPath: $("#ofPath").val(),
740+
selectedPlatforms: selectedPlatformArray,
741+
bMulti: false
742+
}
743+
ipc.send('refreshTemplateList', arg);
744+
})
745+
$("#platformsDropdownMulti").on('change', function () {
746+
let selectedPlatforms = $("#platformsDropdownMulti input").val();
747+
let selectedPlatformArray = selectedPlatforms.trim().split(',');
748+
let arg = {
749+
ofPath: $("#ofPath").val(),
750+
selectedPlatforms: selectedPlatformArray,
751+
bMulti: true
752+
}
753+
ipc.send('refreshTemplateList', arg);
754+
})
755+
657756
});
658757
}
659758

@@ -797,6 +896,12 @@ function generate() {
797896
// let's get all the info:
798897
var platformValueArray = getPlatformList();
799898

899+
var templatePicked = $("#templatesDropdown .active");
900+
var templateValueArray = [];
901+
for (var i = 0; i < templatePicked.length; i++){
902+
templateValueArray.push($(templatePicked[i]).attr("data-value"));
903+
}
904+
800905
var addonsPicked = $("#addonsDropdown .active");
801906
var addonValueArray = [];
802907

@@ -816,6 +921,7 @@ function generate() {
816921
gen['projectName'] = $("#projectName").val();
817922
gen['projectPath'] = $("#projectPath").val();
818923
gen['platformList'] = platformValueArray;
924+
gen['templateList'] = templateValueArray;
819925
gen['addonList'] = addonValueArray; //$("#addonsDropdown").val();
820926
gen['ofPath'] = $("#ofPath").val();
821927
gen['verbose'] = bVerbose;
@@ -850,11 +956,16 @@ function updateRecursive() {
850956
platformValueArray.push($(platformsPicked[i]).attr("data-value"));
851957
}
852958

853-
959+
var templatePicked = $("#templatesDropdownMulti .active");
960+
var templateValueArray = [];
961+
for (var i = 0; i < templatePicked.length; i++){
962+
templateValueArray.push($(templatePicked[i]).attr("data-value"));
963+
}
854964

855965
var gen = {};
856966
gen['updatePath'] = $("#updateMultiplePath").val();
857967
gen['platformList'] = platformValueArray;
968+
gen['templateList'] = templateValueArray;
858969
gen['updateRecursive'] = true;
859970
gen['ofPath'] = $("#ofPath").val();
860971
gen['verbose'] = bVerbose;
@@ -922,10 +1033,18 @@ function enableAdvancedMode(isAdvanced) {
9221033
$("body").addClass('advanced');
9231034
$('a.updateMultiMenuOption').show();
9241035

1036+
$('#templateSection').show();
1037+
$('#templateSectionMulti').show();
1038+
9251039
} else {
9261040
$('#platformsDropdown').addClass("disabled");
9271041
$('#platformsDropdown').dropdown('set exactly', defaultSettings['defaultPlatform']);
9281042

1043+
$('#templateSection').hide();
1044+
$('#templateSectionMulti').hide();
1045+
$('#templateDropdown').dropdown('set exactly', '');
1046+
$('#templateDropdownMulti').dropdown('set exactly', '');
1047+
9291048
$("body").removeClass('advanced');
9301049
$('a.updateMultiMenuOption').hide();
9311050

frontend/index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,18 @@
202202
</div>
203203
<div id="test"></div>
204204
</div>
205+
<div id="templateSection" class="field">
206+
<label>Template:</label>
207+
<div class="ui multiple search selection dropdown" id="templatesDropdown">
208+
<input name="templates" type="hidden">
209+
<i class="dropdown icon"></i>
210+
<div class="default text">Template...</div>
211+
<div class="menu" id="templateList">
212+
</div>
213+
</div>
214+
<div id="test"></div>
215+
</div>
216+
205217
<div class="ui hidden divider"></div>
206218
<div class="field">
207219
<div class="ui olive button" id="generateButton" onclick="generate()">Generate</div>
@@ -246,6 +258,17 @@
246258
</div>
247259
</div>
248260
</div>
261+
<div id="templateSectionMulti" class="field">
262+
<label>Template:</label>
263+
<div class="ui multiple search selection dropdown" id="templatesDropdownMulti">
264+
<input name="templates" type="hidden">
265+
<i class="dropdown icon"></i>
266+
<div class="default text">Template...</div>
267+
<div class="menu" id="templateListMulti">
268+
</div>
269+
</div>
270+
<div id="test"></div>
271+
</div>
249272
<div class="ui hidden divider"></div>
250273
<div class="field">
251274
<div class="ui orange button" id="updateMultipleButton" onclick="updateRecursive()">Update multiple</div>

0 commit comments

Comments
 (0)