Skip to content

Commit 3d9c56c

Browse files
adamcarhedenMarkusBordihn
authored andcommitted
Merged UI portions of workbench into tutorial (#173)
Workbench/Tutorial UI: * Made Workbench and Tutorial share a single UI/sidebar component Data can be loaded either from workbench or a .cwct file * Greyed out completed steps * Sidebar icon is now numbered list to coorispond to the content that gets displayed Tutorial Features/Operation: * Tutorial now allows per-step validation * Tutorial now supports loading code into editor for each step * Tutoiral validation runs in dedicated webview instead of preview * setTutorial() now automatically starts the tuorial when async operations are complete instead of requiring separate all to startTutorial() Logging: * Messenger displays a warning instead of an error for unknown messages because tutorial validation posts messages to the main CwC window, which messenger does not recognize Testing: * Added tests for Workbench/Tutorial UI * Added builder.getHelper() function to aid in unit testing * Exported various functions to aid in unit testing
1 parent f018147 commit 3d9c56c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2286
-1111
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99

1010
Google Inc.
1111
Shenzhen Maker Works Co, Ltd.
12+
cwist, Inc. (d/b/a Workbench)
1213
and other contributors

build/cwc/tutorials.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ let replacePlaceholders = function(obj, pwd) {
6363
if (obj === null || typeof obj !== 'object') {
6464
return;
6565
}
66+
let templateRE = /^___TEMPLATE___:(binary:)?/;
6667
for (let k in obj) {
67-
if (k.match(/^___TEMPLATE___:/)) {
68-
obj[k.replace('___TEMPLATE___:', '')] =
68+
if (!Object.prototype.hasOwnProperty.call(obj, k)) continue;
69+
const matches = k.match(templateRE);
70+
if (matches) {
71+
const data = matches[1] ?
72+
fs.readFileSync(pwd+'/'+obj[k]).toString('base64') :
6973
fs.readFileSync(pwd+'/'+obj[k], 'utf8');
74+
obj[k.replace(matches[0], '')] = data;
7075
delete obj[k];
7176
} else {
7277
replacePlaceholders(obj[k], pwd);

src/addon/workbench/workbench.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
goog.provide('cwc.addon.Workbench');
2121

2222
goog.require('cwc.addon.WorkbenchLoader');
23-
goog.require('cwc.addon.WorkbenchProject');
2423
goog.require('cwc.mode.Type');
2524
goog.require('cwc.soy.SelectScreenTemplate');
2625
goog.require('cwc.ui.SelectScreen.Events');
2726
goog.require('cwc.utils.Database');
27+
goog.require('cwc.utils.I18n');
2828
goog.require('cwc.utils.Logger');
2929

3030

@@ -154,6 +154,9 @@ cwc.addon.Workbench = function(helper) {
154154

155155
/** @private {!cwc.utils.Logger} */
156156
this.log_ = new cwc.utils.Logger(this.name);
157+
158+
/** @private {!string} */
159+
this.projectDetailLinkBase_ = 'https://edu.workbencheducation.com/cwists/preview/';
157160
};
158161

159162

@@ -210,7 +213,6 @@ cwc.addon.Workbench.prototype.filterProjectsByTag_ = function(
210213
));
211214
};
212215

213-
214216
/**
215217
* @private
216218
*/
@@ -223,7 +225,10 @@ cwc.addon.Workbench.prototype.showRelevantProjects_ = async function() {
223225
if (!tabNode) return;
224226

225227
const mode = tagMap[tag].mode;
226-
const matchingProjects = this.filterProjectsByTag_(allProjects, tag);
228+
const userLanguage = this.helper.getUserLanguage();
229+
const userLanguageName = cwc.utils.I18n.getEnglishName()[userLanguage];
230+
let matchingProjects = this.filterProjectsByTag_(allProjects.filter(
231+
(project) => project.language == userLanguageName), tag);
227232

228233
matchingProjects.forEach((project) => {
229234
const card = goog.soy.renderAsElement(
@@ -236,15 +241,35 @@ cwc.addon.Workbench.prototype.showRelevantProjects_ = async function() {
236241
});
237242

238243
card.addEventListener('click', () => {
244+
let tutorialInstance = this.helper.getInstance('tutorial');
239245
this.helper.getInstance('mode')
240246
.loadMode(mode)
241247
.then(() => {
242-
const projectUI = new cwc.addon.WorkbenchProject(
243-
this.helper,
244-
project,
245-
this.imagesDb_,
246-
);
247-
projectUI.decorate();
248+
// Map Workbench project data structure into CwC Tutorial structure
249+
let tutorialSpec = {
250+
'url': this.projectDetailLinkBase_ + project.id,
251+
'description': {
252+
'text': project['description'],
253+
'mime_type': 'text/html',
254+
},
255+
'steps': project['steps'].sort((a, b) => {
256+
return a.order - b.order;
257+
}).map((step) => {
258+
return {
259+
'title': step['title'],
260+
'description': {
261+
'text': step['description'],
262+
'mime_type': 'text/html',
263+
},
264+
'images': step['images'],
265+
'videos': step['videos'],
266+
};
267+
}),
268+
};
269+
return tutorialInstance.setTutorial(tutorialSpec, this.imagesDb_);
270+
})
271+
.then(() => {
272+
tutorialInstance.startTutorial();
248273
});
249274
});
250275

@@ -254,7 +279,6 @@ cwc.addon.Workbench.prototype.showRelevantProjects_ = async function() {
254279
});
255280
};
256281

257-
258282
/**
259283
* @private
260284
*/

src/addon/workbench/workbench_project.gss

Lines changed: 0 additions & 242 deletions
This file was deleted.

0 commit comments

Comments
 (0)