Project

General

Profile

« Previous | Next » 

Revision 7218849a

Added by koszko over 1 year ago

add a mapping/resources installation dialog

View differences:

common/indexeddb.js
61 61
const stores = 	[
62 62
    ["files",     {keyPath: "hash_key"}],
63 63
    ["file_uses", {keyPath: "hash_key"}],
64
    ["resources", {keyPath: "identifier"}],
65
    ["mappings",  {keyPath: "identifier"}],
64
    ["resource",  {keyPath: "identifier"}],
65
    ["mapping",   {keyPath: "identifier"}],
66 66
    ["settings",  {keyPath: "name"}],
67 67
    ["blocking",  {keyPath: "pattern"}],
68 68
    ["repos",     {keyPath: "url"}]
......
175 175
}
176 176

  
177 177
/*
178
 * item_store_names should be an array with either string "mappings", string
179
 * "resources" or both. files should be a dict with values being contents of
178
 * item_store_names should be an array with either string "mapping", string
179
 * "resource" or both. files should be an object with values being contents of
180 180
 * files that are to be possibly saved in this transaction and keys of the form
181 181
 * `sha256-<file's-sha256-sum>`.
182 182
 *
......
292 292
 */
293 293
async function save_items(data)
294 294
{
295
    const item_store_names = ["resources", "mappings"];
295
    const item_store_names = ["resource", "mapping"];
296 296
    const context = await start_items_transaction(item_store_names, data.files);
297 297

  
298 298
    return _save_items(data.resources, data.mappings, context);
......
323 323
 */
324 324
async function save_item(item, context)
325 325
{
326
    const store_name = {resource: "resources", mapping: "mappings"}[item.type];
327

  
328 326
    for (const file_ref of entities.get_files(item))
329 327
	await incr_file_uses(context, file_ref);
330 328

  
331
    broadcast.prepare(context.sender, `idb_changes_${store_name}`,
329
    broadcast.prepare(context.sender, `idb_changes_${item.type}`,
332 330
		      item.identifier);
333
    await _remove_item(store_name, item.identifier, context, false);
334
    await idb_put(context.transaction, store_name, item);
331
    await _remove_item(item.type, item.identifier, context, false);
332
    await idb_put(context.transaction, item.type, item);
335 333
}
336 334
#EXPORT save_item
337 335

  
......
360 358
    await idb_del(context.transaction, store_name, identifier);
361 359
}
362 360

  
363
const remove_resource = (id, ctx) => remove_item("resources", id, ctx);
361
const remove_resource = (id, ctx) => remove_item("resource", id, ctx);
364 362
#EXPORT remove_resource
365 363

  
366
const remove_mapping = (id, ctx) => remove_item("mappings",  id, ctx);
364
const remove_mapping = (id, ctx) => remove_item("mapping",  id, ctx);
367 365
#EXPORT remove_mapping
368 366

  
369 367
/* Function to retrieve all items from a given store. */
......
460 458
/*
461 459
 * Monitor changes to `store_name` IndexedDB object store.
462 460
 *
463
 * `store_name` should be either "resources", "mappings" or "settings".
461
 * `store_name` should be either "resource", "mapping", "settings", "blocking"
462
 * or "repos".
464 463
 *
465 464
 * `onchange` should be a callback that will be called when an item is added,
466 465
 * modified or removed from the store. The callback will be passed an object
......
491 490
}
492 491

  
493 492
const track = {};
494
const trackable = ["resources", "mappings", "settings", "blocking", "repos"];
493
const trackable = ["resource", "mapping", "settings", "blocking", "repos"];
495 494
for (const store_name of trackable)
496 495
    track[store_name] = onchange => start_tracking(store_name, onchange);
497 496
#EXPORT track

Also available in: Unified diff