Adding a "shared" property to gpxes and family.
This commit is contained in:
parent
8853ea4670
commit
9dacad9af3
|
@ -1,6 +1,6 @@
|
||||||
import { useI18n } from '@solid-primitives/i18n';
|
import { useI18n } from '@solid-primitives/i18n';
|
||||||
import { Box, Button, IconButton, SvgIcon, TextField } from '@suid/material';
|
import { Box, Button, IconButton, SvgIcon, TextField } from '@suid/material';
|
||||||
import { cloneDeep } from 'lodash';
|
import { cloneDeep, isPlainObject } from 'lodash';
|
||||||
import { Component, createSignal, Show } from 'solid-js';
|
import { Component, createSignal, Show } from 'solid-js';
|
||||||
import { newEmptyGpx } from '../../db/gpx';
|
import { newEmptyGpx } from '../../db/gpx';
|
||||||
import { peekCachedSignal } from '../../workers/cached-signals';
|
import { peekCachedSignal } from '../../workers/cached-signals';
|
||||||
|
@ -93,6 +93,20 @@ const GpxDialog: Component<{}> = (props) => {
|
||||||
gpx: gpx(),
|
gpx: gpx(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const gpxSharedChangeHandler = (event: any) => {
|
||||||
|
const newGpx: Gpx = cloneDeep(gpx()) as Gpx;
|
||||||
|
if (!isPlainObject(newGpx.extensions)) {
|
||||||
|
newGpx.extensions = {};
|
||||||
|
}
|
||||||
|
newGpx.extensions.shared = event.target.value;
|
||||||
|
setGpx(newGpx);
|
||||||
|
console.log({
|
||||||
|
caller: 'GpxDialog / gpxSharedChangeHandler',
|
||||||
|
value: event.target.value,
|
||||||
|
gpx: gpx(),
|
||||||
|
newGpx,
|
||||||
|
});
|
||||||
|
};
|
||||||
const gpxTimeChangeHandler = (event: any) => {
|
const gpxTimeChangeHandler = (event: any) => {
|
||||||
const newGpx: Gpx = cloneDeep(gpx()) as Gpx;
|
const newGpx: Gpx = cloneDeep(gpx()) as Gpx;
|
||||||
if (newGpx.metadata === undefined) {
|
if (newGpx.metadata === undefined) {
|
||||||
|
@ -164,6 +178,14 @@ const GpxDialog: Component<{}> = (props) => {
|
||||||
onChange={gpxDescChangeHandler}
|
onChange={gpxDescChangeHandler}
|
||||||
InputProps={{ inputComponent: 'textarea' }}
|
InputProps={{ inputComponent: 'textarea' }}
|
||||||
/>
|
/>
|
||||||
|
<TextField
|
||||||
|
label={t('gpxShared')}
|
||||||
|
multiline={true}
|
||||||
|
rows={5}
|
||||||
|
value={gpx()?.extensions?.shared || ''}
|
||||||
|
onChange={gpxSharedChangeHandler}
|
||||||
|
InputProps={{ inputComponent: 'textarea' }}
|
||||||
|
/>
|
||||||
<Button variant='contained' onClick={saveHandler}>
|
<Button variant='contained' onClick={saveHandler}>
|
||||||
{t('gpxSave')}
|
{t('gpxSave')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -43,7 +43,7 @@ for (const property in methods) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const changeHandler = async (change: any) => {
|
const changeHandler = async (change: any) => {
|
||||||
// console.log({ caller: 'ChangeHandler', change, watches: globalThis.watches });
|
// console.log({ caller: 'ChangeHandler', change, watches: globalThis.watches });
|
||||||
const { id } = change;
|
const { id } = change;
|
||||||
if (!globalThis.watches) {
|
if (!globalThis.watches) {
|
||||||
globalThis.watches = new Map();
|
globalThis.watches = new Map();
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { Rowing } from '@suid/icons-material';
|
||||||
import { cloneDeep, isEmpty } from 'lodash';
|
import { cloneDeep, isEmpty } from 'lodash';
|
||||||
import { PureComponent } from 'react';
|
import { PureComponent } from 'react';
|
||||||
import { $DEVCOMP } from 'solid-js';
|
import { $DEVCOMP } from 'solid-js';
|
||||||
|
@ -423,9 +424,20 @@ export const getGpx = async (params: any) => {
|
||||||
}
|
}
|
||||||
//level 1 (extensions)
|
//level 1 (extensions)
|
||||||
if (target !== undefined && row.doc.type === 'extensions') {
|
if (target !== undefined && row.doc.type === 'extensions') {
|
||||||
target.splice(1);
|
console.log({
|
||||||
appendToArray(target.at(-1), row.doc.type, row.doc.doc);
|
caller: 'getGpx / extensions',
|
||||||
target.push(row.doc.doc);
|
gpx,
|
||||||
|
row,
|
||||||
|
doc: row.doc.doc,
|
||||||
|
gpx_extensions: gpx?.extensions,
|
||||||
|
target,
|
||||||
|
});
|
||||||
|
|
||||||
|
gpx.extensions = row.doc.doc;
|
||||||
|
|
||||||
|
// target.splice(1);
|
||||||
|
// appendToArray(target.at(-1), row.doc.type, row.doc.doc);
|
||||||
|
// target.push(row.doc.doc);
|
||||||
}
|
}
|
||||||
//level 1 (others)
|
//level 1 (others)
|
||||||
if (
|
if (
|
||||||
|
@ -477,7 +489,10 @@ export const putGpx = async (params: any) => {
|
||||||
gpx: intToGpxId(date.valueOf()),
|
gpx: intToGpxId(date.valueOf()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log({ caller: 'putGpx', params, id, gpx });
|
|
||||||
|
const previousShared = (await get(`${id}/4extensions`)).doc?.shared;
|
||||||
|
|
||||||
|
console.log({ caller: 'putGpx', params, id, gpx, previousShared });
|
||||||
const extensions = gpx?.extensions;
|
const extensions = gpx?.extensions;
|
||||||
|
|
||||||
gpx.extensions = undefined;
|
gpx.extensions = undefined;
|
||||||
|
@ -494,5 +509,24 @@ export const putGpx = async (params: any) => {
|
||||||
extensions
|
extensions
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (previousShared !== extensions?.shared) {
|
||||||
|
const shared = extensions?.shared.split(/\s*,\s*/);
|
||||||
|
const family = (await getFamily(id, { include_docs: true })).rows.map(
|
||||||
|
(row: any) => {
|
||||||
|
return { ...row.doc, shared };
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log({
|
||||||
|
caller: 'putGpx / updateShared',
|
||||||
|
params,
|
||||||
|
id,
|
||||||
|
gpx,
|
||||||
|
previousShared,
|
||||||
|
family,
|
||||||
|
});
|
||||||
|
await db.bulkDocs(family);
|
||||||
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,7 +49,8 @@ interface Extensions {
|
||||||
'dyo:batterylevel'?: number;
|
'dyo:batterylevel'?: number;
|
||||||
'dyo:useragent'?: string;
|
'dyo:useragent'?: string;
|
||||||
'dyo:minZoom'?: number;
|
'dyo:minZoom'?: number;
|
||||||
address: any;
|
address?: any;
|
||||||
|
shared?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Trk {
|
interface Trk {
|
||||||
|
|
|
@ -44,6 +44,7 @@ const dict = {
|
||||||
gpxNoName: 'No name',
|
gpxNoName: 'No name',
|
||||||
gpxDesc: 'Description',
|
gpxDesc: 'Description',
|
||||||
gpxTime: 'Start date',
|
gpxTime: 'Start date',
|
||||||
|
gpxShared: 'Shared with',
|
||||||
gpxSave: 'Save',
|
gpxSave: 'Save',
|
||||||
newGpx: '-- new journey --',
|
newGpx: '-- new journey --',
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ const dict = {
|
||||||
gpxNoName: 'Pas de nom',
|
gpxNoName: 'Pas de nom',
|
||||||
gpxDesc: 'Description',
|
gpxDesc: 'Description',
|
||||||
gpxTime: 'Date de début',
|
gpxTime: 'Date de début',
|
||||||
|
gpxShared: 'Partagé avec',
|
||||||
gpxSave: 'Sauvegarder',
|
gpxSave: 'Sauvegarder',
|
||||||
newGpx: '-- nouveau voyage --',
|
newGpx: '-- nouveau voyage --',
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue