Basic dialog to start/pause/stop and clear track recording.

This commit is contained in:
vdv committed 2022-09-27 21:53:52 +02:00
1 parent d71881dc02
commit 3235d9ae70
4 files changed
+264 -25

No files matched your search

+53 -2
View File
@@ -1,6 +1,6 @@
import { initDb } from '.';
import PouchDB from 'pouchdb';
import { appendTrkpt } from './gpx';
import { appendTrkpt, deleteCurrent, saveCurrent } from './gpx';
import PouchDBFind from 'pouchdb-find';
import { mkdtempSync, rmdirSync } from 'fs';
@@ -27,7 +27,7 @@ beforeEach(async () => {
});
afterEach(async () => {
// await db.close();
// await db.close();
await db.destroy();
});
@@ -48,3 +48,54 @@ describe('Checking that trkpts are beeing inserted', () => {
expect(docs.length).toBe(3);
});
});
describe('Checking that saveCurrent() is working as expected', () => {
test(', that we still have two documents after saving.', async () => {
await appendTrkpt(db, {});
await saveCurrent(db);
const results = await db.find({
selector: {},
});
const docs = results.docs;
// console.log(`docs: ${JSON.stringify(docs)}`);
expect(docs.length).toBe(2);
});
test("and that we don't have current tracks after saving.", async () => {
await appendTrkpt(db, {});
await saveCurrent(db);
const results = await db.find({
selector: {
type: 'gpx',
subtype: 'current',
},
});
const docs = results.docs;
// console.log(`docs: ${JSON.stringify(docs)}`);
expect(docs.length).toBe(0);
});
});
describe('Checking that deleteCurrent() is working as expected', () => {
test(', that we have no more documents after deleting.', async () => {
await appendTrkpt(db, { time: '' });
await deleteCurrent(db);
const results = await db.find({
selector: {},
});
const docs = results.docs;
// console.log(`docs: ${JSON.stringify(docs)}`);
expect(docs.length).toBe(0);
});
test(', that we have two documents from a saved track after deleting the current one.', async () => {
await appendTrkpt(db, { time: '' });
await saveCurrent(db);
await appendTrkpt(db, { time: '' });
await deleteCurrent(db);
const results = await db.find({
selector: {},
});
const docs = results.docs;
// console.log(`docs: ${JSON.stringify(docs)}`);
expect(docs.length).toBe(2);
});
});
+46 -2
View File
@@ -93,8 +93,6 @@ const initialGpx = {
};
export const appendTrkpt = async (db: any, trkpt: any) => {
const currents = await db.find({
selector: {
type: 'gpx',
@@ -118,3 +116,49 @@ export const appendTrkpt = async (db: any, trkpt: any) => {
await db.post(docPoint);
console.log(JSON.stringify(docPoint));
};
export const saveCurrent = async (db: any) => {
const currents = await db.find({
selector: {
type: 'gpx',
subtype: 'current',
},
});
console.log(`saveCurrent - db.find() : ${JSON.stringify(currents)}`);
if (currents.docs.length > 0) {
const doc = currents.docs[0];
doc.subtype = 'other';
await db.put(doc);
}
};
export const deleteCurrent = async (db: any) => {
const currents = await db.find({
selector: {
type: 'gpx',
subtype: 'current',
},
fields: ['_id', '_rev'],
});
console.log(`deleteCurrent - db.find(gpx) : ${JSON.stringify(currents)}`);
const docs: { _id: string; _rev: string }[] = currents.docs;
for (let i = 0; i < docs.length; i++) {
console.log(`Deleting document ${JSON.stringify(docs[i])}`);
await db.put({ _deleted: true, ...docs[i] });
console.log(`done, id: ${docs[i]._id}`);
const currentTrkpts = await db.find({
selector: {
type: 'trkpt',
gpx: docs[i]._id,
},
fields: ['_id', '_rev', 'type'],
});
console.log(
`deleteCurrent - db.find(trkpts) : ${JSON.stringify(currentTrkpts)}`
);
const trkpts: { _id: string; _rev: string }[] = currentTrkpts.docs;
for (let j = 0; j < trkpts.length; j++) {
await db.put({ _deleted: true, ...trkpts[j] });
}
}
};
+5 -4
View File
@@ -53,9 +53,9 @@ export const initDb = async (db: any, setDbReady: any) => {
for (var index of existingIndexes) {
if (index.type === 'json') {
// Non system indexes
console.log(`Checking existing index :${JSON.stringify(index)}`);
// console.log(`Checking existing index :${JSON.stringify(index)}`);
if (!findIndex(requiredIndexes, index)) {
console.log(`db.deleteIndex(${JSON.stringify(index)})`);
// console.log(`db.deleteIndex(${JSON.stringify(index)})`);
await db.deleteIndex(index);
}
}
@@ -63,14 +63,14 @@ export const initDb = async (db: any, setDbReady: any) => {
for (var index of requiredIndexes) {
if (!findIndex(existingIndexes, index)) {
console.log(`db.createIndex(${JSON.stringify(index)})`);
// console.log(`db.createIndex(${JSON.stringify(index)})`);
await db.createIndex({ name: index.name, ...index.def });
}
}
setDbReady(true);
const indexes = await db.getIndexes();
/* const indexes = await db.getIndexes();
console.log(`indexes: ${JSON.stringify(indexes)}`);
const explain1 = await db.explain({
@@ -90,4 +90,5 @@ export const initDb = async (db: any, setDbReady: any) => {
// use_index: 'type-trkpt-gpx-time',
});
console.log(`explain2: ${JSON.stringify(explain2)}`);
*/
};