Skip to content

Commit 1e88253

Browse files
start implementing store
1 parent 041a82d commit 1e88253

File tree

5 files changed

+65
-61
lines changed

5 files changed

+65
-61
lines changed

public/evileval.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ define([], function(){
44
// TODO this is not a path, rename
55
var jsAnimPath = toDataUri(codeString);
66
return loadJsAnimOnCanvasAnim(jsAnimPath, canvasAnim, canvasAnim.animationName);
7-
},
7+
};
88

9-
loadJsAnim = function(jsAnimPath){
10-
return new Promise(function(resolve, reject){
11-
require([jsAnimPath],
12-
function(animationCode){
13-
resolve(Object.create(animationCode));
14-
},
15-
function(err){
16-
reject(err);
17-
});
18-
});
19-
},
20-
21-
loadJsAnimOnCanvasAnim = function(jsAnimPath, canvasAnim, animationName){
9+
var loadJsAnim = function(jsAnimPath){
10+
return new Promise(function(resolve, reject){
11+
require([jsAnimPath],
12+
function(animationCode){
13+
resolve(Object.create(animationCode));
14+
},
15+
function(err){
16+
reject(err);
17+
});
18+
});
19+
};
20+
21+
var loadJsAnimOnCanvasAnim = function(jsAnimPath, canvasAnim, animationName){
2222
return loadJsAnim(jsAnimPath)
2323
.then(function(animationCodeClone){
2424
canvasAnim.uri = jsAnimPath;
@@ -29,9 +29,9 @@ define([], function(){
2929
}
3030
return canvasAnim;
3131
});
32-
},
33-
34-
toDataUri = function(jsCode){
32+
};
33+
34+
var toDataUri = function(jsCode){
3535
return "data:text/javascript;base64," + btoa(jsCode);
3636
},
3737

public/exquis.js

+21-13
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ define(["iter2d", "csshelper", "evileval", "net"], function(iter2d, csshelper, e
1010
cell.context = context;
1111
cell.hint = createCellDiv("hint", row, col, height, width);
1212
cell.ui = makeCellUi(row, col, height, width);
13-
addCellUiListener(cell.ui);
1413
return cell;
1514
};
1615

17-
var addCellUiListener = function(cellUi){
16+
var addCellUiListeners = function(cellUi, store){
1817
var childNodes = cellUi.childNodes;
1918
cellUi.addEventListener("mouseover", function(e){
2019
for(var i = 0; i < childNodes.length; i++){
@@ -26,7 +25,7 @@ define(["iter2d", "csshelper", "evileval", "net"], function(iter2d, csshelper, e
2625
childNodes[i].style.visibility = "hidden";
2726
};
2827
});
29-
28+
addLoadAnimationHandler(cellUi.id, store);
3029
};
3130

3231
var makeCanvasAnimation = function(context){
@@ -125,26 +124,34 @@ define(["iter2d", "csshelper", "evileval", "net"], function(iter2d, csshelper, e
125124
return cellDiv;
126125
};
127126

128-
var makeIcon = function(classNames){
127+
var makeIcon = function(classNames, id){
129128
var icon = document.createElement('span');
130129
icon.style.visibility = "hidden";
131130
icon.style.cursor = "pointer";
132131
icon.className = classNames;
132+
if(id){
133+
icon.id = id;
134+
}
133135
return icon;
134136
};
135137

138+
var loadIconSuffix = "-load-icon";
136139
var makeCellUi = function(row, col, height, width){
137140
var cellUi = createCellDiv("cellUi", row, col, height, width);
138-
var loadAnimationIcon = makeIcon("fa fa-folder-open-o fa-lg");
141+
var loadAnimationIcon = makeIcon("fa fa-folder-open-o fa-lg", cellUi.id + loadIconSuffix);
139142
cellUi.appendChild(loadAnimationIcon);
143+
return cellUi;
144+
};
145+
146+
var addLoadAnimationHandler = function(cellUiId, store){
147+
var loadAnimationIcon = document.getElementById(cellUiId + loadIconSuffix);
140148
loadAnimationIcon.addEventListener('click', function(){
141-
alert("not today");
142-
//TODO load list of animations from store
149+
store.loadAnimationList().then(function(fileUris){
150+
alert(fileUris);
151+
});
143152
//TODO display list in dialog
144153
//TODO load animation on canvasAnim
145154
});
146-
147-
return cellUi;
148155
};
149156

150157
var addHintListeners = function(cells){
@@ -176,7 +183,7 @@ define(["iter2d", "csshelper", "evileval", "net"], function(iter2d, csshelper, e
176183
exquis.editorController.show();
177184
};
178185

179-
var editIcon = makeIcon("fa fa-pencil-square-o fa-lg");
186+
var editIcon = makeIcon("fa fa-pencil-square-o fa-lg", cell.ui.id + "-edit-icon");
180187
editIcon.addEventListener('click', edit, false);
181188
cell.ui.appendChild(editIcon);
182189
});
@@ -191,18 +198,19 @@ define(["iter2d", "csshelper", "evileval", "net"], function(iter2d, csshelper, e
191198
document.addEventListener('click', possiblyHideEditor, true);
192199
};
193200

194-
var init = function (assName, animUris, makeEditorView, makeEditorController) {
201+
var init = function (assName, animUris, makeEditorView, makeEditorController, store) {
195202
var container = document.getElementById("container"),
196203
exquis = {};
197204
exquis.assName = assName;
198205

199-
//TODO give the code url as argument instead of animCode
200-
// canvasAnim should have a method to load the code from the url:
206+
//TODO canvasAnim should have a method to load the source code from the url:
201207
// getSourceCodeString (which reads from the cache of the canvasAnim, or the store)
208+
// This becomes necessary when start to have code other than javascript
202209
exquis.cells = iter2d.map2dArray(animUris,function(animUri,row,col){
203210
var height = 150,
204211
width = 150,
205212
cell = makeCell(row, col, height, width);
213+
addCellUiListeners(cell.ui, store);
206214
cell.canvasAnim = makeCanvasAnimation(cell.context);
207215
evileval.loadJsAnim(animUri).then(function(animationCodeClone){
208216
cell.canvasAnim.setAnimation(animationCodeClone, animUri);

public/main.js

+5-26
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,17 @@
1-
2-
var makeAnimationPath = function (animName){
3-
if(/^https?:\/\//.exec(animName)){
4-
return animName;
5-
}
6-
return "/animations/" + animName + ".js";
7-
};
8-
9-
var splitarray = function(input, spacing){
10-
var output = [];
11-
for (var i = 0; i < input.length; i += spacing){
12-
output[output.length] = input.slice(i, i + spacing);
13-
}
14-
return output;
15-
};
16-
17-
var main = function(net, exquisInit, makeEditorView, makeEditorController, evileval){
1+
var main = function(net, exquisInit, makeEditorView, makeEditorController, store, iter2d){
182
window.onerror = function(message, url, lineNumber){
193
//console.log(message +" "+ url +" "+ lineNumber);
204
};
215
var assemblageName = net.getAssemblageNameFromUrlOrDefaultWithUrlChange();
226
net.loadAssemblage(assemblageName)
237
.then(function(animationNames){
24-
var animNamesList = animationNames.reduce(function(a, b) {
25-
return a.concat(b);
26-
}),
27-
animUris = animNamesList.map(function(animName){
28-
return makeAnimationPath(animName);
29-
});
30-
var animUris2DArray = splitarray(animUris, 3);
8+
var animUris2DArray = iter2d.map2dArray(animationNames, net.makeAnimationPath);
319
var exquis = exquisInit(assemblageName, animUris2DArray,
32-
makeEditorView, makeEditorController);
10+
makeEditorView, makeEditorController,
11+
store);
3312
// this is only for debugging in the console
3413
window.x = exquis;
3514
});
3615
};
3716

38-
require(["net", "exquis", "editorView", "editorController", "evileval", "lib/domReady!"], main);
17+
require(["net", "exquis", "editorView", "editorController", "nodestore", "iter2d", "lib/domReady!"], main);

public/net.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ define(["iter2d", "evileval"], function(iter2d, evileval){
3131
ajax.send(params);
3232
};
3333

34-
var makeAnimationFileName = function(animationName){
35-
return "/animations/"+animationName + ".js";
36-
};
37-
3834
var makeAnimationFileUri = function(animationName){
3935
return "/animations/"+animationName + ".js";
4036
};
@@ -111,7 +107,8 @@ define(["iter2d", "evileval"], function(iter2d, evileval){
111107
getAssemblageNameFromUrlOrDefaultWithUrlChange: getAssemblageNameFromUrlOrDefaultWithUrlChange,
112108
loadAssemblage: loadAssemblage,
113109
makeAnimationFileUri: makeAnimationFileUri,
114-
extractAnimationNameFromUri : extractAnimationNameFromUri,
110+
makeAnimationPath: makeAnimationPath ,
111+
extractAnimationNameFromUri: extractAnimationNameFromUri,
115112
saveAssemblage: saveAssemblage,
116113
HTTPgetJSON: HTTPgetJSON,
117114
HTTPget: HTTPget

public/nodestore.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
/**
3+
different implementations of the store would save the animation in different places.
4+
The original url of the animation is independent of the store
5+
because we want exquis to be able to just display animations from any url.
6+
The store needs to know where to save an animation based on its url.
7+
Currently the original url is replaced by a data uri when it is first edited,
8+
because it's only used to load the code. We need to keep it in order to save it.
9+
*/
10+
define(["net", "evileval"], function(net, evileval){
11+
//TODO load list of animations from store
12+
var loadAnimationList = function(){
13+
return net.HTTPgetJSON("/animations/").then(function(files){
14+
return files.filter(function(f){
15+
return f.match(/\.js$/);
16+
});
17+
});
18+
};
19+
return {loadAnimationList: loadAnimationList};
20+
});

0 commit comments

Comments
 (0)