|
7 | 7 | this.apiMiddleware = new ApiMiddleware(); |
8 | 8 | this.requesting = false; |
9 | 9 | this.fileList = []; |
10 | | - this.currentPath = []; |
| 10 | + this.currentPath = this.getBasePath(); |
11 | 11 | this.history = []; |
12 | 12 | this.error = ''; |
13 | 13 |
|
14 | 14 | this.onRefresh = function() {}; |
15 | 15 | }; |
16 | 16 |
|
| 17 | + FileNavigator.prototype.getBasePath = function() { |
| 18 | + var path = (fileManagerConfig.basePath || '').replace(/^\//, ''); |
| 19 | + return path.trim() ? path.split('/') : []; |
| 20 | + }; |
| 21 | + |
17 | 22 | FileNavigator.prototype.deferredHandler = function(data, deferred, code, defaultMsg) { |
18 | 23 | if (!data || typeof data !== 'object') { |
19 | 24 | this.error = 'Error %s - Bridge response error, please check the API docs or this ajax response.'.replace('%s', code); |
|
22 | 27 | this.error = 'Error 404 - Backend bridge is not working, please check the ajax response.'; |
23 | 28 | } |
24 | 29 | if (code == 200) { |
25 | | - this.error = ''; |
| 30 | + this.error = null; |
26 | 31 | } |
27 | 32 | if (!this.error && data.result && data.result.error) { |
28 | 33 | this.error = data.result.error; |
|
46 | 51 | FileNavigator.prototype.refresh = function() { |
47 | 52 | var self = this; |
48 | 53 | if (! self.currentPath.length) { |
49 | | - self.currentPath = fileManagerConfig.basePath || []; |
| 54 | + self.currentPath = this.getBasePath(); |
50 | 55 | } |
51 | 56 | var path = self.currentPath.join('/'); |
52 | 57 | self.requesting = true; |
|
67 | 72 |
|
68 | 73 | function recursive(parent, item, path) { |
69 | 74 | var absName = path ? (path + '/' + item.model.name) : item.model.name; |
70 | | - if (parent.name.trim() && path.trim().indexOf(parent.name) !== 0) { |
| 75 | + if (parent.name && parent.name.trim() && path.trim().indexOf(parent.name) !== 0) { |
71 | 76 | parent.nodes = []; |
72 | 77 | } |
73 | 78 | if (parent.name !== path) { |
|
102 | 107 | } |
103 | 108 |
|
104 | 109 | //!this.history.length && this.history.push({name: '', nodes: []}); |
105 | | - !this.history.length && this.history.push({ name: fileManagerConfig.basePath ? fileManagerConfig.basePath[0] : '', nodes: [] }); |
| 110 | + !this.history.length && this.history.push({ name: this.getBasePath()[0] || '', nodes: [] }); |
106 | 111 | flatten(this.history[0], flatNodes); |
107 | 112 | selectedNode = findNode(flatNodes, path); |
108 | 113 | selectedNode && (selectedNode.nodes = []); |
|
135 | 140 |
|
136 | 141 | FileNavigator.prototype.fileNameExists = function(fileName) { |
137 | 142 | return this.fileList.find(function(item) { |
138 | | - return fileName.trim && item.model.name.trim() === fileName.trim(); |
| 143 | + return fileName && item.model.name.trim() === fileName.trim(); |
139 | 144 | }); |
140 | 145 | }; |
141 | 146 |
|
|
145 | 150 | }); |
146 | 151 | }; |
147 | 152 |
|
| 153 | + FileNavigator.prototype.getCurrentFolderName = function() { |
| 154 | + return this.currentPath.slice(-1)[0] || '/'; |
| 155 | + }; |
| 156 | + |
148 | 157 | return FileNavigator; |
149 | 158 | }]); |
150 | 159 | })(angular); |
0 commit comments