Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: chrome/browser/resources/file_manager/js/util.js

Issue 10342010: Add gdata content search to file_manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some fixes Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/file_manager/js/util.js
diff --git a/chrome/browser/resources/file_manager/js/util.js b/chrome/browser/resources/file_manager/js/util.js
index eb39b1b8a08c5554754f476fb303f15d3efca309..74b978035496791bf0901da07a7ba081f99e0f04 100644
--- a/chrome/browser/resources/file_manager/js/util.js
+++ b/chrome/browser/resources/file_manager/js/util.js
@@ -499,5 +499,93 @@ var util = {
*/
isOffline: function() {
return !navigator.onLine;
+ },
+
+ /*
+ * Returns root path used for displaying gdata content search results.
+ * Search results will be shown in directory gdataSearchRootPath/query.
+ *
+ * @return {string}
+ */
+ getGDataSearchRootPath: function() {
Oleg Eterevsky 2012/05/03 15:52:24 Define constants instead? /** * @const * @type
tbarzic 2012/05/03 19:16:02 Done.
+ return '/gdata/.search';
+ },
+
+ /*
+ * Creates directory path in which gdata content search results for |query|
+ * should be displayed.
+ *
+ * @param {string} Search query.
Oleg Eterevsky 2012/05/03 15:52:24 Please add the parameter name: @param {string} qu
tbarzic 2012/05/03 19:16:02 Done.
+ * @return {string} Virtual directory path for search results.
+ */
+ createGDataSearchPath: function(query) {
+ return this.getGDataSearchRootPath() + '/' + query;
+ },
+
+ /*
+ * Tests if we can create new entries on gdata search path. If the provided
+ * path is not gdata path, it returns true.
+ *
+ * @param {string} Path which is being tested.
Oleg Eterevsky 2012/05/03 15:52:24 Please add the parameter name: @param {string} pa
tbarzic 2012/05/03 19:16:02 Done.
+ * @return {boolean} Test result.
+ */
+ shouldCreateOnGDataPath: function(path) {
+ var gdataSearchRootPath = this.getGDataSearchRootPath();
+ // If the path is not search root or it's child, we're fine.
+ if (path.search(gdataSearchRootPath) != 0)
+ return true;
+
+ var pathComponents = path.split('/');
+ var searchRootComponents = gdataSearchRootPath.split('/');
+
+ // We should not create entries on path if it's either gdata search root,
+ // or its immediate child.
+ return pathComponents.length != searchRootComponents.length &&
+ pathComponents.length != searchRootComponents.length + 1;
+ },
+
+ /*
+ * Tests if the given path is a gdata search result path, and if it is returns
+ * files fileName in virtual search file system, and display name we that
Oleg Eterevsky 2012/05/03 15:52:24 ... display name that ...
tbarzic 2012/05/03 19:16:02 Done.
+ * should be used when the file is shown in file browser.
+ *
+ * @param {string} The potential gdata search result path.
Oleg Eterevsky 2012/05/03 15:52:24 Please add the parameter name.
tbarzic 2012/05/03 19:16:02 Done.
+ * @return {object} Object that will contain file's fileName and displayName,
+ * or undefined if the path is not gdata search result path.
dgozman 2012/05/03 11:21:47 Use null instead of undefined.
Oleg Eterevsky 2012/05/03 15:52:24 @return {Object.<string,string>?}
tbarzic 2012/05/03 19:16:02 Done.
tbarzic 2012/05/03 19:16:02 Done.
+ */
+ getFileAndDisplayNameForGDataSearchResult: function(path) {
+ var gdataSearchRootPath = this.getGDataSearchRootPath();
+
+ // Nothing to do it the path is not under gdata search root path.
Oleg Eterevsky 2012/05/03 15:52:24 ... to do IF the path ...
tbarzic 2012/05/03 19:16:02 Done.
+ if (path.search(gdataSearchRootPath) != 0)
+ return undefined;
+
+ var pathComponents = path.split('/');
+ var searchRootComponents = gdataSearchRootPath.split('/');
+
+ // Search result should be formated like:
Oleg Eterevsky 2012/05/03 15:52:24 formatted
tbarzic 2012/05/03 19:16:02 Done.
+ // gdataSearchRoot/query/result
+ if (pathComponents.length != searchRootComponents.length + 2)
+ return undefined;
+ for (var i = 0; i < searchRootComponents.length; i++) {
+ if (pathComponents[i] != searchRootComponents[i])
+ return undefined;
+ }
+
+ // Search result file name should be formatted like:
+ // resource_id.referenced_file_name
+ // We should display referenced file name only.
+ var result = {};
+ result.fileName = pathComponents.pop();
+ result.displayName =
+ result.fileName.slice(result.fileName.indexOf('.') + 1);
+ result.resourceId =
+ result.fileName.substr(0, result.fileName.indexOf('.'));
+
+ if (result.fileName.length > 0 && result.displayName.length > 0) {
+ return result;
+ } else {
+ return undefined;
+ }
}
};

Powered by Google App Engine
This is Rietveld 408576698