forked from chilipeppr/workspace-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workspace.1.js
305 lines (282 loc) · 14.1 KB
/
workspace.1.js
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/* global cpdefine chilipeppr cprequire */
cprequire_test(["inline:com-chilipeppr-workspace-bastianf2"], function(ws) {
console.log("initting workspace");
/**
* The Root workspace (when you see the ChiliPeppr Header) auto Loads the Flash
* Widget so we can show the 3 second flash messages. However, in test mode we
* like to see them as well, so just load it from the cprequire_test() method
* so we have similar functionality when testing this workspace.
*/
var loadFlashMsg = function() {
chilipeppr.load("#com-chilipeppr-widget-flash-instance",
"http://fiddle.jshell.net/chilipeppr/90698kax/show/light/",
function() {
console.log("mycallback got called after loading flash msg module");
cprequire(["inline:com-chilipeppr-elem-flashmsg"], function(fm) {
//console.log("inside require of " + fm.id);
fm.init();
});
}
);
};
loadFlashMsg();
// Init workspace
ws.init();
// Do some niceties for testing like margins on widget and title for browser
$('title').html("bastianf2 Workspace");
$('body').css('padding', '10px');
} /*end_test*/ );
// This is the main definition of your widget. Give it a unique name.
cpdefine("inline:com-chilipeppr-workspace-bastianf2", ["chilipeppr_ready"], function() {
return {
/**
* The ID of the widget. You must define this and make it unique.
*/
id: "com-chilipeppr-workspace-bastianf2", // Make the id the same as the cpdefine id
name: "Workspace / bastianf2", // The descriptive name of your widget.
desc: `A ChiliPeppr Workspace bastianf2.`,
url: "(auto fill by runme.js)", // The final URL of the working widget as a single HTML file with CSS and Javascript inlined. You can let runme.js auto fill this if you are using Cloud9.
fiddleurl: "(auto fill by runme.js)", // The edit URL. This can be auto-filled by runme.js in Cloud9 if you'd like, or just define it on your own to help people know where they can edit/fork your widget
githuburl: "(auto fill by runme.js)", // The backing github repo
testurl: "(auto fill by runme.js)", // The standalone working widget so can view it working by itself
foreignSubscribe: {
"/com-chilipeppr-elem-dragdrop/ondragover": "The Chilipeppr drag drop element will publish on channel /com-chilipeppr-elem-dragdrop/ondropped when a file is dropped so we subscribe to it so we can load a Gcode file when the user drags it onto the browser. It also adds a hover class to the bound DOM elem so we can add a CSS to hilite on hover",
"/com-chilipeppr-elem-dragdrop/ondragleave": "We need to know when the drag is over to remove the CSS hilites.",
"/com-chilipeppr-widget-gcode/resize": "We watch if the Gcode viewer resizes so that we can reposition or resize other elements in the workspace. Specifically we ask the Serial Port Console to resize. We also redraw the 3D Viewer so it fills the whole screen."
},
/**
* Contains reference to the Console widget object. Hang onto the reference
* so we can resize it when the window resizes because we want it to manually
* resize to fill the height of the browser so it looks clean.
*/
widgetConsole: null,
/**
* Contains reference to the Serial Port JSON Server object.
*/
widgetSpjs: null,
/**
* The workspace's init method. It loads the all the widgets contained in the workspace
* and inits them.
*/
init: function() {
// Most workspaces will instantiate the Serial Port JSON Server widget
this.loadSpjsWidget();
// Most workspaces will instantiate the Serial Port Console widget
this.loadConsoleWidget(function() {
setTimeout(function() { $(window).trigger('resize'); }, 100);
});
this.loadTemplateWidget();
this.loadSenscapeBootloaderWidget();
this.loadLuaEditorWidget();
this.loadDropTestWidget();
// Create our workspace upper right corner triangle menu
this.loadWorkspaceMenu();
// Add our billboard to the menu (has name, url, picture of workspace)
this.addBillboardToWorkspaceMenu();
// Setup an event to react to window resize. This helps since
// some of our widgets have a manual resize to cleanly fill
// the height of the browser window. You could turn this off and
// just set widget min-height in CSS instead
this.setupResize();
setTimeout(function() { $(window).trigger('resize'); }, 100);
},
/**
* Returns the billboard HTML, CSS, and Javascript for this Workspace. The billboard
* is used by the home page, the workspace picker, and the fork pulldown to show a
* consistent name/image/description tag for the workspace throughout the ChiliPeppr ecosystem.
*/
getBillboard: function() {
var el = $('#' + this.id + '-billboard').clone();
el.removeClass("hidden");
el.find('.billboard-desc').text(this.desc);
return el;
},
/**
* Inject the billboard into the Workspace upper right corner pulldown which
* follows the standard template for workspace pulldown menus.
*/
addBillboardToWorkspaceMenu: function() {
// get copy of billboard
var billboardEl = this.getBillboard();
$('#' + this.id + ' .com-chilipeppr-ws-billboard').append(billboardEl);
},
/**
* Listen to window resize event.
*/
setupResize: function() {
$(window).on('resize', this.onResize.bind(this));
},
/**
* When browser window resizes, forcibly resize the Console window
*/
onResize: function() {
if (this.widgetConsole) this.widgetConsole.resize();
},
/**
* Load the Template widget via chilipeppr.load() so folks have a sample
* widget they can fork as a starting point for their own.
*/
loadTemplateWidget: function(callback) {
chilipeppr.load(
"#com-chilipeppr-widget-template-instance",
"http://raw.githubusercontent.com/chilipeppr/widget-template/master/auto-generated-widget.html",
function() {
// Callback after widget loaded into #myDivWidgetTemplate
// Now use require.js to get reference to instantiated widget
cprequire(
["inline:com-chilipeppr-widget-template"], // the id you gave your widget
function(myObjWidgetTemplate) {
// Callback that is passed reference to the newly loaded widget
console.log("Widget / Template just got loaded.", myObjWidgetTemplate);
myObjWidgetTemplate.init();
}
);
}
);
},
/**
* Load the Serial Port JSON Server widget via chilipeppr.load()
*/
loadSpjsWidget: function(callback) {
var that = this;
chilipeppr.load(
"#com-chilipeppr-widget-serialport-instance",
"http://fiddle.jshell.net/chilipeppr/vetj5fvx/show/light/",
function() {
console.log("mycallback got called after loading spjs module");
cprequire(["inline:com-chilipeppr-widget-serialport"], function(spjs) {
//console.log("inside require of " + fm.id);
spjs.setSingleSelectMode();
spjs.init({
isSingleSelectMode: true,
defaultBuffer: "default",
defaultBaud: 115200,
bufferEncouragementMsg: 'For your device please choose the "default" buffer in the pulldown and a 115200 baud rate before connecting.'
});
//spjs.showBody();
//spjs.consoleToggle();
that.widgetSpjs - spjs;
if (callback) callback(spjs);
});
}
);
},
/**
* Load Senscape Bootloader Wedget via chilipeppr.load()
*/
loadSenscapeBootloaderWidget: function(callback) {
chilipeppr.load(
"#com-senscape-widget-bootloader-instance",
"http://raw.githubusercontent.com/bastian-f/widget-senscape-bootlader/master/auto-generated-widget.html",
function() {
// Callback after widget loaded into #myDivComSenscapeWidgetBootloader
// Now use require.js to get reference to instantiated widget
cprequire(
["inline:com-senscape-widget-bootloader"], // the id you gave your widget
function(myObjComSenscapeWidgetBootloader) {
// Callback that is passed reference to the newly loaded widget
console.log("Widget / Senscape Bootloader just got loaded.", myObjComSenscapeWidgetBootloader);
myObjComSenscapeWidgetBootloader.init();
}
);
}
);
},
/**
* Load Senscape Bootloader Wedget via chilipeppr.load()
*/
loadDropTestWidget: function(callback) {
chilipeppr.load(
"#drop-test-instance",
"http://raw.githubusercontent.com/chilipeppr/elem-dragdrop/master/auto-generated-widget.html",
function() {
// Callback after widget loaded into #myDivElemDragdrop
// Now use require.js to get reference to instantiated widget
cprequire(
["inline:drop-test"], // the id you gave your widget
function(myObjElemDragdrop) {
// Callback that is passed reference to the newly loaded widget
console.log("Element / Drag Drop just got loaded.", myObjElemDragdrop);
myObjElemDragdrop.init();
}
);
}
);
},
/**
* Load the Lua Editor Widget widget via chilipeppr.load()
*/
loadLuaEditorWidget: function(callback) {
var that = this;
chilipeppr.load(
"#com-chilipeppr-luaeditor-instance",
"http://raw.githubusercontent.com/chilipeppr/widget-luaeditor/master/auto-generated-widget.html",
function() {
// Callback after widget loaded into #myDivWidgetLuaeditor
// Now use require.js to get reference to instantiated widget
cprequire(
["inline:com-chilipeppr-widget-luaeditor"], // the id you gave your widget
function(myObjWidgetLuaeditor) {
// Callback that is passed reference to the newly loaded widget
console.log("Widget / Lua Editor just got loaded.", myObjWidgetLuaeditor);
myObjWidgetLuaeditor.init();
}
);
}
);
},
/**
* Load the Console widget via chilipeppr.load()
*/
loadConsoleWidget: function(callback) {
var that = this;
chilipeppr.load(
"#com-chilipeppr-widget-spconsole-instance",
"http://fiddle.jshell.net/chilipeppr/rczajbx0/show/light/",
function() {
// Callback after widget loaded into #com-chilipeppr-widget-spconsole-instance
cprequire(
["inline:com-chilipeppr-widget-spconsole"], // the id you gave your widget
function(mywidget) {
// Callback that is passed reference to your newly loaded widget
console.log("My Console widget just got loaded.", mywidget);
that.widgetConsole = mywidget;
// init the serial port console
// 1st param tells the console to use "single port mode" which
// means it will only show data for the green selected serial port
// rather than for multiple serial ports
// 2nd param is a regexp filter where the console will filter out
// annoying messages you don't generally want to see back from your
// device, but that the user can toggle on/off with the funnel icon
that.widgetConsole.init(true, /myfilter/);
if (callback) callback(mywidget);
}
);
}
);
},
/**
* Load the workspace menu and show the pubsubviewer and fork links using
* our pubsubviewer widget that makes those links for us.
*/
loadWorkspaceMenu: function(callback) {
// Workspace Menu with Workspace Billboard
var that = this;
chilipeppr.load(
"http://fiddle.jshell.net/chilipeppr/zMbL9/show/light/",
function() {
require(['inline:com-chilipeppr-elem-pubsubviewer'], function(pubsubviewer) {
var el = $('#' + that.id + ' .com-chilipeppr-ws-menu .dropdown-menu-ws');
console.log("got callback for attachto menu for workspace. attaching to el:", el);
pubsubviewer.attachTo(
el,
that,
"Workspace"
);
if (callback) callback();
});
}
);
},
}
});