Skip to content

Commit

Permalink
Merge pull request #376 from andygup/v2.10
Browse files Browse the repository at this point in the history
v2.10
  • Loading branch information
andygup committed Jul 27, 2015
2 parents 87e136e + 942fb4e commit 2ae3071
Show file tree
Hide file tree
Showing 20 changed files with 228 additions and 90 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# offline-editor-js - Changelog

## Version 2.10 - July 27, 2015

No breaking changes.

**Enhancements**
* Closes #288. Adds the ability to modify `offlineTilesEnabler` and `offlineTilesEnablerLayer` database name and data store name.
* Updates to API and How-to Docs

## Version 2.9.5 - July 14, 2015

No breaking changes.
Expand Down
2 changes: 1 addition & 1 deletion dist/offline-edit-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/offline-edit-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! offline-editor-js - v2.9.5 - 2015-07-14
/*! offline-editor-js - v2.10.0 - 2015-07-27
* Copyright (c) 2015 Environmental Systems Research Institute, Inc.
* Apache License*/
/*jshint -W030 */
Expand Down
6 changes: 3 additions & 3 deletions dist/offline-tiles-advanced-min.js

Large diffs are not rendered by default.

49 changes: 31 additions & 18 deletions dist/offline-tiles-advanced-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! offline-editor-js - v2.9.5 - 2015-07-14
/*! offline-editor-js - v2.10.0 - 2015-07-27
* Copyright (c) 2015 Environmental Systems Research Institute, Inc.
* Apache License*/
define([
Expand All @@ -24,13 +24,23 @@ define([
_maxZoom: null,
_tilesCore:null,

constructor:function(url,callback,state){
constructor:function(url,callback,/* boolean */ state,/* Object */ dbConfig){

if(this._isLocalStorage() === false){
alert("OfflineTiles Library not supported on this browser.");
callback(false);
}

if( dbConfig === "undefined" || dbConfig === null){
// Database properties
this.DB_NAME = "offline_tile_store"; // Sets the database name.
this.DB_OBJECTSTORE_NAME = "tilepath"; // Represents an object store that allows access to a set of data in the IndexedDB database
}
else {
this.DB_NAME = dbConfig.dbName;
this.DB_OBJECTSTORE_NAME = dbConfig.objectStoreName;
}

this._tilesCore = new O.esri.Tiles.TilesCore();

//For calculating minZoom and maxZoom
Expand Down Expand Up @@ -72,6 +82,8 @@ define([

if( /*false &&*/ this.offline.store.isSupported() )
{
this.offline.store.dbName = this.DB_NAME;
this.offline.store.objectStoreName = this.DB_OBJECTSTORE_NAME;
this.offline.store.init(function(success){
if(success){
this._getTileInfoPrivate(url,function(result){
Expand Down Expand Up @@ -1188,7 +1200,8 @@ O.esri.Tiles.TilesStore = function(){
*/
this._db = null;

var DB_NAME = "offline_tile_store";
this.dbName = "offline_tile_store";
this.objectStoreName = "tilepath";

/**
* Determines if indexedDB is supported
Expand All @@ -1212,7 +1225,7 @@ O.esri.Tiles.TilesStore = function(){
{
try
{
var transaction = this._db.transaction(["tilepath"],"readwrite");
var transaction = this._db.transaction([this.objectStoreName],"readwrite");

transaction.oncomplete = function()
{
Expand All @@ -1224,7 +1237,7 @@ O.esri.Tiles.TilesStore = function(){
callback(false,event.target.error.message);
};

var objectStore = transaction.objectStore("tilepath");
var objectStore = transaction.objectStore(this.objectStoreName);
var request = objectStore.put(urlDataPair);
request.onsuccess = function()
{
Expand All @@ -1247,7 +1260,7 @@ O.esri.Tiles.TilesStore = function(){
{
if(this._db !== null)
{
var objectStore = this._db.transaction(["tilepath"]).objectStore("tilepath");
var objectStore = this._db.transaction([this.objectStoreName]).objectStore(this.objectStoreName);
var request = objectStore.get(url);
request.onsuccess = function(event)
{
Expand Down Expand Up @@ -1277,8 +1290,8 @@ O.esri.Tiles.TilesStore = function(){
{
if(this._db !== null)
{
var request = this._db.transaction(["tilepath"],"readwrite")
.objectStore("tilepath")
var request = this._db.transaction([this.objectStoreName],"readwrite")
.objectStore(this.objectStoreName)
.clear();
request.onsuccess = function()
{
Expand All @@ -1304,8 +1317,8 @@ O.esri.Tiles.TilesStore = function(){
{
if(this._db !== null)
{
var request = this._db.transaction(["tilepath"],"readwrite")
.objectStore("tilepath")
var request = this._db.transaction([this.objectStoreName],"readwrite")
.objectStore(this.objectStoreName)
.delete(url);
request.onsuccess = function()
{
Expand All @@ -1329,8 +1342,8 @@ O.esri.Tiles.TilesStore = function(){
this.getAllTiles = function(callback)
{
if(this._db !== null){
var transaction = this._db.transaction(["tilepath"])
.objectStore("tilepath")
var transaction = this._db.transaction([this.objectStoreName])
.objectStore(this.objectStoreName)
.openCursor();

transaction.onsuccess = function(event)
Expand Down Expand Up @@ -1366,8 +1379,8 @@ O.esri.Tiles.TilesStore = function(){
if(this._db !== null){
var usage = { sizeBytes: 0, tileCount: 0 };

var transaction = this._db.transaction(["tilepath"])
.objectStore("tilepath")
var transaction = this._db.transaction([this.objectStoreName])
.objectStore(this.objectStoreName)
.openCursor();

transaction.onsuccess = function(event){
Expand Down Expand Up @@ -1401,7 +1414,7 @@ O.esri.Tiles.TilesStore = function(){

this.init = function(callback)
{
var request = indexedDB.open(DB_NAME, 4);
var request = indexedDB.open(this.dbName, 4);
callback = callback || function(success) { console.log("TilesStore::init() success:", success); }.bind(this);

request.onerror = function(event)
Expand All @@ -1414,12 +1427,12 @@ O.esri.Tiles.TilesStore = function(){
{
var db = event.target.result;

if( db.objectStoreNames.contains("tilepath"))
if( db.objectStoreNames.contains(this.objectStoreName))
{
db.deleteObjectStore("tilepath");
db.deleteObjectStore(this.objectStoreName);
}

db.createObjectStore("tilepath", { keyPath: "url" });
db.createObjectStore(this.objectStoreName, { keyPath: "url" });
}.bind(this);

request.onsuccess = function(event)
Expand Down
6 changes: 3 additions & 3 deletions dist/offline-tiles-basic-min.js

Large diffs are not rendered by default.

51 changes: 33 additions & 18 deletions dist/offline-tiles-basic-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! offline-editor-js - v2.9.5 - 2015-07-14
/*! offline-editor-js - v2.10.0 - 2015-07-27
* Copyright (c) 2015 Environmental Systems Research Institute, Inc.
* Apache License*/
define([
Expand Down Expand Up @@ -28,9 +28,11 @@ define([
* @param callback
* @param state Optional Recommended. Pre-sets whether or not the application is online or offline.
* Specifically used for applications that need to protect against browser reload/restart while offline.
* @param dbConfig is an optional object that can be used to customize the database name (`dbName`) and
* the object store (`objectStoreName`) name. Example: `{dbName: "TILES_TEST", objectStoreName: "TILES"}`.
* @returns {callback} callback(boolean, string)
*/
extend: function(layer,callback,/* boolean */ state)
extend: function(layer,callback,/* boolean */ state,/* Object */ dbConfig)
{
console.log("extending layer", layer.url);

Expand All @@ -40,6 +42,16 @@ define([
layer._minZoom = null;
layer._maxZoom = null;

if( dbConfig === "undefined" || dbConfig === null){
// Database properties
layer.DB_NAME = "offline_tile_store"; // Sets the database name.
layer.DB_OBJECTSTORE_NAME = "tilepath"; // Represents an object store that allows access to a set of data in the IndexedDB database
}
else {
layer.DB_NAME = dbConfig.dbName;
layer.DB_OBJECTSTORE_NAME = dbConfig.objectStoreName;
}

/* we add some methods to the layer object */
/* we don't want to extend the tiled layer class, as it is a capability that we want to add only to one instance */
/* we also add some additional attributes inside an "offline" object */
Expand Down Expand Up @@ -72,6 +84,8 @@ define([

if( /*false &&*/ layer.offline.store.isSupported() )
{
layer.offline.store.dbName = layer.DB_NAME;
layer.offline.store.objectStoreName = layer.DB_OBJECTSTORE_NAME;
// Important: wait to load tiles until after database has initialized!
layer.offline.store.init(function(success){
if(success){
Expand Down Expand Up @@ -1104,7 +1118,8 @@ O.esri.Tiles.TilesStore = function(){
*/
this._db = null;

var DB_NAME = "offline_tile_store";
this.dbName = "offline_tile_store";
this.objectStoreName = "tilepath";

/**
* Determines if indexedDB is supported
Expand All @@ -1128,7 +1143,7 @@ O.esri.Tiles.TilesStore = function(){
{
try
{
var transaction = this._db.transaction(["tilepath"],"readwrite");
var transaction = this._db.transaction([this.objectStoreName],"readwrite");

transaction.oncomplete = function()
{
Expand All @@ -1140,7 +1155,7 @@ O.esri.Tiles.TilesStore = function(){
callback(false,event.target.error.message);
};

var objectStore = transaction.objectStore("tilepath");
var objectStore = transaction.objectStore(this.objectStoreName);
var request = objectStore.put(urlDataPair);
request.onsuccess = function()
{
Expand All @@ -1163,7 +1178,7 @@ O.esri.Tiles.TilesStore = function(){
{
if(this._db !== null)
{
var objectStore = this._db.transaction(["tilepath"]).objectStore("tilepath");
var objectStore = this._db.transaction([this.objectStoreName]).objectStore(this.objectStoreName);
var request = objectStore.get(url);
request.onsuccess = function(event)
{
Expand Down Expand Up @@ -1193,8 +1208,8 @@ O.esri.Tiles.TilesStore = function(){
{
if(this._db !== null)
{
var request = this._db.transaction(["tilepath"],"readwrite")
.objectStore("tilepath")
var request = this._db.transaction([this.objectStoreName],"readwrite")
.objectStore(this.objectStoreName)
.clear();
request.onsuccess = function()
{
Expand All @@ -1220,8 +1235,8 @@ O.esri.Tiles.TilesStore = function(){
{
if(this._db !== null)
{
var request = this._db.transaction(["tilepath"],"readwrite")
.objectStore("tilepath")
var request = this._db.transaction([this.objectStoreName],"readwrite")
.objectStore(this.objectStoreName)
.delete(url);
request.onsuccess = function()
{
Expand All @@ -1245,8 +1260,8 @@ O.esri.Tiles.TilesStore = function(){
this.getAllTiles = function(callback)
{
if(this._db !== null){
var transaction = this._db.transaction(["tilepath"])
.objectStore("tilepath")
var transaction = this._db.transaction([this.objectStoreName])
.objectStore(this.objectStoreName)
.openCursor();

transaction.onsuccess = function(event)
Expand Down Expand Up @@ -1282,8 +1297,8 @@ O.esri.Tiles.TilesStore = function(){
if(this._db !== null){
var usage = { sizeBytes: 0, tileCount: 0 };

var transaction = this._db.transaction(["tilepath"])
.objectStore("tilepath")
var transaction = this._db.transaction([this.objectStoreName])
.objectStore(this.objectStoreName)
.openCursor();

transaction.onsuccess = function(event){
Expand Down Expand Up @@ -1317,7 +1332,7 @@ O.esri.Tiles.TilesStore = function(){

this.init = function(callback)
{
var request = indexedDB.open(DB_NAME, 4);
var request = indexedDB.open(this.dbName, 4);
callback = callback || function(success) { console.log("TilesStore::init() success:", success); }.bind(this);

request.onerror = function(event)
Expand All @@ -1330,12 +1345,12 @@ O.esri.Tiles.TilesStore = function(){
{
var db = event.target.result;

if( db.objectStoreNames.contains("tilepath"))
if( db.objectStoreNames.contains(this.objectStoreName))
{
db.deleteObjectStore("tilepath");
db.deleteObjectStore(this.objectStoreName);
}

db.createObjectStore("tilepath", { keyPath: "url" });
db.createObjectStore(this.objectStoreName, { keyPath: "url" });
}.bind(this);

request.onsuccess = function(event)
Expand Down
6 changes: 3 additions & 3 deletions dist/offline-tpk-min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 2ae3071

Please sign in to comment.