AngularJS service used to add, retrieve and update recent items that the user has viewed within a MobileCaddy application.
- Encrypted DB support
- Updating recent item objects following
devUtils.updateRecords()
and sync completion processes. - Remove recent item entries when they are deleted from localDB, or maked as deleted following sync completion processes.
npm install mobilecaddy-app-addon-recent-items
The installation will include the tasks of moving the relevant scripts into the correct place of your MobileCaddy application project structure. The relevant unit tests will also be included.
You can set the configuration information of the recent items, such as the maximum number of items, if they will be saved in localStorage or encrypted in the database, the type of items, among other details. This can be run in the .run
in the app.js file, thus it can be updated by the developer easily.
RecentItemsService.setConfig({
maxItems: 50,
encrypted: false,
tables: [
{
name: 'Account',
icon: 'ion-folder',
href: '/accounts/:Id'
},
{
name: 'Contact',
icon: 'ion-person',
href: '/accounts/:AccountId/contacts/:Id'
}
]
});
setConfig( { maxItems, encrypted, tables } );
How many recent items to store. Defaults to 10.
Whether or not to use the encrypted database to store the recent items. If false, stored in localStorage. Defaults to false. Note: Not yet supported.
Array of objects configuring each table to be included in the global search, thus;
[{
name, // string:
icon, // string: Ionicon to be used in enriched output
href // string: State URL to be used for direct record access in enriched output.
}]
Adds an item to the recent items list.
addRecentItem( type, object );
type : String. Represents the type of the new item, e.g. "Account".
object : Object. It is the object that will be added to the recent items list.
var object = {
Id: 'acc1',
Name: 'MobileCaddy'
};
RecentItemsService.addRecentItem( 'Account', object );
Retrieves an array of recent items.
getRecentItems( type, amount, config );
type : String | NULL . Represents the type of the items, e.g. "Account". NULL can be supplied.
amount : Number. Refers to the number of recent items that the controller wants to receive. It's optional.
config : Boolean. Defines if the user wants to get config information about the recent items. It's optional.
An array of recent item objects.
Get the two most recent items of type Account that don't include configuration information, such as icon and href.
var recentItems = RecentItemsService.getRecentItems( 'Account', 2 );
Get all recentItems for all types, and include configuration information, such as icon and href.
var recentItems = RecentItemsService.getRecentItems( null, null true );
clearRecentItems( type );
type : String. Represents the type of the items, e.g. "Account". Optional.
RecentItemsService.clearRecentItems();
RecentItemsService.clearRecentItems( 'Account' );
Looks for an object in the recentItems store for a specific Id. Returns the object if it exists, else returns false.
contains( id );
id : String. Represents the Id of the object being searched for.
The matching object, or false if not found.
RecentItemsService.contains( 'AB123CD456EF789' );
Removes an item from the recentItems for a specific Id
removeItem( id );
id : String. Represents the Id of the object being searched for.
true if object was found, false if not.
RecentItemsService.removeItem( 'AB123CD456EF789' );