diff --git a/README.md b/README.md index 81f05e12ff73092fef75eecc1777e53851f45957..38ccb3bc24976fa606c7faa606fb8a11bc045ac5 100644 --- a/README.md +++ b/README.md @@ -135,3 +135,18 @@ emulator -avd Pixel_3a_API_30_x86 -wipe-data ``` Replace your emulator name with the example above + +## Android publishing +### Notes and docs + +[Developer account for Google Play](https://play.google.com/console/) + +https://stackoverflow.com/questions/69357694/unable-to-build-app-bundle-aab-in-cordova + +https://cordova.apache.org/docs/en/11.x/guide/platforms/android/plugin.html + +https://developer.android.com/guide/app-bundle + +https://developer.android.com/studio/publish#unknown-sources + + diff --git a/src/components/CommonUtil.vue b/src/components/CommonUtil.vue index 164afde41d4f464928f950e76346df6cc576d839..ecd966fd21c74117e2b1caddb1a29bcd2ec9ecf7 100644 --- a/src/components/CommonUtil.vue +++ b/src/components/CommonUtil.vue @@ -69,7 +69,7 @@ CONST_GPS_OBSERVATION_ZOOM: 10, CONST_DB_NAME: 'db-index-observation', - CONST_DB_VERSION: 1, + CONST_DB_VERSION: 3, CONST_DB_ENTITY_PHOTO: 'entityPhoto', CONST_DB_INDEX_NAME_OBSERVATION_ID: 'observationId', diff --git a/src/components/ObservationIllustration.vue b/src/components/ObservationIllustration.vue index 201fdeb42c9599f7e982b0ef09da678596e17378..cd805242688dc742b077b23aa7213cfe4147bed1 100644 --- a/src/components/ObservationIllustration.vue +++ b/src/components/ObservationIllustration.vue @@ -108,40 +108,28 @@ }, /* Fetch the image data (base64 encoded) from the IndexedDB*/ getObservationIllustrationDataFromStore() { - - let isDBStoreNotAvailable = null; let dbRequest = indexedDB.open(CommonUtil.CONST_DB_NAME, CommonUtil.CONST_DB_VERSION); - this.checkDBUpgrade(dbRequest, CommonUtil.CONST_DB_ENTITY_PHOTO); dbRequest.onsuccess = (evt) => { let db = evt.target.result; - if (db.objectStoreNames.contains(CommonUtil.CONST_DB_ENTITY_PHOTO)) { - let transaction = db.transaction([CommonUtil.CONST_DB_ENTITY_PHOTO], 'readwrite'); - let objectstore = transaction.objectStore(CommonUtil.CONST_DB_ENTITY_PHOTO); - if (this.observationIllustration.observationIllustrationPK.fileName) { - let objectstoreRequest = objectstore.get(this.observationIllustration.observationIllustrationPK.fileName); - objectstoreRequest.onsuccess = (event) => { - let observationImage = event.target.result; - if (observationImage) { - //console.info("Rendering image data for file " + observationImage.illustration.fileName); - this.imageBase64Data = observationImage.illustration.imageTextData; - } - else { - console.log('Image filename mentioned in Observation, but no image data found'); - } - }; - } - else { - // Pass?? - } + let transaction = db.transaction([CommonUtil.CONST_DB_ENTITY_PHOTO], 'readwrite'); + let objectstore = transaction.objectStore(CommonUtil.CONST_DB_ENTITY_PHOTO); + if (this.observationIllustration.observationIllustrationPK.fileName) { + let objectstoreRequest = objectstore.get(this.observationIllustration.observationIllustrationPK.fileName); + objectstoreRequest.onsuccess = (event) => { + let observationImage = event.target.result; + if (observationImage) { + //console.info("Rendering image data for file " + observationImage.illustration.fileName); + this.imageBase64Data = observationImage.illustration.imageTextData; + } + else { + console.log('Image filename mentioned in Observation, but no image data found'); + } + }; } else { - db.close(); - isDBStoreNotAvailable = true; + // Pass?? } } - if (isDBStoreNotAvailable) { - this.checkDBUpgrade(dbRequest, CommonUtil.CONST_DB_ENTITY_PHOTO); - } }, /** Remove the image data from IndexedDB */ deleteImageFromIndexedDB() { @@ -175,23 +163,6 @@ } }; } - }, - /** Check requirement for DB upgrade */ - checkDBUpgrade(dbRequest, entityName, keyName) { - dbRequest.onupgradeneeded = function (event) { - let db = event.target.result; - if (!db.objectStoreNames.contains(entityName)) { - let store = null; - if (keyName) { - store = db.createObjectStore(entityName, {keypath: keyName}); - } - else { - store = db.createObjectStore(entityName); - } - store.createIndex('observationId', 'observationId', {unique: false}); - store.createIndex('organismId', 'organismId', {unique: false}); - } - } } }, diff --git a/src/components/ObservationIllustrationBoard.vue b/src/components/ObservationIllustrationBoard.vue index aba587030b6e6acf1c810e0e5fab7ba141bd1bdb..e90c35700cb5fc105023687faafe3b1cbf4e4ec0 100644 --- a/src/components/ObservationIllustrationBoard.vue +++ b/src/components/ObservationIllustrationBoard.vue @@ -131,53 +131,49 @@ var db = evt.target.result; // Get all registered fileNames, and find an available filename var fileName = this.observationId + "_illustration.jpg"; - if (db.objectStoreNames.contains(CommonUtil.CONST_DB_ENTITY_PHOTO)) { - var transaction = db.transaction([CommonUtil.CONST_DB_ENTITY_PHOTO], 'readwrite') - var objectStore = transaction.objectStore(CommonUtil.CONST_DB_ENTITY_PHOTO); - // Finding an available filename - var request = objectStore.getAllKeys().onsuccess = (event) => { - //console.info("All keys?"); - // Array(4) [ "20799_illustration.jpg", "20801_illustration.jpg", "20801_illustration_1.jpg", "20801_illustration_2.jpg" ] - //console.info(event.target.result); //DETTE funker!!! + var transaction = db.transaction([CommonUtil.CONST_DB_ENTITY_PHOTO], 'readwrite') + var objectStore = transaction.objectStore(CommonUtil.CONST_DB_ENTITY_PHOTO); + // Finding an available filename + var request = objectStore.getAllKeys().onsuccess = (event) => { + //console.info("All keys?"); + // Array(4) [ "20799_illustration.jpg", "20801_illustration.jpg", "20801_illustration_1.jpg", "20801_illustration_2.jpg" ] + //console.info(event.target.result); //DETTE funker!!! - var existingFileNames = event.target.result; - var counter = 1; - while (existingFileNames.indexOf(fileName) >= 0) { - fileName = this.observationId + "_illustration_" + (counter++) + ".jpg"; + var existingFileNames = event.target.result; + var counter = 1; + while (existingFileNames.indexOf(fileName) >= 0) { + fileName = this.observationId + "_illustration_" + (counter++) + ".jpg"; + } + // Create the illustration object for storage in IndexedDB + var newIndexedDBIllustration = { + observationId: this.observationId, + deleted: false, + illustration: { + fileName: fileName, + imageTextData: "data:image/jpeg;base64," + imageTextData } - // Create the illustration object for storage in IndexedDB - var newIndexedDBIllustration = { - observationId: this.observationId, - deleted: false, - illustration: { - fileName: fileName, - imageTextData: "data:image/jpeg;base64," + imageTextData - } - }; - // Store the image in IndexedDB - transaction.objectStore(CommonUtil.CONST_DB_ENTITY_PHOTO).add(newIndexedDBIllustration, newIndexedDBIllustration.illustration.fileName).onsuccess = (event) => { - // Create an item for the ObservationIllustrationSet - var newObservationIllustration = { - observationIllustrationPK: { - observationId: this.observationId, - fileName: fileName - }, - uploaded: false - } - // Add the component to the ObservationIllustrationBoard - this.observationIllustrations.push(newObservationIllustration); - this.organizeIllustrationsForRendering(); // Need to do this to ensure the first image is rendered - this.$emit("observationIllustrationSetUpdated", this.observationIllustrations); - }; }; - - } - - + // Store the image in IndexedDB + transaction.objectStore(CommonUtil.CONST_DB_ENTITY_PHOTO).add(newIndexedDBIllustration, newIndexedDBIllustration.illustration.fileName).onsuccess = (event) => { + // Create an item for the ObservationIllustrationSet + var newObservationIllustration = { + observationIllustrationPK: { + observationId: this.observationId, + fileName: fileName + }, + uploaded: false + } + // Add the component to the ObservationIllustrationBoard + this.observationIllustrations.push(newObservationIllustration); + this.organizeIllustrationsForRendering(); // Need to do this to ensure the first image is rendered + this.$emit("observationIllustrationSetUpdated", this.observationIllustrations); + }; + }; // Add the component to the ObservationIllustrationBoard // Mark the observation as "InNeedOfSync" or similar... } + }, onFail: function (message) { alert(message); diff --git a/src/components/Sync.vue b/src/components/Sync.vue index df7daed5385e5f99225e3b10a3ab1f8cb9a30ad4..854f4bdf994a66c7aac1f58515e7655e71e40673 100644 --- a/src/components/Sync.vue +++ b/src/components/Sync.vue @@ -980,19 +980,7 @@ let objectstore = transaction.objectStore(entityName).add(observationImage, observationImage.illustration.fileName); } else { - let store = db.createObjectStore(entityName, {keypath: observationImage.illustration.fileName}); - store.createIndex('observationId', 'observationId', {unique: false}); - store.createIndex('organismId', 'organismId', {unique: false}); - } - } - - - dbRequest.onupgradeneeded = function (event) { - let db = event.target.result; - if (!db.objectStoreNames.contains(entityName)) { - let store = db.createObjectStore(entityName, {keypath: observationImage.illustration.fileName}); - store.createIndex('observationId', 'observationId', {unique: false}); - store.createIndex('organismId', 'organismId', {unique: false}); + alert("Photo part of IndexedDB not created. Please report this error."); } } diff --git a/src/main.js b/src/main.js index c8a54eaf48ca2ce10cfc317c33d56ee1e6a75a9c..f6b016e0a24ff4d2a53744ce5f92d227091ab26e 100644 --- a/src/main.js +++ b/src/main.js @@ -73,6 +73,24 @@ const init = () => { console.info("Vue is ready"); console.info("User's preferred language is " + this.$i18n.locale); // Are we logged in already? + // Load the database, in case we need to create the schema + let dbRequest = indexedDB.open(CommonUtil.CONST_DB_NAME, CommonUtil.CONST_DB_VERSION); + dbRequest.onsuccess = function (evt) { + console.info("IndexedDB contacted"); + // All good + } + + dbRequest.onupgradeneeded = function (event) { + console.info("No/outdated IndexedDB database found. Updating schema.") + // Define the database schema here + let db = event.target.result; + if(!db.objectStoreNames.contains(CommonUtil.CONST_DB_ENTITY_PHOTO)) + { + let store = db.createObjectStore(CommonUtil.CONST_DB_ENTITY_PHOTO, {keypath: "fileName"}); + store.createIndex('observationId', 'observationId', {unique: false}); + store.createIndex('organismId', 'organismId', {unique: false}); + } + } } });