Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
feat(logs): Move logs to the database
Browse files Browse the repository at this point in the history
feat: store last updates in log
  • Loading branch information
ahmadalfy authored Feb 10, 2020
2 parents 15dbf8b + 26b3f85 commit a0a9a6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 4 additions & 2 deletions scripts/base-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ class Base {
}

updateLastModified() {
const lastModified = localStorage.getItem(this.component);
document.querySelector(`#${this.component}-update`).innerHTML = lastModified ? timeAgo.format(JSON.parse(lastModified)) : 'Not available';
db.logs.get(this.component,(item)=> {
document.querySelector(`#${this.component}-update`).innerHTML = item ?
timeAgo.format(JSON.parse(item.last_updated)) : 'Not available';
});
}

prepareFilters() {
Expand Down
15 changes: 12 additions & 3 deletions scripts/data-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class DataSource {
const groups = await Groups.load();
this.data.groups = groups;
db.groups.bulkPut(groups);
localStorage.setItem('groups', Date.now());
db.logs.put({
last_updated: Date.now(),
id: 'groups'
});
return this.data.groups;
}

Expand All @@ -30,7 +33,10 @@ class DataSource {
project.group_id = project.namespace.id;
});
db.projects.bulkPut(this.data.projects);
localStorage.setItem('projects', Date.now());
db.logs.put({
last_updated: Date.now(),
id: 'projects'
});
return this.data.projects;
}

Expand All @@ -39,7 +45,10 @@ class DataSource {
const key = 'id';
this.data.members = [...new Map(members.flat().map(item => [item[key], item])).values()];
db.members.bulkPut(this.data.members);
localStorage.setItem('members', Date.now());
db.logs.put({
last_updated: Date.now(),
id: 'members'
});
return this.data.members;
}
}
Expand Down
1 change: 1 addition & 0 deletions scripts/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ db.version(1).stores({
events: 'created_at, project_id -> projects.id, author_id -> members.id',
member_events: 'id++, member_id -> members.id',
commits: 'short_id, author_name -> members.name, authored_date, project_id -> projects.id',
logs: 'id'
});

export default db;

0 comments on commit a0a9a6f

Please sign in to comment.