Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit 47e16da

Browse files
Cristian TraversoRoberto Ciccone
authored andcommitted
Fix DESIGNER-1845
1 parent ae19069 commit 47e16da

10 files changed

Lines changed: 62597 additions & 51989 deletions

app/scripts/services/raml-repository.js

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
return file.path.slice(-5) !== '.meta';
3838
}
3939

40+
function metaFile(file) {
41+
return file.path.slice(-5) === '.meta';
42+
}
43+
4044
function handleErrorFor(file) {
4145
return function markFileWithError(error) {
4246
file.error = error;
@@ -144,15 +148,20 @@
144148
separated[entry.type || 'file'].push(entry);
145149
});
146150

147-
var files = separated.file.filter(notMetaFile).map(function (file) {
151+
var createRamlFile = function (file) {
148152
return new RamlFile(file.path, file.contents, { dirty: false, persisted: true, root: file.root} );
149-
});
153+
};
154+
155+
var files = separated.file.filter(notMetaFile).map(createRamlFile);
156+
157+
var metaFiles = separated.file.filter(metaFile).map(createRamlFile);
150158

151159
var directories = separated.folder.map(function (directory) {
152160
return new RamlDirectory(directory.path, directory.meta, directory.children);
153161
});
154162

155163
this.children = directories.concat(files).sort(sortingFunction);
164+
this.metaChildren = directories.concat(metaFiles).sort(sortingFunction);
156165
}
157166

158167
RamlDirectory.prototype.getDirectories = function getDirectories() {
@@ -163,6 +172,10 @@
163172
return this.children.filter(function(t) { return !t.isDirectory; });
164173
};
165174

175+
RamlDirectory.prototype.getMetaFiles = function getMetaFiles() {
176+
return this.metaChildren.filter(function(t) { return !t.isDirectory; });
177+
};
178+
166179
RamlDirectory.prototype.forEachChildDo = function forEachChildDo(action) {
167180
// BFS
168181
var queue = this.children.slice();
@@ -179,6 +192,22 @@
179192
}
180193
};
181194

195+
RamlDirectory.prototype.forEachMetaChildDo = function forEachMetaChildDo(action) {
196+
// BFS
197+
var queue = this.metaChildren.slice();
198+
var current;
199+
200+
while (queue.length > 0) {
201+
current = queue.shift();
202+
203+
if (current.isDirectory) {
204+
queue = queue.concat(current.metaChildren);
205+
}
206+
207+
action.call(current, current);
208+
}
209+
};
210+
182211
RamlDirectory.prototype.sortChildren = function sortChildren() {
183212
this.children.sort(sortingFunction);
184213
};
@@ -249,6 +278,7 @@
249278
var promises = [];
250279
directory.getDirectories().forEach(function(dir) { promises.push(service.removeDirectory(dir)); });
251280
directory.getFiles().forEach(function(file) { promises.push(service.removeFile(file)); });
281+
directory.getMetaFiles().forEach(function(file) { promises.push(service.removeFile(file)); });
252282

253283
// remove this directory object from parent's children list
254284
var parent = service.getParent(directory);
@@ -353,10 +383,18 @@
353383
.then(modifyFile, handleErrorFor(file))
354384
.then(function () {
355385
// remove the file object from the parent's children list
356-
var index = parent.children.indexOf(file);
386+
if (notMetaFile(file)) {
387+
var index = parent.children.indexOf(file);
357388

358-
if (index !== -1) {
359-
parent.children.splice(index, 1);
389+
if (index !== -1) {
390+
parent.children.splice(index, 1);
391+
}
392+
} else {
393+
var metaIndex = parent.metaChildren.indexOf(file);
394+
395+
if (metaIndex !== -1) {
396+
parent.metaChildren.splice(metaIndex, 1);
397+
}
360398
}
361399

362400
$rootScope.$broadcast('event:raml-editor-file-removed', file);
@@ -458,7 +496,13 @@
458496
target.forEachChildDo(function(c) {
459497
c.path = c.path.replace(target.path, newPath);
460498
});
499+
500+
// renames the path of each meta child under the current directory
501+
target.forEachMetaChildDo(function(c) {
502+
c.path = c.path.replace(target.path, newPath);
503+
});
461504
} else {
505+
service.moveMeta(target, destination);
462506
promise = target.persisted ? fileSystem.rename(target.path, newPath) : $q.when(target);
463507
}
464508

@@ -475,6 +519,8 @@
475519
var metaFile = new RamlFile(file.path + '.meta', JSON.stringify(meta));
476520
return service.saveFile(metaFile)
477521
.then(function () {
522+
var parent = service.getParent(metaFile);
523+
parent.metaChildren.push(metaFile);
478524
return meta;
479525
})
480526
;
@@ -493,6 +539,35 @@
493539
);
494540
};
495541

542+
service.moveMeta = function moveMeta(file, destination) {
543+
var metaName = file.name + '.meta';
544+
var newMetaPath = service.join(destination.path, metaName);
545+
var metaPathName = file.path + '.meta';
546+
var oldParent = service.getParent(file);
547+
548+
var metaFile = oldParent.metaChildren.find(function(meta) {
549+
return meta.path === metaPathName;
550+
});
551+
552+
if (metaFile) {
553+
return fileSystem.rename(metaFile.path, newMetaPath).then(
554+
function success() {
555+
//Remove old parent meta data
556+
var index = oldParent.metaChildren.indexOf(metaFile);
557+
if (index !== -1) {
558+
oldParent.metaChildren.splice(index, 1);
559+
}
560+
metaFile.path = newMetaPath;
561+
destination.metaChildren.push(metaFile);
562+
return metaFile;
563+
},
564+
function failure() {
565+
return metaFile;
566+
}
567+
);
568+
}
569+
};
570+
496571
service.join = function () {
497572
return Array.prototype.reduce.call(arguments, function (path, segment) {
498573
if (segment == null) {

dist/scripts/api-designer-parser.js

Lines changed: 73 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/scripts/api-designer-parser.min.js

Lines changed: 57 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/scripts/api-designer-vendor.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51857,7 +51857,7 @@ Renderer.prototype.link = function(href, title, text) {
5185751857
} catch (e) {
5185851858
return '';
5185951859
}
51860-
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
51860+
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
5186151861
return '';
5186251862
}
5186351863
}
@@ -84015,6 +84015,10 @@ exports.javascript = require('./javascript');
8401584015
};
8401684016

8401784017
function getRequest($event) {
84018+
if (!validateForm($scope.form)) {
84019+
return;
84020+
}
84021+
8401884022
var url;
8401984023
var context = $scope.context;
8402084024
var segmentContexts = resolveSegmentContexts($scope.resource.pathSegments, $scope.context.uriParameters.data());

dist/scripts/api-designer-vendor.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)