| 
68 | 68 |     };  | 
69 | 69 | 
 
  | 
70 | 70 |     this.createNewFromCurrent = (projectTitle) => {  | 
71 |  | -      if ($rootScope.r.projects.length > 0) {  | 
 | 71 | +      const projects = this.getListWithLsData();  | 
 | 72 | +      if (projects) {  | 
72 | 73 |         SimpleToast('ERROR', 'ERROR: There is already a project');  | 
73 | 74 |         return;  | 
74 | 75 |       }  | 
75 | 76 | 
 
  | 
76 | 77 |       this.createNew(projectTitle, $rootScope.r);  | 
77 | 78 |     };  | 
78 | 79 | 
 
  | 
 | 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 | + | 
79 | 101 |     this.createNew = (projectTitle, data) => {  | 
80 | 102 |       if (projectTitle && angular.isObject(data)) {  | 
81 | 103 |         // save new project  | 
 | 
89 | 111 |         $rootScope.r.projects.push(newProject);  | 
90 | 112 | 
 
  | 
91 | 113 |         // update ls  | 
92 |  | -        const projects = this.getListWithLsData();  | 
 | 114 | +        const projects = this.getListWithLsData() || [];  | 
93 | 115 |         projects.push(newProject);  | 
94 | 116 |         AppStorage.saveProjects(projects);  | 
95 | 117 | 
 
  | 
 | 
158 | 180 | 
 
  | 
159 | 181 |         // re-init all global models  | 
160 | 182 |         InitGlobalModels();  | 
 | 183 | + | 
 | 184 | +        // Show success message  | 
 | 185 | +        SimpleToast('SUCCESS', `Switched to project "${newCurrentProject.title}"`);  | 
161 | 186 |       }  | 
162 | 187 |     };  | 
163 | 188 |   }  | 
 | 
0 commit comments