Skip to content

Commit a43b56a

Browse files
Theme preview extracted from can code and refactored
1 parent a51fed7 commit a43b56a

5 files changed

Lines changed: 60 additions & 14 deletions

File tree

frontend/src/modules/editor/selectTheme/less/editorTheme.less

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}
77

88
.theme-list-item {
9-
height: 175px;
9+
height: 280px;
1010
width: 275px;
1111
margin-left:0px;
1212
margin-right: 30px;
@@ -33,19 +33,26 @@
3333
}
3434

3535
&-inner {
36-
padding: 20px;
36+
padding-top: 20px;
37+
3738
.theme-header {
38-
padding-bottom: 30px;
39-
}
40-
}
39+
.display-name {
40+
padding-left: 20px;
41+
font-size: 175%;
42+
font-weight: @font-weight;
43+
}
4144

42-
.display-name {
43-
font-size: 175%;
44-
font-weight: @font-weight;
45-
}
46-
.description {
47-
font-size: 110%;
48-
color: #a6c2ca;
45+
.description {
46+
padding-left: 20px;
47+
padding-bottom: 15px;
48+
font-size: 110%;
49+
color: @quaternary-color;
50+
}
51+
52+
.theme_preview {
53+
padding-top: 10px;
54+
}
55+
}
4956
}
5057
}
5158

@@ -56,7 +63,7 @@
5663
width: 60px;
5764
float: left;
5865
position: relative;
59-
background: url(/css/assets/theme_bg.png) top left no-repeat;
66+
background: url(/images/theme_bg.png) top left no-repeat;
6067
margin-left: 0;
6168
margin-right: 18px;
6269

frontend/src/modules/editor/selectTheme/templates/editorThemeItem.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div class="theme-header">
33
<div class="display-name"><h4 style="color: {{foreground_color.default}}">{{displayName}}</h4></div>
44
<div class="description">{{description}}</div>
5+
<div class="theme-preview"></div>
56
</div>
67
{{#if settings}}
78
<div class="theme-pallet-container">

frontend/src/modules/editor/selectTheme/views/editorThemeItemView.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ define(function(require){
2424
},
2525

2626
postRender: function() {
27+
var previewUrl = '/api/theme/preview/' + this.model.attributes.name + '/' + this.model.attributes.version;
28+
var $previewLoc = this.$el.find('.theme-preview');
29+
30+
$.ajax(previewUrl, {
31+
statusCode: {
32+
// if a preview image is found
33+
200: function() {
34+
$previewLoc.prepend('<img src="' + previewUrl + '"alt="Preview image"' + '/>');
35+
}
36+
}
37+
});
2738
},
2839

2940
toggleSelect: function(event) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
},
9191
"dependencies": {
9292
"archiver": "~0.16.0",
93-
"async": "0.2.5",
93+
"async": "2.5.0",
9494
"bcrypt-nodejs": "0.0.3",
9595
"body-parser": "^1.13.3",
9696
"bower": "1.6.5",

plugins/content/theme/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,33 @@ function initialize () {
130130
var app = origin();
131131
app.once('serverStarted', function (server) {
132132

133+
//get the theme preview image
134+
rest.get('/theme/preview/:themename/:version', function (req, res, next) {
135+
//strip slashes to stop unwanted directory traversal
136+
var themeName = req.params.themename.replace(/\\(.)/mg, "$1");
137+
var themeVersion = req.params.version.replace(/\\(.)/mg, "$1");
138+
var tenantId = configuration.getConfig('masterTenantID');
139+
140+
async.tryEach([
141+
function(callback) {
142+
//try manual install location
143+
fs.readFile(path.join(__dirname, 'versions', themeName, themeVersion, themeName, 'preview.jpg'), callback);
144+
},
145+
function(callback) {
146+
//try bower install location
147+
fs.readFile(path.join(__dirname, '..', '..', '..', 'temp', tenantId, 'adapt_framework', 'src', 'theme', themeName, 'preview.jpg'), callback);
148+
}
149+
],function(err, img) {
150+
if(err){
151+
res.sendStatus(404);
152+
return res;
153+
}
154+
res.writeHead(200, {'Content-Type': 'image/jpg' });
155+
res.end(img);
156+
return res;
157+
});
158+
});
159+
133160
// Assign a theme to to a course
134161
rest.post('/theme/:themeid/makeitso/:courseid', function (req, res, next) {
135162
var themeId = req.params.themeid;

0 commit comments

Comments
 (0)