Permalink
Browse files

- Added new graphics

- Removed client database creation
  • Loading branch information...
1 parent ac4e93f commit e37c0e43658354500d44b8fccb0a7ee977c147ca taniele committed Jul 7, 2011
View
BIN .DS_Store
Binary file not shown.
View
Binary file not shown.
View
@@ -1,39 +0,0 @@
-var makeTree = function(docs, callback) {
-
- var keys = {};
- for(var module in docs) {
- var path = module.split('.');
- tree(path, keys);
- }
-
- function tree(path, keys) {
-
- while(module = path.shift()) {
-
- if(path.length == 0) {
- keys[module] = null;
- }
- else if(!keys[module]) {
- keys[module] = {};
- }
-
- tree(path, keys[module]);
- }
- }
-
- function walk(tree, path) {
- path = path || [];
-
- for(var i in tree) {
- path.push(i);
- walk(tree[i], path);
- if(callback) {
- var key = path.join('.');
- callback(i, key, tree[i] != null);
- }
- path.pop();
- }
- }
-
- walk(keys);
-}
View
@@ -131,21 +131,8 @@ var SearchWindow = {
SearchWindow.noResults.hide();
SearchWindow.noResults.add(SearchWindow.noResultsLabel);
SearchWindow.mainWindow.add(SearchWindow.noResults);
-
- if(Ti.App.Properties.hasProperty('indexing')) {
- var view = SearchWindow.indicator.show();
- SearchWindow.mainWindow.add(view);
-
- Ti.App.addEventListener('indexcomplete', function() {
- Ti.API.info('index complete, hiding indicator');
- SearchWindow.indicator.hide();
- SearchWindow.start();
- });
- }
- else {
- SearchWindow.start();
- }
-
+
+ SearchWindow.start();
},
start: function() {
View
Binary file not shown.
View
@@ -1,13 +1,5 @@
-Ti.include('MakeTree.js');
Ti.include('UI.js');
-var docs = null;
-function trimstrip(text) {
- text = text || "";
- text = text.replace(/<\S[^><]*>/g, '');
- text = text.length > 254 ? text.substr(0, 254) + '' : text;
- return text;
-}
-
+var BASE_URL = 'http://melonpielabs.com/tidocs/'
var checkUpdates = function(callback) {
callback = callback || function() {};
if(!Ti.Network.online) {
@@ -21,13 +13,19 @@ var checkUpdates = function(callback) {
}
var url = Ti.App.Properties.getString('url');
+ if(url == null) {
+ Ti.API.info('first run, installing default database');
+ var db = Ti.Database.install('cache.sqlite', 'cache.sqlite');
+ db.close();
+ Ti.API.info('done');
+ }
var version = Ti.App.Properties.getString('docsVersion');
var req = Ti.Network.createHTTPClient();
var timestamp = new Date().getTime();
- req.open('GET', 'http://melonpielabs.com/tidocs/?' + timestamp);
+ req.open('GET', BASE_URL + '?' + timestamp);
req.onerror = function() {
- Ti.API.error('error ' + this.status + ': ' + this.responseText);
+ Ti.API.error('error ' + this.status + ' while retrieving the version descriptor: ' + this.responseText);
// if error on first run (no url yet)
if(url == null) {
callback({error: true, success: false});
@@ -43,108 +41,56 @@ var checkUpdates = function(callback) {
catch(e) {
callback({error: true, success: false});
}
- var serverURL = response.url;
+ var database = response.db;
var serverVersion = response.version;
-
+ Ti.API.info('version: ' + version + ', server version: ' + serverVersion);
if(serverVersion != version || response.forceUpdate) {
- url = serverURL;
+ url = database;
+
Ti.App.Properties.setString('url', url);
Ti.App.Properties.setString('docsVersion', response.version);
- // update database keys
- try {
-
- var db = Ti.Database.open('cache.sqlite');
-
- db.execute('DROP TABLE IF EXISTS cache');
- db.execute('DROP TABLE IF EXISTS entries');
- db.execute('CREATE TABLE IF NOT EXISTS cache (id INTEGER PRIMARY KEY, key TEXT(255), path TEXT(255), description TEXT(255), type TEXT(64))');
- db.execute('CREATE TABLE IF NOT EXISTS entries (id INTEGER PRIMARY KEY, name TEXT(255), fullname TEXT(255), parent TEXT(255), hasChild INTEGER)');
-
- var apireq = Ti.Network.createHTTPClient();
- apireq.open('GET', url);
-
- apireq.onload = function() {
+ var docsFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'docs.json');
+ var f = Ti.Network.createHTTPClient();
+ f.setTimeout(10000);
+ f.onload = function(e) {
+ docsFile.write(this.responseText);
- var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'docs.json');
- // Titanium.File.createFile
- // file.createFile();
- file.write(this.responseText);
+ // update database
+ Ti.API.info('replacing database')
+ var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'../Library/Application Support/database/cache.sqlite.sql');
+ var c = Ti.Network.createHTTPClient();
+ c.setTimeout(10000);
+ c.onload = function(e){
+ file.write(this.responseData);
+ Ti.API.info('file wrote, location: ' + file.nativePath);
- docs = JSON.parse(this.responseText);
- if(docs) {
- db.execute('DELETE FROM cache');
- db.execute('DELETE FROM entries');
+ setTimeout(function() {
+ callback({error: false, success: true});
+ }, 1000);
- makeTree(docs, function(name, fullname, hasChild) {
- var parent = fullname.split('.');
- parent.pop();
- parent = parent.join('.');
- db.execute('INSERT INTO entries (name, fullname, parent, hasChild) VALUES (?, ?, ?, ?)', name, fullname, parent, hasChild ? 1 : 0);
- if(docs[fullname].description) {
- var text = trimstrip(docs[fullname].description);
- db.execute('INSERT INTO cache (key, path, description) VALUES (?, ?, ?)', fullname, fullname, text);
- }
- });
- }
- db.close();
- Ti.App.Properties.setBool('indexing', true);
- Ti.App.fireEvent('indexsearch');
- callback({error: false, success: true});
- }
-
- apireq.onerror = function() {
- Ti.API.error('error ' + this.status + ': ' + this.responseText);
- callback({error: true, success: false});
- }
+ };
- apireq.send();
+ c.onerror = function(e){
+ callback({error: true, success: false});
+ };
+ c.open('GET',BASE_URL + url);
+ c.send();
}
- catch(e) {
- Ti.API.error('[database] exception: ' + e);
+
+ f.onerror = function(e) {
callback({error: true, success: false});
}
+
+ f.open('GET', response.url);
+ f.send();
+
}
else {
- if(Ti.App.Properties.hasProperty('indexing')) {
- Ti.API.info('indexing resumes…')
- Ti.App.fireEvent('indexsearch');
- }
callback({error: false, success: true});
}
}
}
- req.send();
-
+ req.send();
}
-
-Ti.App.addEventListener('indexsearch', function() {
- Ti.API.info('start indexing…');
- var db = Ti.Database.open('cache.sqlite');
- db.execute('DELETE FROM cache');
- var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'docs.json');
- var docs = JSON.parse(file.read().text);
- for(var module in docs) {
- var text = trimstrip(docs[module].description);
- db.execute('INSERT INTO cache (key, path, description, type) VALUES (?, ?, ?, ?)', module.split('.').pop(), module, text, 'module');
- if(docs[module].properties) {
- entries = docs[module].properties;
- for(var i in entries) {
- var text = trimstrip(entries[i].value);
- db.execute('INSERT INTO cache (key, path, description, type) VALUES (?, ?, ?, ?)', entries[i].name, module, text, 'property');
- }
- }
- if(docs[module].methods) {
- entries = docs[module].methods;
- for(var i in entries) {
- var text = trimstrip(entries[i].value);
- db.execute('INSERT INTO cache (key, path, description, type) VALUES (?, ?, ?, ?)', entries[i].name, module, text, 'method');
- }
- }
- }
- Ti.API.info('indexing complete')
- Ti.App.Properties.removeProperty('indexing');
- Ti.App.fireEvent('indexcomplete');
- db.close();
-});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Deleted file not rendered
View
Deleted file not rendered
View
Deleted file not rendered
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Deleted file not rendered
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<ti:app xmlns:ti="http://ti.appcelerator.org">
- <id>com.studiomelonpie.tidocs</id>
- <name>TiDocs</name>
- <version>1.0</version>
- <publisher>not specified</publisher>
- <url>not specified</url>
- <description>not specified</description>
- <copyright>not specified</copyright>
- <icon>appicon.png</icon>
+<id>com.studiomelonpie.tidocs</id>
+<name>TiDocs</name>
+<version>1.0</version>
+<publisher>dbernardi</publisher>
+<url>http://studiomelonpie.com/tidocs</url>
+<description>No description provided</description>
+<copyright>2011 by dbernardi</copyright>
+<icon>appicon.png</icon>
<persistent-wifi>false</persistent-wifi>
<prerendered-icon>false</prerendered-icon>
<statusbar-style>default</statusbar-style>

0 comments on commit e37c0e4

Please sign in to comment.