Skip to content

Commit

Permalink
fix(appStorage): messing up with backlog data and import of settings
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesjo committed Nov 24, 2017
1 parent 746af5d commit ebed0c9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
39 changes: 35 additions & 4 deletions app-src/scripts/main/global-services/app-storage-s.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/* @ngInject */
constructor(LS_DEFAULTS, SAVE_APP_STORAGE_POLL_INTERVAL, TMP_FIELDS, $interval, $rootScope, ON_DEMAND_LS_FIELDS, ON_DEMAND_LS_FIELDS_FOR_PROJECT, IS_ELECTRON) {
this.PROJECTS_KEY = 'projects';
this.BACKLOG_TASKS_KEY = 'doneBacklogTasks';
this.DONE_BACKLOG_TASKS_KEY = 'doneBacklogTasks';
this.LS_DEFAULTS = LS_DEFAULTS;
this.TMP_FIELDS = TMP_FIELDS;
this.SAVE_APP_STORAGE_POLL_INTERVAL = SAVE_APP_STORAGE_POLL_INTERVAL;
Expand Down Expand Up @@ -72,7 +72,7 @@
// also add projects data
data[this.PROJECTS_KEY] = this.getProjects();
// also add backlog tasks
data[this.BACKLOG_TASKS_KEY] = this.getDoneBacklogTasks();
data[this.DONE_BACKLOG_TASKS_KEY] = this.getDoneBacklogTasks();

fs.writeFile(path, JSON.stringify(data), function(err) {
if (err) {
Expand Down Expand Up @@ -104,12 +104,32 @@
}

getDoneBacklogTasks() {
return this.getLsItem(this.BACKLOG_TASKS_KEY);
const projects = this.getProjects();

if (projects && this.$rootScope.r.currentProject && this.$rootScope.r.currentProject.id) {
const currentProject = _.find(projects, ['id', this.$rootScope.r.currentProject.id]);
console.log(currentProject.data);

return currentProject.data[this.DONE_BACKLOG_TASKS_KEY];
} else {
return this.getLsItem(this.DONE_BACKLOG_TASKS_KEY);
}
}

saveDoneBacklogTasks(doneBacklogTasks) {
if (Array.isArray(doneBacklogTasks)) {
this.saveLsItem(doneBacklogTasks, this.BACKLOG_TASKS_KEY);
const projects = this.getProjects();

// we also need to save the backlog tasks to the current project
if (projects && this.$rootScope.r.currentProject && this.$rootScope.r.currentProject.id) {
console.log(projects, this.$rootScope.r.currentProject.id);

const currentProject = _.find(projects, ['id', this.$rootScope.r.currentProject.id]);
currentProject.data[this.DONE_BACKLOG_TASKS_KEY] = doneBacklogTasks;
this.saveProjects(projects);
} else {
this.saveLsItem(doneBacklogTasks, this.DONE_BACKLOG_TASKS_KEY);
}
}
}

Expand All @@ -120,6 +140,17 @@
}
}

importData(data) {
_.forOwn(data, (val, key) => {
this.$rootScope.r[key] = val;
});

// update to ls (NOTE: order is important!)
this.saveToLs();
this.saveProjects(data[this.PROJECTS_KEY]);
this.saveDoneBacklogTasks(data[this.DONE_BACKLOG_TASKS_KEY]);
}

getProjects() {
return this.getLsItem(this.PROJECTS_KEY);
}
Expand Down
9 changes: 2 additions & 7 deletions app-src/scripts/settings/backup-settings/backup-settings-d.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,14 @@
}

/* @ngInject */
function BackupSettingsCtrl($rootScope, AppStorage, IS_ELECTRON) {
function BackupSettingsCtrl(AppStorage, IS_ELECTRON) {
let vm = this;
vm.IS_ELECTRON = IS_ELECTRON;

// import/export stuff
vm.importSettings = (uploadSettingsTextarea) => {
let settings = JSON.parse(uploadSettingsTextarea);

_.forOwn(settings, (val, key) => {
$rootScope.r[key] = val;
});

AppStorage.saveToLs();
AppStorage.importData(settings);

// reload page completely afterwards
window.location.reload(true);
Expand Down

0 comments on commit ebed0c9

Please sign in to comment.