Skip to content

Commit 3aeecca

Browse files
committed
fix: unable to create or delete projects #37
1 parent 6998272 commit 3aeecca

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

app-src/scripts/main/global-services/projects-s.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,36 @@
6868
};
6969

7070
this.createNewFromCurrent = (projectTitle) => {
71-
if ($rootScope.r.projects.length > 0) {
71+
const projects = this.getListWithLsData();
72+
if (projects) {
7273
SimpleToast('ERROR', 'ERROR: There is already a project');
7374
return;
7475
}
7576

7677
this.createNew(projectTitle, $rootScope.r);
7778
};
7879

80+
this.remove = (projectToRemove) => {
81+
const projects = this.getListWithLsData();
82+
const indexToDelete = projects.findIndex((lProj) => {
83+
return lProj.id === projectToRemove.id;
84+
});
85+
86+
projects.splice(indexToDelete, 1);
87+
AppStorage.saveProjects(projects);
88+
89+
// project has been deleted so show message already here
90+
// even if something below goes wrong
91+
SimpleToast('SUCCESS', projectToRemove.title + ' deleted!');
92+
93+
// also delete from $rootScope
94+
const indexToDeleteViewModel = $rootScope.r.projects.findIndex((lProj) => {
95+
return lProj.id === projectToRemove.id;
96+
});
97+
$rootScope.r.projects.splice(indexToDeleteViewModel, 1);
98+
99+
};
100+
79101
this.createNew = (projectTitle, data) => {
80102
if (projectTitle && angular.isObject(data)) {
81103
// save new project
@@ -89,7 +111,7 @@
89111
$rootScope.r.projects.push(newProject);
90112

91113
// update ls
92-
const projects = this.getListWithLsData();
114+
const projects = this.getListWithLsData() || [];
93115
projects.push(newProject);
94116
AppStorage.saveProjects(projects);
95117

@@ -158,6 +180,9 @@
158180

159181
// re-init all global models
160182
InitGlobalModels();
183+
184+
// Show success message
185+
SimpleToast('SUCCESS', `Switched to project "${newCurrentProject.title}"`);
161186
}
162187
};
163188
}

app-src/scripts/settings/project-settings/project-settings-d.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
Dialogs('CREATE_PROJECT');
4343
};
4444

45-
vm.deleteProject = (project, $index) => {
45+
vm.deleteProject = (project) => {
4646
if (project.id === $rootScope.r.currentProject.id) {
4747
SimpleToast('ERROR', 'Cannot delete ' + project.title + ' as it is the current project!');
4848
} else {
@@ -54,8 +54,7 @@
5454
.cancel('Better not');
5555

5656
$mdDialog.show(confirm).then(function () {
57-
vm.allProjects.splice($index, 1);
58-
SimpleToast('SUCCESS', project.title + ' deleted!');
57+
Projects.remove(project);
5958
});
6059
}
6160
};

0 commit comments

Comments
 (0)