Skip to content

Commit 146e98a

Browse files
committed
fixed #481
1 parent aa8684f commit 146e98a

File tree

5 files changed

+45
-43
lines changed

5 files changed

+45
-43
lines changed

quick-start/src/main/java/com/marklogic/quickstart/model/SearchPathModel.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
public class SearchPathModel {
1919

2020
public String name;
21-
public String path;
21+
public String relativePath;
22+
public String absolutePath;
2223

23-
public SearchPathModel(String path, String name) {
24-
this.path = path;
24+
public SearchPathModel(String name, String relativePath, String absolutePath) {
25+
this.relativePath = relativePath;
26+
this.absolutePath = absolutePath;
2527
this.name = name;
2628
}
2729
}

quick-start/src/main/java/com/marklogic/quickstart/web/UtilController.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,41 @@ public class UtilController extends EnvironmentAware {
3939

4040
@RequestMapping(value = "/searchPath", method = RequestMethod.GET)
4141
@ResponseBody
42-
public Map<String, Object> searchPath(@RequestParam String path, @RequestParam boolean absolute) {
42+
public Map<String, Object> searchPath(@RequestParam String path) {
4343
logger.debug("Search Path:" + path);
4444
List<SearchPathModel> paths = new ArrayList<>();
45-
String currentPath;
45+
Path currentPath = Paths.get(".").toAbsolutePath().normalize();
46+
Path relativePath;
4647

4748
if (path == null || path.length() == 0) {
48-
currentPath = "/";
49-
File[] roots = File.listRoots();
50-
for (File root : roots) {
51-
paths.add(new SearchPathModel(root.getAbsolutePath(), root.getAbsolutePath()));
52-
}
49+
relativePath = Paths.get("/");
5350
}
5451
else {
55-
if (absolute) {
56-
currentPath = Paths.get(path).toAbsolutePath().normalize().toString();
57-
}
58-
else {
59-
currentPath = path;
60-
}
61-
if (!path.equals("/")) {
62-
path = path + java.io.File.separator;
63-
Path parent = Paths.get(path).toAbsolutePath().normalize().getParent();
64-
if (parent != null) {
65-
paths.add(new SearchPathModel(parent.toString(), ".."));
66-
}
67-
}
52+
relativePath = Paths.get(path).toAbsolutePath().normalize();
53+
}
6854

69-
List<String> folders = FileUtil.listDirectFolders(new File(path));
70-
for (String folder : folders) {
71-
String absPath = Paths.get(path, folder).toAbsolutePath().normalize().toString();
72-
paths.add(new SearchPathModel(absPath, folder));
73-
}
74-
}
55+
Path parent = relativePath.getParent();
56+
if (parent != null) {
57+
String relativePathStr = currentPath.relativize(parent).toString();
58+
String absolutePathStr = parent.toAbsolutePath().toString();
59+
paths.add(new SearchPathModel("..", relativePathStr, absolutePathStr));
60+
}
61+
62+
List<String> folders = FileUtil.listDirectFolders(relativePath.toFile());
63+
for (String folder : folders) {
64+
Path childPath = relativePath.resolve(folder);
65+
String relativePathStr = currentPath.relativize(childPath).toString();
66+
String absolutePathStr = childPath.toAbsolutePath().normalize().toString();
67+
paths.add(new SearchPathModel(folder, relativePathStr, absolutePathStr));
68+
}
7569

7670
Map<String, Object> result = new HashMap<>();
77-
result.put("currentPath", currentPath);
71+
String relativePathStr = currentPath.relativize(relativePath).toString();
72+
if (relativePathStr.equals("")) {
73+
relativePathStr = ".";
74+
}
75+
result.put("currentPath", relativePathStr);
76+
result.put("currentAbsolutePath", relativePath.toString());
7877
result.put("folders", paths);
7978
return result;
8079
}

quick-start/src/main/ui/app/folder-browser/folder-browser.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class FolderBrowserComponent implements OnInit, OnChanges {
3131
}
3232

3333
ngOnChanges(changes: any) {
34-
if (changes.startPath) {
34+
if (changes.startPath && changes.startPath.currentValue) {
3535
this.getFolders(changes.startPath.currentValue);
3636
}
3737
}
@@ -45,12 +45,15 @@ export class FolderBrowserComponent implements OnInit, OnChanges {
4545
getFolders(path: string): void {
4646
if (path) {
4747
this.isLoading = true;
48-
this.http.get(`/api/utils/searchPath?path=${encodeURIComponent(path)}&absolute=${this.absoluteOnly}`)
48+
this.http.get(`/api/utils/searchPath?path=${encodeURIComponent(path)}`)
4949
.map(this.extractData)
5050
.subscribe(resp => {
5151
this.folders = resp.folders;
52-
this.currentPath = resp.currentPath;
53-
this.folderChosen.emit(this.currentPath);
52+
this.currentPath = this.absoluteOnly ? resp.currentAbsolutePath : resp.currentPath;
53+
this.folderChosen.emit({
54+
relativePath: resp.currentPath,
55+
absolutePath: resp.currentAbsolutePath
56+
});
5457
},
5558
error => {
5659
console.log(error);
@@ -62,7 +65,7 @@ export class FolderBrowserComponent implements OnInit, OnChanges {
6265
}
6366

6467
entryClicked(entry: any): void {
65-
this.getFolders(entry.path);
68+
this.getFolders(entry.absolutePath);
6669
}
6770

6871
private extractData(res: Response) {

quick-start/src/main/ui/app/login/login.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ export class LoginComponent implements OnInit {
161161
this.router.navigate(['']);
162162
}
163163

164-
folderClicked(folder: string): void {
165-
this.folder = folder;
164+
folderClicked(folders: any): void {
165+
this.folder = folders.absolutePath;
166166
}
167167

168168
back() {

quick-start/src/main/ui/app/mlcp-ui/mlcp-ui.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface MlcpOptions {
2626
styleUrls: ['./mlcp-ui.component.scss']
2727
})
2828
export class MlcpUiComponent implements OnChanges {
29-
startPath: string = '.';
29+
startPath: string;
3030
inputFilePath: string;
3131
mlcp = <MlcpOptions>{};
3232

@@ -528,11 +528,9 @@ export class MlcpUiComponent implements OnChanges {
528528
return `${this.inputFilePath.replace(/\\/g, '/').replace(/^([A-Za-z]):/, '/$1:')},''`;
529529
}
530530

531-
folderClicked(folder: string): void {
532-
if (!this.inputFilePath) {
533-
this.inputFilePath = folder;
534-
} else if (this.inputFilePath !== folder) {
535-
this.inputFilePath = folder;
531+
folderClicked(folders: any): void {
532+
if (this.inputFilePath !== folders.absolutePath) {
533+
this.inputFilePath = folders.absolutePath;
536534
// update the outputUriReplace options
537535
let generalGroup = _.find(this.groups, (group: any) => {
538536
return group.category === 'General Options';

0 commit comments

Comments
 (0)