Revision 611de529
b/src/gr/grnet/pithos/web/client/FileContextMenu.java | ||
---|---|---|
218 | 218 |
// sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1)); |
219 | 219 |
// contextMenu.addItem(sharingItem); |
220 | 220 |
if (!selectedFolder.isInTrash()) { |
221 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, images, 0))); |
|
221 |
if (selectedFiles.size() == 1) |
|
222 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, images, 0))); |
|
222 | 223 |
|
223 | 224 |
if (!selectedFiles.isEmpty()) |
224 | 225 |
contextMenu.addItem(new MenuItem("<span><a class='hidden-link' href='" + app.getApiPath() + app.getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + app.getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, (Command) null)); |
b/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java | ||
---|---|---|
35 | 35 |
package gr.grnet.pithos.web.client; |
36 | 36 |
|
37 | 37 |
import gr.grnet.pithos.web.client.foldertree.File; |
38 |
import gr.grnet.pithos.web.client.foldertree.FileVersions; |
|
38 | 39 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
40 |
import gr.grnet.pithos.web.client.foldertree.Version; |
|
41 |
import gr.grnet.pithos.web.client.rest.GetRequest; |
|
39 | 42 |
import gr.grnet.pithos.web.client.rest.PostRequest; |
40 | 43 |
import gr.grnet.pithos.web.client.rest.PutRequest; |
44 |
import gr.grnet.pithos.web.client.rest.RestException; |
|
41 | 45 |
import gr.grnet.pithos.web.client.tagtree.Tag; |
42 | 46 |
|
47 |
import java.util.List; |
|
43 | 48 |
import java.util.Map; |
44 | 49 |
|
45 | 50 |
import com.google.gwt.core.client.GWT; |
46 | 51 |
import com.google.gwt.core.client.Scheduler; |
47 | 52 |
import com.google.gwt.event.dom.client.ClickEvent; |
48 | 53 |
import com.google.gwt.event.dom.client.ClickHandler; |
54 |
import com.google.gwt.event.logical.shared.SelectionEvent; |
|
55 |
import com.google.gwt.event.logical.shared.SelectionHandler; |
|
49 | 56 |
import com.google.gwt.i18n.client.DateTimeFormat; |
50 | 57 |
import com.google.gwt.resources.client.ImageResource; |
51 | 58 |
import com.google.gwt.user.client.Window; |
... | ... | |
125 | 132 |
|
126 | 133 |
inner.add(createSharingPanel(), "Sharing"); |
127 | 134 |
|
128 |
inner.add(createVersionPanel(), "Versions");
|
|
129 |
|
|
135 |
fetchVersions();
|
|
136 |
|
|
130 | 137 |
inner.selectTab(0); |
131 | 138 |
|
132 | 139 |
outer.add(inner); |
... | ... | |
165 | 172 |
setWidget(outer); |
166 | 173 |
} |
167 | 174 |
|
168 |
private VerticalPanel createGeneralPanel() { |
|
175 |
protected void fetchVersions() { |
|
176 |
String path = file.getUri() + "?format=json&version=list"; |
|
177 |
GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwner(), path) { |
|
178 |
|
|
179 |
@Override |
|
180 |
public void onSuccess(FileVersions _result) { |
|
181 |
inner.add(createVersionPanel(_result.getVersions()), "Versions"); |
|
182 |
} |
|
183 |
|
|
184 |
@Override |
|
185 |
public void onError(Throwable t) { |
|
186 |
if (t instanceof RestException) { |
|
187 |
app.displayError("Unable to fetch versions: " + ((RestException) t).getHttpStatusText()); |
|
188 |
} |
|
189 |
else |
|
190 |
app.displayError("System error unable to fetch versions: "+t.getMessage()); |
|
191 |
} |
|
192 |
}; |
|
193 |
getVersions.setHeader("X-Auth-Token", app.getToken()); |
|
194 |
Scheduler.get().scheduleDeferred(getVersions); |
|
195 |
} |
|
196 |
|
|
197 |
private VerticalPanel createGeneralPanel() { |
|
169 | 198 |
final VerticalPanel generalPanel = new VerticalPanel(); |
170 | 199 |
final FlexTable generalTable = new FlexTable(); |
171 | 200 |
generalTable.setText(0, 0, "Name"); |
... | ... | |
331 | 360 |
return permPanel; |
332 | 361 |
} |
333 | 362 |
|
334 |
private VerticalPanel createVersionPanel() { |
|
363 |
private VerticalPanel createVersionPanel(List<Version> versions) {
|
|
335 | 364 |
VerticalPanel versionPanel = new VerticalPanel(); |
336 |
|
|
337 |
// VersionsList verList = new VersionsList(this, images, bodies); |
|
338 |
// versionPanel.add(verList); |
|
339 |
// |
|
340 |
// HorizontalPanel vPanel = new HorizontalPanel(); |
|
341 |
// |
|
342 |
// vPanel.setSpacing(8); |
|
343 |
// vPanel.addStyleName("pithos-TabPanelBottom"); |
|
344 |
// vPanel.add(new Label("Versioned")); |
|
345 |
// |
|
346 |
// versioned.setValue(file.isVersioned()); |
|
347 |
// vPanel.add(versioned); |
|
348 |
// versionPanel.add(vPanel); |
|
349 |
// |
|
350 |
// HorizontalPanel vPanel2 = new HorizontalPanel(); |
|
351 |
// vPanel2.setSpacing(8); |
|
352 |
// vPanel2.addStyleName("pithos-TabPanelBottom"); |
|
353 |
// |
|
354 |
// HTML removeAllVersion = new HTML("<span>Remove all previous versions?</span>"); |
|
355 |
// vPanel2.add(removeAllVersion); |
|
356 |
// |
|
357 |
// Button removeVersionsButton = new Button(AbstractImagePrototype.create(images.delete()).getHTML(), new ClickHandler() { |
|
358 |
// @Override |
|
359 |
// public void onClick(ClickEvent event) { |
|
360 |
// ConfirmationDialog confirm = new ConfirmationDialog("Really " + |
|
361 |
// "remove all previous versions?", "Remove") { |
|
362 |
// |
|
363 |
// @Override |
|
364 |
// public void cancel() { |
|
365 |
// } |
|
366 |
// |
|
367 |
// @Override |
|
368 |
// public void confirm() { |
|
369 |
// FilePropertiesDialog.this.closeDialog(); |
|
370 |
// removeAllOldVersions(); |
|
371 |
// } |
|
372 |
// |
|
373 |
// }; |
|
374 |
// confirm.center(); |
|
375 |
// } |
|
376 |
// |
|
377 |
// }); |
|
378 |
// vPanel2.add(removeVersionsButton); |
|
379 |
// if(!file.isVersioned()) |
|
380 |
// vPanel2.setVisible(false); |
|
381 |
// |
|
382 |
// versionPanel.add(vPanel2); |
|
383 |
|
|
365 |
VersionsList verList = new VersionsList(app, this, images, file, versions); |
|
366 |
versionPanel.add(verList); |
|
384 | 367 |
return versionPanel; |
385 | 368 |
} |
386 | 369 |
|
b/src/gr/grnet/pithos/web/client/FilesPropertiesDialog.java | ||
---|---|---|
70 | 70 |
super(_app); |
71 | 71 |
|
72 | 72 |
files = _files; |
73 |
// int versionedNum = 0; |
|
74 |
// for (File fr : files) |
|
75 |
// if (fr.isVersioned()) versionedNum++; |
|
76 |
// Boolean versioned = null; |
|
77 |
// if (versionedNum == 0) |
|
78 |
// versioned = false; |
|
79 |
// if (versionedNum == files.size()) |
|
80 |
// versioned = true; |
|
81 |
|
|
82 |
// initialVersioned = versioned; |
|
83 |
// versionedCheck = new TristateCheckBox(versioned); |
|
84 | 73 |
|
85 | 74 |
// Set the dialog's caption. |
86 | 75 |
setText("Files properties"); |
... | ... | |
94 | 83 |
|
95 | 84 |
inner.add(createGeneralPanel(), "General"); |
96 | 85 |
|
97 |
final VerticalPanel verPanel = new VerticalPanel(); |
|
98 |
|
|
99 |
// final HorizontalPanel vPanel = new HorizontalPanel(); |
|
100 |
// vPanel.setSpacing(8); |
|
101 |
// vPanel.addStyleName("pithos-TabPanelBottom"); |
|
102 |
// vPanel.add(new Label("Versioned")); |
|
103 |
// vPanel.add(versionedCheck); |
|
104 |
// |
|
105 |
// verPanel.add(vPanel); |
|
106 |
|
|
107 |
inner.add(verPanel, "Versions"); |
|
108 | 86 |
inner.selectTab(0); |
109 | 87 |
outer.add(inner); |
110 | 88 |
|
... | ... | |
153 | 131 |
else |
154 | 132 |
generalTable.setText(1, 1, "-"); |
155 | 133 |
|
156 |
// Find if tags are identical |
|
157 |
// List<String> tagsList = files.get(0).getTags(); |
|
158 |
// List<String> tagss; |
|
159 |
// for (int i=1; i<files.size(); i++) { |
|
160 |
// tagss = files.get(i).getTags(); |
|
161 |
// if (tagsList.size() != tagss.size() || !tagsList.containsAll(tagss)) { |
|
162 |
// tagsList = null; |
|
163 |
// break; |
|
164 |
// } |
|
165 |
// } |
|
166 |
// // Get the tags. |
|
167 |
// StringBuffer tagsBuffer = new StringBuffer(); |
|
168 |
// if (tagsList==null) |
|
169 |
// tagsBuffer.append(MULTIPLE_VALUES_TEXT); |
|
170 |
// else { |
|
171 |
// Iterator i = tagsList.iterator(); |
|
172 |
// while (i.hasNext()) { |
|
173 |
// String tag = (String) i.next(); |
|
174 |
// tagsBuffer.append(tag).append(", "); |
|
175 |
// } |
|
176 |
// if (tagsBuffer.length() > 1) |
|
177 |
// tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1); |
|
178 |
// } |
|
179 |
// initialTagText = tagsBuffer.toString(); |
|
180 |
// tags.setText(initialTagText); |
|
181 |
// tags.addFocusHandler(new FocusHandler() { |
|
182 |
// @Override |
|
183 |
// public void onFocus(FocusEvent event) { |
|
184 |
// if (MULTIPLE_VALUES_TEXT.equals(tags.getText())) |
|
185 |
// tags.setText(""); |
|
186 |
// } |
|
187 |
// } |
|
188 |
// ); |
|
189 |
// |
|
190 |
// generalTable.setWidget(2, 1, tags); |
|
191 | 134 |
generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
192 | 135 |
generalTable.getFlexCellFormatter().setColSpan(0, 0, 2); |
193 | 136 |
generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); |
... | ... | |
199 | 142 |
|
200 | 143 |
generalPanel.add(generalTable); |
201 | 144 |
|
202 |
// Asynchronously retrieve the tags defined by this user. |
|
203 |
// DeferredCommand.addCommand(new Command() { |
|
204 |
// |
|
205 |
// @Override |
|
206 |
// public void execute() { |
|
207 |
// updateTags(); |
|
208 |
// } |
|
209 |
// }); |
|
210 |
|
|
211 | 145 |
DisclosurePanel allTags = new DisclosurePanel("All tags"); |
212 | 146 |
allTagsContent = new FlowPanel(); |
213 | 147 |
allTags.setContent(allTagsContent); |
... | ... | |
223 | 157 |
*/ |
224 | 158 |
@Override |
225 | 159 |
protected void accept() { |
226 |
// JSONObject json = new JSONObject(); |
|
227 |
// if ( versionedCheck.getState()!=null && !versionedCheck.getState().equals(initialVersioned) ) |
|
228 |
// json.put("versioned", JSONBoolean.getInstance(versionedCheck.getState())); |
|
229 |
// |
|
230 |
// JSONArray taga = new JSONArray(); |
|
231 |
// int i = 0; |
|
232 |
// String tagText = tags.getText(); |
|
233 |
// if (!MULTIPLE_VALUES_TEXT.equals(tagText) && !initialTagText.equals(tagText)) { |
|
234 |
// String[] tagset = tagText.split(","); |
|
235 |
// for (String t : tagset) { |
|
236 |
// JSONString to = new JSONString(t); |
|
237 |
// taga.set(i, to); |
|
238 |
// i++; |
|
239 |
// } |
|
240 |
// json.put("tags", taga); |
|
241 |
// } |
|
242 |
// String jsonString = json.toString(); |
|
243 |
// if(jsonString.equals("{}")){ |
|
244 |
// GWT.log("NO CHANGES", null); |
|
245 |
// return; |
|
246 |
// } |
|
247 |
// final List<String> fileIds = new ArrayList<String>(); |
|
248 |
// for(FileResource f : files) |
|
249 |
// fileIds.add(f.getUri()+"?update="); |
|
250 |
// MultiplePostCommand rt = new MultiplePostCommand(fileIds.toArray(new String[0]), jsonString, 200){ |
|
251 |
// |
|
252 |
// @Override |
|
253 |
// public void onComplete() { |
|
254 |
// app.getTreeView().refreshCurrentNode(false); |
|
255 |
// } |
|
256 |
// |
|
257 |
// @Override |
|
258 |
// public void onError(String p, Throwable t) { |
|
259 |
// GWT.log("", t); |
|
260 |
// if(t instanceof RestException){ |
|
261 |
// int statusCode = ((RestException)t).getHttpStatusCode(); |
|
262 |
// if(statusCode == 405) |
|
263 |
// app.displayError("You don't have the necessary permissions"); |
|
264 |
// else if(statusCode == 404) |
|
265 |
// app.displayError("File does not exist"); |
|
266 |
// else if(statusCode == 409) |
|
267 |
// app.displayError("A file with the same name already exists"); |
|
268 |
// else if(statusCode == 413) |
|
269 |
// app.displayError("Your quota has been exceeded"); |
|
270 |
// else |
|
271 |
// app.displayError("Unable to modify file::"+((RestException)t).getHttpStatusText()); |
|
272 |
// } |
|
273 |
// else |
|
274 |
// app.displayError("System error modifying file:"+t.getMessage()); |
|
275 |
// } |
|
276 |
// }; |
|
277 |
// DeferredCommand.addCommand(rt); |
|
278 | 160 |
} |
279 | 161 |
} |
b/src/gr/grnet/pithos/web/client/VersionsList.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client; |
36 | 36 |
|
37 |
import gr.grnet.pithos.web.client.FilePropertiesDialog.Images; |
|
38 |
import gr.grnet.pithos.web.client.foldertree.File; |
|
39 |
import gr.grnet.pithos.web.client.foldertree.Resource; |
|
40 |
import gr.grnet.pithos.web.client.foldertree.Version; |
|
41 |
import gr.grnet.pithos.web.client.rest.PostRequest; |
|
42 |
import gr.grnet.pithos.web.client.rest.RestException; |
|
43 |
|
|
44 |
import java.util.List; |
|
45 |
|
|
46 |
import com.google.gwt.core.client.Scheduler; |
|
47 |
import com.google.gwt.event.dom.client.ClickEvent; |
|
48 |
import com.google.gwt.event.dom.client.ClickHandler; |
|
49 |
import com.google.gwt.http.client.Response; |
|
50 |
import com.google.gwt.i18n.client.DateTimeFormat; |
|
51 |
import com.google.gwt.user.client.Window; |
|
52 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
|
37 | 53 |
import com.google.gwt.user.client.ui.Composite; |
54 |
import com.google.gwt.user.client.ui.FlexTable; |
|
55 |
import com.google.gwt.user.client.ui.HTML; |
|
56 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
|
57 |
import com.google.gwt.user.client.ui.VerticalPanel; |
|
38 | 58 |
|
39 | 59 |
public class VersionsList extends Composite { |
40 | 60 |
|
41 |
// private Pithos app; |
|
42 |
// |
|
43 |
// int selectedRow = -1; |
|
44 |
// |
|
45 |
// int permissionCount = -1; |
|
46 |
// |
|
47 |
// List<FileResource> versions = null; |
|
48 |
// |
|
49 |
// final Images images; |
|
50 |
// |
|
51 |
// final VerticalPanel permPanel = new VerticalPanel(); |
|
52 |
// |
|
53 |
// final FlexTable permTable = new FlexTable(); |
|
54 |
// |
|
55 |
// FileResource toRemove = null; |
|
56 |
// |
|
57 |
// FilePropertiesDialog container; |
|
58 |
// |
|
59 |
// public VersionsList(Pithos _app, FilePropertiesDialog aContainer, final Images theImages, List<FileResource> theVersions) { |
|
60 |
// app = _app; |
|
61 |
// images = theImages; |
|
62 |
// container = aContainer; |
|
63 |
// versions = theVersions; |
|
64 |
// Collections.sort(theVersions, new Comparator<FileResource>(){ |
|
65 |
// |
|
66 |
// @Override |
|
67 |
// public int compare(FileResource o1, FileResource o2) { |
|
68 |
// return o1.getVersion().compareTo(o2.getVersion()); |
|
69 |
// } |
|
70 |
// |
|
71 |
// }); |
|
72 |
// permTable.setText(0, 0, "Version"); |
|
73 |
// permTable.setText(0, 1, "Created"); |
|
74 |
// permTable.setText(0, 2, "Modified"); |
|
75 |
// permTable.setText(0, 3, "Size"); |
|
76 |
// permTable.setText(0, 4, ""); |
|
77 |
// permTable.setText(0, 5, ""); |
|
78 |
// permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
|
79 |
// permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
|
80 |
// permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels"); |
|
81 |
// permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels"); |
|
82 |
// permTable.getFlexCellFormatter().setColSpan(0, 1, 2); |
|
83 |
// permTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); |
|
84 |
// permTable.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER); |
|
85 |
// permTable.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER); |
|
86 |
// permTable.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER); |
|
87 |
// permPanel.add(permTable); |
|
88 |
// permPanel.addStyleName("pithos-TabPanelBottom"); |
|
89 |
// permTable.addStyleName("pithos-permList"); |
|
90 |
// initWidget(permPanel); |
|
91 |
// updateTable(); |
|
92 |
// } |
|
93 |
// |
|
94 |
// public void updateTable() { |
|
95 |
// copyListAndContinue(versions); |
|
96 |
// } |
|
97 |
// |
|
98 |
// public void showVersionsTable(){ |
|
99 |
// int i = 1; |
|
100 |
// if (toRemove != null) { |
|
101 |
// versions.remove(toRemove); |
|
102 |
// toRemove = null; |
|
103 |
// } |
|
104 |
// for (final FileResource dto : versions) { |
|
105 |
// HTML restoreVersion = new HTML("<a href='#' class='hidden-link info'><span>"+AbstractImagePrototype.create(images.restore()).getHTML()+"</span><div>Restore this Version</div></a>"); |
|
106 |
// restoreVersion.addClickHandler(new ClickHandler() { |
|
107 |
// @Override |
|
108 |
// public void onClick(ClickEvent event) { |
|
109 |
// restoreVersion(dto); |
|
110 |
// } |
|
111 |
// }); |
|
112 |
// |
|
113 |
// permTable.setHTML(i, 0, "<span>" + dto.getVersion() + "</span>"); |
|
114 |
// permTable.setHTML(i, 1, "<span>" + formatDate(dto.getCreationDate()) + " by " + app.findUserFullName(dto.getCreatedBy()) + "</span>"); |
|
115 |
// permTable.setHTML(i, 2, "<span>" + formatDate(dto.getModificationDate()) + " by " + app.findUserFullName(dto.getModifiedBy()) + "</span>"); |
|
116 |
// permTable.setHTML(i, 3, "<span>" + dto.getFileSizeAsString() + "</span>"); |
|
117 |
// HTML downloadHtml = new HTML("<a class='hidden-link info' href='#'><span>"+AbstractImagePrototype.create(images.download()).getHTML()+"</span><div>View this Version</div></a>"); |
|
118 |
// downloadHtml.addClickHandler(new ClickHandler() { |
|
119 |
// @Override |
|
120 |
// public void onClick(ClickEvent event) { |
|
121 |
// String fileUrl = dto.getUri() + "?version=" + dto.getVersion(); |
|
122 |
// Window.open(fileUrl, "_BLANK", ""); |
|
123 |
// } |
|
124 |
// }); |
|
125 |
// permTable.setWidget(i, 4, downloadHtml); |
|
126 |
// permTable.setWidget(i, 5, restoreVersion); |
|
127 |
// permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels"); |
|
128 |
// permTable.getFlexCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_CENTER); |
|
129 |
// permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER); |
|
130 |
// permTable.getFlexCellFormatter().setColSpan(i, 1, 2); |
|
131 |
// permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER); |
|
132 |
// permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER); |
|
133 |
// i++; |
|
134 |
// } |
|
135 |
// for (; i < permTable.getRowCount(); i++) |
|
136 |
// permTable.removeRow(i); |
|
137 |
// } |
|
138 |
// |
|
139 |
// void restoreVersion(final FileResource version) { |
|
140 |
//// FileResource selectedFile = (FileResource) app.getCurrentSelection(); |
|
141 |
//// PostCommand ep = new PostCommand(app, selectedFile.getUri()+"?restoreVersion="+version.getVersion(),"",200){ |
|
142 |
//// |
|
143 |
//// |
|
144 |
//// @Override |
|
145 |
//// public void onComplete() { |
|
146 |
//// container.hide(); |
|
147 |
//// app.getTreeView().refreshCurrentNode(false); |
|
148 |
//// } |
|
149 |
//// |
|
150 |
//// @Override |
|
151 |
//// public void onError(Throwable t) { |
|
152 |
//// GWT.log("", t); |
|
153 |
//// if(t instanceof RestException) |
|
154 |
//// app.displayError("Unable to restore version:"+((RestException)t).getHttpStatusText()); |
|
155 |
//// else |
|
156 |
//// app.displayError("System error restoring version:"+t.getMessage()); |
|
157 |
//// } |
|
158 |
//// |
|
159 |
//// }; |
|
160 |
//// DeferredCommand.addCommand(ep); |
|
161 |
// } |
|
162 |
// |
|
163 |
// private String formatDate(Date date){ |
|
164 |
// DateTimeFormat format = DateTimeFormat.getFormat("dd/MM/yyyy : HH:mm"); |
|
165 |
// return format.format(date); |
|
166 |
// } |
|
167 |
// |
|
168 |
// /** |
|
169 |
// * Copies the input List to a new List |
|
170 |
// * @param input |
|
171 |
// */ |
|
172 |
// private void copyListAndContinue(List<FileResource> input){ |
|
173 |
// List<FileResource> copiedInput = new ArrayList<FileResource>(); |
|
174 |
// for(FileResource dto : input) { |
|
175 |
// copiedInput.add(dto); |
|
176 |
// } |
|
177 |
// handleFullNames(copiedInput); |
|
178 |
// } |
|
179 |
// |
|
180 |
// /** |
|
181 |
// * Examines whether or not the user's full name exists in the |
|
182 |
// * userFullNameMap in the Pithos.java for every element of the input list. |
|
183 |
// * If the user's full name does not exist in the map then a request is being made |
|
184 |
// * for the specific username. |
|
185 |
// * |
|
186 |
// * @param input |
|
187 |
// */ |
|
188 |
// private void handleFullNames(List<FileResource> input){ |
|
189 |
// if(input.isEmpty()){ |
|
190 |
// showVersionsTable(); |
|
191 |
// return; |
|
192 |
// } |
|
193 |
// |
|
194 |
// if(app.findUserFullName(input.get(0).getOwner()) == null){ |
|
195 |
// findFullNameAndUpdate(input); |
|
196 |
// return; |
|
197 |
// } |
|
198 |
// |
|
199 |
// if(input.size() >= 1){ |
|
200 |
// input.remove(input.get(0)); |
|
201 |
// if(input.isEmpty()){ |
|
202 |
// showVersionsTable(); |
|
203 |
// }else{ |
|
204 |
// handleFullNames(input); |
|
205 |
// } |
|
206 |
// } |
|
207 |
// } |
|
208 |
// |
|
209 |
// /** |
|
210 |
// * Makes a request to search for full name from a given username |
|
211 |
// * and continues checking the next element of the List. |
|
212 |
// * |
|
213 |
// * @param input |
|
214 |
// */ |
|
215 |
// |
|
216 |
// private void findFullNameAndUpdate(final List<FileResource> input){ |
|
217 |
//// final String aUserName = input.get(0).getOwner(); |
|
218 |
//// String path = app.getApiPath() + "users/" + aUserName; |
|
219 |
//// |
|
220 |
//// GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(app, UserSearchResource.class, path, false,null) { |
|
221 |
//// @Override |
|
222 |
//// public void onComplete() { |
|
223 |
//// final UserSearchResource result = getResult(); |
|
224 |
//// for (UserResource user : result.getUsers()){ |
|
225 |
//// String username = user.getUsername(); |
|
226 |
//// String userFullName = user.getName(); |
|
227 |
//// app.putUserToMap(username, userFullName); |
|
228 |
//// if(input.size() >= 1){ |
|
229 |
//// input.remove(input.get(0)); |
|
230 |
//// if(input.isEmpty()){ |
|
231 |
//// showVersionsTable(); |
|
232 |
//// return; |
|
233 |
//// } |
|
234 |
//// handleFullNames(input); |
|
235 |
//// } |
|
236 |
//// } |
|
237 |
//// } |
|
238 |
//// @Override |
|
239 |
//// public void onError(Throwable t) { |
|
240 |
//// app.displayError("Unable to fetch user's full name from the given username " + aUserName); |
|
241 |
//// if(input.size() >= 1){ |
|
242 |
//// input.remove(input.get(0)); |
|
243 |
//// handleFullNames(input); |
|
244 |
//// } |
|
245 |
//// } |
|
246 |
//// }; |
|
247 |
//// DeferredCommand.addCommand(gg); |
|
248 |
// |
|
249 |
// } |
|
250 |
// |
|
61 |
Pithos app; |
|
62 |
|
|
63 |
File file; |
|
64 |
|
|
65 |
private List<Version> versions = null; |
|
66 |
|
|
67 |
private Images images; |
|
68 |
|
|
69 |
private VerticalPanel permPanel = new VerticalPanel(); |
|
70 |
|
|
71 |
private FlexTable permTable = new FlexTable(); |
|
72 |
|
|
73 |
FilePropertiesDialog container; |
|
74 |
|
|
75 |
public VersionsList(Pithos _app, FilePropertiesDialog aContainer, final Images theImages, File _file, List<Version> theVersions) { |
|
76 |
app = _app; |
|
77 |
images = theImages; |
|
78 |
container = aContainer; |
|
79 |
file = _file; |
|
80 |
versions = theVersions; |
|
81 |
permTable.setText(0, 0, "Version"); |
|
82 |
permTable.setText(0, 1, "Date"); |
|
83 |
permTable.setText(0, 2, ""); |
|
84 |
permTable.setText(0, 3, ""); |
|
85 |
permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
|
86 |
permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
|
87 |
permTable.getFlexCellFormatter().setColSpan(0, 1, 2); |
|
88 |
permTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); |
|
89 |
permTable.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER); |
|
90 |
permPanel.add(permTable); |
|
91 |
permPanel.addStyleName("pithos-TabPanelBottom"); |
|
92 |
permTable.addStyleName("pithos-permList"); |
|
93 |
initWidget(permPanel); |
|
94 |
showVersionsTable(); |
|
95 |
} |
|
96 |
|
|
97 |
public void showVersionsTable(){ |
|
98 |
DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); |
|
99 |
int i = 1; |
|
100 |
for (final Version v : versions) { |
|
101 |
HTML restoreVersion = new HTML("<a href='#' class='hidden-link info'><span>" + AbstractImagePrototype.create(images.restore()).getHTML() + "</span><div>Restore this Version</div></a>"); |
|
102 |
restoreVersion.addClickHandler(new ClickHandler() { |
|
103 |
@Override |
|
104 |
public void onClick(ClickEvent event) { |
|
105 |
restoreVersion(v.getVersion()); |
|
106 |
} |
|
107 |
}); |
|
108 |
|
|
109 |
permTable.setHTML(i, 0, "<span>" + v.getVersion() + "</span>"); |
|
110 |
permTable.setHTML(i, 1, "<span>" + formatter.format(v.getDate()) + "</span>"); |
|
111 |
HTML downloadHtml = new HTML("<a class='hidden-link info' href='#'><span>" + AbstractImagePrototype.create(images.download()).getHTML()+"</span><div>View this Version</div></a>"); |
|
112 |
downloadHtml.addClickHandler(new ClickHandler() { |
|
113 |
@Override |
|
114 |
public void onClick(ClickEvent event) { |
|
115 |
String fileUrl = app.getApiPath() + app.getUsername() + file.getUri() + "?X-Auth-Token=" + app.getToken() + "&version=" + v.getVersion(); |
|
116 |
Window.open(fileUrl, "_BLANK", ""); |
|
117 |
} |
|
118 |
}); |
|
119 |
permTable.setWidget(i, 2, downloadHtml); |
|
120 |
permTable.setWidget(i, 3, restoreVersion); |
|
121 |
permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels"); |
|
122 |
permTable.getFlexCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_CENTER); |
|
123 |
permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER); |
|
124 |
permTable.getFlexCellFormatter().setColSpan(i, 1, 2); |
|
125 |
i++; |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
void restoreVersion(int version) { |
|
130 |
String path = file.getUri() + "?update="; |
|
131 |
PostRequest restoreVersion = new PostRequest(app.getApiPath(), file.getOwner(), path) { |
|
132 |
|
|
133 |
@Override |
|
134 |
public void onSuccess(Resource result) { |
|
135 |
container.hide(); |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
public void onError(Throwable t) { |
|
140 |
if (t instanceof RestException) { |
|
141 |
if (((RestException) t).getHttpStatusCode() == Response.SC_NO_CONTENT) |
|
142 |
onSuccess(null); |
|
143 |
else |
|
144 |
app.displayError("Unable to restore version: " + ((RestException) t).getHttpStatusText()); |
|
145 |
} |
|
146 |
else |
|
147 |
app.displayError("System error unable to restore versions: "+t.getMessage()); |
|
148 |
} |
|
149 |
}; |
|
150 |
restoreVersion.setHeader("X-Auth-Token", app.getToken()); |
|
151 |
restoreVersion.setHeader("X-Source-Object", file.getUri()); |
|
152 |
restoreVersion.setHeader("X-Source-Version", String.valueOf(version)); |
|
153 |
restoreVersion.setHeader("Content-Range", "bytes 0-/*"); |
|
154 |
Scheduler.get().scheduleDeferred(restoreVersion); |
|
155 |
} |
|
251 | 156 |
} |
b/src/gr/grnet/pithos/web/client/foldertree/FileVersions.java | ||
---|---|---|
1 |
package gr.grnet.pithos.web.client.foldertree; |
|
2 |
|
|
3 |
import gr.grnet.pithos.web.client.SharingUsers; |
|
4 |
|
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.Date; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
import com.google.gwt.http.client.Response; |
|
10 |
import com.google.gwt.json.client.JSONArray; |
|
11 |
import com.google.gwt.json.client.JSONObject; |
|
12 |
import com.google.gwt.json.client.JSONParser; |
|
13 |
import com.google.gwt.json.client.JSONValue; |
|
14 |
|
|
15 |
public class FileVersions extends Resource { |
|
16 |
private List<Version> versions; |
|
17 |
|
|
18 |
public List<Version> getVersions() { |
|
19 |
return versions; |
|
20 |
} |
|
21 |
|
|
22 |
public static FileVersions createFromResponse(Response response) { |
|
23 |
FileVersions res = new FileVersions(); |
|
24 |
res.populate(response); |
|
25 |
return res; |
|
26 |
} |
|
27 |
|
|
28 |
private void populate(Response response) { |
|
29 |
versions = new ArrayList<Version>(); |
|
30 |
JSONValue json = JSONParser.parseStrict(response.getText()); |
|
31 |
JSONArray array = json.isObject().get("versions").isArray(); |
|
32 |
if (array != null) { |
|
33 |
for (int i=0; i<array.size(); i++) { |
|
34 |
JSONArray o = array.get(i).isArray(); |
|
35 |
if (o != null) { |
|
36 |
int num = (int) o.get(0).isNumber().doubleValue(); |
|
37 |
Date date = new Date((long) o.get(1).isNumber().doubleValue()); |
|
38 |
Version v = new Version(num, date); |
|
39 |
versions.add(v); |
|
40 |
} |
|
41 |
} |
|
42 |
} |
|
43 |
} |
|
44 |
} |
b/src/gr/grnet/pithos/web/client/foldertree/Resource.java | ||
---|---|---|
107 | 107 |
else if (aClass.equals(SharingUsers.class)) { |
108 | 108 |
result1 = (T) SharingUsers.createFromResponse(response, (SharingUsers) result); |
109 | 109 |
} |
110 |
else if (aClass.equals(FileVersions.class)) { |
|
111 |
result1 = (T) FileVersions.createFromResponse(response); |
|
112 |
} |
|
110 | 113 |
return result1; |
111 | 114 |
} |
112 | 115 |
} |
b/src/gr/grnet/pithos/web/client/foldertree/Version.java | ||
---|---|---|
1 |
package gr.grnet.pithos.web.client.foldertree; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
|
|
5 |
public class Version { |
|
6 |
private int version; |
|
7 |
|
|
8 |
private Date date; |
|
9 |
|
|
10 |
public Version(int v, Date d) { |
|
11 |
version = v; |
|
12 |
date = d; |
|
13 |
} |
|
14 |
|
|
15 |
public int getVersion() { |
|
16 |
return version; |
|
17 |
} |
|
18 |
|
|
19 |
public Date getDate() { |
|
20 |
return date; |
|
21 |
} |
|
22 |
} |
Also available in: Unified diff