Skip to content

Commit ffe5d01

Browse files
committed
Merge pull request #310 from piotrpalek/cli-2.3.0-beta.1
upgrade ember-cli/ember/ember-data to 2.3
2 parents bb72ff8 + cf874a2 commit ffe5d01

File tree

19 files changed

+189
-109
lines changed

19 files changed

+189
-109
lines changed

app/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Ember from 'ember';
2-
import Resolver from 'ember-resolver';
2+
import Resolver from './resolver';
33
import loadInitializers from 'ember/load-initializers';
44
import config from './config/environment';
55

app/components/file-tree.js

Lines changed: 65 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,77 @@
11
import Ember from "ember";
2-
import _ from 'lodash/lodash';
3-
42
const { computed } = Ember;
53

64
export default Ember.Component.extend({
75
jsTreeActionReceiver: null,
86

9-
/**
10-
* Calculate data for file tree
11-
*/
12-
fileTreeData: computed('model.files.[]', function() {
13-
let seq = 0;
14-
let treeData = this.get('model.files').map(function(file) {
15-
let path = file.get('filePath');
16-
let splitPath = path.split("/");
17-
let parentPath = splitPath.slice(0, -1).join("/");
18-
let fileName = splitPath[splitPath.length - 1];
19-
if (parentPath === "") {
20-
parentPath = "#";
21-
}
22-
return {
23-
id: "node" + seq++,
24-
text: fileName,
25-
parent: parentPath,
26-
icon: "glyphicon glyphicon-file light-gray",
27-
path: path,
28-
leaf: true
29-
};
30-
});
7+
fileTreeHash: computed('model.files.[]', function() {
8+
const files = this.get('model.files');
319

32-
let done = false;
33-
do {
34-
done = true;
35-
let paths = _.uniq(_.pluck(treeData, 'text'));
36-
let parents = _.uniq(_.pluck(treeData, 'parent'));
37-
parents.forEach(function(parent) {
38-
if (!paths.contains(parent) && parent !== "#" && treeData.filterBy('path', parent).length === 0) {
39-
let splitPath = parent.split("/");
40-
let parentPath = splitPath.slice(0, -1).join("/");
41-
let fileName = splitPath[splitPath.length - 1];
42-
if (parentPath === "") {
43-
parentPath = "#";
44-
}
45-
treeData.push({
46-
id: "node" + seq++,
47-
text: fileName,
48-
parent: parentPath,
49-
icon: "glyphicon glyphicon-folder-open yellow",
50-
path: parent
51-
});
52-
done = false;
10+
return files.reduce((accumulator, file) => {
11+
const path = file.get('filePath');
12+
const splitPath = path.split('/');
13+
const splitPathZeroBasedLength = splitPath.length - 1;
14+
15+
const possiblePaths = splitPath.map((pathPart, index, paths) => {
16+
const previousPathIsRoot = index - 1 < 0;
17+
const pathObj = {
18+
nodeName: pathPart,
19+
isFile: false
20+
};
21+
22+
if(previousPathIsRoot) {
23+
pathObj.path = pathPart;
24+
pathObj.parent = '#';
25+
} else {
26+
const previousPath = paths.slice(0, index).join('/');
27+
pathObj.path = `${previousPath}/${pathPart}`;
28+
pathObj.parent = previousPath;
29+
}
30+
31+
if(index === splitPathZeroBasedLength) {
32+
pathObj.isFile = true;
5333
}
34+
35+
return pathObj;
5436
});
55-
} while (!done);
5637

57-
let idMap = {};
58-
treeData.forEach(function(node) {
59-
idMap[node.path] = node.id;
60-
});
38+
const existingFilteredOut = possiblePaths.filter(pathObj => {
39+
return !accumulator[pathObj.path];
40+
});
6141

62-
treeData.forEach(function(node) {
63-
if (node.parent !== "#") {
64-
node.parent = idMap[node.parent];
42+
existingFilteredOut.forEach(pathObj => {
43+
accumulator[pathObj.path] = pathObj;
44+
});
45+
46+
return accumulator;
47+
}, {});
48+
}),
49+
50+
/**
51+
* Calculate data for file tree
52+
*/
53+
fileTreeData: computed('fileTreeHash', function() {
54+
const fileTreeHash = this.get('fileTreeHash');
55+
const fileTreeKeys = Object.keys(fileTreeHash);
56+
const fileTreeObjects = fileTreeKeys.map(key => fileTreeHash[key]);
57+
58+
return fileTreeObjects.map(treeObject => {
59+
const treeDataObject = {
60+
id: treeObject.path,
61+
text: treeObject.nodeName,
62+
parent: treeObject.parent,
63+
path: treeObject.path
64+
};
65+
66+
if(treeObject.isFile) {
67+
treeDataObject.leaf = true;
68+
treeDataObject.icon = 'glyphicon glyphicon-file light-gray';
69+
} else {
70+
treeDataObject.icon = 'glyphicon glyphicon-folder-open yellow';
6571
}
66-
});
6772

68-
return treeData;
73+
return treeDataObject;
74+
});
6975
}),
7076

7177
actions: {
@@ -77,7 +83,10 @@ export default Ember.Component.extend({
7783
this.get('jsTreeActionReceiver').send('toggleNode', node.id);
7884
},
7985

80-
handleReady() {
86+
didBecomeReady() {
87+
if(this.attrs.didBecomeReady) {
88+
this.attrs.didBecomeReady();
89+
}
8190
},
8291

8392
hideFileTree() {

app/gist/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export default Ember.Controller.extend({
206206
}
207207

208208
fileProperties.filePath = filePath;
209-
let file = this.store.createRecord('gistFile', fileProperties);
209+
let file = this.get('store').createRecord('gistFile', fileProperties);
210210

211211
this.get('model.files').pushObject(file);
212212
this.get('notify').info(`File ${file.get('filePath')} was added`);

app/gist/edit/route.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import GistRoute from "ember-twiddle/routes/gist-base-route";
33

44
export default GistRoute.extend({
55
model (params) {
6-
this.store.unloadAll('gistFile');
6+
this.get('store').unloadAll('gistFile');
77

8-
return this.store.find('gist', params.id);
8+
return this.get('store').find('gist', params.id);
99
},
1010

1111
setupController() {

app/gist/new/route.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ export default GistRoute.extend({
55
emberCli: Ember.inject.service('ember-cli'),
66

77
model (params) {
8-
var model = this.store.createRecord('gist', {description: 'New Twiddle'});
8+
var model = this.get('store').createRecord('gist', {description: 'New Twiddle'});
99

1010
if (params.copyCurrentTwiddle) {
11-
this.store.peekAll('gistFile').setEach('gist', model);
11+
this.get('store').peekAll('gistFile').setEach('gist', model);
1212
} else {
13-
this.store.unloadAll('gistFile');
13+
this.get('store').unloadAll('gistFile');
1414

1515
model.get('files').pushObject(this.get('emberCli').generate('controllers/application'));
1616
model.get('files').pushObject(this.get('emberCli').generate('templates/application'));

app/gist/route.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default Ember.Route.extend({
1717
deactivate () {
1818
var gist = this.controller.get('model');
1919
if (gist.get('isNew')) {
20-
this.store.unloadRecord(gist);
20+
this.get('store').unloadRecord(gist);
2121
}
2222
},
2323

app/resolver.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Resolver from 'ember-resolver';
2+
3+
export default Resolver;

app/services/dependency-resolver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Ember from 'ember';
22

3-
const EMBER_VERSIONS = ['2.2.0', '2.1.1', '2.0.2', '1.13.11', '1.12.1'];
4-
const EMBER_DATA_VERSIONS = ['2.3.0', '2.2.1', '2.1.0', '2.0.1', '1.13.15'];
3+
const EMBER_VERSIONS = ['2.3.0', '2.2.2', '2.1.2', '2.0.3', '1.13.13', '1.12.2'];
4+
const EMBER_DATA_VERSIONS = ['2.3.3', '2.2.1', '2.1.0', '2.0.1', '1.13.15'];
55

66
const VERSION_REGEX = /^\d+.\d+.\d+$/;
77

app/services/ember-cli.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import config from '../config/environment';
55
import Ember from 'ember';
66
import moment from 'moment';
77

8+
const { inject } = Ember;
89
const twiddleAppName = 'demo-app';
910

1011
// These files will be included if not present
1112
const boilerPlateJs = [
1213
'app',
1314
'router',
1415
'initializers/router',
15-
'initializers/mouse-events'
16+
'initializers/mouse-events',
17+
'resolver'
1618
];
1719

1820
// These files have to be present
@@ -84,6 +86,10 @@ const availableBlueprints = {
8486
'twiddle.json': {
8587
blueprint: 'twiddle.json',
8688
filePath: 'twiddle.json'
89+
},
90+
'resolver': {
91+
blueprint: 'resolver',
92+
filePath: 'resolver.js'
8793
}
8894
};
8995

@@ -101,15 +107,11 @@ const requiredDependencies = [
101107
* source code at https://github.com/ember-cli/ember-cli
102108
*/
103109
export default Ember.Service.extend({
104-
dependencyResolver: Ember.inject.service(),
105-
106-
init (...args) {
107-
this._super(...args);
108-
this.set('store', this.container.lookup("service:store"));
109-
},
110+
dependencyResolver: inject.service(),
111+
store: inject.service(),
110112

111113
generate(type) {
112-
return this.store.createRecord('gistFile', this.buildProperties(type));
114+
return this.get('store').createRecord('gistFile', this.buildProperties(type));
113115
},
114116

115117
buildProperties(type, replacements) {
@@ -218,6 +220,7 @@ export default Ember.Service.extend({
218220

219221
let EmberENV = twiddleJSON.EmberENV || {};
220222
depScriptTags += `<script type="text/javascript">EmberENV = ${JSON.stringify(EmberENV)};</script>`;
223+
depScriptTags += `<script type="text/javascript" src="${config.assetsHost}assets/loader.js?${config.APP.version}"></script>`;
221224

222225
Object.keys(deps).forEach(function(depKey) {
223226
let dep = deps[depKey];
@@ -264,7 +267,7 @@ export default Ember.Service.extend({
264267
requiredFiles.forEach(filePath => {
265268
var file = gist.get('files').findBy('filePath', filePath);
266269
if(!file) {
267-
gist.get('files').pushObject(this.store.createRecord('gistFile', {
270+
gist.get('files').pushObject(this.get('store').createRecord('gistFile', {
268271
filePath: filePath,
269272
content: blueprints[filePath]
270273
}));

app/templates/components/file-tree.hbs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
</div>
1818
{{ember-jstree data=fileTreeData
1919
actionReceiver=jsTreeActionReceiver
20-
eventDidSelectNode="handleSelectTreeNode"
21-
}}
20+
eventDidSelectNode=(action "handleSelectTreeNode")
21+
eventDidBecomeReady=(action "didBecomeReady")
22+
}}

0 commit comments

Comments
 (0)