mirror of
https://github.com/zombieFox/nightTab.git
synced 2025-02-01 19:09:51 +01:00
add or replace bookmarks when importing data
This commit is contained in:
parent
23d0fbb106
commit
fbb16cacdd
@ -478,8 +478,23 @@ bookmark.count = () => {
|
||||
};
|
||||
|
||||
bookmark.restore = (dataToRestore) => {
|
||||
|
||||
bookmark.all = dataToRestore.bookmark;
|
||||
console.log('bookmark restored');
|
||||
|
||||
console.log('bookmarks restored');
|
||||
|
||||
};
|
||||
|
||||
bookmark.append = (dataToAppend) => {
|
||||
|
||||
dataToAppend.bookmark.forEach((item, i) => {
|
||||
|
||||
bookmark.all.push(item);
|
||||
|
||||
});
|
||||
|
||||
console.log('bookmarks appended');
|
||||
|
||||
};
|
||||
|
||||
bookmark.reset = () => {
|
||||
|
@ -24,12 +24,20 @@ data.get = (key) => {
|
||||
};
|
||||
|
||||
data.import = {
|
||||
state: { setup: true, bookmark: true, theme: true },
|
||||
state: {
|
||||
setup: { include: true },
|
||||
bookmark: { include: true, type: 'restore' },
|
||||
theme: { include: true }
|
||||
},
|
||||
reset: () => {
|
||||
|
||||
for (let key in data.import.state) {
|
||||
data.import.state[key] = true;
|
||||
};
|
||||
data.import.state.setup.include = true;
|
||||
|
||||
data.import.state.bookmark.include = true;
|
||||
|
||||
data.import.state.bookmark.type = 'restore';
|
||||
|
||||
data.import.state.theme.include = true;
|
||||
|
||||
},
|
||||
file: ({
|
||||
@ -104,7 +112,7 @@ data.validateFile = ({
|
||||
width: 'small',
|
||||
successAction: () => {
|
||||
|
||||
if (data.import.state.setup || data.import.state.theme || data.import.state.bookmark) {
|
||||
if (data.import.state.setup.include || data.import.state.theme.include || data.import.state.bookmark.include) {
|
||||
|
||||
let dataToRestore = JSON.parse(event.target.result);
|
||||
|
||||
@ -255,16 +263,28 @@ data.restore = (dataToRestore) => {
|
||||
|
||||
console.log('data found to load');
|
||||
|
||||
if (data.import.state.setup) {
|
||||
if (data.import.state.setup.include) {
|
||||
state.set.restore.setup(dataToRestore);
|
||||
};
|
||||
|
||||
if (data.import.state.theme) {
|
||||
if (data.import.state.theme.include) {
|
||||
state.set.restore.theme(dataToRestore);
|
||||
};
|
||||
|
||||
if (data.import.state.bookmark) {
|
||||
bookmark.restore(dataToRestore);
|
||||
if (data.import.state.bookmark.include) {
|
||||
|
||||
switch (data.import.state.bookmark.type) {
|
||||
|
||||
case 'restore':
|
||||
bookmark.restore(dataToRestore);
|
||||
break;
|
||||
|
||||
case 'append':
|
||||
bookmark.append(dataToRestore);
|
||||
break;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
} else {
|
||||
|
@ -50,39 +50,76 @@ export const ImportForm = function({
|
||||
|
||||
this.control = {
|
||||
import: {
|
||||
bookmark: new Control_checkbox({
|
||||
object: state,
|
||||
path: 'bookmark',
|
||||
id: 'bookmark',
|
||||
labelText: 'Bookmarks',
|
||||
description: [`This includes <strong>${this.count.bookmark()} ${this.count.bookmark() > 1 ? `Bookmarks` : `Bookmark`}</strong> in <strong>${dataToImport.bookmark.length} ${dataToImport.bookmark.length > 1 ? `Groups` : `Group`}.<strong>`, 'Bookmarks will keep any custom Colours, Accents and Borders when imported.']
|
||||
}),
|
||||
theme: new Control_checkbox({
|
||||
object: state,
|
||||
path: 'theme',
|
||||
id: 'theme',
|
||||
labelText: 'Theme',
|
||||
description: 'This includes the Colour, Accent, Fonts, Background and any saved Custom Themes.'
|
||||
}),
|
||||
setup: new Control_checkbox({
|
||||
object: state,
|
||||
path: 'setup',
|
||||
id: 'setup',
|
||||
labelText: 'Settings',
|
||||
description: 'This includes Layout size and position, Header area size, Bookmark area size and other user settings.'
|
||||
})
|
||||
bookmark: {
|
||||
include: new Control_checkbox({
|
||||
object: state,
|
||||
path: 'bookmark.include',
|
||||
id: 'bookmark-include',
|
||||
labelText: 'Bookmarks',
|
||||
description: [`This includes <strong>${this.count.bookmark()} ${this.count.bookmark() > 1 ? `Bookmarks` : `Bookmark`}</strong> in <strong>${dataToImport.bookmark.length} ${dataToImport.bookmark.length > 1 ? `Groups` : `Group`}.<strong>`, 'Bookmarks will keep any custom Colours, Accents and Borders when imported.'],
|
||||
action: () => {
|
||||
this.disable();
|
||||
}
|
||||
}),
|
||||
type: new Control_radio({
|
||||
object: state,
|
||||
radioGroup: [
|
||||
{ id: 'bookmark-type-restore', labelText: 'Replace existing bookmarks', value: 'restore' },
|
||||
{ id: 'bookmark-type-append', labelText: 'Add to existing bookmarks', value: 'append' }
|
||||
],
|
||||
groupName: 'bookmark-type',
|
||||
path: 'bookmark.type'
|
||||
})
|
||||
},
|
||||
theme: {
|
||||
include: new Control_checkbox({
|
||||
object: state,
|
||||
path: 'theme.include',
|
||||
id: 'theme-include',
|
||||
labelText: 'Theme',
|
||||
description: 'This includes the Colour, Accent, Fonts, Background and any saved Custom Themes.'
|
||||
})
|
||||
},
|
||||
setup: {
|
||||
include: new Control_checkbox({
|
||||
object: state,
|
||||
path: 'setup.include',
|
||||
id: 'setup-include',
|
||||
labelText: 'Settings',
|
||||
description: 'This includes Layout size and position, Header area size, Bookmark area size and other user settings.'
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.disable = () => {};
|
||||
this.disable = () => {
|
||||
|
||||
if (state.bookmark.include) {
|
||||
this.control.import.bookmark.type.enable();
|
||||
} else {
|
||||
this.control.import.bookmark.type.disable();
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
this.assemble = () => {
|
||||
|
||||
this.element.form.append(node('div', [
|
||||
this.element.description,
|
||||
this.control.import.bookmark.wrap(),
|
||||
this.control.import.theme.wrap(),
|
||||
this.control.import.setup.wrap()
|
||||
this.control.import.bookmark.include.wrap(),
|
||||
form.wrap({
|
||||
children: [
|
||||
form.indent({
|
||||
children: [
|
||||
this.control.import.bookmark.type.wrap(),
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
node('hr'),
|
||||
this.control.import.theme.include.wrap(),
|
||||
node('hr'),
|
||||
this.control.import.setup.include.wrap()
|
||||
]));
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user