Skip to content

Commit 7fbab8d

Browse files
Merge pull request #1692 from CanStudios/theme-previews
Theme previews
2 parents b63a403 + a19acf9 commit 7fbab8d

6 files changed

Lines changed: 76 additions & 19 deletions

File tree

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

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

88
.theme-list-item {
9-
height: 175px;
9+
height: 295px;
1010
width: 275px;
1111
margin-left:0px;
1212
margin-right: 30px;
@@ -20,33 +20,49 @@
2020
transition:all 0.3s;
2121
border: 1px solid #d6f2f9;
2222

23+
&-inner {
24+
.theme-header {
25+
padding: 20px;
26+
27+
.display-name {
28+
font-size: 175%;
29+
font-weight: @font-weight;
30+
}
31+
32+
.description {
33+
font-size: 110%;
34+
color: @quaternary-color;
35+
}
36+
}
37+
38+
.theme-preview {
39+
position: relative;
40+
height: 205px;
41+
width: 100%;
42+
43+
.fa {
44+
color:rgb(214, 242, 249);
45+
position: absolute;
46+
font-size: 70px;
47+
top: 45%;
48+
left: 50%;
49+
transform: translate(-50%, -50%);
50+
}
51+
}
52+
}
53+
2354
&.selected {
2455
background-color: @primary-color;
2556
color: @button-primary-text-color;
2657
.description {
2758
color: #d6f2f9;
2859
}
2960
}
61+
3062
&:hover {
3163
cursor: pointer;
3264
box-shadow: 0 0 5px 2px #CBE1E6;
3365
}
34-
35-
&-inner {
36-
padding: 20px;
37-
.theme-header {
38-
padding-bottom: 30px;
39-
}
40-
}
41-
42-
.display-name {
43-
font-size: 175%;
44-
font-weight: @font-weight;
45-
}
46-
.description {
47-
font-size: 110%;
48-
color: #a6c2ca;
49-
}
5066
}
5167

5268
.theme-palette {
@@ -56,7 +72,6 @@
5672
width: 60px;
5773
float: left;
5874
position: relative;
59-
background: url(/css/assets/theme_bg.png) top left no-repeat;
6075
margin-left: 0;
6176
margin-right: 18px;
6277

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

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

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

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

2626
postRender: function() {
27+
var previewUrl = '/api/theme/preview/' + this.model.get('name') + '/' + this.model.get('name');
28+
var $previewLoc = this.$('.theme-preview');
29+
30+
$.ajax(previewUrl, {
31+
statusCode: {
32+
200: function() {
33+
$previewLoc.prepend($('<img/>', { src: previewUrl, alt: Origin.l10n.t('app.themepreviewalt') }));
34+
},
35+
204: function() {
36+
$previewLoc.prepend($('<i/>', { 'class': 'fa fa-paint-brush' }));
37+
}
38+
}
39+
});
2740
},
2841

2942
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(204);
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;

routes/lang/en-application.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
"app.configurationsettings": "Configuration settings",
145145
"app.themesettings": "Theme settings",
146146
"app.themepicker": "Theme picker",
147+
"app.themepreviewalt": "Preview image",
147148
"app.lastupdated": "UPDATED",
148149
"app.recent": "Recent",
149150
"app.assettitle": "Asset title",

0 commit comments

Comments
 (0)