-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
400 lines (304 loc) · 13.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<!DOCTYPE html>
<html><head>
<meta http-equiv='X-UA-Compatible' content='IE=edge' />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>MindMill openCMIS Client</title>
<script id='sap-ui-bootstrap'
src="resources/sap-ui-core.js"
data-sap-ui-theme='sap_bluecrystal'
data-sap-ui-libs='sap.ui.commons,sap.ui.ux3,sap.ui.table,sap.ui.demokit'></script>
<!-- CMIS Library -->
<script src="resources/mindmill/cmis.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.15.0.css">
<link rel="stylesheet" href="css/prettyprint.css">
<script>
/***************************************************
CMIS Explorer Panel
***************************************************/
var oPanelCMIS = new sap.ui.commons.Panel().setText('CMIS Browser');
oPanelCMIS.placeAt("uiArea");
//create a horizontal Splitter
var oSplitterV = new sap.ui.commons.Splitter("splitterV");
oSplitterV.setSplitterOrientation(sap.ui.commons.Orientation.vertical);
oSplitterV.setSplitterPosition("20%");
oSplitterV.setMinSizeFirstPane("20%");
oSplitterV.setMinSizeSecondPane("30%");
oSplitterV.setWidth("100%");
oSplitterV.setHeight("100%");
//adding Labels to both panes
//var oLabel1 = new sap.ui.commons.Label({text: "Directory"});
//oSplitterV.addFirstPaneContent(oLabel1);
//var oLabel2 = new sap.ui.commons.Label({text: "Second Pane"});
//oSplitterV.addSecondPaneContent(oLabel2);
oPanelCMIS.addContent(oSplitterV);
/******** LEFT PANEL ***************/
//create the Tree control
var oTree = new sap.ui.commons.Tree("tree", {select:onNodeSelect});
oTree.setShowHeader(false);
oTree.setTitle("MindMill CMIS Explorer");
oTree.setWidth("100%");
oTree.setHeight("800px");
oTree.setShowHeaderIcons(true);
oTree.setShowHorizontalScrollbar(true);
//create Tree Nodes
var filePath = "/user/admin";
var pathSuffix;
var imageLocation = "https://sapui5.hana.ondemand.com/sdk/test-resources/sap/ui/commons/demokit/";
var oNode1 = new sap.ui.commons.TreeNode("node1", {text:"CMIS Cluster", icon:imageLocation + "images/system.gif", expanded: true});
var oNode2 = new sap.ui.commons.TreeNode("node2", {text:"CMIS" + filePath, icon:imageLocation + "images/disk.gif", expanded: true, isSelected: true});
//var oNode3 = new sap.ui.commons.TreeNode("node3", {text:"Program Files", icon:imageLocation + "images/folder.gif"});
//var oNode4 = new sap.ui.commons.TreeNode("node4", {text:"Windows", icon: imageLocation + "images/folder.gif"});
jQuery.sap.require("sap.ui.core.IconPool");
//var aNames = sap.ui.core.IconPool.getIconNames();
fileIcon = new sap.ui.core.Icon( {
src : "sap-icon://document-text"
});
var nodesJSON= {};
var currentNode ={};
//Default path and directory
currentNode.path = '/user';
currentNode.dirname = 'admin';
currentNode.parentNode = '';
nodesJSON['node2'] = currentNode ;
oNode1.addNode(oNode2);
//add Tree Node root to the Tree
oTree.addNode(oNode1);
//oTree.placeAt("uiArea");
oSplitterV.addFirstPaneContent(oTree);
var directoryListing = {};
function onNodesAdd (currentNode){
files = [{"file":"aaa"},{"file":"bbb"},{"file":"bbb"}];
files = directoryListing.body.FileStatuses.FileStatus;
for(var row in files) {
if (files[row].type === "DIRECTORY") {
var newNodeId = currentNode.getId() + "_"+ row
var newNode = {};
newNode.path = nodesJSON[currentNode.getId()].path + "/" + nodesJSON[currentNode.getId()].dirname;
newNode.dirname = files[row].pathSuffix; //.file;
newNode.parentNode = currentNode.getId();
nodesJSON[newNodeId] = newNode ;
var varNode = new sap.ui.commons.TreeNode(newNodeId, {text:files[row].pathSuffix, icon: imageLocation + "images/folder.gif", expanded: true});
currentNode.addNode(varNode);
}
}
}
/******** RIGHT PANEL ***************/
var oModelCMIS = new sap.ui.model.json.JSONModel();
oTableCMIS = new sap.ui.table.Table("CMISDirectoy",{tableId: "CMISDir",
//visibleRowCount: 15,
//firstVisibleRow: 3,
visibleRowCountMode: sap.ui.table.VisibleRowCountMode.Auto,
rowSelectionChange: onRowSelect,
selectionMode: sap.ui.table.SelectionMode.Single,
selectionBehavior: sap.ui.table.SelectionBehavior.Row,
extension: [
new sap.ui.commons.Button({text: "Download", press: downloadSelected })
]
});
oTableCMIS.setModel(oModelCMIS);
//Table Column Definitions
fileIcon.bindProperty("src", {
path : "type",
//type : ofloatTwoDecimal, //conflicts with fomratter
formatter: function(cellValue) {
// do formatting here...
switch(cellValue) {
case "DIRECTORY":
cellValue = "sap-icon://folder-full"; //folder-blank
break;
default:
cellValue = "sap-icon://document-text";
}
return cellValue;
}
});
colGby = new sap.ui.table.Column({label: new sap.ui.commons.Label({text:"Type"}),
template: fileIcon, //new sap.ui.commons.TextView().bindProperty("text","type"),
width: "10%",
sortProperty: "type",
filterProperty: "type"
});
oTableCMIS.addColumn(colGby);
var colGby = new sap.ui.table.Column({label: new sap.ui.commons.Label({text:"Name"}),
template: new sap.ui.commons.TextView().bindProperty("text","pathSuffix"),
width: "45%",
sortProperty: "pathSuffix",
filterProperty: "pathSuffix"
});
oTableCMIS.addColumn(colGby);
// Float Format 2 decimals
var ofloatTwoDecimal = new sap.ui.model.type.Float({
minFractionDigits : 3,
maxFractionDigits : 3
}, {
maximum : 80
});
var oControl = new sap.ui.commons.TextView().bindProperty("text", {
path : "length",
//type : ofloatTwoDecimal, //conflicts with fomratter
formatter: function(cellValue) {
// do formatting here...
//NOT easy to refer to other columns
// but could do sub JSON http://scn.sap.com/thread/3180215
// Better to do in JSON source prior
if (cellValue == "") {
return "";
}
cellValue = Number(cellValue);
if ( cellValue > 0) {
cellValue = cellValue / 1024 ;
}
//else return cellValue;
var num = 5.56789;
var n = num.toFixed(2);
return Number(cellValue).toFixed(3);
}
});
oControl.setTextAlign("End");
colGby = new sap.ui.table.Column({label: new sap.ui.commons.Label({text:"Size Kb"}),
template: oControl,
width: "10%",
sortProperty: "length",
filterProperty: "length",
//hAlign: sap.ui.commons.layout.HAlign.End,
});
oTableCMIS.addColumn(colGby);
colGby = new sap.ui.table.Column({label: new sap.ui.commons.Label({text:"Date modified"}),
template: new sap.ui.commons.TextView().bindProperty("text","modificationTime",function(cellValue) {
// do formatting here...
return new Date(cellValue);
}),
width: "35%",
sortProperty: "modificationTime",
filterProperty: "modificationTime"
});
oTableCMIS.addColumn(colGby);
//Initially sort the table
var sortCMIS = new sap.ui.model.Sorter("pathSuffix");
oTableCMIS.bindRows("/body/FileStatuses/FileStatus",sortCMIS); // /body/Row/0
oTableCMIS.sort("pathSuffix");
oTableCMIS.setEditable(false);
//Add Layout to CMIS Panel
//oPanelCMIS.addContent(oTableCMIS);
oSplitterV.addSecondPaneContent(oTableCMIS);
/******** Initialise dataset ***************/
onDirList(currentNode.path + "/" + currentNode.dirname, oNode2);
/***************************************************
ON Download Select
***************************************************/
//function() { alert("Button pressed!"); }
function downloadSelected (){
var downloadFile = "webCMIS.xsjs?path=" + filePath + "/" + pathSuffix + "&op=OPEN";
var data;
jQuery.ajax({
url: downloadFile,
method: 'GET',
async: true, // Switch off ASync
success: function(collection) {getData(collection);} ,
error: function(xhr, textStatus, errorThrown) {return;} });
function getData(collection) {
data = collection.body;
var downloadLink = document.createElement("a");
downloadLink.href = "data:application/octet-stream;content-disposition:attachment;filename=file.txt," + escape(collection); //"webCMIS.xsjs?path=/user/admin/archivesmall.csv&op=OPEN";
downloadLink.download = pathSuffix; //"archivesmall.csv";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
return collection;
}
}
/***************************************************
ON NODE Select
***************************************************/
function onNodeSelect (oEvent){
var vNode = oEvent.getParameter("node");
//var Col1 = oContext.getProperty("nodeContext");
var vPath = nodesJSON[vNode.getId()].path + "/" + nodesJSON[vNode.getId()].dirname ;
onDirList(vPath, vNode);
filePath = vPath;
}
/***************************************************
ON ROW SELECT
***************************************************/
function onRowSelect (oEvent){
var oContext = oEvent.getParameter("rowContext");
pathSuffix = oContext.getProperty("pathSuffix");
}
/***************************************************
ON DIRECTORY LISTING
***************************************************/
function onDirList (path, node){
var session;
session = cmis.createSession($("input[name='serverUrl']").val());
session.setCredentials($("input[name='username']").val(), $("input[name='password']").val()).loadRepositories({
request : {
success : function(data) {
library.displayResult("CMIS Connexion", data);
ok(true, "Successful connexion!");
start();
testSuite();
},
error : function(e) {
if (e.responseJSON)
ok(false, "Error during the request: " + e.responseJSON.message);
else
ok(false, "Error during the request: " + e.statusText);
start();
}
}
});
}
/*
jQuery.ajax({
url: "webCMIS.xsjs?path=" + path ,
method: 'GET',
dataType: 'json',
//data: path,
async: false, // Switch of ASync
//success: appendDirectory, //(data, textStatus, jqXHR),
success: function(collection) {
appendDirectory(collection, node);
},
error: function(xhr, textStatus, errorThrown) {return;} });
}
function appendDirectory(collection,node) {
directoryListing = collection;
onNodesAdd (node);
oModelCMIS.setData(collection);
}
*/
</script>
</head>
<body class='sapUiBody'>
<div id="params">
<h1>Configuration</h1>
<table>
<tr>
<td class="param-key">Server URL:</td>
<td class="param-value"><input type="text" name="serverUrl"
autocomplete="off"
value="http://schlagmich.net:8080/browser"></input></td>
</tr>
<td class="param-key">Username:</td>
<td class="param-value"><input type="text" name="username"
value="test" autocomplete="off"></input></td>
</tr>
<tr>
<td class="param-key">Password:</td>
<td class="param-value"><input type="password" name="password"
value="test123" autocomplete="off"></input></td>
</tr>
<tr>
<td class="param-key">Test File:</td>
<td class="param-value"><input type="file" name="file"></input></td>
</tr>
<tr>
<tr>
<td><input type="button" id="start" value="Connect"
autocomplete="off" /></td>
</tr>
</table>
</div>
<div id="uiArea"></div>
</body>
</html>